2019-02-15 18:05:59 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Extension to schedule tasks on Pandora FMS Console
|
|
|
|
*
|
|
|
|
* @category Wizard
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Host&Devices
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
|
|
|
* Please see http://pandorafms.org for full contribution list
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation for version 2.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once __DIR__.'/Wizard.main.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_users.php';
|
2019-02-22 12:53:35 +01:00
|
|
|
require_once $config['homedir'].'/include/functions_reports.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_cron.php';
|
2019-02-15 18:05:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defined as wizard to guide user to explore running tasks.
|
|
|
|
*/
|
|
|
|
class DiscoveryTaskList extends Wizard
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param integer $page Start page, by default 0.
|
|
|
|
* @param string $msg Custom default mesage.
|
|
|
|
* @param string $icon Custom icon.
|
|
|
|
* @param string $label Custom label.
|
|
|
|
*
|
|
|
|
* @return class HostDevices
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
int $page=0,
|
|
|
|
string $msg='Default message. Not set.',
|
2019-02-21 13:05:48 +01:00
|
|
|
string $icon='images/wizard/tasklist.png',
|
2019-02-15 18:05:59 +01:00
|
|
|
string $label='Task list'
|
|
|
|
) {
|
|
|
|
$this->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()
|
|
|
|
{
|
2019-02-22 13:45:59 +01:00
|
|
|
global $config;
|
2019-02-15 18:05:59 +01:00
|
|
|
// Load styles.
|
|
|
|
parent::run();
|
2019-02-15 18:35:35 +01:00
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
$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();
|
|
|
|
}
|
2019-02-15 18:35:35 +01:00
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
$delete = (bool) get_parameter('delete', false);
|
|
|
|
if ($delete === true) {
|
2019-02-15 18:35:35 +01:00
|
|
|
return $this->deleteTask();
|
|
|
|
}
|
|
|
|
|
2019-02-22 13:45:59 +01:00
|
|
|
$ret = $this->showListConsoleTask();
|
|
|
|
$ret2 = $this->showList();
|
|
|
|
|
|
|
|
if ($ret === false && $ret2 === false) {
|
|
|
|
include_once $config['homedir'].'/general/firts_task/recon_view.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements load method.
|
|
|
|
*
|
|
|
|
* @return mixed Skeleton for button.
|
|
|
|
*/
|
|
|
|
public function load()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'icon' => $this->icon,
|
|
|
|
'label' => $this->label,
|
|
|
|
'url' => $this->url,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-15 18:35:35 +01:00
|
|
|
/**
|
|
|
|
* 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) {
|
2019-02-21 18:00:50 +01:00
|
|
|
$result = db_process_sql_delete(
|
2019-02-15 18:35:35 +01:00
|
|
|
'trecon_task',
|
|
|
|
['id_rt' => $task]
|
|
|
|
);
|
2019-02-21 18:00:50 +01:00
|
|
|
|
|
|
|
if ($result == 1) {
|
|
|
|
return [
|
|
|
|
'result' => 0,
|
|
|
|
'msg' => __('Task successfully deleted'),
|
|
|
|
'id' => false,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trick to avoid double execution.
|
|
|
|
header('Location: '.$this->url);
|
2019-02-15 18:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-15 18:05:59 +01:00
|
|
|
/**
|
|
|
|
* 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';
|
2019-02-15 18:35:35 +01:00
|
|
|
return false;
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 18:35:35 +01:00
|
|
|
// Get all recon servers.
|
2019-02-15 18:05:59 +01:00
|
|
|
$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'));
|
2019-02-15 18:35:35 +01:00
|
|
|
return false;
|
2019-02-15 18:05:59 +01:00
|
|
|
} else {
|
|
|
|
$recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task');
|
|
|
|
if ($recon_task === false) {
|
2019-02-15 18:35:35 +01:00
|
|
|
return false;
|
2019-02-15 18:05:59 +01:00
|
|
|
} 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);
|
2019-02-15 18:35:35 +01:00
|
|
|
header(
|
|
|
|
'Location: '.ui_get_full_url(
|
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist'
|
|
|
|
)
|
|
|
|
);
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($servers as $serverItem) {
|
|
|
|
$id_server = $serverItem['id_server'];
|
|
|
|
$server_name = servers_get_name($id_server);
|
2019-02-22 12:53:35 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 18:05:59 +01:00
|
|
|
|
2019-02-15 18:35:35 +01:00
|
|
|
// Show network tasks for Recon Server.
|
2019-02-15 18:05:59 +01:00
|
|
|
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';
|
|
|
|
|
2019-02-15 18:35:35 +01:00
|
|
|
$table->head[8] = __('Operations');
|
2019-02-15 18:05:59 +01:00
|
|
|
$table->align[8] = 'left';
|
|
|
|
|
|
|
|
foreach ($recon_tasks as $task) {
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
if ($task['disabled'] == 0) {
|
2019-02-15 18:35:35 +01:00
|
|
|
$data[0] = '<a href="'.ui_get_full_url(
|
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&server_id='.$id_server.'&force='.$task['id_rt']
|
|
|
|
).'">';
|
2019-02-15 18:05:59 +01:00
|
|
|
$data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} else {
|
|
|
|
$data[0] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[1] = '<b>'.$task['name'].'</b>';
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
$data[2] = human_time_description_raw(
|
|
|
|
$task['interval_sweep']
|
|
|
|
);
|
2019-02-15 18:05:59 +01:00
|
|
|
|
|
|
|
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) {
|
2019-02-15 18:35:35 +01:00
|
|
|
// Network recon task.
|
2019-02-22 12:53:35 +01:00
|
|
|
$data[5] = html_print_image(
|
|
|
|
'images/network.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Network recon task')]
|
|
|
|
).' ';
|
|
|
|
$data[5] .= network_profiles_get_name(
|
|
|
|
$task['id_network_profile']
|
|
|
|
);
|
2019-02-15 18:05:59 +01:00
|
|
|
} else {
|
2019-02-15 18:35:35 +01:00
|
|
|
// APP recon task.
|
2019-02-22 12:53:35 +01:00
|
|
|
$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']
|
|
|
|
)
|
|
|
|
);
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($task['status'] <= 0 || $task['status'] > 100) {
|
|
|
|
$data[6] = '-';
|
|
|
|
} else {
|
2019-02-22 12:53:35 +01:00
|
|
|
$data[6] = progress_bar(
|
|
|
|
$task['status'],
|
|
|
|
100,
|
|
|
|
20,
|
|
|
|
__('Progress').':'.$task['status'].'%',
|
|
|
|
1
|
|
|
|
);
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
$data[7] = ui_print_timestamp(
|
|
|
|
$task['utimestamp'],
|
|
|
|
true
|
|
|
|
);
|
2019-02-15 18:05:59 +01:00
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
if (check_acl(
|
|
|
|
$config['id_user'],
|
|
|
|
$task['id_group'],
|
|
|
|
'PM'
|
|
|
|
)
|
|
|
|
) {
|
2019-02-19 20:27:05 +01:00
|
|
|
// Check if is a H&D, Cloud or Application.
|
2019-02-15 18:05:59 +01:00
|
|
|
$data[8] = '<a href="'.ui_get_full_url(
|
2019-02-19 20:27:05 +01:00
|
|
|
sprintf(
|
2019-02-21 15:35:44 +01:00
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d',
|
2019-02-19 20:27:05 +01:00
|
|
|
$this->getTargetWiz($task),
|
|
|
|
$task['id_rt']
|
|
|
|
)
|
2019-02-15 18:05:59 +01:00
|
|
|
).'">'.html_print_image(
|
2019-02-22 12:53:35 +01:00
|
|
|
'images/config.png',
|
2019-02-15 18:05:59 +01:00
|
|
|
true
|
|
|
|
).'</a>';
|
2019-02-15 18:35:35 +01:00
|
|
|
$data[8] .= '<a href="'.ui_get_full_url(
|
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&delete=1&task='.$task['id_rt']
|
2019-02-22 12:53:35 +01:00
|
|
|
).'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'.html_print_image(
|
2019-02-15 18:35:35 +01:00
|
|
|
'images/cross.png',
|
|
|
|
true
|
|
|
|
).'</a>';
|
2019-02-15 18:05:59 +01:00
|
|
|
} else {
|
|
|
|
$data[8] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($table->data, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($table->data)) {
|
|
|
|
echo '<div class="nf">'.__('Server').' '.$server_name.' '.__('has no recon tasks assigned').'</div>';
|
|
|
|
} else {
|
2019-02-22 12:53:35 +01:00
|
|
|
echo '<h2>'.__('Server task').'</h2>';
|
2019-02-15 18:05:59 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-22 12:53:35 +01:00
|
|
|
/**
|
|
|
|
* 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 '<h2>'.__('Console task').'</h2>';
|
|
|
|
|
|
|
|
$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] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_console_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} 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] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id=".$args[0]."'>";
|
|
|
|
$data[2] .= $report['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Email').": <a href='mailto:".$email."'>";
|
|
|
|
$data[2] .= ui_print_truncate_text(
|
|
|
|
$email,
|
|
|
|
60,
|
|
|
|
false
|
|
|
|
).'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_generate_report_by_template':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_console_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} 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] .= '<br>- '.__('Template').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer";
|
|
|
|
$data[2] .= '&id='.$args[0]."'>".$template['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Agents').': '.$agents_id.'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Report per agent').': '.$report_per_agent.'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Report name').': '.$report_name.'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Email').": <a href='mailto:".$email."'>".$email.'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_execute_custom_script':
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_console_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} 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] .= '<br>- '.__('Custom script').': '.$args[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_save_report_to_disk':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_console_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} 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] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer";
|
|
|
|
$data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Path').': '.$path.'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_save_xml_report_to_disk':
|
|
|
|
if ($write_perms || $manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_console_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} 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] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer";
|
|
|
|
$data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>';
|
|
|
|
$data[2] .= '<br>- '.__('Path').': '.$path.'</a>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cron_task_do_backup':
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[0] = '<a href="'.$url;
|
|
|
|
$data[0] .= 'force_run=1&id_console_task='.$task['id'].'">';
|
|
|
|
$data[0] .= html_print_image(
|
|
|
|
'images/target.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Force run')]
|
|
|
|
);
|
|
|
|
$data[0] .= '</a>';
|
|
|
|
} 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) {
|
2019-02-22 13:45:59 +01:00
|
|
|
$data[7] = '<a href="'.ui_get_full_url(
|
|
|
|
sprintf(
|
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d',
|
|
|
|
$this->getTargetWiz(['description' => 'console_task']),
|
|
|
|
$task['id']
|
|
|
|
)
|
|
|
|
).'">';
|
2019-02-22 12:53:35 +01:00
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/config.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Edit')]
|
2019-02-22 13:45:59 +01:00
|
|
|
).'</a>';
|
2019-02-22 12:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($manage_pandora) {
|
|
|
|
$data[7] .= '<a href="'.$url;
|
|
|
|
$data[7] .= 'delete_console_task=1&id_console_task='.$task['id'].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
|
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/cross.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Delete')]
|
|
|
|
);
|
|
|
|
$data[7] .= '</a>';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($write_perms || $manage_pandora) {
|
2019-02-22 13:45:59 +01:00
|
|
|
$data[7] = '<a href="'.ui_get_full_url(
|
|
|
|
sprintf(
|
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d',
|
|
|
|
$this->getTargetWiz(['description' => 'console_task']),
|
|
|
|
$task['id']
|
|
|
|
)
|
|
|
|
).'">';
|
2019-02-22 12:53:35 +01:00
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/config.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Edit')]
|
2019-02-22 13:45:59 +01:00
|
|
|
).'</a>';
|
2019-02-22 12:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($manage_perms || $manage_pandora) {
|
|
|
|
$data[7] .= '<a href="'.$url;
|
|
|
|
$data[7] .= 'delete_console_task=1&id_console_task='.$task['id'].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
|
|
|
|
$data[7] .= html_print_image(
|
|
|
|
'images/cross.png',
|
|
|
|
true,
|
|
|
|
['title' => __('Delete')]
|
|
|
|
);
|
|
|
|
$data[7] .= '</a>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($table->data, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
html_print_table($table);
|
2019-02-22 13:45:59 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
2019-02-22 12:53:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-19 20:27:05 +01:00
|
|
|
/**
|
|
|
|
* 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':
|
2019-02-21 15:35:44 +01:00
|
|
|
return 'wiz=app&mode=vmware&page=0';
|
|
|
|
|
|
|
|
case CLOUDWIZARD_AWS_DESCRIPTION:
|
|
|
|
return 'wiz=cloud&mode=amazonws&page=1';
|
2019-02-19 20:27:05 +01:00
|
|
|
|
2019-02-22 13:45:59 +01:00
|
|
|
case 'console_task':
|
|
|
|
return 'wiz=ctask';
|
|
|
|
|
2019-02-19 20:27:05 +01:00
|
|
|
default:
|
|
|
|
return 'wiz=hd&mode=netscan';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|