BzzWare AS, Norway This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ require_once ('functions.php') ; loadConfig () ; session_start() ; ob_start () ; loadLocale () ; $key = lwat_key () ; $ldap = lwat_ldap () ; $authenticated = lwat_login ($ldap, readkey ('admindn'), readkey ('adminpw'), $key); echo "\n" ; echo " \n" ; header('Content-type: text/html; charset=UTF-8'); echo " lwat Debian-Edu fixup\n" ; echo " \n" ; echo " \n" ; echo "
\n" ; echo ''; print (_("Check") . ' ?'); print ('
') ; echo "
\n" ; echo ''; print (_("Check") . ' ?'); print ('
') ; $action = readKey ('Action') ; switch ($action) { case "": break ; case "Personal_Groups": $filter="(&(objectClass=lisGroup)(groupType=private))" ; $want = array ('cn') ; $result= ldap_search ($ldap, $base, $filter, $want); $entries= ldap_get_entries ($ldap, $result); if ($entries['count']) { printf(_("There are %d lisGroups that is of type private."),$entries['count']); #print (_("There is ") . $entries['count'] . " " ) ; #print (_("lisGroups that is of type private")) ; if ($authenticated) { print ("
") ; print ("") ; print (" ") ; print ("
") ; break ; } else $needToLogin = true ; } else { print (_("Could not find any lisGroups with groupType=private") . "
") ; } case "move_around_the_groups": $filter="(&(objectClass=posixGroup)(!(memberUid=*)))" ; $want = array ('cn', 'gidNumber') ; $result= ldap_search ($ldap, $groupbase, $filter, $want); $entries= ldap_get_entries ($ldap, $result); $count=0 ; $filter = "" ; $want = array () ; for ($i = 0 ; $i < $entries['count'] ; $i++) { $filter .= "(gidNumber=" . $entries[$i]['gidnumber'][0] . ")"; } unset ($entries) ; if (!empty($filter)) { $want = array ('gidNumber') ; $filter="(&(|" . $filter . ")(objectClass=posixAccount))" ; $result=ldap_search ($ldap, $base, $filter, $want); $count = ldap_count_entries ($ldap, $result) ; } if (!$count) { print (_("Could not find any personal groups that are located under the Group OU")) ; break ; } if (0 == strcmp ($action, "move_around_the_groups")) { $entries = ldap_get_entries ($ldap, $result) ; for ($i = 0 ; $i < $entries['count'] ; $i++) { $persondn = ldap_explode_dn ($entries[$i]['dn'],0); array_shift($persondn) ; $filter = '(&(gidNumber=' . $entries[$i]['gidnumber'][0] . ')(objectClass=posixGroup))' ; $result=ldap_search ($ldap, $base, $filter, $want); $found=ldap_first_entry ($ldap, $result) ; $groupdn = ldap_explode_dn (ldap_get_dn($ldap, $found), 0) ; array_shift($groupdn) ; array_shift($persondn) ; $personou=implode(",", $persondn) ; $olddn=implode(",", $groupdn) ; if (ldap_rename ($ldap, implode (",", $groupdn), $groupdn[0], implode (",", $persondn), true)) { printf(_("Moved %s to %s,%s"),$olddn, $groupdn[0], $personou); echo "
"; #echo _('Moved') . " $olddn " . _('to') ." $groupdn[0],$personou
\n" ; } else { printf(_("Failed to move %s to %s,%s"),$olddn, $groupdn[0],$personou); echo "
"; #echo _('Failed to move') . " $olddn " . _('to') ." $groupdn[0],$personou
\n" ; echo _("The reason we got from the ldap server was this:") . ldap_error ($ldap) . "
\n" ; } ob_end_flush () ; } unset ($entries) ; break ; } printf (_("There are %s personal groups in the group OU that could(should) be moved into the personal OU's"), $count ); echo "
"; #print (_("personal groups in the group OU that could(should) ")) ; #print (_("be moved into the personal OU's") . "
") ; if ($authenticated) { print ("
") ; print ("") ; print ("") ; print ("
") ; } else $needToLogin = true ; break ; case "remove_empty_groups": case "Empty_Groups": $filter="(&(objectClass=posixGroup)(!(memberUid=*)))" ; $want = array ('cn', 'gidNumber') ; $result= ldap_search ($ldap, $groupbase, $filter, $want); $entries= ldap_get_entries ($ldap, $result); $count=$entries['count'] ; $filter = "" ; $want = array () ; for ($i = 0 ; $i < $entries['count'] ; $i++) { $filter .= "(gidNumber=" . $entries[$i]['gidnumber'][0] . ")"; } if (!empty($filter)) { $want = array ('gidNumber') ; $filter="(&(|" . $filter . ")(objectClass=posixAccount))" ; $result=ldap_search ($ldap, $base, $filter, $want); $count = $count - ldap_count_entries ($ldap, $result) ; } if (!$count) { print (_("Could not find any empty groups")) ; break ; } if (0 == strcmp ($action, "remove_empty_groups")) { $want = array () ; for ($i = 0 ; $i < $entries['count'] ; $i++) { $filter = '(&(gidNumber=' . $entries[$i]['gidnumber'][0] . ')(objectClass=posixAccount))' ; $result=ldap_search ($ldap, $base, $filter, $want); if (0 == ldap_count_entries ($ldap, $result)) ; if (@ldap_delete ($ldap, $entries[$i]['dn'])) echo _('Removed empty group ') . $entries[$i]['dn'] . "
\n" ; else { echo _('Failed to remove empty group ') . $entries[$i]['dn'] . "
\n" ; echo _("The reason we got from the ldap server was this:") . ldap_error ($ldap) . "
\n" ; } ob_end_flush () ; } unset ($entries) ; break ; } printf (_("There are %s empty groups."), $count); if ($authenticated) { print ("
") ; print ("") ; print ("") ; print ("
") ; } else $needToLogin = true ; break ; case "login": if (!$authenticated) { print ('

' . _("You need to login before changing/adding anything") . '

') ; print ('
') ; print (_('Login name:') . '
') ; print ('
') ; print (_('Login password:') . '
') ; print ('
') ; print ('') ; print ('') ; print ('
') ; } break ; default: echo "Function not implemented (yet). This is som debug info:" ; debug ($_POST); break ; } ldap_close ($ldap); if ($needToLogin) { print ("
") ; print ('
' . _("You need to") . ' ') ; print ('
') ; } echo " \n" ; echo "\n" ; ?>