Esempio n. 1
0
function build_au_array($au, $parentau)
{
    global $ds, $ldaperror, $tree_array, $tree;
    if ($parentau == "") {
        $tree_array[$au]['mode'] = "exp";
    } else {
        $tree_array[$au]['mode'] = "coll";
    }
    # au data
    $au_data = get_au_data($au, array("ou", "associateddomain"));
    #print_r($au_data); echo "<br><br>";
    $tree_array[$au]['roles'] = get_au_roles($au);
    # Falls MainAdmin dann auch MainAdmin automatisch im gesamten Subtree
    if ($parentau && in_array("MainAdmin", $tree_array[$parentau]['roles'])) {
        if (!in_array("MainAdmin", $tree_array[$au]['roles'])) {
            $tree_array[$au]['roles'][] = "MainAdmin";
        }
    }
    if ($tree_array[$au]['roles']) {
        $roles = implode('_', $tree_array[$au]['roles']);
        $tree_array[$au]['zone'] = $au_data[0]['associateddomain'];
        if ($au_data[0]['associateddomain']) {
            $tree_array[$au]['text'] = "<a href='zwischen.php?audn={$au}' class='headerlink'><b>" . $au_data[0]['ou'] . "</b></a>\n\t\t\t\t\t\t\t\t\t\t\t\t&nbsp;&nbsp;&nbsp;[ " . $au_data[0]['associateddomain'] . " ]";
        } else {
            $tree_array[$au]['text'] = "<code class='inactive_au'>" . $au_data[0]['ou'] . "</code> &nbsp;(Nicht aktiviert - noch keine DNS Zone)";
        }
    } else {
        $tree_array[$au]['text'] = "<code class='noadmin_au'>" . $au_data[0]['ou'] . "</code>";
    }
    # childaus
    $childs = get_childau($au, array("dn", "ou"));
    if ($childs) {
        if ($tree_array[$au]['roles']) {
            $tree_array[$au]['mode'] = "exp";
        } else {
            $tree_array[$au]['mode'] = "coll";
        }
        foreach ($childs as $child) {
            $childau = $child['dn'];
            $tree_array[$au]['childs'][] = $childau;
            # rekursiver Aufruf
            build_au_array($childau, $au);
            # Tree Pfad zu AUs unten expanden
            if ($tree_array[$childau]['roles'] || $tree_array[$childau]['mode'] == "exp") {
                $tree_array[$au]['mode'] = "exp";
            }
        }
    }
}
/**
* reduce_ip_delegation($oldmipb,$newmipb,$childauDN,$auDN)  
* Einen an eine untergeordnete AU delegierten IP Bereich verkleinern. Diese Funktion wird rekursiv fuer
* alle weiter-delegierten Teilbereiche abgearbeitet. FreeIPBlocks der AU und Child-AU, sowie MaxIPBlocks
* der Child-AU werden angepasst.
*
* @param string oldmipb delegierter maximaler IP Bereich, der verkleinert werden soll
* @param string newmipb delegierter maximaler IP Bereich nach der Verkleinerung
* @param string childauDN Distinguished Name des untergeordneten (Child) LDAP AU-Objektes
* @param string auDN Distinguished Name des LDAP AU-Objektes
*
* @return boolean 1 bei Erfolg bzw. 0 bei Misserfolg
*
* @author Tarik Gasmi
*/
function reduce_ip_delegation($oldmipb, $newmipb, $childauDN, $auDN)
{
    global $ds, $suffix, $ldapError;
    # Durch Reduzierung zu loeschende IP Ranges (Array)
    $delip = split_iprange($newmipb, $oldmipb);
    #print_r($delip);printf("<br><br>");
    # Finde unter allen Child-AUs diejenigen, die von Reduzierung betroffene Child-Child-AUs haben
    # Diese sind werden rekursiv abgearbeitet
    $cchild_array = get_childau($childauDN, array("dn", "maxipblock"));
    $cchild_todo = array();
    foreach ($delip as $delipitem) {
        foreach ($cchild_array as $item) {
            if (count($item['maxipblock']) > 1) {
                foreach ($item['maxipblock'] as $item2) {
                    if (intersect_ipranges($delipitem, $item2) != false) {
                        $cchild_todo[] = array('coldmipb' => $item2, 'cnewmipb' => intersect_ipranges($newmipb, $item2), 'ccauDN' => $item['dn'], 'childauDN' => $childauDN);
                    }
                }
            } elseif (count($item['maxipblock']) == 1) {
                if (intersect_ipranges($delipitem, $item['maxipblock']) != false) {
                    $cchild_todo[] = array('coldmipb' => $item['maxipblock'], 'cnewmipb' => intersect_ipranges($newmipb, $item['maxipblock']), 'ccauDN' => $item['dn'], 'childauDN' => $childauDN);
                }
            }
        }
    }
    #print_r($cchild_todo);printf("<br><br>");
    ######################
    # Rekursionsaufruf (für jede Child-AU, die betroffene Child-Child-AU hat)
    foreach ($cchild_todo as $item) {
        if ($item['cnewmipb'] == false) {
            delete_ip_delegation($item['coldmipb'], $item['ccauDN'], $item['childauDN']);
        } else {
            reduce_ip_delegation($item['coldmipb'], $item['cnewmipb'], $item['ccauDN'], $item['childauDN']);
        }
    }
    ######################
    # Ab hier: alles was bei jedem Fkt.Aufruf zu machen ist (auf Ebene AU und Child-AU)
    # in CAU Check ob RechnerIPs oder DhcpIPs betroffen:
    # - falls ja: nochmals Abfrage (Hammermethode: diese auch loeschen) ob diese zu loeschen sind
    #   -> ja, betreffende IPs loeschen
    #   -> nein, Abbruch.
    # - falls nein: fuer jedes FIPB in CAU intersect(FIPB,newmipb)-> Schnittmengen bilden die neuen FIPB
    $del_objects = objects_to_adjust($newmipb, $delip, $childauDN, $cchild_array);
    # print_r($del_objects);printf("<br><br>");
    if (count($del_objects['hostips']) != 0) {
        printf("<br>Host IP Addresses that will be deleted: <br>");
        foreach ($del_objects['hostips'] as $item) {
            printf("HostDN: %s &nbsp;&nbsp; IP Address: %s <br>", $item['dn'], $item['ip']);
        }
    }
    if (count($del_objects['dhcpranges']) != 0) {
        printf("<br>Subnet IP Ranges that will be adjusted: <br>");
        foreach ($del_objects['dhcpranges'] as $item) {
            printf("DhcpObjectDN: %s &nbsp;&nbsp; New IP Range: %s <br>", $item['dn'], $item['newrange']);
        }
    }
    # momentan wird einfach geloescht:
    if (count($del_objects['hostips']) != 0) {
        foreach ($del_objects['hostips'] as $item) {
            delete_ip_host($item['dn'], $item['auDN']);
        }
    }
    if (count($del_objects['dhcpranges']) != 0) {
        foreach ($del_objects['dhcpranges'] as $item) {
            if (count($item['newrange']) >= 1) {
                modify_ip_dhcprange($item['newrange'], $item['dn'], $item['auDN']);
            } else {
                delete_ip_dhcprange($item['dn'], $item['auDN']);
            }
        }
    }
    # in Child-AU: oldmipb -> newmipb
    $mipb_array = get_maxipblocks_au($childauDN);
    # print_r($mipb_array);printf("<br><br>");
    foreach ($delip as $delipitem) {
        for ($i = 0; $i < count($mipb_array); $i++) {
            if (intersect_ipranges($delipitem, $mipb_array[$i]) != 0) {
                $ipranges = intersect_ipranges($newmipb, $mipb_array[$i]);
                array_splice($mipb_array, $i, 1, $ipranges);
            }
        }
    }
    # print_r($mipb_array);printf("<br><br>");
    for ($i = 0; $i < count($mipb_array); $i++) {
        if ($mipb_array[$i] == false) {
            array_splice($mipb_array, $i, 1);
        }
    }
    #print_r($mipb_array);printf("<br><br>");
    if (count($mipb_array) == 0) {
        $entry['MaxIPBlock'] = array();
        #print_r($entry);printf("<br><br>");
        $results = ldap_mod_del($ds, $childauDN, $entry);
    } else {
        foreach ($mipb_array as $item) {
            $entry['MaxIPBlock'][] = $item;
        }
        #print_r($entry);printf("<br><br>");
        $results = ldap_mod_replace($ds, $childauDN, $entry);
    }
    if ($results) {
        echo "<br>MIPBs in Child-AU erfolgreich aktualisiert!<br>";
        # in Child-AU: FIPBs anpassen
        $fipb_array = get_freeipblocks_au($childauDN);
        #print_r($fipb_array);printf("<br><br>");
        foreach ($delip as $delipitem) {
            for ($i = 0; $i < count($fipb_array); $i++) {
                if (intersect_ipranges($delipitem, $fipb_array[$i]) != 0) {
                    $ipranges = intersect_ipranges($newmipb, $fipb_array[$i]);
                    array_splice($fipb_array, $i, 1, $ipranges);
                }
            }
        }
        # print_r($fipb_array);printf("<br><br>");
        for ($i = 0; $i < count($fipb_array); $i++) {
            if ($fipb_array[$i] == false) {
                array_splice($fipb_array, $i, 1);
            }
        }
        #print_r($fipb_array);printf("<br><br>");
        if (count($fipb_array) == 0) {
            $entry1['FreeIPBlock'] = array();
            #print_r($entry1);printf("<br><br>");
            $results = ldap_mod_del($ds, $childauDN, $entry1);
        } else {
            foreach ($fipb_array as $item) {
                $entry1['FreeIPBlock'][] = $item;
            }
            #print_r($entry1);printf("<br><br>");
            $results = ldap_mod_replace($ds, $childauDN, $entry1);
        }
        if ($results) {
            echo "FIPBs in Child-AU erfolgreich aktualisiert!<br>";
            # in AU: Geloeschte IP Bereiche als neue FIPBs aufnehmen
            foreach ($delip as $item) {
                $entry2['FreeIPBlock'][] = $item;
            }
            #print_r($entry2);printf("<br><br>");
            $results = ldap_mod_add($ds, $auDN, $entry2);
            if ($results) {
                echo "FIPBs in AU erfolgreich aktualisiert!<br>";
                # IP Bloecke aufraeumen in Child-AU und AU (Merging)
                merge_ipranges($auDN);
                merge_ipranges($childauDN);
                return 1;
            } else {
                echo "Fehler beim aktualisieren der FIPBs in AU!<br>";
                return 0;
            }
        } else {
            echo "Fehler beim aktualisieren der FIPBs in Child-AU!<br>";
            return 0;
        }
    } else {
        echo "<br>Fehler beim aktualisieren der MIPBs in Child-AU!<br>";
        return 0;
    }
}
<?php

