setBreadcrum([]);
$this->task = [];
$this->msg = $msg;
$this->icon = $icon;
$this->label = __($label);
$this->page = $page;
$this->url = ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist'
);
return $this;
}
/**
* Implements run method.
*
* @return mixed Returns null if wizard is ongoing. Result if done.
*/
public function run()
{
global $config;
// Load styles.
parent::run();
$force_run = (bool) get_parameter('force_run');
if ($force_run === true) {
return $this->forceConsoleTask();
}
$delete_console_task = (bool) get_parameter('delete_console_task');
if ($delete_console_task === true) {
return $this->deleteConsoleTask();
}
$delete = (bool) get_parameter('delete', false);
if ($delete === true) {
return $this->deleteTask();
}
$ret = $this->showListConsoleTask();
$ret2 = $this->showList();
if ($ret === false && $ret2 === false) {
include_once $config['homedir'].'/general/firts_task/recon_view.php';
}
return $ret;
}
/**
* Implements load method.
*
* @return mixed Skeleton for button.
*/
public function load()
{
return [
'icon' => $this->icon,
'label' => $this->label,
'url' => $this->url,
];
}
/**
* Delete a recon task.
*
* @return void
*/
public function deleteTask()
{
global $config;
if (! check_acl($config['id_user'], 0, 'PM')) {
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_delete(
'trecon_task',
['id_rt' => $task]
);
if ($result == 1) {
return [
'result' => 0,
'msg' => __('Task successfully deleted'),
'id' => false,
];
}
// Trick to avoid double execution.
header('Location: '.$this->url);
}
}
/**
* Force console task.
*
* @return void
*/
public function forceConsoleTask()
{
global $config;
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
'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 !== null) {
cron_task_run($id_console_task, true);
// Trick to avoid double execution.
header('Location: '.$this->url);
}
}
/**
* Delete a Console task.
*
* @return void
*/
public function deleteConsoleTask()
{
global $config;
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
'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 !== null) {
$result = db_process_sql_delete(
'tuser_task_scheduled',
['id' => $id_console_task]
);
if ($result == 1) {
return [
'result' => 0,
'msg' => __('Console Task successfully deleted'),
'id' => false,
];
}
// Trick to avoid double execution.
header('Location: '.$this->url);
}
}
/**
* Show complete list of running tasks.
*
* @return boolean Success or not.
*/
public function showList()
{
global $config;
check_login();
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
'ACL Violation',
'Trying to access recon task viewer'
);
include 'general/noaccess.php';
return false;
}
// Get all recon servers.
$servers = db_get_all_rows_sql('SELECT * FROM tserver WHERE server_type = 3');
if ($servers === false) {
$servers = [];
ui_print_error_message(__('Discovery Server is disabled'));
return false;
} else {
$recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task');
if ($recon_task === false) {
return false;
} else {
include_once $config['homedir'].'/include/functions_graph.php';
include_once $config['homedir'].'/include/functions_servers.php';
include_once $config['homedir'].'/include/functions_network_profiles.php';
$modules_server = 0;
$total_modules = 0;
$total_modules_data = 0;
// --------------------------------
// FORCE A RECON TASK
// --------------------------------
if (check_acl($config['id_user'], 0, 'PM')) {
if (isset($_GET['force'])) {
$id = (int) get_parameter_get('force', 0);
servers_force_recon_task($id);
header(
'Location: '.ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist'
)
);
}
}
foreach ($servers as $serverItem) {
$id_server = $serverItem['id_server'];
$server_name = servers_get_name($id_server);
$recon_tasks = db_get_all_rows_field_filter(
'trecon_task',
'id_recon_server',
$id_server
);
$user_groups = implode(',', array_keys(users_get_groups()));
$defined_tasks = db_get_all_rows_filter(
'tuser_task_scheduled',
'id_grupo IN ('.$user_groups.')'
);
if (isset($tasks_console) === true
&& is_array($tasks_console) === true
) {
foreach ($tasks_console as $key => $value) {
$value['parameters'] = unserialize(
$value['parameters']
);
$value['type'] = 'Cron';
array_push($recon_tasks, $value);
}
}
// Show network tasks for Recon Server.
if ($recon_tasks === false) {
$recon_tasks = [];
}
$table = new StdClass();
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->width = '100%';
$table->class = 'databox data';
$table->head = [];
$table->data = [];
$table->align = [];
$table->headstyle = [];
for ($i = 0; $i < 9; $i++) {
$table->headstyle[$i] = 'text-align: left;';
}
$table->head[0] = __('Force');
$table->align[0] = 'left';
$table->head[1] = __('Task name');
$table->align[1] = 'left';
$table->head[2] = __('Interval');
$table->align[2] = 'left';
$table->head[3] = __('Network');
$table->align[3] = 'left';
$table->head[4] = __('Status');
$table->align[4] = 'left';
$table->head[5] = __('Template');
$table->align[5] = 'left';
$table->head[6] = __('Progress');
$table->align[6] = 'left';
$table->head[7] = __('Updated at');
$table->align[7] = 'left';
$table->head[8] = __('Operations');
$table->align[8] = 'left';
foreach ($recon_tasks as $task) {
$data = [];
if ($task['disabled'] == 0) {
$data[0] = '';
$data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]);
$data[0] .= '';
} else {
$data[0] = '';
}
$data[1] = ''.$task['name'].'';
$data[2] = human_time_description_raw(
$task['interval_sweep']
);
if ($task['id_recon_script'] == 0) {
$data[3] = $task['subnet'];
} else {
$data[3] = '-';
}
if ($task['status'] <= 0) {
$data[4] = __('Done');
} else {
$data[4] = __('Pending');
}
if ($task['id_recon_script'] == 0) {
// Network recon task.
$data[5] = html_print_image(
'images/network.png',
true,
['title' => __('Network recon task')]
).' ';
$data[5] .= network_profiles_get_name(
$task['id_network_profile']
);
} else {
// APP recon task.
$data[5] = html_print_image(
'images/plugin.png',
true
).' ';
$data[5] .= db_get_sql(
sprintf(
'SELECT name FROM trecon_script WHERE id_recon_script = %d',
$task['id_recon_script']
)
);
}
if ($task['status'] <= 0 || $task['status'] > 100) {
$data[6] = '-';
} else {
$data[6] = progress_bar(
$task['status'],
100,
20,
__('Progress').':'.$task['status'].'%',
1
);
}
$data[7] = ui_print_timestamp(
$task['utimestamp'],
true
);
if (check_acl(
$config['id_user'],
$task['id_group'],
'PM'
)
) {
// Check if is a H&D, Cloud or Application.
$data[8] = ''.html_print_image(
'images/config.png',
true
).'';
$data[8] .= ''.html_print_image(
'images/cross.png',
true
).'';
} else {
$data[8] = '';
}
array_push($table->data, $data);
}
if (empty($table->data)) {
echo '
'.__('Server').' '.$server_name.' '.__('has no recon tasks assigned').'
';
} else {
echo ''.__('Server task').'
';
html_print_table($table);
}
unset($table);
}
}
}
$form = [
'form' => [
'method' => 'POST',
'action' => ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery'
),
],
'inputs' => [
[
'arguments' => [
'name' => 'submit',
'label' => __('Go back'),
'type' => 'submit',
'attributes' => 'class="sub cancel"',
'return' => true,
],
],
],
];
$this->printForm($form);
return true;
}
/**
* Show complete list of running tasks.
*
* @return boolean Success or not.
*/
public function showListConsoleTask()
{
global $config;
check_login();
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
'ACL Violation',
'Trying to access recon task viewer'
);
include 'general/noaccess.php';
return false;
}
$read_perms = check_acl(
$config['id_user'],
0,
'RR'
);
$write_perms = check_acl(
$config['id_user'],
0,
'RW'
);
$manage_perms = check_acl(
$config['id_user'],
0,
'RM'
);
$manage_pandora = check_acl(
$config['id_user'],
0,
'PM'
);
$url = 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&';
$user_groups = implode(
',',
array_keys(users_get_groups())
);
$defined_tasks = db_get_all_rows_filter(
'tuser_task_scheduled',
'id_grupo IN ('.$user_groups.')'
);
if (!check_acl($config['id_user'], 0, 'PM')) {
$read_tasks = [];
foreach ($defined_tasks as $task) {
$function_name = db_get_value(
'function_name',
'tuser_task',
'id',
$task['id_user_task']
);
if (($function_name != 'cron_task_execute_custom_script')
&& ($function_name != 'cron_task_do_backup')
) {
$read_tasks[] = $task;
}
}
$defined_tasks = $read_tasks;
if (empty($defined_tasks)) {
$defined_tasks = false;
}
}
if ($defined_tasks !== false) {
echo ''.__('Console task').'
';
$table = new stdClass();
$table->class = 'databox data';
$table->width = '100%';
$table->data = [];
$table->head = [];
$table->head[0] = '';
$table->head[1] = __('User');
$table->head[2] = __('Task');
$table->head[3] = __('Scheduled');
$table->head[4] = __('Next execution');
$table->head[5] = __('Last run');
$table->head[6] = __('Group');
$table->head[7] = __('Operations');
$table->align[7] = 'left';
foreach ($defined_tasks as $task) {
$data = [];
$function_name = db_get_value(
'function_name',
'tuser_task',
'id',
$task['id_user_task']
);
switch ($function_name) {
case 'cron_task_generate_report':
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']);
$report = reports_get_report($args[0]);
// Check ACL in reports_get_report return false.
if ($report === false) {
continue;
}
$email = $args[1];
$data[2] .= '
- '.__('Report').": ";
$data[2] .= $report['name'].'';
$data[2] .= '
- '.__('Email').": ";
$data[2] .= ui_print_truncate_text(
$email,
60,
false
).'';
break;
case 'cron_task_generate_report_by_template':
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']);
$filter = [];
$filter['id_report'] = $args[0];
$template = db_get_row_filter(
'treport_template',
$filter,
false
);
// Check ACL in reports_get_report return false.
if ($template === false) {
continue;
}
$agents_id = $args[1];
$id_group = $args[2];
$report_per_agent = $args[0];
$report_name = $args[3];
$email = $args[4];
$data[2] .= '
- '.__('Template').": ".$template['name'].'';
$data[2] .= '
- '.__('Agents').': '.$agents_id.'';
$data[2] .= '
- '.__('Report per agent').': '.$report_per_agent.'';
$data[2] .= '
- '.__('Report name').': '.$report_name.'';
$data[2] .= '
- '.__('Email').": ".$email.'';
break;
case 'cron_task_execute_custom_script':
if ($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']);
$data[2] .= '
- '.__('Custom script').': '.$args[0];
break;
case 'cron_task_save_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']);
$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':
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']);
$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_do_backup':
if ($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']);
break;
default:
// Ignore.
break;
}
$data[3] = cron_get_scheduled_string($task['scheduled']);
$data[4] = date('Y/m/d H:i:s', $args['first_execution']);
$data[5] = empty($task['last_run']) ? __('Never') : date('Y/m/d H:i:s', $task['last_run']);
$data[6] = ui_print_group_icon($task['id_grupo'], true);
if ($function_name == 'cron_task_do_backup' || $function_name == 'cron_task_execute_custom_script') {
if ($manage_pandora) {
$data[7] = '';
$data[7] .= html_print_image(
'images/config.png',
true,
['title' => __('Edit')]
).'';
}
if ($manage_pandora) {
$data[7] .= '';
$data[7] .= html_print_image(
'images/cross.png',
true,
['title' => __('Delete')]
);
$data[7] .= '';
}
} else {
if ($write_perms || $manage_pandora) {
$data[7] = '';
$data[7] .= html_print_image(
'images/config.png',
true,
['title' => __('Edit')]
).'';
}
if ($manage_perms || $manage_pandora) {
$data[7] .= '';
$data[7] .= html_print_image(
'images/cross.png',
true,
['title' => __('Delete')]
);
$data[7] .= '';
}
}
array_push($table->data, $data);
}
html_print_table($table);
} else {
return false;
}
return true;
}
/**
* Return target url sub-string to edit target task.
*
* @param array $task With all data.
*
* @return string
*/
public function getTargetWiz($task)
{
// TODO: Do not use description. Use recon_script ID instead.
switch ($task['description']) {
case 'Discovery.Application.VMware':
return 'wiz=app&mode=vmware&page=0';
case CLOUDWIZARD_AWS_DESCRIPTION:
return 'wiz=cloud&mode=amazonws&page=1';
case 'console_task':
return 'wiz=ctask';
default:
return 'wiz=hd&mode=netscan';
}
}
}