From cc776ddbf7293b42b65a00ba4d6a2d89d96eb726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 23 Mar 2022 11:47:34 +0100 Subject: [PATCH 1/5] Added enable console task feature --- .../wizards/DiscoveryTaskList.class.php | 48 +++++++++++++++++++ pandora_console/pandoradb.sql | 1 + 2 files changed, 49 insertions(+) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index f4a10a3fbb..ba690e8ce6 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -133,6 +133,11 @@ class DiscoveryTaskList extends HTML return $this->deleteConsoleTask(); } + $toggle_console_task = (int) get_parameter('toggle_console_task', -1); + if ($toggle_console_task === 1 || $toggle_console_task === 0) { + return $this->toggleConsoleTask($toggle_console_task); + } + $delete = (bool) get_parameter('delete', false); if ($delete === true) { return $this->deleteTask(); @@ -321,6 +326,49 @@ class DiscoveryTaskList extends HTML } + /** + * Toggle enable/disable status of selected Console Task. + * + * @param integer $enable If 1 enable the console task. + * + * @return void + */ + public function toggleConsoleTask(int $enable) + { + global $config; + + if ((bool) check_acl($config['id_user'], 0, 'RM') === false) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Trying to access recon task viewer' + ); + include 'general/noaccess.php'; + return; + } + + $id_console_task = (int) get_parameter('id_console_task'); + + if ($id_console_task > 0) { + $result = db_process_sql_update( + 'tuser_task_scheduled', + ['enabled' => $enable], + ['id' => $id_console_task] + ); + + if ((int) $result === 1) { + return [ + 'result' => 0, + 'msg' => ((bool) $enable === true) ? __('Task successfully enabled') : __('Task succesfully disabled'), + 'id' => false, + ]; + } + + // Trick to avoid double execution. + header('Location: '.$this->url); + } + } + + /** * Delete a Console task. * diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index e9ef437992..fe1b9d6752 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3845,6 +3845,7 @@ CREATE TABLE IF NOT EXISTS `tuser_task_scheduled` ( `custom_data` INT NULL DEFAULT 0, `flag_delete` TINYINT UNSIGNED NOT NULL DEFAULT 0, `id_grupo` INT UNSIGNED NOT NULL DEFAULT 0, + `enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; From cae8290c77e9f05d3fe4cae0319103d4296c299d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Thu, 24 Mar 2022 14:20:20 +0100 Subject: [PATCH 2/5] Missed MR file --- pandora_console/extras/mr/53.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/extras/mr/53.sql b/pandora_console/extras/mr/53.sql index dfb7976a91..8e08c185dd 100644 --- a/pandora_console/extras/mr/53.sql +++ b/pandora_console/extras/mr/53.sql @@ -1,6 +1,7 @@ START TRANSACTION; ALTER TABLE `tipam_vlan` ADD COLUMN `custom_id` bigint(20) unsigned DEFAULT NULL; +ALTER TABLE `tuser_task_scheduled`ADD COLUMN `enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1;: UPDATE `tuser_task` SET `parameters` = 'a:3:{i:0;a:2:{s:11:"description";s:11:"Description";s:4:"type";s:4:"text";}i:1;a:3:{s:11:"description";s:20:"Save to disk in path";s:4:"type";s:6:"string";s:13:"default_value";s:21:"_%_ATTACHMENT_PATH_%_";}i:2;a:3:{s:11:"description";s:14:"Active backups";s:4:"type";s:6:"number";s:13:"default_value";i:3;}}' WHERE `function_name` = 'cron_task_do_backup'; From 187a633bae2a9bc4ace6ed467d250319a19d2bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= <79-jose.gonzalez@users.noreply.brutus.artica.es> Date: Fri, 25 Mar 2022 11:19:41 +0000 Subject: [PATCH 3/5] Fix mistake --- pandora_console/extras/mr/53.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/extras/mr/53.sql b/pandora_console/extras/mr/53.sql index 8e08c185dd..659cba316e 100644 --- a/pandora_console/extras/mr/53.sql +++ b/pandora_console/extras/mr/53.sql @@ -1,7 +1,7 @@ START TRANSACTION; ALTER TABLE `tipam_vlan` ADD COLUMN `custom_id` bigint(20) unsigned DEFAULT NULL; -ALTER TABLE `tuser_task_scheduled`ADD COLUMN `enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1;: +ALTER TABLE `tuser_task_scheduled`ADD COLUMN `enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1; UPDATE `tuser_task` SET `parameters` = 'a:3:{i:0;a:2:{s:11:"description";s:11:"Description";s:4:"type";s:4:"text";}i:1;a:3:{s:11:"description";s:20:"Save to disk in path";s:4:"type";s:6:"string";s:13:"default_value";s:21:"_%_ATTACHMENT_PATH_%_";}i:2;a:3:{s:11:"description";s:14:"Active backups";s:4:"type";s:6:"number";s:13:"default_value";i:3;}}' WHERE `function_name` = 'cron_task_do_backup'; From 18927108ef05b40c86f54dec99e3d437602a03a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 29 Mar 2022 14:44:12 +0200 Subject: [PATCH 4/5] Added in meta console task enable/disable feature --- pandora_console/include/functions_cron.php | 276 ++++++++++++++------- 1 file changed, 182 insertions(+), 94 deletions(-) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index bbbac884b5..bb0163f83f 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -1,23 +1,32 @@ '.__('Scheduled jobs').''; + echo '

'.__('Scheduled jobssss').'

'; $table = new stdClass(); $table->class = 'databox data'; @@ -474,17 +483,28 @@ function cron_list_table() case 'cron_task_generate_csv_log': case 'cron_task_call_user_function': // Ignore. - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, - [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] - ); - $data[0] .= ''; + if ((bool) $task['enabled'] === true) { + $data[0] = html_print_anchor( + [ + 'href' => sprintf( + '%sforce_run=1&id_console_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true + ); + } else { + $data[0] = ''; + } $data[1] = $task['id_usuario']; $data[2] = db_get_value( @@ -501,18 +521,25 @@ function cron_list_table() break; case 'cron_task_generate_report': - if ($write_perms || $manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true && ($write_perms === true || $manage_pandora === true)) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -549,18 +576,25 @@ function cron_list_table() break; case 'cron_task_generate_report_by_template': - if ($write_perms || $manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true && ($write_perms === true || $manage_pandora === true)) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -634,18 +668,25 @@ function cron_list_table() break; case 'cron_task_execute_custom_script': - if ($manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -663,18 +704,25 @@ function cron_list_table() break; case 'cron_task_save_report_to_disk': - if ($write_perms || $manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -702,18 +750,25 @@ function cron_list_table() break; case 'cron_task_save_xml_report_to_disk': - if ($write_perms || $manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true && ($write_perms === true || $manage_pandora === true)) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -734,22 +789,28 @@ function cron_list_table() $data[2] .= '&id='.$args[0]."'>".$report['name'].''; $data[2] .= '
- '.__('Path').': '.$path.''; $data[2] .= '
- '.__('Report type').': '.$report_type; - break; case 'cron_task_do_backup': - if ($manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true && $manage_pandora === true) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -765,18 +826,25 @@ function cron_list_table() break; case 'cron_task_generate_csv_log': - if ($manage_pandora) { - $data[0] = ''; - $data[0] .= html_print_image( - 'images/target.png', - true, + if ((bool) $task['enabled'] === true && $manage_pandora === true) { + $data[0] = html_print_anchor( [ - 'title' => __('Force run'), - 'class' => 'invert_filter', - ] + 'href' => sprintf( + '%sforce_run=1&id_user_task=%s', + $url, + $task['id'] + ), + 'content' => html_print_image( + 'images/target.png', + true, + [ + 'title' => __('Force run'), + 'class' => 'invert_filter', + ] + ), + ], + true ); - $data[0] .= ''; } else { $data[0] = ''; } @@ -860,6 +928,26 @@ function cron_list_table() } } + $data[7] .= html_print_anchor( + [ + 'href' => sprintf( + '%stoggle_console_task=%s&id_user_task=%s', + $url, + ((bool) $task['enabled'] === true) ? '0' : '1', + $task['id'] + ), + 'content' => html_print_image( + ((bool) $task['enabled'] === true) ? 'images/lightbulb.png' : 'images/lightbulb_off.png', + true, + [ + 'title' => ((bool) $task['enabled'] === true) ? __('Disable task') : __('Enable task'), + 'class' => 'invert_filter', + ] + ), + ], + true + ); + array_push($table->data, $data); } From 1e3355730b87bae7e4f2872487a834cf21bee3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 30 Mar 2022 09:19:04 +0200 Subject: [PATCH 5/5] Fix typo --- pandora_console/include/functions_cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index bb0163f83f..a311b7ec4a 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -452,7 +452,7 @@ function cron_list_table() } if ($defined_tasks !== false) { - echo '

'.__('Scheduled jobssss').'

'; + echo '

'.__('Scheduled jobs').'

'; $table = new stdClass(); $table->class = 'databox data';