예제 #1
0
 public function IndexAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     try {
         $adldap = new adLDAP();
         $adldap->authenticate('rlesaffre_stage', '');
         $versionCarto = $em->getRepository('DeveloppementCartopliBundle:Installation')->getVersionCarto();
         return $this->render('DeveloppementCartopliBundle:Default:acces.html.twig', array('versionCarto' => $versionCarto));
     } catch (adLDAPException $e) {
         echo $e;
         exit;
     }
 }
예제 #2
0
 /**
  * Create an organizational unit
  * 
  * @param array $attributes Default attributes of the ou
  * @return bool
  */
 public function create($attributes)
 {
     if (!is_array($attributes)) {
         return "Attributes must be an array";
     }
     if (!is_array($attributes["container"])) {
         return "Container attribute must be an array.";
     }
     if (!array_key_exists("ou_name", $attributes)) {
         return "Missing compulsory field [ou_name]";
     }
     if (!array_key_exists("container", $attributes)) {
         return "Missing compulsory field [container]";
     }
     $attributes["container"] = array_reverse($attributes["container"]);
     $add = array();
     $add["objectClass"] = "organizationalUnit";
     $add["OU"] = $attributes['ou_name'];
     $containers = "";
     if (count($attributes['container']) > 0) {
         $containers = "OU=" . implode(",OU=", $attributes["container"]) . ",";
     }
     $containers = "OU=" . implode(",OU=", $attributes["container"]);
     $result = ldap_add($this->adldap->getLdapConnection(), "OU=" . $add["OU"] . ", " . $containers . $this->adldap->getBaseDn(), $add);
     if ($result != true) {
         return false;
     }
     return true;
 }
예제 #3
0
 /**
  * Return a list of all users in AD without limitation by incremental
  * 
  * @param bool $includeDescription Return a description of the user
  * @param string $search Search parameter
  * @param bool $sorted Sort the user accounts
  * @param string $increment a letter to find users' parameter
  * @return array
  */
 public function allWithoutLimit($includeDescription = false, $search = "*", $sorted = true, $increment = true)
 {
     if (!$this->adldap->getLdapBind()) {
         return false;
     }
     $incre = $increment;
     // Perform the search and grab all their details
     for ($i = 0; $search != $incre . 'z'; $search++) {
         $search = $incre;
         $filter = "(&(objectClass=user)(samaccounttype=" . adLDAP::ADLDAP_NORMAL_ACCOUNT . ")(objectCategory=person)(cn=" . $search . '*' . "))";
         $fields = array("samaccountname", "displayname");
         $sr = @ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields);
         $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr);
         $usersArray = array();
         for ($i = 0; $i < $entries["count"]; $i++) {
             if ($includeDescription && strlen($entries[$i]["displayname"][0]) > 0) {
                 $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["displayname"][0];
             } elseif ($includeDescription) {
                 $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["samaccountname"][0];
             } else {
                 array_push($usersArray, $entries[$i]["samaccountname"][0]);
             }
         }
         if ($sorted) {
             asort($usersArray);
         }
         return $usersArray;
     }
 }
예제 #4
0
 /**
  * Returns a list of Databases within any given storage group in Exchange for a given mail server
  * 
  * @param string $storageGroup The full DN of an Storage Group.  You can use exchange_storage_groups() to find the DN 
  * @param array $attributes An array of the AD attributes you wish to return
  * @return array
  */
 public function storageDatabases($storageGroup, $attributes = array('cn', 'distinguishedname', 'displayname'))
 {
     if (!$this->adldap->getLdapBind()) {
         return false;
     }
     if ($storageGroup === NULL) {
         return "Missing compulsory field [storageGroup]";
     }
     $filter = '(&(objectCategory=msExchPrivateMDB))';
     $sr = @ldap_search($this->adldap->getLdapConnection(), $storageGroup, $filter, $attributes);
     $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr);
     return $entries;
 }
 public function AfterLoginAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $adldap = new adLDAP();
     $username = $this->get('security.context')->getToken()->getUsername();
     //var_dump($adldap->user()->authenticate($username, $this->get('security.context')->getToken()->getCredentials()));
     $TousLesPersonne = $em->getRepository('DeveloppementCartopliBundle:Personne')->findAll();
     foreach ($TousLesPersonne as $Personne) {
         $prenom = $Personne->getPrenom();
         $nom = $Personne->getNom();
         $compteAd = strtolower(substr($prenom, 0, 1)) . strtolower($nom);
         $userinfo = $adldap->user()->infoCollection($compteAd, array("*"));
         if ($userinfo == false) {
             echo $compteAd;
             exit;
         } else {
             echo $userinfo->mail;
             exit;
         }
     }
     $userinfo = $adldap->user()->infoCollection($username, array("*"));
     if ($em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($username)) {
         $UtilisateurCo = $em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($this->get('security.context')->getToken()->getUsername());
         $em->flush();
         echo "Connecté au moins une fois";
     } else {
         if ($em->getRepository('DeveloppementCartopliBundle:Personne')->PersonneByMailPersonne($userinfo->mail)) {
             echo "Nouveau utilisateur";
         } else {
             //var_dump($em->getRepository('DeveloppementCartopliBundle:Personne')->PersonneByMailPersonne($userinfo->mail));
             echo "Nouveau";
         }
     }
     exit;
     return $this->redirect($this->generateUrl('developpement_cartopli_applications'));
 }
