00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Mage_Core_Helper_Http extends Mage_Core_Helper_Abstract
00033 {
00034 public function authValidate($headers=null)
00035 {
00036 if(!is_null($headers)) {
00037 $_SERVER = $headers;
00038 }
00039
00040 $user = '';
00041 $pass = '';
00042
00043 if (empty($_SERVER['HTTP_AUTHORIZATION'])) {
00044 foreach ($_SERVER as $k=>$v) {
00045 if (substr($k, -18)==='HTTP_AUTHORIZATION' && !empty($v)) {
00046 $_SERVER['HTTP_AUTHORIZATION'] = $v;
00047 break;
00048 }
00049 }
00050 }
00051
00052 if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
00053 $user = $_SERVER['PHP_AUTH_USER'];
00054 $pass = $_SERVER['PHP_AUTH_PW'];
00055 }
00056
00057
00058 elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
00059 $auth = $_SERVER['HTTP_AUTHORIZATION'];
00060 list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
00061 }
00062 elseif (!empty($_SERVER['Authorization'])) {
00063 $auth = $_SERVER['Authorization'];
00064 list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
00065 }
00066
00067 if(!$user || !$pass) {
00068 $this->authFailed();
00069 }
00070
00071 return array($user, $pass);
00072 }
00073
00074 public function authFailed()
00075 {
00076 Mage::app()->getResponse()
00077 ->setHeader('HTTP/1.1','401 Unauthorized')
00078 ->setHeader('WWW-Authenticate','Basic realm="RSS Feeds"')
00079 ->setBody('<h1>401 Unauthorized</h1>')
00080 ->sendResponse();
00081 exit;
00082 }
00083 }