function _gui_monitor_which_peers_lvm($sudo_user) { $kks = @_get_kostenstellen_lvm($sudo_user); if ($kks === false || !is_array($kks)) { return false; } $kostenstelle_prop = 'lvmkostenstelle'; $limit = 100; $filter = ''; foreach ($kks as $ks) { $filter .= '(' . $kostenstelle_prop . '=' . subStr($ks, 0, 2) . '*)'; } $filter = '(|' . $filter . ')'; //echo $filter, "<br />\n"; $ldap = gs_ldap_connect(); $matches = gs_ldap_get_list($ldap, GS_LDAP_SEARCHBASE, $filter, array(GS_LDAP_PROP_USER), (int) $limit); if (isGsError($matches)) { return false; } if (!is_array($matches)) { return false; } /* echo "<pre>"; print_r($matches); echo "</pre>"; */ $lc_GS_LDAP_PROP_USER = strToLower(GS_LDAP_PROP_USER); $peers = array(); foreach ($matches as $match) { if (!is_array($match[$lc_GS_LDAP_PROP_USER])) { continue; } foreach ($match[$lc_GS_LDAP_PROP_USER] as $mm) { //if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) { // this check is not really needed as this is a custom function anyway $mm = str_pad($mm, 6, '0', STR_PAD_LEFT); # without leading "0" in their LDAP database //} $peers[] = $mm; } } /* echo "<pre>"; print_r($peers); echo "</pre>"; */ return $peers; }
function gs_ldap_user_search($user) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } $GS_LDAP_HOST = gs_get_conf('GS_LDAP_HOST'); if (in_array($GS_LDAP_HOST, array(null, false, '', '0.0.0.0'), true)) { return new GsError('LDAP not configured.'); } if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $GS_LDAP_HOST)) { $tmp = getHostByName($GS_LDAP_HOST); if ($tmp == $GS_LDAP_HOST) { return new GsError('Failed to look up LDAP server.'); } $GS_LDAP_HOST = $tmp; } $tmp = @ip2long($GS_LDAP_HOST); if (in_array($tmp, array(false, null, -1, 0), true)) { return new GsError('LDAP not configured (bad IP address).'); } if (!($ldap_conn = gs_ldap_connect($GS_LDAP_HOST))) { return new GsError('Could not connect to LDAP server.'); } $req_props = array(); $GS_LDAP_PROP_FIRSTNAME = trim(gs_get_conf('GS_LDAP_PROP_FIRSTNAME')); $GS_LDAP_PROP_LASTNAME = trim(gs_get_conf('GS_LDAP_PROP_LASTNAME')); $GS_LDAP_PROP_EMAIL = trim(gs_get_conf('GS_LDAP_PROP_EMAIL')); $GS_LDAP_PROP_PHONE = trim(gs_get_conf('GS_LDAP_PROP_PHONE')); if ($GS_LDAP_PROP_FIRSTNAME != '') { $req_props[] = $GS_LDAP_PROP_FIRSTNAME; } if ($GS_LDAP_PROP_LASTNAME != '') { $req_props[] = $GS_LDAP_PROP_LASTNAME; } if ($GS_LDAP_PROP_EMAIL != '') { $req_props[] = $GS_LDAP_PROP_EMAIL; } if ($GS_LDAP_PROP_PHONE != '') { $req_props[] = $GS_LDAP_PROP_PHONE; } $users_arr = gs_ldap_get_list($ldap_conn, gs_get_conf('GS_LDAP_SEARCHBASE'), gs_get_conf('GS_LDAP_PROP_USER') . '=' . $user, $req_props, 2); //print_r($users_arr); @gs_ldap_disconnect($ldap_conn); if (isGsError($users_arr)) { return $users_arr; } if (!is_array($users_arr) || count($users_arr) < 1) { return new GsError('User "' . $user . '" not found in LDAP.'); } if (count($users_arr) > 1) { return new GsError('LDAP search did not return a unique user for "' . $user . '".'); } $user_arr = $users_arr[0]; unset($users_arr); $user_info = array('fn' => null, 'ln' => null, 'email' => null, 'exten' => null); if (array_key_exists($GS_LDAP_PROP_FIRSTNAME, $user_arr)) { $user_info['fn'] = @$user_arr[$GS_LDAP_PROP_FIRSTNAME][0]; } if (array_key_exists($GS_LDAP_PROP_LASTNAME, $user_arr)) { $user_info['ln'] = @$user_arr[$GS_LDAP_PROP_LASTNAME][0]; } if (array_key_exists($GS_LDAP_PROP_EMAIL, $user_arr)) { $user_info['email'] = @$user_arr[$GS_LDAP_PROP_EMAIL][0]; } if (array_key_exists($GS_LDAP_PROP_PHONE, $user_arr)) { require_once GS_DIR . 'inc/canonization.php'; $phone = @$user_arr[$GS_LDAP_PROP_PHONE][0]; $phone = preg_replace('/[^0-9+#*]/', '', $phone); $cpn = new CanonicalPhoneNumber($phone); if ($cpn->in_prv_branch) { $user_info['exten'] = $cpn->extn; } unset($cpn); } unset($user_arr); gs_log(GS_LOG_DEBUG, 'Found user "' . $user . '" (' . trim($user_info['fn'] . ' ' . $user_info['ln']) . ') in LDAP'); return $user_info; }
function gs_ldap_get_first($ldap_conn, $base, $filter = '', $props = array()) { $list = gs_ldap_get_list($ldap_conn, $base, $filter, $props, 1); if (isGsError($list)) { return new GsError($list->getMsg()); } if (!is_array($list)) { return new GsError('Failed to get LDAP entries.'); } return reset($list); }
$has_more = !isGsError($results) && count($results) > $per_page; if ($has_more) { unset($results[count($results) - 1]); } } else { # search by name $number = ''; $search_url = '&name=' . urlEncode($name); $name_filter = str_replace(array('?'), array('*'), str_replace(array('(', ')', '\\', ""), array('\\28', '\\29', '\\5c', '\\00'), $name)) . '*'; $name_filter = preg_replace('/[*]+/', '*', $name_filter); $ldap = gs_ldap_connect(); if (!$ldap) { echo __('Could not connect to LDAP server.'); $results = array(); } else { $results = gs_ldap_get_list($ldap, GS_LDAP_SEARCHBASE, '(|(' . GS_LDAP_PROP_LASTNAME . '=' . $name_filter . ')' . '(' . GS_LDAP_PROP_FIRSTNAME . '=' . $name_filter . '))', array(GS_LDAP_PROP_LASTNAME, GS_LDAP_PROP_FIRSTNAME, GS_LDAP_PROP_PHONE), $per_page + 1); } $has_more = !isGsError($results) && count($results) > $per_page; if ($has_more) { unset($results[count($results) - 1]); } } ?> <table cellspacing="1" class="phonebook"> <thead> <tr> <th style="width:270px;"><?php echo __('Name suchen'); ?> </th>