Merge branch 'ent-1959-cron-supervisor-de-estado' into 'ent-3430-discovery'

Ent 1959 cron supervisor de estado

See merge request artica/pandorafms!2159

Former-commit-id: 806a9b9d0d26010eb98f59eaca8860d237cf13d8
This commit is contained in:
fbsanchez 2019-02-12 11:59:23 +01:00
commit 54248661cf
22 changed files with 4340 additions and 709 deletions

View File

@ -1868,3 +1868,111 @@ CREATE TABLE IF NOT EXISTS `tgis_map_layer_groups` (
FOREIGN KEY (`group_id`) REFERENCES `tgrupo` (`id_grupo`) ON DELETE CASCADE,
FOREIGN KEY (`agent_id`) REFERENCES `tagente` (`id_agente`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tnotification_source`
-- -----------------------------------------------------
CREATE TABLE `tnotification_source` (
`id` serial,
`description` VARCHAR(255) DEFAULT NULL,
`icon` text,
`max_postpone_time` int(11) DEFAULT NULL,
`enabled` int(1) DEFAULT NULL,
`user_editable` int(1) DEFAULT NULL,
`also_mail` int(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tnotification_source`
--
INSERT INTO `tnotification_source`(`description`, `icon`, `max_postpone_time`, `enabled`, `user_editable`, `also_mail`) VALUES
("System status", "icono_info_mr.png", 86400, 1, 1, 0),
("Message", "icono_info_mr.png", 86400, 1, 1, 0),
("Pending task", "icono_info_mr.png", 86400, 1, 1, 0),
("Advertisement", "icono_info_mr.png", 86400, 1, 1, 0),
("Official communication", "icono_info_mr.png", 86400, 1, 1, 0),
("Sugerence", "icono_info_mr.png", 86400, 1, 1, 0);
-- -----------------------------------------------------
-- Table `tmensajes`
-- -----------------------------------------------------
ALTER TABLE `tmensajes` ADD COLUMN `url` TEXT;
ALTER TABLE `tmensajes` ADD COLUMN `response_mode` VARCHAR(200) DEFAULT NULL;
ALTER TABLE `tmensajes` ADD COLUMN `citicity` INT(10) UNSIGNED DEFAULT '0';
ALTER TABLE `tmensajes` ADD COLUMN `id_source` BIGINT(20) UNSIGNED NOT NULL;
ALTER TABLE `tmensajes` ADD COLUMN `subtype` VARCHAR(255) DEFAULT '';
ALTER TABLE `tmensajes` ADD CONSTRAINT `tsource_fk` FOREIGN KEY (`id_source`) REFERENCES `tnotification_source` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-- ----------------------------------------------------------------------
-- Table `tnotification_user`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_user` (
`id_mensaje` INT(10) UNSIGNED NOT NULL,
`id_user` VARCHAR(60) NOT NULL,
`utimestamp_read` BIGINT(20),
`utimestamp_erased` BIGINT(20),
`postpone` INT,
PRIMARY KEY (`id_mensaje`,`id_user`),
FOREIGN KEY (`id_mensaje`) REFERENCES `tmensajes`(`id_mensaje`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_user`) REFERENCES `tusuario`(`id_user`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_group`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_group` (
`id_mensaje` INT(10) UNSIGNED NOT NULL,
`id_group` mediumint(4) UNSIGNED NOT NULL,
PRIMARY KEY (`id_mensaje`,`id_group`),
FOREIGN KEY (`id_mensaje`) REFERENCES `tmensajes`(`id_mensaje`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_source_user`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_source_user` (
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`id_user` VARCHAR(60),
`enabled` INT(1) DEFAULT NULL,
`also_mail` INT(1) DEFAULT NULL,
PRIMARY KEY (`id_source`,`id_user`),
FOREIGN KEY (`id_source`) REFERENCES `tnotification_source`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_user`) REFERENCES `tusuario`(`id_user`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_source_group`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_source_group` (
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`id_group` mediumint(4) unsigned NOT NULL,
PRIMARY KEY (`id_source`,`id_group`),
INDEX (`id_group`),
FOREIGN KEY (`id_source`) REFERENCES `tnotification_source`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_source_user`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_source_group_user` (
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`id_group` mediumint(4) unsigned NOT NULL,
`id_user` VARCHAR(60),
`enabled` INT(1) DEFAULT NULL,
`also_mail` INT(1) DEFAULT NULL,
PRIMARY KEY (`id_source`,`id_user`),
FOREIGN KEY (`id_source`) REFERENCES `tnotification_source`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_user`) REFERENCES `tusuario`(`id_user`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_group`) REFERENCES `tnotification_source_group`(`id_group`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -57,7 +57,7 @@ config_check();
$table->cellspacing = 0;
$table->head = [];
$table->data = [];
$table->style[0] = $table->style['clippy'] = $table->style[1] = $table->style[3] = $table->style[4] = $table->style[5] = $table->style[6] = $table->style[8] = $table->style[9] = $table->style['qr'] = 'width: 22px; text-align:center; height: 22px; padding-right: 9px;padding-left: 9px;';
$table->style[0] = $table->style['clippy'] = $table->style[1] = $table->style[3] = $table->style[4] = $table->style[5] = $table->style[6] = $table->style[8] = $table->style[9] = $table->style['qr'] = $table->style['notifications'] = 'width: 22px; text-align:center; height: 22px; padding-right: 9px;padding-left: 9px;';
$table->style[7] = 'width: 20px; padding-right: 9px;';
$table->style['searchbar'] = 'width: 180px; min-width: 180px;';
$table->style[11] = 'padding-left: 10px; padding-right: 5px;width: 16px;';
@ -254,21 +254,8 @@ config_check();
$table->data[0][1] = $autorefresh_link_open_img.$autorefresh_img.$autorefresh_link_close;
$table->data[0][2] = $autorefresh_link_open_txt.$autorefresh_txt.$autorefresh_link_close.$autorefresh_additional;
// ======================================================
$check_minor_release_available = false;
$pandora_management = check_acl($config['id_user'], 0, 'PM');
$check_minor_release_available = db_check_minor_relase_available();
if ($check_minor_release_available) {
if (users_is_admin($config['id_user'])) {
if ($config['language'] == 'es') {
set_pandora_error_for_header('Hay una o mas revisiones menores en espera para ser actualizadas. <a style="font-size:8pt;font-style:italic;" target="blank" href="http://wiki.pandorafms.com/index.php?title=Pandora:Documentation_es:Actualizacion#Versi.C3.B3n_7.0NG_.28_Rolling_Release_.29">'.__('Sobre actualización de revisión menor').'</a>', 'Revisión/es menor/es disponible/s');
} else {
set_pandora_error_for_header('There are one or more minor releases waiting for update. <a style="font-size:8pt;font-style:italic;" target="blank" href="http://wiki.pandorafms.com/index.php?title=Pandora:Documentation_en:Anexo_Upgrade#Version_7.0NG_.28_Rolling_Release_.29">'.__('About minor release update').'</a>', 'minor release/s available');
}
}
}
echo '<div id="alert_messages" style="display: none"></div>';
if ($config['alert_cnt'] > 0) {
@ -351,7 +338,7 @@ config_check();
$table->data[0][9] .= '</a>';
}
$table->data[0]['notifications'] = notifications_print_ball();
html_print_table($table);

View File

@ -0,0 +1,271 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// 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.
// Warning: This file may be required into the metaconsole's setup
// Load global vars
global $config;
require_once $config['homedir'].'/include/functions_notifications.php';
check_login();
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
db_pandora_audit('ACL Violation', 'Trying to access Setup Management');
include 'general/noaccess.php';
return;
}
// AJAX actions.
$source_id = get_parameter('source_id', '');
$users = get_parameter('users', '');
$elements = get_parameter('elements', []);
$id = empty($source_id) ? 0 : get_notification_source_id($source_id);
$is_users = $users === 'users';
if (get_parameter('get_selection_two_ways_form', 0)) {
$info_selec = $is_users ? notifications_get_user_source_not_configured($id) : notifications_get_group_source_not_configured($id);
echo notifications_print_two_ways_select(
$info_selec,
$users,
$source_id
);
return;
}
if (get_parameter('add_source_to_database', 0)) {
$res = $is_users ? notifications_add_users_to_source($id, $elements) : notifications_add_group_to_source($id, $elements);
$result = ['result' => $res];
echo json_encode($result);
return;
}
if (get_parameter('remove_source_on_database', 0)) {
$res = $is_users ? notifications_remove_users_from_source($id, $elements) : notifications_remove_group_from_source($id, $elements);
$result = ['result' => $res];
echo json_encode($result);
return;
}
// Form actions.
if (get_parameter('update_config', 0)) {
$res_global = array_reduce(
notifications_get_all_sources(),
function ($carry, $source) {
$id = notifications_desc_to_id($source['description']);
if (empty($id)) {
return false;
}
$enable_value = switch_to_int(get_parameter("enable-$id"));
$mail_value = (int) get_parameter("mail-{$id}", 0);
$user_value = (int) get_parameter("user-{$id}", 0);
$postpone_value = (int) get_parameter("postpone-{$id}", 0);
$all_users = (int) get_parameter("all-{$id}", 0);
$res = db_process_sql_update(
'tnotification_source',
[
'enabled' => $enable_value,
'user_editable' => $user_value,
'also_mail' => $mail_value,
'max_postpone_time' => $postpone_value,
],
['id' => $source['id']]
);
$all_users_res = $all_users ? notifications_add_group_to_source($source['id'], [0]) : notifications_remove_group_from_source($source['id'], [0]);
return $all_users_res && $res && $carry;
},
true
);
}
// Notification table. It is just a wrapper.
$table_content = new StdClass();
$table_content->data = [];
$table_content->width = '100%';
$table_content->id = 'notifications-wrapper';
$table_content->class = 'databox filters';
$table_content->size['name'] = '30%';
// Print each source configuration
$table_content->data = array_map(
function ($source) {
return notifications_print_global_source_configuration($source);
},
notifications_get_all_sources()
);
$table_content->data[] = html_print_submit_button(
__('Update'),
'update_button',
false,
'class="sub upd" style="display: flex; "',
true
);
echo '<form id="form_enable" method="post">';
html_print_input_hidden('update_config', 1);
html_print_table($table_content);
echo '</form>';
?>
<script>
// Get the source id
function notifications_get_source_id(id) {
var matched = id.match(/.*-(.*)/);
if (matched == null) return '';
return matched[1];
}
// Get index of two ways element dialog.
function notifications_two_ways_element_get_dialog (id, source_id) {
return 'global_config_notifications_dialog_add-' + id + '-' + source_id;
}
// Get index of two ways element form.
function notifications_two_ways_element_get_sufix (id, source_id) {
return 'multi-' + id + '-' + source_id;
}
// Disable or enable the select seeing the checked value of notify all users
function notifications_disable_source(event) {
var id = notifications_get_source_id(event.target.id);
var is_checked = document.getElementById(event.target.id).checked;
var selectors = ['groups', 'users'];
selectors.map(function (select) {
document.getElementById(notifications_two_ways_element_get_sufix(select, id)).disabled = is_checked;
});
}
// Open a dialog with selector of source elements.
function add_source_dialog(users, source_id) {
// Display the dialog
var dialog_id = notifications_two_ways_element_get_dialog(users, source_id);
// Clean id element.
var previous_dialog = document.getElementById(dialog_id);
if (previous_dialog !== null) previous_dialog.remove();
// Create or recreate the content.
var not_dialog = document.createElement('div');
not_dialog.setAttribute('class', 'global_config_notifications_dialog_add_wrapper');
not_dialog.setAttribute('id', dialog_id);
document.body.appendChild(not_dialog);
$("#" + dialog_id).dialog({
resizable: false,
draggable: true,
modal: true,
dialogClass: "global_config_notifications_dialog_add_full",
overlay: {
opacity: 0.5,
background: "black"
},
closeOnEscape: true,
modal: true
});
jQuery.post ("ajax.php",
{"page" : "godmode/setup/setup_notifications",
"get_selection_two_ways_form" : 1,
"users" : users,
"source_id" : source_id
},
function (data, status) {
not_dialog.innerHTML = data
},
"html"
);
}
// Move from selected and not selected source elements.
function notifications_modify_two_ways_element (id, source_id, operation) {
var index_sufix = notifications_two_ways_element_get_sufix (id, source_id);
var start_id = operation === 'add' ? 'all-' : 'selected-';
var end_id = operation !== 'add' ? 'all-' : 'selected-';
var select = document.getElementById(
start_id + index_sufix
);
var select_end = document.getElementById(
end_id + index_sufix
);
for (var i = select.options.length - 1; i >= 0; i--) {
if(select.options[i].selected){
select_end.appendChild(select.options[i]);
}
}
}
// Add elements to database and close dialog
function notifications_add_source_element_to_database(id, source_id) {
var index = 'selected-' + notifications_two_ways_element_get_sufix (id, source_id);
var select = document.getElementById(index);
var selected = [];
for (var i = select.options.length - 1; i >= 0; i--) {
selected.push(select.options[i].value);
}
jQuery.post ("ajax.php",
{"page" : "godmode/setup/setup_notifications",
"add_source_to_database" : 1,
"users" : id,
"source_id" : source_id,
"elements": selected
},
function (data, status) {
if (data.result) {
// Append to other element
var out_select = document.getElementById(
notifications_two_ways_element_get_sufix(id, source_id)
);
for (var i = select.options.length - 1; i >= 0; i--) {
out_select.appendChild(select.options[i]);
}
// Close the dialog
$("#" + notifications_two_ways_element_get_dialog(id, source_id)).dialog("close");
} else {
console.log("Cannot update element.");
}
},
"json"
);
}
// Add elements to database and remove it form main select
function remove_source_elements(id, source_id) {
var index = notifications_two_ways_element_get_sufix(id, source_id);
var select = document.getElementById(index);
var selected = [];
var selected_index = [];
for (var i = select.options.length - 1; i >= 0; i--) {
if(select.options[i].selected){
selected.push(select.options[i].value);
selected_index.push(i);
}
}
jQuery.post ("ajax.php",
{"page" : "godmode/setup/setup_notifications",
"remove_source_on_database" : 1,
"users" : id,
"source_id" : source_id,
"elements": selected
},
function (data, status) {
if (data.result) {
// Append to other element
for (var i = selected_index.length - 1; i >= 0; i--) {
select.remove(selected_index[i]);
}
} else {
console.log("Cannot delete elements.");
}
},
"json"
);
}
</script>

File diff suppressed because it is too large Load Diff

View File

@ -1,47 +1,57 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2012 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
// 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.
/**
* @package Include
* @subpackage Constants
* Constants definitions.
*
* @category Library
* @package Pandora FMS
* @subpackage Opensource
* @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.
* ============================================================================
*/
// Enterprise hook constant
// Enterprise hook constant.
define('ENTERPRISE_NOT_HOOK', -1);
// Others
// Others.
define('GROUP_ALL', 0);
// Date and time formats
// Date and time formats.
define('DATE_FORMAT', 'Y/m/d');
define('DATE_FORMAT_JS', 'yy/mm/dd');
define('TIME_FORMAT', 'H:i:s');
define('TIME_FORMAT_JS', 'HH:mm:ss');
// Events state constants
// Events state constants.
define('EVENT_NEW', 0);
define('EVENT_VALIDATE', 1);
define('EVENT_PROCESS', 2);
// Agents disabled status
// Agents disabled status.
define('AGENT_ENABLED', 0);
define('AGENT_DISABLED', 1);
// Error report codes
// Error report codes.
define('NOERR', 11111);
define('ERR_GENERIC', -10000);
define('ERR_EXIST', -20000);
@ -61,12 +71,12 @@ define('ERR_ACL', -110000);
define('ERR_AUTH', -120000);
define('ERR_COULDNT_RESOLVE_HOST', -130000);
// Event status code
// Event status code.
define('EVENT_STATUS_NEW', 0);
define('EVENT_STATUS_INPROCESS', 2);
define('EVENT_STATUS_VALIDATED', 1);
// Seconds in a time unit constants
// Seconds in a time unit constants.
define('SECONDS_1MINUTE', 60);
define('SECONDS_2MINUTES', 120);
define('SECONDS_5MINUTES', 300);
@ -97,16 +107,16 @@ define('SECONDS_3YEARS', 93312000);
// Separator constats
// Separator constats.
define('SEPARATOR_COLUMN', ';');
define('SEPARATOR_ROW', chr(10));
// chr(10) = '\n'
// Chr(10) is \n.
define('SEPARATOR_COLUMN_CSV', '#');
define('SEPARATOR_ROW_CSV', "@\n");
// Backup paths
// Backup paths.
switch ($config['dbtype']) {
case 'mysql':
case 'postgresql':
@ -118,11 +128,15 @@ switch ($config['dbtype']) {
define('BACKUP_DIR', 'DATA_PUMP_DIR');
define('BACKUP_FULLPATH', 'DATA_PUMP_DIR');
break;
default:
// Ignore.
break;
}
// Color constants
// Color constants.
define('COL_CRITICAL', '#FC4444');
define('COL_WARNING', '#FAD403');
define('COL_WARNING_DARK', '#FFB900');
@ -152,14 +166,13 @@ define('COL_GRAPH12', '#F45B95');
define('COL_GRAPH13', '#E83128');
/*
The styles */
// Size of text in characters for truncate
// Styles.
// Size of text in characters for truncate.
define('GENERIC_SIZE_TEXT', 50);
// Agent module status
// Agent module status.
define('AGENT_MODULE_STATUS_ALL', -1);
define('AGENT_MODULE_STATUS_CRITICAL_BAD', 1);
define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 100);
@ -172,7 +185,7 @@ define('AGENT_MODULE_STATUS_WARNING_ALERT', 200);
define('AGENT_MODULE_STATUS_UNKNOWN', 3);
define('AGENT_MODULE_STATUS_NOT_INIT', 5);
// Agent status
// Agent status.
define('AGENT_STATUS_ALL', -1);
define('AGENT_STATUS_CRITICAL', 1);
define('AGENT_STATUS_NORMAL', 0);
@ -183,9 +196,8 @@ define('AGENT_STATUS_ALERT_FIRED', 4);
define('AGENT_STATUS_WARNING', 2);
/*
Visual maps contants */
// The items kind
// Visual maps contants.
// The items kind.
define('STATIC_GRAPH', 0);
define('PERCENTILE_BAR', 3);
define('MODULE_GRAPH', 1);
@ -208,59 +220,58 @@ define('DONUT_GRAPH', 17);
define('BARS_GRAPH', 18);
define('CLOCK', 19);
define('COLOR_CLOUD', 20);
// Some styles
// Some styles.
define('MIN_WIDTH', 300);
define('MIN_HEIGHT', 120);
define('MIN_WIDTH_CAPTION', 420);
// The process for simple value
// The process for simple value.
define('PROCESS_VALUE_NONE', 0);
define('PROCESS_VALUE_MIN', 1);
define('PROCESS_VALUE_MAX', 2);
define('PROCESS_VALUE_AVG', 3);
// Status
// Status.
define('VISUAL_MAP_STATUS_CRITICAL_BAD', 1);
define('VISUAL_MAP_STATUS_CRITICAL_ALERT', 4);
define('VISUAL_MAP_STATUS_NORMAL', 0);
define('VISUAL_MAP_STATUS_WARNING', 2);
define('VISUAL_MAP_STATUS_UNKNOWN', 3);
define('VISUAL_MAP_STATUS_WARNING_ALERT', 10);
// Wizard
// Wizard.
define('VISUAL_MAP_WIZARD_PARENTS_NONE', 0);
define('VISUAL_MAP_WIZARD_PARENTS_ITEM_MAP', 1);
define('VISUAL_MAP_WIZARD_PARENTS_AGENT_RELANTIONSHIP', 2);
/*
Service constants */
// Status
// Service constants.
// Status.
define('SERVICE_STATUS_UNKNOWN', -1);
define('SERVICE_STATUS_NORMAL', 0);
define('SERVICE_STATUS_CRITICAL', 1);
define('SERVICE_STATUS_WARNING', 2);
define('SERVICE_STATUS_ALERT', 4);
// Default weights
// Default weights.
define('SERVICE_WEIGHT_CRITICAL', 1);
define('SERVICE_WEIGHT_WARNING', 0.5);
define('SERVICE_ELEMENT_WEIGHT_CRITICAL', 1);
define('SERVICE_ELEMENT_WEIGHT_WARNING', 0.5);
define('SERVICE_ELEMENT_WEIGHT_OK', 0);
define('SERVICE_ELEMENT_WEIGHT_UNKNOWN', 0);
// Modes
// Modes.
define('SERVICE_MODE_MANUAL', 0);
define('SERVICE_MODE_AUTO', 1);
define('SERVICE_MODE_SIMPLE', 2);
/*
Status images */
// For modules
// Status images.
// For modules.
define('STATUS_MODULE_OK', 'module_ok.png');
define('STATUS_MODULE_CRITICAL', 'module_critical.png');
define('STATUS_MODULE_WARNING', 'module_warning.png');
define('STATUS_MODULE_NO_DATA', 'module_no_data.png');
define('STATUS_MODULE_UNKNOWN', 'module_unknown.png');
// For agents
// For agents.
define('STATUS_AGENT_CRITICAL', 'agent_critical.png');
define('STATUS_AGENT_WARNING', 'agent_warning.png');
define('STATUS_AGENT_DOWN', 'agent_down.png');
@ -269,24 +280,24 @@ define('STATUS_AGENT_OK', 'agent_ok.png');
define('STATUS_AGENT_NO_DATA', 'agent_no_data.png');
define('STATUS_AGENT_NO_MONITORS', 'agent_no_monitors.png');
define('STATUS_AGENT_NOT_INIT', 'agent_notinit.png');
// For alerts
// For alerts.
define('STATUS_ALERT_FIRED', 'alert_fired.png');
define('STATUS_ALERT_NOT_FIRED', 'alert_not_fired.png');
define('STATUS_ALERT_DISABLED', 'alert_disabled.png');
// For servers
// For servers.
define('STATUS_SERVER_OK', 'server_ok.png');
define('STATUS_SERVER_DOWN', 'server_down.png');
/*
Status images (ball) */
// For modules
// Status images (ball).
// For modules.
define('STATUS_MODULE_OK_BALL', 'module_ok_ball.png');
define('STATUS_MODULE_CRITICAL_BALL', 'module_critical_ball.png');
define('STATUS_MODULE_WARNING_BALL', 'module_warning_ball.png');
define('STATUS_MODULE_NO_DATA_BALL', 'module_no_data_ball.png');
define('STATUS_MODULE_UNKNOWN_BALL', 'module_unknown_ball.png');
// For agents
// For agents.
define('STATUS_AGENT_CRITICAL_BALL', 'agent_critical_ball.png');
define('STATUS_AGENT_WARNING_BALL', 'agent_warning_ball.png');
define('STATUS_AGENT_DOWN_BALL', 'agent_down_ball.png');
@ -295,17 +306,17 @@ define('STATUS_AGENT_OK_BALL', 'agent_ok_ball.png');
define('STATUS_AGENT_NO_DATA_BALL', 'agent_no_data_ball.png');
define('STATUS_AGENT_NO_MONITORS_BALL', 'agent_no_monitors_ball.png');
define('STATUS_AGENT_NOT_INIT_BALL', 'agent_notinit_ball.png');
// For alerts
// For alerts.
define('STATUS_ALERT_FIRED_BALL', 'alert_fired_ball.png');
define('STATUS_ALERT_NOT_FIRED_BALL', 'alert_not_fired_ball.png');
define('STATUS_ALERT_DISABLED_BALL', 'alert_disabled_ball.png');
// For servers
// For servers.
define('STATUS_SERVER_OK_BALL', 'server_ok_ball.png');
define('STATUS_SERVER_DOWN_BALL', 'server_down_ball.png');
// Events criticity
// Events criticity.
define('EVENT_CRIT_MAINTENANCE', 0);
define('EVENT_CRIT_INFORMATIONAL', 1);
define('EVENT_CRIT_NORMAL', 2);
@ -317,7 +328,7 @@ define('EVENT_CRIT_WARNING_OR_CRITICAL', 34);
define('EVENT_CRIT_NOT_NORMAL', 20);
define('EVENT_CRIT_OR_NORMAL', 21);
// Id Module (more use in component)
// Id Module (more use in component).
define('MODULE_DATA', 1);
define('MODULE_NETWORK', 2);
define('MODULE_SNMP', 2);
@ -327,7 +338,7 @@ define('MODULE_WMI', 6);
define('MODULE_WEB', 7);
define('MODULE_WUX', 8);
// Type of Modules of Prediction
// Type of Modules of Prediction.
define('MODULE_PREDICTION_SERVICE', 2);
define('MODULE_PREDICTION_SYNTHETIC', 3);
define('MODULE_PREDICTION_NETFLOW', 4);
@ -335,7 +346,7 @@ define('MODULE_PREDICTION_CLUSTER', 5);
define('MODULE_PREDICTION_CLUSTER_AA', 6);
define('MODULE_PREDICTION_CLUSTER_AP', 7);
// SNMP CONSTANTS
// SNMP CONSTANTS.
define('SNMP_DIR_MIBS', 'attachment/mibs');
define('SNMP_TRAP_TYPE_NONE', -1);
@ -346,12 +357,12 @@ define('SNMP_TRAP_TYPE_LINK_UP', 3);
define('SNMP_TRAP_TYPE_AUTHENTICATION_FAILURE', 4);
define('SNMP_TRAP_TYPE_OTHER', 5);
// PASSWORD POLICIES
// PASSWORD POLICIES.
define('PASSSWORD_POLICIES_OK', 0);
define('PASSSWORD_POLICIES_FIRST_CHANGE', 1);
define('PASSSWORD_POLICIES_EXPIRED', 2);
// SERVER TYPES
// SERVER TYPES.
define('SERVER_TYPE_DATA', 0);
define('SERVER_TYPE_NETWORK', 1);
define('SERVER_TYPE_SNMP', 2);
@ -374,7 +385,7 @@ define('SERVER_TYPE_SYSLOG', 18);
define('SERVER_TYPE_AUTOPROVISION', 19);
define('SERVER_TYPE_MIGRATION', 20);
// REPORTS
// REPORTS.
define('REPORT_TOP_N_MAX', 1);
define('REPORT_TOP_N_MIN', 2);
define('REPORT_TOP_N_AVG', 0);
@ -412,7 +423,7 @@ define('REPORT_GENERAL_GROUP_BY_AGENT', 1);
define('REPORTING_CUSTOM_GRAPH_LEGEND_EACH_MODULE_VERTICAL_SIZE', 15);
// POLICIES
// POLICIES.
define('POLICY_UPDATED', 0);
define('POLICY_PENDING_DATABASE', 1);
define('POLICY_PENDING_ALL', 2);
@ -426,7 +437,7 @@ define('MODULE_LINKED', 1);
define('MODULE_PENDING_UNLINK', 10);
define('MODULE_PENDING_LINK', 11);
// EVENTS
// EVENTS.
define('EVENTS_GOING_UNKNOWN', 'going_unknown');
define('EVENTS_UNKNOWN', 'unknown');
define('EVENTS_ALERT_FIRED', 'alert_fired');
@ -445,7 +456,7 @@ define('EVENTS_GOING_DOWN_CRITICAL', 'going_down_critical');
define('EVENTS_GOING_UP_NORMAL', 'going_up_normal');
define('EVENTS_CONFIGURATION_CHANGE', 'configuration_change');
// CUSTOM GRAPHS
// CUSTOM GRAPHS.
define('CUSTOM_GRAPH_AREA', 0);
define('CUSTOM_GRAPH_STACKED_AREA', 1);
define('CUSTOM_GRAPH_LINE', 2);
@ -457,26 +468,26 @@ define('CUSTOM_GRAPH_VBARS', 7);
define('CUSTOM_GRAPH_PIE', 8);
define('CUSTOM_GRAPH_BULLET_CHART_THRESHOLD', 9);
// COLLECTIONS
// COLLECTIONS.
define('COLLECTION_PENDING_APPLY', 0);
define('COLLECTION_CORRECT', 1);
define('COLLECTION_ERROR_LOST_DIRECTORY', 2);
define('COLLECTION_UNSAVED', 3);
// PAGINATION
// PAGINATION.
define('PAGINATION_BLOCKS_LIMIT', 15);
// CHARTS
// CHARTS.
define('CHART_DEFAULT_WIDTH', 150);
define('CHART_DEFAULT_HEIGHT', 110);
define('CHART_DEFAULT_ALPHA', 50);
// Statwin
// Statwin.
define('STATWIN_DEFAULT_CHART_WIDTH', 555);
define('STATWIN_DEFAULT_CHART_HEIGHT', 245);
// Dashboard
// Dashboard.
define('DASHBOARD_DEFAULT_COUNT_CELLS', 1);
define('OPTION_TEXT', 1);
@ -491,11 +502,11 @@ define('OPTION_AGENT_AUTOCOMPLETE', 9);
define('OPTION_SELECT_MULTISELECTION', 10);
define('OPTION_COLOR_PICKER', 11);
// Transactional map constants
// Transactional map constants.
define('NODE_TYPE', 0);
define('ARROW_TYPE', 1);
// SAML attributes constants
// SAML attributes constants.
define('SAML_ROLE_AND_TAG', 'eduPersonEntitlement');
define('SAML_USER_DESC', 'commonName');
define('SAML_ID_USER_IN_PANDORA', 'eduPersonTargetedId');
@ -503,11 +514,11 @@ define('SAML_GROUP_IN_PANDORA', 'schacHomeOrganization');
define('SAML_MAIL_IN_PANDORA', 'mail');
define('SAML_DEFAULT_PROFILES_AND_TAGS_FORM', 'urn:mace:rediris.es:entitlement:monitoring:');
// Other constants
// Other constants.
define('STATUS_OK', 0);
define('STATUS_ERROR', 1);
// Maps (new networkmaps and new visualmaps)
// Maps (new networkmaps and new visualmaps).
define('MAP_TYPE_NETWORKMAP', 0);
define('MAP_TYPE_VISUALMAP', 1);
@ -530,14 +541,14 @@ define('MAP_SOURCE_IP_MASK', 1);
define('NETWORKMAP_DEFAULT_WIDTH', 800);
define('NETWORKMAP_DEFAULT_HEIGHT', 800);
// Background options
// Background options.
define('CENTER', 0);
define('MOSAIC', 1);
define('STRECH', 2);
define('FIT_WIDTH', 3);
define('FIT_HEIGH', 4);
// Items of maps
// Items of maps.
define('ITEM_TYPE_AGENT_NETWORKMAP', 0);
define('ITEM_TYPE_MODULE_NETWORKMAP', 1);
define('ITEM_TYPE_EDGE_NETWORKMAP', 2);
@ -546,7 +557,7 @@ define('ITEM_TYPE_MODULEGROUP_NETWORKMAP', 4);
define('ITEM_TYPE_GROUP_NETWORKMAP', 5);
define('ITEM_TYPE_POLICY_NETWORKMAP', 6);
// Another constants new networkmap
// Another constants new networkmap.
define('DEFAULT_NODE_WIDTH', 30);
define('DEFAULT_NODE_HEIGHT', 30);
define('DEFAULT_NODE_SHAPE', 'circle');

View File

@ -14610,57 +14610,66 @@ function api_get_users($thrash1, $thrash2, $other, $returnType)
}
/**
* Resets module counts and alert counts in the agents
*
* @param $id id of the agent you want to synchronize. Add "All" to synchronize all agents
* @param $trash1
* @param $trash2
* @param $trash3
*
* Example:
*
* Example:
* api.php?op=set&op2=reset_agent_counts&apipass=1234&user=admin&pass=pandora&id=All
*/
function api_set_reset_agent_counts ($id, $thrash1, $thrash2, $thrash3)
function api_set_reset_agent_counts($id, $thrash1, $thrash2, $thrash3)
{
global $config;
global $config;
if (!check_acl($config['id_user'], 0, "AW")) {
returnError('forbidden', 'string');
return;
}
if (!check_acl($config['id_user'], 0, 'AW')) {
returnError('forbidden', 'string');
return;
}
if ($id == '' || !$id) {
returnError('error_parameter', __('Error. Agent cannot be left blank.'));
return;
}
if ($id == '' || !$id) {
returnError('error_parameter', __('Error. Agent cannot be left blank.'));
return;
}
if ($id != "All"){
$agent = db_get_row_filter('tagente', array('id_agente' => $id));
if (empty ($agent)){
returnError('error_agent', __('This agent does not exist.'));
return;
}else {
$return = db_process_sql_update ('tagente',
array ('update_module_count' => 1, 'update_alert_count' => 1),
array('id_agente' => $id)
);
}
}
else {
$return = db_process_sql_update ('tagente',
array ('update_module_count' => 1, 'update_alert_count' => 1)
);
}
if ($id != 'All') {
$agent = db_get_row_filter('tagente', ['id_agente' => $id]);
if (empty($agent)) {
returnError('error_agent', __('This agent does not exist.'));
return;
} else {
$return = db_process_sql_update(
'tagente',
[
'update_module_count' => 1,
'update_alert_count' => 1,
],
['id_agente' => $id]
);
}
} else {
$return = db_process_sql_update(
'tagente',
[
'update_module_count' => 1,
'update_alert_count' => 1,
]
);
}
$data = __('Successfully updated module/alert count in id agent %d.', $id);
if ($id == 'All') {
$data = __('Successfully updated module/alert count in all agents');
}
$data = __('Successfully updated module/alert count in id agent %d.', $id);
if ($id == "All")
$data = __('Successfully updated module/alert count in all agents');
if ($return === false)
returnError('error_reset_agent_counts', 'Could not be updated module/alert counts in id agent %d.', $id);
else
returnData('string', array('type' => 'string', 'data' => $data));
if ($return === false) {
returnError('error_reset_agent_counts', 'Could not be updated module/alert counts in id agent %d.', $id);
} else {
returnData('string', ['type' => 'string', 'data' => $data]);
}
}

View File

@ -1,26 +1,39 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// 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
// 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.
/**
* @package Include
* Extension to self monitor Pandora FMS Console
*
* @category Config
* @package Pandora FMS
* @subpackage Config
* @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.
* ============================================================================
*/
// Config functions.
/**
* Creates a single config value in the database.
*
* @param string Config token to create.
* @param string Value to set.
* @param string $token Config token to create.
* @param string $value Value to set.
*
* @return boolean Config id if success. False on failure.
*/
@ -41,15 +54,15 @@ function config_create_value($token, $value)
*
* If the config token doesn't exists, it's created.
*
* @param string Config token to update.
* @param string New value to set.
* @param string $token Config token to update.
* @param string $value New value to set.
*
* @return boolean True if success. False on failure.
*/
function config_update_value($token, $value)
{
global $config;
// Include functions_io to can call __() function
// Include functions_io to can call __() function.
include_once $config['homedir'].'/include/functions_io.php';
if ($token == 'list_ACL_IPs_for_API') {
@ -73,7 +86,7 @@ function config_update_value($token, $value)
return (bool) config_create_value($token, io_safe_input($value));
}
// If it has not changed
// If it has not changed.
if ($config[$token] == $value) {
return true;
}
@ -97,15 +110,17 @@ function config_update_value($token, $value)
/**
* Updates all config values in case setup page was invoked
*
* @return boolean
*/
function config_update_config()
{
global $config;
// Include functions_io to can call __() function
// Include functions_io to can call __() function.
include_once $config['homedir'].'/include/functions_io.php';
// If user is not even log it, don't try this
// If user is not even log it, don't try this.
if (! isset($config['id_user'])) {
$config['error_config_update_config'] = [];
$config['error_config_update_config']['correct'] = false;
@ -127,7 +142,7 @@ function config_update_config()
if ($update_config) {
db_pandora_audit('Setup', 'Setup has changed');
} else {
// Do none
// Do nothing.
return false;
}
@ -137,8 +152,8 @@ function config_update_config()
switch ($sec2) {
case 'godmode/setup/setup':
$section_setup = get_parameter('section');
// MAIN SETUP
// Setup now is divided in different tabs
// MAIN SETUP.
// Setup now is divided in different tabs.
switch ($section_setup) {
case 'general':
if (!config_update_value('language', (string) get_parameter('language'))) {
@ -228,7 +243,7 @@ function config_update_config()
$error_update[] = __('Sound for Monitor warning');
}
// Update of Pandora FMS license
// Update of Pandora FMS license.
$update_manager_installed = db_get_value('value', 'tconfig', 'token', 'update_manager_installed');
if ($update_manager_installed == 1) {
@ -468,7 +483,7 @@ function config_update_config()
break;
case 'auth':
// AUTHENTICATION SETUP
// AUTHENTICATION SETUP.
if (!config_update_value('auth', get_parameter('auth'))) {
$error_update[] = __('Authentication method');
}
@ -635,9 +650,10 @@ function config_update_config()
break;
case 'perf':
// PERFORMANCE SETUP
// PERFORMANCE SETUP.
if (!config_update_value('event_purge', get_parameter('event_purge'))) {
$error_update[] = $check_metaconsole_events_history = get_parameter('metaconsole_events_history', -1);
$check_metaconsole_events_history = get_parameter('metaconsole_events_history', -1);
$error_update[] = $check_metaconsole_events_history;
}
if ($check_metaconsole_events_history != -1) {
@ -738,7 +754,7 @@ function config_update_config()
break;
case 'vis':
// VISUAL STYLES SETUP
// VISUAL STYLES SETUP.
if (!config_update_value('date_format', (string) get_parameter('date_format'))) {
$error_update[] = __('Date format string');
}
@ -1052,12 +1068,12 @@ function config_update_config()
$error_update[] = __('Display text when proc modules have state critical');
}
// Daniel maya 02/06/2016 Display menu with click --INI
// Daniel maya 02/06/2016 Display menu with click --INI.
if (!config_update_value('click_display', (bool) get_parameter('click_display', false))) {
$error_update[] = __('Display lateral menus with left click');
}
// Daniel maya 02/06/2016 Display menu with click --END
// Daniel maya 02/06/2016 Display menu with click --END.
if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) {
if (!config_update_value('service_label_font_size', get_parameter('service_label_font_size', false))) {
$error_update[] = __('Service label font size');
@ -1128,7 +1144,7 @@ function config_update_config()
// --------------------------------------------------
$interval_values = get_parameter('interval_values');
// Add new interval value if is provided
// Add new interval value if is provided.
$interval_value = (float) get_parameter('interval_value', 0);
if ($interval_value > 0) {
@ -1146,7 +1162,7 @@ function config_update_config()
}
}
// Delete interval value if is required
// Delete interval value if is required.
$interval_to_delete = (float) get_parameter('interval_to_delete');
if ($interval_to_delete > 0) {
$interval_values_array = explode(',', $interval_values);
@ -1168,7 +1184,7 @@ function config_update_config()
$error_update[] = __('Custom report info');
}
// Juanma (06/05/2014) New feature: Custom front page for reports
// Juanma (06/05/2014) New feature: Custom front page for reports.
if (!config_update_value('custom_report_front', get_parameter('custom_report_front'))) {
$error_update[] = __('Custom report front');
}
@ -1329,7 +1345,15 @@ function config_update_config()
$error_update[] = __('eHorus id custom field');
}
break;
default:
// Ignore.
break;
}
default:
// Ignore.
break;
}
if (count($error_update) > 0) {
@ -1351,7 +1375,9 @@ function config_update_config()
/**
* Process config variables
* Process config variables.
*
* @return void
*/
function config_process_config()
{
@ -1369,7 +1395,7 @@ function config_process_config()
$is_windows = true;
}
// Compatibility fix
// Compatibility fix.
foreach ($configs as $c) {
$config[$c['token']] = $c['value'];
}
@ -1426,18 +1452,18 @@ function config_process_config()
if (!isset($config['prominent_time'])) {
// Prominent time tells us what to show prominently when a timestamp is
// displayed. The comparation (... days ago) or the timestamp (full date)
// displayed. The comparation (... days ago) or the timestamp (full date).
config_update_value('prominent_time', 'comparation');
}
if (!isset($config['timesource'])) {
// Timesource says where time comes from (system or mysql)
// Timesource says where time comes from (system or mysql).
config_update_value('timesource', 'system');
}
if (!isset($config['https'])) {
// Sets whether or not we want to enforce https. We don't want to go to a
// potentially unexisting config by default
// potentially unexisting config by default.
config_update_value('https', false);
}
@ -1446,7 +1472,7 @@ function config_process_config()
}
if (!isset($config['cert_path'])) {
// Sets name and path of ssl path for use in application
// Sets name and path of ssl path for use in application.
config_update_value('cert_path', '/etc/ssl/certs/pandorafms.pem');
}
@ -1458,7 +1484,7 @@ function config_process_config()
config_update_value('status_images_set', 'default');
}
// Load user session
// Load user session.
if (isset($_SESSION['id_usuario'])) {
$config['id_user'] = $_SESSION['id_usuario'];
}
@ -1658,8 +1684,9 @@ function config_process_config()
}
/*
*Parse the ACL IP list for access API
* Parse the ACL IP list for access API
*/
$temp_list_ACL_IPs_for_API = [];
if (isset($config['list_ACL_IPs_for_API'])) {
if (!empty($config['list_ACL_IPs_for_API'])) {
@ -1675,8 +1702,7 @@ function config_process_config()
// the first time make a conenction and disable itself
// Not Managed here !
// if (!isset ($config["autoupdate"])) {
// config_update_value ('autoupdate', true);
// }
// config_update_value ('autoupdate', true);.
include_once $config['homedir'].'/include/auth/mysql.php';
include_once $config['homedir'].'/include/functions_io.php';
@ -2271,7 +2297,7 @@ function config_process_config()
}
if (defined('METACONSOLE')) {
// Customizable sections (Metaconsole)
// Customizable sections (Metaconsole).
enterprise_include_once('include/functions_enterprise.php');
$customizable_sections = enterprise_hook('enterprise_get_customizable_sections');
@ -2293,15 +2319,15 @@ function config_process_config()
) {
$isFunctionSkins = enterprise_include_once('include/functions_skins.php');
if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) {
// Try to update user table in order to refresh skin inmediatly
// Try to update user table in order to refresh skin inmediatly.
$is_user_updating = get_parameter('sec2', '');
if ($is_user_updating == 'operation/users/user_edit') {
$id = get_parameter_get('id', $config['id_user']);
// ID given as parameter
// ID given as parameter.
$user_info = get_user_info($id);
// If current user is editing himself or if the user has UM (User Management) rights on any groups the user is part of AND the authorization scheme allows for users/admins to update info
// If current user is editing himself or if the user has UM (User Management) rights on any groups the user is part of AND the authorization scheme allows for users/admins to update info.
if (($config['id_user'] == $id || check_acl($config['id_user'], users_get_groups($id), 'UM')) && $config['user_can_update_info']) {
$view_mode = false;
} else {
@ -2315,7 +2341,7 @@ function config_process_config()
}
if (!is_metaconsole()) {
// Skins are available only in console mode
// Skins are available only in console mode.
if (isset($config['id_user'])) {
$relative_path = enterprise_hook('skins_set_image_skin_path', [$config['id_user']]);
} else {
@ -2445,12 +2471,12 @@ function config_process_config()
config_update_value('render_proc_fail', __('Fail'));
}
// Daniel maya 02/06/2016 Display menu with click --INI
// Daniel maya 02/06/2016 Display menu with click --INI.
if (!isset($config['click_display'])) {
config_update_value('click_display', 1);
}
// Daniel maya 02/06/2016 Display menu with click --END
// Daniel maya 02/06/2016 Display menu with click --END.
if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) {
if (!isset($config['service_label_font_size'])) {
config_update_value('service_label_font_size', 20);
@ -2477,7 +2503,7 @@ function config_process_config()
config_update_value('custom_report_info', 1);
}
// Juanma (06/05/2014) New feature: Custom front page for reports
// Juanma (06/05/2014) New feature: Custom front page for reports.
if (!isset($config['custom_report_front'])) {
config_update_value('custom_report_front', 0);
}
@ -2587,7 +2613,7 @@ function config_process_config()
config_update_value('instance_registered', 0);
}
// eHorus
// Ehorus.
if (!isset($config['ehorus_enabled'])) {
config_update_value('ehorus_enabled', 0);
}
@ -2622,285 +2648,72 @@ function config_process_config()
}
}
// Finally, check if any value was overwritten in a form
// Finally, check if any value was overwritten in a form.
config_update_config();
}
/**
* Start supervisor.
*
* @return void
*/
function config_check()
{
global $config;
// At this first version I'm passing errors using session variables, because the error management
// is done by an AJAX request. Better solutions could be implemented in the future :-)
if (license_free() && users_is_admin($config['id_user'])) {
$login = get_parameter('login', false);
// Registration advice
if ((!isset($config['instance_registered']) || ($config['instance_registered'] != 1)) && ($login === false)) {
set_pandora_error_for_header(
__('Click <a style="font-weight:bold; text-decoration:underline" href="javascript: force_run_register();"> here</a> to start the registration process'),
__('This instance is not registered in the Update manager')
);
}
include_once __DIR__.'/class/ConsoleSupervisor.php';
// Newsletter advice
$newsletter = db_get_value('middlename', 'tusuario', 'id_user', $config['id_user']);
if ($newsletter != 1 && $login === false) {
set_pandora_error_for_header(
__('Click <a style="font-weight:bold; text-decoration:underline" href="javascript: force_run_newsletter();"> here</a> to start the newsletter subscription process'),
__('Not subscribed to the newsletter')
);
}
// Enterprise customers launch supervisor using discovery task.
if (license_free()) {
$supervisor = new ConsoleSupervisor(false);
$supervisor->run();
}
// Check default password for "admin"
$is_admin = db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']);
if ($is_admin) {
$hashpass = db_get_sql(
"SELECT password
FROM tusuario WHERE id_user = 'admin'"
);
if ($hashpass == '1da7ee7d45b96d0e1f45ee4ee23da560') {
set_pandora_error_for_header(
__('Default password for "Admin" user has not been changed.'),
__('Please change the default password because is a common vulnerability reported.')
);
}
}
if (isset($config['license_expired'])) {
set_pandora_error_for_header(
__('You can not get updates until you renew the license.'),
__('This license has expired.')
);
}
if (!is_writable('attachment')) {
set_pandora_error_for_header(
__('Please check that the web server has write rights on the {HOMEDIR}/attachment directory'),
__('Attachment directory is not writable by HTTP Server')
);
}
// Get remote file dir.
$remote_config = io_safe_output(
db_get_value_filter(
'value',
'tconfig',
['token' => 'remote_config']
)
);
if (enterprise_installed()) {
if (!is_readable($remote_config)) {
set_pandora_error_for_header(
__('Remote configuration directory is not readble for the console').' - '.$remote_config
);
}
$remote_config_conf = $remote_config.'/conf';
if (!is_writable($remote_config_conf)) {
set_pandora_error_for_header(
__('Remote configuration directory is not writtable for the console').' - '.$remote_config.'/conf'
);
}
$remote_config_col = $remote_config.'/collections';
if (!is_writable($remote_config_col)) {
set_pandora_error_for_header(
__('Remote configuration directory is not writtable for the console').' - '.$remote_config.'/collections'
);
}
}
// Check attachment directory (too much files?)
$filecount = count(glob($config['homedir'].'/attachment/*'));
// N temporal files of trash should be enough for most people.
if ($filecount > $config['num_files_attachment']) {
set_pandora_error_for_header(
__('There are too much files in attachment directory. This is not fatal, but you should consider cleaning up your attachment directory manually')." ( $filecount ".__('files').' )',
__('Too much files in your tempora/attachment directory')
);
}
// Check database maintance
$db_maintance = db_get_value_filter(
'value',
'tconfig',
['token' => 'db_maintance']
);
// If never was executed, it means we are in the first Pandora FMS execution. Set current timestamp
if (empty($db_maintance)) {
config_update_value('db_maintance', date('U'));
}
$last_maintance = (date('U') - $db_maintance);
// ~ about 50 hr
if ($last_maintance > 190000) {
set_pandora_error_for_header(
__('Your database is not maintained correctly. It seems that more than 48hrs have passed without proper maintenance. Please review documents of %s on how to perform this maintenance process (DB Tool) and enable it as soon as possible.', get_product_name()),
__('Database maintance problem')
);
}
$fontpath = io_safe_output(db_get_value_filter('value', 'tconfig', ['token' => 'fontpath']));
if (($fontpath == '') or (!file_exists($fontpath))) {
set_pandora_error_for_header(
__('Your defined font doesnt exist or is not defined. Please check font parameters in your config'),
__('Default font doesnt exist')
);
}
if ($config['event_storm_protection']) {
set_pandora_error_for_header(
__('You need to restart server after altering this configuration setting.'),
__('Event storm protection is activated. No events will be generated during this mode.')
);
}
global $develop_bypass;
if ($develop_bypass == 1) {
set_pandora_error_for_header(
__('Your %s has the "develop_bypass" mode enabled. This is a developer mode and should be disabled in a production system. This value is written in the main index.php file', get_product_name()),
__('Developer mode is enabled')
);
}
if (isset($_SESSION['new_update'])) {
if (!empty($_SESSION['return_installation_open'])) {
if (!$_SESSION['return_installation_open']['return']) {
foreach ($_SESSION['return_installation_open']['text'] as $message) {
set_pandora_error_for_header(
$message,
__('Error first setup Open update')
);
}
}
}
if ($_SESSION['new_update'] == 'new') {
set_pandora_error_for_header(
__('There is a new update available. Please<a style="font-weight:bold;" href="index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=online"> go to Administration:Setup:Update Manager</a> for more details.'),
__('New %s Console update', get_product_name())
);
}
}
// PHP configuration values
$PHPupload_max_filesize = config_return_in_bytes(ini_get('upload_max_filesize'));
$PHPmax_input_time = ini_get('max_input_time');
$PHPmemory_limit = config_return_in_bytes(ini_get('memory_limit'));
$PHPmax_execution_time = ini_get('max_execution_time');
$PHPsafe_mode = ini_get('safe_mode');
$PHPdisable_functions = ini_get('disable_functions');
if ($PHPsafe_mode === '1') {
set_pandora_error_for_header(
__('To disable, change it on your PHP configuration file (php.ini) and put safe_mode = Off (Dont forget restart apache process after changes)'),
sprintf(__('PHP safe mode is enabled. Some features may not properly work.'))
);
}
if ($PHPmax_input_time !== '-1') {
set_pandora_error_for_header(
sprintf(__('Recommended value is %s'), '-1 ('.__('Unlimited').')').'<br><br>'.__('Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)'),
sprintf(__("Not recommended '%s' value in PHP configuration"), 'max_input_time')
);
}
if ($PHPmax_execution_time !== '0') {
set_pandora_error_for_header(
sprintf(__('Recommended value is: %s'), '0 ('.__('Unlimited').')').'<br><br>'.__('Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)'),
sprintf(__("Not recommended '%s' value in PHP configuration"), 'max_execution_time')
);
}
$PHPupload_max_filesize_min = config_return_in_bytes('800M');
if ($PHPupload_max_filesize < $PHPupload_max_filesize_min) {
set_pandora_error_for_header(
sprintf(__('Recommended value is: %s'), sprintf(__('%s or greater'), '800M')).'<br><br>'.__('Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)'),
sprintf(__("Not recommended '%s' value in PHP configuration"), 'upload_max_filesize')
);
}
$PHPmemory_limit_min = config_return_in_bytes('500M');
if ($PHPmemory_limit < $PHPmemory_limit_min && $PHPmemory_limit !== '-1') {
set_pandora_error_for_header(
sprintf(__('Recommended value is: %s'), sprintf(__('%s or greater'), '500M')).'<br><br>'.__('Please, change it on your PHP configuration file (php.ini) or contact with administrator'),
sprintf(__("Not recommended '%s' value in PHP configuration"), 'memory_limit')
);
}
if (preg_match('/system/', $PHPdisable_functions) or preg_match('/exec/', $PHPdisable_functions)) {
set_pandora_error_for_header(
__('Variable disable_functions containts functions system() or exec(), in PHP configuration file (php.ini)').'<br /><br />'.__('Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)'),
__('Problems with disable functions in PHP.INI')
);
}
$result_ejecution = exec($config['phantomjs_bin'].'/phantomjs --version');
if (!isset($result_ejecution) || $result_ejecution == '') {
if ($config['language'] == 'es') {
set_pandora_error_for_header(
__('To be able to create images of the graphs for PDFs, please install the phantom.js extension. For that, it is necessary to follow these steps:').'<a target="blank" href="https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_es:Configuracion#Phantomjs">Click here</a>',
__('phantomjs is not installed')
);
} else {
set_pandora_error_for_header(
__('To be able to create images of the graphs for PDFs, please install the phantom.js extension. For that, it is necessary to follow these steps:').'<a target="blank" href="https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_en:Configuration#Phantomjs">Click here</a>',
__('phantomjs is not installed')
);
}
}
$php_version = phpversion();
$php_version_array = explode('.', $php_version);
if ($php_version_array[0] < 7) {
if ($config['language'] == 'es') {
$url_help = 'https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_es:Instalaci%C3%B3n_y_actualizaci%C3%B3n_PHP_7';
} else {
$url_help = 'https://wiki.pandorafms.com/index.php?title=Pandora:Documentation_en:_PHP_7';
}
set_pandora_error_for_header(
__('For a correct operation of PandoraFMS, PHP must be updated to version 7.0 or higher.').'<br>'.__('Otherwise, functionalities will be lost.').'<br>'."<ol><li style='color: #676767'>".__('Report download in PDF format').'</li>'."<li style='color: #676767'>".__('Emails Sending').'</li>'."<li style='color: #676767'>".__('Metaconsole Collections').'</li>'."<li style='color: #676767'>".'...'.'</li>'.'</ol>'.'<a target="blank" href="'.$url_help.'">'.__('Access Help').'</a>',
__('PHP UPDATE REQUIRED')
);
}
}
/**
* Return in bytes
*
* @param string $val Value to convert.
*
* @return integer
*/
function config_return_in_bytes($val)
{
$val = trim($val);
$last = strtolower($val[(strlen($val) - 1)]);
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
// The 'G' modifier is available since PHP 5.1.0.
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
default:
// Ignore.
break;
}
return $val;
}
/**
* Undocumented function
*
* @return void
*/
function config_user_set_custom_config()
{
global $config;
$userinfo = get_user_info($config['id_user']);
// Refresh the last_connect info in the user table
// if last update was more than 5 minutes ago
// Refresh the last_connect info in the user table.
// if last update was more than 5 minutes ago.
if ($userinfo['last_connect'] < (time() - SECONDS_1MINUTE)) {
update_user($config['id_user'], ['last_connect' => time()]);
}
@ -2909,7 +2722,7 @@ function config_user_set_custom_config()
$config['block_size'] = $userinfo['block_size'];
}
// Each user could have it's own timezone)
// Each user could have it's own timezone).
if (isset($userinfo['timezone'])) {
if ($userinfo['timezone'] != '') {
date_default_timezone_set($userinfo['timezone']);
@ -2922,6 +2735,11 @@ function config_user_set_custom_config()
}
/**
* Undocumented function
*
* @return void
*/
function config_prepare_session()
{
global $config;
@ -2934,10 +2752,10 @@ function config_prepare_session()
}
if ($user_sesion_time == 0) {
// Change the session timeout value to session_timeout minutes // 8*60*60 = 8 hours
// Change the session timeout value to session_timeout minutes // 8*60*60 = 8 hours.
$sessionCookieExpireTime = $config['session_timeout'];
} else {
// Change the session timeout value to session_timeout minutes // 8*60*60 = 8 hours
// Change the session timeout value to session_timeout minutes // 8*60*60 = 8 hours.
$sessionCookieExpireTime = $user_sesion_time;
}
@ -2947,7 +2765,7 @@ function config_prepare_session()
$sessionCookieExpireTime *= 60;
}
// Reset the expiration time upon page load //session_name() is default name of session PHPSESSID
// Reset the expiration time upon page load //session_name() is default name of session PHPSESSID.
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), $_COOKIE[session_name()], (time() + $sessionCookieExpireTime), '/');
}

View File

@ -2991,3 +2991,22 @@ function html_print_csrf_error()
return true;
}
/**
* Print an swith button
*
* @param array $atributes. Valid params:
* name: Usefull to handle in forms
* value: If is checked or not
* @return string with HTML of button
*/
function html_print_switch($attributes=[])
{
$name_html = isset($attributes['name']) ? "name = {$attributes['name']}" : '';
$checked_html = (bool) $attributes['value'] ? 'checked' : '';
return "<label class='p-switch'>
<input type='checkbox' $name_html $checked_html>
<span class='p-slider'></span>
</label>";
}

View File

@ -1,55 +1,150 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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
// 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.
/**
* @package Include
* @subpackage Messages
* Extension to manage a list of gateways and the node address where they should
* point to.
*
* @category Extensions
* @package Pandora FMS
* @subpackage Community
* @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 $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_groups.php';
require_once $config['homedir'].'/include/functions_notifications.php';
/**
* Set targets for given messaje
*
* @param integer $message_id Message id.
* @param array $users An array with all target users.
* @param array $groups An array with all target groups.
*
* @return boolean Task status.
*/
function message_set_targets(
int $message_id,
array $users=null,
array $groups=null
) {
if (empty($message_id)) {
return false;
}
if (is_array($users)) {
$values = [];
foreach ($users as $user) {
if (empty($user)) {
continue;
}
$values['id_mensaje'] = $message_id;
$values['id_user'] = $user;
}
if (!empty($values)) {
$ret = db_process_sql_insert('tnotification_user', $values);
if ($ret === false) {
return false;
}
}
}
if (is_array($groups)) {
$values = [];
foreach ($groups as $group) {
if ($group != 0 && empty($group)) {
continue;
}
$values['id_mensaje'] = $message_id;
$values['id_group'] = $group;
}
if (!empty($values)) {
$ret = db_process_sql_insert('tnotification_group', $values);
if ($ret === false) {
return false;
}
}
}
return true;
}
/**
* Creates a private message to be forwarded to other people
*
* @param string $usuario_origen The sender of the message
* @param string $usuario_destino The receiver of the message
* @param string $subject Subject of the message (much like E-Mail)
* @param string $mensaje The actual message. This message will be cleaned by io_safe_input
* (html is allowed but loose html chars will be translated)
* @param string $usuario_origen The sender of the message.
* @param array $target_users The receiver of the message.
* @param array $target_groups Target groups to be delivered.
* @param string $subject Subject of the message (much like E-Mail).
* @param string $mensaje The actual message. This message will be
* cleaned by io_safe_input (html is allowed but
* loose html chars will be translated).
*
* @return boolean true when delivered, false in case of error
*/
function messages_create_message($usuario_origen, $usuario_destino, $subject, $mensaje)
{
function messages_create_message(
string $usuario_origen,
array $target_users,
array $target_groups,
string $subject,
string $mensaje
) {
$users = users_get_info();
if (!array_key_exists($usuario_origen, $users) || !array_key_exists($usuario_destino, $users)) {
return false;
// Users don't exist so don't send to them
// Create message.
$message_id = db_process_sql_insert(
'tmensajes',
[
'id_usuario_origen' => $usuario_origen,
'subject' => $subject,
'mensaje' => $mensaje,
'id_source' => get_notification_source_id('message'),
'timestamp' => get_system_time(),
]
);
// Update URL
// Update targets.
if ($message_id !== false) {
$ret = message_set_targets(
$message_id,
$target_users,
$target_groups
);
if ($ret === false) {
// Failed to deliver messages. Erase message and show error.
db_process_sql_delete(
'tmensajes',
['id_mensaje' => $message_id]
);
return false;
}
}
$values = [];
$values['id_usuario_origen'] = $usuario_origen;
$values['id_usuario_destino'] = $usuario_destino;
$values['subject'] = $subject;
$values['mensaje'] = $mensaje;
$values['timestamp'] = get_system_time();
$return = db_process_sql_insert('tmensajes', $values);
if ($return === false) {
return false;
} else {
@ -58,108 +153,134 @@ function messages_create_message($usuario_origen, $usuario_destino, $subject, $m
}
/**
* Creates private messages to be forwarded to groups
*
* @param string The sender of the message
* @param string The receivers (group) of the message
* @param string Subject of the message (much like E-Mail)
* @param string The actual message. This message will be cleaned by io_safe_input
* (html is allowed but loose html chars will be translated)
*
* @return boolean true when delivered, false in case of error
*/
function messages_create_group($usuario_origen, $dest_group, $subject, $mensaje)
{
$users = users_get_info();
$group_users = groups_get_users($dest_group);
if (! array_key_exists($usuario_origen, $users)) {
// Users don't exist in the system
return false;
} else if (empty($group_users)) {
// There are no users in the group, so it hasn't failed although it hasn't done anything.
return true;
}
// array unique
foreach ($group_users as $user) {
foreach ($user as $key => $us) {
if ($key == 'id_user') {
$group_user[$us] = $us;
}
}
}
foreach ($group_user as $user) {
$return = messages_create_message($usuario_origen, get_user_id($user), $subject, $mensaje);
if ($return === false) {
// Error sending message
return false;
}
}
return true;
}
/**
* Deletes a private message
*
* @param integer $id_message
* @param integer $id_message Message to be deleted.
*
* @return boolean true when deleted, false in case of error
*/
function messages_delete_message($id_message)
function messages_delete_message(int $id_message)
{
global $config;
$where = [
// 'id_usuario_destino' => $config["id_user"],
'id_mensaje' => $id_message,
];
return (bool) db_process_sql_delete('tmensajes', $where);
// Check if user has grants to access the message.
if (check_notification_readable($id_message) === false) {
return false;
}
$utimestamp = time();
$ret = db_process_sql_update(
'tnotification_user',
['utimestamp_erased' => $utimestamp],
[
'id_mensaje' => $id_message,
'id_user' => $config['id_user'],
]
);
if ($ret === 0) {
// No previous updates.
// Message available to user due group assignment.
$ret = db_process_sql_insert(
'tnotification_user',
[
'id_mensaje' => $id_message,
'id_user' => $config['id_user'],
'utimestamp_erased' => $utimestamp,
]
);
// Quick fix. Insertions returns 0.
if ($ret !== false) {
$ret = 1;
}
}
return (bool) $ret;
}
/**
* Marks a private message as read/unread
*
* @param integer $message_id The message to modify
* @param boolean $read To set unread pass 0, false or empty value
* @param integer $message_id The message to modify.
* @param boolean $read To set unread pass 0, false or empty value.
*
* @return boolean true when marked, false in case of error
*/
function messages_process_read($message_id, $read=true)
{
if (empty($read)) {
$read = 0;
} else {
$read = 1;
function messages_process_read(
int $message_id,
bool $read=true
) {
global $config;
// Check if user has grants to read the message.
if (check_notification_readable($message_id) === false) {
return false;
}
return (bool) db_process_sql_update('tmensajes', ['estado' => $read], ['id_mensaje' => $message_id]);
if (empty($read)) {
// Mark as unread.
$utimestamp = null;
} else {
// Mark as read.
$utimestamp = time();
}
$ret = db_process_sql_update(
'tnotification_user',
['utimestamp_read' => $utimestamp],
[
'id_mensaje' => $message_id,
'id_user' => $config['id_user'],
'utimestamp_read' => null,
]
);
if ($ret === 0) {
// No previous updates.
// Message available to user due group assignment.
$ret = db_process_sql_insert(
'tnotification_user',
[
'id_mensaje' => $message_id,
'id_user' => $config['id_user'],
'utimestamp_read' => $utimestamp,
]
);
}
return (bool) $ret;
}
/**
* Gets a private message
*
* This function abstracts the database backend so it can simply be replaced with another system
* This function abstracts the database backend so it can simply be
* replaced with another system
*
* @param integer $message_id
* @param integer $message_id Message to be retrieved.
*
* @return mixed False if it doesn't exist or a filled array otherwise
*/
function messages_get_message($message_id)
function messages_get_message(int $message_id)
{
global $config;
// Check if user has grants to read the message.
if (check_notification_readable($message_id) === false) {
return false;
}
$sql = sprintf(
"SELECT id_usuario_origen, id_usuario_destino, subject, mensaje, timestamp
FROM tmensajes
WHERE id_usuario_destino='%s' AND id_mensaje=%d",
$config['id_user'],
'SELECT *, nu.utimestamp_read > 0 as "read"
FROM tmensajes tm
LEFT JOIN tnotification_user nu
ON nu.id_mensaje = tm.id_mensaje
WHERE tm.id_mensaje=%d',
$message_id
);
$row = db_get_row_sql($sql);
@ -168,6 +289,8 @@ function messages_get_message($message_id)
return false;
}
$row['id_usuario_destino'] = $config['id_user'];
return $row;
}
@ -175,20 +298,21 @@ function messages_get_message($message_id)
/**
* Gets a sent message
*
* This function abstracts the database backend so it can simply be replaced with another system
* This function abstracts the database backend so it can simply be
* replaced with another system
*
* @param integer $message_id
* @param integer $message_id Message to be retrieved.
*
* @return mixed False if it doesn't exist or a filled array otherwise
*/
function messages_get_message_sent($message_id)
function messages_get_message_sent(int $message_id)
{
global $config;
$sql = sprintf(
"SELECT id_usuario_origen, id_usuario_destino, subject, mensaje, timestamp
FROM tmensajes
WHERE id_usuario_origen='%s' AND id_mensaje=%d",
"SELECT id_usuario_origen, subject, mensaje, timestamp
FROM tmensajes
WHERE id_usuario_origen='%s' AND id_mensaje=%d",
$config['id_user'],
$message_id
);
@ -198,6 +322,16 @@ function messages_get_message_sent($message_id)
return false;
}
$targets = get_notification_targets($message_id);
$row['id_usuario_destino'] = implode(
',',
$targets['users']
).','.implode(
',',
$targets['groups']
);
return $row;
}
@ -205,29 +339,45 @@ function messages_get_message_sent($message_id)
/**
* Counts private messages
*
* @param string $user
* @param boolean $incl_read Whether or not to include read messages
* @param string $user Target user.
* @param boolean $incl_read Whether or not to include read messages.
*
* @return integer The number of messages this user has
*/
function messages_get_count($user=false, $incl_read=false)
{
function messages_get_count(
string $user='',
bool $incl_read=false
) {
if (empty($user)) {
global $config;
$user = $config['id_user'];
}
if (empty($incl_read)) {
$filter = 'AND estado = 0';
if (!empty($incl_read)) {
// Do not filter.
$read = '';
} else {
$filter = '';
// Retrieve only unread messages.
$read = 'where t.read is null';
}
$sql = sprintf(
"SELECT COUNT(*)
FROM tmensajes WHERE id_usuario_destino='%s' %s",
'SELECT count(*) FROM (
SELECT tm.*, utimestamp_read > 0 as "read" FROM tmensajes tm
LEFT JOIN tnotification_user nu
ON tm.id_mensaje=nu.id_mensaje
LEFT JOIN (tnotification_group ng
INNER JOIN tusuario_perfil up
ON ng.id_group=up.id_grupo
AND up.id_grupo=ng.id_group
) ON tm.id_mensaje=ng.id_mensaje
WHERE utimestamp_erased is null
AND (up.id_usuario="%s" OR nu.id_user="%s" OR ng.id_group=0)
) t
%s',
$user,
$filter
$user,
$read
);
return (int) db_get_sql($sql);
@ -235,13 +385,13 @@ function messages_get_count($user=false, $incl_read=false)
/**
* Counts sended messages
* Counts messages sent.
*
* @param string $user
* @param string $user Target user.
*
* @return integer The number of messages this user has sent
*/
function messages_get_count_sent($user=false)
function messages_get_count_sent(string $user='')
{
if (empty($user)) {
global $config;
@ -250,7 +400,7 @@ function messages_get_count_sent($user=false)
$sql = sprintf(
"SELECT COUNT(*)
FROM tmensajes WHERE id_usuario_origen='%s'",
FROM tmensajes WHERE id_usuario_origen='%s'",
$user
);
@ -261,20 +411,28 @@ function messages_get_count_sent($user=false)
/**
* Get message overview in array
*
* @param string $order How to order them valid:
* (status (default), subject, timestamp, sender)
* @param string $order_dir Direction of order (ASC = Ascending, DESC = Descending)
* @param string $order How to order them valid:
* (status (default), subject, timestamp, sender).
* @param string $order_dir Direction of order
* (ASC = Ascending, DESC = Descending).
* @param boolean $incl_read Include read messages in return.
*
* @return integer The number of messages this user has
*/
function messages_get_overview($order='status', $order_dir='ASC')
{
function messages_get_overview(
string $order='status',
string $order_dir='ASC',
bool $incl_read=true
) {
global $config;
switch ($order) {
case 'timestamp':
case 'sender':
case 'subject':
case 'timestamp':{
}
case 'sender':{
}
case 'subject':{
}
break;
case 'status':
@ -287,21 +445,36 @@ function messages_get_overview($order='status', $order_dir='ASC')
$order .= ' DESC';
}
$result = [];
$return = db_get_all_rows_field_filter('tmensajes', 'id_usuario_destino', $config['id_user'], $order);
if ($return === false) {
return $result;
if (!empty($incl_read)) {
// Do not filter.
$read = '';
} else {
// Retrieve only unread messages.
$read = 'where t.read is null';
}
foreach ($return as $message) {
$result[$message['id_mensaje']]['sender'] = $message['id_usuario_origen'];
$result[$message['id_mensaje']]['subject'] = $message['subject'];
$result[$message['id_mensaje']]['timestamp'] = $message['timestamp'];
$result[$message['id_mensaje']]['status'] = $message['estado'];
}
$sql = sprintf(
'SELECT * FROM (
SELECT tm.*, utimestamp_read > 0 as "read" FROM tmensajes tm
LEFT JOIN tnotification_user nu
ON tm.id_mensaje=nu.id_mensaje
LEFT JOIN (tnotification_group ng
INNER JOIN tusuario_perfil up
ON ng.id_group=up.id_grupo
AND up.id_grupo=ng.id_group
) ON tm.id_mensaje=ng.id_mensaje
WHERE utimestamp_erased is null
AND (up.id_usuario="%s" OR nu.id_user="%s" OR ng.id_group=0)
) t
%s
ORDER BY %s',
$config['id_user'],
$config['id_user'],
$read,
$order
);
return $result;
return db_get_all_rows_sql($sql);
}
@ -309,19 +482,25 @@ function messages_get_overview($order='status', $order_dir='ASC')
* Get sent message overview in array
*
* @param string $order How to order them valid:
* (status (default), subject, timestamp, sender)
* @param string $order_dir Direction of order (ASC = Ascending, DESC = Descending)
* (status (default), subject, timestamp, sender).
* @param string $order_dir Direction of order
* (ASC = Ascending, DESC = Descending).
*
* @return integer The number of messages this user has
*/
function messages_get_overview_sent($order='timestamp', $order_dir='ASC')
{
function messages_get_overview_sent(
string $order='timestamp',
string $order_dir='ASC'
) {
global $config;
switch ($order) {
case 'timestamp':
case 'sender':
case 'subject':
case 'timestamp':{
}
case 'sender':{
}
case 'subject':{
}
break;
case 'status':
@ -334,19 +513,10 @@ function messages_get_overview_sent($order='timestamp', $order_dir='ASC')
$order .= ' DESC';
}
$result = [];
$return = db_get_all_rows_field_filter('tmensajes', 'id_usuario_origen', $config['id_user'], $order);
if ($return === false) {
return $result;
}
foreach ($return as $message) {
$result[$message['id_mensaje']]['dest'] = $message['id_usuario_destino'];
$result[$message['id_mensaje']]['subject'] = $message['subject'];
$result[$message['id_mensaje']]['timestamp'] = $message['timestamp'];
$result[$message['id_mensaje']]['status'] = $message['estado'];
}
return $result;
return db_get_all_rows_field_filter(
'tmensajes',
'id_usuario_origen',
$config['id_user'],
$order
);
}

View File

@ -0,0 +1,615 @@
<?php
/**
* Library. Notification system auxiliary functions.
*
* @category Library
* @package Pandora FMS
* @subpackage Community
* @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.
* ============================================================================
*/
define('NOTIFICATIONS_POSTPONE_FOREVER', -1);
/**
* Retrieves source ID for given source.
*
* @param string $source Source.
*
* @return integer source's id.
*/
function get_notification_source_id(string $source)
{
if (empty($source) === true) {
return false;
}
return db_get_value_sql(
"SELECT id
FROM `tnotification_source`
WHERE `description` LIKE '".$source."%'"
);
}
/**
* Converts description into a handable identifier
*
* @param string $desc Full description.
*
* @return string First word in lowercase. Empty string if no word detected.
*/
function notifications_desc_to_id(string $desc)
{
preg_match('/^[a-zA-Z]*/', $desc, $matches);
$match = $matches[0];
return isset($match) ? $match : '';
}
/**
* Retrieve all targets for given message.
*
* @param integer $id_message Message id.
*
* @return array of users and groups target of this message.
*/
function get_notification_targets(int $id_message)
{
$targets = [
'users' => [],
'groups' => [],
];
if (empty($id_message)) {
return $targets;
}
$ret = db_get_all_rows_sql(
sprintf(
'SELECT id_user
FROM tnotification_user nu
WHERE nu.id_mensaje = %d',
$id_message
)
);
if (is_array($ret)) {
foreach ($ret as $row) {
array_push(
$targets['users'],
get_user_fullname($row['id_user'])
);
}
}
$ret = db_get_all_rows_sql(
sprintf(
'SELECT COALESCE(tg.nombre,ng.id_group) as "id_group"
FROM tnotification_group ng
LEFT JOIN tgrupo tg
ON tg.id_grupo=ng.id_group
WHERE ng.id_mensaje = %d',
$id_message
)
);
if (is_array($ret)) {
foreach ($ret as $row) {
if ($row['id_group'] == '0') {
$row['id_group'] = '<b>'.__('All').'</b>';
}
array_push($targets['groups'], $row['id_group']);
}
}
return $targets;
}
/**
* Check if current user has grants to read this notification
*
* @param integer $id_message Target message.
*
* @return boolean true, read available. False if not.
*/
function check_notification_readable(int $id_message)
{
global $config;
if (empty($id_message)) {
return false;
}
$sql = sprintf(
'SELECT tm.*, utimestamp_read > 0 as "read" FROM tmensajes tm
LEFT JOIN tnotification_user nu
ON tm.id_mensaje=nu.id_mensaje
AND tm.id_mensaje=%d
LEFT JOIN (tnotification_group ng
INNER JOIN tusuario_perfil up
ON ng.id_group=up.id_grupo
AND up.id_grupo=ng.id_group
) ON tm.id_mensaje=ng.id_mensaje
WHERE utimestamp_erased is null
AND (up.id_usuario="%s" OR nu.id_user="%s" OR ng.id_group=0)',
$id_message,
$config['id_user'],
$config['id_user']
);
return (bool) db_get_value_sql($sql);
}
/**
* Returns the target users and groups assigned to be notified on
* desired source.
*
* @param integer $id_source
*
* @return array [users] and [groups] with the targets.
*/
function get_notification_source_targets(int $id_source)
{
$ret = [];
$users = db_get_all_rows_sql(
sprintf(
'SELECT
id_user,
IF(ns.user_editable = 1,nsu.also_mail,ns.also_mail) AS also_mail
FROM tnotification_source_user nsu
INNER JOIN tnotification_source ns
ON ns.id=nsu.id_source
WHERE ns.id = %d
AND ((ns.enabled is NULL OR ns.enabled != 0)
OR (nsu.enabled is NULL OR nsu.enabled != 0))',
$id_source
)
);
if ($users !== false) {
$i = 0;
foreach ($users as $user) {
$ret['users'][$i]['id_user'] = $user['id_user'];
$ret['users'][$i++]['also_mail'] = $user['also_mail'];
}
}
$groups = db_get_all_rows_sql(
sprintf(
'SELECT id_group,ns.also_mail
FROM tnotification_source_group nsg
INNER JOIN tnotification_source ns
ON ns.id=nsg.id_source
WHERE ns.id = %d
AND (ns.enabled is NULL OR ns.enabled != 0)',
$id_source
)
);
if ($groups !== false) {
$i = 0;
foreach ($groups as $group) {
$ret['groups'][$i]['id_group'] = $group['id_group'];
$ret['groups'][$i++]['also_mail'] = $group['also_mail'];
}
}
return $ret;
}
/**
* Return all info from tnotification_source
*
* @return array with sources info
*/
function notifications_get_all_sources()
{
return db_get_all_rows_in_table('tnotification_source');
}
/**
* Return the user sources to be inserted into a select
*
* @param integer $source_id Source database identificator
*
* @return array with the user id in keys and user id in value too
*/
function notifications_get_user_sources_for_select($source_id)
{
$users = db_get_all_rows_filter(
'tnotification_source_user',
['id_source' => $source_id],
'id_user'
);
// If fails or no one is selected, return empty array
if ($users === false) {
return [];
}
return index_array($users, 'id_user', 'id_user');
}
/**
* Return the groups sources to be inserted into a select
*
* @param integer $source_id Source database identificator
*
* @return array with the group id in keys and group name in value
*/
function notifications_get_group_sources_for_select($source_id)
{
$groups = notifications_get_group_sources(
['id_source' => $source_id],
['id_group']
);
return index_array($groups, 'id_group', 'name');
}
/**
* Get the group sources
*
* @param array $filter Filter of sql query.
*/
function notifications_get_group_sources($filter=[], $fields=[])
{
// Get only the tnotifications_source_group fields in addition to group name.
if (empty($fields)) {
$fields[] = 'tnsg.*';
}
$fields = array_map(
function ($field) {
if (!preg_match('/^tnsg./', $field)) {
$field = "tnsg.{$field}";
}
return $field;
},
$fields
);
// Get groups.
$groups = db_get_all_rows_filter(
'tnotification_source_group tnsg
LEFT JOIN tgrupo tg ON tnsg.id_group = tg.id_grupo',
$filter,
array_merge($fields, ['IFNULL(tg.nombre, "All") AS name'])
);
// If fails or no one is selected, return empty array
if ($groups === false) {
return [];
}
return $groups;
}
/**
* Delete a set of groups from notification source
*
* @param int Source id
* @param array Id of groups to be deleted
*
* @return boolean True if success. False otherwise.
*/
function notifications_remove_group_from_source($source_id, $groups)
{
// Source id is mandatory
if (!isset($source_id)) {
return false;
}
// Delete from database
return db_process_sql_delete(
'tnotification_source_group',
[
'id_group' => $groups,
'id_source' => $source_id,
]
) !== false;
}
/**
* Delete a set of users from notification source
*
* @param int Source id
* @param array Id of users to be deleted
*
* @return boolean True if success. False otherwise.
*/
function notifications_remove_users_from_source($source_id, $users)
{
// Source id is mandatory
if (!isset($source_id)) {
return false;
}
// Delete from database
return db_process_sql_delete(
'tnotification_source_user',
[
'id_user' => $users,
'id_source' => $source_id,
]
) !== false;
}
/**
* Insert a set of groups to notification source
*
* @param int Source id
* @param array Id of groups to be deleted
*
* @return boolean True if success. False otherwise.
*/
function notifications_add_group_to_source($source_id, $groups)
{
// Source id is mandatory
if (!isset($source_id)) {
return false;
}
// Insert into database all groups passed
$res = true;
foreach ($groups as $group) {
if (empty($group)) {
continue;
}
$res = $res && db_process_sql_insert(
'tnotification_source_group',
[
'id_group' => $group,
'id_source' => $source_id,
]
) !== false;
}
return $res;
}
/**
* Insert a set of users to notification source
*
* @param int Source id
* @param array Id of users to be deleted
*
* @return boolean True if success. False otherwise.
*/
function notifications_add_users_to_source($source_id, $users)
{
// Source id is mandatory
if (!isset($source_id)) {
return false;
}
// Insert into database all groups passed
$res = true;
foreach ($users as $user) {
if (empty($user)) {
continue;
}
$res = $res && db_process_sql_insert(
'tnotification_source_user',
[
'id_user' => $user,
'id_source' => $source_id,
]
) !== false;
}
return $res;
}
/**
* Get the groups that not own to a source and, for that reason, they can be
* added to the source.
*
* @param integer $source_id Source id.
* @return array Indexed by id group all selectable groups.
*/
function notifications_get_group_source_not_configured($source_id)
{
$groups_selected = notifications_get_group_sources_for_select($source_id);
$all_groups = users_get_groups_for_select(false, 'AR', false, true, $groups_selected);
return array_diff($all_groups, $groups_selected);
}
/**
* Get the users that not own to a source and, for that reason, they can be
* added to the source.
*
* @param integer $source_id
* @return array Indexed by id user, all selectable users.
*/
function notifications_get_user_source_not_configured($source_id)
{
$users_selected = array_keys(notifications_get_user_sources_for_select($source_id));
$users = get_users(
'id_user',
['!id_user' => $users_selected],
['id_user']
);
return index_array($users, 'id_user', 'id_user');
}
/**
* Print the notification ball to see unread messages
*
* @return string with HTML code of notification ball
*/
function notifications_print_ball()
{
$num_notifications = messages_get_count();
$class_status = $num_notifications == 0 ? 'notification-ball-no-messages' : 'notification-ball-new-messages';
return "<div class='notification-ball $class_status' id='notification-ball-header'>
$num_notifications
</div>";
}
/**
* Print notification configuration global
*
* @param array notification source data
*
* @return string with HTML of source configuration
*/
function notifications_print_global_source_configuration($source)
{
// Get some values to generate the title
$id = notifications_desc_to_id($source['description']);
$switch_values = [
'name' => 'enable-'.$id,
'value' => $source['enabled'],
];
// Search if group all is set and handle that situation
$source_groups = notifications_get_group_sources_for_select($source['id']);
$is_group_all = isset($source_groups['0']);
if ($is_group_all) {
unset($source_groups['0']);
}
// Generate the title
$html_title = "<div class='global-config-notification-title'>";
$html_title .= html_print_switch($switch_values);
$html_title .= "<h2>{$source['description']}</h2>";
$html_title .= '</div>';
// Generate the html for title
$html_selectors = "<div class='global-config-notification-selectors'>";
$html_selectors .= notifications_print_source_select_box(notifications_get_user_sources_for_select($source['id']), 'users', $id, $is_group_all);
$html_selectors .= notifications_print_source_select_box($source_groups, 'groups', $id, $is_group_all);
$html_selectors .= '</div>';
// Generate the checkboxes and time select
$html_checkboxes = "<div class='global-config-notification-checkboxes'>";
$html_checkboxes .= ' <span>';
$html_checkboxes .= html_print_checkbox("all-$id", 1, $is_group_all, true, false, 'notifications_disable_source(event)');
$html_checkboxes .= __('Notify all users');
$html_checkboxes .= ' </span><br><span>';
$html_checkboxes .= html_print_checkbox("mail-$id", 1, $source['also_mail'], true);
$html_checkboxes .= __('Also email users with notification content');
$html_checkboxes .= ' </span><br><span>';
$html_checkboxes .= html_print_checkbox("user-$id", 1, $source['user_editable'], true);
$html_checkboxes .= __('Users cannot modify notification preferences');
$html_checkboxes .= ' </span>';
$html_checkboxes .= '</div>';
// Generate the select with the time
$html_select_pospone = __('Users can postpone notifications up to');
$html_select_pospone .= html_print_select(
[
SECONDS_5MINUTES => __('5 minutes'),
SECONDS_15MINUTES => __('15 minutes'),
SECONDS_12HOURS => __('12 hours'),
SECONDS_1DAY => __('1 day'),
SECONDS_1WEEK => __('1 week'),
SECONDS_15DAYS => __('15 days'),
SECONDS_1MONTH => __('1 month'),
NOTIFICATIONS_POSTPONE_FOREVER => __('forever'),
],
"postpone-{$id}",
$source['max_postpone_time'],
'',
'',
0,
true
);
// Return all html
return $html_title.$html_selectors.$html_checkboxes.$html_select_pospone;
}
/**
* Print select boxes of notified users or groups
*
* @param array $info_selec All info required for build the selector
* @param string $id users|groups
* @param string $source_id Id of source
* @param boolean $disabled Disable the selectors
*
* @return string HTML with the generated selector
*/
function notifications_print_source_select_box($info_selec, $id, $source_id, $disabled)
{
$title = $id == 'users' ? __('Notified users') : __('Notified groups');
$add_title = $id == 'users' ? __('Add users') : __('Add groups');
$delete_title = $id == 'users' ? __('Delete users') : __('Delete groups');
// Generate the HTML
$html_select = "<div class='global-config-notification-single-selector'>";
$html_select .= ' <div>';
$html_select .= " <h4>$title</h4>";
// Put a true if empty sources to avoid to sow the 'None' value
$html_select .= html_print_select(empty($info_selec) ? true : $info_selec, "multi-{$id}-{$source_id}[]", 0, false, '', '', true, true, true, '', $disabled);
$html_select .= ' </div>';
$html_select .= " <div class='global-notifications-icons'>";
$html_select .= html_print_image('images/input_add.png', true, ['title' => $add_title, 'onclick' => "add_source_dialog('$id', '$source_id')"]);
$html_select .= html_print_image('images/input_delete.png', true, ['title' => $delete_title, 'onclick' => "remove_source_elements('$id', '$source_id')"]);
$html_select .= ' </div>';
$html_select .= '</div>';
return $html_select;
}
/**
* Print the select with right and left arrows to select new sources
* (groups or users).
*
* @param array $info_selec Array with source info.
* @param string $users users|groups.
* @param source $source_id Source id.
* @return string HTML with the select code.
*/
function notifications_print_two_ways_select($info_selec, $users, $source_id)
{
$html_select = "<div class='global_config_notifications_dialog_add'>";
$html_select .= html_print_select(empty($info_selec) ? true : $info_selec, "all-multi-{$users}-{$source_id}[]", 0, false, '', '', true, true, true, '');
$html_select .= "<div class='global_config_notifications_two_ways_form_arrows'>";
$html_select .= html_print_image('images/darrowright.png', true, ['title' => $add_title, 'onclick' => "notifications_modify_two_ways_element('$users', '$source_id', 'add')"]);
$html_select .= html_print_image('images/darrowleft.png', true, ['title' => $add_title, 'onclick' => "notifications_modify_two_ways_element('$users', '$source_id', 'remove')"]);
$html_select .= '</div>';
$html_select .= html_print_select(true, "selected-multi-{$users}-{$source_id}[]", 0, false, '', '', true, true, true, '');
$html_select .= '</div>';
$html_select .= html_print_button(__('Add'), 'Add', false, "notifications_add_source_element_to_database('$users', '$source_id')", "class='sub add'", true);
return $html_select;
}

View File

@ -1,20 +1,29 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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
// 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.
/**
* @package Include
* @subpackage Servers
* Auxiliary functions to manage servers.
*
* @category Library
* @package Pandora FMS
* @subpackage Opensource
* @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.
* ============================================================================
*/
@ -921,3 +930,64 @@ function servers_get_status($id_server)
$serverinfo = servers_get_info($id_server);
return $serverinfo[$id_server];
}
/**
* Return server name based on identifier.
*
* @param integer $server Server identifier.
*
* @return string Server name
*/
function servers_get_server_string_name(int $server)
{
switch ($server) {
case SERVER_TYPE_DATA:
return __('Data server');
case SERVER_TYPE_NETWORK:
return __('Network server');
case SERVER_TYPE_SNMP:
return __('SNMP server');
case SERVER_TYPE_ENTERPRISE_ICMP:
return __('Enterprise ICMP server');
case SERVER_TYPE_ENTERPRISE_SNMP:
return __('Enterprise SNMP server');
case SERVER_TYPE_PLUGIN:
return __('Plugin server');
case SERVER_TYPE_PREDICTION:
return __('Prediction Server');
case SERVER_TYPE_WMI:
return __('WMI server');
case SERVER_TYPE_WEB:
return __('Web server');
case SERVER_TYPE_EXPORT:
return __('Export server');
case SERVER_TYPE_INVENTORY:
return __('Inventory server');
case SERVER_TYPE_EVENT:
return __('Event server');
case SERVER_TYPE_RECON:
return __('Discovery server');
case SERVER_TYPE_SYSLOG:
return __('Syslog server');
case SERVER_TYPE_WUX:
return __('WUX server');
default:
return __('N/A');
}
}

View File

@ -144,7 +144,7 @@ function gd_histogram($width, $height, $mode, $data, $max_value, $font, $title,
foreach ($data as $label => $value) {
imagefilledrectangle($image, $leftmargin, $margin_up, (($value / $size_per) + $leftmargin), ($margin_up + $rectangle_height - 1), $colors[$c]);
if ($mode != 2) {
ImageTTFText($image, $fontsize, 0, 0, ($margin_up + 8), $black, $font, $label);
imagettftext($image, $fontsize, 0, 0, ($margin_up + 8), $black, $font, $label);
}
$margin_up += ($rectangle_height + 1);
@ -164,9 +164,9 @@ function gd_histogram($width, $height, $mode, $data, $max_value, $font, $title,
imageline($image, $risk_low, 0, $risk_low, $height, $grey);
imageline($image, $risk_med, 0, $risk_med, $height, $grey);
imageline($image, $risk_high, 0, $risk_high, $height, $grey);
ImageTTFText($image, $fontsize, 0, ($risk_low - 20), $height, $grey, $font, 'Low');
ImageTTFText($image, $fontsize, 0, ($risk_med - 20), $height, $grey, $font, 'Med.');
ImageTTFText($image, $fontsize, 0, ($risk_high - 25), $height, $grey, $font, 'High');
imagettftext($image, $fontsize, 0, ($risk_low - 20), $height, $grey, $font, 'Low');
imagettftext($image, $fontsize, 0, ($risk_med - 20), $height, $grey, $font, 'Med.');
imagettftext($image, $fontsize, 0, ($risk_high - 25), $height, $grey, $font, 'High');
}
imagepng($image);
@ -279,7 +279,7 @@ function gd_progress_bubble($width, $height, $progress, $title, $font, $out_of_l
// Write the value
$size = imagettfbbox($fontsize, 0, $font, $value_text);
ImageTTFText(
imagettftext(
$image,
$fontsize,
0,
@ -409,12 +409,12 @@ function drawRating($rating, $width, $height, $font, $out_of_lim_str, $mode, $fo
if ($rating > 50) {
if ($rating > 100) {
ImageTTFText($image, ($fontsize + 2), 0, ($width / 4), (($height / 2) + ($height / 5)), $back, $font, $out_of_lim_str);
imagettftext($image, ($fontsize + 2), 0, ($width / 4), (($height / 2) + ($height / 5)), $back, $font, $out_of_lim_str);
} else {
ImageTTFText($image, $fontsize, 0, (($width / 2) - ($width / 10)), (($height / 2) + ($height / 5)), $back, $font, $value_text);
imagettftext($image, $fontsize, 0, (($width / 2) - ($width / 10)), (($height / 2) + ($height / 5)), $back, $font, $value_text);
}
} else {
ImageTTFText($image, $fontsize, 0, (($width / 2) - ($width / 10)), (($height / 2) + ($height / 5)), $text, $font, $value_text);
imagettftext($image, $fontsize, 0, (($width / 2) - ($width / 10)), (($height / 2) + ($height / 5)), $text, $font, $value_text);
}
break;

View File

@ -4273,6 +4273,89 @@ div#dialog_messages table th:last-child {
text-align: right;
}
/*
* ---------------------------------------------------------------------
* - Notifications
* ---------------------------------------------------------------------
*/
.notification-ball {
border: white solid 2px;
border-radius: 50px;
width: 18px;
height: 18px;
display: flex;
justify-content: center;
align-items: center;
}
.notification-ball-no-messages {
background-color: #82b92e;
}
.notification-ball-new-messages {
background-color: #fc4444;
}
.global-config-notification-title {
display: flex;
flex-direction: row;
align-items: center;
}
.global-config-notification-title h2 {
margin-left: 10px;
}
.global-config-notification-checkboxes :first-child {
font-weight: bold;
}
.global-config-notification-selectors {
display: flex;
flex-direction: row;
margin-bottom: 10px;
}
.global-config-notification-selectors h4 {
margin: 0;
}
.global-config-notification-single-selector,
.global_config_notifications_dialog_add select {
display: flex;
width: 100%;
padding: 0 10px;
}
.global-config-notification-single-selector :first-child,
.global-config-notification-single-selector :first-child select {
width: 99%;
}
.global-config-notification-single-selector :last-child,
.global_config_notifications_dialog_add_wrapper {
flex-direction: column;
display: flex;
justify-content: flex-end;
}
.global_config_notifications_dialog_add {
display: flex;
flex-direction: row;
margin: 8px;
}
.global_config_notifications_two_ways_form_arrows {
display: flex;
flex-flow: column;
justify-content: center;
margin: 0 5px;
}
.global_config_notifications_two_ways_form_arrows img {
margin: 15px 0;
}
/* jQuery dialog */
.no-close .ui-dialog-titlebar-close {
display: none;

View File

@ -112,8 +112,8 @@
</div>
<div style='height: 10px'>
<?php
$version = '7.0NG.731';
$build = '190208';
$version = '7.0NG.731';
$build = '190208';
$banner = "v$version Build $build";
error_reporting(0);

View File

@ -375,6 +375,11 @@ $sub['operation/users/user_edit']['text'] = __('Edit my user');
$sub['operation/users/user_edit']['id'] = 'Edit my user';
$sub['operation/users/user_edit']['refr'] = 0;
// Users
$sub['operation/users/user_edit_notifications']['text'] = __('Configure user notifications');
$sub['operation/users/user_edit_notifications']['id'] = 'Configure user notifications';
$sub['operation/users/user_edit_notifications']['refr'] = 0;
// ANY user can chat with other user and dogs.
// Users
$sub['operation/users/webchat']['text'] = __('WebChat');

View File

@ -1,24 +1,39 @@
<?php
/**
* Extension to manage a list of gateways and the node address where they should
* point to.
*
* @category Extensions
* @package Pandora FMS
* @subpackage Community
* @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.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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.
// Load global vars
global $config;
require_once 'include/functions_users.php';
require_once 'include/functions_groups.php';
require_once 'include/functions_io.php';
// params
// Parse parameters.
$new_msg = get_parameter('new_msg', 0);
$dst_user = get_parameter('dst_user');
$dst_group = get_parameter('dst_group');
@ -30,23 +45,42 @@ $show_sent = get_parameter('show_sent', 0);
$buttons['message_list'] = [
'active' => false,
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_list">'.html_print_image('images/email_inbox.png', true, ['title' => __('Received messages')]).'</a>',
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_list">'.html_print_image(
'images/email_inbox.png',
true,
['title' => __('Received messages')]
).'</a>',
];
$buttons['sent_messages'] = [
'active' => false,
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_list&amp;show_sent=1">'.html_print_image('images/email_outbox.png', true, ['title' => __('Sent messages')]).'</a>',
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_list&amp;show_sent=1">'.html_print_image(
'images/email_outbox.png',
true,
['title' => __('Sent messages')]
).'</a>',
];
$buttons['create_message'] = [
'active' => true,
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_edit">'.html_print_image('images/new_message.png', true, ['title' => __('Create message')]).'</a>',
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_edit">'.html_print_image(
'images/new_message.png',
true,
['title' => __('Create message')]
).'</a>',
];
// Header
ui_print_page_header(__('Messages'), 'images/email_mc.png', false, '', false, $buttons);
// Header.
ui_print_page_header(
__('Messages'),
'images/email_mc.png',
false,
'',
false,
$buttons
);
// read a message
// Read a message.
if ($read_message) {
$message_id = (int) get_parameter('id_message');
if ($show_sent) {
@ -56,10 +90,10 @@ if ($read_message) {
messages_process_read($message_id);
}
if ($message == false) {
if ($message === false) {
echo '<div>'.__('This message does not exist in the system').'</div>';
return;
// Move out of this page and go processing other pages
// Move out of this page and go processing other pages.
}
$user_name = get_user_fullname($message['id_usuario_origen']);
@ -78,13 +112,28 @@ if ($read_message) {
$table->data = [];
$table->data[0][0] = __('Sender');
$table->data[0][1] = $user_name.' '.__('at').' '.ui_print_timestamp($message['timestamp'], true, ['prominent' => 'timestamp']);
$table->data[0][1] = $user_name.' '.__('at').' '.ui_print_timestamp(
$message['timestamp'],
true,
['prominent' => 'timestamp']
);
$table->data[1][0] = __('Destination');
$table->data[1][1] = $dst_name;
$table->data[2][0] = __('Subject');
$table->data[2][1] = html_print_input_text_extended('subject', $message['subject'], 'text-subject', '', 50, 70, true, false, '', 'readonly');
$table->data[2][1] = html_print_input_text_extended(
'subject',
$message['subject'],
'text-subject',
'',
50,
70,
true,
false,
'',
'readonly'
);
$order = [
"\r\n",
@ -95,17 +144,27 @@ if ($read_message) {
$parsed_message = str_replace($order, $replace, $message['mensaje']);
$table->data[3][0] = __('Message');
$table->data[3][1] = html_print_textarea('message', 15, 255, $message['mensaje'], 'readonly', true);
$table->data[3][1] = html_print_textarea(
'message',
15,
255,
$message['mensaje'],
'readonly',
true
);
// Prevent RE: RE: RE:
// Prevent RE: RE: RE:.
if (strstr($message['subject'], 'RE:')) {
$new_subj = $message['subject'];
} else {
$new_subj = 'RE: '.$message['subject'];
}
// Start the message much like an e-mail reply
$new_msg = "\n\n\nOn ".date($config['date_format'], $message['timestamp']).' '.$user_name.' '.__('wrote').":\n\n".$message['mensaje'];
// Start the message much like an e-mail reply.
$new_msg = "\n\n\nOn ".date(
$config['date_format'],
$message['timestamp']
).' '.$user_name.' '.__('wrote').":\n\n".$message['mensaje'];
echo '<form id="delete_message" method="post" action="index.php?sec=message_list&amp;sec2=operation/messages/message_list&show_sent=1&amp;delete_message=1&amp;id='.$message_id.'">';
html_print_table($table);
@ -119,17 +178,33 @@ if ($read_message) {
echo '</form>';
echo "<div class= 'action-buttons' style=' width:".$table->width."'>";
html_print_submit_button(__('Delete'), 'delete_btn', false, 'form="delete_message" class="sub delete"');
html_print_submit_button(
__('Delete'),
'delete_btn',
false,
'form="delete_message" class="sub delete"'
);
echo '&nbsp';
html_print_submit_button(__('Reply'), 'reply', false, 'form="reply_message" class="sub next"');
html_print_submit_button(
__('Reply'),
'reply',
false,
'form="reply_message" class="sub next"'
);
echo '</div>';
return;
}
// Create message (destination user)
// Create message (destination user).
if (($new_msg) && (!empty($dst_user)) && (!$reply)) {
$return = messages_create_message($config['id_user'], $dst_user, $subject, $message);
$return = messages_create_message(
$config['id_user'],
[$dst_user],
[],
$subject,
$message
);
$user_name = get_user_fullname($dst_user);
if (!$user_name) {
@ -143,9 +218,15 @@ if (($new_msg) && (!empty($dst_user)) && (!$reply)) {
);
}
// Create message (destination group)
// Create message (destination group).
if (($new_msg) && ($dst_group != '') && (!$reply)) {
$return = messages_create_group($config['id_user'], $dst_group, $subject, $message);
$return = messages_create_message(
$config['id_user'],
[],
[$dst_group],
$subject,
$message
);
ui_print_result_message(
$return,
@ -154,8 +235,8 @@ if (($new_msg) && ($dst_group != '') && (!$reply)) {
);
}
// message creation form
// user info
// Message creation form.
// User info.
$own_info = get_user_info($config['id_user']);
$table = new stdClass();
@ -174,12 +255,28 @@ if (!empty($own_info['fullname'])) {
$table->data[1][0] = __('Destination');
$is_admin = (bool) db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']);
$is_admin = (bool) db_get_value(
'is_admin',
'tusuario',
'id_user',
$config['id_user']
);
if ($is_admin) {
$users_full = db_get_all_rows_filter('tusuario', [], ['id_user', 'fullname']);
$users_full = db_get_all_rows_filter(
'tusuario',
[],
[
'id_user',
'fullname',
]
);
} else {
$users_full = groups_get_users(array_keys(users_get_groups()), false, false);
$users_full = groups_get_users(
array_keys(users_get_groups()),
false,
false
);
}
$users = [];
@ -187,10 +284,10 @@ foreach ($users_full as $user_id => $user_info) {
$users[$user_info['id_user']] = $user_info['fullname'];
}
// Check if the user to reply is in the list, if not add reply user
// Check if the user to reply is in the list, if not add reply user.
if ($reply) {
if (!array_key_exists($dst_user, $users)) {
// Add the user to reply
// Add the user to reply.
$user_reply = db_get_row('tusuario', 'id_user', $dst_user);
$users[$user_reply['id_user']] = $user_reply['fullname'];
}
@ -205,21 +302,61 @@ if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) {
}
$groups = users_get_groups($config['id_user'], 'AR');
// Get a list of all groups
$table->data[1][1] = html_print_select($users, 'dst_user', $dst_user, '', __('Select user'), false, true, false, '', false);
// Get a list of all groups.
$table->data[1][1] = html_print_select(
$users,
'dst_user',
$dst_user,
'',
__('Select user'),
false,
true,
false,
'',
false
);
$table->data[1][1] .= '&nbsp;&nbsp;'.__('OR').'&nbsp;&nbsp;';
$table->data[1][1] .= html_print_select_groups($config['id_user'], 'AR', $return_all_groups, 'dst_group', $dst_group, '', __('Select group'), '', true);
$table->data[1][1] .= html_print_select_groups(
$config['id_user'],
'AR',
$return_all_groups,
'dst_group',
$dst_group,
'',
__('Select group'),
'',
true
);
$table->data[2][0] = __('Subject');
$table->data[2][1] = html_print_input_text('subject', $subject, '', 50, 70, true);
$table->data[2][1] = html_print_input_text(
'subject',
$subject,
'',
50,
70,
true
);
$table->data[3][0] = __('Message');
$table->data[3][1] = html_print_textarea('message', 15, 255, $message, '', true);
$table->data[3][1] = html_print_textarea(
'message',
15,
255,
$message,
'',
true
);
echo '<form method="post" action="index.php?sec=message_list&amp;sec2=operation/messages/message_edit&amp;new_msg=1">';
html_print_table($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
html_print_submit_button(__('Send message'), 'send_mes', false, 'class="sub wand"');
echo '</form>';
echo '</div>';
html_print_submit_button(
__('Send message'),
'send_mes',
false,
'class="sub wand"'
);
echo '</form>';
echo '</div>';

View File

@ -1,16 +1,32 @@
<?php
/**
* Extension to manage a list of gateways and the node address where they should
* point to.
*
* @category Extensions
* @package Pandora FMS
* @subpackage Community
* @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.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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 'include/functions_messages.php';
$delete_msg = get_parameter('delete_message', 0);
@ -20,7 +36,7 @@ $mark_unread = get_parameter('mark_unread', 0);
$active_list = true;
$active_sent = false;
if ($show_sent) {
if ($show_sent !== 0) {
$active_list = false;
$active_sent = true;
}
@ -37,11 +53,22 @@ $buttons['sent_messages'] = [
$buttons['create_message'] = [
'active' => false,
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_edit">'.html_print_image('images/new_message.png', true, ['title' => __('Create message')]).'</a>',
'text' => '<a href="index.php?sec=message_list&sec2=operation/messages/message_edit">'.html_print_image(
'images/new_message.png',
true,
['title' => __('Create message')]
).'</a>',
];
if (!is_ajax()) {
ui_print_page_header(__('Messages'), 'images/email_mc.png', false, '', false, $buttons);
ui_print_page_header(
__('Messages'),
'images/email_mc.png',
false,
'',
false,
$buttons
);
}
if ($mark_unread) {
@ -52,7 +79,7 @@ if ($mark_unread) {
if ($delete_msg) {
$id = (int) get_parameter('id');
$result = messages_delete_message($id);
// Delete message function will actually check the credentials
// Delete message function will actually check the credentials.
ui_print_result_message(
$result,
__('Successfully deleted'),
@ -61,13 +88,10 @@ if ($delete_msg) {
}
if ($multiple_delete) {
$ids = (array) get_parameter('delete_multiple', []);
$ids = (array) get_parameter('delete_multiple_messages', []);
foreach ($ids as $id) {
$result = db_process_sql_delete(
'tmensajes',
['id_mensaje' => $id]
);
$result = messages_delete_message($id);
if ($result === false) {
break;
@ -82,21 +106,23 @@ if ($multiple_delete) {
}
if ($show_sent) {
// sent view
// Sent view.
$num_messages = messages_get_count_sent($config['id_user']);
if ($num_messages > 0 && !is_ajax()) {
echo '<p>'.__('You have').' <b>'.$num_messages.'</b> '.' '.__('sent message(s)').'.</p>';
echo '<p>'.__('You have').' <b>'.$num_messages.'</b> '.__('sent message(s)').'.</p>';
}
$messages = messages_get_overview_sent('', 'DESC');
} else {
// messages received
$num_messages = messages_get_count($config['id_user']);
// Messages received.
$num_messages = messages_get_count($config['id_user'], true);
if ($num_messages > 0 && !is_ajax()) {
echo '<p>'.__('You have').' <b>'.$num_messages.'</b> '.' '.__('unread message(s)').'.</p>';
$unread_messages = messages_get_count($config['id_user']);
echo '<p>'.__('You have').' <b>'.$unread_messages.'</b> '.__('unread message(s)').'.</p>';
$messages = messages_get_overview();
} else {
$messages = messages_get_overview('status', 'ASC', false);
}
$messages = messages_get_overview();
}
if (empty($messages)) {
@ -139,10 +165,12 @@ if (empty($messages)) {
$table->head[3] = __('Timestamp');
$table->head[4] = __('Delete').html_print_checkbox('all_delete_messages', 0, false, true, false);
foreach ($messages as $message_id => $message) {
foreach ($messages as $message) {
$message_id = $message['id_mensaje'];
$data = [];
$data[0] = '';
if ($message['status'] == 1) {
if ($message['read'] == 1) {
if ($show_sent) {
$data[0] .= '<a href="index.php?sec=message_list&amp;sec2=operation/messages/message_edit&read_message=1&amp;show_sent=1&amp;id_message='.$message_id.'">';
$data[0] .= html_print_image('images/email_open.png', true, ['border' => 0, 'title' => __('Click to read')]);
@ -202,10 +230,10 @@ if (empty($messages)) {
if ($show_sent) {
$data[4] = '<a href="index.php?sec=message_list&amp;sec2=operation/messages/message_list&show_sent=1&delete_message=1&id='.$message_id.'"
onClick="javascript:if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>'.html_print_checkbox_extended('delete_multiple_messages[]', $message_id, false, false, '', 'class="check_delete_messages"', true);
onClick="javascript:if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>'.html_print_checkbox_extended('delete_multiple_messages[]', $message_id, false, false, '', 'class="check_delete_messages"', true);
} else {
$data[4] = '<a href="index.php?sec=message_list&amp;sec2=operation/messages/message_list&delete_message=1&id='.$message_id.'"
onClick="javascript:if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>'.html_print_checkbox_extended('delete_multiple_messages[]', $message_id, false, false, '', 'class="check_delete_messages"', true);
onClick="javascript:if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>'.html_print_checkbox_extended('delete_multiple_messages[]', $message_id, false, false, '', 'class="check_delete_messages"', true);
}
array_push($table->data, $data);

View File

@ -0,0 +1,87 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 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.
// Load global vars
global $config;
check_login();
enterprise_hook('open_meta_frame');
require_once $config['homedir'].'/include/functions_profile.php';
require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_groups.php';
require_once $config['homedir'].'/include/functions_visual_map.php';
$meta = false;
if (enterprise_installed() && defined('METACONSOLE')) {
$meta = true;
}
$id = get_parameter_get('id', $config['id_user']);
// ID given as parameter
$status = get_parameter('status', -1);
// Flag to print action status message
$user_info = get_user_info($id);
$id = $user_info['id_user'];
// This is done in case there are problems with uppercase/lowercase (MySQL auth has that problem)
if ((!check_acl($config['id_user'], users_get_groups($id), 'UM'))
and ($id != $config['id_user'])
) {
db_pandora_audit('ACL Violation', 'Trying to view a user without privileges');
include 'general/noaccess.php';
exit;
}
// If current user is editing himself or if the user has UM (User Management) rights on any groups the user is part of AND the authorization scheme allows for users/admins to update info
if (($config['id_user'] == $id || check_acl($config['id_user'], users_get_groups($id), 'UM')) && $config['user_can_update_info']) {
$view_mode = false;
} else {
$view_mode = true;
}
$urls = [];
if (is_metaconsole()) {
user_meta_print_header();
$urls['main'] = 'index.php?sec=advanced&amp;sec2=advanced/users_setup&amp;tab=user_edit';
} else {
$urls['main'] = 'index.php?sec=workspace&amp;sec2=operation/users/user_edit';
$urls['notifications'] = 'index.php?sec=workspace&amp;sec2=operation/users/user_edit_notifications';
$buttons = [
'main' => [
'active' => $_GET['sec2'] === 'operation/users/user_edit',
'text' => "<a href='{$urls['main']}'>".html_print_image(
'images/user_green.png',
true,
['title' => __('User management')]
).'</a>',
],
'notifications' => [
'active' => $_GET['sec2'] === 'operation/users/user_edit_notifications',
'text' => "<a href='{$urls['notifications']}'>".html_print_image(
'images/alerts_template.png',
true,
['title' => __('User notifications')]
).'</a>',
],
];
ui_print_page_header(
__('User detail editor'),
'images/op_workspace.png',
false,
'',
false,
$buttons
);
}

View File

@ -0,0 +1,24 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 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.
// Load global vars
global $config;
// Load the header
require($config['homedir'] . "/operation/users/user_edit_header.php");
// TODO
?>

View File

@ -719,20 +719,6 @@ CREATE TABLE IF NOT EXISTS `tlink` (
PRIMARY KEY (`id_link`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tmensajes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tmensajes` (
`id_mensaje` int(10) unsigned NOT NULL auto_increment,
`id_usuario_origen` varchar(60) NOT NULL default '',
`id_usuario_destino` varchar(60) NOT NULL default '',
`mensaje` text NOT NULL,
`timestamp` bigint (20) unsigned NOT NULL default '0',
`subject` varchar(255) NOT NULL default '',
`estado` int(4) unsigned NOT NULL default '0',
PRIMARY KEY (`id_mensaje`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tmodule_group`
-- ----------------------------------------------------------------------
@ -1177,6 +1163,113 @@ CREATE TABLE IF NOT EXISTS `treset_pass_history` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tnotification_source`
-- -----------------------------------------------------
CREATE TABLE `tnotification_source` (
`id` serial,
`description` VARCHAR(255) DEFAULT NULL,
`icon` text,
`max_postpone_time` int(11) DEFAULT NULL,
`enabled` int(1) DEFAULT NULL,
`user_editable` int(1) DEFAULT NULL,
`also_mail` int(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tmensajes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tmensajes` (
`id_mensaje` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_usuario_origen` VARCHAR(60) NOT NULL DEFAULT '',
`mensaje` TEXT NOT NULL,
`timestamp` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
`subject` VARCHAR(255) NOT NULL DEFAULT '',
`estado` INT(4) UNSIGNED NOT NULL DEFAULT '0',
`url` TEXT,
`response_mode` VARCHAR(200) DEFAULT NULL,
`citicity` INT(10) UNSIGNED DEFAULT '0',
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`subtype` VARCHAR(255) DEFAULT '',
PRIMARY KEY (`id_mensaje`),
UNIQUE KEY `id_mensaje` (`id_mensaje`),
KEY `tsource_fk` (`id_source`),
CONSTRAINT `tsource_fk` FOREIGN KEY (`id_source`) REFERENCES `tnotification_source` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_user`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_user` (
`id_mensaje` INT(10) UNSIGNED NOT NULL,
`id_user` VARCHAR(60) NOT NULL,
`utimestamp_read` BIGINT(20),
`utimestamp_erased` BIGINT(20),
`postpone` INT,
PRIMARY KEY (`id_mensaje`,`id_user`),
FOREIGN KEY (`id_mensaje`) REFERENCES `tmensajes`(`id_mensaje`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_user`) REFERENCES `tusuario`(`id_user`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_group`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_group` (
`id_mensaje` INT(10) UNSIGNED NOT NULL,
`id_group` mediumint(4) UNSIGNED NOT NULL,
PRIMARY KEY (`id_mensaje`,`id_group`),
FOREIGN KEY (`id_mensaje`) REFERENCES `tmensajes`(`id_mensaje`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_source_user`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_source_user` (
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`id_user` VARCHAR(60),
`enabled` INT(1) DEFAULT NULL,
`also_mail` INT(1) DEFAULT NULL,
PRIMARY KEY (`id_source`,`id_user`),
FOREIGN KEY (`id_source`) REFERENCES `tnotification_source`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_user`) REFERENCES `tusuario`(`id_user`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_source_group`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_source_group` (
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`id_group` mediumint(4) unsigned NOT NULL,
PRIMARY KEY (`id_source`,`id_group`),
INDEX (`id_group`),
FOREIGN KEY (`id_source`) REFERENCES `tnotification_source`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnotification_source_user`
-- ----------------------------------------------------------------------
CREATE TABLE `tnotification_source_group_user` (
`id_source` BIGINT(20) UNSIGNED NOT NULL,
`id_group` mediumint(4) unsigned NOT NULL,
`id_user` VARCHAR(60),
`enabled` INT(1) DEFAULT NULL,
`also_mail` INT(1) DEFAULT NULL,
PRIMARY KEY (`id_source`,`id_user`),
FOREIGN KEY (`id_source`) REFERENCES `tnotification_source`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_user`) REFERENCES `tusuario`(`id_user`)
ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (`id_group`) REFERENCES `tnotification_source_group`(`id_group`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tnews`
-- ----------------------------------------------------------------------

View File

@ -1267,3 +1267,22 @@ INSERT INTO `tcontainer` SET `name` = 'Default graph container';
INSERT INTO tlog_graph_models VALUES (1, 'Apache&#x20;log&#x20;model',
'^.*?&#92;s+.*&quot;.*?&#92;s&#40;&#92;/.*?&#41;&#92;?.*1.1&quot;&#92;s+&#40;.*?&#41;&#92;s+&#40;.*?&#41;&#92;s+',
'pagina,&#x20;html_err_code,&#x20;_tiempo_', 1);
--
-- Dumping data for table `tnotification_source`
--
INSERT INTO `tnotification_source`(`description`, `icon`, `max_postpone_time`, `enabled`, `user_editable`, `also_mail`) VALUES
("System&#x20;status", "icono_info_mr.png", 86400, 1, 1, 0),
("Message", "icono_info_mr.png", 86400, 1, 1, 0),
("Pending&#x20;task", "icono_info_mr.png", 86400, 1, 1, 0),
("Advertisement", "icono_info_mr.png", 86400, 1, 1, 0),
("Official&#x20;communication", "icono_info_mr.png", 86400, 1, 1, 0),
("Sugerence", "icono_info_mr.png", 86400, 1, 1, 0);
--
-- Dumping data for table `tnotification_source_user`
--
INSERT INTO `tnotification_source_user`(`id_source`,`id_user`,`enabled`,`also_mail`) VALUES
((SELECT `id` FROM `tnotification_source` WHERE `description`="System&#x20;status"), "admin",1,0);

View File

@ -163,6 +163,8 @@ sub csv_to_obj {
@hr_headers = map { $_ =~ s/\"//g; trim($_); } @hr_headers;
foreach my $line (@lines) {
next if empty($line);
my $i = 0;
my %hr = map { $_ =~ s/\"//g; $hr_headers[$i++] => trim($_) } split /,/, $line;