"Delete", 2 => "Copy", 3 => "Enable", 4 => "Disable" ); /* set default action */ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; } switch ($_REQUEST["action"]) { case 'actions': form_actions(); break; case 'save': form_save(); break; case 'perm_remove': perm_remove(); break; case 'user_realms_edit': include_once("include/top_header.php"); user_edit(); include_once("include/bottom_footer.php"); break; case 'graph_settings_edit': include_once("include/top_header.php"); user_edit(); include_once("include/bottom_footer.php"); break; case 'graph_perms_edit': include_once("include/top_header.php"); user_edit(); include_once("include/bottom_footer.php"); break; case 'user_edit': include_once("include/top_header.php"); user_edit(); include_once("include/bottom_footer.php"); break; default: include_once("include/top_header.php"); user(); include_once("include/bottom_footer.php"); break; } /* -------------------------- Actions Function -------------------------- */ function form_actions() { global $colors, $user_actions; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { if ($_POST["drp_action"] != "2") { $selected_items = unserialize(stripslashes($_POST["selected_items"])); } if ($_POST["drp_action"] == "1") { /* delete */ for ($i=0;($i"; } $user_array[$i] = $matches[1]; } $i++; } include_once("./include/top_header.php"); html_start_box("" . $user_actions{$_POST["drp_action"]} . "", "60%", $colors["header_panel"], "3", "center", ""); print "
\n"; if ($_POST["drp_action"] == "1") { /* delete */ print "

Are you sure you want to delete the following users?

$user_list

\n"; } $user_id = ""; if ($_POST["drp_action"] == "2") { /* copy */ $user_id = $user_array[0]; print " Would you like to copy this user?

Template Username: " . db_fetch_cell("SELECT username FROM user_auth WHERE id=" . $user_id) . " New Username: \n"; } if ($_POST["drp_action"] == "3") { /* enable */ print "

Are you sure you want to enable the following users?

$user_list

\n"; } if ($_POST["drp_action"] == "4") { /* disable */ print "

Are you sure you want to disable the following users?

$user_list

\n"; } if (!isset($user_array)) { print "You must select at least one user.\n"; $save_html = ""; }else{ $save_html = ""; } print " "; if ($_POST["drp_action"] == "2") { /* copy */ print " \n"; }else{ print " \n"; } print " Cancel $save_html "; html_end_box(); include_once("./include/bottom_footer.php"); } /* -------------------------- Save Function -------------------------- */ function form_save() { global $settings_graphs; /* graph permissions */ if ((isset($_POST["save_component_graph_perms"])) && (!is_error_message())) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("id")); input_validate_input_number(get_request_var_post("perm_graphs")); input_validate_input_number(get_request_var_post("perm_trees")); input_validate_input_number(get_request_var_post("perm_hosts")); input_validate_input_number(get_request_var_post("perm_graph_templates")); /* ==================================================== */ $add_button_clicked = false; if (isset($_POST["add_graph_y"])) { db_execute("replace into user_auth_perms (user_id,item_id,type) values (" . $_POST["id"] . "," . $_POST["perm_graphs"] . ",1)"); $add_button_clicked = true; }elseif (isset($_POST["add_tree_y"])) { db_execute("replace into user_auth_perms (user_id,item_id,type) values (" . $_POST["id"] . "," . $_POST["perm_trees"] . ",2)"); $add_button_clicked = true; }elseif (isset($_POST["add_host_y"])) { db_execute("replace into user_auth_perms (user_id,item_id,type) values (" . $_POST["id"] . "," . $_POST["perm_hosts"] . ",3)"); $add_button_clicked = true; }elseif (isset($_POST["add_graph_template_y"])) { db_execute("replace into user_auth_perms (user_id,item_id,type) values (" . $_POST["id"] . "," . $_POST["perm_graph_templates"] . ",4)"); $add_button_clicked = true; } if ($add_button_clicked == true) { header("Location: user_admin.php?action=graph_perms_edit&id=" . $_POST["id"]); exit; } } /* user management save */ if (isset($_POST["save_component_user"])) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("id")); /* ==================================================== */ if (($_POST["password"] == "") && ($_POST["password_confirm"] == "")) { $password = db_fetch_cell("select password from user_auth where id=" . $_POST["id"]); }else{ $password = md5($_POST["password"]); } /* check duplicate username */ if (sizeof(db_fetch_row("select * from user_auth where realm = 0 and username = '" . $_POST["username"] . "' and id != '" . $_POST["id"] . "'"))) { raise_message(12); } /* check to make sure the passwords match; if not error */ if ($_POST["password"] != $_POST["password_confirm"]) { raise_message(4); } form_input_validate($_POST["password"], "password", "" . preg_quote($_POST["password_confirm"]) . "", true, 4); form_input_validate($_POST["password_confirm"], "password_confirm", "" . preg_quote($_POST["password"]) . "", true, 4); $save["id"] = $_POST["id"]; $save["username"] = form_input_validate($_POST["username"], "username", "^[A-Za-z0-9\._\-]+$", false, 3); $save["full_name"] = form_input_validate($_POST["full_name"], "full_name", "", true, 3); $save["password"] = $password; $save["must_change_password"] = form_input_validate((isset($_POST["must_change_password"]) ? $_POST["must_change_password"] : ""), "must_change_password", "", true, 3); $save["show_tree"] = form_input_validate((isset($_POST["show_tree"]) ? $_POST["show_tree"] : ""), "show_tree", "", true, 3); $save["show_list"] = form_input_validate((isset($_POST["show_list"]) ? $_POST["show_list"] : ""), "show_list", "", true, 3); $save["show_preview"] = form_input_validate((isset($_POST["show_preview"]) ? $_POST["show_preview"] : ""), "show_preview", "", true, 3); $save["graph_settings"] = form_input_validate((isset($_POST["graph_settings"]) ? $_POST["graph_settings"] : ""), "graph_settings", "", true, 3); $save["login_opts"] = form_input_validate($_POST["login_opts"], "login_opts", "", true, 3); $save["policy_graphs"] = form_input_validate((isset($_POST["policy_graphs"]) ? $_POST["policy_graphs"] : $_POST["_policy_graphs"]), "policy_graphs", "", true, 3); $save["policy_trees"] = form_input_validate((isset($_POST["policy_trees"]) ? $_POST["policy_trees"] : $_POST["_policy_trees"]), "policy_trees", "", true, 3); $save["policy_hosts"] = form_input_validate((isset($_POST["policy_hosts"]) ? $_POST["policy_hosts"] : $_POST["_policy_hosts"]), "policy_hosts", "", true, 3); $save["policy_graph_templates"] = form_input_validate((isset($_POST["policy_graph_templates"]) ? $_POST["policy_graph_templates"] : $_POST["_policy_graph_templates"]), "policy_graph_templates", "", true, 3); $save["realm"] = form_input_validate($_POST["realm"], "realm", "", true, 3); $save["enabled"] = form_input_validate($_POST["enabled"], "enabled", "", true, 3); if (!is_error_message()) { $user_id = sql_save($save, "user_auth"); if ($user_id) { raise_message(1); }else{ raise_message(2); } if (isset($_POST["save_component_realm_perms"])) { db_execute("delete from user_auth_realm where user_id=$user_id"); while (list($var, $val) = each($_POST)) { if (eregi("^[section]", $var)) { if (substr($var, 0, 7) == "section") { db_execute("replace into user_auth_realm (user_id,realm_id) values($user_id," . substr($var, 7) . ")"); } } } }elseif (isset($_POST["save_component_graph_settings"])) { while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { while (list($field_name, $field_array) = each($tab_fields)) { if ((isset($field_array["items"])) && (is_array($field_array["items"]))) { while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) { db_execute("replace into settings_graphs (user_id,name,value) values (" . (!empty($user_id) ? $user_id : $_POST["id"]) . ",'$sub_field_name', '" . (isset($_POST[$sub_field_name]) ? $_POST[$sub_field_name] : "") . "')"); } }else{ db_execute("replace into settings_graphs (user_id,name,value) values (" . (!empty($user_id) ? $user_id : $_POST["id"]) . ",'$field_name', '" . (isset($_POST[$field_name]) ? $_POST[$field_name] : "") . "')"); } } } /* reset local settings cache so the user sees the new settings */ kill_session_var("sess_graph_config_array"); }elseif (isset($_POST["save_component_graph_perms"])) { db_execute("update user_auth set policy_graphs='" . $_POST["policy_graphs"] . "', policy_trees='" . $_POST["policy_trees"] . "', policy_hosts='" . $_POST["policy_hosts"] . "', policy_graph_templates='" . $_POST["policy_graph_templates"] . "' where id=" . $_POST["id"]); } } } /* redirect to the appropriate page */ if (is_error_message()) { header("Location: user_admin.php?action=user_edit&id=" . (empty($user_id) ? $_POST["id"] : $user_id)); }else{ header("Location: user_admin.php"); } } /* -------------------------- Graph Permissions -------------------------- */ function perm_remove() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("user_id")); /* ==================================================== */ if ($_GET["type"] == "graph") { db_execute("delete from user_auth_perms where type=1 and user_id=" . $_GET["user_id"] . " and item_id=" . $_GET["id"]); }elseif ($_GET["type"] == "tree") { db_execute("delete from user_auth_perms where type=2 and user_id=" . $_GET["user_id"] . " and item_id=" . $_GET["id"]); }elseif ($_GET["type"] == "host") { db_execute("delete from user_auth_perms where type=3 and user_id=" . $_GET["user_id"] . " and item_id=" . $_GET["id"]); }elseif ($_GET["type"] == "graph_template") { db_execute("delete from user_auth_perms where type=4 and user_id=" . $_GET["user_id"] . " and item_id=" . $_GET["id"]); } header("Location: user_admin.php?action=graph_perms_edit&id=" . $_GET["user_id"]); } function graph_perms_edit() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $graph_policy_array = array( 1 => "Allow", 2 => "Deny"); if (!empty($_GET["id"])) { $policy = db_fetch_row("select policy_graphs,policy_trees,policy_hosts,policy_graph_templates from user_auth where id=" . $_GET["id"]); $header_label = "[edit: " . db_fetch_cell("select username from user_auth where id=" . $_GET["id"]) . "]"; } ?>
Graph policies will be evaluated in the order shown until a match is found.
Graph Permissions (By Graph)", "100%", $colors["header"], "3", "center", ""); $graphs = db_fetch_assoc("select graph_templates_graph.local_graph_id, graph_templates_graph.title_cache from graph_templates_graph left join user_auth_perms on (graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1) where graph_templates_graph.local_graph_id > 0 and user_auth_perms.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . " order by graph_templates_graph.title_cache"); ?> "> Default Policy
The default allow/deny graph policy for this user. 0) { foreach ($graphs as $item) { $i++; print " \n"; } }else{ print ""; } ?>
$i) " . $item["title_cache"] . " Delete 
No Graphs
Add Graph:  0 order by title_cache"),"title_cache","local_graph_id","","","");?>  

Graph Permissions (By Host)", "100%", $colors["header"], "3", "center", ""); $hosts = db_fetch_assoc("select host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name from host left join user_auth_perms on (host.id=user_auth_perms.item_id and user_auth_perms.type=3) where user_auth_perms.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . " order by host.description,host.hostname"); ?> "> Default Policy
The default allow/deny graph policy for this user. 0) { foreach ($hosts as $item) { $i++; print " \n"; } }else{ print ""; } ?>
$i) " . $item["name"] . " Delete 
No Hosts
Add Host:   