예제 #6
0
 /**
  * Coping with AD not returning the primary group
  * http://support.microsoft.com/?kbid=321360 
  * 
  * For some reason it's not possible to search on primarygrouptoken=XXX
  * If someone can show otherwise, I'd like to know about it :)
  * this way is resource intensive and generally a pain in the @#%^
  * 
  * @deprecated deprecated since version 3.1, see get get_primary_group
  * @param string $gid Group ID
  * @return string
  */
 public function cn($gid)
 {
     if ($gid === NULL) {
         return false;
     }
     $sr = false;
     $r = '';
     $filter = "(&(objectCategory=group)(samaccounttype=" . adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP . "))";
     $fields = array("primarygrouptoken", "samaccountname", "distinguishedname");
     $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields);
     $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr);
     for ($i = 0; $i < $entries["count"]; $i++) {
         if ($entries[$i]["primarygrouptoken"][0] == $gid) {
             $r = $entries[$i]["distinguishedname"][0];
             $i = $entries["count"];
         }
     }
     return $r;
 }
예제 #7
0
 /**
  * Get the groups a computer is in
  * 
  * @param string $computerName The name of the computer
  * @param bool $recursive Whether to check recursively
  * @return array
  */
 public function groups($computerName, $recursive = NULL)
 {
     if ($computerName === NULL) {
         return false;
     }
     if ($recursive === NULL) {
         $recursive = $this->adldap->getRecursiveGroups();
     }
     //use the default option if they haven't set it
     if (!$this->adldap->getLdapBind()) {
         return false;
     }
     //search the directory for their information
     $info = @$this->info($computerName, array("memberof", "primarygroupid"));
     $groups = $this->adldap->utilities()->niceNames($info[0]["memberof"]);
     //presuming the entry returned is our guy (unique usernames)
     if ($recursive === true) {
         foreach ($groups as $id => $groupName) {
             $extraGroups = $this->adldap->group()->recursiveGroups($groupName);
             $groups = array_merge($groups, $extraGroups);
         }
     }
     return $groups;
 }
 public function loadUserByUsername($username)
 {
     // effectuez un appel à votre service web ici
     // $userData = ...
     // supposons qu'il retourne un tableau en cas de succès, ou bien
     // « false » s'il n'y a pas d'utilisateur
     //return new LdapUser($username, $password, $salt, $roles);
     $adldap = new adLDAP();
     if ($adldap->user()->authenticate($username, $this->password)) {
         //                $userinfo = $adldap->user()->info($username, array("physicalDeliveryOfficeName","mail","displayname"));
         //                $em=$this->getDoctrine()->getEntityManager();
         //                 if($em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($username))
         //                 {
         //
         //                    $UtilisateurCo=$em->getRepository('DeveloppementCartopliBundle:Utilisateurs')->find($this->get('security.context')->getToken()->getUsername());
         //                    $em->flush();
         //                    throw new UsernameNotFoundException("Connecté au moin une foi");
         //                 }
         //                 else{
         //
         //                   if($em->getRepository('DeveloppementCartopliBundle:Personne')->PersonneByMailPersonne($userinfo[0]["mail"][0]))
         //                 {
         //                       throw new UsernameNotFoundException("Nouveau utilisateur");
         //                   }
         //                   else{
         //                       throw new UsernameNotFoundException("Nouveau");
         //                   }
         //                 }
         if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_ADMIN')) {
             return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_ADMIN"));
         } else {
             if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_ADMIN_CST')) {
                 return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_ADMIN_CST"));
             } else {
                 if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_UTILISATEUR')) {
                     return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_UTILISATEUR"));
                 } else {
                     if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_CORRECTEUR')) {
                         return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_CORRECTEUR"));
                     } else {
                         if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_CORRECTEUR_IT')) {
                             return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_CORRECTEUR_IT"));
                         } else {
                             if ($adldap->user()->inGroup($username, 'CARTOPLI_WEB_LECTEUR')) {
                                 return new LdapUser($username, $this->password, "", array("ROLE_CARTOPLI_WEB_LECTEUR"));
                             } else {
                                 throw new UsernameNotFoundException("Vous ne faites pas partie d'un groupe pour l'application, vous n'avez pas les droits.");
                             }
                         }
                     }
                 }
             }
         }
     } else {
         // var_dump ($this->password);
         //var_dump ($adldap->user()->authenticate($username, $this->password));
         //exit();
         throw new UsernameNotFoundException("Erreur de saisie");
     }
     //var_dump( $adldap->user()->authenticate('jbeutin_stage', '070893'));
     //$user = $adldap->user()->infoCollection('jbeutin_stage', array('*'));
     //var_dump($adldap);
     //echo $user->displayName;
     //$groupArray = $user->memberOf;
     // foreach ($groupArray as $group) {
     //echo $group . "\n";
     //}
     // if ($username=="user2"&& $this->password=="userpass2" )
     // {
     // }
     // else {
     //  throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     //}
 }
예제 #9
0
 /**
  * Mail enable a contact
  * Allows email to be sent to them through Exchange
  * 
  * @param string $distinguishedname The contact to mail enable
  * @param string $emailaddress The email address to allow emails to be sent through
  * @param string $mailnickname The mailnickname for the contact in Exchange.  If NULL this will be set to the display name
  * @return bool
  */
 public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL)
 {
     return $this->adldap->exchange()->contactMailEnable($distinguishedName, $emailAddress, $mailNickname);
 }