" . __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.', cacti_sizeof($group_array)) . "
" . __n('Click \'Continue\' to enable the following User Group.', 'Click \'Continue\' to enable following User Groups.', cacti_sizeof($group_array)) . "
" . __n('Click \'Continue\' to disable the following User Group.', 'Click \'Continue\' to disable following User Groups.', cacti_sizeof($group_array)) . "
";
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 (cacti_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&tab=general&id=' . (isset($group_id) && $group_id > 0 ? $group_id : get_nfilter_request_var('id')));
exit;
}
if (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&tab=realms&id=' . get_request_var('id'));
exit;
}
if (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(OPTIONS_USER);
reset_group_perms(get_request_var('id'));
raise_message(1);
header('Location: user_group_admin.php?action=edit&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&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&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 ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR full_name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
} else {
$sql_where = '';
}
if (get_request_var('associated') != 'false') {
$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('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 (cacti_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 (cacti_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_auth_method = read_config_option('graph_auth_method');
if ($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');
} elseif ($graph_auth_method == 2) {
$policy_note = __('Note: System Graph Policy is \'Restrictive\' meaning the User must have access to either the Graph or the Device and Graph Template to gain access to the Graph');
} elseif ($graph_auth_method == 3) {
$policy_note = __('Note: System Graph Policy is \'Device\' meaning the User must have access to the Graph or Device to gain access to the Graph');
} else {
$policy_note = __('Note: System Graph Policy is \'Graph Template\' meaning the User must have access to the Graph or Graph Template to gain access to the Graph');
}
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');
}
$policies = db_fetch_assoc_prepared("SELECT uag.id, 'group' AS type, uag.name,
uag.policy_graphs, uag.policy_hosts, uag.policy_graph_templates
FROM user_auth_group AS uag
WHERE uag.enabled = 'on'
AND uag.id = ?",
array(get_request_var('id')));
/**
* if viewing just the graphs that the user has access to
* we use a custom crafted sql_where clause to calculate
* permissions due to the inefficient nature of the HAVING
* SQL clause.
*/
if (get_request_var('associated') == 'false') {
$sql_where = get_policy_where($graph_auth_method, $policies, $sql_where);
}
/**
* get the sql join and select to display the policy information
* this includes the four graph permission types
*/
$details = get_policy_join_select($policies);
if (cacti_sizeof($details)) {
$sql_select = $details['sql_select'];
$sql_join = $details['sql_join'];
} else {
$sql_select = '';
$sql_join = '';
}
$graphs = db_fetch_assoc("SELECT gtg.local_graph_id, h.description,
h.disabled, h.deleted, 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
ORDER BY gtg.title_cache
$sql_limit");
$total_rows = db_fetch_cell("SELECT COUNT(DISTINCT gl.id)
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_where");
$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('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 (cacti_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 '