include '../standard_header.inc.php';
# Dateiname und evtl. Pfad des Templates für die Webseite
$webseite = "dns_au_zones.dwt";
include 'dns_header.inc.php';
###################################################################################
$mnr = 1;
# Menuleisten erstellen
createMainMenu($rollen, $mainnr);
createDNSMenu($rollen, $mnr);
###################################################################################
$template->assign(array("AUOU" => "Noch keine untergordnete AU angelegt", "AUCN" => "", "AUDN" => "", "AUZONE" => "", "AUIPS" => ""));
$attributes = array("dn", "ou", "associateddomain");
#$aunits = get_all_aus($attributes);
$backbone_nodes = get_childau($auDN, $attributes);
$template->define_dynamic("Aus", "Webseite");
foreach ($backbone_nodes as $bn) {
    $aulist = "";
    $aunits = get_childau_sub($bn['dn'], $attributes);
    #print_r($aunits);echo "<br><br>";
    $aunits = array_slice($aunits, 1);
    $aunits = array_natsort($aunits, "ou", "ou");
    if ($aunits) {
        $aulist .= "<table cellpadding='2' cellspacing='0' border='1' align='left' width='100%' style='border-width: 0 0 0 0;'>";
        foreach ($aunits as $au) {
            $aulist .= "\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td class='tab_dgrey' width='50%'>{$au['ou']}&nbsp;</td>\n\t\t\t\t\t\t\t<td class='tab_dgrey'>\n\t\t\t\t\t\t\t\t<input type='Text' name='auzone[]' value='{$au['associateddomain']}' size='23' class='medium_form_field'>\n\t\t\t\t\t\t\t\t<input type='hidden' name='oldauzone[]' value='{$au['associateddomain']}'>\n\t\t\t\t\t\t\t\t<input type='hidden' name='audn[]' value='{$au['dn']}'></td>\n\t\t\t\t\t\t</tr>";
        }
        $aulist .= "</table>";
    } else {
        $aulist = "Keine untergeordneten AUs";
function delete_childau($childDN, $childou, $delmodus)
{
    global $ds, $suffix, $auDN, $domDN, $assocdom, $ldapError;
    if ($delmodus == "integrate") {
        # Associated DNS Domain integrieren
        $childdc = get_domain_data($childDN, array("dn", "associatedname"));
        print_r($childdc);
        echo "<br>";
        # wenn einzige AU dann einfach in Parentdomain aufnehmen und betroffene Einträge löschen
        if (count($childdc[0]['associatedname']) == 1) {
            echo "einzige AU<br>";
            # dc Childs verschieben
            $dcchilds = get_dc_childs($childdc[0]['dn'], array("dn", "dc"));
            # print_r($dcchilds); echo "<br>";
            if (count($dcchilds) != 0) {
                foreach ($dcchilds as $dcc) {
                    # print_r($dcc['dn']); echo " >> "; print_r("dc=".$dcc['dc'].",".$domDN); echo "<br>";
                    if (move_subtree($dcc['dn'], "dc=" . $dcc['dc'] . "," . $domDN)) {
                        $newdom = $dcc['dc'] . "." . $assocdom;
                        #print_r($newdom); echo "<br><br>";
                        dive_into_dctree_adapt("dc=" . $dcc['dc'] . "," . $domDN, $newdom);
                    }
                }
            }
            # alten dc-Knoten löschen
            dive_into_tree_del($childdc[0]['dn'], "");
        }
        # wenn noch andere AUs in der Domain, dann nur betroffene Einträge entfernen
        if (count($childdc[0]['associatedname']) > 1) {
            echo "mehrere AUs<br>";
            # ChildAU-Rollen unterhalb dc-Knoten löschen (nur diese)(oder übernehmen: MA zu HA, HA zu HA)
            $roles = get_roles($childDN);
            #print_r($roles); echo "<br>";
            # was ist wenn rollen nur noch ein member haben ... fehler
            if (count($roles['MainAdmin']) != 0) {
                $mainadmins = $roles['MainAdmin'];
                for ($i = 0; $i < count($mainadmins); $i++) {
                    $entryRoleMain['member'][$i] = $mainadmins[$i];
                }
                #print_r($entryRoleHost); echo "<br>";
                $resultMA = ldap_mod_del($ds, "cn=MainAdmin,cn=roles," . $childdc[0]['dn'], $entryRoleMain);
            }
            if (count($roles['HostAdmin']) != 0) {
                $hostadmins = $roles['HostAdmin'];
                for ($i = 0; $i < count($hostadmins); $i++) {
                    $entryRoleHost['member'][$i] = $hostadmins[$i];
                }
                #print_r($entryRoleHost); echo "<br>";
                $resultHA = ldap_mod_del($ds, "cn=HostAdmin,cn=roles," . $childdc[0]['dn'], $entryRoleHost);
            }
            if (count($roles['ZoneAdmin']) != 0) {
                $zoneadmins = $roles['ZoneAdmin'];
                for ($i = 0; $i < count($zoneadmins); $i++) {
                    $entryRoleZone['member'][$i] = $zoneadmins[$i];
                }
                $resultZA = ldap_mod_del($ds, "cn=ZoneAdmin,cn=roles," . $childdc[0]['dn'], $entryRoleZone);
            }
            $entrydel['associatedname'] = $childDN;
            # print_r($entrydel); echo "<br>";
            ldap_mod_del($ds, $childdc[0]['dn'], $entrydel);
            $zentries = get_zone_entries_assocname($childdc[0]['dn'], array("dn"), $childDN);
            # print_r($zentries); echo "<br>";
            foreach ($zentries as $ze) {
                # print_r($ze['dn']); echo "<br>";
                ldap_delete($ds, $ze['dn']);
            }
        }
        # Rechner (mit IP) + dranhängende MCs, PXEs verschieben
        $hosts = get_hosts($childDN, array("dn", "hostname"));
        if (count($hosts) != 0) {
            foreach ($hosts as $host) {
                # print_r($host['dn']); echo "<br>";
                # print_r($host['hostname']);  echo "<br>";
                # print_r("hostname=".$host['hostname']."-int-".$childou.",cn=computers,".$auDN); echo "<br><br>";
                if (move_subtree($host['dn'], "hostname=" . $host['hostname'] . "-ex-" . $childou . ",cn=computers," . $auDN)) {
                    $newhostDN = "hostname=" . $host['hostname'] . "-ex-" . $childou . ",cn=computers," . $auDN;
                    $dhcp = get_node_data($newhostDN, array("dhcphlpcont"));
                    # print_r($dhcp); echo "<br>";
                    if ($dhcp['dhcphlpcont'] != "") {
                        $entrydel['dhcphlpcont'] = array();
                        $entrydel['objectclass'] = "dhcpHost";
                        # print_r($dhcphlpcont);
                        ldap_mod_del($ds, $newhostDN, $entrydel);
                    }
                }
            }
        }
        # DHCP Objekte IP Ranges löschen
        $subnets = get_subnets($childDN, array("dn"));
        # print_r($subnets); echo "<br>";
        if (count($subnets) != 0) {
            foreach ($subnets as $subnet) {
                # print_r($subnet['dn']); echo "<br>";
                delete_ip_dhcprange($subnet['dn'], $childDN);
            }
        }
        # DHCP Pools auch noch
        # Freie IP Bereiche zurücknehmen
        $fipb_array = get_freeipblocks_au($childDN);
        # print_r($fipb_array); echo "<br>";
        # print_r(count($fipb_array)); echo "<br>";
        if (count($fipb_array) == 1 && $fipb_array[0] != "") {
            $entry_ipblock['freeipblock'] = $fipb_array[0];
            # print_r($entry_ipblock); echo "<br>";
            ldap_mod_add($ds, $auDN, $entry_ipblock);
        }
        if (count($fipb_array) > 1) {
            foreach ($fipb_array as $fipb) {
                $entry_ipblock['FreeIPBlock'][] = $fipb;
                # print_r($entry_ipblock); echo "<br>";
                ldap_mod_add($ds, $auDN, $entry_ipblock);
            }
        }
        merge_ipranges($auDN);
        # Verschieben der Childs an neue Stelle
        $child_childs = get_childau($childDN, array("dn", "ou"));
        # print_r($child_childs); echo "<br>";
        if (count($child_childs) != 0) {
            foreach ($child_childs as $cc) {
                $child_childDN = $cc['dn'];
                $newccDN = "ou=" . $cc['ou'] . "," . $auDN;
                # print_r($child_childDN); echo " >> ";
                # print_r($newccDN); echo "<br>";
                if (move_subtree($child_childDN, $newccDN)) {
                    adjust_dn_entries($child_childDN, $newccDN);
                }
            }
        }
        # Löschen des AU Knotens
        dive_into_tree_del($childDN, "");
        $mesg = "<br>Erfolgreich gel&ouml;scht mit Integration<br>";
        return $mesg;
    }
    if ($delmodus == "complete") {
        # IP Bereiche zurück
        # DNS Teilbaum Objekte löschen
        # alles rekursive löschen
        /*if (dive_into_tree_del($dcDN,"")){
        			$delentry ['objectclass'] = "domainrelatedobject";
        			$delentry ['associateddomain'] = $domsuffix;
        			#print_r($delentry); echo "<br>";
        			$delresult = ldap_mod_del($ds,$childDN,$delentry);
        		   if ($delresult){
        				$mesg = "Domain komplett gel&ouml;scht<br>";
        			}else{$mesg = "Fehler! ldap_mod_del<br>";}
        		}else{$mesg = "Fehler! dive_into_tree_del<br>";}
        		*/
        $mesg = "Komplettes l&ouml;schen mometan noch nicht unterst&uuml;tzt.<br>\n\t\t\t\t\tNur eine Ebene mit Integration ...<br>";
        return $mesg;
    }
}
Esempio n. 5
0
<?php

include '../standard_header.inc.php';
# Filename of Template
$webseite = "au_childs.dwt";
include 'au_header.inc.php';
###############################################################################
# Menus
$mnr = 2;
$sbmnr = -1;
createMainMenu($rollen, $mainnr);
createAUMenu($rollen, $mnr, $auDN, $sbmnr);
###############################################################################
# Mainpage Data
$template->assign(array("CHILDOU" => "Noch keine untergordnete AU angelegt", "CHILDCN" => "", "CHILDDN" => "", "CHILDDOMAIN" => "", "CHILDIPS" => "", "CHILDDESC" => ""));
$childau_array = get_childau($auDN, array("dn", "cn", "ou", "associateddomain", "description", "maxipblock"));
$template->define_dynamic("Childaus", "Webseite");
foreach ($childau_array as $childau) {
    #$auname = "<a href='child_au.php?dn=".$childau['dn']."' class='headerlink'>".$childau['ou']."</a>";
    $auname = "<a href='child_au.php?cau=" . $childau['ou'] . "' class='headerlink'>" . $childau['ou'] . "</a>";
    $delegips = "";
    if (is_array($childau['maxipblock'])) {
        natsort($childau['maxipblock']);
        $delegips = "<table cellpadding='0' cellspacing='0' border='0' align='left' width='100%'>";
        foreach ($childau['maxipblock'] as $mipb) {
            $exp = explode('_', $mipb);
            $delegips .= "<tr valign='top'>\n\t\t\t\t\t\t<td width='35%'>{$exp['0']}</td><td> - </td><td width='35%'>{$exp['1']}</td>\n\t\t\t\t\t\t<td width='20%'>&nbsp;</td>\n\t\t\t\t\t\t</tr>";
        }
        $delegips .= "</table>";
    } elseif ($childau['maxipblock']) {
        $exp = explode('_', $childau['maxipblock']);