diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 1dfc7063e7..33009263d3 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -138,6 +138,16 @@ class DiscoveryTaskList extends HTML return $this->deleteTask(); } + $disable = (bool) get_parameter('disabled', false); + if ($disable === true) { + return $this->disableTask(); + } + + $enable = (bool) get_parameter('enabled', false); + if ($enable === true) { + return $this->enableTask(); + } + if (enterprise_installed()) { // This check only applies to enterprise users. enterprise_hook('tasklist_checkrunning'); @@ -351,6 +361,93 @@ class DiscoveryTaskList extends HTML } + /** + * Disable a recon task. + * + * @return void + */ + public function disableTask() + { + global $config; + + if (! check_acl($config['id_user'], 0, 'AW')) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access recon task viewer' + ); + include 'general/noaccess.php'; + return; + } + + $task = get_parameter('task', null); + + if ($task !== null) { + $result = db_process_sql_update( + 'trecon_task', + ['disabled' => 1], + ['id_rt' => $task] + ); + + if ($result == 1) { + return [ + 'result' => 0, + 'msg' => __('Task successfully disabled'), + 'id' => false, + ]; + } + + // Trick to avoid double execution. + header('Location: '.$this->url); + } + + } + + + /** + * Enable a recon task. + * + * @return void + */ + public function enableTask() + { + global $config; + + if (! check_acl($config['id_user'], 0, 'AW')) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access recon task viewer' + ); + include 'general/noaccess.php'; + return; + } + + $task = get_parameter('task', null); + + if ($task !== null) { + $result = db_process_sql_update( + 'trecon_task', + [ + 'disabled' => 0, + 'status' => 0, + ], + ['id_rt' => $task] + ); + + if ($result == 1) { + return [ + 'result' => 0, + 'msg' => __('Task successfully enabled'), + 'id' => false, + ]; + } + + // Trick to avoid double execution. + header('Location: '.$this->url); + } + + } + + /** * Show complete list of running tasks. * @@ -522,7 +619,12 @@ class DiscoveryTaskList extends HTML $data[1] .= ''; } - $data[1] .= ''.$task['name'].''; + if ($task['disabled'] == 1) { + $data[1] .= ''.$task['name'].''; + } else { + $data[1] .= ''.$task['name'].''; + } + if ($task['disabled'] != 2) { $data[1] .= ''; } @@ -799,6 +901,24 @@ class DiscoveryTaskList extends HTML ['title' => __('Delete task')] ).''; } + + if ($task['disabled'] == 1) { + $data[9] .= ''.html_print_image( + 'images/lightbulb_off.png', + true, + ['title' => __('enable task')] + ).''; + } else if ($task['disabled'] == 0) { + $data[9] .= ''.html_print_image( + 'images/lightbulb.png', + true, + ['title' => __('Disable task')] + ).''; + } } else { $data[9] = ''; } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 1afd3f8431..0eb3679607 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -16393,3 +16393,95 @@ function api_set_event_in_progress($event_id, $trash2, $returnType) returnError('id_not_found', 'string'); } } + + +/** + * Enable/Disable discovery task. + * + * @param string $id_task Integer discovery task ID + * @param $thrash2 not used. + * @param array $other it's array, $other as param is in this order and separator char + * (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) + * example: + * + * example 1 (Enable) + * + * api.php?op=set&op2=enable_disable_discovery_task&id=1&other=0&other_mode=url_encode_separator_| + * + * example 2 (Disable) + * + * api.php?op=set&op2=enable_disable_discovery_task&id=1&other=1&other_mode=url_encode_separator_| + * + * http://localhost/pandora_console/include/api.php?op=set&op2=enable_disable_discovery_task&id=1&other=1&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora + */ +function api_set_enable_disable_discovery_task($id_task, $thrash2, $other) +{ + global $config; + + if (defined('METACONSOLE')) { + return; + } + + if (!check_acl($config['id_user'], 0, 'AW')) { + returnError('forbidden', 'string'); + return; + } + + if ($id_task == '') { + returnError( + 'error_enable_disable_discovery_task', + __('Error enable/disable discovery task. Id_user cannot be left blank.') + ); + return; + } + + if ($other['data'][0] != '0' and $other['data'][0] != '1') { + returnError( + 'error_enable_disable_discovery_task', + __('Error enable/disable discovery task. Enable/disable value cannot be left blank.') + ); + return; + } + + if ($other['data'][0] == '0') { + $result = db_process_sql_update( + 'trecon_task', + [ + 'disabled' => $other['data'][0], + 'status' => 0, + ], + ['id_rt' => $id_task] + ); + } else { + $result = db_process_sql_update( + 'trecon_task', + ['disabled' => $other['data'][0]], + ['id_rt' => $id_task] + ); + } + + if (is_error($result)) { + returnError( + 'error_enable_disable_discovery_task', + __('Error in discovery task enabling/disabling.') + ); + } else { + if ($other['data'][0] == '0') { + returnData( + 'string', + [ + 'type' => 'string', + 'data' => __('Enabled discovery task.'), + ] + ); + } else { + returnData( + 'string', + [ + 'type' => 'string', + 'data' => __('Disabled discovery task.'), + ] + ); + } + } +}