From a1b6d316be45a65a48e5bbfb41e09980d6af4405 Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Fri, 13 Nov 2020 20:12:03 +0100 Subject: [PATCH 1/5] WIP:Added CSV an JSON formats in console task report save to disk --- pandora_console/include/functions_cron.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index abc7d45984..7895779e25 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -623,6 +623,9 @@ function cron_list_table() break; case 'cron_task_save_xml_report_to_disk': + case 'cron_task_save_json_report_to_disk': + case 'cron_task_save_csv_report_to_disk': + if ($write_perms || $manage_pandora) { $data[0] = ''; From 84f3ead86a02828c520547b151ae4be4a98505ed Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Mon, 25 Jan 2021 11:51:53 +0100 Subject: [PATCH 2/5] Added csv, json, xml formats to save report to disk task --- pandora_console/include/functions_cron.php | 42 ++-------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index 7895779e25..dd51e10cb3 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -600,45 +600,6 @@ function cron_list_table() $data[0] = ''; } - $data[1] = $task['id_usuario']; - $data[2] = db_get_value( - 'name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - - $args = unserialize($task['args']); - $report = reports_get_report($args[0]); - - // Check ACL in reports_get_report return false. - if ($report === false) { - continue; - } - - $path = $args[1]; - $data[2] .= '
- '.__('Report').":
".$report['name'].''; - $data[2] .= '
- '.__('Path').': '.$path.''; - break; - - case 'cron_task_save_xml_report_to_disk': - case 'cron_task_save_json_report_to_disk': - case 'cron_task_save_csv_report_to_disk': - - if ($write_perms || $manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= ''; - } else { - $data[0] = ''; - } - $data[1] = $task['id_usuario']; $data[2] = db_get_value('name', 'tuser_task', 'id', $task['id_user_task']); $args = unserialize($task['args']); @@ -650,9 +611,12 @@ function cron_list_table() } $path = $args[1]; + $report_type = $args[3]; $data[2] .= '
- '.__('Report').": ".$report['name'].''; $data[2] .= '
- '.__('Path').': '.$path.''; + $data[2] .= '
- '.__('Report type').': '.$report_type; + break; case 'cron_task_do_backup': From dc3ee2d553be22a3b288cfc297a28ec08577cf8b Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Tue, 26 Jan 2021 16:36:13 +0100 Subject: [PATCH 3/5] Added task save report to disk changes to MR --- pandora_console/extras/mr/44.sql | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pandora_console/extras/mr/44.sql b/pandora_console/extras/mr/44.sql index 527d1e0b2f..3241c2001e 100644 --- a/pandora_console/extras/mr/44.sql +++ b/pandora_console/extras/mr/44.sql @@ -133,4 +133,19 @@ ADD COLUMN `field16` TEXT NOT NULL AFTER `field15` ALTER TABLE `trecon_task` MODIFY COLUMN `review_mode` TINYINT(1) UNSIGNED DEFAULT 1; -COMMIT; +DELETE FROM `tuser_task` WHERE id = 6; + +UPDATE `tuser_task` SET `parameters`='a:4:{i:0;a:6:{s:11:"description";s:28:"Report pending to be created";s:5:"table";s:7:"treport";s:8:"field_id";s:9:"id_report";s:10:"field_name";s:4:"name";s:4:"type";s:3:"int";s:9:"acl_group";s:8:"id_group";}i:1;a:2:{s:11:"description";s:426:"Save to disk in pathThe Apache user should have read-write access on this folder. E.g. /var/www/html/pandora_console/attachment";s:4:"type";s:6:"string";}i:2;a:2:{s:11:"description";s:16:"File nane prefix";s:4:"type";s:6:"string";}i:3;a:2:{s:11:"description";s:11:"Report Type";s:4:"type";s:11:"report_type";}}' WHERE `id`=3; + +UPDATE `tuser_task_scheduled` SET + `args` = REPLACE (`args`, 'a:3', 'a:5'), + `args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:3;s:3:"PDF";s:15:"first_execution"') + WHERE `id_user_task` = 3; + +UPDATE `tuser_task_scheduled` SET + `id_user_task` = 3, + `args` = REPLACE (`args`, 'a:3', 'a:5'), + `args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:3;s:3:"XML";s:15:"first_execution"') + WHERE `id_user_task` = 6; + +COMMIT; \ No newline at end of file From 954c12646b6609e0264745fd3a8c045262d313ff Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Tue, 26 Jan 2021 16:46:45 +0100 Subject: [PATCH 4/5] Added task save report to disk changes to migrate --- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index b06a4c3c56..46cbef2bbc 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2525,6 +2525,20 @@ ALTER TABLE `tnetflow_filter` MODIFY COLUMN `router_ip` text NOT NULL; -- ---------------------------------------------------------------------- UPDATE tuser_task set parameters = 'a:5:{i:0;a:6:{s:11:\"description\";s:28:\"Report pending to be created\";s:5:\"table\";s:7:\"treport\";s:8:\"field_id\";s:9:\"id_report\";s:10:\"field_name\";s:4:\"name\";s:4:\"type\";s:3:\"int\";s:9:\"acl_group\";s:8:\"id_group\";}i:1;a:2:{s:11:\"description\";s:46:\"Send to email addresses (separated by a comma)\";s:4:\"type\";s:4:\"text\";}i:2;a:2:{s:11:\"description\";s:7:\"Subject\";s:8:\"optional\";i:1;}i:3;a:3:{s:11:\"description\";s:7:\"Message\";s:4:\"type\";s:4:\"text\";s:8:\"optional\";i:1;}i:4;a:2:{s:11:\"description\";s:11:\"Report Type\";s:4:\"type\";s:11:\"report_type\";}}' where function_name = "cron_task_generate_report"; INSERT IGNORE INTO tuser_task VALUES (8, 'cron_task_generate_csv_log', 'a:1:{i:0;a:2:{s:11:"description";s:14:"Send to e-mail";s:4:"type";s:4:"text";}}', 'Send csv log'); +UPDATE `tuser_task` SET `parameters`='a:4:{i:0;a:6:{s:11:"description";s:28:"Report pending to be created";s:5:"table";s:7:"treport";s:8:"field_id";s:9:"id_report";s:10:"field_name";s:4:"name";s:4:"type";s:3:"int";s:9:"acl_group";s:8:"id_group";}i:1;a:2:{s:11:"description";s:426:"Save to disk in pathThe Apache user should have read-write access on this folder. E.g. /var/www/html/pandora_console/attachment";s:4:"type";s:6:"string";}i:2;a:2:{s:11:"description";s:16:"File nane prefix";s:4:"type";s:6:"string";}i:3;a:2:{s:11:"description";s:11:"Report Type";s:4:"type";s:11:"report_type";}}' WHERE `id`=3; +DELETE FROM `tuser_task` WHERE id = 6; + +-- Migrate old tasks +UPDATE `tuser_task_scheduled` SET + `args` = REPLACE (`args`, 'a:3', 'a:5'), + `args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:3;s:3:"PDF";s:15:"first_execution"') + WHERE `id_user_task` = 3; + +UPDATE `tuser_task_scheduled` SET + `id_user_task` = 3, + `args` = REPLACE (`args`, 'a:3', 'a:5'), + `args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:3;s:3:"XML";s:15:"first_execution"') + WHERE `id_user_task` = 6; -- ---------------------------------------------------------------------- -- ADD message in table 'tnews' @@ -3967,4 +3981,5 @@ SELECT `id_recon_script`,`type`, `name`, `description`, `script`, `macros` FROM DELETE FROM `tconfig` WHERE `token` = 'ipam_installed'; -DELETE FROM `tconfig` WHERE `token` = 'ipam_recon_script_id'; \ No newline at end of file +DELETE FROM `tconfig` WHERE `token` = 'ipam_recon_script_id'; + From 905f8801b7963c00d38ffff83a93fc6bc98298cb Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Jan 2021 13:37:20 +0100 Subject: [PATCH 5/5] Update 44.sql --- pandora_console/extras/mr/44.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/extras/mr/44.sql b/pandora_console/extras/mr/44.sql index ecb2280f48..aaa2202e56 100644 --- a/pandora_console/extras/mr/44.sql +++ b/pandora_console/extras/mr/44.sql @@ -150,7 +150,6 @@ UPDATE `tuser_task_scheduled` SET `args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:3;s:3:"XML";s:15:"first_execution"') WHERE `id_user_task` = 6; -COMMIT; ALTER TABLE `ttag` MODIFY COLUMN `name` text NOT NULL default ''; COMMIT;