1<?php 2/* 3 +-------------------------------------------------------------------------+ 4 | Copyright (C) 2004-2021 The Cacti Group | 5 | | 6 | This program is free software; you can redistribute it and/or | 7 | modify it under the terms of the GNU General Public License | 8 | as published by the Free Software Foundation; either version 2 | 9 | of the License, or (at your option) any later version. | 10 | | 11 | This program is distributed in the hope that it will be useful, | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | GNU General Public License for more details. | 15 +-------------------------------------------------------------------------+ 16 | Cacti: The Complete RRDtool-based Graphing Solution | 17 +-------------------------------------------------------------------------+ 18 | This code is designed, written, and maintained by the Cacti Group. See | 19 | about.php and/or the AUTHORS file for specific developer information. | 20 +-------------------------------------------------------------------------+ 21 | http://www.cacti.net/ | 22 +-------------------------------------------------------------------------+ 23*/ 24 25include('./include/auth.php'); 26include_once('./lib/poller.php'); 27include_once('./lib/utility.php'); 28 29$actions = array( 30 1 => __('Delete'), 31 2 => __('Disable'), 32 3 => __('Enable'), 33 4 => __('Default') 34); 35 36/* set default action */ 37set_default_action(); 38 39switch (get_request_var('action')) { 40 case 'save': 41 form_save(); 42 43 break; 44 case 'actions': 45 form_actions(); 46 47 break; 48 case 'edit': 49 top_header(); 50 51 domain_edit(); 52 53 bottom_footer(); 54 break; 55 default: 56 top_header(); 57 58 domains(); 59 60 bottom_footer(); 61 break; 62} 63 64/* -------------------------- 65 The Save Function 66 -------------------------- */ 67 68function form_save() { 69 global $registered_cacti_names; 70 71 if (isset_request_var('save_component_domain_ldap')) { 72 /* ================= input validation ================= */ 73 get_filter_request_var('domain_id'); 74 get_filter_request_var('type'); 75 get_filter_request_var('user_id'); 76 /* ==================================================== */ 77 78 $save['domain_id'] = get_nfilter_request_var('domain_id'); 79 $save['type'] = get_nfilter_request_var('type'); 80 $save['user_id'] = get_nfilter_request_var('user_id'); 81 $save['domain_name'] = form_input_validate(get_nfilter_request_var('domain_name'), 'domain_name', '', false, 3); 82 $save['enabled'] = (isset_request_var('enabled') ? form_input_validate(get_nfilter_request_var('enabled'), 'enabled', '', true, 3):''); 83 84 if (!is_error_message()) { 85 $domain_id = sql_save($save, 'user_domains', 'domain_id'); 86 87 if ($domain_id) { 88 // Disable template user from logging in 89 db_execute_prepared('UPDATE user_auth 90 SET enabled="" 91 WHERE id = ?', array($save['user_id'])); 92 93 raise_message(1); 94 } else { 95 raise_message(2); 96 } 97 98 if (!is_error_message()) { 99 /* ================= input validation ================= */ 100 get_filter_request_var('domain_id'); 101 get_filter_request_var('port'); 102 get_filter_request_var('port_ssl'); 103 get_filter_request_var('proto_version'); 104 get_filter_request_var('encryption'); 105 get_filter_request_var('referrals'); 106 get_filter_request_var('mode'); 107 get_filter_request_var('group_member_type'); 108 /* ==================================================== */ 109 110 $save = array(); 111 $save['domain_id'] = $domain_id; 112 $save['server'] = form_input_validate(get_nfilter_request_var('server'), 'server', '', false, 3); 113 $save['port'] = get_nfilter_request_var('port'); 114 $save['port_ssl'] = get_nfilter_request_var('port_ssl'); 115 $save['proto_version'] = get_nfilter_request_var('proto_version'); 116 $save['encryption'] = get_nfilter_request_var('encryption'); 117 $save['referrals'] = get_nfilter_request_var('referrals'); 118 $save['mode'] = get_nfilter_request_var('mode'); 119 $save['group_member_type'] = get_nfilter_request_var('group_member_type'); 120 $save['dn'] = form_input_validate(get_nfilter_request_var('dn'), 'dn', '', true, 3); 121 $save['group_require'] = isset_request_var('group_require') ? 'on':''; 122 $save['group_dn'] = form_input_validate(get_nfilter_request_var('group_dn'), 'group_dn', '', true, 3); 123 $save['group_attrib'] = form_input_validate(get_nfilter_request_var('group_attrib'), 'group_attrib', '', true, 3); 124 $save['search_base'] = form_input_validate(get_nfilter_request_var('search_base'), 'search_base', '', true, 3); 125 $save['search_filter'] = form_input_validate(get_nfilter_request_var('search_filter'), 'search_filter', '', true, 3); 126 $save['specific_dn'] = form_input_validate(get_nfilter_request_var('specific_dn'), 'specific_dn', '', true, 3); 127 $save['specific_password'] = form_input_validate(get_nfilter_request_var('specific_password'), 'specific_password', '', true, 3); 128 $save['cn_full_name'] = get_nfilter_request_var('cn_full_name'); 129 $save['cn_email'] = get_nfilter_request_var('cn_email'); 130 131 if (!is_error_message()) { 132 $insert_id = sql_save($save, 'user_domains_ldap', 'domain_id', false); 133 134 if ($insert_id) { 135 raise_message(1); 136 } else { 137 raise_message(2); 138 } 139 } 140 } 141 } 142 } elseif (isset_request_var('save_component_domain')) { 143 /* ================= input validation ================= */ 144 get_filter_request_var('domain_id'); 145 get_filter_request_var('type'); 146 get_filter_request_var('user_id'); 147 /* ==================================================== */ 148 149 $save['domain_id'] = get_nfilter_request_var('domain_id'); 150 $save['domain_name'] = form_input_validate(get_nfilter_request_var('domain_name'), 'domain_name', '', false, 3); 151 $save['type'] = get_nfilter_request_var('type'); 152 $save['user_id'] = get_nfilter_request_var('user_id'); 153 $save['enabled'] = (isset_request_var('enabled') ? form_input_validate(get_nfilter_request_var('enabled'), 'enabled', '', true, 3):''); 154 155 if (!is_error_message()) { 156 $domain_id = sql_save($save, 'user_domains', 'domain_id'); 157 158 if ($domain_id) { 159 raise_message(1); 160 } else { 161 raise_message(2); 162 } 163 } 164 } 165 166 header('Location: user_domains.php?header=false&action=edit&domain_id=' . (empty($domain_id) ? get_nfilter_request_var('domain_id') : $domain_id)); 167} 168 169function form_actions() { 170 global $actions; 171 172 /* if we are to save this form, instead of display it */ 173 if (isset_request_var('selected_items')) { 174 $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); 175 176 if ($selected_items != false) { 177 if (get_nfilter_request_var('drp_action') == '1') { // delete 178 for ($i=0;($i<cacti_count($selected_items));$i++) { 179 domain_remove($selected_items[$i]); 180 } 181 } elseif (get_nfilter_request_var('drp_action') == '2') { // disable 182 for ($i=0;($i<cacti_count($selected_items));$i++) { 183 domain_disable($selected_items[$i]); 184 } 185 } elseif (get_nfilter_request_var('drp_action') == '3') { // enable 186 for ($i=0;($i<cacti_count($selected_items));$i++) { 187 domain_enable($selected_items[$i]); 188 } 189 } elseif (get_nfilter_request_var('drp_action') == '4') { // default 190 if (cacti_sizeof($selected_items) > 1) { 191 /* error message */ 192 } else { 193 for ($i=0;($i<cacti_count($selected_items));$i++) { 194 domain_default($selected_items[$i]); 195 } 196 } 197 } 198 } 199 200 header('Location: user_domains.php?header=false'); 201 exit; 202 } 203 204 /* setup some variables */ 205 $d_list = ''; 206 $d_array = array(); 207 208 /* loop through each of the data queries and process them */ 209 foreach ($_POST as $var => $val) { 210 if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { 211 /* ================= input validation ================= */ 212 input_validate_input_number($matches[1]); 213 /* ==================================================== */ 214 215 $d_list .= '<li>' . html_escape(db_fetch_cell_prepared('SELECT domain_name FROM user_domains WHERE domain_id = ?', array($matches[1]))) . '</li>'; 216 $d_array[] = $matches[1]; 217 } 218 } 219 220 top_header(); 221 222 form_start('user_domains.php'); 223 224 html_start_box($actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', ''); 225 226 if (isset($d_array) && cacti_sizeof($d_array)) { 227 if (get_nfilter_request_var('drp_action') == '1') { // delete 228 print "<tr> 229 <td class='textArea'> 230 <p>" . __n('Click \'Continue\' to delete the following User Domain.', 'Click \'Continue\' to delete following User Domains.', cacti_sizeof($d_array)) . "</p> 231 <div class='itemlist'><ul>$d_list</ul></div> 232 </td> 233 </tr>\n"; 234 235 $save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'> <input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __n('Delete User Domain', 'Delete User Domains', cacti_sizeof($d_array)) . "'>"; 236 }else if (get_nfilter_request_var('drp_action') == '2') { // disable 237 print "<tr> 238 <td class='textArea'> 239 <p>" . __n('Click \'Continue\' to disable the following User Domain.', 'Click \'Continue\' to disable following User Domains.', cacti_sizeof($d_array)) . "</p> 240 <div class='itemlist'><ul>$d_list</ul></div> 241 </td> 242 </tr>\n"; 243 244 $save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'> <input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __n('Disable User Domain', 'Disable User Domains', cacti_sizeof($d_array)) . "'>"; 245 }else if (get_nfilter_request_var('drp_action') == '3') { // enable 246 print "<tr> 247 <td class='textArea'> 248 <p>" . __('Click \'Continue\' to enable the following User Domain.', 'Click \'Continue\' to enable following User Domains.', cacti_sizeof($d_array)) . "</p> 249 <div class='itemlist'><ul>$d_list</ul></div> 250 </td> 251 </tr>\n"; 252 253 $save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'> <input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __n('Enabled User Domain', 'Enable User Domains', cacti_sizeof($d_array)) . "'>"; 254 }else if (get_nfilter_request_var('drp_action') == '4') { // default 255 print "<tr> 256 <td class='textArea'> 257 <p>" . __('Click \'Continue\' to make the following the following User Domain the default one.') . "</p> 258 <div class='itemlist'><ul>$d_list</ul></div> 259 </td> 260 </tr>\n"; 261 262 $save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'> <input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __esc('Make Selected Domain Default') . "'>"; 263 } 264 } else { 265 raise_message(40); 266 header('Location: user_domains.php?header=false'); 267 exit; 268 } 269 270 print "<tr> 271 <td class='saveRow'> 272 <input type='hidden' name='action' value='actions'> 273 <input type='hidden' name='selected_items' value='" . (isset($d_array) ? serialize($d_array) : '') . "'> 274 <input type='hidden' name='drp_action' value='" . html_escape(get_nfilter_request_var('drp_action')) . "'> 275 $save_html 276 </td> 277 </tr>\n"; 278 279 html_end_box(); 280 281 form_end(); 282 283 bottom_footer(); 284} 285 286/* ----------------------- 287 Domain Functions 288 ----------------------- */ 289 290function domain_remove($domain_id) { 291 db_execute_prepared('DELETE FROM user_domains WHERE domain_id = ?', array($domain_id)); 292 db_execute_prepared('DELETE FROM user_domains_ldap WHERE domain_id = ?', array($domain_id)); 293} 294 295function domain_disable($domain_id) { 296 db_execute_prepared('UPDATE user_domains SET enabled = "" WHERE domain_id = ?', array($domain_id)); 297} 298 299function domain_enable($domain_id) { 300 db_execute_prepared('UPDATE user_domains SET enabled = "on" WHERE domain_id = ?', array($domain_id)); 301} 302 303function domain_default($domain_id) { 304 db_execute('UPDATE user_domains SET defdomain = 0'); 305 db_execute_prepared('UPDATE user_domains SET defdomain = 1 WHERE domain_id = ?', array($domain_id)); 306} 307 308function domain_edit() { 309 global $ldap_versions, $ldap_encryption, $ldap_modes, $domain_types; 310 311 /* ================= input validation ================= */ 312 get_filter_request_var('domain_id'); 313 /* ==================================================== */ 314 315 if (!isempty_request_var('domain_id')) { 316 $domain = db_fetch_row_prepared('SELECT * FROM user_domains WHERE domain_id = ?', array(get_request_var('domain_id'))); 317 $header_label = __esc('User Domain [edit: %s]', $domain['domain_name']); 318 } else { 319 $header_label = __('User Domain [new]'); 320 } 321 322 /* file: data_input.php, action: edit */ 323 $fields_domain_edit = array( 324 'domain_name' => array( 325 'method' => 'textbox', 326 'friendly_name' => __('Name'), 327 'description' => __('Enter a meaningful name for this domain. This will be the name that appears in the Login Realm during login.'), 328 'value' => '|arg1:domain_name|', 329 'max_length' => '255', 330 ), 331 'type' => array( 332 'method' => 'drop_array', 333 'friendly_name' => __('Domains Type'), 334 'description' => __('Choose what type of domain this is.'), 335 'value' => '|arg1:type|', 336 'array' => $domain_types, 337 'default' => '2' 338 ), 339 'user_id' => array( 340 'friendly_name' => __('User Template'), 341 'description' => __('The name of the user that Cacti will use as a template for new user accounts.'), 342 'method' => 'drop_sql', 343 'value' => '|arg1:user_id|', 344 'none_value' => __('No User'), 345 'sql' => 'SELECT id AS id, username AS name FROM user_auth WHERE realm=0 ORDER BY username', 346 'default' => '0' 347 ), 348 'enabled' => array( 349 'method' => 'checkbox', 350 'friendly_name' => __('Enabled'), 351 'description' => __('If this checkbox is checked, users will be able to login using this domain.'), 352 'value' => '|arg1:enabled|', 353 'default' => '', 354 ), 355 'domain_id' => array( 356 'method' => 'hidden_zero', 357 'value' => '|arg1:domain_id|' 358 ), 359 'save_component_domain' => array( 360 'method' => 'hidden', 361 'value' => '1' 362 ) 363 ); 364 365 $fields_domain_ldap_edit = array( 366 'server' => array( 367 'friendly_name' => __('Server(s)'), 368 'description' => __('A space delimited list of DNS hostnames or IP address of for valid LDAP servers. Cacti will attempt to use the LDAP servers from left to right to authenticate a user.'), 369 'method' => 'textbox', 370 'value' => '|arg1:server|', 371 'default' => read_config_option('ldap_server'), 372 'size' => 80, 373 'max_length' => '255' 374 ), 375 'port' => array( 376 'friendly_name' => __('Port Standard'), 377 'description' => __('TCP/UDP port for Non SSL communications.'), 378 'method' => 'textbox', 379 'max_length' => '5', 380 'value' => '|arg1:port|', 381 'default' => read_config_option('ldap_port'), 382 'size' => '5' 383 ), 384 'port_ssl' => array( 385 'friendly_name' => __('Port SSL'), 386 'description' => __('TCP/UDP port for SSL communications.'), 387 'method' => 'textbox', 388 'max_length' => '5', 389 'value' => '|arg1:port_ssl|', 390 'default' => read_config_option('ldap_port_ssl'), 391 'size' => '5' 392 ), 393 'proto_version' => array( 394 'friendly_name' => __('Protocol Version'), 395 'description' => __('Protocol Version that the server supports.'), 396 'method' => 'drop_array', 397 'value' => '|arg1:proto_version|', 398 'array' => $ldap_versions 399 ), 400 'encryption' => array( 401 'friendly_name' => __('Encryption'), 402 'description' => __('Encryption that the server supports. TLS is only supported by Protocol Version 3.'), 403 'method' => 'drop_array', 404 'value' => '|arg1:encryption|', 405 'array' => $ldap_encryption 406 ), 407 'referrals' => array( 408 'friendly_name' => __('Referrals'), 409 'description' => __('Enable or Disable LDAP referrals. If disabled, it may increase the speed of searches.'), 410 'method' => 'drop_array', 411 'value' => '|arg1:referrals|', 412 'array' => array( '0' => __('Disabled'), '1' => __('Enable')) 413 ), 414 'mode' => array( 415 'friendly_name' => __('Mode'), 416 'description' => __('Mode which cacti will attempt to authenticate against the LDAP server.<blockquote><i>No Searching</i> - No Distinguished Name (DN) searching occurs, just attempt to bind with the provided Distinguished Name (DN) format.<br><br><i>Anonymous Searching</i> - Attempts to search for username against LDAP directory via anonymous binding to locate the users Distinguished Name (DN).<br><br><i>Specific Searching</i> - Attempts search for username against LDAP directory via Specific Distinguished Name (DN) and Specific Password for binding to locate the users Distinguished Name (DN).'), 417 'method' => 'drop_array', 418 'value' => '|arg1:mode|', 419 'array' => $ldap_modes 420 ), 421 'dn' => array( 422 'friendly_name' => __('Distinguished Name (DN)'), 423 'description' => __('Distinguished Name syntax, such as for windows: <i>"<username>@win2kdomain.local"</i> or for OpenLDAP: <i>"uid=<username>,ou=people,dc=domain,dc=local"</i>. "<username>" is replaced with the username that was supplied at the login prompt. This is only used when in "No Searching" mode.'), 424 'method' => 'textbox', 425 'value' => '|arg1:dn|', 426 'max_length' => '255' 427 ), 428 'group_require' => array( 429 'friendly_name' => __('Require Group Membership'), 430 '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.'), 431 'value' => '|arg1:group_require|', 432 'method' => 'checkbox' 433 ), 434 'group_header' => array( 435 'friendly_name' => __('LDAP Group Settings'), 436 'method' => 'spacer' 437 ), 438 'group_dn' => array( 439 'friendly_name' => __('Group Distinguished Name (DN)'), 440 'description' => __('Distinguished Name of the group that user must have membership.'), 441 'method' => 'textbox', 442 'value' => '|arg1:group_dn|', 443 'max_length' => '255' 444 ), 445 'group_attrib' => array( 446 'friendly_name' => __('Group Member Attribute'), 447 'description' => __('Name of the attribute that contains the usernames of the members.'), 448 'method' => 'textbox', 449 'value' => '|arg1:group_attrib|', 450 'max_length' => '255' 451 ), 452 'group_member_type' => array( 453 'friendly_name' => __('Group Member Type'), 454 'description' => __('Defines if users use full Distinguished Name or just Username in the defined Group Member Attribute.'), 455 'method' => 'drop_array', 456 'value' => '|arg1:group_member_type|', 457 'array' => array( 1 => 'Distinguished Name', 2 => 'Username' ) 458 ), 459 'search_base_header' => array( 460 'friendly_name' => __('LDAP Specific Search Settings'), 461 'method' => 'spacer' 462 ), 463 'search_base' => array( 464 'friendly_name' => __('Search Base'), 465 'description' => __('Search base for searching the LDAP directory, such as <i>"dc=win2kdomain,dc=local"</i> or <i>"ou=people,dc=domain,dc=local"</i>.'), 466 'method' => 'textbox', 467 'value' => '|arg1:search_base|', 468 'max_length' => '255' 469 ), 470 'search_filter' => array( 471 'friendly_name' => __('Search Filter'), 472 'description' => __('Search filter to use to locate the user in the LDAP directory, such as for windows: <i>"(&(objectclass=user)(objectcategory=user)(userPrincipalName=<username>*))"</i> or for OpenLDAP: <i>"(&(objectClass=account)(uid=<username>))"</i>. "<username>" is replaced with the username that was supplied at the login prompt.'), 473 'method' => 'textbox', 474 'value' => '|arg1:search_filter|', 475 'max_length' => '512' 476 ), 477 'specific_dn' => array( 478 'friendly_name' => __('Search Distinguished Name (DN)'), 479 'description' => __('Distinguished Name for Specific Searching binding to the LDAP directory.'), 480 'method' => 'textbox', 481 'value' => '|arg1:specific_dn|', 482 'max_length' => '255' 483 ), 484 'specific_password' => array( 485 'friendly_name' => __('Search Password'), 486 'description' => __('Password for Specific Searching binding to the LDAP directory.'), 487 'method' => 'textbox_password', 488 'value' => '|arg1:specific_password|', 489 'max_length' => '255' 490 ), 491 'cn_header' => array( 492 'friendly_name' => __('LDAP CN Settings'), 493 'method' => 'spacer' 494 ), 495 'cn_full_name' => array( 496 'friendly_name' => __('Full Name'), 497 'description' => __('Field that will replace the Full Name when creating a new user, taken from LDAP. (on windows: displayname) '), 498 'method' => 'textbox', 499 'value' => '|arg1:cn_full_name|', 500 'max_length' => '255' 501 ), 502 'cn_email' => array( 503 'friendly_name' => __('eMail'), 504 'description' => __('Field that will replace the email taken from LDAP. (on windows: mail) '), 505 'method' => 'textbox', 506 'value' => '|arg1:cn_email|', 507 'max_length' => '255' 508 ), 509 'save_component_domain_ldap' => array( 510 'method' => 'hidden', 511 'value' => '1' 512 ) 513 ); 514 515 form_start('user_domains.php'); 516 517 html_start_box($header_label, '100%', true, '3', 'center', ''); 518 519 draw_edit_form(array( 520 'config' => array(), 521 'fields' => inject_form_variables($fields_domain_edit, (isset($domain) ? $domain : array())) 522 )); 523 524 html_end_box(true, true); 525 526 if (!isempty_request_var('domain_id')) { 527 $domain = db_fetch_row_prepared('SELECT * FROM user_domains_ldap WHERE domain_id = ?', array(get_request_var('domain_id'))); 528 529 html_start_box( __('Domain Properties'), '100%', true, '3', 'center', ''); 530 531 draw_edit_form(array( 532 'config' => array(), 533 'fields' => inject_form_variables($fields_domain_ldap_edit, (isset($domain) ? $domain : array())) 534 )); 535 536 html_end_box(true, true); 537 } 538 539 ?> 540 <script type='text/javascript'> 541 function initGroupMember() { 542 if ($('#group_require').is(':checked')) { 543 $('#row_group_header').show(); 544 $('#row_group_dn').show(); 545 $('#row_group_attrib').show(); 546 $('#row_group_member_type').show(); 547 } else { 548 $('#row_group_header').hide(); 549 $('#row_group_dn').hide(); 550 $('#row_group_attrib').hide(); 551 $('#row_group_member_type').hide(); 552 } 553 } 554 555 function initSearch() { 556 switch($('#mode').val()) { 557 case '0': 558 $('#row_search_base_header').hide(); 559 $('#row_search_base').hide(); 560 $('#row_search_filter').hide(); 561 $('#row_specific_dn').hide(); 562 $('#row_specific_password').hide(); 563 $('#row_cn_full_name').hide(); 564 $('#row_cn_email').hide(); 565 break; 566 case '1': 567 $('#row_search_base_header').show(); 568 $('#row_search_base').show(); 569 $('#row_search_filter').show(); 570 $('#row_specific_dn').hide(); 571 $('#row_specific_password').hide(); 572 $('#row_cn_full_name').hide(); 573 $('#row_cn_email').hide(); 574 break; 575 case '2': 576 $('#row_search_base_header').show(); 577 $('#row_search_base').show(); 578 $('#row_search_filter').show(); 579 $('#row_specific_dn').show(); 580 $('#row_specific_password').show(); 581 $('#row_cn_full_name').show(); 582 $('#row_cn_email').show(); 583 break; 584 } 585 } 586 587 $(function() { 588 initSearch(); 589 initGroupMember(); 590 591 $('#mode').change(function() { 592 initSearch(); 593 }); 594 595 $('#group_require').change(function() { 596 initGroupMember(); 597 }); 598 }); 599 </script> 600 <?php 601 602 form_save_button('user_domains.php', 'return', 'domain_id'); 603} 604 605function domains() { 606 global $domain_types, $actions, $item_rows; 607 608 /* ================= input validation and session storage ================= */ 609 $filters = array( 610 'rows' => array( 611 'filter' => FILTER_VALIDATE_INT, 612 'pageset' => true, 613 'default' => '-1' 614 ), 615 'page' => array( 616 'filter' => FILTER_VALIDATE_INT, 617 'default' => '1' 618 ), 619 'filter' => array( 620 'filter' => FILTER_DEFAULT, 621 'pageset' => true, 622 'default' => '' 623 ), 624 'sort_column' => array( 625 'filter' => FILTER_CALLBACK, 626 'default' => 'domain_name', 627 'options' => array('options' => 'sanitize_search_string') 628 ), 629 'sort_direction' => array( 630 'filter' => FILTER_CALLBACK, 631 'default' => 'ASC', 632 'options' => array('options' => 'sanitize_search_string') 633 ) 634 ); 635 636 validate_store_request_vars($filters, 'sess_domains'); 637 /* ================= input validation ================= */ 638 639 if (get_request_var('rows') == '-1') { 640 $rows = read_config_option('num_rows_table'); 641 } else { 642 $rows = get_request_var('rows'); 643 } 644 645 html_start_box( __('User Domains'), '100%', '', '3', 'center', 'user_domains.php?action=edit'); 646 647 ?> 648 <tr class='even' class='noprint'> 649 <td class='noprint'> 650 <form id='form_domains' method='get' action='user_domains.php'> 651 <table class='filterTable'> 652 <tr class='noprint'> 653 <td> 654 <?php print __('Search');?> 655 </td> 656 <td> 657 <input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'> 658 </td> 659 <td> 660 <?php print __('Domains');?> 661 </td> 662 <td> 663 <select id='rows' onChange="applyFilter()"> 664 <option value='-1'<?php print (get_request_var('rows') == '-1' ? ' selected>':'>') . __('Default');?></option> 665 <?php 666 if (cacti_sizeof($item_rows)) { 667 foreach ($item_rows as $key => $value) { 668 print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . html_escape($value) . "</option>\n"; 669 } 670 } 671 ?> 672 </select> 673 </td> 674 <td> 675 <span> 676 <input type='button' class='ui-button ui-corner-all ui-widget' id='refresh' value='<?php print __x('filter: use', 'Go');?>' title='<?php print __esc('Set/Refresh Filters');?>'> 677 <input type='button' class='ui-button ui-corner-all ui-widget' id='clear' value='<?php print __esc('Clear');?>' title='<?php print __esc('Clear Filters');?>'> 678 </span> 679 </td> 680 </tr> 681 </table> 682 </form> 683 <script type='text/javascript'> 684 function applyFilter() { 685 strURL = 'user_domains.php?rows=' + $('#rows').val(); 686 strURL += '&filter=' + $('#filter').val(); 687 strURL += '&header=false'; 688 loadPageNoHeader(strURL); 689 } 690 691 function clearFilter() { 692 strURL = 'user_domains.php?clear=1&header=false'; 693 loadPageNoHeader(strURL); 694 } 695 696 $(function() { 697 $('#refresh').click(function() { 698 applyFilter(); 699 }); 700 701 $('#clear').click(function() { 702 clearFilter(); 703 }); 704 705 $('#form_domains').submit(function(event) { 706 event.preventDefault(); 707 applyFilter(); 708 }); 709 }); 710 </script> 711 </td> 712 </tr> 713 <?php 714 715 html_end_box(); 716 717 /* form the 'where' clause for our main sql query */ 718 if (get_request_var('filter') != '') { 719 $sql_where = 'WHERE 720 domain_name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' 721 OR type LIKE ' . db_qstr('%' . get_request_var('filter') . '%'); 722 } else { 723 $sql_where = ''; 724 } 725 726 $total_rows = db_fetch_cell("SELECT 727 count(*) 728 FROM user_domains 729 $sql_where"); 730 731 $domains = db_fetch_assoc("SELECT * 732 FROM user_domains 733 $sql_where 734 ORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' 735 LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows); 736 737 $nav = html_nav_bar('user_user_domains.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('User Domains'), 'page', 'main'); 738 739 form_start('user_domains.php', 'chk'); 740 741 print $nav; 742 743 html_start_box('', '100%', '', '3', 'center', ''); 744 745 $display_text = array( 746 'domain_name' => array(__('Domain Name'), 'ASC'), 747 'type' => array(__('Domain Type'), 'ASC'), 748 'defdomain' => array(__('Default'), 'ASC'), 749 'user_id' => array(__('Effective User'), 'ASC'), 750 'cn_full_name' => array(__('CN FullName'), 'ASC'), 751 'cn_email' => array(__('CN eMail'), 'ASC'), 752 'enabled' => array(__('Enabled'), 'ASC')); 753 754 html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); 755 756 $i = 0; 757 if (cacti_sizeof($domains)) { 758 foreach ($domains as $domain) { 759 /* hide system types */ 760 form_alternate_row('line' . $domain['domain_id'], true); 761 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']); 762 form_selectable_cell($domain_types[$domain['type']], $domain['domain_id']); 763 form_selectable_cell(($domain['defdomain'] == '0' ? '--': __('Yes') ), $domain['domain_id']); 764 form_selectable_ecell(($domain['user_id'] == '0' ? __('None Selected') : db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array($domain['user_id']))), $domain['domain_id']); 765 form_selectable_ecell(db_fetch_cell_prepared('SELECT cn_full_name FROM user_domains_ldap WHERE domain_id = ?', array($domain['domain_id'])), $domain['domain_id']); 766 form_selectable_ecell(db_fetch_cell_prepared('SELECT cn_email FROM user_domains_ldap WHERE domain_id = ?', array($domain['domain_id'])), $domain['domain_id']); 767 form_selectable_cell($domain['enabled'] == 'on' ? __('Yes'):__('No'), $domain['domain_id']); 768 form_checkbox_cell($domain['domain_name'], $domain['domain_id']); 769 form_end_row(); 770 } 771 } else { 772 print '<tr><td colspan="' . (cacti_sizeof($display_text)+1) . '"><em>' . __('No User Domains Found') . '</em></td></tr>'; 773 } 774 775 html_end_box(false); 776 777 if (cacti_sizeof($domains)) { 778 print $nav; 779 } 780 781 /* draw the dropdown containing a list of available actions for this form */ 782 draw_actions_dropdown($actions); 783 784 form_end(); 785} 786