diff --git a/user_admin.php b/user_admin.php index fd8e2166e..4aec66d07 100644 --- a/user_admin.php +++ b/user_admin.php @@ -751,8 +751,6 @@ function graph_perms_edit($tab, $header_label) { header('Location: user_admin.php'); } - process_graph_request_vars(); - graph_filter($header_label); form_start('user_admin.php', 'policy'); @@ -773,24 +771,24 @@ function graph_perms_edit($tab, $header_label) { html_start_box(__('Default Graph Policy'), '100%', '', '3', 'center', ''); ?> - - - - - -
- - - '> - - '> - -
- - -
- - + + + + +
+ + + '> + + '> + +
+ + +
+ + - - + 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') . ''; + print '' . __('No Matching User Groups Found') . ''; } html_end_box(false); @@ -1044,8 +1050,6 @@ function graph_perms_edit($tab, $header_label) { header('Location: user_admin.php'); } - process_device_request_vars(); - device_filter($header_label); form_start('user_admin.php', 'policy'); @@ -1053,21 +1057,21 @@ function graph_perms_edit($tab, $header_label) { html_start_box(__('Default Device Policy'), '100%', '', '3', 'center', ''); ?> - - - - - -
- - - '> - - '> - -
- - + + + + +
+ + + '> + + '> + +
+ + 0) { + $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' host.host_template_id = ?'; + $sql_params[] = get_request_var('host_template_id'); } if (get_request_var('associated') != 'false') { $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' user_auth_perms.user_id=' . get_request_var('id', 0); } - $total_rows = db_fetch_cell('SELECT - COUNT(host.id) - FROM host - LEFT JOIN user_auth_perms - ON host.id = user_auth_perms.item_id - AND user_auth_perms.type = 3 - AND user_auth_perms.user_id = ' . get_request_var('id') . " - $sql_where"); + $total_rows = db_fetch_cell_prepared("SELECT COUNT(host.id) + FROM host + LEFT JOIN user_auth_perms + ON host.id = user_auth_perms.item_id + AND user_auth_perms.type = 3 + AND user_auth_perms.user_id = ?, + $sql_where", + $sql_params); - $host_graphs = array_rekey( + $host_graphs = array_rekey( db_fetch_assoc('SELECT host_id, count(*) AS graphs - FROM graph_local - GROUP BY host_id'), - 'host_id', 'graphs'); + FROM graph_local + GROUP BY host_id'), + 'host_id', 'graphs' + ); $host_data_sources = array_rekey( db_fetch_assoc('SELECT host_id, count(*) AS data_sources - FROM data_local - GROUP BY host_id'), - 'host_id', 'data_sources'); - - $sql_query = 'SELECT host.*, user_auth_perms.user_id - FROM host - LEFT JOIN user_auth_perms - ON host.id = user_auth_perms.item_id - AND user_auth_perms.type = 3 - AND user_auth_perms.user_id = ' . get_request_var('id') . " - $sql_where - ORDER BY description - LIMIT " . ($rows * (get_request_var('page') - 1)) . ',' . $rows; - - $hosts = db_fetch_assoc($sql_query); + FROM data_local + GROUP BY host_id'), + 'host_id', 'data_sources' + ); + + $sql_query = "SELECT host.*, user_auth_perms.user_id + FROM host + LEFT JOIN user_auth_perms + ON host.id = user_auth_perms.item_id + AND user_auth_perms.type = 3 + AND user_auth_perms.user_id = ? + $sql_where + ORDER BY description + LIMIT " . ($rows * (get_request_var('page') - 1)) . ',' . $rows; + + $hosts = db_fetch_assoc_prepared($sql_query, $sql_params); $nav = html_nav_bar('user_admin.php?action=user_edit&tab=permsd&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 11, __('Devices'), 'page', 'main'); @@ -1150,6 +1157,7 @@ function graph_perms_edit($tab, $header_label) { if (cacti_sizeof($hosts)) { foreach ($hosts as $host) { form_alternate_row('line' . $host['id'], true); + form_selectable_cell(filter_value($host['description'], get_request_var('filter')), $host['id']); form_selectable_cell($host['id'], $host['id']); @@ -1170,11 +1178,13 @@ function graph_perms_edit($tab, $header_label) { 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') . ''; + print '' . __('No Matching Devices Found') . ''; } html_end_box(false); @@ -1210,8 +1220,6 @@ function graph_perms_edit($tab, $header_label) { header('Location: user_admin.php'); } - process_template_request_vars(); - template_filter($header_label); form_start('user_admin.php', 'policy'); @@ -1219,21 +1227,21 @@ function graph_perms_edit($tab, $header_label) { html_start_box(__('Default Graph Template Policy'), '100%', '', '3', 'center', ''); ?> - - - - - -
- - - '> - - '> - -
- - + + + + +
+ + + '> + + '> + +
+ + ' . __('No Matching Graph Templates Found') . ''; + print '' . __('No Matching Graph Templates Found') . ''; } html_end_box(false); @@ -1355,8 +1376,6 @@ function graph_perms_edit($tab, $header_label) { header('Location: user_admin.php'); } - process_tree_request_vars(); - tree_filter($header_label); form_start('user_admin.php', 'policy'); @@ -1364,21 +1383,21 @@ function graph_perms_edit($tab, $header_label) { html_start_box(__('Default Tree Policy'), '100%', '', '3', 'center', ''); ?> - - - - - + + - - + ' . __('Access Granted') . '', $t['id']); } } + form_checkbox_cell($t['name'], $t['id']); + form_end_row(); } } else { - print ''; + print ''; } html_end_box(false); @@ -1983,55 +2008,123 @@ function changeRealm() { } } -function user() { - global $config, $auth_realms, $actions, $item_rows; +function create_user_filter() { + global $item_rows; + + $all = array('-1' => __('All')); + $any = array('-1' => __('Any')); + $none = array('0' => __('None')); + + $groups = array_rekey( + db_fetch_assoc('SELECT id, description + FROM user_auth_group + ORDER BY description'), + 'id', 'description' + ); - /* ================= input validation and session storage ================= */ - $filters = array( + $groups = $all + $groups; + + $logins = array( + '0' => __esc('All'), + '1' => __esc('< 1 Week Ago'), + '2' => __esc('< 1 Month Ago'), + '3' => __esc('> 1 Month Ago'), + '4' => __esc('> 2 Months Ago'), + '5' => __esc('> 4 Months Ago'), + '6' => __esc('Never') + ); + + $realms = array( + '-1' => __('All'), + '0' => __('Local'), + '2' => __('Basic'), + '3' => __('LDAP/AD'), + '4' => __('Domain') + ); + + return array( 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'realm' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'login' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '0' - ), - 'filter' => array( - 'filter' => FILTER_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'group' => array( - 'filter' => FILTER_CALLBACK, - 'default' => '-1', - 'pageset' => true, - 'options' => array('options' => 'sanitize_search_string') + array( + 'filter' => array( + 'method' => 'textbox', + 'friendly_name' => __('Search'), + 'filter' => FILTER_DEFAULT, + 'placeholder' => __('Enter a search term'), + 'size' => '30', + 'default' => '', + 'pageset' => true, + 'max_length' => '120', + 'value' => '' + ), + 'group' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Group'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $groups, + 'value' => '-1' + ), + 'login' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Last Login'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '0', + 'pageset' => true, + 'array' => $logins, + 'value' => '0' + ), + 'realm' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Realm'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '0', + 'pageset' => true, + 'array' => $realms, + 'value' => '0' + ), + 'rows' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Users'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $item_rows, + 'value' => '-1' + ) + ) ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'username', - 'options' => array('options' => 'sanitize_search_string') + 'buttons' => array( + 'go' => array( + 'method' => 'submit', + 'display' => __('Go'), + 'title' => __('Apply filter to table'), + ), + 'clear' => array( + 'method' => 'button', + 'display' => __('Clear'), + 'title' => __('Reset filter to default values'), + ) ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, - 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') + 'sort' => array( + 'sort_column' => 'username', + 'sort_direction' => 'ASC' ) ); +} - validate_store_request_vars($filters, 'sess_usera'); - /* ================= input validation ================= */ +function user() { + global $config, $auth_realms, $actions, $item_rows; + + $filters = create_user_filter(); + + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('User Management'), 'user_admin.php', 'form_user', 'sess_ua', 'user_admin.php?action=edit'); + + $pageFilter->rows_label = __('Users'); + + $pageFilter->set_filter_array($filters); + $pageFilter->render(); if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); @@ -2039,155 +2132,29 @@ function user() { $rows = get_request_var('rows'); } - html_filter_start_box(__('User Management'), 'user_admin.php?tab=general&action=user_edit'); - - ?> - - - - = 0) { if (get_request_var('realm') < 4) { - $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' ua.realm = ' . get_request_var('realm'); + $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' ua.realm = ?'; + $sql_params[] = get_request_var('realm'); } else { $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' ua.realm > 3'; } } if (get_request_var('group') > 0) { - $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' ug.group_id = ' . get_request_var('group'); + $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' ug.group_id = ?'; + $sql_params[] = get_request_var('group'); } if (get_request_var('login') > 0) { @@ -2206,7 +2173,7 @@ function clearFilter() { } } - $total_rows = db_fetch_cell("SELECT + $total_rows = db_fetch_cell_prepared("SELECT COUNT(DISTINCT ua.id) FROM user_auth AS ua LEFT JOIN ( @@ -2217,12 +2184,13 @@ function clearFilter() { ON ua.id = ul.user_id LEFT JOIN user_auth_group_members AS ug ON ua.id = ug.user_id - $sql_where"); + $sql_where", + $sql_params); $sql_order = get_order_string(); $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; - $user_list = db_fetch_assoc("SELECT ua.id, ua.username, ua.full_name, + $user_list = db_fetch_assoc_prepared("SELECT ua.id, ua.username, ua.full_name, ua.realm, ua.enabled, ua.policy_graphs, ua.policy_hosts, ua.policy_graph_templates, time, MAX(UNIX_TIMESTAMP(time)) as dtime FROM user_auth AS ua @@ -2237,7 +2205,47 @@ function clearFilter() { $sql_where GROUP BY ua.id $sql_order - $sql_limit"); + $sql_limit", + $sql_params); + + $display_text = array( + 'username' => array( + 'display' => __('User Name'), + 'sort' => 'ASC' + ), + 'id' => array( + 'display' => __('User ID'), + 'sort' => 'ASC' + ), + 'full_name' => array( + 'display' => __('Full Name'), + 'sort' => 'ASC' + ), + 'enabled' => array( + 'display' => __('Enabled'), + 'sort' => 'ASC' + ), + 'realm' => array( + 'display' => __('Realm'), + 'sort' => 'ASC' + ), + 'policy_graphs' => array( + 'display' => __('Graph Policy'), + 'sort' => 'ASC' + ), + 'policy_hosts' => array( + 'display' => __('Device Policy'), + 'sort' => 'ASC' + ), + 'policy_graph_templates' => array( + 'display' => __('Template Policy'), + 'sort' => 'ASC' + ), + 'dtime' => array( + 'display' => __('Last Login'), + 'sort' => 'DESC' + ) + ); $nav = html_nav_bar('user_admin.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 9, __('Users'), 'page', 'main'); @@ -2247,18 +2255,6 @@ function clearFilter() { html_start_box('', '100%', '', '3', 'center', ''); - $display_text = array( - 'username' => array(__('User Name'), 'ASC'), - 'id' => array(__('User ID'), '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 (cacti_sizeof($user_list)) { @@ -2318,787 +2314,221 @@ function clearFilter() { 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_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - '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_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - '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_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - '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' - ) - ); +function create_graphs_filter() { + global $item_rows; - validate_store_request_vars($filters, 'sess_uad'); - /* ================= input validation ================= */ -} + $any = array('-1' => __('Any')); + $none = array('0' => __('None')); -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_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - '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' - ) + $graph_templates = array_rekey( + db_fetch_assoc('SELECT DISTINCT gt.id, gt.name + FROM graph_templates AS gt + INNER JOIN graph_local AS gl + ON gl.graph_template_id = gt.id + ORDER BY name'), + 'id', 'name' ); - validate_store_request_vars($filters, 'sess_uate'); - /* ================= input validation ================= */ -} + $graph_templates = $any + $none + $graph_templates; -function process_tree_request_vars() { - /* ================= input validation and session storage ================= */ - $filters = array( + return 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_DEFAULT, - 'pageset' => true, - 'default' => '' - ), - 'graph_template_id' => array( - 'filter' => FILTER_VALIDATE_INT, - 'pageset' => true, - 'default' => '-1', + array( + 'filter' => array( + 'method' => 'textbox', + 'friendly_name' => __('Search'), + 'filter' => FILTER_DEFAULT, + 'placeholder' => __('Enter a search term'), + 'size' => '30', + 'default' => '', + 'pageset' => true, + 'max_length' => '120', + 'value' => '' + ), + 'graph_template_id' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Template'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '0', + 'pageset' => true, + 'array' => $graph_templates, + 'value' => '0' + ), + 'rows' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Graphs'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $item_rows, + 'value' => '-1' + ) + ) ), - 'associated' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array('options' => array('regexp' => '(true|false)')), - 'pageset' => true, - 'default' => 'true' + 'buttons' => array( + 'go' => array( + 'method' => 'submit', + 'display' => __('Go'), + 'title' => __('Apply filter to table'), + ), + 'clear' => array( + 'method' => 'button', + 'display' => __('Clear'), + 'title' => __('Reset filter to default values'), + ) ) ); - - validate_store_request_vars($filters, 'sess_uatr'); - /* ================= input validation ================= */ } function graph_filter($header_label) { global $config, $item_rows; - html_filter_start_box(__esc('Graph Permissions %s', $header_label)); + $filters = create_device_filter(); - ?> - - - - - - - - array( + array( + 'filter' => array( + 'method' => 'textbox', + 'friendly_name' => __('Search'), + 'filter' => FILTER_DEFAULT, + 'placeholder' => __('Enter a search term'), + 'size' => '30', + 'default' => '', + 'pageset' => true, + 'max_length' => '120', + 'value' => '' + ), + 'host_template_id' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Template'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '0', + 'pageset' => true, + 'array' => $host_templates, + 'value' => '0' + ), + 'rows' => array( + 'method' => 'drop_array', + 'friendly_name' => __('Devices'), + 'filter' => FILTER_VALIDATE_INT, + 'default' => '-1', + 'pageset' => true, + 'array' => $item_rows, + 'value' => '-1' + ) + ) + ), + 'buttons' => array( + 'go' => array( + 'method' => 'submit', + 'display' => __('Go'), + 'title' => __('Apply filter to table'), + ), + 'clear' => array( + 'method' => 'button', + 'display' => __('Clear'), + 'title' => __('Reset filter to default values'), + ) + ) + ); } function device_filter($header_label) { global $config, $item_rows; - html_filter_start_box(__esc('Devices Permission %s', $header_label)); - - ?> - - - - set_filter_array($filters); + $pageFilter->render(); - html_end_box(); + form_hidden_box('action', 'user_edit', ''); + form_hidden_box('tab', 'permste', ''); + form_hidden_box('id', get_request_var('id'), ''); } function template_filter($header_label) { global $config, $item_rows; - html_filter_start_box(__esc('Template Permission %s', $header_label)); + /* create the page filter */ + $pageFilter = new CactiTableFilter(__('Template Permissions %s', $header_label), 'user_admin.php?action=user_edit&tab=permste&id=' . get_request_var('id'), 'form_template', 'sess_ua_te'); - ?> - - - - - - - - - - - -
- - - '> - - '> - -
+ + +
+ + + '> + + '> + +
' . __('No Matching Trees Found') . '
' . __('No Matching Trees Found') . '
-
- - - - - - - - - - - - - - -
- - - '> - - - - - - - - - - - - - - - - - - - ' title=''> - ' title=''> - -
-
- -
-
- - - - - - - - - - - -
- - - '> - - - - - - - - - - - > - - - - - ' title=''> - ' title=''> - -
- - - '> -
- -
-
- - - - - - - - - -
- - - '> - - - - - - - > - - - - - ' title=''> - ' title=''> - -
- - - '> -
- -
-
- - - - - - - - - - - -
- - - '> - - - - - - - - - - - > - - - - - ' title=''> - ' title=''> - -
- - - '> -
- -
-
- - - - - - - - - -
- - - '> - - - - - - - > - - - - - ' title=''> - ' title=''> - -
- - - '> -
- -
-
- - - - - - - - - -
- - - '> - - - - - - - > - - - - - ' title=''> - ' title=''> - -
- - - '> -
- -
-
- - - - - - - - - -
- - - '> - - - - - - - > - - - - - ' title=''> - ' title=''> - -
- - - '> -
- -