Graph Permissions (By Graph Template)", "100%", $colors["header"], "3", "center", ""); $graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from graph_templates left join user_auth_perms on (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4) where user_auth_perms.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . " order by graph_templates.name"); ?> "> Default Policy
The default allow/deny graph policy for this user. 0) { foreach ($graph_templates as $item) { $i++; print " \n"; } }else{ print ""; } ?>
$i) " . $item["name"] . " Delete 
No Graph Templates
Add Graph Template:   

Tree Permissions", "100%", $colors["header"], "3", "center", ""); $trees = db_fetch_assoc("select graph_tree.id, graph_tree.name from graph_tree left join user_auth_perms on (graph_tree.id=user_auth_perms.item_id and user_auth_perms.type=2) where user_auth_perms.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . " order by graph_tree.name"); ?> "> Default Policy
The default allow/deny graph policy for this user. 0) { foreach ($trees as $item) { $i++; print " \n"; } }else{ print ""; } ?>
$i) " . $item["name"] . " Delete 
No Trees
Add Tree:   

Realm permissions control which sections of Cacti this user will have access to.
Realm Permissions \n \n"; ?>
0) { $old_value = "on"; }else{ $old_value = ""; } $column1 = floor((sizeof($user_auth_realms) / 2) + (sizeof($user_auth_realms) % 2)); if ($i == $column1) { print ""; } form_checkbox("section" . $realm_id, $old_value, $realm_name, "", (!empty($_GET["id"]) ? 1 : 0)); print "
"; $i++; } ?>
Graph settings control how graphs are displayed for this user.
Graph Settings", "100%", $colors["header"], "3", "center", ""); while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { ?> $tab_fields[$field_name]); if ((isset($field_array["items"])) && (is_array($field_array["items"]))) { while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) { if (graph_config_value_exists($sub_field_name, $_GET["id"])) { $form_array[$field_name]["items"][$sub_field_name]["form_id"] = 1; } $form_array[$field_name]["items"][$sub_field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_GET["id"]); } }else{ if (graph_config_value_exists($field_name, $_GET["id"])) { $form_array[$field_name]["form_id"] = 1; } $form_array[$field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$field_name' and user_id=" . $_GET["id"]); } } draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); } html_end_box(); form_hidden_box("save_component_graph_settings","1",""); } /* -------------------------- User Administration -------------------------- */ function user_remove($user_id) { /* ================= input validation ================= */ input_validate_input_number($user_id); /* ==================================================== */ db_execute("delete from user_auth where id=" . $user_id); db_execute("delete from user_auth_realm where user_id=" . $user_id); db_execute("delete from user_auth_perms where user_id=" . $user_id); db_execute("delete from settings_graphs where user_id=" . $user_id); } function user_disable($user_id) { /* ================= input validation ================= */ input_validate_input_number($user_id); /* ==================================================== */ db_execute("UPDATE user_auth SET enabled = '' where id=" . $user_id); } function user_enable($user_id) { /* ================= input validation ================= */ input_validate_input_number($user_id); /* ==================================================== */ db_execute("UPDATE user_auth SET enabled = 'on' where id=" . $user_id); } function user_edit() { global $colors, $fields_user_user_edit_host; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $user = db_fetch_row("select * from user_auth where id=" . $_GET["id"]); $header_label = "[edit: " . $user["username"] . "]"; }else{ $header_label = "[new]"; } html_start_box("User Management $header_label", "100%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_user_user_edit_host, (isset($user) ? $user : array())) )); html_end_box(); if (!empty($_GET["id"])) { /* draw user admin nav tabs */ ?>
nowrap='nowrap' width='150' align='center' class='tab'> Realm Permissions nowrap='nowrap' width='150' align='center' class='tab'> Graph Permissions nowrap='nowrap' width='130' align='center' class='tab'> Graph Settings
User Management", "100%", $colors["header"], "3", "center", "user_admin.php?action=user_edit"); include("./include/html/inc_user_admin_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST["filter"])) { $sql_where = "where (user_auth.username like '%%" . $_REQUEST["filter"] . "%%' OR user_auth.full_name like '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(user_auth.id) FROM user_auth $sql_where"); $user_list = db_fetch_assoc("SELECT id, user_auth.username, full_name, realm, enabled, policy_graphs, time, max(time) as dtime FROM user_auth LEFT JOIN user_log ON (user_auth.id = user_log.user_id) $sql_where GROUP BY id ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device")); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host_templates.php?filter=" . $_REQUEST["filter"]); $nav = " \n \n \n
<< "; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= " Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] "; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= " >>
\n"; print $nav; $display_text = array( "username" => array("User Name", "ASC"), "full_name" => array("Full Name", "ASC"), "enabled" => array("Enabled", "ASC"), "realm" => array("Realm", "ASC"), "policy_graphs" => array("Default Graph Policy", "ASC"), "dtime" => array("Last Login", "DESC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($user_list) > 0) { 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"; } form_alternate_row_color($colors["alternate"],$colors["light"],$i,$user["id"]); $i++; form_selectable_cell("" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "\\1", $user["username"]) : $user["username"]) , $user["id"]); form_selectable_cell((strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "\\1", $user["full_name"]) : $user["full_name"]), $user["id"]); form_selectable_cell($enabled, $user["id"]); form_selectable_cell($auth_realms[$user["realm"]], $user["id"]); if ($user["policy_graphs"] == "1") { form_selectable_cell("ALLOW", $user["id"]); }else{ form_selectable_cell("DENY", $user["id"]); } form_selectable_cell($last_login, $user["id"]); form_checkbox_cell($user["username"], $user["id"]); form_end_row(); } print $nav; }else{ print "No Users"; } html_end_box(false); draw_actions_dropdown($user_actions); } ?>