server, $new_suff[$i], "", array()); $res = @ldap_get_entries($_SESSION['ldap']->server, $info); if ($res) continue; $suff = $new_suff[$i]; // generate DN and attributes $tmp = explode(",", $suff); $name = explode("=", $tmp[0]); array_shift($tmp); $end = implode(",", $tmp); if ($name[0] != "ou") { // add root entry $attr = array(); $attr[$name[0]] = $name[1]; $attr['objectClass'] = 'organization'; $dn = $suff; if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) { $fail[] = $suff; continue; } } else { // add organizational unit $name = $name[1]; $attr = array(); $attr['objectClass'] = "organizationalunit"; $attr['ou'] = $name; $dn = $suff; if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) { // check if we have to add parent entries if (ldap_errno($_SESSION['ldap']->server()) == 32) { $temp = explode(",", $suff); $subsuffs = array(); // make list of subsuffixes for ($k = 0; $k < sizeof($temp); $k++) { $part = explode("=", $temp[$k]); if ($part[0] == "ou") $subsuffs[] = implode(",", array_slice($temp, $k)); else { $subsuffs[] = implode(",", array_slice($temp, $k)); break; } } // create missing entries for ($k = sizeof($subsuffs) - 1; $k >= 0; $k--) { // check if subsuffix is present $info = @ldap_search($_SESSION['ldap']->server, $subsuffs[$k], "", array()); $res = @ldap_get_entries($_SESSION['ldap']->server, $info); if (!$res) { $suffarray = explode(",", $subsuffs[$k]); $headarray = explode("=", $suffarray[0]); if ($headarray[0] == "ou") { // add ou entry $attr = array(); $attr['objectClass'] = 'organizationalunit'; $attr['ou'] = $headarray[1]; $dn = $subsuffs[$k]; if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) { $fail[] = $suff; $error[] = ldap_error($_SESSION['ldap']->server()); break; } } else { // add root entry $attr = array(); $attr['objectClass'][] = 'organization'; $attr[$headarray[0]] = $headarray[1]; if ($headarray[0] == "dc") { $attr['o'] = $headarray[1]; $attr['objectClass'][] = 'dcObject'; } $dn = $subsuffs[$k]; if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) { $fail[] = $suff; $error[] = ldap_error($_SESSION['ldap']->server()); break; } } } } } else { $fail[] = $suff; $error[] = ldap_error($_SESSION['ldap']->server()); } } } } } echo $_SESSION['header']; echo "initsuff\n"; echo "\n"; echo "\n\n"; // print error/success messages if ($_POST['add_suff']) { if (sizeof($fail) > 0) { // print error messages for ($i = 0; $i < sizeof($fail); $i++) { StatusMessage("ERROR", _("Failed to create entry!") . "
" . $error[$i], $fail[$i]); } echo "

 

\n"; echo "" . _("User list") . "\n"; echo "\n"; } else { // print success message StatusMessage("INFO", "", _("All changes were successful.")); if ($_SESSION['config']->is_samba3()) { $doms = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix()); echo "

 

\n"; if (sizeof($doms) == 0) { echo "" . _("No domains found, please create one.") . "\n"; } else { echo "" . _("User list") . "\n"; } echo "\n"; } else { echo "

 

\n"; echo "" . _("User list") . "\n"; echo "\n"; } } } else { // no suffixes were created StatusMessage("INFO", "", _("No changes were made.")); echo "

 

\n"; echo "" . _("User list") . "\n"; echo "\n"; } exit; } // first show of page $new_suff = $_GET['suffs']; $new_suff = str_replace("\\", "", $new_suff); $new_suff = str_replace("'", "", $new_suff); $new_suff = explode(";", $new_suff); echo $_SESSION['header']; echo "initsuff\n"; echo "\n"; echo "\n"; echo "

 

\n"; echo "

" . _("The following suffix(es) are missing in LDAP. LAM can create them for you.") . "

\n"; echo "

 

\n"; // print missing suffixes for ($i = 0; $i < sizeof($new_suff); $i++) { echo "

" . $new_suff[$i] . "

\n"; } echo "

 

\n"; echo "
\n"; echo "\n"; echo ""; echo ""; echo "
\n"; echo "\n"; ?>