Index: branches/5.1.x/core/units/admin/admin_tag_processor.php =================================================================== diff -u -N -r12453 -r12657 --- branches/5.1.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 12453) +++ branches/5.1.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 12657) @@ -1,6 +1,6 @@ Application->ConfigValue('UsePopups') || $this->Application->GetVar('_force_popup'); + if ($this->Application->GetVar('_force_popup')) { + return true; + } + + $use_popups = (int)$this->Application->ConfigValue('UsePopups'); + + if (array_key_exists('mode', $params)) { + $mode_mapping = Array ('popup' => 1, 'modal' => 2); + return $use_popups == $mode_mapping[ $params['mode'] ]; + } + + return $use_popups; } function UseToolbarLabels($params) @@ -805,68 +824,10 @@ function AdminSkin($params) { - static $style; - if (!isset($style)) { - $style = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Skins WHERE IsPrimary = 1'); - } + $skin_helper =& $this->Application->recallObject('SkinHelper'); + /* @var $skin_helper SkinHelper */ - $css_path = (defined('WRITEABLE') ? WRITEABLE : FULL_PATH. DIRECTORY_SEPARATOR . 'kernel') . DIRECTORY_SEPARATOR . 'user_files'; - $css_url = $this->Application->BaseURL(defined('WRITEBALE_BASE') ? str_replace(DIRECTORY_SEPARATOR, '/', WRITEBALE_BASE) : '/kernel') . 'user_files/'; - - $type = array_key_exists('type', $params) ? $params['type'] : false; - if ($type == 'logo') { - $type = 'Logo'; - } - - if ($type == 'Logo' || $type == 'LogoBottom' || $type == 'LogoLogin') { - return $style[$type] ? $css_url.$style[$type] : ''; - } - - $last_compiled = $style['LastCompiled']; - - $style_name = mb_strtolower( $style['Name'] ); - - if( file_exists($css_path.'/'.'admin-'.$style_name.'-'.$last_compiled.'.css') ) - { - $ret = $css_url.'admin-'.$style_name.'-'.$last_compiled.'.css'; - - } - else - { - // search for previously compiled stylesheet - $last_compiled = 0; - if( $dh = opendir($css_path) ) - { - while( ($file = readdir($dh)) !== false ) - { - if( preg_match('/admin-(.*)-([\d]+).css/', $file, $rets) ) - { - if( $rets[1] == $style_name && $rets[2] > $last_compiled ) $last_compiled = $rets[2]; - } - } - closedir($dh); - } - if ($last_compiled) { - // found - $ret = $css_url.'admin-'.$style_name.'-'.$last_compiled.'.css'; - } - else { - // not found (try to compile on the fly) - $object =& $this->Application->recallObject('skin.-item', null, Array ('skip_autoload' => true)); - /* @var $object kDBItem */ - - $skin_eh =& $this->Application->recallObject('skin_EventHandler'); - /* @var $skin_eh SkinEventHandler */ - - $object->Load(1, 'IsPrimary'); - $skin_eh->Compile($object); - $ret = $css_url.'admin-'.$style_name.'-'.adodb_mktime().'.css'; - } - } - - if (isset($params['file_only'])) return $ret; - - return ''; + return $skin_helper->AdminSkinTag($params); } function PrintCompileErrors($params) @@ -1148,6 +1109,65 @@ $this->Application->Phrases->LanguageId = $params['language_id']; $this->Application->Phrases->LoadPhrases( $this->Application->Caches['PhraseList'] ); } - } -?> \ No newline at end of file + /** + * Performs HTTP Authentification for administrative console + * + * @param Array $params + */ + function HTTPAuth($params) + { + if (!$this->Application->ConfigValue('UseHTTPAuth')) { + // http authentification not required + return true; + } + + $super_admin_ips = defined('SA_IP') ? SA_IP : false; + $auth_bypass_ips = $this->Application->ConfigValue('HTTPAuthBypassIPs'); + + if (($auth_bypass_ips && ipMatch($auth_bypass_ips)) || ($super_admin_ips && ipMatch($super_admin_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