Merge branch 'ent-6839-Crear-llamadas-a-la-api-para-activar-o-parar-una-discovery-task' into 'develop'
Ent 6839 crear llamadas a la api para activar o parar una discovery task See merge request artica/pandorafms!3798
This commit is contained in:
commit
6c2a353812
|
@ -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] .= '<span class="link" onclick="progress_task_list('.$task['id_rt'].',\''.$task['name'].'\')">';
|
||||
}
|
||||
|
||||
$data[1] .= '<b>'.$task['name'].'</b>';
|
||||
if ($task['disabled'] == 1) {
|
||||
$data[1] .= '<b><em>'.$task['name'].'</em></b>';
|
||||
} else {
|
||||
$data[1] .= '<b>'.$task['name'].'</b>';
|
||||
}
|
||||
|
||||
if ($task['disabled'] != 2) {
|
||||
$data[1] .= '</span>';
|
||||
}
|
||||
|
@ -809,6 +911,24 @@ class DiscoveryTaskList extends HTML
|
|||
['title' => __('Delete task')]
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
if ($task['disabled'] == 1) {
|
||||
$data[9] .= '<a href="'.ui_get_full_url(
|
||||
'index.php?sec=gservers&sec2=godmode/servers/discovery&enabled=1&wiz=tasklist&task='.$task['id_rt']
|
||||
).'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'.html_print_image(
|
||||
'images/lightbulb_off.png',
|
||||
true,
|
||||
['title' => __('enable task')]
|
||||
).'</a>';
|
||||
} else if ($task['disabled'] == 0) {
|
||||
$data[9] .= '<a href="'.ui_get_full_url(
|
||||
'index.php?sec=gservers&sec2=godmode/servers/discovery&disabled=1&wiz=tasklist&task='.$task['id_rt']
|
||||
).'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'.html_print_image(
|
||||
'images/lightbulb.png',
|
||||
true,
|
||||
['title' => __('Disable task')]
|
||||
).'</a>';
|
||||
}
|
||||
} else {
|
||||
$data[9] = '';
|
||||
}
|
||||
|
|
|
@ -16536,3 +16536,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 <enable/disable value> in this order and separator char
|
||||
* (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<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.'),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue