Error. Si devuelve 1-> correcto. * gesc2llwat -f fichero.xml -l. Devuelve una lista de los grupos que están incluidos en el fichero * gesc2llwat -f fichero.xml -g lista_de_grupos -d directorio_destino * * Author : Jose Ricardo Pla Pons */ function upload_file() { $_FILES["archivo"]['name'] = 'importgescen.xml'; $filename = $_FILES["archivo"]['name']; $tempfilename = $_FILES["archivo"]['tmp_name']; $temp_path= "/tmp/"; $temp_path= $temp_path.basename($filename); if(move_uploaded_file($_FILES['archivo']['tmp_name'], $temp_path)) { //echo "The file ". basename( $_FILES['archivo']['name'])." has been uploaded"; } else { echo _("There was an error uploading the file, please try again!
"); echo "
"; exit(); } $cmd = "gesc2llwat -f ".$temp_path." -t"; $cmdresult = shell_exec($cmd); if($cmdresult == "1") { //Primera combprobación el fichero *.xml es correcto, Generaremos los .llwat $cmd_2 = "gesc2llwat -f ".$temp_path." -d /tmp"; shell_exec($cmd_2); } else { echo _("Error in the file, incorrect format.
"); echo "
"; exit(); } } function importalloption() { upload_file(); $fileusersllwat = file('/tmp/users.llwat'); $filegroupsllwat = file('/tmp/groups.llwat'); import2ldap($fileusersllwat,$filegroupsllwat,false); } function importselectoption() { upload_file(); $fileusersllwat = file('/tmp/users.llwat'); $filegroupsllwat = file('/tmp/groups.llwat'); echo _("Select groups to import:

"); echo "
"; for ($i=0;$i".$line[0]."
"; } echo "


"; echo ""; echo ""; } function genuserllwat() { $grupos=array(); $grupos = $_POST["grupos"]; $gruposfin=implode(",",$grupos); $cmd = "gesc2llwat -f /tmp/importgescen.xml -d /tmp -g ".$gruposfin; shell_exec($cmd); $fileusersllwat = file('/tmp/users.llwat'); $filegroupsllwat = file('/tmp/groups.llwat'); import2ldap($fileusersllwat,$filegroupsllwat, true); } function compareldap($a,$b) { return Person::compare($a,$b); } /** * * This function is called by importalloption (full import)and genuserllwat (partial import) * This read all users from ldap and make with them an array. * Later compare users of array with users read from gescen file and result is : * ** If users exist in both, this users is updated * ** If users only exist in gescen , this users is insert * ** If users only exist in ldap , this users is deleted * * foreach action do create and remove links of groups; create home and groups; and delete home ang links on groups respectively * */ function import2ldap($fileusersllwat,$filegroupsllwat,$parcialimport) { global $ldap; $typeusers = array("ou=Students,ou=People,","ou=Teachers,ou=People,","ou=Other,ou=People,"); $fileusersldap = file('/var/log/lliurex-lwatlogs/users_id'); $fileusersadded = '/var/log/lliurex-lwatlogs/users_id'; $fileprebackend = '/var/log/lliurex-lwatlogs/prebackend'; $fileprebackendupdate = '/var/log/lliurex-lwatlogs/prebackend_update'; $fd=fopen($fileprebackend,"w"); $fdup=fopen($fileprebackendupdate,"w"); $addedvalues = array(); //Array que controla los usuarios q SI añadimos $groupscolection = array(); for($i=0;$iset_name($line[0]); $groupscolection[$line[0]] = $aux; } $contador=0; /* * * Get all users from ldap database and push on array. later ordered to search for quicksort * */ global $base; $filter="(uid=*)"; $want = array('cn','uid','dn','sn','description'); $ldapusers = array(); foreach($typeusers as $type) { $resultado = ldap_search($ldap,$type.$base,$filter,$want); $entries = @ldap_get_entries ($ldap, $resultado); unset($entries['count']); foreach ($entries as $user) { $tmpperson = new Person(); $tmpperson->set_cn($user['cn'][0]); $tmpperson->set_uid($user['uid'][0]); $tmpperson->set_dn($user['dn']); $tmpperson->set_sn($user['sn']); $tmpperson->set_gecos($user['description'][0]); array_push($ldapusers, $tmpperson); } } usort($ldapusers,"compareldap"); for($i=0;$iId : Si es un alumno sera el numero de expediente y si es un profesor sera el nif * 1->Template * 2->Fullname (gecos) * 3->Username * 4->Pass * 5->Groups * 6->Profile * 7->Name (cn) * 8->Surname (sn) */ $line=split(";",$fileusersllwat[$i]); $line[3]=get_username($ldap,$line[2]); //Obtenemos un nombre posible, y ldap nos confirma si ya esta utilizado en dicho caso se prueba con otro. $line[4]=pwgen(); $line[2]=trim(utf8_encode($line[2])); $line[7]=trim(utf8_encode($line[7])); $line[8]=trim(utf8_encode($line[8])); $group=array(); $group[]=trim(utf8_encode($line[5])); $contador++; if($contador == 10 ) { llxUserSync("clean-logs"); $contador = 0; } $newneedle = new Person(); $newneedle->set_cn($line[7]);//($line[2]); $newneedle->set_gecos($line[2]); $userpos = Person::search($ldapusers,$newneedle); if($userpos == -1) { //Añadir nuevos usuarios del sistema ldapAddUser($ldap,$line[2],$line[1],$line[3],$line[4],$group,$line[6],$line[7],$line[8],$fd); $line[0] = $line[0]."\n"; $newneedle->set_touch(true); array_push($ldapusers,$newneedle); usort($ldapusers,"compareldap"); array_push($addedvalues, $line[0]); //echo _("User Added : ".$line[2].".
"); } else { $userdn = $ldapusers[$userpos]->get_dn(); $ldapusers[$userpos]->set_touch(true); $auxarray = array(); $auxarray[0] = $userdn; ldapModUser($auxarray,$ldap,"ou=Managed,ou=Group,".$base,$group,$line[6],$fdup); } foreach($group as $addgroup) { $auxgroup = $groupscolection[$addgroup]; if (is_a($auxgroup,'classgroup')) { $auxgroup->add_member($line[2]); $groupscolection[$$addgroup] = $auxgroup; } } } /* * Partial import do partial read of gescen file, but total read of ldap. For this reason * always exist users on ldap array and always try delete users that has been inserted before. * Solution is that process for delete no launched */ if (!$parcialimport) { // Recorrer $ldapusers y eliminar aquellos que el touch = false $usersdelete = array(); foreach ($ldapusers as $user) { if(!$user->get_touch()) { $want = array("cn"); $filter = "uid=".$user->get_uid() ; $result = ldap_search ($ldap, $base, $filter, $want); $entries = ldap_get_entries ($ldap, $result); $user->set_dn($entries[0]['dn']); array_push($usersdelete, $user); } } if ( count($usersdelete) > 0) { formdelusergescen ($usersdelete); } } fclose($fd); fclose($fdup); $descrip = fopen($fileusersadded,'a'); for($i=0;$i"._("The import has completed successfully").""; echo '
'; foreach($groupscolection as $group) { echo "

".$group->get_name()."

"; $aux = $group->get_memmber(); if (count($aux)>0) { echo '
    '; sort($aux); foreach($aux as $memmber) { echo "
  • $memmber
  • "; } echo "
"; } else { echo _('This group is void'); } } echo "
"; //Fixing permission for script backend can open and read file.(If files no has been these permission prebackend not work with it) chmod($fileprebackend,0600); chmod($fileprebackendupdate,0600); //PREBACKEND CALL llxUserSync("batch"); llxUserSync("batch-update"); } function action_opt($opc) { if($opc == "importall") { importalloption(); } elseif($opc == "importselect") { importselectoption(); } elseif($opc == "selectedvalues") { genuserllwat(); } } /** * Do form for confirm delete users that not been on gescen file, but they are on ldap. Suppose this users go out system. * * @param $delperson Array of Person * @return void */ function formdelusergescen($delperson) { echo '
'; echo '

'._("This users will be deleted. Are you sure?").'

'; foreach ($delperson as $person) { echo ''.$person->get_cn().'
'; } echo ''; echo ''; echo '
'; } require_once ('functions.php') ; require_once ('person.php'); require_once ('group.php'); loadLocale(); loadConfig () ; session_start () ; $key = lwat_key () ; $ldap = lwat_ldap ($ldaphost); $authenticated = lwat_login ($ldap, '', '', $key) ; $cmdresult = 0; $opc = $_POST["opc"]; ?>