Merge branch 'ent-8300-gestion-ejecucion-console-tasks' into 'develop'

Added enable console task feature

See merge request artica/pandorafms!4776
This commit is contained in:
Daniel Rodriguez 2022-03-30 09:29:22 +00:00
commit 134ee890eb
4 changed files with 231 additions and 93 deletions

View File

@ -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;
ALTER TABLE tagente MODIFY alias varchar(600) NOT NULL DEFAULT '';
ALTER TABLE tagente MODIFY nombre varchar(600) NOT NULL DEFAULT '';

View File

@ -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.
*

View File

@ -1,23 +1,32 @@
<?php
/**
* PHP Linux cron functions.
* Cron Functions.
*
* @package Linux cron functions.
* @subpackage Backend functions.
* @category Utils
* @package Pandora FMS Community
* @subpackage Cron
* @version 1.0.0
* @license See below
*
* Pandora FMS- http://pandorafms.com
* ==================================================
* Copyright (c) 20012 Artica Soluciones Tecnologicas
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2022 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 Lesser General Public License
* as published by the Free Software Foundation; version 2
* 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.
* ============================================================================
*/
// Begin.
global $config;
require_once $config['homedir'].'/include/functions_db.php';
@ -402,9 +411,9 @@ function cron_list_table()
global $config;
$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');
$write_perms = (bool) check_acl($config['id_user'], 0, 'RW');
$manage_perms = (bool) check_acl($config['id_user'], 0, 'RM');
$manage_pandora = (bool) check_acl($config['id_user'], 0, 'PM');
$url = 'index.php?extension_in_menu=gservers&sec=extensions&sec2=enterprise/extensions/cron&';
@ -474,17 +483,28 @@ function cron_list_table()
case 'cron_task_generate_csv_log':
case 'cron_task_call_user_function':
// Ignore.
$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'),
'class' => 'invert_filter',
]
);
$data[0] .= '</a>';
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] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} 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] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} else {
$data[0] = '';
}
@ -634,18 +668,25 @@ function cron_list_table()
break;
case 'cron_task_execute_custom_script':
if ($manage_pandora) {
$data[0] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} 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] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} 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] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} else {
$data[0] = '';
}
@ -734,22 +789,28 @@ function cron_list_table()
$data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>';
$data[2] .= '<br>- '.__('Path').': '.$path.'</a>';
$data[2] .= '<br>- '.__('Report type').': '.$report_type;
break;
case 'cron_task_do_backup':
if ($manage_pandora) {
$data[0] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} else {
$data[0] = '';
}
@ -765,18 +826,25 @@ function cron_list_table()
break;
case 'cron_task_generate_csv_log':
if ($manage_pandora) {
$data[0] = '<a href="'.$url;
$data[0] .= 'force_run=1&id_user_task='.$task['id'].'">';
$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] .= '</a>';
} 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);
}

View File

@ -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;