Example #1
0
 /**
  * Establish LDAP connection
  *
  * @static
  * @access public
  * @param  string $username
  * @param  string $password
  * @return Client
  */
 public static function connect($username = null, $password = null)
 {
     $client = new self();
     $client->open($client->getLdapServer());
     $username = $username ?: $client->getLdapUsername();
     $password = $password ?: $client->getLdapPassword();
     if (empty($username) && empty($password)) {
         $client->useAnonymousAuthentication();
     } else {
         $client->authenticate($username, $password);
     }
     return $client;
 }
Example #2
0
File: JWT.php Project: firehed/jwt
 public static function fromEncoded(string $encoded, KeyContainer $keys) : self
 {
     // This should exactly follow s7.2 of the IETF JWT spec
     $parts = explode('.', $encoded);
     if (3 !== count($parts)) {
         throw new InvalidFormatException('Invalid format, wrong number of segments');
     }
     list($enc_header, $enc_claims, $signature) = $parts;
     $headers = self::b64decode($enc_header);
     $claims = self::b64decode($enc_claims);
     $token = new self($claims);
     $token->headers = $headers;
     $token->signature = $signature;
     $token->setKeys($keys);
     $token->authenticate();
     $token->enforceExpirations();
     return $token;
 }
 /**
  * Static convienence method which uses this class to implement the DNS
  * Update API to allow compatible DDNS clients to set GoDaddy DNS records
  * using HTTP requests.
  *
  * See: http://dyn.com/support/developers/api/perform-update/
  *      http://dyn.com/support/developers/api/return-codes/
  */
 public static function ddns($defaults = array())
 {
     // Merge the default request values with those passed into the function argument
     $defaults = array_merge(array('username' => '', 'password' => '', 'hostname' => '', 'myip' => '', 'offline' => false, 'offline_ip' => '127.0.0.1', 'detect_external_ip' => false), $defaults);
     // Get request values from HTTP data, falling back to the defaults above
     $username = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : (isset($_REQUEST['user']) ? $_REQUEST['user'] : $defaults['username']);
     $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : (isset($_REQUEST['pw']) ? $_REQUEST['pw'] : $defaults['password']);
     $hostname = isset($_REQUEST['hostname']) ? $_REQUEST['hostname'] : $defaults['hostname'];
     $myip = isset($_REQUEST['myip']) ? $_REQUEST['myip'] : (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : $defaults['myip']);
     $offline = isset($_REQUEST['offline']) ? strtoupper($_REQUEST['offline']) == 'YES' : $defaults['offline'];
     if ($hostname) {
         if ($username && $password) {
             // Instantiate the GoDaddyDNS class
             $dns = new self($defaults);
             if ($dns->authenticate($username, $password, $hostname)) {
                 if ($offline) {
                     // Use offline IP
                     $myip = $defaults['offline_ip'];
                 } elseif ($defaults['detect_external_ip'] && $dns->isPrivateIp($myip)) {
                     if ($externalip = $dns->getPublicIp($myip)) {
                         // Use detected external IP
                         $myip = $externalip;
                     }
                 }
                 // Attempt to update the hostname's A record
                 if ($result = $dns->setRecord($hostname, $myip, 'A')) {
                     echo ($result['last_ip'] == $result['new_ip'] ? 'nochg' : 'good') . ' ' . $result['new_ip'];
                 } else {
                     header('HTTP/1.1 500 Internal Server Error');
                     echo '911';
                 }
             } else {
                 header('HTTP/1.1 403 Forbidden');
                 echo 'badauth';
             }
         } else {
             header('WWW-Authenticate: Basic realm="Dynamic DNS"');
             header('HTTP/1.1 401 Unauthorized');
             echo 'noauth';
         }
     } else {
         header('HTTP/1.1 500 Internal Server Error');
         echo 'nohost';
     }
 }