Esempio n. 1
0
 /**
  * LDAP options:
  *
  *      host *required
  *      port
  *      baseDn
  *      accountDomainName
  *      accountDomainNameShort
  *      accountCanonicalForm
  *      defaultUsername
  *      defaultPassword
  *      searchSizeLimit - Limit entries.
  *      searchTimeout - Timeout in seconds.
  *
  * @param array $options
  * @throws ServiceException
  */
 public function __construct(array $options)
 {
     if (empty($options['host'])) {
         throw new ServiceException('LDAP host required.');
     }
     $host = explode(':', $options['host']);
     unset($options['host']);
     $isIp = \NObjects\Validate::isIp($host[0]);
     // set defaults
     $this->setHost($host[0]);
     $this->setPort(self::DEFAULT_PORT);
     $this->setSsl(false);
     if (!empty($host[1])) {
         $this->setPort($host[1]);
         if ($host[1] == self::DEFAULT_PORT_SSL) {
             $this->setSsl(true);
         }
     }
     $this->setSearchSizeLimit(self::DEFAULT_SEARCH_SIZE_LIMIT);
     $this->setSearchTimeout(self::DEFAULT_SEARCH_TIMEOUT);
     $this->setNetworkTimeout(self::DEFAULT_NETWORK_TIMEOUT);
     // if host is domain name parse defaults from name
     if (!$isIp) {
         $domain = explode('.', $host[0]);
         if (count($domain) > 1) {
             $this->setBaseDn('DC=' . implode(',DC=', $domain));
             $this->setAccountDomainName($domain[count($domain) - 2] . '.' . $domain[count($domain) - 1]);
             $this->setAccountDomainNameShort($domain[count($domain) - 2]);
         }
     }
     // set options/override defaults
     if (!empty($options)) {
         $properties = $this->getProperties();
         foreach ($options as $k => $v) {
             $method = 'set' . $k;
             if (in_array($k, $properties) && method_exists($this, $method)) {
                 $this->{$method}($v);
             }
         }
     }
     // set default accountCanonicalForm if not in options
     if (!$this->getAccountCanonicalForm()) {
         if ($this->getAccountDomainNameShort()) {
             $this->setAccountCanonicalForm(self::ACCOUNT_NAME_FORM_BACKSLASHES);
         } else {
             $this->setAccountCanonicalForm(self::ACCOUNT_NAME_FORM_PRINCIPAL);
         }
     }
 }
Esempio n. 2
0
 public function testIsIp()
 {
     $ipv4 = "82.237.3.3";
     $ipv6 = "2a01:e35:aaa4:6860:a5e7:5ba9:965e:cc93";
     $ipv4Private = "255.255.255.255";
     $ipv6Private = "::1";
     $real = "10.10.10.10";
     $fake = "3342423423";
     $this->assertTrue(Validate::isIp($ipv4));
     $this->assertTrue(Validate::isIp($ipv6));
     $this->assertTrue(Validate::isIp($ipv4Private));
     $this->assertTrue(Validate::isIp($ipv6Private));
     $this->assertTrue(Validate::isIp($real));
     $this->assertFalse(Validate::isIp($fake));
 }