function get_au_roles($audn) { global $ds, $userDN, $ldapError; $au_roles = array(); if (!($result = uniLdapSearch($ds, "cn=roles," . $audn, "(&(member={$userDN})(cn=*))", array("dn", "cn"), "cn", "list", 0, 0))) { redirect(5, "index.php", $ldapError, FALSE); die; } else { $result = ldapArraySauber($result); #print_r($result); foreach ($result as $item) { $au_roles[] = $item['cn']; } return $au_roles; } }
function get_dhcp_range2($dhcpobjectDN) { global $ds, $suffix, $ldapError; if (!($result = uniLdapSearch($ds, $dhcpobjectDN, "(objectclass=*)", array("dhcpRange"), "", "one", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; return 0; } else { $result = ldapArraySauber($result); $dhcp_array = array(); foreach ($result as $item) { if (count($item['dhcprange']) == 1) { $dhcp_array[] = $item['dhcprange']; } if (count($item['dhcprange']) > 1) { foreach ($item['dhcprange'] as $range) { $dhcp_array[] = $range; } } } return $dhcp_array; } }
function add_dhcppool($dhcpsubnetdn, $range, $pcl, $dhcpservicedn, $poolopt_domain, $rbssrvdn) { global $ds, $suffix, $auDN, $ldapError; if (!($result = uniLdapSearch($ds, "cn=dhcp," . $auDN, "(objectclass=*)", array("cn"), "dn", "list", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } $result = ldapArraySauber($result); $dhcpcn_array = array(); foreach ($result as $item) { $dhcpcn_array[] = $item['cn']; } #print_r($dhcpcn_array);echo "<br><br>"; for ($i = 0; $i < 100; $i++) { if (array_search("Pool" . $i, $dhcpcn_array) === false) { $cn = "Pool" . $i; break; } } $dhcppoolDN = "cn=" . $cn . ",cn=dhcp," . $auDN; $entrydhcp['objectclass'][0] = "dhcpPool"; $entrydhcp['objectclass'][1] = "dhcpOptions"; $entrydhcp['objectclass'][2] = "top"; $entrydhcp['cn'] = $cn; $entrydhcp['dhcphlpcont'] = $dhcpsubnetdn; $entrydhcp['dhcprange'] = $range; if ($pcl) { $entrydhcp['dhcppermittedclients'] = $pcl; } if ($poolopt_domain) { $entrydhcp['dhcpoptdomain-name'] = $poolopt_domain; } if ($rbssrvdn) { $entrydhcp['hlprbservice'] = $rbssrvdn; } #print_r($dhcppoolDN);echo "<br><br>"; #print_r($entrydhcp);echo "<br><br>"; if ($result = ldap_add($ds, $dhcppoolDN, $entrydhcp)) { #add_to_file_structure($dhcppoolDN); return 1; } else { return 0; } }
function get_node_data($nodeDN, $attributes) { global $ds, $suffix, $ldapError; $node_data = array(); if (!($result = uniLdapSearch($ds, $nodeDN, "(objectclass=*)", $attributes, "", "one", 0, 0))) { # redirect(5, "", $ldapError, FALSE); # redirect(0, $START_PATH."/au/au.php", "", TRUE); echo "no search"; die; } else { $result = ldapArraySauber($result); foreach ($result as $item) { foreach ($attributes as $att) { $node_data[$att] = $item[$att]; } } if ($attributes != false) { return $node_data; } else { return $result; } } }
function zone_exists($zonename) { global $ds, $suffix, $rootAU, $ldapError; if (!($result = uniLdapSearch($ds, $rootAU, "(&(objectclass=administrativeUnit)(associateddomain={$zonename}))", array("dn"), "", "sub", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } else { } }
function get_pool_subnet_data($dhcprange, $attributes) { global $ds, $suffix, $ldapError; $iprange = explode('_', $dhcprange); $fs = explode('.', $iprange[0]); $fe = explode('.', $iprange[1]); if ($fs[0] == $fe[0] && $fs[1] == $fe[1] && $fs[2] == $fe[2] && $fs[3] <= $fe[3]) { # DHCP Subnet DN finden $subnet = implode(".", array($fs[0], $fs[1], $fs[2], "0")); if (!($result = uniLdapSearch($ds, "ou=RIPM," . $suffix, "(&(objectclass=dhcpSubnet)(cn={$subnet}))", $attributes, "", "sub", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } $result = ldapArraySauber($result); #print_r($result);echo "<br><br>"; if (count($result[0]) != 0) { return $result[0]; } else { print "kein DHCP Subnet gefunden!<br><br>"; return 0; } } else { print "DHCP Range {$dhcprange} nicht korrekt!<br><br>"; return 0; } }
function get_role_members($roleDN) { global $ds, $suffix, $ldapError; if (!($result = uniLdapSearch($ds, $roleDN, "objectclass=*", array("member"), "", "one", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "search problem"; die; } else { $members_array = array(); $result = ldapArraySauber($result); foreach ($result as $item) { if (count($item['member']) > 1) { $members_array = $item['member']; } else { $members_array[] = $item['member']; } } } return $members_array; }
function getRoles2($ds, $userDN) { global $ldapError, $suffix, $uid; if (!($result = uniLdapSearch($ds, "ou=RIPM," . $suffix, "(&(member={$userDN})(cn=*))", array("dn", "cn"), "dn", "sub", 0, 0))) { redirect(5, "index.php", $ldapError, FALSE); die; } else { $result = ldapArraySauber($result); $au_roles = array(); foreach ($result as $item) { $dn = ldap_explode_dn($item['dn'], 0); $dnsub = array_slice($dn, 3); $auDN = implode(',', $dnsub); if (array_key_exists($auDN, $au_roles)) { if (!in_array($item['cn'], $au_roles[$auDN])) { $au_roles[$auDN][] = $item['cn']; } } else { $au_roles[$auDN][] = $item['cn']; } } } return $au_roles; }
function adjust_gbm_dn($newgbmDN, $gbmDN) { global $ds, $suffix, $auDN, $ldapError; if (!($result = uniLdapSearch($ds, "ou=RIPM," . $suffix, "(&(objectclass=MenuEntry)(genericmenuentrydn={$gbmDN}))", array("dn"), "dn", "sub", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } $result = ldapArraySauber($result); $modentry['genericmenuentrydn'] = $newgbmDN; foreach ($result as $item) { ldap_mod_replace($ds, $item['dn'], $modentry); } }
function get_entry_number($entryDN, $entryobjectclass) { global $ds, $suffix, $ldapError; if (!($result = uniLdapSearch($ds, $entryDN, "(objectclass=machineconfig)", array("count"), "", "one", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } $result = ldapArraySauber($result); print_r($result); }
/** * userLogin($uid, $userPassword) - Führt den Login am LSM-LDAP durch. * * Nach erfolgreicher Identifikation und ggf. neuem Anlegen oder Datenabgleich wird * mit userLogin() der Bind am LSM-LDAP durchgeführt. * Die Rechte und der CN des Users werden ausgelesen und in der Session gespeichert. * Anschließend leitet das Skript auf die Startseite (start.php) weiter. * * @param string UID * @param string Password */ function userLogin($uid, $userPassword) { global $userDN, $suffix, $ldapError; # Verbindung mit der Datenbank herstellen if ($uid == "" || $userPassword == "" || !($ds = uniLdapConnect($uid, $userPassword))) { redirect(3, "index.php", "Falscher Login<br>" . $ldapError, FALSE); die; } # cn abfragen if (!($person_daten = uniLdapSearch($ds, "ou=people," . $suffix, "uid={$uid}", array("cn"), "", "list", 0, 0))) { redirect(3, "index.php", $ldapError, FALSE); die; } else { $cn = str_replace('\\"', '', $person_daten[0]['cn'][0]); } # Speichern der Sessionvariablen $_SESSION['uid'] = $uid; $_SESSION['userPassword'] = $userPassword; $_SESSION['dn'] = $userDN; $_SESSION['cn'] = $cn; $_SESSION['audn'] = ""; $_SESSION['status'] = "in"; $_SESSION['error']; # LDAP-Bind aufheben ldap_unbind($ds); $mesg = "<html>\n\t\t\t\t<head>\n\t\t\t\t\t<title>AdminUnit Management</title>\n\t\t\t\t\t<link rel='stylesheet' href='styles.css' type='text/css'>\n\t\t\t\t</head>\n\t\t\t\t<body>\n\t\t\t\t<table border='0' cellpadding='200' cellspacing='0' width='100%'> \n\t\t\t\t<tr valign='middle'><td align='center'>\n\t \t\t\t<h3>Bitte einen Moment Geduld, die Seite wird geladen ... <br>\n\t \t\t\tFalls nicht, klicken Sie bitte <a href='start.php'>hier</a>.<h3>\n\t \t\t\t</td></tr>\n\t \t\t\t</table>\n\t \t\t\t</body>\n\t\t\t\t</html>"; # Redirect auf die Startseite: redirect(2, "start.php", $mesg, TRUE); }
$result = ldapArraySauber($result); if (count($result) > 0) { echo "Folgende Menü Einträge sind davon betroffen: <br><br>"; foreach ($result as $item) { $exp = ldap_explode_dn($item['dn'], 1); echo "Menü Eintrag <b>" . $exp[0] . "</b> in PXE Bootmenü <b>" . $exp[1] . "</b> [ Abteilung: " . $exp[4] . " ]<br>"; } } else { echo "Keine Menü Einträge davon betroffen!<br>"; } } } if ($type == "rbs") { $rbsDN = $dn; $attribs = array("dn"); if (!($result = uniLdapSearch($ds, "ou=RIPM," . $suffix, "(&(objectclass=PXEConfig)(rbservicedn={$rbsDN}))", $attribs, "dn", "sub", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } else { $result = ldapArraySauber($result); if (count($result) > 0) { echo "Folgende PXE Boot Menüs sind davon betroffen: <br><br>"; foreach ($result as $item) { $exp = ldap_explode_dn($item['dn'], 1); echo "PXE Boot Menü <b>" . $exp[0] . "</b> an Objekt <b>" . $exp[1] . "</b> [ Abteilung: " . $exp[3] . " ]<br>"; } } else { echo "Keine PXE Boot Menüs davon betroffen!<br>"; } }
<?php include '../standard_header.inc.php'; #$dhcpdn = $_POST['dhcpdn']; $dhcpdn = $DHCP_SERVICE; #$dhcpdn = "cn=DHCP_RZ,cn=dhcp,ou=Rechenzentrum,ou=UniFreiburg,ou=RIPM,dc=uni-freiburg,dc=de"; $seconds = 200; $url = "dhcpservice.php?dn=" . $dhcpdn; echo "\n<html>\n<head>\n\t<title>Computers Management</title>\n\t<link rel='stylesheet' href='../styles.css' type='text/css'>\n</head>\n<body>\n<table border='0' cellpadding='30' cellspacing='0'> \n<tr><td>"; ############################################## # DHCP Service CN (DN) $filter = "(&(|(objectClass=dhcpSubnet)(objectclass=dhcpHost))(dhcphlpcont=*))"; if (!($result = uniLdapSearch($ds, "ou=RIPM," . $suffix, $filter, array("dn"), "dn", "sub", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } $result = ldapArraySauber($result); $modentry['dhcphlpcont'] = $dhcpdn; $number = count($result); echo "Number of DHCP Entries: {$number}<br><br>"; foreach ($result as $item) { $modres = ldap_mod_replace($ds, $item['dn'], $modentry); if ($modres) { echo "changed {$item['dn']}<br>"; } else { echo "<b>ERROR</b> changing {$item['dn']}<br>"; } } /* # alle hosts ohne hwaddress in dhcpservice (alle host die nicht in dhcp sein dürften ...)
$pcl = $_POST['pcl']; $unknownclients = $_POST['unknownclients']; $rbs = ""; $mnr = $_POST['mnr']; $poolopt_domain = ""; $seconds = 2; $url = "dhcppools.php?mnr=" . $mnr; echo "\n<html>\n<head>\n\t<title>Computers Management</title>\n\t<link rel='stylesheet' href='../styles.css' type='text/css'>\n</head>\n<body>\n<table border='0' cellpadding='30' cellspacing='0'> \n<tr><td>"; if ($syntax->check_ip_syntax($range1) && $syntax->check_ip_syntax($range2)) { $fs = explode('.', $range1); $fe = explode('.', $range2); if ($fs[0] == $fe[0] && $fs[1] == $fe[1] && $fs[2] == $fe[2]) { if ($fs[3] <= $fe[3]) { # DHCP Subnet DN finden $subnet = implode(".", array($fs[0], $fs[1], $fs[2], "0")); if (!($result = uniLdapSearch($ds, "ou=RIPM," . $suffix, "(&(objectclass=dhcpSubnet)(cn={$subnet}))", array("dn", "dhcphlpcont"), "", "sub", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } $result = ldapArraySauber($result); #print_r($result);echo "<br><br>"; if (count($result[0]) != 0) { $subnetdn = $result[0]['dn']; $subnetau = get_audn_of_objectdn($subnetdn); $subnet_data = get_node_data($subnetdn, array("dhcpoptdomain-name")); if ($subnet_data['dhcpoptdomain-name'] != $assocdom) { $poolopt_domain = $assocdom; echo "Pool spezifische Option <b>domain-name</b> auf <b>" . $assocdom . "</b> gesetzt<br>"; } # Range zusammenstellen