cacti-1.1.38/ 0000775 0001750 0001750 00000000000 13264740214 012256 5 ustar troman troman cacti-1.1.38/vdef.php 0000664 0001750 0001750 00000067353 13264740213 013730 0 ustar troman troman __('Delete'),
'2' => __('Duplicate')
);
set_default_action();
switch (get_request_var('action')) {
case 'save':
vdef_form_save();
break;
case 'actions':
vdef_form_actions();
break;
case 'item_remove_confirm':
vdef_item_remove_confirm();
break;
case 'item_remove':
vdef_item_remove();
break;
case 'item_movedown':
get_filter_request_var('vdef_id');
item_movedown();
header('Location: vdef.php?header=false&action=edit&id=' . get_request_var('vdef_id'));
break;
case 'item_moveup':
get_filter_request_var('vdef_id');
item_moveup();
header('Location: vdef.php?header=false&action=edit&id=' . get_request_var('vdef_id'));
break;
case 'item_edit':
top_header();
vdef_item_edit();
bottom_footer();
break;
case 'edit':
top_header();
vdef_edit();
bottom_footer();
break;
case 'ajax_dnd':
vdef_item_dnd();
break;
default:
top_header();
vdef();
bottom_footer();
break;
}
/* --------------------------
Global Form Functions
-------------------------- */
function draw_vdef_preview($vdef_id) {
?>
$val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$vdef_list .= '' . db_fetch_cell_prepared('SELECT name FROM vdef WHERE id = ?', array($matches[1])) . ' ';
$vdef_array[] = $matches[1];
}
}
top_header();
form_start('vdef.php', 'vdef_actions');
html_start_box($vdef_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (isset($vdef_array)) {
if (get_nfilter_request_var('drp_action') === '1') { // delete
print "
" . __n('Click \'Continue\' to delete the following VDEF.', 'Click \'Continue\' to delete following VDEFs.', sizeof($vdef_array)) . "
\n";
$save_html = " ";
} elseif (get_nfilter_request_var('drp_action') === '2') { // duplicate
print "
" . __n('Click \'Continue\' to duplicate the following VDEF. You can optionally change the title format for the new VDEF.', 'Click \'Continue\' to duplicate following VDEFs. You can optionally change the title format for the new VDEFs.', sizeof($vdef_array)) . "
" . __('Title Format:') . " "; form_text_box("title_format", " (1)", "", "255", "30", "text"); print "
\n";
$save_html = " ";
}
} else {
print "" . __('You must select at least one VDEF.') . " \n";
$save_html = " ";
}
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}
/* --------------------------
VDEF Item Functions
-------------------------- */
function vdef_item_remove_confirm() {
global $vdef_functions, $vdef_item_types, $custom_vdef_data_source_types;
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('vdef_id');
/* ==================================================== */
form_start('vdef.php');
html_start_box('', '100%', '', '3', 'center', '');
$vdef = db_fetch_row_prepared('SELECT * FROM vdef WHERE id = ?', array(get_request_var('id')));
$vdef_item = db_fetch_row_prepared('SELECT * FROM vdef_items WHERE id = ?', array(get_request_var('vdef_id')));
?>
VDEF Name: ''
:
' onClick='$("#cdialog").dialog("close");' name='cancel'>
' name='continue' title=''>
array(
'method' => 'drop_array',
'friendly_name' => __('VDEF Item Type'),
'description' => __('Choose what type of VDEF item this is.'),
'value' => $current_type,
'array' => $vdef_item_types
),
'value' => array(
'method' => 'drop_array',
'friendly_name' => __('VDEF Item Value'),
'description' => __('Enter a value for this VDEF item.'),
'value' => (isset($vdef['value']) ? $vdef['value']:'')
),
'id' => array(
'method' => 'hidden',
'value' => isset_request_var('id') ? get_request_var('id') : '0',
),
'type' => array(
'method' => 'hidden',
'value' => $current_type
),
'vdef_id' => array(
'method' => 'hidden',
'value' => get_request_var('vdef_id')
),
'save_component_item' => array(
'method' => 'hidden',
'value' => '1'
)
);
switch ($current_type) {
case '1':
$form_vdef['value']['array'] = $vdef_functions;
break;
case '4':
$form_vdef['value']['array'] = $custom_vdef_data_source_types;
break;
case '6':
$form_vdef['value']['method'] = 'textbox';
$form_vdef['value']['max_length'] = '255';
$form_vdef['value']['size'] = '30';
break;
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($form_vdef, $vdef)
)
);
?>
array('no_form_tag' => true),
'fields' => inject_form_variables($preset_vdef_form_list, (isset($vdef) ? $vdef : array()))
)
);
html_end_box(true, true);
form_hidden_box('id', (isset($vdef['id']) ? $vdef['id'] : '0'), '');
form_hidden_box('save_component_vdef', '1', '');
if (!isempty_request_var('id')) {
html_start_box('', '100%', '', '3', 'center', '');
draw_vdef_preview(get_request_var('id'));
html_end_box();
html_start_box(__('VDEF Items'), '100%', '', '3', 'center', 'vdef.php?action=item_edit&vdef_id=' . $vdef['id']);
$header_items = array(
array('display' => __('Item'), 'align' => 'left'),
array('display' => __('Item Value'), 'align' => 'left')
);
html_header($header_items, 2);
$vdef_items = db_fetch_assoc_prepared('SELECT *
FROM vdef_items
WHERE vdef_id = ?
ORDER BY sequence',
array(get_request_var('id')));
$i = 1;
$total_items = sizeof($vdef_items);
if (sizeof($vdef_items)) {
foreach ($vdef_items as $vdef_item) {
form_alternate_row('line' . $vdef_item['id'], true, true);
?>
'>
:
1) {
echo ' ';
} else {
echo ' ';
}
if ($i > 1 && $i <= $total_items) {
echo ' ';
} else {
echo ' ';
}
}
?>
' class='delete deleteMarker fa fa-remove' title=''>
0';
} else {
$sql_having = '';
}
$total_rows = db_fetch_cell("SELECT
COUNT(`rows`)
FROM (
SELECT vd.id AS `rows`, vd.name,
SUM(CASE WHEN local_graph_id>0 THEN 1 ELSE 0 END) AS graphs
FROM vdef AS vd
LEFT JOIN graph_templates_item AS gti
ON gti.vdef_id=vd.id
GROUP BY vd.id
) AS rs
$sql_where
$sql_having
");
$sql_order = get_order_string();
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
return db_fetch_assoc("SELECT rs.*,
SUM(CASE WHEN local_graph_id=0 THEN 1 ELSE 0 END) AS templates,
SUM(CASE WHEN local_graph_id>0 THEN 1 ELSE 0 END) AS graphs
FROM (
SELECT vd.*, gti.local_graph_id
FROM vdef AS vd
LEFT JOIN graph_templates_item AS gti
ON gti.vdef_id=vd.id
GROUP BY vd.id, gti.graph_template_id, gti.local_graph_id
) AS rs
$sql_where
GROUP BY rs.id
$sql_having
$sql_order
$sql_limit");
}
function vdef($refresh = true) {
global $vdef_actions;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'has_graphs' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => read_config_option('default_has') == 'on' ? 'true':'false'
)
);
validate_store_request_vars($filters, 'sess_vdef');
/* ================= input validation ================= */
vdef_filter();
$total_rows = 0;
$vdefs = array();
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
$vdefs = get_vdef_records($total_rows, $rows);
$nav = html_nav_bar('vdef.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 5, __('VDEFs'), 'page', 'main');
form_start('vdef.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'name' => array('display' => __('VDEF Name'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __esc('The name of this VDEF.') ),
'nosort' => array('display' => __('Deletable'), 'align' => 'right', 'tip' => __esc('VDEFs that are in use cannot be Deleted. In use is defined as being referenced by a Graph or a Graph Template.') ),
'graphs' => array('display' => __('Graphs Using'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __esc('The number of Graphs using this VDEF.') ),
'templates' => array('display' => __('Templates Using'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __esc('The number of Graphs Templates using this VDEF.') )
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
$i = 0;
if (sizeof($vdefs)) {
foreach ($vdefs as $vdef) {
if ($vdef['graphs'] == 0 && $vdef['templates'] == 0) {
$disabled = false;
} else {
$disabled = true;
}
form_alternate_row('line' . $vdef['id'], false, $disabled);
form_selectable_cell(filter_value($vdef['name'], get_request_var('filter'), 'vdef.php?action=edit&id=' . $vdef['id']), $vdef['id']);
form_selectable_cell($disabled ? __('No'):__('Yes'), $vdef['id'], '', 'text-align:right');
form_selectable_cell(number_format_i18n($vdef['graphs'], '-1'), $vdef['id'], '', 'text-align:right');
form_selectable_cell(number_format_i18n($vdef['templates'], '-1'), $vdef['id'], '', 'text-align:right');
form_checkbox_cell($vdef['name'], $vdef['id'], $disabled);
form_end_row();
}
} else {
print "" . __('No VDEFs') . " \n";
}
html_end_box(false);
if (sizeof($vdefs)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($vdef_actions);
form_end();
}
cacti-1.1.38/utilities.php 0000664 0001750 0001750 00000260761 13264740213 015015 0 ustar troman troman 0
GROUP BY i.type_id');
/* Get RRDtool version */
$rrdtool_version = 'Unknown';
if ((file_exists(read_config_option('path_rrdtool'))) && ((function_exists('is_executable')) && (is_executable(read_config_option('path_rrdtool'))))) {
$out_array = array();
exec(cacti_escapeshellcmd(read_config_option('path_rrdtool')), $out_array);
if (sizeof($out_array) > 0) {
if (preg_match('/^RRDtool ([1-9]\.[0-9])/', $out_array[0], $m)) {
$rrdtool_version = 'rrd-'. $m[1] .'.x';
}
}
}
/* Get SNMP cli version */
if ((file_exists(read_config_option('path_snmpget'))) && ((function_exists('is_executable')) && (is_executable(read_config_option('path_snmpget'))))) {
$snmp_version = shell_exec(cacti_escapeshellcmd(read_config_option('path_snmpget')) . ' -V 2>&1');
} else {
$snmp_version = "" . __('NET-SNMP Not Installed or its paths are not set. Please install if you wish to monitor SNMP enabled devices.') . " ";
}
/* Check RRDtool issues */
$rrdtool_error = '';
if ($rrdtool_version != read_config_option('rrdtool_version')) {
$rrdtool_error .= "" . __('ERROR: Installed RRDtool version does not match configured version. Please visit the %s and select the correct RRDtool Utility Version.', "" . __('Configuration Settings') . ' ') . " ";
}
$graph_gif_count = db_fetch_cell('SELECT COUNT(*) FROM graph_templates_graph WHERE image_format_id = 2');
if ($graph_gif_count > 0) {
$rrdtool_error .= "" . __('ERROR: RRDtool 1.2.x+ does not support the GIF images format, but %d" graph(s) and/or templates have GIF set as the image format.', $graph_gif_count) . ' ';
}
/* Get spine version */
$spine_version = 'Unknown';
if ((file_exists(read_config_option('path_spine'))) && ((function_exists('is_executable')) && (is_executable(read_config_option('path_spine'))))) {
$out_array = array();
exec(read_config_option('path_spine') . ' --version', $out_array);
if (sizeof($out_array) > 0) {
$spine_version = $out_array[0];
}
}
/* ================= input validation ================= */
get_filter_request_var('tab', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z]+)$/')));
/* ==================================================== */
/* present a tabbed interface */
$tabs = array(
'summary' => __('Summary'),
'database' => __('Database'),
'phpinfo' => __('PHP Info'),
);
/* set the default tab */
load_current_session_value('tab', 'sess_ts_tabs', 'summary');
$current_tab = get_nfilter_request_var('tab');
$header_label = __('Technical Support [%s]', $tabs[get_request_var('tab')]);
if (sizeof($tabs)) {
$i = 0;
/* draw the tabs */
print "\n";
}
/* Display tech information */
html_start_box($header_label, '100%', '', '3', 'center', '');
if (get_request_var('tab') == 'summary') {
html_section_header(__('General Information'), 2);
form_alternate_row();
print '' . __('Date') . " \n";
print '' . date('r') . " \n";
form_end_row();
api_plugin_hook_function('custom_version_info');
form_alternate_row();
print '' . __('Cacti Version') . " \n";
print '' . CACTI_VERSION . " \n";
form_end_row();
form_alternate_row();
print '' . __('Cacti OS') . " \n";
print '' . $config['cacti_server_os'] . " \n";
form_end_row();
form_alternate_row();
print '' . __('RSA Fingerprint') . " \n";
print '' . read_config_option('rsa_fingerprint') . " \n";
form_end_row();
form_alternate_row();
print '' . __('NET-SNMP Version') . " \n";
print '' . $snmp_version . " \n";
form_end_row();
form_alternate_row();
print '' . __('RRDtool Version') . " \n";
print '' . $rrdtool_versions[$rrdtool_version] . ' ' . $rrdtool_error . " \n";
form_end_row();
form_alternate_row();
print '' . __('Devices') . " \n";
print '' . number_format_i18n($host_count, -1) . " \n";
form_end_row();
form_alternate_row();
print '' . __('Graphs') . " \n";
print '' . number_format_i18n($graph_count, -1) . " \n";
form_end_row();
form_alternate_row();
print '' . __('Data Sources') . " \n";
print '';
$data_total = 0;
if (sizeof($data_count)) {
foreach ($data_count as $item) {
print $input_types[$item['type_id']] . ': ' . number_format_i18n($item['total'], -1) . ' ';
$data_total += $item['total'];
}
print __('Total: %s', number_format_i18n($data_total, -1));
} else {
print "0 ";
}
print " \n";
form_end_row();
html_section_header(__('Poller Information'), 2);
form_alternate_row();
print "Interval \n";
print '' . read_config_option('poller_interval') . " \n";
if (file_exists(read_config_option('path_spine')) && $poller_options[read_config_option('poller_type')] == 'spine') {
$type = $spine_version;
} else {
$type = $poller_options[read_config_option('poller_type')];
}
form_end_row();
form_alternate_row();
print '' . __('Type') . " \n";
print '' . $type . " \n";
form_end_row();
form_alternate_row();
print '' . __('Items') . " \n";
print '';
$total = 0;
if (sizeof($poller_item)) {
foreach ($poller_item as $item) {
print __('Action[%s]', $item['action']) . ': ' . number_format_i18n($item['total'], -1) . ' ';
$total += $item['total'];
}
print __('Total: %s', number_format_i18n($total, -1));
} else {
print "" . __('No items to poll') . " ";
}
print " \n";
form_end_row();
form_alternate_row();
print '' . __('Concurrent Processes') . " \n";
print '' . read_config_option('concurrent_processes') . " \n";
form_end_row();
form_alternate_row();
print '' . __('Max Threads') . " \n";
print '' . read_config_option('max_threads') . " \n";
form_end_row();
form_alternate_row();
print '' . __('PHP Servers') . " \n";
print '' . read_config_option('php_servers') . " \n";
form_end_row();
form_alternate_row();
print '' . __('Script Timeout') . " \n";
print '' . read_config_option('script_timeout') . " \n";
form_end_row();
form_alternate_row();
print '' . __('Max OID') . " \n";
print '' . read_config_option('max_get_size') . " \n";
form_end_row();
form_alternate_row();
print '' . __('Last Run Statistics') . " \n";
print '' . read_config_option('stats_poller') . " \n";
form_end_row();
/* Get System Memory */
$memInfo = utilities_get_system_memory();
if (sizeof($memInfo)) {
html_section_header(__('System Memory'), 2);
foreach($memInfo as $name => $value) {
if ($config['cacti_server_os'] == 'win32') {
form_alternate_row();
print "$name \n";
print '' . number_format_i18n($value/1000, 2) . " MB \n";
form_end_row();
} else {
switch($name) {
case 'SwapTotal':
case 'SwapFree':
case 'Cached':
case 'MemTotal':
case 'MemFree':
case 'Buffers':
case 'Active':
case 'Inactive':
form_alternate_row();
print "$name \n";
print '' . number_format_i18n($value/1000/1000, 2) . " MB \n";
form_end_row();
}
}
}
form_end_row();
}
html_section_header(__('PHP Information'), 2);
form_alternate_row();
print "" . __('PHP Version') . " \n";
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
print '' . PHP_VERSION . " \n";
} else {
print '' . PHP_VERSION . "" . __('PHP Version 5.5.0+ is recommended due to strong password hashing support.') . " \n";
}
form_end_row();
form_alternate_row();
print "" . __('PHP OS') . " \n";
print '' . PHP_OS . " \n";
form_end_row();
form_alternate_row();
print "" . __('PHP uname') . " \n";
print '';
if (function_exists('php_uname')) {
print php_uname();
} else {
print __('N/A');
}
print " \n";
form_end_row();
form_alternate_row();
print "" . __('PHP SNMP') . " \n";
print '';
if (function_exists('snmpget')) {
print __('Installed');
} else {
print __('Not Installed');
}
print " \n";
form_end_row();
form_alternate_row();
print "max_execution_time \n";
print '' . ini_get('max_execution_time') . " \n";
form_end_row();
form_alternate_row();
print "memory_limit \n";
print '' . ini_get('memory_limit');
/* Calculate memory suggestion based off of data source count */
$memory_suggestion = $data_total * 32768;
/* Set minimum - 16M */
if ($memory_suggestion < 16777216) {
$memory_suggestion = 16777216;
}
/* Set maximum - 512M */
if ($memory_suggestion > 536870912) {
$memory_suggestion = 536870912;
}
/* Suggest values in 8M increments */
$memory_suggestion = round($memory_suggestion / 8388608) * 8388608;
if (memory_bytes(ini_get('memory_limit')) < $memory_suggestion) {
print "";
if ((ini_get('memory_limit') == -1)) {
print __("You've set memory limit to 'unlimited'.") . " ";
}
print __('It is highly suggested that you alter you php.ini memory_limit to %s or higher.', memory_readable($memory_suggestion)) . ' ' .
__('This suggested memory value is calculated based on the number of data source present and is only to be used as a suggestion, actual values may vary system to system based on requirements.');
print ' ';
}
print " \n";
form_end_row();
utilities_get_mysql_recommendations();
} elseif (get_request_var('tab') == 'database') {
html_section_header(__('MySQL Table Information - Sizes in KBytes'), 2);
form_alternate_row();
print " ";
if (sizeof($tables) > 0) {
print "\n";
print "\n";
print "\n";
print " \n";
foreach ($tables as $table) {
form_alternate_row();
print '' . $table['TABLE_NAME'] . " \n";
print '' . $table['ENGINE'] . " \n";
print '' . number_format_i18n($table['TABLE_ROWS'], -1) . " \n";
print '' . number_format_i18n($table['AVG_ROW_LENGTH'], -1) . " \n";
print '' . number_format_i18n($table['DATA_LENGTH'], -1) . " \n";
print '' . number_format_i18n($table['INDEX_LENGTH'], -1) . " \n";
print '' . $table['TABLE_COLLATION'] . " \n";
print '' . $table['TABLE_COMMENT'] . " \n";
form_end_row();
}
print "
\n";
} else {
print __('Unable to retrieve table status');
}
print " \n";
form_end_row();
} else {
html_section_header(__('PHP Module Information'), 2);
form_alternate_row();
$php_info = str_replace(
array('width="600"', 'th colspan="2"', ','),
array('', 'th class="subHeaderColumn"', ', '),
$php_info
);
print "" . $php_info . " \n";
form_end_row();
}
html_end_box();
?>
array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'time',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'username' => array(
'filter' => FILTER_CALLBACK,
'default' => '-1',
'options' => array('options' => 'sanitize_search_string')
),
'result' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_userlog');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
?>
array(__('User'), 'ASC'),
'full_name' => array(__('Full Name'), 'ASC'),
'realm' => array(__('Authentication Realm'), 'ASC'),
'time' => array(__('Date'), 'ASC'),
'result' => array(__('Result'), 'DESC'),
'ip' => array(__('IP Address'), 'DESC')
);
html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), 1, 'utilities.php?action=view_user_log');
if (sizeof($user_log)) {
foreach ($user_log as $item) {
form_alternate_row('', true);
?>
1) {
db_execute_prepared('DELETE
FROM user_log
WHERE username = ?
AND result IN(1)
ORDER BY time LIMIT ' . ($total_login_rows - 1),
array($user['username']));
}
if ($total_token_rows > 1) {
db_execute_prepared('DELETE
FROM user_log
WHERE username = ?
AND result IN(2)
ORDER BY time
LIMIT ' . ($total_token_rows - 1),
array($user['username']));
}
db_execute_prepared('DELETE
FROM user_log
WHERE username = ?
AND result = 0',
array($user['username']));
}
/* delete inactive users */
db_execute('DELETE
FROM user_log
WHERE user_id NOT IN (SELECT id FROM user_auth)
OR username NOT IN (SELECT username FROM user_auth)');
}
}
function utilities_view_logfile() {
global $log_tail_lines, $page_refresh_interval, $config;
$logfile = read_config_option('path_cactilog');
$logbase = basename($logfile);
if (is_base64_encoded(get_nfilter_request_var('rfilter'))) {
set_request_var('rfilter', base64_decode(get_nfilter_request_var('rfilter')));
}
if (isset_request_var('filename')) {
$requestedFile = dirname($logfile) . '/' . basename(get_nfilter_request_var('filename'));
if (file_exists($requestedFile)) {
$logfile = $requestedFile;
} else {
$logfile = read_config_option('path_cactilog');
}
}
if ($logfile == '') {
$logfile = $config['base_path'] . '/log/cacti.log';
}
if (get_nfilter_request_var('filename') != '') {
if (strpos(get_nfilter_request_var('filename'), $logbase) === false) {
raise_message('clog_invalid');
header('Location: utilities.php?action=view_logfile&filename=' . $logbase);
exit(0);
}
}
/* ================= input validation and session storage ================= */
$filters = array(
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'tail_lines' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'rfilter' => array(
'filter' => FILTER_VALIDATE_IS_REGEX,
'pageset' => true,
'default' => ''
),
'message_type' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'reverse' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'refresh' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => read_config_option('log_refresh_interval')
)
);
validate_store_request_vars($filters, 'sess_log');
/* ================= input validation ================= */
$page_nr = get_request_var('page');
$page = 'utilities.php?action=view_logfile&header=false';
$page .= '&filename=' . basename($logfile) . '&page=' . $page_nr;
$refresh = array(
'seconds' => get_request_var('refresh'),
'page' => $page,
'logout' => 'false'
);
set_page_refresh($refresh);
top_header();
?>
0) {
$start_string = __('Log [Total Lines: %d - Non-Matching Items Hidden]', $total_rows);
} else {
$start_string = __('Log [Total Lines: %d - All Items Shown]', $total_rows);
}
$rfilter = get_request_var('rfilter');
$reverse = get_request_var('reverse');
$refreshTime = get_request_var('refresh');
$message_type = get_request_var('message_type');
$tail_lines = get_request_var('tail_lines');
$base_url = 'utilities.php?action=view_logfile&rfilter='.$rfilter.'&reverse='.$reverse.'&refresh='.$refreshTime.'&message_type='.$message_type.'&tail_lines='.$tail_lines.'&filename='.basename($logfile);
$nav = html_nav_bar($base_url, MAX_DISPLAY_PAGES, $page_nr, $number_of_lines, $total_rows, 13, __('Entries'), 'page', 'main');
echo $nav;
html_start_box($start_string, '100%', '', '3', 'center', '');
$linecolor = false;
foreach ($logcontents as $item) {
$host_start = strpos($item, 'Device[');
$ds_start = strpos($item, 'DS[');
if (!$host_start && !$ds_start) {
$new_item = html_escape($item);
} else {
$new_item = '';
while ($host_start) {
$host_end = strpos($item, ']', $host_start);
$host_id = substr($item, $host_start + 7, $host_end - ($host_start + 7));
$new_item .= html_escape(substr($item, 0, $host_start + 7)) . "" . html_escape(substr($item, $host_start + 7, $host_end - ($host_start + 7))) . ' ';
$item = substr($item, $host_end);
$host_start = strpos($item, 'Device[');
}
$ds_start = strpos($item, 'DS[');
while ($ds_start) {
$ds_end = strpos($item, ']', $ds_start);
$ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
$new_item .= html_escape(substr($item, 0, $ds_start + 3)) . "" . html_escape(substr($item, $ds_start + 3, $ds_end - ($ds_start + 3))) . ' ';
$item = substr($item, $ds_end);
$ds_start = strpos($item, 'DS[');
}
$new_item .= html_escape($item);
}
/* get the background color */
if (strpos($new_item, 'ERROR') !== false || strpos($new_item, 'FATAL') !== false) {
$class = 'clogError';
} elseif (strpos($new_item, 'WARN') !== false) {
$class = 'clogWarning';
} elseif (strpos($new_item, ' SQL ') !== false) {
$class = 'clogSQL';
} elseif (strpos($new_item, 'DEBUG') !== false) {
$class = 'clogDebug';
} elseif (strpos($new_item, 'STATS') !== false) {
$class = 'clogStats';
} else {
if ($linecolor) {
$class = 'odd';
} else {
$class = 'even';
}
$linecolor = !$linecolor;
}
print "" . $new_item . " \n";
}
html_end_box();
if ($total_rows) {
echo $nav;
}
bottom_footer();
}
function utilities_clear_logfile() {
load_current_session_value('refresh', 'sess_logfile_refresh', read_config_option('log_refresh_interval'));
$refresh['seconds'] = get_request_var('refresh');
$refresh['page'] = 'utilities.php?action=view_logfile&header=false';
$refresh['logout'] = 'false';
set_page_refresh($refresh);
top_header();
$logfile = read_config_option('path_cactilog');
if ($logfile == '') {
$logfile = './log/cacti.log';
}
html_start_box(__('Clear Cacti Log'), '100%', '', '3', 'center', '');
if (file_exists($logfile)) {
if (is_writable($logfile)) {
$timestamp = date('Y-m-d H:i:s');
$log_fh = fopen($logfile, 'w');
fwrite($log_fh, __('%s - WEBUI: Cacti Log Cleared from Web Management Interface.', $timestamp) . "\n");
fclose($log_fh);
print '' . __('Cacti Log Cleared') . ' ';
} else {
print "" . __('Error: Unable to clear log, no write permissions.') . " ";
}
} else {
print "" . __('Error: Unable to clear log, file does not exist.'). " ";
}
html_end_box();
}
function utilities_view_snmp_cache() {
global $poller_actions, $item_rows;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'with_index' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '0'
),
'host_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'snmp_query_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'poller_action' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_usnmp');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
$refresh['seconds'] = '300';
$refresh['page'] = 'utilities.php?action=view_snmp_cache&header=false';
$refresh['logout'] = 'false';
set_page_refresh($refresh);
?>
array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'dtd.name_cache',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'host_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'poller_action' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_poller');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
$refresh['seconds'] = '300';
$refresh['page'] = 'utilities.php?action=view_poller_cache';
$refresh['logout'] = 'false';
set_page_refresh($refresh);
?>
array(__('Data Source Name'), 'ASC'),
'h.description' => array(__('Device Description'), 'ASC'),
'nosort' => array(__('Details'), 'ASC'));
html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), 1, 'utilities.php?action=view_poller_cache');
$i = 0;
if (sizeof($poller_cache)) {
foreach ($poller_cache as $item) {
if ($i % 2 == 0) {
$class = 'odd';
} else {
$class = 'even';
}
print "\n";
?>
\n";
?>
array(
'link' => 'utilities.php?action=view_tech',
'description' => __('Cacti technical support page. Used by developers and technical support persons to assist with issues in Cacti. Includes checks for common configuration issues.')
),
__('Log Administration') => array(
'link' => 'utilities.php?action=view_logfile',
'description' => __('The Cacti Log stores statistic, error and other message depending on system settings. This information can be used to identify problems with the poller and application.')
),
__('View User Log') => array(
'link' => 'utilities.php?action=view_user_log',
'description' => __('Allows Administrators to browse the user log. Administrators can filter and export the log as well.')
)
);
$utilities[__('Poller Cache Administration')] = array(
__('View Poller Cache') => array(
'link' => 'utilities.php?action=view_poller_cache',
'description' => __('This is the data that is being passed to the poller each time it runs. This data is then in turn executed/interpreted and the results are fed into the RRDfiles for graphing or the database for display.')
),
__('View Data Query Cache') => array(
'link' => 'utilities.php?action=view_snmp_cache',
'description' => __('The Data Query Cache stores information gathered from Data Query input types. The values from these fields can be used in the text area of Graphs for Legends, Vertical Labels, and GPRINTS as well as in CDEF\'s.')
),
__('Rebuild Poller Cache') => array(
'link' => 'utilities.php?action=clear_poller_cache',
'description' => __('The Poller Cache will be re-generated if you select this option. Use this option only in the event of a database crash if you are experiencing issues after the crash and have already run the database repair tools. Alternatively, if you are having problems with a specific Device, simply re-save that Device to rebuild its Poller Cache. There is also a command line interface equivalent to this command that is recommended for large systems. NOTE: On large systems, this command may take several minutes to hours to complete and therefore should not be run from the Cacti UI. You can simply run \'php -q cli/rebuild_poller_cache.php --help\' at the command line for more information. ')
),
__('Rebuild Resource Cache') => array(
'link' => 'utilities.php?action=rebuild_resource_cache',
'description' => __('When operating multiple Data Collectors in Cacti, Cacti will attempt to maintain state for key files on all Data Collectors. This includes all core, non-install related website and plugin files. When you force a Resource Cache rebild, Cacti will clear the local Resource Cache, and then rebuild it at the next scheduled poller start. This will trigger all Remote Data Collectors to recheck their website and plugin files for consistency.')
),
);
$utilities[__('Boost Utilities')] = array(
__('View Boost Status') => array(
'link' => 'utilities.php?action=view_boost_status',
'description' => __('This menu pick allows you to view various boost settings and statistics associated with the current running Boost configuration.')
),
);
$utilities[__('RRD Utilities')] = array(
__('RRDfile Cleaner') => array(
'link' => 'rrdcleaner.php',
'description' => __('When you delete Data Sources from Cacti, the corresponding RRDfiles are not removed automatically. Use this utility to facilitate the removal of these old files.')
),
);
$utilities[__('SNMPAgent Utilities')] = array(
__('View SNMPAgent Cache') => array(
'link' => 'utilities.php?action=view_snmpagent_cache',
'description' => __('This shows all objects being handled by the SNMPAgent.')
),
__('Rebuild SNMPAgent Cache') => array(
'link' => 'utilities.php?action=rebuild_snmpagent_cache',
'description' => __('The SNMP cache will be cleared and re-generated if you select this option. Note that it takes another poller run to restore the SNMP cache completely.')
),
__('View SNMPAgent Notification Log') => array(
'link' => 'utilities.php?action=view_snmpagent_events',
'description' => __('This menu pick allows you to view the latest events SNMPAgent has handled in relation to the registered notification receivers.')
),
__('SNMP Notification Receivers') => array(
'link' => 'managers.php',
'description' => __('Allows Administrators to maintain SNMP notification receivers.')
),
);
api_plugin_hook('utilities_array');
html_start_box(__('Cacti System Utilities'), '100%', '', '3', 'center', '');
foreach($utilities as $header => $content) {
html_section_header($header, 2);
foreach($content as $title => $details) {
form_alternate_row();
print "";
print "" . $title . " ";
print " \n";
print "";
print $details['description'];
print " \n";
form_end_row();
}
}
api_plugin_hook('utilities_list');
html_end_box();
}
function boost_display_run_status() {
global $config, $refresh_interval, $boost_utilities_interval, $boost_refresh_interval, $boost_max_runtime;
/* ================= input validation ================= */
get_filter_request_var('refresh');
/* ==================================================== */
load_current_session_value('refresh', 'sess_boost_utilities_refresh', '30');
$last_run_time = read_config_option('boost_last_run_time', true);
$next_run_time = read_config_option('boost_next_run_time', true);
$rrd_updates = read_config_option('boost_rrd_update_enable', true);
$boost_cache = read_config_option('boost_png_cache_enable', true);
$max_records = read_config_option('boost_rrd_update_max_records', true);
$max_runtime = read_config_option('boost_rrd_update_max_runtime', true);
$update_interval = read_config_option('boost_rrd_update_interval', true);
$peak_memory = read_config_option('boost_peak_memory', true);
$detail_stats = read_config_option('stats_detail_boost', true);
$refresh['seconds'] = get_request_var('refresh');
$refresh['page'] = 'utilities.php?action=view_boost_status&header=false';
$refresh['logout'] = 'false';
set_page_refresh($refresh);
html_start_box(__('Boost Status'), '100%', '', '3', 'center', '');
?>
' . __('WARNING:') . '' . __('Cannot open directory');
$cache_files = '' . __('WARNING:') . ' ' . __('Unknown');
}
} else {
$directory_size = '' . __('WARNING:') . ' ' . __('Directory Does NOT Exist!!');
$cache_files = '' . __('WARNING:') . ' ' . __('N/A');
}
$i = 0;
/* boost status display */
html_section_header(__('Current Boost Status'), 2);
form_alternate_row();
print '' . __('Boost On-demand Updating:') . ' ' . ($rrd_updates == '' ? 'Disabled' : $boost_status_text) . ' ';
form_alternate_row();
print '' . __('Total Data Sources:') . ' ' . number_format_i18n($total_data_sources, -1) . ' ';
if ($total_records) {
form_alternate_row();
print '' . __('Pending Boost Records:') . ' ' . number_format_i18n($pending_records, -1) . ' ';
form_alternate_row();
print '' . __('Archived Boost Records:') . ' ' . number_format_i18n($arch_records, -1) . ' ';
form_alternate_row();
print '' . __('Total Boost Records:') . ' ' . number_format_i18n($total_records, -1) . ' ';
}
/* boost status display */
html_section_header(__('Boost Storage Statistics'), 2);
/* describe the table format */
form_alternate_row();
print '' . __('Database Engine:') . ' ' . $engine . ' ';
/* tell the user how big the table is */
form_alternate_row();
print '' . __('Current Boost Table(s) Size:') . ' ' . boost_file_size_display($data_length, 2) . ' ';
/* tell the user about the average size/record */
form_alternate_row();
print '' . __('Avg Bytes/Record:') . ' ' . boost_file_size_display($avg_row_length, 0) . ' ';
/* tell the user about the average size/record */
$output_length = read_config_option('boost_max_output_length');
if ($output_length != '') {
$parts = explode(':', $output_length);
if ((time()-1200) > $parts[0]) {
$ref = true;
} else {
$ref = false;
}
} else {
$ref = true;
}
if ($ref) {
if (strcmp($engine, 'MEMORY') == 0) {
$max_length = db_fetch_cell('SELECT MAX(LENGTH(output)) FROM poller_output_boost');
} else {
$max_length = '0';
}
db_execute("REPLACE INTO settings (name, value) VALUES ('boost_max_output_length', '" . time() . ':' . $max_length . "')");
} else {
$max_length = $parts[1];
}
if ($max_length != 0) {
form_alternate_row();
print '' . __('Max Record Length:') . ' ' . __('%d Bytes', number_format_i18n($max_length)) . ' ';
}
/* tell the user about the "Maximum Size" this table can be */
form_alternate_row();
if (strcmp($engine, 'MEMORY')) {
$max_table_allowed = __('Unlimited');
$max_table_records = __('Unlimited');
} else {
$max_table_allowed = boost_file_size_display($max_data_length, 2);
$max_table_records = number_format_i18n(($avg_row_length ? $max_data_length/$avg_row_length : 0), 3, 1000);
}
print '' . __('Max Allowed Boost Table Size:') . ' ' . $max_table_allowed . ' ';
/* tell the user about the estimated records that "could" be held in memory */
form_alternate_row();
print '' . __('Estimated Maximum Records:') . ' ' . $max_table_records . ' Records ';
/* boost last runtime display */
html_section_header(__('Runtime Statistics'), 2);
form_alternate_row();
print '' . __('Last Start Time:') . ' ' . $last_run_time . ' ';
form_alternate_row();
print '' . __('Last Run Duration:') . ' ';
if (is_numeric($boost_last_run_duration)) {
print (($boost_last_run_duration > 60) ? __('%d minutes', (int)($boost_last_run_duration/60)) : '' ) . __('%d seconds', $boost_last_run_duration%60);
if ($rrd_updates != ''){ print ' (' . __('%0.2f percent of update frequency)', round(100*$boost_last_run_duration/$update_interval/60));}
} else {
print __('N/A');
}
print ' ';
form_alternate_row();
print '' . __('RRD Updates:') . ' ' . ($boost_rrds_updated != '' ? number_format_i18n($boost_rrds_updated, -1):'-') . ' ';
form_alternate_row();
print '' . __('Peak Poller Memory:') . ' ' . ((read_config_option('boost_peak_memory') != '' && is_numeric(read_config_option('boost_peak_memory'))) ? (round(read_config_option('boost_peak_memory')/1024/1024,2)) . ' ' . __('MBytes') : __('N/A')) . ' ';
form_alternate_row();
print '' . __('Detailed Runtime Timers:') . ' ' . (($detail_stats != '') ? $detail_stats:__('N/A')) . ' ';
form_alternate_row();
print '' . __('Max Poller Memory Allowed:') . ' ' . ((read_config_option('boost_poller_mem_limit') != '') ? (read_config_option('boost_poller_mem_limit')) . ' ' . __('MBytes') : __('N/A')) . ' ';
/* boost runtime display */
html_section_header(__('Run Time Configuration'), 2);
form_alternate_row();
print '' . __('Update Frequency:') . ' ' . ($rrd_updates == '' ? __('N/A') : $boost_refresh_interval[$update_interval]) . ' ';
form_alternate_row();
print '' . __('Next Start Time:') . ' ' . $next_run_time . ' ';
form_alternate_row();
print '' . __('Maximum Records:') . ' ' . number_format_i18n($max_records, -1) . ' ' . __('Records') . ' ';
form_alternate_row();
print '' . __('Maximum Allowed Runtime:') . ' ' . $boost_max_runtime[$max_runtime] . ' ';
/* boost caching */
html_section_header(__('Image Caching'), 2);
form_alternate_row();
print '' . __('Image Caching Status:') . ' ' . ($boost_cache == '' ? __('Disabled') : __('Enabled')) . ' ';
form_alternate_row();
print '' . __('Cache Directory:') . ' ' . $cache_directory . ' ';
form_alternate_row();
print '' . __('Cached Files:') . ' ' . $cache_files . ' ';
form_alternate_row();
print '' . __('Cached Files Size:') . ' ' . $directory_size . ' ';
html_end_box(true);
}
/**
*
*
* snmpagent_utilities_run_cache()
*
* @param mixed
* @return
*/
function snmpagent_utilities_run_cache() {
global $item_rows;
get_filter_request_var('mib', FILTER_CALLBACK, array('options' => 'sanitize_search_string'));
$mibs = db_fetch_assoc('SELECT DISTINCT mib FROM snmpagent_cache');
$registered_mibs = array();
if($mibs && $mibs >0) {
foreach($mibs as $mib) { $registered_mibs[] = $mib['mib']; }
}
/* ================= input validation ================= */
if(!in_array(get_request_var('mib'), $registered_mibs) && get_request_var('mib') != '-1' && get_request_var('mib') != '') {
die_html_input_error();
}
/* ==================================================== */
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'mib' => array(
'filter' => FILTER_CALLBACK,
'default' => '-1',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_snmpac');
/* ================= input validation ================= */
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
?>
' . $name . ' ';
}else {
print "$name ";
}
form_selectable_cell($mib, $item['oid']);
form_selectable_cell($item['kind'], $item['oid']);
form_selectable_cell($max_access, $item['oid']);
form_selectable_cell((in_array($item['kind'], array(__('Scalar'), __('Column Data'))) ? $item['value'] : __('N/A')), $item['oid']);
form_end_row();
}
}
html_end_box();
if (sizeof($snmp_cache)) {
print $nav;
}
?>
'LOW',
SNMPAGENT_EVENT_SEVERITY_MEDIUM => 'MEDIUM',
SNMPAGENT_EVENT_SEVERITY_HIGH => 'HIGH',
SNMPAGENT_EVENT_SEVERITY_CRITICAL => 'CRITICAL'
);
$severity_colors = array(
SNMPAGENT_EVENT_SEVERITY_LOW => '#00FF00',
SNMPAGENT_EVENT_SEVERITY_MEDIUM => '#FFFF00',
SNMPAGENT_EVENT_SEVERITY_HIGH => '#FF0000',
SNMPAGENT_EVENT_SEVERITY_CRITICAL => '#FF00FF'
);
$receivers = db_fetch_assoc('SELECT DISTINCT manager_id, hostname
FROM snmpagent_notifications_log
INNER JOIN snmpagent_managers
ON snmpagent_managers.id = snmpagent_notifications_log.manager_id');
/* ================= input validation ================= */
get_filter_request_var('receiver');
if(!in_array(get_request_var('severity'), array_keys($severity_levels)) && get_request_var('severity') != '-1' && get_request_var('severity') != '') {
die_html_input_error();
}
/* ==================================================== */
if (isset_request_var('purge')) {
db_execute('TRUNCATE table snmpagent_notifications_log');
/* reset filters */
set_request_var('clear', true);
}
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'severity' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'receiver' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_snmpl');
/* ================= input validation ================= */
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
?>
";
print "" . date('Y-m-d H:i:s', $item['time']) . ' ';
print '' . html_escape($item['hostname']) . ' ';
if($item['description']) {
print '' . html_escape($item['notification']) . ' ';
}else {
print '' . html_escape($item['notification']) . ' ';
}
print "$varbinds ";
form_end_row();
}
} else {
print '' . __('No SNMP Notification Log Entries') . ' ';
}
html_end_box();
if (sizeof($logs)) {
print $nav;
}
?>
__('Delete'),
2 => __('Copy'),
3 => __('Enable'),
4 => __('Disable')
);
$href_options = array(
3 => array(
'radio_value' => '4',
'radio_caption' => __('Defer to the Users Setting')
),
0 => array(
'radio_value' => '1',
'radio_caption' => __('Show the Page that the User pointed their browser to')
),
1 => array(
'radio_value' => '2',
'radio_caption' => __('Show the Console')
),
2 => array(
'radio_value' => '3',
'radio_caption' => __('Show the default Graph Screen')
)
);
$gperm_options = array(
0 => array(
'radio_value' => '1',
'radio_caption' => __('Defer to the Users Setting')
),
1 => array(
'radio_value' => '2',
'radio_caption' => __('Grant Access')
),
2 => array(
'radio_value' => '3',
'radio_caption' => __('Restrict Access')
)
);
$fields_user_group_edit = array(
'name' => array(
'method' => 'textbox',
'friendly_name' => __('Group Name'),
'description' => __('The name of this Group.'),
'value' => '|arg1:name|',
'max_length' => '255'
),
'description' => array(
'method' => 'textbox',
'friendly_name' => __('Group Description'),
'description' => __('A more descriptive name for this group, that can include spaces or special characters.'),
'value' => '|arg1:description|',
'max_length' => '255'
),
'enabled' => array(
'method' => 'checkbox',
'friendly_name' => __('Enabled'),
'description' => __('Determines if user is able to login.'),
'value' => '|arg1:enabled|',
'default' => ''
),
'grp1' => array(
'friendly_name' => __('General Group Options'),
'method' => 'checkbox_group',
'description' => __('Set any user account-specific options here.'),
'items' => array(
'graph_settings' => array(
'value' => '|arg1:graph_settings|',
'friendly_name' => __('Allow Users of this Group to keep custom User Settings'),
'form_id' => '|arg1:id|',
'default' => 'on'
)
)
),
'show_tree' => array(
'friendly_name' => __('Tree Rights'),
'method' => 'radio',
'description' => __('Should Users of this Group have access to the Tree?'),
'value' => '|arg1:show_tree|',
'default' => '1',
'items' => $gperm_options
),
'show_list' => array(
'friendly_name' => __('Graph List Rights'),
'method' => 'radio',
'description' => __('Should Users of this Group have access to the Graph List?'),
'value' => '|arg1:show_list|',
'default' => '1',
'items' => $gperm_options
),
'show_preview' => array(
'friendly_name' => __('Graph Preview Rights'),
'method' => 'radio',
'description' => __('Should Users of this Group have access to the Graph Preview?'),
'value' => '|arg1:show_preview|',
'default' => '1',
'items' => $gperm_options
),
'login_opts' => array(
'friendly_name' => __('Login Options'),
'method' => 'radio',
'default' => '1',
'description' => __('What to do when a User from this User Group logs in.'),
'value' => '|arg1:login_opts|',
'items' => $href_options
),
'id' => array(
'method' => 'hidden_zero',
'value' => '|arg1:id|'
),
'save_component_group' => array(
'method' => 'hidden',
'value' => '1'
)
);
if (isset_request_var('update_policy')) {
update_policies();
} else {
switch (get_request_var('action')) {
case 'actions':
form_actions();
break;
case 'save':
form_save();
break;
case 'perm_remove':
perm_remove();
break;
case 'edit':
top_header();
group_edit();
bottom_footer();
break;
default:
if (!api_plugin_hook_function('user_group_admin_action', get_request_var('action'))) {
top_header();
user_group();
bottom_footer();
}
break;
}
}
/* --------------------------
Actions Function
-------------------------- */
function user_group_disable($id) {
db_execute_prepared("UPDATE user_auth_group SET enabled = '' WHERE id = ?", array($id));
}
function user_group_enable($id) {
db_execute_prepared("UPDATE user_auth_group SET enabled = 'on' WHERE id = ?", array($id));
}
function user_group_remove($id) {
db_execute_prepared('DELETE FROM user_auth_group WHERE id = ?', array($id));
db_execute_prepared('DELETE FROM user_auth_group_members WHERE group_id = ?', array($id));
db_execute_prepared('DELETE FROM user_auth_group_realm WHERE group_id = ?', array($id));
db_execute_prepared('DELETE FROM user_auth_group_perms WHERE group_id = ?', array($id));
}
function user_group_copy($id, $prefix = 'New Group') {
static $count = 1;
$name = $prefix . ' ' . $count;
db_execute_prepared('INSERT INTO user_auth_group
(name, description, graph_settings, login_opts, show_tree, show_list, show_preview,
policy_graphs, policy_trees, policy_hosts, policy_graph_templates, enabled)
SELECT ' . db_qstr($name) . ', description, graph_settings, login_opts, show_tree, show_list, show_preview,
policy_graphs, policy_trees, policy_hosts, policy_graph_templates, enabled
FROM user_auth_group WHERE id = ?', array($id));
$id = db_fetch_insert_id();
if (!empty($id)) {
$perms = db_fetch_assoc_prepared('SELECT *
FROM user_auth_group_perms
WHERE group_id = ?',
array($id));
if (sizeof($perms)) {
foreach($perms as $p) {
db_execute_prepared('INSERT INTO user_auth_group_perms
(group_id, item_id, type)
VALUES (?, ?, ?)',
array($id, $p['item_id'], $p['type']));
}
}
$realms = db_fetch_assoc_prepared('SELECT *
FROM user_auth_group_realm
WHERE group_id = ?',
array($id));
if (sizeof($realms)) {
foreach($realms as $r) {
db_execute_prepared('INSERT INTO user_auth_group_realm
(group_id, realm_id)
VALUES (?, ?)',
array($id, $r['realm_id']));
}
}
}
$count++;
}
function update_policies() {
$set = '';
$set .= isset_request_var('policy_graphs') ? 'policy_graphs=' . get_nfilter_request_var('policy_graphs'):'';
$set .= isset_request_var('policy_trees') ? ($set != '' ? ',':'') . 'policy_trees=' . get_nfilter_request_var('policy_trees'):'';
$set .= isset_request_var('policy_hosts') ? ($set != '' ? ',':'') . 'policy_hosts=' . get_nfilter_request_var('policy_hosts'):'';
$set .= isset_request_var('policy_graph_templates') ? ($set != '' ? ',':'') . 'policy_graph_templates=' . get_nfilter_request_var('policy_graph_templates'):'';
if ($set != '') {
db_execute_prepared("UPDATE user_auth_group SET $set WHERE id = ?", array(get_nfilter_request_var('id')));
}
header('Location: user_group_admin.php?action=edit&header=false&tab=' . get_nfilter_request_var('tab') . '&id=' . get_nfilter_request_var('id'));
exit;
}
function form_actions() {
global $group_actions, $user_auth_realms;
/* if we are to save this form, instead of display it */
if (isset_request_var('associate_host')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_group_perms
(group_id, item_id, type)
VALUES (?, ?, 3)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_group_perms
WHERE group_id = ?
AND item_id = ?
AND type = 3',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_group_admin.php?action=edit&header=false&tab=permsd&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_graph')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_group_perms
(group_id, item_id, type)
VALUES (?, ?, 1)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_group_perms
WHERE group_id = ?
AND item_id = ?
AND type = 1',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_group_admin.php?action=edit&header=false&tab=permsg&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_template')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_group_perms
(group_id, item_id, type)
VALUES (?, ?, 4)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_group_perms
WHERE group_id = ?
AND item_id = ?
AND type = 4',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_group_admin.php?action=edit&header=false&tab=permste&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_tree')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_group_perms
(group_id, item_id, type)
VALUES (?, ?, 2)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_group_perms
WHERE group_id = ?
AND item_id = ?
AND type = 2',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_group_admin.php?action=edit&header=false&tab=permstr&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_member')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_group_members
(group_id, user_id)
VALUES (?, ?)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_group_members
WHERE group_id = ?
AND user_id = ?',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_group_admin.php?action=edit&header=false&tab=members&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
for ($i=0;($i $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') != '2') {
$group_list .= '' . db_fetch_cell_prepared('SELECT name FROM user_auth_group WHERE id = ?', array($matches[1])) . ' ';
}
$group_array[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('user_group_admin.php');
html_start_box($group_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (isset($group_array) && sizeof($group_array)) {
if ((get_nfilter_request_var('drp_action') == '1') && (sizeof($group_array))) { /* delete */
print "
" . __n('Click \'Continue\' to delete the following User Group', 'Click \'Continue\' to delete following User Groups', sizeof($group_array)) . "
\n";
$save_html = " ";
}
$group_id = '';
if ((get_nfilter_request_var('drp_action') == '2') && (sizeof($group_array))) { /* copy */
print "
" . __n('Click \'Continue\' to Copy the following User Group to a new User Group.', 'Click \'Continue\' to Copy following User Groups to new User Groups.', sizeof($group_array)) . "
" . __('Group Prefix:') . " ";
print form_text_box('group_prefix', __('New Group'), '', 25);
print "
\n";
$save_html = " ";
}
if ((get_nfilter_request_var('drp_action') == '3') && (sizeof($group_array))) { /* enable */
print "
" . __n('Click \'Continue\' to enable the following User Group.', 'Click \'Continue\' to enable following User Groups.', sizeof($group_array)) . "
\n";
$save_html = " ";
}
if ((get_nfilter_request_var('drp_action') == '4') && (sizeof($group_array))) { /* disable */
print "
" . __n('Click \'Continue\' to disable the following User Group.', 'Click \'Continue\' to disable following User Groups.', sizeof($group_array)) . "
\n";
$save_html = " ";
}
} else {
print "" . __('You must select at least one Group.') . " \n";
$save_html = " ";
}
print "
";
print " \n";
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}
/* --------------------------
Save Function
-------------------------- */
function form_save() {
global $settings_user;
if (isset_request_var('save_component_group')) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('realm');
/* ==================================================== */
/* check duplicate group */
if (sizeof(db_fetch_row_prepared('SELECT * FROM user_auth_group WHERE name = ? AND id != ?', array(get_nfilter_request_var('name'), get_nfilter_request_var('id'))))) {
raise_message(12);
}
$save['id'] = get_nfilter_request_var('id');
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', "^[A-Za-z0-9\._\\\@\ -]+$", false, 3);
$save['description'] = form_input_validate(get_nfilter_request_var('description'), 'description', '', true, 3);
$save['show_tree'] = form_input_validate(get_nfilter_request_var('show_tree', ''), 'show_tree', '', true, 3);
$save['show_list'] = form_input_validate(get_nfilter_request_var('show_list', ''), 'show_list', '', true, 3);
$save['show_preview'] = form_input_validate(get_nfilter_request_var('show_preview', ''), 'show_preview', '', true, 3);
$save['graph_settings'] = form_input_validate(get_nfilter_request_var('graph_settings', ''), 'graph_settings', '', true, 3);
$save['login_opts'] = form_input_validate(get_nfilter_request_var('login_opts'), 'login_opts', '', true, 3);
$save['enabled'] = form_input_validate(get_nfilter_request_var('enabled', ''), 'enabled', '', true, 3);
$save = api_plugin_hook_function('user_group_admin_setup_sql_save', $save);
if (!is_error_message()) {
$group_id = sql_save($save, 'user_auth_group');
if ($group_id) {
reset_group_perms($group_id);
raise_message(1);
} else {
raise_message(2);
}
}
header('Location: user_group_admin.php?action=edit&header=false&tab=general&id=' . (isset($group_id) && $group_id > 0 ? $group_id : get_nfilter_request_var('id')));
exit;
} elseif (isset_request_var('save_component_realm_perms')) {
db_execute_prepared('DELETE FROM user_auth_group_realm WHERE group_id = ?', array(get_filter_request_var('id')));
foreach ($_POST as $var => $val) {
if (preg_match('/^[section]/i', $var)) {
if (substr($var, 0, 7) == 'section') {
db_execute_prepared('REPLACE INTO user_auth_group_realm (group_id, realm_id) VALUES (?, ?)', array(get_request_var('id'), substr($var, 7)));
}
}
}
reset_group_perms(get_request_var('id'));
raise_message(1);
header('Location: user_group_admin.php?action=edit&header=false&tab=realms&id=' . get_request_var('id'));
exit;
} elseif (isset_request_var('save_component_graph_settings')) {
foreach ($settings_user as $tab_short_name => $tab_fields) {
foreach ($tab_fields as $field_name => $field_array) {
if ((isset($field_array['items'])) && (is_array($field_array['items']))) {
foreach ($field_array['items'] as $sub_field_name => $sub_field_array) {
db_execute_prepared('REPLACE INTO settings_user_group (group_id, name, value) VALUES (?, ?, ?)', array(get_filter_request_var('id'), $sub_field_name, get_nfilter_request_var($sub_field_name, '')));
}
} else {
db_execute_prepared('REPLACE INTO settings_user_group (group_id, name, value) VALUES (?, ?, ?)', array(get_request_var('id'), $field_name, get_nfilter_request_var($field_name)));
}
}
}
kill_session_var('sess_user_config_array');
reset_group_perms(get_request_var('id'));
raise_message(1);
header('Location: user_group_admin.php?action=edit&header=false&tab=settings&id=' . get_nfilter_request_var('id'));
exit;
} else {
api_plugin_hook('user_group_admin_save');
}
/* redirect to the appropriate page */
header('Location: user_group_admin.php?action=edit&header=false&tab=general&id=' . get_nfilter_request_var('id'));
}
/* --------------------------
Graph Permissions
-------------------------- */
function perm_remove() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('group_id');
/* ==================================================== */
if (get_request_var('type') == 'graph') {
db_execute_prepared('DELETE FROM user_auth_group_perms WHERE type=1 AND group_id = ? AND item_id = ?', array(get_request_var('group_id'), get_request_var('id')));
} elseif (get_request_var('type') == 'tree') {
db_execute_prepared('DELETE FROM user_auth_group_perms WHERE type=2 AND group_id = ? AND item_id = ?', array(get_request_var('group_id'), get_request_var('id')));
} elseif (get_request_var('type') == 'host') {
db_execute_prepared('DELETE FROM user_auth_group_perms WHERE type=3 AND group_id = ? AND item_id = ?', array(get_request_var('group_id'), get_request_var('id')));
} elseif (get_request_var('type') == 'graph_template') {
db_execute_prepared('DELETE FROM user_auth_group_perms WHERE type=4 AND group_id = ? AND item_id = ?', array(get_request_var('group_id'), get_request_var('id')));
}
header('Location: user_group_admin.php?action=edit&header=false&tab=gperms&id=' . get_request_var('group_id'));
}
function user_group_members_edit($header_label) {
global $config, $auth_realms;
process_member_request_vars();
member_filter($header_label);
/* if the number of rows is -1, set it to the default */
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = "WHERE (username LIKE '%" . get_request_var('filter') . "%' OR full_name LIKE '%" . get_request_var('filter') . "%')";
} else {
$sql_where = '';
}
if (get_request_var('associated') == 'false') {
/* Show all items */
} else {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' (user_auth_group_members.group_id=' . get_request_var('id', 0) . ')';
}
$total_rows = db_fetch_cell("SELECT
COUNT(ua.id)
FROM user_auth AS ua
LEFT JOIN user_auth_group_members
ON (ua.id = user_auth_group_members.user_id)
$sql_where");
$sql_query = "SELECT DISTINCT ua.id, ua.username, ua.full_name, ua.enabled, ua.realm
FROM user_auth AS ua
LEFT JOIN user_auth_group_members
ON (ua.id = user_auth_group_members.user_id)
$sql_where
ORDER BY username, full_name
LIMIT " . ($rows*(get_request_var('page')-1)) . ',' . $rows;
$members = db_fetch_assoc($sql_query);
$nav = html_nav_bar('user_group_admin.php?action=edit&tab=members&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 7, __('Users'), 'page', 'main');
form_start(htmlspecialchars('user_group_admin.php?tab=members&id=' . get_request_var('id')), 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array( __('Login Name'), __('Full Name'), __('ID'), __('Membership'), __('Enabled'), __('Realm'));
html_header_checkbox($display_text, false);
if (sizeof($members)) {
foreach ($members as $g) {
form_alternate_row('line' . $g['id'], true);
form_selectable_cell(filter_value($g['username'], get_request_var('filter'), 'user_admin.php?action=user_edit&id=' . $g['id']), $g['id']);
form_selectable_cell(filter_value($g['full_name'], get_request_var('filter')), $g['id']);
form_selectable_cell($g['id'], $g['id']);
if (user_group_is_member($g['id'], get_request_var('id'))) {
form_selectable_cell('' . __('Group Member') . ' ', $g['id']);
} else {
form_selectable_cell('' . __('Non Member') . ' ', $g['id']);
}
form_selectable_cell(($g['enabled'] == 'on' ? __('Enabled'): __('Disabled') ), $g['id']);
form_selectable_cell((isset($auth_realms[$g['realm']]) ? $auth_realms[$g['realm']]:'Unknown'), $g['id']);
form_checkbox_cell($g['full_name'], $g['id']);
form_end_row();
}
} else {
print '' . __('No Matching Group Members Found') . ' ';
}
html_end_box(false);
if (sizeof($members)) {
print $nav;
}
form_hidden_box('tab', 'members', '');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_member', '1', '');
$assoc_actions = array(
1 => __('Add to Group'),
2 => __('Remove from Group')
);
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
}
function user_group_graph_perms_edit($tab, $header_label) {
global $config, $assoc_actions;
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
$policy_array = array(
1 => __('Allow'),
2 => __('Deny')
);
if (!isempty_request_var('id')) {
$policy = db_fetch_row_prepared('SELECT policy_graphs, policy_trees, policy_hosts, policy_graph_templates FROM user_auth_group WHERE id = ?', array(get_request_var('id')));
}
switch($tab) {
case 'permsg':
process_graph_request_vars();
graph_filter($header_label);
form_start('user_group_admin.php', 'policy');
/* box: device permissions */
html_start_box( __('Default Graph Policy'), '100%', '', '3', 'center', '');
?>
0)";
} else {
$sql_where = 'WHERE (gtg.local_graph_id>0)';
}
if (get_request_var('graph_template_id') == '-1') {
/* Show all items */
} elseif (get_request_var('graph_template_id') == '0') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' gtg.graph_template_id=0';
} elseif (!isempty_request_var('graph_template_id')) {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' gtg.graph_template_id=' . get_request_var('graph_template_id');
}
if (get_request_var('associated') == 'false') {
/* Show all items */
} else {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' (user_auth_group_perms.type = 1 AND user_auth_group_perms.group_id=' . get_request_var('id', 0) . ')';
}
$total_rows = db_fetch_cell("SELECT
COUNT(DISTINCT gtg.id)
FROM graph_templates_graph AS gtg
LEFT JOIN user_auth_group_perms
ON (gtg.local_graph_id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 1 AND user_auth_group_perms.group_id = " . get_request_var('id') . ")
$sql_where");
$sql_query = "SELECT gtg.local_graph_id, gtg.title_cache, user_auth_group_perms.group_id
FROM graph_templates_graph AS gtg
LEFT JOIN user_auth_group_perms
ON (gtg.local_graph_id=user_auth_group_perms.item_id AND user_auth_group_perms.type = 1 AND user_auth_group_perms.group_id = " . get_request_var('id') . ")
$sql_where
ORDER BY title_cache
LIMIT " . ($rows*(get_request_var('page')-1)) . ',' . $rows;
$graphs = db_fetch_assoc($sql_query);
$nav = html_nav_bar('user_group_admin.php?action=edit&tab=permsg&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 7, __('Graphs'), 'page', 'main');
form_start(htmlspecialchars('user_group_admin.php?tab=permsg&id=' . get_request_var('id')), 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array( __('Graph Title'), __('ID'), __('Effective Policy'));
html_header_checkbox($display_text, false);
if (sizeof($graphs)) {
foreach ($graphs as $g) {
form_alternate_row('line' . $g['local_graph_id'], true);
form_selectable_cell(filter_value($g['title_cache'], get_request_var('filter')), $g['local_graph_id']);
form_selectable_cell($g['local_graph_id'], $g['local_graph_id']);
if (empty($g['group_id']) || $g['group_id'] == NULL) {
if ($policy['policy_graphs'] == 1) {
form_selectable_cell('' . __('Access Granted') . ' ', $g['local_graph_id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $g['local_graph_id']);
}
} else {
if ($policy['policy_graphs'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $g['local_graph_id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $g['local_graph_id']);
}
}
form_checkbox_cell($g['title_cache'], $g['local_graph_id']);
form_end_row();
}
} else {
print '' . __('No Matching Graphs Found') . ' ';
}
html_end_box(false);
if (sizeof($graphs)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_graph', '1', '');
if ($policy['policy_graphs'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permsd':
process_device_request_vars();
device_filter($header_label);
form_start('user_group_admin.php', 'policy');
/* box: device permissions */
html_start_box( __('Default Device Policy'), '100%', '', '3', 'center', '');
?>
' . __('Access Granted') . '', $host['id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $host['id']);
}
} else {
if ($policy['policy_hosts'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $host['id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $host['id']);
}
}
form_selectable_cell((isset($host_graphs[$host['id']]) ? $host_graphs[$host['id']] : 0), $host['id']);
form_selectable_cell((isset($host_data_sources[$host['id']]) ? $host_data_sources[$host['id']] : 0), $host['id']);
form_selectable_cell(get_colored_device_status(($host['disabled'] == 'on' ? true : false), $host['status']), $host['id']);
form_selectable_cell(filter_value($host['hostname'], get_request_var('filter')), $host['id']);
form_checkbox_cell($host['description'], $host['id']);
form_end_row();
}
} else {
print '' . __('No Matching Devices Found') . ' ';
}
html_end_box(false);
if (sizeof($hosts)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_host', '1', '');
if ($policy['policy_hosts'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permste':
process_template_request_vars();
template_filter($header_label);
form_start('user_group_admin.php', 'policy');
/* box: device permissions */
html_start_box( __('Default Graph Template Policy'), '100%', '', '3', 'center', '');
?>
' . __('Access Granted') . '', $g['id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $g['id']);
}
} else {
if ($policy['policy_graph_templates'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $g['id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $g['id']);
}
}
form_selectable_cell($g['totals'], $g['id']);
form_checkbox_cell($g['name'], $g['id']);
form_end_row();
}
} else {
print '' . __('No Matching Graph Templates Found') . ' ';
}
html_end_box(false);
if (sizeof($graphs)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_template', '1', '');
if ($policy['policy_graph_templates'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permstr':
process_tree_request_vars();
tree_filter($header_label);
form_start('user_group_admin.php', 'policy');
/* box: device permissions */
html_start_box( __('Default Tree Policy'), '100%', '', '3', 'center', '');
?>
' . __('Access Granted') . '', $t['id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $t['id']);
}
} else {
if ($policy['policy_trees'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $t['id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $t['id']);
}
}
form_checkbox_cell($t['name'], $t['id']);
form_end_row();
}
} else {
print '' . __('No Matching Trees Found') . ' ';
}
html_end_box(false);
if (sizeof($trees)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_tree', '1', '');
if ($policy['policy_trees'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
}
}
function user_group_is_member($user_id, $group_id) {
return db_fetch_cell_prepared('SELECT COUNT(*) FROM user_auth_group_members WHERE user_id = ? AND group_id = ?', array($user_id, $group_id));
}
function user_group_realms_edit($header_label) {
global $user_auth_realms, $user_auth_roles;
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
print "\n";
form_start('user_group_admin.php', 'chk');
$all_realms = $user_auth_realms;
html_start_box('', '100%', '', '3', 'center', '');
/* do cacti realms first */
$i = 1;
foreach($user_auth_roles as $role_name => $perms) {
$j = 1;
print "\n";
print "\n";
foreach($perms as $realm) {
if ($j == 1) {
print "\n";
}
print "\n";
if (isset($user_auth_realms[$realm])) {
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_group_realm WHERE group_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
unset($all_realms[$realm]);
form_checkbox('section' . $realm, $old_value, $user_auth_realms[$realm], '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
}
print " \n";
if ($j == 5) {
print " \n";
$j = 1;
} else {
$j++;
}
}
if ($j > 1) {
print " \n";
print "\n";
}
print "
\n";
}
?>
__('Console'),
'TAB' => __('Top Tab'),
'FRONT' => __('Bottom Console'),
'FRONTTOP' => __('Top Console')
);
print "\n";
print "\n";
if (sizeof($links)) {
$j = 1;
foreach($links as $r) {
if ($j == 1) {
print " \n";
}
$realm = $r['id'] + 10000;
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_group_realm WHERE group_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
unset($all_realms[$realm]);
print "\n";
switch($r['style']) {
case 'CONSOLE':
$description = $style_translate[$r['style']] . ': ' . ($r['extendedstyle'] == '' ? 'External Links' : $r['extendedstyle']) . '/' . $r['title'];
break;
default:
$description = $style_translate[$r['style']] . ': ' . ucfirst($r['title']);
break;
}
form_checkbox('section' . $realm, $old_value, $description, '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
print " \n";
if ($j == 5) {
print " \n";
$j = 1;
} else {
$j++;
}
}
if ($j > 1) {
print " \n";
print "\n";
}
}
print "
\n";
/* do plugin realms */
$realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display
FROM plugin_config AS pc
INNER JOIN plugin_realms AS pr
ON pc.directory = pr.plugin
ORDER BY pc.name, pr.display');
print "\n";
print "\n";
if (sizeof($realms)) {
$last_plugin = 'none';
$i = 1;
$j = 1;
foreach($realms as $r) {
$break = false;
if ($last_plugin != $r['name'] && $last_plugin != 'none') {
$break = true;
if ($j == 5) {
print " \n";
$break = true;;
$j = 1;
} else {
$j++;
}
}
if ($break) {
print "\n";
}
if ($break || $i == 1) {
print '' . $r['name'] . " \n";
}
$realm = $r['realm_id'] + 100;
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_group_realm WHERE group_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
unset($all_realms[$realm]);
$pos = (strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->')+2:0);
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
$last_plugin = $r['name'];
$i++;
}
}
/* get the old PIA 1.x realms */
if (sizeof($all_realms)) {
if ($break) {
print " \n";
}
print "Legacy 1.x Plugins \n";
foreach($all_realms as $realm => $name) {
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_group_realm WHERE group_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
$pos = (strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->')+2:0);
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
}
}
print "
\n";
html_end_box();
form_hidden_box('save_component_realm_perms','1','');
form_hidden_box('tab','realms','');
form_hidden_box('id',get_request_var('id'),'');
form_save_button('user_group_admin.php', 'return');
}
function user_group_settings_edit($header_label) {
global $settings_user, $tabs_graphs, $graph_views;
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
form_start('user_group_admin.php', 'chk');
html_start_box( __('User Settings %s', $header_label), '100%', true, '3', 'center', '');
foreach ($settings_user as $tab_short_name => $tab_fields) {
$collapsible = true;
print "\n";
$form_array = array();
foreach ($tab_fields as $field_name => $field_array) {
$form_array += array($field_name => $tab_fields[$field_name]);
if ((isset($field_array['items'])) && (is_array($field_array['items']))) {
foreach ($field_array['items'] as $sub_field_name => $sub_field_array) {
if (graph_config_value_exists($sub_field_name, get_request_var('id'))) {
$form_array[$field_name]['items'][$sub_field_name]['form_id'] = 1;
}
$form_array[$field_name]['items'][$sub_field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_user_group WHERE name = ? AND group_id = ?', array($sub_field_name, get_request_var('id')));
}
} else {
if (graph_config_value_exists($field_name, get_request_var('id'))) {
$form_array[$field_name]['form_id'] = 1;
}
$form_array[$field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_user_group WHERE name = ? AND group_id = ?', array($field_name, get_request_var('id')));
}
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => $form_array
)
);
}
html_end_box(true, true);
form_hidden_box('save_component_graph_settings','1','');
form_hidden_box('tab','settings','');
form_hidden_box('id',get_request_var('id'),'');
form_save_button('user_group_admin.php', 'return');
?>
array('regexp' => '/^([a-zA-Z]+)$/')));
/* ==================================================== */
/* present a tabbed interface */
$tabs = array(
'general' => __('General'),
'members' => __('Members'),
'realms' => __('Permissions'),
'permsg' => __('Graph Perms'),
'permsd' => __('Device Perms'),
'permste' => __('Template Perms'),
'permstr' => __('Tree Perms'),
'settings' => __('User Settings')
);
$tabs = api_plugin_hook_function('ugroup_tabs', $tabs);
if (!isempty_request_var('id')) {
$group = db_fetch_row_prepared('SELECT * FROM user_auth_group WHERE id = ?', array(get_request_var('id')));
$header_label = __('User Group Management [edit: %s]', $group['name']);
} else {
$header_label = __('User Group Management [new]');
}
/* set the default tab */
load_current_session_value('tab', 'sess_ugroup_tab', 'general');
$current_tab = get_nfilter_request_var('tab');
if (sizeof($tabs) && !isempty_request_var('id')) {
$i = 0;
/* draw the tabs */
print "\n";
}
switch(get_request_var('tab')) {
case 'general':
api_plugin_hook_function('user_group_admin_edit', (isset($user) ? get_request_var('id') : 0));
form_start('user_group_admin.php');
html_start_box( $header_label, '100%', true, '3', 'center', '');
draw_edit_form(array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_user_group_edit, (isset($group) ? $group : array()))
));
html_end_box(true, true);
form_save_button('user_group_admin.php', 'return');
break;
case 'settings':
user_group_settings_edit($header_label);
break;
case 'realms':
user_group_realms_edit($header_label);
break;
case 'permsg':
case 'permsd':
case 'permste':
case 'permstr':
user_group_graph_perms_edit(get_request_var('tab'), $header_label);
break;
case 'members':
user_group_members_edit($header_label);
break;
}
}
function user_group() {
global $group_actions, $item_rows;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'has_graphs' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_ugad');
/* ================= input validation ================= */
?>
array(__('Group Name'), 'ASC'),
'members' => array(__('Members'), 'ASC'),
'description' => array(__('Description'), 'ASC'),
'policy_graphs' => array(__('Graph Policy'), 'ASC'),
'policy_hosts' => array(__('Device Policy'), 'ASC'),
'policy_graph_templates' => array(__('Template Policy'), 'ASC'),
'enabled' => array(__('Enabled'), 'ASC')
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (sizeof($group_list)) {
foreach ($group_list as $group) {
if ($group['enabled'] == 'on') {
$enabled = __('Yes');
} else {
$enabled = __('No');
}
form_alternate_row('line' . $group['id'], true);
form_selectable_cell(filter_value($group['name'], get_request_var('filter'), 'user_group_admin.php?action=edit&tab=general&id=' . $group['id']), $group['id']);
form_selectable_cell(($group['members'] > 0 ? number_format_i18n($group['members'], 0):'None'), $group['id']);
form_selectable_cell(filter_value($group['description'], get_request_var('filter')), $group['id']);
form_selectable_cell(($group['policy_graphs'] == 1 ? __('ALLOW') : __('DENY') ), $group['id']);
form_selectable_cell(($group['policy_hosts'] == 1 ? __('ALLOW') : __('DENY') ), $group['id']);
form_selectable_cell(($group['policy_graph_templates'] == 1 ? __('ALLOW') : __('DENY') ), $group['id']);
form_selectable_cell($enabled, $group['id']);
form_checkbox_cell($group['name'], $group['id']);
form_end_row();
}
} else {
print '' . __('No User Groups Found') . ' ';
}
html_end_box(false);
if (sizeof($group_list)) {
print $nav;
}
draw_actions_dropdown($group_actions);
form_end();
}
function process_graph_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
),
'graph_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_ugg');
/* ================= input validation ================= */
}
function process_device_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
),
'host_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_ugd');
/* ================= input validation ================= */
}
function process_template_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
),
'host_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_ugte');
/* ================= input validation ================= */
}
function process_tree_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_ugtr');
/* ================= input validation ================= */
}
function process_member_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_ugm');
/* ================= input validation ================= */
}
function graph_filter($header_label) {
global $config, $item_rows;
?>
__('Delete'),
2 => __('Disable'),
3 => __('Enable'),
4 => __('Default')
);
/* set default action */
set_default_action();
switch (get_request_var('action')) {
case 'save':
form_save();
break;
case 'actions':
form_actions();
break;
case 'edit':
top_header();
domain_edit();
bottom_footer();
break;
default:
top_header();
domains();
bottom_footer();
break;
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
global $registered_cacti_names;
if (isset_request_var('save_component_domain_ldap')) {
/* ================= input validation ================= */
get_filter_request_var('domain_id');
get_filter_request_var('type');
get_filter_request_var('user_id');
/* ==================================================== */
$save['domain_id'] = get_nfilter_request_var('domain_id');
$save['type'] = get_nfilter_request_var('type');
$save['user_id'] = get_nfilter_request_var('user_id');
$save['domain_name'] = form_input_validate(get_nfilter_request_var('domain_name'), 'domain_name', '', false, 3);
$save['enabled'] = (isset_request_var('enabled') ? form_input_validate(get_nfilter_request_var('enabled'), 'enabled', '', true, 3):'');
if (!is_error_message()) {
$domain_id = sql_save($save, 'user_domains', 'domain_id');
if ($domain_id) {
raise_message(1);
} else {
raise_message(2);
}
if (!is_error_message()) {
/* ================= input validation ================= */
get_filter_request_var('domain_id');
get_filter_request_var('port');
get_filter_request_var('port_ssl');
get_filter_request_var('proto_version');
get_filter_request_var('encryption');
get_filter_request_var('referrals');
get_filter_request_var('mode');
get_filter_request_var('group_member_type');
/* ==================================================== */
$save = array();
$save['domain_id'] = $domain_id;
$save['server'] = form_input_validate(get_nfilter_request_var('server'), 'server', '', false, 3);
$save['port'] = get_nfilter_request_var('port');
$save['port_ssl'] = get_nfilter_request_var('port_ssl');
$save['proto_version'] = get_nfilter_request_var('proto_version');
$save['encryption'] = get_nfilter_request_var('encryption');
$save['referrals'] = get_nfilter_request_var('referrals');
$save['mode'] = get_nfilter_request_var('mode');
$save['group_member_type'] = get_nfilter_request_var('group_member_type');
$save['dn'] = form_input_validate(get_nfilter_request_var('dn'), 'dn', '', true, 3);
$save['group_require'] = isset_request_var('group_require') ? 'on':'';
$save['group_dn'] = form_input_validate(get_nfilter_request_var('group_dn'), 'group_dn', '', true, 3);
$save['group_attrib'] = form_input_validate(get_nfilter_request_var('group_attrib'), 'group_attrib', '', true, 3);
$save['search_base'] = form_input_validate(get_nfilter_request_var('search_base'), 'search_base', '', true, 3);
$save['search_filter'] = form_input_validate(get_nfilter_request_var('search_filter'), 'search_filter', '', true, 3);
$save['specific_dn'] = form_input_validate(get_nfilter_request_var('specific_dn'), 'specific_dn', '', true, 3);
$save['specific_password'] = form_input_validate(get_nfilter_request_var('specific_password'), 'specific_password', '', true, 3);
if (!is_error_message()) {
$insert_id = sql_save($save, 'user_domains_ldap', 'domain_id', false);
if ($insert_id) {
raise_message(1);
} else {
raise_message(2);
}
}
}
}
} elseif (isset_request_var('save_component_domain')) {
/* ================= input validation ================= */
get_filter_request_var('domain_id');
get_filter_request_var('type');
get_filter_request_var('user_id');
/* ==================================================== */
$save['domain_id'] = get_nfilter_request_var('domain_id');
$save['domain_name'] = form_input_validate(get_nfilter_request_var('domain_name'), 'domain_name', '', false, 3);
$save['type'] = get_nfilter_request_var('type');
$save['user_id'] = get_nfilter_request_var('user_id');
$save['enabled'] = (isset_request_var('enabled') ? form_input_validate(get_nfilter_request_var('enabled'), 'enabled', '', true, 3):'');
if (!is_error_message()) {
$domain_id = sql_save($save, 'user_domains', 'domain_id');
if ($domain_id) {
raise_message(1);
} else {
raise_message(2);
}
}
}
header('Location: user_domains.php?header=false&action=edit&domain_id=' . (empty($domain_id) ? get_nfilter_request_var('domain_id') : $domain_id));
}
function form_actions() {
global $actions;
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { // delete
for ($i=0;($i 1) {
/* error message */
} else {
for ($i=0;($i $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$d_list .= '' . db_fetch_cell_prepared('SELECT domain_name FROM user_domains WHERE domain_id = ?', array($matches[1])) . ' ';
$d_array[] = $matches[1];
}
}
top_header();
form_start('user_domains.php');
html_start_box($actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (isset($d_array) && sizeof($d_array)) {
if (get_nfilter_request_var('drp_action') == '1') { // delete
print "
" . __n('Click \'Continue\' to delete the following User Domain.', 'Click \'Continue\' to delete following User Domains.', sizeof($d_array)) . "
\n";
$save_html = " ";
}else if (get_nfilter_request_var('drp_action') == '2') { // disable
print "
" . __n('Click \'Continue\' to disable the following User Domain.', 'Click \'Continue\' to disable following User Domains.', sizeof($d_array)) . "
\n";
$save_html = " ";
}else if (get_nfilter_request_var('drp_action') == '3') { // enable
print "
" . __('Click \'Continue\' to enable the following User Domain.', 'Click \'Continue\' to enable following User Domains.', sizeof($d_array)) . "
\n";
$save_html = " ";
}else if (get_nfilter_request_var('drp_action') == '4') { // default
print "
" . __('Click \'Continue\' to make the following the following User Domain the default one.') . "
\n";
$save_html = " ";
}
} else {
print "" . __('You must select at least one User Domain.') . " \n";
$save_html = " ";
}
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}
/* -----------------------
Domain Functions
----------------------- */
function domain_remove($domain_id) {
db_execute_prepared('DELETE FROM user_domains WHERE domain_id = ?', array($domain_id));
db_execute_prepared('DELETE FROM user_domains_ldap WHERE domain_id = ?', array($domain_id));
}
function domain_disable($domain_id) {
db_execute_prepared('UPDATE user_domains SET enabled = "" WHERE domain_id = ?', array($domain_id));
}
function domain_enable($domain_id) {
db_execute_prepared('UPDATE user_domains SET enabled = "on" WHERE domain_id = ?', array($domain_id));
}
function domain_default($domain_id) {
db_execute('UPDATE user_domains SET defdomain = 0');
db_execute_prepared('UPDATE user_domains SET defdomain = 1 WHERE domain_id = ?', array($domain_id));
}
function domain_edit() {
global $ldap_versions, $ldap_encryption, $ldap_modes, $domain_types;
/* ================= input validation ================= */
get_filter_request_var('domain_id');
/* ==================================================== */
if (!isempty_request_var('domain_id')) {
$domain = db_fetch_row_prepared('SELECT * FROM user_domains WHERE domain_id = ?', array(get_request_var('domain_id')));
$header_label = __('User Domain [edit: %s]', $domain['domain_name']);
} else {
$header_label = __('User Domain [new]');
}
/* file: data_input.php, action: edit */
$fields_domain_edit = array(
'domain_name' => array(
'method' => 'textbox',
'friendly_name' => __('Name'),
'description' => __('Enter a meaningful name for this domain. This will be the name that appears in the Login Realm during login.'),
'value' => '|arg1:domain_name|',
'max_length' => '255',
),
'type' => array(
'method' => 'drop_array',
'friendly_name' => __('Domains Type'),
'description' => __('Choose what type of domain this is.'),
'value' => '|arg1:type|',
'array' => $domain_types,
'default' => '2'
),
'user_id' => array(
'friendly_name' => __('User Template'),
'description' => __('The name of the user that Cacti will use as a template for new user accounts.'),
'method' => 'drop_sql',
'value' => '|arg1:user_id|',
'none_value' => __('No User'),
'sql' => 'SELECT id AS id, username AS name FROM user_auth WHERE realm=0 ORDER BY username',
'default' => '0'
),
'enabled' => array(
'method' => 'checkbox',
'friendly_name' => __('Enabled'),
'description' => __('If this checkbox is checked, users will be able to login using this domain.'),
'value' => '|arg1:enabled|',
'default' => '',
),
'domain_id' => array(
'method' => 'hidden_zero',
'value' => '|arg1:domain_id|'
),
'save_component_domain' => array(
'method' => 'hidden',
'value' => '1'
)
);
$fields_domain_ldap_edit = array(
'server' => array(
'friendly_name' => __('Server'),
'description' => __('The dns hostname or ip address of the server.'),
'method' => 'textbox',
'value' => '|arg1:server|',
'default' => read_config_option('ldap_server'),
'max_length' => '255'
),
'port' => array(
'friendly_name' => __('Port Standard'),
'description' => __('TCP/UDP port for Non SSL communications.'),
'method' => 'textbox',
'max_length' => '5',
'value' => '|arg1:port|',
'default' => read_config_option('ldap_port'),
'size' => '5'
),
'port_ssl' => array(
'friendly_name' => __('Port SSL'),
'description' => __('TCP/UDP port for SSL communications.'),
'method' => 'textbox',
'max_length' => '5',
'value' => '|arg1:port_ssl|',
'default' => read_config_option('ldap_port_ssl'),
'size' => '5'
),
'proto_version' => array(
'friendly_name' => __('Protocol Version'),
'description' => __('Protocol Version that the server supports.'),
'method' => 'drop_array',
'value' => '|arg1:proto_version|',
'array' => $ldap_versions
),
'encryption' => array(
'friendly_name' => __('Encryption'),
'description' => __('Encryption that the server supports. TLS is only supported by Protocol Version 3.'),
'method' => 'drop_array',
'value' => '|arg1:encryption|',
'array' => $ldap_encryption
),
'referrals' => array(
'friendly_name' => __('Referrals'),
'description' => __('Enable or Disable LDAP referrals. If disabled, it may increase the speed of searches.'),
'method' => 'drop_array',
'value' => '|arg1:referrals|',
'array' => array( '0' => __('Disabled'), '1' => __('Enable'))
),
'mode' => array(
'friendly_name' => __('Mode'),
'description' => __('Mode which cacti will attempt to authenticate against the LDAP server.No Searching - No Distinguished Name (DN) searching occurs, just attempt to bind with the provided Distinguished Name (DN) format.Anonymous Searching - Attempts to search for username against LDAP directory via anonymous binding to locate the users Distinguished Name (DN).Specific Searching - Attempts search for username against LDAP directory via Specific Distinguished Name (DN) and Specific Password for binding to locate the users Distinguished Name (DN).'),
'method' => 'drop_array',
'value' => '|arg1:mode|',
'array' => $ldap_modes
),
'dn' => array(
'friendly_name' => __('Distinguished Name (DN)'),
'description' => __('Distinguished Name syntax, such as for windows: "<username>@win2kdomain.local" or for OpenLDAP: "uid=<username>,ou=people,dc=domain,dc=local" . "<username>" is replaced with the username that was supplied at the login prompt. This is only used when in "No Searching" mode.'),
'method' => 'textbox',
'value' => '|arg1:dn|',
'max_length' => '255'
),
'group_require' => array(
'friendly_name' => __('Require Group Membership'),
'description' => __('Require user to be member of group to authenticate. Group settings must be set for this to work, enabling without proper group settings will cause authentication failure.'),
'value' => '|arg1:group_require|',
'method' => 'checkbox'
),
'group_header' => array(
'friendly_name' => __('LDAP Group Settings'),
'method' => 'spacer'
),
'group_dn' => array(
'friendly_name' => __('Group Distinguished Name (DN)'),
'description' => __('Distinguished Name of the group that user must have membership.'),
'method' => 'textbox',
'value' => '|arg1:group_dn|',
'max_length' => '255'
),
'group_attrib' => array(
'friendly_name' => __('Group Member Attribute'),
'description' => __('Name of the attribute that contains the usernames of the members.'),
'method' => 'textbox',
'value' => '|arg1:group_attrib|',
'max_length' => '255'
),
'group_member_type' => array(
'friendly_name' => __('Group Member Type'),
'description' => __('Defines if users use full Distinguished Name or just Username in the defined Group Member Attribute.'),
'method' => 'drop_array',
'value' => '|arg1:group_member_type|',
'array' => array( 1 => 'Distinguished Name', 2 => 'Username' )
),
'search_base_header' => array(
'friendly_name' => __('LDAP Specific Search Settings'),
'method' => 'spacer'
),
'search_base' => array(
'friendly_name' => __('Search Base'),
'description' => __('Search base for searching the LDAP directory, such as "dc=win2kdomain,dc=local" or "ou=people,dc=domain,dc=local" .'),
'method' => 'textbox',
'value' => '|arg1:search_base|',
'max_length' => '255'
),
'search_filter' => array(
'friendly_name' => __('Search Filter'),
'description' => __('Search filter to use to locate the user in the LDAP directory, such as for windows: "(&(objectclass=user)(objectcategory=user)(userPrincipalName=<username>*))" or for OpenLDAP: "(&(objectClass=account)(uid=<username>))" . "<username>" is replaced with the username that was supplied at the login prompt.'),
'method' => 'textbox',
'value' => '|arg1:search_filter|',
'max_length' => '255'
),
'specific_dn' => array(
'friendly_name' => __('Search Distinguished Name (DN)'),
'description' => __('Distinguished Name for Specific Searching binding to the LDAP directory.'),
'method' => 'textbox',
'value' => '|arg1:specific_dn|',
'max_length' => '255'
),
'specific_password' => array(
'friendly_name' => __('Search Password'),
'description' => __('Password for Specific Searching binding to the LDAP directory.'),
'method' => 'textbox_password',
'value' => '|arg1:specific_password|',
'max_length' => '255'
),
'save_component_domain_ldap' => array(
'method' => 'hidden',
'value' => '1'
)
);
form_start('user_domains.php');
html_start_box($header_label, '100%', true, '3', 'center', '');
draw_edit_form(array(
'config' => array(),
'fields' => inject_form_variables($fields_domain_edit, (isset($domain) ? $domain : array()))
));
html_end_box(true, true);
if (!isempty_request_var('domain_id')) {
$domain = db_fetch_row_prepared('SELECT * FROM user_domains_ldap WHERE domain_id = ?', array(get_request_var('domain_id')));
html_start_box( __('Domain Properties'), '100%', true, '3', 'center', '');
draw_edit_form(array(
'config' => array(),
'fields' => inject_form_variables($fields_domain_ldap_edit, (isset($domain) ? $domain : array()))
));
html_end_box(true, true);
}
?>
array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'domain_name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_domains');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
html_start_box( __('User Domains'), '100%', '', '3', 'center', 'user_domains.php?action=edit');
?>
array( __('Domain Name'), 'ASC'),
'type' => array( __('Domain Type'), 'ASC'),
'defdomain' => array( __('Default'), 'ASC'),
'user_id' => array( __('Effective User'), 'ASC'),
'enabled' => array( __('Enabled'), 'ASC'));
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
$i = 0;
if (sizeof($domains)) {
foreach ($domains as $domain) {
/* hide system types */
form_alternate_row('line' . $domain['domain_id'], true);
form_selectable_cell(filter_value($domain['domain_name'], get_request_var('filter'), 'user_domains.php?action=edit&domain_id=' . $domain['domain_id']), $domain['domain_id']);
form_selectable_cell($domain_types[$domain['type']], $domain['domain_id']);
form_selectable_cell( ($domain['defdomain'] == '0' ? '--': __('Yes') ), $domain['domain_id']);
form_selectable_cell( ($domain['user_id'] == '0' ? __('None Selected') : db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array($domain['user_id']))), $domain['domain_id']);
form_selectable_cell( ($domain['enabled'] == 'on' ? __('Yes'):__('No') ), $domain['domain_id']);
form_checkbox_cell($domain['domain_name'], $domain['domain_id']);
form_end_row();
}
} else {
print '' . __('No User Domains Found') . ' ';
}
html_end_box(false);
if (sizeof($domains)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($actions);
form_end();
}
cacti-1.1.38/user_admin.php 0000664 0001750 0001750 00000304722 13264740213 015124 0 ustar troman troman __('Delete'),
2 => __('Copy'),
3 => __('Enable'),
4 => __('Disable'),
5 => __('Batch Copy')
);
set_default_action();
if (isset_request_var('update_policy')) {
update_policies();
} else {
switch (get_request_var('action')) {
case 'actions':
form_actions();
break;
case 'save':
form_save();
break;
case 'perm_remove':
perm_remove();
break;
case 'user_edit':
top_header();
user_edit();
bottom_footer();
break;
case 'checkpass':
$error = secpass_check_pass(get_nfilter_request_var('password'));
if ($error == '') {
print $error;
} else {
print 'ok';
}
break;
default:
if (!api_plugin_hook_function('user_admin_action', get_request_var('action'))) {
top_header();
user();
bottom_footer();
}
break;
}
}
/* --------------------------
Actions Function
-------------------------- */
function update_policies() {
$set = '';
$set .= isset_request_var('policy_graphs') ? 'policy_graphs=' . get_nfilter_request_var('policy_graphs'):'';
$set .= isset_request_var('policy_trees') ? ($set != '' ? ',':'') . 'policy_trees=' . get_nfilter_request_var('policy_trees'):'';
$set .= isset_request_var('policy_hosts') ? ($set != '' ? ',':'') . 'policy_hosts=' . get_nfilter_request_var('policy_hosts'):'';
$set .= isset_request_var('policy_graph_templates') ? ($set != '' ? ',':'') . 'policy_graph_templates=' . get_nfilter_request_var('policy_graph_templates'):'';
if ($set != '') {
db_execute_prepared("UPDATE user_auth SET $set WHERE id = ?", array(get_nfilter_request_var('id')));
}
header('Location: user_admin.php?action=user_edit&header=false&tab=' . get_nfilter_request_var('tab') . '&id=' . get_nfilter_request_var('id'));
exit;
}
function form_actions() {
global $user_actions, $auth_realms;
/* if we are to save this form, instead of display it */
if (isset_request_var('associate_host')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id, item_id, type)
VALUES (?, ?, 3)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE user_id = ?
AND item_id = ?
AND type = 3',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_admin.php?action=user_edit&header=false&tab=permsd&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_graph')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id, item_id, type)
VALUES (?, ?, 1)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE user_id = ?
AND item_id = ?
AND type = 1',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_admin.php?action=user_edit&header=false&tab=permsg&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_template')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id, item_id, type)
VALUES (?, ?, 4)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE user_id = ?
AND item_id = ?
AND type = 4',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_admin.php?action=user_edit&header=false&tab=permste&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_groups')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_group_members
(user_id, group_id)
VALUES (?, ?)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_group_members
WHERE user_id = ?
AND group_id = ?',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_admin.php?action=user_edit&header=false&tab=permsgr&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('associate_tree')) {
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') == '1') {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id, item_id, type)
VALUES (?, ?, 2)',
array(get_nfilter_request_var('id'), $matches[1]));
} else {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE user_id = ?
AND item_id = ?
AND type = 2',
array(get_nfilter_request_var('id'), $matches[1]));
}
}
}
header('Location: user_admin.php?action=user_edit&header=false&tab=permstr&id=' . get_nfilter_request_var('id'));
exit;
} elseif (isset_request_var('selected_items')) {
if (get_nfilter_request_var('drp_action') == '2') { /* copy */
/* ================= input validation ================= */
get_filter_request_var('selected_items');
get_filter_request_var('new_realm');
/* ==================================================== */
$new_username = get_nfilter_request_var('new_username');
$new_realm = get_nfilter_request_var('new_realm', 0);
$template_user = db_fetch_row_prepared('SELECT username, realm
FROM user_auth
WHERE id = ?',
array(get_nfilter_request_var('selected_items')));
$overwrite = array( 'full_name' => get_nfilter_request_var('new_fullname') );
if ($new_username != '') {
if (sizeof(db_fetch_assoc_prepared('SELECT username FROM user_auth WHERE username = ? AND realm = ?', array($new_username, $new_realm)))) {
raise_message(19);
} else {
if (user_copy($template_user['username'], $new_username, $template_user['realm'], $new_realm, false, $overwrite) === false) {
raise_message(2);
} else {
raise_message(1);
}
}
}
} else {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { // delete
for ($i=0;($i $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (get_nfilter_request_var('drp_action') != '2') {
$user_list .= '' . htmlspecialchars(db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array($matches[1]))) . ' ';
}
$user_array[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('user_admin.php');
html_start_box($user_actions[get_nfilter_request_var('drp_action')], '40%', '', '3', 'center', '');
if (isset($user_array) && sizeof($user_array)) {
if ((get_nfilter_request_var('drp_action') == '1') && (sizeof($user_array))) { // delete
print "
" . __('Click \'Continue\' to delete the selected User(s).') . "
\n";
$save_html = " ";
}
$user_id = '';
if ((get_nfilter_request_var('drp_action') == '2') && (sizeof($user_array))) { // copy
$user_id = $user_array[0];
$user_realm = db_fetch_cell_prepared('SELECT realm FROM user_auth WHERE id = ?', array($user_id));
print "
" . __('Click \'Continue\' to copy the selected User to a new User below.') . "
" . __('Template Username:') . " " . htmlspecialchars(db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array($user_id))) . "
" . __('Username:') . " ";
print form_text_box('new_username', '', '', 25);
print "
" . __('Full Name:') . " ";
print form_text_box('new_fullname', '', '', 35);
print "
" . __('Realm:') ." ";
print form_dropdown('new_realm', $auth_realms, '', '', $user_realm, '', 0);
print "
\n";
$save_html = " ";
}
if ((get_nfilter_request_var('drp_action') == '3') && (sizeof($user_array))) { // enable
print "
" . __('Click \'Continue\' to enable the selected User(s).'). "
\n";
$save_html = " ";
}
if ((get_nfilter_request_var('drp_action') == '4') && (sizeof($user_array))) { // disable
print "
" . __('Click \'Continue\' to disable the selected User(s).') . "
\n";
$save_html = " ";
}
if ((get_nfilter_request_var('drp_action') == '5') && (sizeof($user_array))) { // batch copy
$usernames = db_fetch_assoc('SELECT id, username FROM user_auth WHERE realm = 0 ORDER BY username');
print "
" . __('Click \'Continue\' to overwrite the User(s) settings with the selected template User settings and permissions. The original users Full Name, Password, Realm and Enable status will be retained, all other fields will be overwritten from Template User.') . "
" . __('Template User:') . " ";
print form_dropdown('template_user', $usernames, 'username', 'id', '', '', 0);
print "
" . __('User(s) to update:') . "
\n";
$save_html = " ";
}
} else {
print "" . __('You must select at least one user.') . " \n";
$save_html = " ";
}
print "
";
if (get_nfilter_request_var('drp_action') == '2') { // copy
print " \n";
} else {
print " \n";
}
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}
/* --------------------------
Save Function
-------------------------- */
function form_save() {
global $settings_user;
/* graph permissions */
if ((isset_request_var('save_component_graph_perms')) && (!is_error_message())) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('perm_graphs');
get_filter_request_var('perm_trees');
get_filter_request_var('perm_hosts');
get_filter_request_var('perm_graph_templates');
get_filter_request_var('policy_graphs');
get_filter_request_var('policy_trees');
get_filter_request_var('policy_hosts');
get_filter_request_var('policy_graph_templates');
/* ==================================================== */
$add_button_clicked = false;
if (isset_request_var('add_graph_x')) {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id,item_id,type)
VALUES (?, ?, 1)',
array(get_nfilter_request_var('id'), get_nfilter_request_var('perm_graphs')));
$add_button_clicked = true;
} elseif (isset_request_var('add_tree_x')) {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id,item_id,type)
VALUES (?, ?, 2)',
array(get_nfilter_request_var('id'), get_nfilter_request_var('perm_trees')));
$add_button_clicked = true;
} elseif (isset_request_var('add_host_x')) {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id,item_id,type)
VALUES (?, ?, 3)',
array(get_nfilter_request_var('id'), get_nfilter_request_var('perm_hosts')));
$add_button_clicked = true;
} elseif (isset_request_var('add_graph_template_x')) {
db_execute_prepared('REPLACE INTO user_auth_perms
(user_id,item_id,type)
VALUES (?, ?, 4)',
array(get_nfilter_request_var('id'), get_nfilter_request_var('perm_graph_templates')));
$add_button_clicked = true;
}
if ($add_button_clicked == true) {
header('Location: user_admin.php?action=user_edit&header=false&tab=graph_perms_edit&id=' . get_nfilter_request_var('id'));
exit;
}
} elseif (isset_request_var('save_component_user')) {
/* user management save */
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('realm');
get_filter_request_var('policy_hosts');
get_filter_request_var('policy_graphs');
get_filter_request_var('policy_trees');
get_filter_request_var('policy_graph_templates');
/* ==================================================== */
if ((get_nfilter_request_var('password') == '') && (get_nfilter_request_var('password_confirm') == '')) {
$password = db_fetch_cell_prepared('SELECT password
FROM user_auth
WHERE id = ?',
array(get_nfilter_request_var('id')));
} else {
$password = compat_password_hash(get_nfilter_request_var('password'), PASSWORD_DEFAULT);
}
/* check duplicate username */
if (sizeof(db_fetch_row_prepared('SELECT * FROM user_auth WHERE realm = ? AND username = ? AND id != ?', array(get_nfilter_request_var('realm'), get_nfilter_request_var('username'), get_nfilter_request_var('id'))))) {
raise_message(12);
}
/* check for guest or template user */
$username = db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array(get_nfilter_request_var('id')));
$history = db_fetch_cell_prepared('SELECT password_history FROM user_auth WHERE id = ?', array(get_nfilter_request_var('id')));
if ($username != '' && $username != get_nfilter_request_var('username')) {
$template_user = read_config_option('user_template');
$guest_user = read_config_option('guest_user');
if ($username == $template_user) {
raise_message(20);
}
if ($username == $guest_user) {
raise_message(20);
}
}
/* check to make sure the passwords match; if not error */
if (get_nfilter_request_var('password') != get_nfilter_request_var('password_confirm')) {
raise_message(4);
}
if (get_nfilter_request_var('must_change_password') == 'on' && get_nfilter_request_var('password_change') != 'on') {
raise_message('password_change');
}
$save['id'] = get_nfilter_request_var('id');
$save['username'] = form_input_validate(get_nfilter_request_var('username'), 'username', "^[A-Za-z0-9\._\\\@\ -]+$", false, 3);
$save['full_name'] = form_input_validate(get_nfilter_request_var('full_name'), 'full_name', '', true, 3);
$save['password'] = $password;
$save['must_change_password'] = form_input_validate(get_nfilter_request_var('must_change_password', ''), 'must_change_password', '', true, 3);
$save['password_change'] = form_input_validate(get_nfilter_request_var('password_change', ''), 'password_change', '', true, 3);
$save['show_tree'] = form_input_validate(get_nfilter_request_var('show_tree', ''), 'show_tree', '', true, 3);
$save['show_list'] = form_input_validate(get_nfilter_request_var('show_list', ''), 'show_list', '', true, 3);
$save['show_preview'] = form_input_validate(get_nfilter_request_var('show_preview', ''), 'show_preview', '', true, 3);
$save['graph_settings'] = form_input_validate(get_nfilter_request_var('graph_settings', ''), 'graph_settings', '', true, 3);
$save['login_opts'] = form_input_validate(get_nfilter_request_var('login_opts'), 'login_opts', '', true, 3);
$save['realm'] = get_nfilter_request_var('realm', 0);
$save['password_history'] = $history;
$save['enabled'] = form_input_validate(get_nfilter_request_var('enabled', ''), 'enabled', '', true, 3);
$save['email_address'] = form_input_validate(get_nfilter_request_var('email_address', ''), 'email_address', '', true, 3);
$save['locked'] = form_input_validate(get_nfilter_request_var('locked', ''), 'locked', '', true, 3);
$save['reset_perms'] = mt_rand();
if ($save['locked'] == '') {
$save['failed_attempts'] = 0;
}
$save = api_plugin_hook_function('user_admin_setup_sql_save', $save);
if (!is_error_message()) {
$user_id = sql_save($save, 'user_auth');
if ($user_id) {
raise_message(1);
} else {
raise_message(2);
}
}
} elseif (isset_request_var('save_component_realm_perms')) {
db_execute_prepared('DELETE FROM user_auth_realm WHERE user_id = ?', array(get_nfilter_request_var('id')));
foreach ($_POST as $var => $val) {
if (preg_match('/^[section]/i', $var)) {
if (substr($var, 0, 7) == 'section') {
db_execute_prepared('REPLACE INTO user_auth_realm
(user_id, realm_id)
VALUES (?, ?)',
array(get_nfilter_request_var('id'), substr($var, 7)));
}
}
}
reset_user_perms(get_nfilter_request_var('id'));
raise_message(1);
} elseif (isset_request_var('save_component_graph_settings')) {
foreach ($settings_user as $tab_short_name => $tab_fields) {
foreach ($tab_fields as $field_name => $field_array) {
if ((isset($field_array['items'])) && (is_array($field_array['items']))) {
foreach ($field_array['items'] as $sub_field_name => $sub_field_array) {
db_execute_prepared('REPLACE INTO settings_user
(user_id, name, value)
VALUES (?, ?, ?)',
array((!empty($user_id) ? $user_id : get_filter_request_var('id')), $sub_field_name, get_nfilter_request_var($sub_field_name, '')));
}
} else {
db_execute_prepared('REPLACE INTO settings_user
(user_id, name, value)
VALUES (?, ?, ?)',
array((!empty($user_id) ? $user_id : get_filter_request_var('id')), $field_name, get_nfilter_request_var($field_name)));
}
}
}
/* reset local settings cache so the user sees the new settings */
kill_session_var('sess_user_config_array');
reset_user_perms(get_request_var('id'));
raise_message(1);
} elseif (isset_request_var('save_component_graph_perms')) {
db_execute_prepared('UPDATE user_auth
SET policy_graphs = ?, policy_trees = ?, policy_hosts = ?, policy_graph_templates = ?
WHERE id = ?',
array(get_nfilter_request_var('policy_graphs'), get_nfilter_request_var('policy_trees'), get_nfilter_request_var('policy_hosts'), get_nfilter_request_var('policy_graph_templates'), get_nfilter_request_var('id')));
} else {
api_plugin_hook('user_admin_user_save');
reset_user_perms(get_filter_request_var('id'));
}
/* redirect to the appropriate page */
header('Location: user_admin.php?action=user_edit&header=false&id=' . (empty($user_id) ? get_filter_request_var('id') : $user_id));
}
/* --------------------------
Graph Permissions
-------------------------- */
function perm_remove() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('user_id');
/* ==================================================== */
if (get_request_var('type') == 'graph') {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE type = 1
AND user_id = ?
AND item_id = ?',
array(get_request_var('user_id'), get_request_var('id')));
} elseif (get_request_var('type') == 'tree') {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE type = 2
AND user_id = ?
AND item_id = ?',
array(get_request_var('user_id'), get_request_var('id')));
} elseif (get_request_var('type') == 'host') {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE type = 3
AND user_id = ?
AND item_id = ?',
array(get_request_var('user_id'), get_request_var('id')));
} elseif (get_request_var('type') == 'graph_template') {
db_execute_prepared('DELETE FROM user_auth_perms
WHERE type = 4
AND user_id = ?
AND item_id = ?',
array(get_request_var('user_id'), get_request_var('id')));
}
header('Location: user_admin.php?action=user_edit&header=false&tab=graph_perms_edit&id=' . get_request_var('user_id'));
}
function get_permission_string(&$graph, &$policies) {
$grantStr = '';
$rejectStr = '';
if (read_config_option('graph_auth_method') == 1) {
$method = 'loose';
} else {
$method = 'strong';
}
$i = 1;
foreach($policies as $p) {
$allowed = 0;
$rejected = 0;
if ($p['policy_graphs'] == 1) {
if ($graph["user$i"] == '') {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Graph:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} else {
$rejectStr = $rejectStr . ($rejectStr != '' ? ', ':'') . 'Graph:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
}
} elseif ($graph["user$i"] != '') {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Graph:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} elseif ($method == 'loose') {
$rejected++;
} else {
$rejectStr = $rejectStr . ($rejectStr != '' ? ', ':'') . 'Graph:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
}
$i++;
if ($p['policy_hosts'] == 1) {
if ($graph["user$i"] == '') {
if ($method == 'loose') {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Device:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} else {
$allowed++;
}
} else {
$rejectStr = $rejectStr . ($rejectStr != '' ? ', ':'') . 'Device:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
}
} elseif ($graph["user$i"] != '') {
if ($method == 'loose') {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Device:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} else {
$allowed++;
}
} elseif ($method == 'loose') {
$rejected++;
}
$i++;
if ($p['policy_graph_templates'] == 1) {
if ($graph["user$i"] == '') {
if ($method == 'loose') {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Template:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} else {
$allowed++;
}
} else {
$rejectStr = $rejectStr . ($rejectStr != '' ? ', ':'') . 'Template:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
}
} elseif ($graph["user$i"] != '') {
if ($method == 'loose') {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Template:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} else {
$allowed++;
}
} elseif ($method == 'loose') {
$rejected++;
}
$i++;
if ($method != 'loose') {
if ($allowed == 2) {
$grantStr = $grantStr . ($grantStr != '' ? ', ':'') . 'Device+Template:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
} else {
$rejectStr = $rejectStr . ($rejectStr != '' ? ', ':'') . 'Device+Template:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
}
} elseif ($rejected == 3) {
$rejectStr = $rejectStr . ($rejectStr != '' ? ', ':'') . 'Graph+Device+Template:(' . ucfirst($p['type']) . ($p['type'] != 'user' ? '/' . $p['name'] . ')':')');
}
}
$permStr = '';
if ($grantStr != '') {
$permStr = "Granted: " . trim($grantStr,',') . ' ';
}
if ($rejectStr != '') {
if ($grantStr == '') {
$permStr = "Restricted: " . trim($rejectStr,',') . ' ';
} else {
$permStr .= ", " . trim($rejectStr,',') . ' ';
}
}
return $permStr;
}
function graph_perms_edit($tab, $header_label) {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
$sql_where = '';
$sql_join = '';
$limit = '';
$sql_having = '';
$policy_array = array(
1 => __('Allow'),
2 => __('Deny')
);
if (!isempty_request_var('id')) {
$policy = db_fetch_row_prepared('SELECT policy_graphs, policy_trees, policy_hosts, policy_graph_templates
FROM user_auth
WHERE id = ?', array(get_request_var('id')));
} else {
$policy = array(
'policy_graphs' => '1',
'policy_trees' => '1',
'policy_hosts' => '1',
'policy_graph_templates' => '1'
);
}
switch($tab) {
case 'permsg':
process_graph_request_vars();
graph_filter($header_label);
form_start('user_admin.php', 'policy');
if (read_config_option('graph_auth_method') == 1) {
$policy_note = __('Note: System Graph Policy is \'Permissive\' meaning the User must have access to at least one of Graph, Device, or Graph Template to gain access to the Graph');
} else {
$policy_note = __('Note: System Graph Policy is \'Restrictive\' meaning the User must have access to the Graph, Device, and Graph Template to gain access to the Graph');
}
/* box: device permissions */
html_start_box(__('Default Graph Policy'), '100%', '', '3', 'center', '');
?>
0)";
} else {
$sql_where = 'WHERE (gtg.local_graph_id > 0)';
}
if (get_request_var('graph_template_id') == '-1') {
/* Show all items */
} elseif (get_request_var('graph_template_id') == '0') {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' gtg.graph_template_id=0';
} elseif (!isempty_request_var('graph_template_id')) {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' gtg.graph_template_id=' . get_request_var('graph_template_id');
}
$i = 1;
$user_perm = '';
$sql_select = '';
foreach($policies as $policy) {
if ($policy['type'] == 'user' && $user_perm == '') {
$user_perm = $i;
}
if (get_request_var('associated') == 'false') {
if ($policy['policy_graphs'] == 1) {
$sql_having .= ($sql_having != '' ? ' OR ':'') . " (user$i IS NULL";
} else {
$sql_having .= ($sql_having != '' ? ' OR ':'') . " (user$i IS NOT NULL";
}
}
$sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '':'group_') . "perms AS uap$i ON (gl.id=uap$i.item_id AND uap$i.type=1 AND uap$i." . $policy['type'] . '_id=' . get_request_var('id') . ') ';
$sql_select .= ($sql_select != '' ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i";
$i++;
if (get_request_var('associated') == 'false') {
if ($policy['policy_hosts'] == 1) {
$sql_having .= " OR (user$i IS NULL";
} else {
$sql_having .= " OR (user$i IS NOT NULL";
}
}
$sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '':'group_') . "perms AS uap$i ON (gl.host_id=uap$i.item_id AND uap$i.type=3 AND uap$i." . $policy['type'] . '_id=' . get_request_var('id') . ') ';
$sql_select .= ($sql_select != '' ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i";
$i++;
if (get_request_var('associated') == 'false') {
if ($policy['policy_graph_templates'] == 1) {
$sql_having .= " $sql_operator user$i IS NULL))";
} else {
$sql_having .= " $sql_operator user$i IS NOT NULL))";
}
}
$sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '':'group_') . "perms AS uap$i ON (gl.graph_template_id=uap$i.item_id AND uap$i.type=4 AND uap$i." . $policy['type'] . '_id=' . get_request_var('id') . ') ';
$sql_select .= ($sql_select != '' ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i";
$i++;
}
if ($sql_having != '') {
$sql_having = 'HAVING ' . $sql_having;
}
$graphs = db_fetch_assoc("SELECT gtg.local_graph_id, h.description, gt.name AS template_name,
gtg.title_cache, gtg.width, gtg.height, gl.snmp_index, gl.snmp_query_id,
$sql_select
FROM graph_templates_graph AS gtg
INNER JOIN graph_local AS gl
ON gl.id = gtg.local_graph_id
LEFT JOIN graph_templates AS gt
ON gt.id = gl.graph_template_id
LEFT JOIN host AS h
ON h.id = gl.host_id
$sql_join
$sql_where
$sql_having
ORDER BY gtg.title_cache
$limit");
$total_rows = db_fetch_cell("SELECT COUNT(*)
FROM (
SELECT $sql_select
FROM graph_templates_graph AS gtg
INNER JOIN graph_local AS gl
ON gl.id = gtg.local_graph_id
LEFT JOIN graph_templates AS gt
ON gt.id = gl.graph_template_id
LEFT JOIN host AS h
ON h.id = gl.host_id
$sql_join
$sql_where
$sql_having
) AS rows");
$nav = html_nav_bar('user_admin.php?action=user_edit&tab=permsg&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 11, __('Graphs'), 'page', 'main');
form_start(htmlspecialchars('user_admin.php?tab=permsg&id=' . get_request_var('id')), 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(__('Graph Title'), __('ID'), __('Effective Policy'));
html_header_checkbox($display_text, false);
if (sizeof($graphs)) {
foreach ($graphs as $g) {
form_alternate_row('line' . $g['local_graph_id'], true);
form_selectable_cell(filter_value($g['title_cache'], get_request_var('filter')), $g['local_graph_id']);
form_selectable_cell($g['local_graph_id'], $g['local_graph_id']);
form_selectable_cell(get_permission_string($g, $policies), $g['local_graph_id']);
form_checkbox_cell($g['title_cache'], $g['local_graph_id']);
form_end_row();
}
} else {
print '' . __('No Matching Graphs Found') . ' ';
}
html_end_box(false);
if (sizeof($graphs)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_graph', '1', '');
if ($policy['policy_graphs'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permsgr':
process_group_request_vars();
group_filter($header_label);
/* if the number of rows is -1, set it to the default */
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = "WHERE (uag.name LIKE '%" . get_request_var('filter') . "%' OR uag.description LIKE '%" . get_request_var('filter') . "%')";
} else {
$sql_where = '';
}
if (get_request_var('associated') != 'false') {
/* Show all items */
} else {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' uagm.user_id=' . get_request_var('id');
}
$total_rows = db_fetch_cell("SELECT
COUNT(DISTINCT uag.id)
FROM user_auth_group AS uag
LEFT JOIN (SELECT user_id, group_id FROM user_auth_group_members WHERE user_id=" . get_request_var('id') . ") AS uagm
ON uag.id = uagm.group_id
$sql_where");
$sql_query = "SELECT DISTINCT uag.*, uagm.user_id
FROM user_auth_group AS uag
LEFT JOIN (SELECT user_id, group_id FROM user_auth_group_members WHERE user_id=" . get_request_var('id') . ") AS uagm
ON uag.id = uagm.group_id
$sql_where
ORDER BY name
LIMIT " . ($rows*(get_request_var('page')-1)) . ',' . $rows;
$groups = db_fetch_assoc($sql_query);
$nav = html_nav_bar('user_admin.php?action=user_edit&tab=permsgr&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 11, __('Groups'), 'page', 'main');
form_start(htmlspecialchars('user_admin.php?tab=permsd&id=' . get_request_var('id')), 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(__('Name'), __('Description'), __('Member'), __('ID'), __('Policies (Graph/Device/Template)'), __('Enabled'));
html_header_checkbox($display_text, false);
if (sizeof($groups)) {
foreach ($groups as $g) {
form_alternate_row('line' . $g['id'], true);
form_selectable_cell(filter_value($g['name'], get_request_var('filter'), 'user_group_admin.php?action=edit&id=' . $g['id']), $g['id']);
form_selectable_cell(filter_value($g['description'], get_request_var('filter')), $g['id']);
form_selectable_cell($g['user_id'] > 0 ? __('Member'):__('Non Member'), $g['id']);
form_selectable_cell(($g['id']), $g['id']);
form_selectable_cell(($g['policy_graphs'] == 1 ? __('ALLOW'):__('DENY')) . '/' . ($g['policy_hosts'] == 1 ? __('ALLOW'):__('DENY')) . '/' . ($g['policy_graph_templates'] == 1 ? __('ALLOW'):__('DENY')), $g['id']);
form_selectable_cell($g['enabled'] == 'on' ? __('Enabled'):__('Disabled'), $g['id']);
form_checkbox_cell($g['name'], $g['id']);
form_end_row();
}
} else {
print '' . __('No Matching User Groups Found') . ' ';
}
html_end_box(false);
if (sizeof($groups)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_groups', '1', '');
$assoc_actions = array(
1 => __('Assign Membership'),
2 => __('Remove Membership')
);
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permsd':
process_device_request_vars();
device_filter($header_label);
form_start('user_admin.php', 'policy');
html_start_box(__('Default Device Policy'), '100%', '', '3', 'center', '');
?>
' . __('Access Granted') . '', $host['id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $host['id']);
}
} else {
if ($policy['policy_hosts'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $host['id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $host['id']);
}
}
form_selectable_cell((isset($host_graphs[$host['id']]) ? $host_graphs[$host['id']] : 0), $host['id']);
form_selectable_cell((isset($host_data_sources[$host['id']]) ? $host_data_sources[$host['id']] : 0), $host['id']);
form_selectable_cell(get_colored_device_status(($host['disabled'] == 'on' ? true : false), $host['status']), $host['id']);
form_selectable_cell(filter_value($host['hostname'], get_request_var('filter')), $host['id']);
form_checkbox_cell($host['description'], $host['id']);
form_end_row();
}
} else {
print '' . __('No Matching Devices Found') . ' ';
}
html_end_box(false);
if (sizeof($hosts)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_host', '1', '');
if ($policy['policy_hosts'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permste':
process_template_request_vars();
template_filter($header_label);
form_start('user_admin.php', 'policy');
html_start_box(__('Default Graph Template Policy'), '100%', '', '3', 'center', '');
?>
' . __('Access Granted') . '', $g['id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $g['id']);
}
} else {
if ($policy['policy_graph_templates'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $g['id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $g['id']);
}
}
form_selectable_cell($g['totals'], $g['id']);
form_checkbox_cell($g['name'], $g['id']);
form_end_row();
}
} else {
print '' . __('No Matching Graph Templates Found') . ' ';
}
html_end_box(false);
if (sizeof($graphs)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_template', '1', '');
if ($policy['policy_graph_templates'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
case 'permstr':
process_tree_request_vars();
tree_filter($header_label);
form_start('user_admin.php', 'policy');
html_start_box(__('Default Tree Policy'), '100%', '', '3', 'center', '');
?>
' . __('Access Granted') . '', $t['id']);
} else {
form_selectable_cell('' . __('Access Restricted') . ' ', $t['id']);
}
} else {
if ($policy['policy_trees'] == 1) {
form_selectable_cell('' . __('Access Restricted') . ' ', $t['id']);
} else {
form_selectable_cell('' . __('Access Granted') . ' ', $t['id']);
}
}
form_checkbox_cell($t['name'], $t['id']);
form_end_row();
}
} else {
print '' . __('No Matching Trees Found') . ' ';
}
html_end_box(false);
if (sizeof($trees)) {
print $nav;
}
form_hidden_box('tab',$tab,'');
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('associate_tree', '1', '');
if ($policy['policy_trees'] == 1) {
$assoc_actions = array(
1 => __('Revoke Access'),
2 => __('Grant Access')
);
} else {
$assoc_actions = array(
1 => __('Grant Access'),
2 => __('Revoke Access')
);
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
form_end();
break;
}
}
function user_realms_edit($header_label) {
global $user_auth_realms, $user_auth_roles;
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
$all_realms = $user_auth_realms;
print "\n";
form_start('user_admin.php', 'chk');
html_start_box('', '100%', '', '3', 'center', '');
/* do cacti realms first */
$i = 1;
foreach($user_auth_roles as $role_name => $perms) {
$j = 1;
print "\n";
print "\n";
foreach($perms as $realm) {
if ($j == 1) {
print "\n";
}
print "\n";
if (isset($user_auth_realms[$realm])) {
$set = db_fetch_cell_prepared('SELECT realm_id
FROM user_auth_realm
WHERE user_id = ?
AND realm_id = ?',
array(get_request_var('id', 0), $realm));
if (!empty($set)) {
$old_value = 'on';
} else {
$old_value = '';
}
unset($all_realms[$realm]);
form_checkbox('section' . $realm, $old_value, $user_auth_realms[$realm], '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
}
print " \n";
if ($j == 5) {
print " \n";
$j = 1;
} else {
$j++;
}
}
if ($j > 1) {
print " \n";
print "\n";
}
print "
\n";
}
/* external links */
$links = db_fetch_assoc('SELECT * FROM external_links ORDER BY sortorder');
$style_translate = array(
'CONSOLE' => __('Console'),
'TAB' => __('Top Tab'),
'FRONT' => __('Bottom Console'),
'FRONTTOP' => __('Top Console')
);
print "\n";
print "\n";
if (sizeof($links)) {
$j = 1;
foreach($links as $r) {
if ($j == 1) {
print " \n";
}
$realm = $r['id'] + 10000;
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
unset($all_realms[$realm]);
print "\n";
switch($r['style']) {
case 'CONSOLE':
$description = $style_translate[$r['style']] . ': ' . ($r['extendedstyle'] == '' ? 'External Links' : $r['extendedstyle']) . '/' . $r['title'];
break;
default:
$description = $style_translate[$r['style']] . ': ' . ucfirst($r['title']);
break;
}
form_checkbox('section' . $realm, $old_value, $description, '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
print " \n";
if ($j == 5) {
print " \n";
$j = 1;
} else {
$j++;
}
}
if ($j > 1) {
print " \n";
print "\n";
}
}
print "
\n";
/* do plugin realms */
$realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display
FROM plugin_config AS pc
INNER JOIN plugin_realms AS pr
ON pc.directory = pr.plugin
ORDER BY pc.name, pr.display');
print "\n";
print "\n";
if (sizeof($realms)) {
$last_plugin = 'none';
$i = 1;
$j = 1;
foreach($realms as $r) {
$break = false;
if ($last_plugin != $r['name'] && $last_plugin != 'none') {
$break = true;
if ($j == 5) {
print " \n";
$break = true;;
$j = 1;
} else {
$j++;
}
}
if ($break) {
print "\n";
}
if ($break || $i == 1) {
print "" . $r['name'] . " \n";
}
$realm = $r['realm_id'] + 100;
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
unset($all_realms[$realm]);
$pos = (strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->')+2:0);
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
$last_plugin = $r['name'];
$i++;
}
}
/* get the old PIA 1.x realms */
if (sizeof($all_realms)) {
if ($break) {
print " \n";
}
print "" . __('Legacy 1.x Plugins') . " \n";
foreach($all_realms as $realm => $name) {
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
} else {
$old_value = '';
}
$pos = (strpos($user_auth_realms[$realm], '->') !== false ? strpos($user_auth_realms[$realm], '->')+2:0);
form_checkbox('section' . $realm, $old_value, substr($user_auth_realms[$realm], $pos), '', '', '', (!isempty_request_var('id') ? 1 : 0)); print ' ';
}
}
print "
\n";
?>
$tab_fields) {
$collapsible = true;
print "\n";
$form_array = array();
foreach ($tab_fields as $field_name => $field_array) {
$form_array += array($field_name => $tab_fields[$field_name]);
if ((isset($field_array['items'])) && (is_array($field_array['items']))) {
foreach ($field_array['items'] as $sub_field_name => $sub_field_array) {
if (graph_config_value_exists($sub_field_name, get_request_var('id'))) {
$form_array[$field_name]['items'][$sub_field_name]['form_id'] = 1;
}
$form_array[$field_name]['items'][$sub_field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_user WHERE name = ? AND user_id = ?', array($sub_field_name, get_request_var('id')));
}
} else {
if (graph_config_value_exists($field_name, get_request_var('id'))) {
$form_array[$field_name]['form_id'] = 1;
}
$form_array[$field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_user WHERE name = ? and user_id = ?', array($field_name, get_request_var('id')));
}
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => $form_array
)
);
}
html_end_box(true, true);
form_hidden_box('id', get_request_var('id'), '');
form_hidden_box('tab', 'settings', '');
form_hidden_box('save_component_graph_settings','1','');
form_save_button('user_admin.php', 'return');
?>
array('regexp' => '/^([a-zA-Z]+)$/')));
/* ==================================================== */
/* present a tabbed interface */
$tabs = array(
'general' => __('General'),
'realms' => __('Permissions'),
'permsgr' => __('Group Membership'),
'permsg' => __('Graph Perms'),
'permsd' => __('Device Perms'),
'permste' => __('Template Perms'),
'permstr' => __('Tree Perms'),
'settings' => __('User Settings')
);
/* set the default tab */
load_current_session_value('tab', 'sess_user_admin_tab', 'general');
$current_tab = get_nfilter_request_var('tab');
if (!isempty_request_var('id')) {
$user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array(get_request_var('id')));
$header_label = __('[edit: %s]', $user['username']);
} else {
$header_label = __('[new]');
}
if (sizeof($tabs) && !isempty_request_var('id')) {
$i = 0;
/* draw the tabs */
print "\n";
}
switch($current_tab) {
case 'general':
api_plugin_hook_function('user_admin_edit', (isset($user) ? get_request_var('id') : 0));
form_start('user_admin.php');
html_start_box(__('User Management %s', $header_label), '100%', '', '3', 'center', '');
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_user_user_edit_host, (isset($user) ? $user : array()))
)
);
html_end_box();
form_save_button('user_admin.php', 'return');
?>
array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'username',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
);
validate_store_request_vars($filters, 'sess_usera');
/* ================= input validation ================= */
?>
array(__('User Name'), 'ASC'),
'full_name' => array(__('Full Name'), 'ASC'),
'enabled' => array(__('Enabled'), 'ASC'),
'realm' => array(__('Realm'), 'ASC'),
'policy_graphs' => array(__('Graph Policy'), 'ASC'),
'policy_hosts' => array(__('Device Policy'), 'ASC'),
'policy_graph_templates' => array(__('Template Policy'), 'ASC'),
'dtime' => array(__('Last Login'), 'DESC')
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
if (sizeof($user_list)) {
foreach ($user_list as $user) {
if (empty($user['dtime']) || ($user['dtime'] == '12/31/1969')) {
$last_login = __('N/A');
} else {
$last_login = strftime('%A, %B %d, %Y %H:%M:%S ', strtotime($user['dtime']));;
}
if ($user['enabled'] == 'on') {
$enabled = __('Yes');
} else {
$enabled = __('No');
}
if (isset($auth_realms[$user['realm']])) {
$realm = $auth_realms[$user['realm']];
} else {
$realm = __('Unavailable');
}
form_alternate_row('line' . $user['id'], true);
form_selectable_cell(filter_value($user['username'], get_request_var('filter'), $config['url_path'] . 'user_admin.php?action=user_edit&tab=general&id=' . $user['id']), $user['id']);
form_selectable_cell(filter_value($user['full_name'], get_request_var('filter')), $user['id']);
form_selectable_cell($enabled, $user['id']);
form_selectable_cell($realm, $user['id']);
form_selectable_cell(($user['policy_graphs'] == 1 ? __('ALLOW'):__('DENY')), $user['id']);
form_selectable_cell(($user['policy_hosts'] == 1 ? __('ALLOW'):__('DENY')), $user['id']);
form_selectable_cell(($user['policy_graph_templates'] == 1 ? __('ALLOW'):__('DENY')), $user['id']);
form_selectable_cell($last_login, $user['id']);
form_checkbox_cell($user['username'], $user['id']);
form_end_row();
}
} else {
print '' . __('No Users Found') . ' ';
}
html_end_box(false);
if (sizeof($user_list)) {
print $nav;
}
draw_actions_dropdown($user_actions);
form_end();
}
function process_graph_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'graph_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_uag');
/* ================= input validation ================= */
}
function process_group_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_uagr');
/* ================= input validation ================= */
}
function process_device_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'host_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_uad');
/* ================= input validation ================= */
}
function process_template_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'graph_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_uate');
/* ================= input validation ================= */
}
function process_tree_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => read_config_option('num_rows_table')
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'graph_template_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
),
'associated' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => 'true'
)
);
validate_store_request_vars($filters, 'sess_uatr');
/* ================= input validation ================= */
}
function graph_filter($header_label) {
global $config, $item_rows;
?>
__x('dropdown action', 'Delete'),
2 => __x('dropdown action', 'Publish'),
3 => __x('dropdown action', 'Un Publish')
);
/* set default action */
set_default_action();
if (get_request_var('action') != '') {
/* ================= input validation and session storage ================= */
$filters = array(
'tree_id' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => ''
),
'leaf_id' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => ''
),
'graph_tree_id' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => ''
),
'parent_item_id' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => ''
),
'parent' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '/([_\-a-z:0-9#]+)/')),
'pageset' => true,
'default' => ''
),
'position' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => ''
),
'nodeid' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '/([_\-a-z:0-9#]+)/')),
'pageset' => true,
'default' => ''
),
'id' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '/([_\-a-z:0-9#]+)/')),
'pageset' => true,
'default' => ''
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters);
/* ================= input validation ================= */
}
switch (get_request_var('action')) {
case 'save':
form_save();
break;
case 'actions':
form_actions();
break;
case 'sortasc':
tree_sort_name_asc();
header('Location: tree.php?header=false');
break;
case 'sortdesc':
tree_sort_name_desc();
header('Location: tree.php?header=false');
break;
case 'edit':
top_header();
tree_edit();
bottom_footer();
break;
case 'hosts':
display_hosts();
break;
case 'graphs':
display_graphs();
break;
case 'tree_up':
tree_up();
break;
case 'tree_down':
tree_down();
break;
case 'ajax_dnd':
tree_dnd();
break;
case 'lock':
api_tree_lock(get_request_var('id'), $_SESSION['sess_user_id']);
break;
case 'unlock':
api_tree_unlock(get_request_var('id'), $_SESSION['sess_user_id']);
break;
case 'copy_node':
api_tree_copy_node(get_request_var('tree_id'), get_request_var('id'), get_request_var('parent'), get_request_var('position'));
break;
case 'create_node':
api_tree_create_node(get_request_var('tree_id'), get_request_var('id'), get_request_var('position'), get_nfilter_request_var('text'));
break;
case 'delete_node':
api_tree_delete_node(get_request_var('tree_id'), get_request_var('id'));
break;
case 'move_node':
api_tree_move_node(get_request_var('tree_id'), get_request_var('id'), get_request_var('parent'), get_request_var('position'));
break;
case 'rename_node':
api_tree_rename_node(get_request_var('tree_id'), get_request_var('id'), get_nfilter_request_var('text'));
break;
case 'get_node':
api_tree_get_node(get_request_var('tree_id'), get_request_var('id'), true);
break;
case 'get_host_sort':
get_host_sort_type();
break;
case 'set_host_sort':
set_host_sort_type();
break;
case 'get_branch_sort':
get_branch_sort_type();
break;
case 'set_branch_sort':
set_branch_sort_type();
break;
default:
top_header();
tree();
bottom_footer();
break;
}
function tree_get_max_sequence() {
$max_seq = db_fetch_cell('SELECT MAX(sequence) FROM graph_tree');
if ($max_seq == NULL) {
$max_seq = 0;
}
}
function tree_check_sequences() {
$bad_seq = db_fetch_cell('SELECT COUNT(sequence)
FROM graph_tree
WHERE sequence <= 0');
$dup_seq = db_fetch_cell('SELECT SUM(count)
FROM (
SELECT sequence, COUNT(sequence) AS count
FROM graph_tree
GROUP BY sequence
) AS t
WHERE t.count > 1');
// report any bad or duplicate sequencs to the log for reporting purposes
if ($bad_seq > 0) {
cacti_log('WARN: Found ' . $bad_seq . ' Sequences in graph_tree Table', false, 'TREE', POLLER_VERBOSITY_HIGH);
}
if ($dup_seq > 0) {
cacti_log('WARN: Found ' . $dup_seq . ' Sequences in graph_tree Table', false, 'TREE', POLLER_VERBOSITY_HIGH);
}
if ($bad_seq > 0 || $dup_seq > 0) {
// resequence the list so it has no gaps, and 0 values will appear at the top
// since thats where they would have been displayed
db_execute('SET @seq = 0; UPDATE graph_tree SET sequence = (@seq:=@seq+1) ORDER BY sequence, id;');
}
}
function tree_sort_name_asc() {
// resequence the list so it has no gaps, alphabetically ascending
db_execute('SET @seq = 0; UPDATE graph_tree SET sequence = (@seq:=@seq+1) ORDER BY name;');
}
function tree_sort_name_desc() {
// resequence the list so it has no gaps, alphabetically ascending
db_execute('SET @seq = 0; UPDATE graph_tree SET sequence = (@seq:=@seq+1) ORDER BY name DESC;');
}
function tree_down() {
tree_check_sequences();
$tree_id = get_filter_request_var('id');
$seq = db_fetch_cell_prepared('SELECT sequence
FROM graph_tree
WHERE id = ?',
array($tree_id));
$new_seq = $seq + 1;
/* update the old tree first */
db_execute_prepared('UPDATE graph_tree
SET sequence = ?
WHERE sequence = ?',
array($seq, $new_seq));
/* update the tree in question */
db_execute_prepared('UPDATE graph_tree
SET sequence = ?
WHERE id = ?',
array($new_seq, $tree_id));
header('Location: tree.php?header=false');
exit;
}
function tree_up() {
tree_check_sequences();
$tree_id = get_filter_request_var('id');
$seq = db_fetch_cell_prepared('SELECT sequence
FROM graph_tree
WHERE id = ?',
array($tree_id));
$new_seq = $seq - 1;
/* update the old tree first */
db_execute_prepared('UPDATE graph_tree
SET sequence = ?
WHERE sequence = ?',
array($seq, $new_seq));
/* update the tree in question */
db_execute_prepared('UPDATE graph_tree
SET sequence = ?
WHERE id = ?',
array($new_seq, $tree_id));
header('Location: tree.php?header=false');
exit;
}
function tree_dnd() {
if (isset_request_var('tree_ids') && is_array(get_nfilter_request_var('tree_ids'))) {
$tids = get_nfilter_request_var('tree_ids');
$sequence = 1;
foreach($tids as $id) {
$id = str_replace('line', '', $id);
input_validate_input_number($id);
db_execute_prepared('UPDATE graph_tree
SET sequence = ?
WHERE id = ?',
array($sequence, $id));
$sequence++;
}
}
header('Location: tree.php?header=false');
exit;
}
function get_host_sort_type() {
if (isset_request_var('nodeid')) {
$ndata = explode('_', get_request_var('nodeid'));
if (sizeof($ndata)) {
foreach($ndata as $n) {
$parts = explode(':', $n);
if (isset($parts[0]) && $parts[0] == 'tbranch') {
$branch = $parts[1];
input_validate_input_number($branch);
$sort_type = db_fetch_cell_prepared('SELECT host_grouping_type FROM graph_tree_items WHERE id = ?', array($branch));
if ($sort_type == HOST_GROUPING_GRAPH_TEMPLATE) {
print 'hsgt';
} else {
print 'hsdq';
}
}
}
}
} else {
return '';
}
}
function set_host_sort_type() {
$type = '';
$branch = '';
/* clean up type string */
if (isset_request_var('type')) {
set_request_var('type', sanitize_search_string(get_request_var('type')));
}
if (isset_request_var('nodeid')) {
$ndata = explode('_', get_request_var('nodeid'));
if (sizeof($ndata)) {
foreach($ndata as $n) {
$parts = explode(':', $n);
if (isset($parts[0]) && $parts[0] == 'tbranch') {
$branch = $parts[1];
input_validate_input_number($branch);
if (get_request_var('type') == 'hsgt') {
$type = HOST_GROUPING_GRAPH_TEMPLATE;
} else {
$type = HOST_GROUPING_DATA_QUERY_INDEX;
}
db_execute_prepared('UPDATE graph_tree_items SET host_grouping_type = ? WHERE id = ?', array($type, $branch));
break;
}
}
}
}
return;
}
function get_branch_sort_type() {
if (isset_request_var('nodeid')) {
$ndata = explode('_', get_request_var('nodeid'));
if (sizeof($ndata)) {
foreach($ndata as $n) {
$parts = explode(':', $n);
if (isset($parts[0]) && $parts[0] == 'tbranch') {
$branch = $parts[1];
input_validate_input_number($branch);
$sort_type = db_fetch_cell_prepared('SELECT sort_children_type FROM graph_tree_items WHERE id = ?', array($branch));
switch($sort_type) {
case TREE_ORDERING_INHERIT:
print __x('ordering of tree items', 'inherit');
break;
case TREE_ORDERING_NONE:
print __x('ordering of tree items', 'manual');
break;
case TREE_ORDERING_ALPHABETIC:
print __x('ordering of tree items', 'alpha');
break;
case TREE_ORDERING_NATURAL:
print __x('ordering of tree items', 'natural');
break;
case TREE_ORDERING_NUMERIC:
print __x('ordering of tree items', 'numeric');
break;
default:
print '';
break;
}
break;
}
}
}
} else {
print '';
}
}
function set_branch_sort_type() {
$type = '';
$branch = '';
/* clean up type string */
if (isset_request_var('type')) {
set_request_var('type', sanitize_search_string(get_request_var('type')));
}
if (isset_request_var('nodeid')) {
$ndata = explode('_', get_request_var('nodeid'));
if (sizeof($ndata)) {
foreach($ndata as $n) {
$parts = explode(':', $n);
if (isset($parts[0]) && $parts[0] == 'tbranch') {
$branch = $parts[1];
input_validate_input_number($branch);
switch(get_request_var('type')) {
case 'inherit':
$type = TREE_ORDERING_INHERIT;
break;
case 'manual':
$type = TREE_ORDERING_NONE;
break;
case 'alpha':
$type = TREE_ORDERING_ALPHABETIC;
break;
case 'natural':
$type = TREE_ORDERING_NATURAL;
break;
case 'numeric':
$type = TREE_ORDERING_NUMERIC;
break;
default:
break;
}
if (is_numeric($type) && is_numeric($branch)) {
db_execute_prepared('UPDATE graph_tree_items
SET sort_children_type = ?
WHERE id = ?',
array($type, $branch));
}
$first_child = db_fetch_row_prepared('SELECT id, graph_tree_id
FROM graph_tree_items
WHERE parent = ?
ORDER BY position
LIMIT 1',
array($branch));
if (!empty($first_child)) {
api_tree_sort_branch($first_child['id'], $first_child['graph_tree_id']);
}
break;
}
}
}
}
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
/* clear graph tree cache on save - affects current user only, other users should see changes in <5 minutes */
if (isset($_SESSION['dhtml_tree'])) {
unset($_SESSION['dhtml_tree']);
}
if (isset_request_var('save_component_tree')) {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
if (get_filter_request_var('id') > 0) {
$prev_order = db_fetch_cell_prepared('SELECT sort_type
FROM graph_tree
WHERE id = ?',
array(get_request_var('id')));
} else {
$prev_order = 1;
}
$save['id'] = get_request_var('id');
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save['sort_type'] = form_input_validate(get_nfilter_request_var('sort_type'), 'sort_type', '', true, 3);
$save['last_modified'] = date('Y-m-d H:i:s', time());
$save['enabled'] = get_nfilter_request_var('enabled') == 'true' ? 'on':'-';
$save['modified_by'] = $_SESSION['sess_user_id'];
if (empty($save['sequence'])) {
$save['sequence'] = tree_get_max_sequence() + 1;
}
if (empty($save['id'])) {
$save['user_id'] = $_SESSION['sess_user_id'];
}
if (!is_error_message()) {
$tree_id = sql_save($save, 'graph_tree');
if ($tree_id) {
raise_message(1);
/* sort the tree using the algorithm chosen by the user */
if ($save['sort_type'] != $prev_order) {
if ($save['sort_type'] != TREE_ORDERING_NONE) {
sort_recursive(0, $tree_id);
}
}
} else {
raise_message(2);
}
}
header("Location: tree.php?header=false&action=edit&id=$tree_id");
exit;
}
}
function sort_recursive($branch, $tree_id) {
$leaves = db_fetch_assoc_prepared('SELECT *
FROM graph_tree_items
WHERE graph_tree_id = ?
AND parent = ?
AND local_graph_id = 0
AND host_id = 0',
array($tree_id, $branch));
if (sizeof($leaves)) {
foreach($leaves as $leaf) {
if ($leaf['sort_children_type'] == TREE_ORDERING_INHERIT) {
$first_child = db_fetch_cell_prepared('SELECT id
FROM graph_tree_items
WHERE parent = ?',
array($leaf['id']));
if (!empty($first_child)) {
api_tree_sort_branch($first_child, $tree_id);
if (leaves_exist($leaf['id'], $tree_id)) {
sort_recursive($first_child, $tree_id);
}
}
}
}
}
}
function leaves_exist($parent, $tree_id) {
return db_fetch_assoc_prepared('SELECT COUNT(*)
FROM graph_tree_items
WHERE graph_tree_id = ?
AND parent = ?
AND local_graph_id = 0
AND host_id = 0',
array($tree_id, $parent));
}
/* -----------------------
Tree Item Functions
----------------------- */
function form_actions() {
global $tree_actions;
/* ================= input validation ================= */
get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { // delete
db_execute('DELETE FROM graph_tree WHERE ' . array_to_sql_or($selected_items, 'id'));
db_execute('DELETE FROM graph_tree_items WHERE ' . array_to_sql_or($selected_items, 'graph_tree_id'));
} elseif (get_nfilter_request_var('drp_action') == '2') { // publish
db_execute("UPDATE graph_tree
SET enabled='on',
last_modified=NOW(),
modified_by=" . $_SESSION['sess_user_id'] . '
WHERE ' . array_to_sql_or($selected_items, 'id'));
} elseif (get_nfilter_request_var('drp_action') == '3') { // un-publish
db_execute("UPDATE graph_tree
SET enabled='',
last_modified=NOW(),
modified_by=" . $_SESSION['sess_user_id'] . '
WHERE ' . array_to_sql_or($selected_items, 'id'));
}
}
header('Location: tree.php?header=false');
exit;
}
/* setup some variables */
$tree_list = ''; $i = 0;
/* loop through each of the selected items */
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$tree_list .= '' . htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($matches[1]))) . ' ';
$tree_array[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('tree.php');
html_start_box($tree_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (isset($tree_array) && sizeof($tree_array)) {
if (get_nfilter_request_var('drp_action') == '1') { // delete
print "
" . __n('Click \'Continue\' to delete the following Tree.', 'Click \'Continue\' to delete following Trees.', sizeof($tree_array)) . "
\n";
$save_html = " ";
} elseif (get_nfilter_request_var('drp_action') == '2') { // publish
print "
" . __n('Click \'Continue\' to publish the following Tree.', 'Click \'Continue\' to publish following Trees.', sizeof($tree_array)) . "
\n";
$save_html = " ";
} elseif (get_nfilter_request_var('drp_action') == '3') { // un-publish
print "
" . __n('Click \'Continue\' to un-publish the following Tree.', 'Click \'Continue\' to un-publish following Trees.', sizeof($tree_array)) . "
\n";
$save_html = " ";
}
} else {
print "" . __('You must select at least one Tree.') . " \n";
$save_html = " ";
}
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}
/* ---------------------
Tree Functions
--------------------- */
function tree_edit() {
global $fields_tree_edit;
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('type');
/* ==================================================== */
/* clean up search string */
if (isset_request_var('filter')) {
set_request_var('filter', sanitize_search_string(get_request_var('filter')));
}
load_current_session_value('filter', 'sess_tree_edit_filter', '');
load_current_session_value('type', 'sess_tree_edit_type', '0');
if (!isempty_request_var('id')) {
$tree = db_fetch_row_prepared('SELECT * FROM graph_tree WHERE id = ?', array(get_request_var('id')));
$header_label = __('Trees [edit: %s]', htmlspecialchars($tree['name']) );
// Reset the cookie state if tree id has changed
if (isset($_SESSION['sess_tree_id']) && $_SESSION['sess_tree_id'] != get_request_var('id')) {
$select_first = true;
} else {
$select_first = false;
}
$_SESSION['sess_tree_id'] = get_request_var('id');
} else {
$tree = array();
$header_label = __('Trees [new]');
}
form_start('tree.php', 'tree_edit');
// Remove inherit from the main tree option
unset($fields_tree_edit['sort_type']['array'][0]);
html_start_box($header_label, '100%', true, '3', 'center', '');
if (!sizeof($tree)) {
unset($fields_tree_edit['enabled']);
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_tree_edit, (isset($tree) ? $tree : array()))
)
);
html_end_box(true, true);
$lockdiv = '';
if (isset($tree['locked']) && $tree['locked'] == 0) {
$lockdiv = "\n";
$editable = false;
} elseif (isset($tree['locked']) && $tree['locked'] == 1) {
$lockdiv = "';
} else {
$editable = false;
$lockdiv .= __('To edit the tree, you must first unlock it and then lock it as yourself') . '';
}
} else {
$tree['id'] = 0;
$editable = true;
}
if ($editable) {
form_save_button('tree.php', 'return');
}
if (!isempty_request_var('id')) {
print $lockdiv;
print "\n";
html_start_box( __('Tree Items'), '100%', '', '3', 'center', '');
echo "
\n";
html_end_box();
print "\n";
html_start_box( __('Available Devices'), '100%', '', '3', 'center', '');
?>
\n";
display_hosts();
echo "
\n";
html_end_box();
print "\n";
html_start_box( __('Available Graphs'), '100%', '', '3', 'center', '');
?>
\n";
display_graphs();
echo "
\n";
html_end_box();
print "
\n";
?>
" . $h['description'] . ' (' . $h['hostname'] . ')' . " \n";
}
}
}
function display_graphs() {
if (get_request_var('filter') != '') {
$sql_where = "WHERE (title_cache LIKE '%" . get_request_var('filter') . "%' OR gt.name LIKE '%" . get_request_var('filter') . "%') AND local_graph_id>0";
} else {
$sql_where = 'WHERE local_graph_id>0';
}
$graphs = db_fetch_assoc("SELECT
gtg.local_graph_id AS id,
gtg.title_cache AS title,
gt.name AS template_name
FROM graph_templates_graph AS gtg
LEFT JOIN graph_templates AS gt
ON gt.id=gtg.graph_template_id
$sql_where
ORDER BY title_cache
LIMIT 20");
if (sizeof($graphs)) {
foreach($graphs as $g) {
if (is_graph_allowed($g['id'])) {
echo "" . html_escape($g['title']) . ' ';
}
}
}
}
function tree() {
global $tree_actions, $item_rows;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'sequence',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_tree');
/* ================= input validation ================= */
/* if the number of rows is -1, set it to the default */
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
?>
'tree.php?action=edit',
'callback' => true,
'title' => __esc('Add Tree'),
'class' => 'fa fa-plus'
),
array(
'href' => 'tree.php?action=sortasc',
'callback' => true,
'title' => __esc('Sort Trees Ascending'),
'class' => 'fa fa-sort-alpha-asc'
),
array(
'href' => 'tree.php?action=sortdesc',
'callback' => true,
'title' => __esc('Sort Trees Descending'),
'class' => 'fa fa-sort-alpha-desc'
)
);
html_start_box(__('Trees'), '100%', '', '3', 'center', $buttons);
?>
0 THEN 1 ELSE 0 END) AS hosts,
SUM(CASE WHEN ti.local_graph_id>0 THEN 1 ELSE 0 END) AS graphs,
SUM(CASE WHEN ti.local_graph_id=0 AND host_id=0 THEN 1 ELSE 0 END) AS branches
FROM graph_tree AS t
LEFT JOIN graph_tree_items AS ti
ON t.id=ti.graph_tree_id
$sql_where
GROUP BY t.id
$sql_order
$sql_limit");
$total_rows = db_fetch_cell("SELECT COUNT(DISTINCT(ti.graph_tree_id))
FROM graph_tree AS t
LEFT JOIN graph_tree_items AS ti
ON t.id=ti.graph_tree_id
$sql_where");
$nav = html_nav_bar('tree.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 11, __('Trees'), 'page', 'main');
form_start('tree.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'name' => array('display' => __('Tree Name'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The name by which this Tree will be referred to as.')),
'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The internal database ID for this Tree. Useful when performing automation or debugging.')),
'enabled' => array('display' => __('Published'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('Unpublished Trees cannot be viewed from the Graph tab')),
'locked' => array('display' => __('Locked'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('A Tree must be locked in order to be edited.')),
'user_id' => array('display' => __('Owner'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The original author of this Tree.')),
'sequence' => array('display' => __('Order'), 'align' => 'center', 'sort' => 'ASC', 'tip' => __('To change the order of the trees, first sort by this column, press the up or down arrows once they appear.')),
'last_modified' => array('display' => __('Last Edited'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The date that this Tree was last edited.')),
'modified_by' => array('display' => __('Edited By'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The last user to have modified this Tree.')),
'branches' => array('display' => __('Branches'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The total number of Branches in this Tree.')),
'hosts' => array('display' => __('Devices'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The total number of individual Devices in this Tree.')),
'graphs' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The total number of individual Graphs in this Tree.')));
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
$i = 1;
if (sizeof($trees)) {
foreach ($trees as $tree) {
$sequence = '';
if (get_request_var('sort_column') == 'sequence' && get_request_var('sort_direction') == 'ASC') {
if ($i == 1 && sizeof($trees) == 1) {
$sequence .= ' ';
$sequence .= ' ';
} elseif ($i == 1) {
$sequence .= ' ';
$sequence .= ' ';
} elseif ($i == sizeof($trees)) {
$sequence .= ' ';
$sequence .= ' ';
} else {
$sequence .= ' ';
$sequence .= ' ';
}
}
form_alternate_row('line' . $tree['id'], true);
form_selectable_cell(filter_value($tree['name'], get_request_var('filter'), 'tree.php?action=edit&id=' . $tree['id']), $tree['id']);
form_selectable_cell($tree['id'], $tree['id'], '', 'text-align:right');
form_selectable_cell($tree['enabled'] == 'on' ? __('Yes'):__('No'), $tree['id']);
form_selectable_cell($tree['locked'] == '1' ? __('Yes'):__('No'), $tree['id']);
form_selectable_cell(get_username($tree['user_id']), $tree['id']);
form_selectable_cell($sequence, $tree['id'], '', 'nowrap center');
form_selectable_cell(substr($tree['last_modified'],0,16), $tree['id'], '', 'text-align:right');
form_selectable_cell(get_username($tree['modified_by']), $tree['id'], '', 'text-align:right');
form_selectable_cell($tree['branches'] > 0 ? number_format_i18n($tree['branches'], '-1'):'-', $tree['id'], '', 'text-align:right');
form_selectable_cell($tree['hosts'] > 0 ? number_format_i18n($tree['hosts'], '-1'):'-', $tree['id'], '', 'text-align:right');
form_selectable_cell($tree['graphs'] > 0 ? number_format_i18n($tree['graphs'], '-1'):'-', $tree['id'], '', 'text-align:right');
form_checkbox_cell($tree['name'], $tree['id']);
form_end_row();
$i++;
}
} else {
print "" . __('No Trees Found') . " ";
}
html_end_box(false);
if (sizeof($trees)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($tree_actions);
form_end();
if (get_request_var('sort_column') == 'sequence' && get_request_var('sort_direction') == 'ASC') {
?>
0) {
$_SESSION['import_debug_info'] = $debug_data;
}
header('Location: templates_import.php?preview=' . $preview_only);
}
}
/* ---------------------------
Template Import Functions
--------------------------- */
function import() {
global $hash_type_names, $fields_template_import;
print "