diff options
| author | Tarik Gasmi | 2007-07-31 09:29:53 +0200 |
|---|---|---|
| committer | Tarik Gasmi | 2007-07-31 09:29:53 +0200 |
| commit | c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd (patch) | |
| tree | 974eb0c95d0ff2678439b161246433cde972564d /ldap-site-mngmt/webinterface/lib | |
| parent | * more work towards Debian & Ubuntu support, Debian-4.0, Ubuntu-6.10 (diff) | |
| download | core-c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd.tar.gz core-c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd.tar.xz core-c7b4e4a81d7f38c0f1f927f6804ef281c4f67dcd.zip | |
Actualized LDAP SiteManagement Code - Web Interface, DHCP Generationscript
git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1284 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'ldap-site-mngmt/webinterface/lib')
6 files changed, 439 insertions, 44 deletions
diff --git a/ldap-site-mngmt/webinterface/lib/commonlib.inc.php b/ldap-site-mngmt/webinterface/lib/commonlib.inc.php index 32df2a1c..7fb68395 100644 --- a/ldap-site-mngmt/webinterface/lib/commonlib.inc.php +++ b/ldap-site-mngmt/webinterface/lib/commonlib.inc.php @@ -171,11 +171,13 @@ function getRoles($ds, $userDN) { */ function createMainMenu($rollen , $mainnr) { - global $template; - global $START_PATH; + + global $template, $START_PATH, $auDN; - # pre-checks - if ( check_if_max_networks() ){ + # pre-checks + $mipbs = get_maxipblocks_au($auDN); + #echo "MIPB: "; print_r ($mipbs); echo "<br>"; + if ($mipbs[0] != ""){ $dhcplink = "dhcp/dhcp.php"; }else{ $dhcplink = "dhcp/no_dhcp.php"; diff --git a/ldap-site-mngmt/webinterface/lib/config.inc.php b/ldap-site-mngmt/webinterface/lib/config.inc.php index 653cc262..e6dc17b1 100644 --- a/ldap-site-mngmt/webinterface/lib/config.inc.php +++ b/ldap-site-mngmt/webinterface/lib/config.inc.php @@ -10,12 +10,13 @@ # einige LDAP-Angaben: # der Anwendungs-LDAP - define('LDAP_HOST', 'ldap://oranje.ruf.uni-freiburg.de'); - #define('LDAP_HOST', 'ldaps://oranje.ruf.uni-freiburg.de'); + define('LDAP_HOST', 'ldap://foo.ruf.uni-freiburg.de'); + #define('LDAP_HOST', 'ldaps://foo.ruf.uni-freiburg.de'); define('LDAP_PORT', 389); #define('LDAP_PORT', 636); $suffix = "dc=uni-freiburg,dc=de"; $domsuffix = "uni-freiburg.de"; + $rootAU = "ou=UniFreiburg,ou=RIPM,dc=uni-freiburg,dc=de"; # der LDAP-Server für die Authentisierung der User #define('LDAP_HOST_RZ', '132.230.1.61'); @@ -26,5 +27,5 @@ #$dummyUid = "rz-ldap"; // Dummy-User für einige Aktionen - muss angelegt werden!!! #$dummyPassword = "dummy"; - #$standardPassword = "dipman02"; // das Passwort mit dem alle User im Anwendungsldap angelegt werden!!! + #$standardPassword = "..."; // das Passwort mit dem alle User im Anwendungsldap angelegt werden!!! ?> diff --git a/ldap-site-mngmt/webinterface/lib/dhcp_management_functions.php b/ldap-site-mngmt/webinterface/lib/dhcp_management_functions.php index 4194a1b3..fd939369 100644 --- a/ldap-site-mngmt/webinterface/lib/dhcp_management_functions.php +++ b/ldap-site-mngmt/webinterface/lib/dhcp_management_functions.php @@ -18,6 +18,22 @@ $ldapError = null; ################################################################################################### +# immer wenn ein DHCP Objekt geändert wird (DHCP modify time aktualisieren) +function update_dhcpmtime(){ + + global $ds, $auDN, $ldapError; + + $entry ['dhcpmtime'] = time(); + $results = ldap_mod_replace($ds,$auDN,$entry); + if ($results){ + echo "<br><b>dhcpMTime</b> erfolgreich aktualisiert!<br>" ; + return 1; + }else{ + echo "<br>Fehler beim Aktualisieren der <b>dhcpMTime</b>!<br>" ; + } +} + + # freie x.x.x.0/24 Netzwerke einer AU holen function get_networks(){ @@ -397,12 +413,11 @@ function alternative_dhcpobjects($objecttype,$objectDN,$ip){ # Funktionen zur Verwaltung von DHCP Subnet Objekten # -function add_dhcpsubnet ($cn,$dhcpservice,$netmask,$range1,$range2,$atts){ +function add_dhcpsubnet ($cn,$dhcpservice,$netmask,$atts){ global $ds, $suffix, $auDN, $ldapError; - $cnarray = array($cn,$cn); - $subnet = implode('_',$cnarray); + $subnet = implode('_',array($cn,$cn)); # IP checken und FIBS anpassen $fipb_array = get_freeipblocks_au($auDN); @@ -445,18 +460,21 @@ function add_dhcpsubnet ($cn,$dhcpservice,$netmask,$range1,$range2,$atts){ print_r($dhcpsubnetDN); echo "<br>"; if ($result = ldap_add($ds, $dhcpsubnetDN, $entrydhcp)){ - if ( check_ip_in_subnet($range1,$cn) && check_ip_in_subnet($range2,$cn)){ - $dhcprange = implode('_',array($range1,$range2)); - if ( $range = new_ip_dhcprange($dhcprange,$dhcpsubnetDN,$auDN) ){ - echo "DHCP Range <b>".$range1." - ".$range2."</b> erfolgreich im Subnetobjekt eingetragen"; - }else{ - echo "DHCP Range <b>".$range1." - ".$range2."</b> konnte nicht im Subnetobjekt eingetragen werden!"; - } - return 1; - }else{ - echo "DHCP Range nicht in Subnetz ".$cn." enthalten.<br>Keine DHCP Range angelegt.<br>"; - return 1; - } + printf("Subnet <b>%s / %s</b> erfolgreich eingetragen",$cn,$netmask); + return 1; + update_dhcpmtime(); + #if ( check_ip_in_subnet($range1,$cn) && check_ip_in_subnet($range2,$cn)){ + # $dhcprange = implode('_',array($range1,$range2)); + # if ( $range = new_ip_dhcprange($dhcprange,$dhcpsubnetDN,$auDN) ){ + # echo "DHCP Range <b>".$range1." - ".$range2."</b> erfolgreich im Subnetobjekt eingetragen"; + # }else{ + # echo "DHCP Range <b>".$range1." - ".$range2."</b> konnte nicht im Subnetobjekt eingetragen werden!"; + # } + # return 1; + #}else{ + # echo "DHCP Range nicht in Subnetz ".$cn." enthalten.<br>Keine DHCP Range angelegt.<br>"; + # return 1; + #} }else{ echo "<br>Fehler beim anlegen des DHCP Subnet Objekts!<br>"; return 0; @@ -485,6 +503,7 @@ function delete_dhcpsubnet($subnetDN,$cn){ $results = ldap_mod_add($ds,$auDN,$entry); if ($results){ merge_ipranges($auDN); + update_dhcpmtime(); return 1; }else{ return 0; @@ -536,6 +555,7 @@ function modify_subnet_dn($subnetDN,$newsubnetDN){ $results = ldap_mod_replace($ds,$auDN,$entry); if ($results){ merge_ipranges($auDN); + update_dhcpmtime(); echo "<br>FIPBs erfolgreich angepasst!<br>" ; return 1; }else{ @@ -550,7 +570,7 @@ function modify_subnet_dn($subnetDN,$newsubnetDN){ } } - +# wird eigentlich nicht benötigt wenn host deklarationen nicht in subnet scope sind ... function cleanup_del_dhcpsubnet ($dhcpsubnetDN){ global $ds, $suffix, $auDN, $ldapError; @@ -569,7 +589,7 @@ function cleanup_del_dhcpsubnet ($dhcpsubnetDN){ } - +# wird eigentlich nicht benötigt wenn host deklarationen nicht in subnet scope sind ... function adjust_dhcpsubnet_dn ($newdhcpsubnetDN,$dhcpsubnetDN){ global $ds, $suffix, $auDN, $ldapError; @@ -590,6 +610,7 @@ function adjust_dhcpsubnet_dn ($newdhcpsubnetDN,$dhcpsubnetDN){ # Nach Änderung der Host IP Adresse, überprüfen ob neue IP noch mit Subnet übereinstimmt # Falls keine Übereinstimmung mehr, dann Subnetzuordnung aus Host löschen. +# wird eigentlich nicht benötigt wenn host deklarationen nicht in subnet scope sind ... function adjust_hostip_dhcpsubnet($ip,$hostDN,$dhcphlpcont) { global $ds, $suffix, $auDN, $ldapError; @@ -622,4 +643,56 @@ function check_ip_in_subnet($ip,$subnet) { } if ($return) { return 1; }else{ return 0; } } + +######################### +# Pools +function add_dhcppool ($dhcpsubnetdn,$range,$unknownclients,$dhcpservicedn){ + + 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 ($unknownclients == "allow"){ + $entrydhcp ['dhcpoptallow'] = "unknown-clients"; + }elseif ($unknownclients == "ignore"){ + $entrydhcp ['dhcpoptignore'] = "unknown-clients"; + }else{ + $entrydhcp ['dhcpoptdeny'] = "unknown-clients"; + } + + print_r($dhcppoolDN);echo "<br><br>"; + print_r($entrydhcp);echo "<br><br>"; + + if ($result = ldap_add($ds,$dhcppoolDN,$entrydhcp)){ + return 1; + }else{return 0;} + + +} + + ?>
\ No newline at end of file diff --git a/ldap-site-mngmt/webinterface/lib/ip_management_functions.php b/ldap-site-mngmt/webinterface/lib/ip_management_functions.php index b4f4a733..b158e35b 100644 --- a/ldap-site-mngmt/webinterface/lib/ip_management_functions.php +++ b/ldap-site-mngmt/webinterface/lib/ip_management_functions.php @@ -93,11 +93,12 @@ function split_iprange($iprange1,$iprange2) if ($ipr3s <= $ipr3e){$iprange3 = long2ip($ipr3s)."_".long2ip($ipr3e); $ipranges[] = $iprange3;} if ($ipr4s <= $ipr4e){$iprange4 = long2ip($ipr4s)."_".long2ip($ipr4e); $ipranges[] = $iprange4;} + #echo "MATCH!<br>"; return $ipranges; } else { - echo "IPRange1 not in IPRange2: "; + #echo "IPRange1 not in IPRange2: "; return 0; } } @@ -246,6 +247,86 @@ function get_maxipblocks_au($auDN) return $mipb_array; } +# benutze IP Ranges (Rechner, Ranges, Delegs) +function get_used_ipblocks_au($auDN) +{ + global $ds, $suffix, $ldapError; + + $host_ips = array(); + $dhcps_ips = array(); + $dhcpr_ips = array(); + $deleg_ips = array(); + # Rechner IPs + if(!($result = uniLdapSearch($ds, "cn=computers,".$auDN, "(objectclass=Host)", array("IPAddress"), "", "list", 0, 0))) { + # redirect(5, "", $ldapError, FALSE); + echo "no search"; + die; + } else { + $result = ldapArraySauber($result); + foreach ($result as $item){ + if (count($item['ipaddress']) != 0){ + $host_ips [] = $item['ipaddress']; + } + } + } + echo "Rechner IPs:<br>"; print_r($host_ips); echo "<br><br>"; + + # DHCP Subnets + if(!($result = uniLdapSearch($ds, "cn=dhcp,".$auDN, "(objectclass=dhcpSubnet)", array("cn"), "", "list", 0, 0))) { + # redirect(5, "", $ldapError, FALSE); + echo "no search"; + die; + } else { + $result = ldapArraySauber($result); + foreach ($result as $item){ + $dhcps_ips [] = $item['cn']."_".$item['cn']; + } + } + echo "DHCP Subnets:<br>"; print_r($dhcps_ips); echo "<br><br>"; + + # DHCP Pool Ranges + if(!($result = uniLdapSearch($ds, "cn=dhcp,".$auDN, "(objectclass=dhcpPool)", array("dhcpRange"), "", "list", 0, 0))) { + # redirect(5, "", $ldapError, FALSE); + echo "no search"; + die; + } else { + $result = ldapArraySauber($result); + foreach ($result as $item){ + if (count($item['dhcprange']) > 1){ + foreach ($item['dhcprange'] as $range){ + $dhcpr_ips [] = $range; + } + } + elseif (count($item['dhcprange']) == 1){ + $dhcpr_ips [] = $item['dhcprange']; + } + } + } + echo "DHCP Pool Ranges:<br>"; print_r($dhcpr_ips); echo "<br><br>"; + + # Delegierte IPs + $childau_array = get_childau($auDN,array("dn","ou","maxipblock")); + #print_r($childau_array); + if (count($childau_array) != 0){ + foreach ($childau_array as $childau){ + if (count($childau['maxipblock']) > 1){ + foreach ($childau['maxipblock'] as $mipb){ + $deleg_ips [] = $mipb; + } + }elseif (count($childau['maxipblock']) == 1){ + $deleg_ips [] = $childau['maxipblock']; + } + } + } + echo "Delegiert IP Blocks:<br>"; print_r($deleg_ips); echo "<br><br>"; + + $used_ips = array_merge($host_ips, $dhcps_ips, $dhcpr_ips, $deleg_ips); + sort($used_ips); + $used_ips = merge_ipranges_array($used_ips); + + return $used_ips; +} + /** * get_host_ip($hostDN) @@ -316,6 +397,33 @@ function get_dhcp_range($dhcpobjectDN) } } +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; + } +} + /** * merge_ipranges($auDN) @@ -349,8 +457,8 @@ function merge_ipranges($auDN) } print_r($fipb_array);printf("<br>"); foreach ( $fipb_array as $item ){ - $entry ['FreeIPBlock'][] = $item; - } + $entry ['FreeIPBlock'][] = $item; + } $results = ldap_mod_replace($ds,$auDN,$entry); if ($results) echo "<br>FIPBs erfolgreich zusammengefasst!<br><br>" ; else echo "<br>Fehler beim eintragen der FIPBs!<br><br>"; @@ -376,6 +484,55 @@ function merge_ipranges($auDN) else echo "<br>Fehler beim eintragen der MIPBs!<br><br>"; } +function merge_dhcpranges($dhcpobjectDN) +{ + global $ds, $suffix, $ldapError; + + $dhcp_array = get_dhcp_range2($dhcpobjectDN); + if ( count($dhcp_array) > 1) sort($dhcp_array); + + $c = count($dhcp_array); + for ($i=0; $i < $c; $i++){ + for ($j=$i+1; $j < $c; $j++){ + if ( merge_2_ipranges($dhcp_array[$i],$dhcp_array[$j])){ + $dhcp_array[$i] = merge_2_ipranges($dhcp_array[$i],$dhcp_array[$j]); + array_splice($dhcp_array, $j, 1); + $c--; + $i=-1; + break; + } + } + } + foreach ( $dhcp_array as $item ){ + $entry ['dhcprange'][] = $item; + } + $results = ldap_mod_replace($ds,$dhcpobjectDN,$entry); + if ($results) echo "<br>DHCP Ranges erfolgreich zusammengefasst!<br><br>" ; + else echo "<br>Fehler beim eintragen der DHCP Ranges!<br><br>"; +} + +function merge_ipranges_array($ipranges_array) +{ + global $ds, $suffix, $ldapError; + + sort($ipranges_array); + $c = count($ipranges_array); + for ($i=0; $i < $c; $i++){ + for ($j=$i+1; $j < $c; $j++){ + if ( merge_2_ipranges($ipranges_array[$i],$ipranges_array[$j])){ + $ipranges_array[$i] = merge_2_ipranges($ipranges_array[$i],$ipranges_array[$j]); + array_splice($ipranges_array, $j, 1); + $c--; + $i=-1; + break; + } + } + } + return $ipranges_array; + # Rückgabewert ... +} + + /** * new_ip_host($ip,$hostDN,$auDN) @@ -454,7 +611,7 @@ function new_ip_dhcprange($ip,$dhcpobjectDN,$auDN) $fipb_array = get_freeipblocks_au($auDN); - print_r($fipb_array); + #print_r($fipb_array); for ($i=0; $i < count($fipb_array); $i++){ if ( split_iprange($ip,$fipb_array[$i]) != 0 ){ @@ -494,6 +651,55 @@ function new_ip_dhcprange($ip,$dhcpobjectDN,$auDN) } } +## Add Dhcprange in DHCP Pool +function add_dhcprange($newrange,$pooldn) { + + global $ds, $auDN, $suffix, $ldapError; + + # Freie IP Bereiche testen + $fipb_array = get_freeipblocks_au($auDN); + $test = 0; + for ($f=0; $f < count($fipb_array); $f++){ + if ( split_iprange($newrange,$fipb_array[$f]) != 0 ){ + $ipranges = split_iprange($newrange,$fipb_array[$f]); + array_splice($fipb_array, $f, 1, $ipranges); + $test = 1; + break; + } + } + if ( $test ){ + foreach ( $fipb_array as $item ){ + $entry ['FreeIPBlock'][] = $item; + } + $result1 = ldap_mod_replace($ds,$auDN,$entry); + if ($result1){ + echo "<br>Neue FIPBs erfolgreich eingetragen!<br>"; + $rangeentry ['dhcprange'] = $newrange; + print_r($rangeentry);echo "<br><br>"; + $result2 = ldap_mod_add($ds,$pooldn,$rangeentry); + if ($result2){ + merge_dhcpranges($pooldn); + #printf("Neue dynamische IP Range %s - %s erfolgreich in Subnetz %s0 eingetragen!<br>",$addrange1[$i],$addrange2[$i],$net); + return 1; + }else{ + # echo "<br>Fehler beim eintragen des dynamischen DHCP Pools!<br>"; + # Range wieder in FIPBs aufnehmen. + $entry2 ['FreeIPBlock'] = $newrange; + ldap_mod_add($ds,$auDN,$entry2); + merge_ipranges($auDN); + return 0; + } + }else{ + echo "<br>Fehler beim eintragen der FIPBs!<br>"; + return 0; + } + }else{ + printf("<br>IP Range %s ist nicht im verfuegbaren Bereich!<br>", $range ); + return 0; + } +} + + /** * delete_ip_host($hostDN,$auDN) * Löscht die IP Adresse eines Hosts, und passt die FreeIPBlocks der AU an. diff --git a/ldap-site-mngmt/webinterface/lib/ldap.inc.php b/ldap-site-mngmt/webinterface/lib/ldap.inc.php index 60a83e0d..292529a6 100644 --- a/ldap-site-mngmt/webinterface/lib/ldap.inc.php +++ b/ldap-site-mngmt/webinterface/lib/ldap.inc.php @@ -629,6 +629,58 @@ function get_dhcppools($auDN,$attributes) if($attributes != false ){return $pool_array;} else{return $result;} } +} + +function get_dhcppools_subnet($subnetDN,$attributes) +{ + global $ds, $suffix, $auDN, $ldapError; + + if(!($result = uniLdapSearch($ds, $auDN, "(&(objectclass=dhcpPool)(dhcphlpcont=$subnetDN))", $attributes, "cn", "sub", 0, 0))) { + # redirect(5, "", $ldapError, FALSE); + echo "no search"; + die; + } + else { + $result = ldapArraySauber($result); + + $pool_array = array(); + foreach ($result as $item){ + $poolexpdn = ldap_explode_dn($item['dn'], 1); + $poolau = $poolexpdn[2]; + foreach ($attributes as $att){ + $atts[$att] = $item[$att]; + } + $atts['poolAU'] = $poolau; + $pool_array[] = $atts; + } + if($attributes != false ){return $pool_array;} + else{return $result;} + } +} + +function get_dhcppoolranges($poolDN) +{ + global $ds, $suffix, $ldapError; + + if(!($result = uniLdapSearch($ds, $poolDN, "(objectclass=dhcpPool)", array("dhcprange"), "", "one", 0, 0))) { + # redirect(5, "", $ldapError, FALSE); + echo "no search"; + die; + } + else { + $result = ldapArraySauber($result); + #print_r($result); echo "<br><br>"; + $ranges_array = array(); + if ( count($result[0]['dhcprange']) == 1 ){ + $ranges_array [] = $result[0]['dhcprange']; + } + elseif ( count($result[0]['dhcprange']) > 1 ){ + foreach ($result[0]['dhcprange'] as $range){ + $ranges_array [] = $range; + } + } + return $ranges_array; + } } function get_childau($auDN,$attributes) @@ -999,4 +1051,5 @@ function get_service_subnets($dhcpserviceDN,$attributes) else{return $result;} } } + ?> diff --git a/ldap-site-mngmt/webinterface/lib/rbs_management_functions.php b/ldap-site-mngmt/webinterface/lib/rbs_management_functions.php index cc73595e..6fd64737 100644 --- a/ldap-site-mngmt/webinterface/lib/rbs_management_functions.php +++ b/ldap-site-mngmt/webinterface/lib/rbs_management_functions.php @@ -206,9 +206,33 @@ function adjust_dhcpnextserver($tftpIP, $rbsDN){ die; } $result = ldapArraySauber($result); - $modtftpentry ['dhcpoptnext-server'] = $tftpIP; - foreach ($result as $item){ - ldap_mod_replace($ds, $item['dn'], $modtftpentry); + $host_au = array(); + if ($tftpIP == ""){ + $deltftpentry ['dhcpoptnext-server'] = array(); + foreach ($result as $item){ + ldap_mod_del($ds, $item['dn'], array()); + $expdn = array_slice(ldap_explode_dn($item['dn'], 0), 3); + $host_au [] = implode(",", $expdn); + } + }else{ + $modtftpentry ['dhcpoptnext-server'] = $tftpIP; + foreach ($result as $item){ + ldap_mod_replace($ds, $item['dn'], $modtftpentry); + $expdn = array_slice(ldap_explode_dn($item['dn'], 0), 3); + $host_au [] = implode(",", $expdn); + } + } + if ( count($host_au) != 0 ){ + $host_au = array_unique($host_au); + $entry ['dhcpmtime'] = time(); + foreach ($host_au as $au){ + $results = ldap_mod_replace($ds,$au,$entry); + if ($results){ + #echo "<br><b>dhcpMTime</b> erfolgreich aktualisiert!<br>" ; + }else{ + echo "<br>Fehler beim Aktualisieren der <b>dhcpMTime</b>!<br>" ; + } + } } } @@ -224,6 +248,7 @@ function adjust_dhcpfilename($initbootfile, $rbsDN, $type){ die; } $result = ldapArraySauber($result); + $host_au = array(); if ($type == "add"){ $modentry ['dhcpoptfilename'] = $initbootfile; foreach ($result as $item){ @@ -239,36 +264,71 @@ function adjust_dhcpfilename($initbootfile, $rbsDN, $type){ elseif ($type == "replace"){ $modentry ['dhcpoptfilename'] = $initbootfile; foreach ($result as $item){ - ldap_mod_replace($ds, $item['dn'], $modentry); + ldap_mod_replace($ds, $item['dn'], $modentry); + $expdn = array_slice(ldap_explode_dn($item['dn'], 0), 3); + $host_au [] = implode(",", $expdn); } } + if ( count($host_au) != 0 ){ + $host_au = array_unique($host_au); + $entry ['dhcpmtime'] = time(); + foreach ($host_au as $au){ + $results = ldap_mod_replace($ds,$au,$entry); + if ($results){ + #echo "<br><b>dhcpMTime</b> erfolgreich aktualisiert!<br>" ; + }else{ + echo "<br>Fehler beim Aktualisieren der <b>dhcpMTime</b>!<br>" ; + } + } + } } +# IP Adresse eines Host ändern -> RBS TFTP Server IP anpassen (inkl. dhcpNext-server) +function adjust_hostip_tftpserverip($oldip,$newip){ + + global $ds, $suffix, $ldapError, $auDN; + + if(!($result = uniLdapSearch($ds, "cn=rbs,".$auDN, "(&(objectclass=RBService)(tftpserverip=$oldip))", array("dn","tftpserverip"), "dn", "sub", 0, 0))) { + # redirect(5, "", $ldapError, FALSE); + echo "no search"; + die; + } + $result = ldapArraySauber($result); + if (count($result) != 0){ + foreach ($result as $item){ + if ($newip == ""){ + $delentry ['tftpserverip'] = array(); + ldap_mod_del($ds, $item['dn'], $delentry); + adjust_dhcpnextserver("", $item['dn']); + }else{ + $modentry ['tftpserverip'] = $newip; + ldap_mod_replace($ds, $item['dn'], $modentry); + adjust_dhcpnextserver($newip, $item['dn']); + } + } + } +} # # Sucht den Hostname zu einer IP im Rechnerteilbaum der AU # Verwaltung der am RBS beteiligten Server # -function get_hostname_from_ip($ip,$auDN){ +function get_hostname_from_ip($ip){ - global $ds, $suffix, $ldapError; + global $ds, $suffix, $ldapError, $auDN; $ipp = array($ip,$ip); $ipaddress = implode('_',$ipp); - - if(!($result = uniLdapSearch($ds, "cn=computers,".$auDN, "(&(objectclass=Host)(ipaddress=$ipaddress))", array("hostname"), "", "list", 0, 0))) { + if(!($result = uniLdapSearch($ds, "cn=computers,".$auDN, "(&(objectclass=Host)(ipaddress=$ipaddress))", array("dn","hostname"), "", "list", 0, 0))) { # redirect(5, "", $ldapError, FALSE); echo "no search"; die; } - elseif(count($result) == 0){echo "kein Rechner mit dieser IP"; return "";} - else{ - $result = ldapArraySauber($result); - #print_r($result); - $host ['hostname'] = $result[0]['hostname']; - $host ['dn'] = $result[0]['dn']; - return $host; - } + $result = ldapArraySauber($result); + #print_r($result); + $host ['hostname'] = $result[0]['hostname']; + $host ['dn'] = $result[0]['dn']; + return $host; } |
