refactoring

This commit is contained in:
Roland Gruber 2017-10-24 20:48:34 +02:00
parent 8629b5d867
commit f1decc1f4c
9 changed files with 21 additions and 19 deletions

View File

@ -239,7 +239,7 @@ if (isset($_POST['delete'])) {
if (!$stopprocessing) {
// modify attributes
if (isset($attributes[$dn]['modify']) && !$stopprocessing) {
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes[$dn]['modify']);
$success = ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes[$dn]['modify']);
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
$stopprocessing = true;
@ -248,7 +248,7 @@ if (isset($_POST['delete'])) {
}
// add attributes
if (isset($attributes[$dn]['add']) && !$stopprocessing) {
$success = @ldap_mod_add($_SESSION['ldap']->server(), $dn, $attributes[$dn]['add']);
$success = ldap_mod_add($_SESSION['ldap']->server(), $dn, $attributes[$dn]['add']);
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
$stopprocessing = true;
@ -257,7 +257,7 @@ if (isset($_POST['delete'])) {
}
// remove attributes
if (isset($attributes[$dn]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes[$dn]['remove']);
$success = ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes[$dn]['remove']);
if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
$stopprocessing = true;

View File

@ -48,7 +48,7 @@ if (!empty($_GET['selfService']) && ($_GET['selfService'] === '1')) {
if (strtolower(session_module_name()) == 'files') {
session_save_path("../sess");
}
@session_start();
session_start();
/** status messages */
include_once("../lib/status.inc");

View File

@ -63,8 +63,8 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
// add entries
foreach ($newSuffixes as $newSuffix) {
// check if entry is already present
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($newSuffix), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = @ldap_get_entries($_SESSION['ldap']->server(), $info);
$info = ldap_read($_SESSION['ldap']->server(), escapeDN($newSuffix), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = ldap_get_entries($_SESSION['ldap']->server(), $info);
if ($res) continue;
$suff = $newSuffix;
// generate DN and attributes
@ -106,8 +106,8 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
// create missing entries
for ($k = sizeof($subsuffs) - 1; $k >= 0; $k--) {
// check if subsuffix is present
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($subsuffs[$k]), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = @ldap_get_entries($_SESSION['ldap']->server(), $info);
$info = ldap_read($_SESSION['ldap']->server(), escapeDN($subsuffs[$k]), "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = ldap_get_entries($_SESSION['ldap']->server(), $info);
if (!$res) {
$suffarray = explode(",", $subsuffs[$k]);
$headarray = explode("=", $suffarray[0]);

View File

@ -604,9 +604,9 @@ if(!empty($_POST['checklogin'])) {
$searchError = _('Cannot connect to specified LDAP server. Please try again.') . ' ' . getDefaultLDAPErrorString($searchLDAP->server());
}
else {
$searchResult = @ldap_search($searchLDAP->server(), $_SESSION['config']->getLoginSearchSuffix(), $searchFilter, array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
$searchResult = ldap_search($searchLDAP->server(), $_SESSION['config']->getLoginSearchSuffix(), $searchFilter, array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($searchResult) {
$searchInfo = @ldap_get_entries($searchLDAP->server(), $searchResult);
$searchInfo = ldap_get_entries($searchLDAP->server(), $searchResult);
if ($searchInfo) {
cleanLDAPResult($searchInfo);
if (sizeof($searchInfo) == 0) {

View File

@ -51,7 +51,9 @@ if (isset($_SESSION['loggedIn']) || ($_SESSION['loggedIn'] === true)) {
logNewMessage(LOG_NOTICE, 'User ' . $ldapUser[0] . ' logged off.');
// close LDAP connection
@$_SESSION["ldap"]->destroy();
if (!empty($_SESSION["ldap"])) {
$_SESSION["ldap"]->destroy();
}
}
setlanguage();

View File

@ -50,8 +50,8 @@ $new_suffs = array();
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = @ldap_get_entries($_SESSION['ldap']->server(), $info);
$info = ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = ldap_get_entries($_SESSION['ldap']->server(), $info);
if (!$res && !in_array($type->getSuffix(), $new_suffs)) {
$new_suffs[] = $type->getSuffix();
}

View File

@ -516,7 +516,7 @@ function doModify() {
$success = false;
switch ($opType) {
case ADD:
$success = @ldap_mod_add($_SESSION['ldap']->server(), $dn, array($attr => array($val)));
$success = ldap_mod_add($_SESSION['ldap']->server(), $dn, array($attr => array($val)));
break;
case DEL:
if (empty($val)) {

View File

@ -103,7 +103,7 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
}
// delete ou, user was sure
elseif (isset($_POST['deleteOU']) && isset($_POST['sure'])) {
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['deletename']);
$ret = ldap_delete($_SESSION['ldap']->server(), $_POST['deletename']);
if ($ret) {
$message = _("OU deleted successfully.");
}
@ -114,8 +114,8 @@ if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
// ask if user is sure to delete
elseif (isset($_POST['deleteOU'])) {
// check for sub entries
$sr = @ldap_list($_SESSION['ldap']->server(), $_POST['deleteableOU'], "ObjectClass=*", array(""));
$info = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['deleteableOU'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($sr && $info['count'] == 0) {
// print header
include 'main_header.php';

View File

@ -50,9 +50,9 @@ $vendorname = '';
$vendorversion = '';
$dynamicSubtrees = '';
$result = @ldap_read($_SESSION['ldap']->server(), '', 'objectclass=*', array('+', '*', 'subschemasubentry'), 0, 0, 0, LDAP_DEREF_NEVER);
$result = ldap_read($_SESSION['ldap']->server(), '', 'objectclass=*', array('+', '*', 'subschemasubentry'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($result) {
$info = @ldap_get_entries($_SESSION['ldap']->server(), $result);
$info = ldap_get_entries($_SESSION['ldap']->server(), $result);
if ($info) {
$info = $info[0];
foreach ($info as $key => $value) {