예제 #1
0
 /**
  * Returns either int or array[2] with user/pass
  *
  * @param $request
  * @return array|int
  */
 function _getBasicAuth(\HTRouter\Request $request)
 {
     // Parse authentication request
     $auth = $request->getInHeaders("Authorization");
     if (!$auth) {
         return \HTRouter::STATUS_HTTP_UNAUTHORIZED;
     }
     list($auth_scheme, $auth_params) = explode(" ", $auth, 2);
     if (strtolower($auth_scheme) != "basic") {
         return \HTRouter::STATUS_HTTP_UNAUTHORIZED;
     }
     // Split user/pass
     $auth_params = base64_decode($auth_params);
     return explode(":", $auth_params, 2);
 }
예제 #2
0
 function matchHeaders(\HTRouter\Request $request)
 {
     foreach ($this->getConfig()->get("SetEnvIf", array()) as $entry) {
         $val = "";
         switch (strtolower($entry->attribute)) {
             case "remote_host":
                 $val = $_SERVER['REMOTE_HOST'];
                 break;
             case "remote_addr":
                 $val = $_SERVER['REMOTE_ADDR'];
                 break;
             case "server_addr":
                 $val = $_SERVER['SERVER_ADDR'];
                 break;
             case "request_method":
                 $val = $_SERVER['REQUEST_METHOD'];
                 break;
             case "request_protocol":
                 $val = $_SERVER['REQUEST_PROTOCOL'];
                 break;
             case "request_uri":
                 $val = $_SERVER['REQUEST_URI'];
                 break;
             default:
                 // Match all headers until we find a match
                 $tmp = array_merge($request->getInHeaders(), $this->getRouter()->getEnvironment());
                 foreach ($tmp as $header => $value) {
                     if ($entry->attribute_is_regex) {
                         // Match against regex
                         $regex = "/" . $entry->attribute . "/";
                         if (preg_match($regex, $header)) {
                             // Match!
                             $val = $value;
                             break;
                         }
                     } else {
                         // Match direct
                         if (strcmp($entry->attribute, $header) == 0) {
                             // Match!
                             $val = $value;
                             break;
                         }
                     }
                 }
                 break;
         }
         // Found a correct value, not check against the actual regex
         $regex = "/" . $entry->regex . "/";
         if ($entry->nocase) {
             $regex .= "i";
         }
         if (preg_match($regex, $val)) {
             $this->_addMatch($request, $entry);
         }
     }
     // All done. Proceed to next module
     return \HTRouter::STATUS_DECLINED;
 }