Index: branches/5.0.x/core/units/admin/admin_tag_processor.php =================================================================== diff -u -r12450 -r12520 --- branches/5.0.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 12450) +++ branches/5.0.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 12520) @@ -1,6 +1,6 @@ Application->Phrases->LanguageId = $params['language_id']; $this->Application->Phrases->LoadPhrases( $this->Application->Caches['PhraseList'] ); } + + /** + * Performs HTTP Authentification for administrative console + * + * @param Array $params + */ + function HTTPAuth($params) + { + if (!$this->Application->ConfigValue('UseHTTPAuth')) { + // http authentification not required + return true; + } + + $auth_bypass_ips = $this->Application->ConfigValue('HTTPAuthBypassIPs'); + + if ($auth_bypass_ips && ipMatch($auth_bypass_ips)) { + // user ip is in ip bypass list + return true; + } + + if (!array_key_exists('PHP_AUTH_USER', $_SERVER)) { + // ask user to authentificate, when not authentificated before + return $this->_httpAuthentificate(); + } + else { + // validate user credentials (browsers remembers user/password + // and sends them each time page is visited, so no need to save + // authentification result in session) + if ($this->Application->ConfigValue('HTTPAuthUsername') != $_SERVER['PHP_AUTH_USER']) { + // incorrect username + return $this->_httpAuthentificate(); + } + + $password_formatter =& $this->Application->recallObject('kPasswordFormatter'); + /* @var $password_formatter kPasswordFormatter */ + + $password = $password_formatter->EncryptPassword($_SERVER['PHP_AUTH_PW'], 'b38'); + + if ($this->Application->ConfigValue('HTTPAuthPassword') != $password) { + // incorrect password + return $this->_httpAuthentificate(); + } + } + + return true; + } + + /** + * Ask user to authentificate + * + * @return false + */ + function _httpAuthentificate() + { + $realm = strip_tags( $this->Application->ConfigValue('Site_Name') ); + header('WWW-Authenticate: Basic realm="' . $realm . '"'); + header('HTTP/1.0 401 Unauthorized'); + + return false; + } } \ No newline at end of file