Revision 2125
Added by darkviper over 10 years ago
| branches/2.8.x/CHANGELOG | ||
|---|---|---|
| 11 | 11 |
! = Update/Change |
| 12 | 12 |
=============================================================================== |
| 13 | 13 |
|
| 14 |
17 Jun -2015 Build 2125 Manuela v.d.Decken(DarkViper) |
|
| 15 |
! /framework/class.Login.php |
|
| 16 |
! /account/ ~login_form.php ~login.php |
|
| 17 |
! /admin/login/index.php |
|
| 18 |
fixed some possible intruder vectors and complete 2.8.4 adaption |
|
| 14 | 19 |
16 May-2015 Build 2124 Manuela v.d.Decken(DarkViper) |
| 15 | 20 |
! /framework/initialize + |
| 16 | 21 |
! /framework/WbAutoloader abbreviation list moved to initialize; added method getAbbreviations() |
| branches/2.8.x/wb/admin/login/index.php | ||
|---|---|---|
| 18 | 18 |
// Include the configuration file |
| 19 | 19 |
$sStartFile = dirname(dirname(__DIR__)).'/framework/initialize.php'; |
| 20 | 20 |
if (!defined('SYSTEM_RUN')) {
|
| 21 |
require($sStartFile);
|
|
| 21 |
require($sStartFile);
|
|
| 22 | 22 |
} |
| 23 |
//if(!class_exists('login', false)){ require_once(WB_PATH.'/framework/class.login.php'); }
|
|
| 24 |
//if(!class_exists('frontend', false)){ require_once(WB_PATH.'/framework/class.frontend.php'); }
|
|
| 23 |
$username_fieldname = 'username'; |
|
| 24 |
$password_fieldname = 'password'; |
|
| 25 |
if(isset($oReg->SmartLogin) && $oReg->SmartLogin == 'true') {
|
|
| 26 |
$sTmp = '_'.substr(md5(microtime()), -8); |
|
| 27 |
$username_fieldname .= $sTmp; |
|
| 28 |
$password_fieldname .= $sTmp; |
|
| 29 |
} |
|
| 25 | 30 |
|
| 26 |
if(defined('SMART_LOGIN') AND SMART_LOGIN == 'enabled') {
|
|
| 27 |
// Generate username field name |
|
| 28 |
$username_fieldname = 'username_'; |
|
| 29 |
$password_fieldname = 'password_'; |
|
| 30 |
$salt = "abchefghjkmnpqrstuvwxyz0123456789"; |
|
| 31 |
srand((double)microtime()*1000000); |
|
| 32 |
$i = 0; |
|
| 33 |
while ($i <= 7) {
|
|
| 34 |
$num = rand() % 33; |
|
| 35 |
$tmp = substr($salt, $num, 1); |
|
| 36 |
$username_fieldname = $username_fieldname . $tmp; |
|
| 37 |
$password_fieldname = $password_fieldname . $tmp; |
|
| 38 |
$i++; |
|
| 39 |
} |
|
| 40 |
} else {
|
|
| 41 |
$username_fieldname = 'username'; |
|
| 42 |
$password_fieldname = 'password'; |
|
| 43 |
} |
|
| 44 | 31 |
$admin = new frontend(); |
| 45 |
$WarnUrl = str_replace(WB_PATH,WB_URL,$admin->correct_theme_source('warning.html'));
|
|
| 32 |
$WarnUrl = str_replace($oReg->AppPath, $oReg->AppUrl, $admin->correct_theme_source('warning.html'));
|
|
| 46 | 33 |
$LoginTpl = 'loginBox.htt'; |
| 47 | 34 |
$ThemePath = dirname($admin->correct_theme_source('loginBox.htt'));
|
| 48 | 35 |
$thisApp = new Login( array( |
| 49 |
'MAX_ATTEMPS' => '3',
|
|
| 36 |
'MAX_ATTEMPS' => 3,
|
|
| 50 | 37 |
'WARNING_URL' => $WarnUrl, |
| 51 | 38 |
'INFO_URL' => '##', |
| 52 | 39 |
'INFO_TEXT' => 'News', |
| 53 | 40 |
'USERNAME_FIELDNAME' => $username_fieldname, |
| 54 | 41 |
'PASSWORD_FIELDNAME' => $password_fieldname, |
| 55 |
'REMEMBER_ME_OPTION' => SMART_LOGIN,
|
|
| 56 |
'MIN_USERNAME_LEN' => '2',
|
|
| 57 |
'MIN_PASSWORD_LEN' => '3',
|
|
| 58 |
'MAX_USERNAME_LEN' => '30',
|
|
| 59 |
'MAX_PASSWORD_LEN' => '30',
|
|
| 60 |
'LOGIN_URL' => ADMIN_URL."/login/index.php",
|
|
| 61 |
'DEFAULT_URL' => ADMIN_URL."/start/index.php",
|
|
| 42 |
'REMEMBER_ME_OPTION' => $oReg->SmartLogin,
|
|
| 43 |
'MIN_USERNAME_LEN' => 2,
|
|
| 44 |
'MIN_PASSWORD_LEN' => 3,
|
|
| 45 |
'MAX_USERNAME_LEN' => 100,
|
|
| 46 |
'MAX_PASSWORD_LEN' => 100,
|
|
| 47 |
'LOGIN_URL' => $oReg->AcpUrl."login/index.php",
|
|
| 48 |
'DEFAULT_URL' => $oReg->AcpUrl."start/index.php",
|
|
| 62 | 49 |
'TEMPLATE_DIR' => $ThemePath, |
| 63 | 50 |
'TEMPLATE_FILE' => $LoginTpl, |
| 64 | 51 |
'FRONTEND' => false, |
| 65 |
'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
|
|
| 66 |
'USERS_TABLE' => TABLE_PREFIX."users",
|
|
| 67 |
'GROUPS_TABLE' => TABLE_PREFIX."groups",
|
|
| 52 |
'FORGOTTEN_DETAILS_APP' => $oReg->AcpUrl."login/forgot/index.php",
|
|
| 53 |
'USERS_TABLE' => $oDb->TablePrefix."users",
|
|
| 54 |
'GROUPS_TABLE' => $oDb->TablePrefix."groups",
|
|
| 68 | 55 |
) |
| 69 | 56 |
); |
| branches/2.8.x/wb/account/login_form.php | ||
|---|---|---|
| 4 | 4 |
* @category frontend |
| 5 | 5 |
* @package account |
| 6 | 6 |
* @author WebsiteBaker Project |
| 7 |
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
|
| 8 |
* @link http://www.websitebaker2.org/
|
|
| 7 |
* @copyright WebsiteBaker Org. e.V. |
|
| 8 |
* @link http://websitebaker.org/
|
|
| 9 | 9 |
* @license http://www.gnu.org/licenses/gpl.html |
| 10 | 10 |
* @platform WebsiteBaker 2.8.x |
| 11 | 11 |
* @requirements PHP 5.2.2 and higher |
| ... | ... | |
| 17 | 17 |
|
| 18 | 18 |
/* -------------------------------------------------------- */ |
| 19 | 19 |
// Must include code to stop this file being accessed directly |
| 20 |
if(!defined('WB_PATH')) {
|
|
| 21 |
require_once(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php'); |
|
| 22 |
throw new IllegalFileException(); |
|
| 20 |
if(!defined('SYSTEM_RUN')) {
|
|
| 21 |
throw new Exception('illegal file access [account/login_form.php]');
|
|
| 23 | 22 |
} |
| 24 | 23 |
/* -------------------------------------------------------- */ |
| 25 | 24 |
|
| 26 |
// Generate username field name |
|
| 27 |
$username_fieldname = 'username_'; |
|
| 28 |
$password_fieldname = 'password_'; |
|
| 25 |
// Generate username field name |
|
| 26 |
$username_fieldname = 'username'; |
|
| 27 |
$password_fieldname = 'password'; |
|
| 28 |
if(isset($oReg->SmartLogin) && $oReg->SmartLogin == 'true') {
|
|
| 29 |
$sTmp = '_'.substr(md5(microtime()), -8); |
|
| 30 |
$username_fieldname .= $sTmp; |
|
| 31 |
$password_fieldname .= $sTmp; |
|
| 32 |
} |
|
| 29 | 33 |
$output = ''; |
| 30 | 34 |
msgQueue::clear(); |
| 31 | 35 |
|
| 32 |
if(defined('SMART_LOGIN') AND SMART_LOGIN == 'true') {
|
|
| 33 |
|
|
| 34 |
$temp = array_merge(range('a','z'), range(0,9));
|
|
| 35 |
shuffle($temp); |
|
| 36 |
for($i=0;$i<=7;$i++) {
|
|
| 37 |
$username_fieldname .= $temp[$i]; |
|
| 38 |
$password_fieldname .= $temp[$i]; |
|
| 39 |
} |
|
| 40 |
} else {
|
|
| 41 |
$username_fieldname = 'username'; |
|
| 42 |
$password_fieldname = 'password'; |
|
| 43 |
} |
|
| 44 |
|
|
| 45 | 36 |
$thisApp->redirect_url = (isset($thisApp->redirect_url) && ($thisApp->redirect_url!='') ? $thisApp->redirect_url : $_SESSION['HTTP_REFERER'] ); |
| 46 | 37 |
//$thisApp->redirect_url = ''; |
| 47 | 38 |
$sIncludeHeadLinkCss = ''; |
| 48 |
if( is_readable(WB_PATH .'/account/frontend.css')) {
|
|
| 49 |
$sIncludeHeadLinkCss .= '<link href="'.WB_URL.'/account/frontend.css"';
|
|
| 50 |
$sIncludeHeadLinkCss .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
|
|
| 39 |
if( is_readable($oReg->AppPath.'account/frontend.css')) {
|
|
| 40 |
$sIncludeHeadLinkCss .= '<link href="'.$oReg->AppUrl.'account/frontend.css"';
|
|
| 41 |
$sIncludeHeadLinkCss .= ' rel="stylesheet" type="text/css" media="screen" />'."\n";
|
|
| 51 | 42 |
} |
| 52 | 43 |
|
| 53 | 44 |
// set template file and assign module and template block |
| 54 |
$oTpl = new Template(dirname(__FILE__).'/htt');
|
|
| 55 |
$oTpl->set_file('page', 'login.htt');
|
|
| 56 |
$oTpl->debug = false; // false, true
|
|
| 57 |
$oTpl->set_block('page', 'main_block', 'main');
|
|
| 45 |
$oTpl = new Template(__DIR__.'/htt');
|
|
| 46 |
$oTpl->set_file('page', 'login.htt');
|
|
| 47 |
$oTpl->debug = false;
|
|
| 48 |
$oTpl->set_block('page', 'main_block', 'main');
|
|
| 58 | 49 |
|
| 59 |
$oTpl->set_block('main_block', 'message_block', 'message');
|
|
| 60 |
$oTpl->set_block('message', '');
|
|
| 61 |
|
|
| 50 |
$oTpl->set_block('main_block', 'message_block', 'message');
|
|
| 51 |
$oTpl->set_block('message', '');
|
|
| 52 |
// language vars |
|
| 53 |
$oTpl->set_var($oReg->Trans->getLangArray()); |
|
| 62 | 54 |
// generell vars |
| 63 |
$oTpl->set_var(array( |
|
| 64 |
'FTAN' => $wb->getFTAN(), |
|
| 65 |
'ACTION_URL' => WB_URL.'/account/login.php', |
|
| 66 |
'FORGOT_URL' => WB_URL.'/account/forgot.php', |
|
| 67 |
'REDIRECT_URL' => $thisApp->redirect_url, |
|
| 68 |
'WB_URL' => WB_URL, |
|
| 69 |
'THEME_URL' => THEME_URL, |
|
| 70 |
'TEMPLATE_URL' => TEMPLATE_DIR, |
|
| 71 |
'HTTP_REFERER' => $thisApp->redirect_url, |
|
| 72 |
'CSS_BLOCK' => $sIncludeHeadLinkCss, |
|
| 73 |
'MESSAGE_VALUE' => '', |
|
| 74 |
'ERROR_VALUE' => '', |
|
| 75 |
'THISAPP_MESSAGE_VALUE' => $thisApp->message, |
|
| 76 |
'TEXT_FORGOTTEN_DETAILS' => $TEXT['FORGOTTEN_DETAILS'], |
|
| 77 |
'TEXT_USERNAME' => $TEXT['USERNAME'], |
|
| 78 |
'TEXT_PASSWORD' => $TEXT['PASSWORD'], |
|
| 79 |
'USER_FIELDNAME' => $username_fieldname, |
|
| 80 |
'PASSWORD_FIELDNAME' => $password_fieldname, |
|
| 81 |
'TEXT_LOGIN' => $TEXT['LOGIN'], |
|
| 82 |
'TEXT_RESET' => $TEXT['RESET'], |
|
| 83 |
'TEXT_CANCEL' => $TEXT['CANCEL'], |
|
| 84 |
) |
|
| 85 |
); |
|
| 55 |
$oTpl->set_var(array( |
|
| 56 |
'FTAN' => $wb->getFTAN(), |
|
| 57 |
'ACTION_URL' => $oReg->AppUrl.'account/login.php', |
|
| 58 |
'FORGOT_URL' => $oReg->AppUrl.'account/forgot.php', |
|
| 59 |
'REDIRECT_URL' => $thisApp->redirect_url, |
|
| 60 |
'WB_URL' => $oReg->AppUrl, |
|
| 61 |
'THEME_URL' => $oReg->ThemeUrl, |
|
| 62 |
'TEMPLATE_URL' => $oReg->TemplateDir, |
|
| 63 |
'HTTP_REFERER' => $thisApp->redirect_url, |
|
| 64 |
'CSS_BLOCK' => $sIncludeHeadLinkCss, |
|
| 65 |
'MESSAGE_VALUE' => '', |
|
| 66 |
'ERROR_VALUE' => '', |
|
| 67 |
'THISAPP_MESSAGE_VALUE' => $thisApp->message, |
|
| 68 |
'USER_FIELDNAME' => $username_fieldname, |
|
| 69 |
'PASSWORD_FIELDNAME' => $password_fieldname, |
|
| 70 |
) |
|
| 71 |
); |
|
| 86 | 72 |
|
| 87 |
$oTpl->set_block('main_block', 'show_smart_login_block', 'show_smart_login');
|
|
| 88 |
// $oTpl->parse('show_smart_login', '');
|
|
| 89 |
if($username_fieldname != 'username') {
|
|
| 90 |
$oTpl->set_var(array(
|
|
| 91 |
'TEXT_REMEMBER_ME' => $TEXT['REMEMBER_ME'],
|
|
| 92 |
)
|
|
| 93 |
);
|
|
| 73 |
$oTpl->set_block('main_block', 'show_smart_login_block', 'show_smart_login');
|
|
| 74 |
// $oTpl->parse('show_smart_login', '');
|
|
| 75 |
if($username_fieldname != 'username') {
|
|
| 76 |
$oTpl->parse('show_smart_login', 'show_smart_login_block', true);
|
|
| 77 |
} else {
|
|
| 78 |
$oTpl->set_block('show_smart_login', '');
|
|
| 79 |
}
|
|
| 94 | 80 |
|
| 95 |
$oTpl->parse('show_smart_login', 'show_smart_login_block', true);
|
|
| 96 |
} else {
|
|
| 97 |
$oTpl->set_block('show_smart_login', '');
|
|
| 98 |
} |
|
| 81 |
//$oTpl->parse('message', 'message_block', true);
|
|
| 82 |
$oTpl->parse('main', 'main_block', false);
|
|
| 83 |
$output = $oTpl->finish($oTpl->parse('output', 'page'));
|
|
| 84 |
unset($oTpl); |
|
| 85 |
print $output; |
|
| 99 | 86 |
|
| 100 |
//$oTpl->parse('message', 'message_block', true);
|
|
| 101 |
$oTpl->parse('main', 'main_block', false);
|
|
| 102 |
$output = $oTpl->finish($oTpl->parse('output', 'page'));
|
|
| 103 |
unset($oTpl); |
|
| 104 |
print $output; |
|
| 105 |
|
|
| branches/2.8.x/wb/account/login.php | ||
|---|---|---|
| 15 | 15 |
* |
| 16 | 16 |
*/ |
| 17 | 17 |
|
| 18 |
// Include config file |
|
| 19 |
$config_file = realpath('../config.php');
|
|
| 20 |
if(file_exists($config_file) && !defined('WB_URL'))
|
|
| 21 |
{
|
|
| 22 |
require_once($config_file); |
|
| 23 |
} |
|
| 18 |
// Include the configuration file |
|
| 19 |
$sStartFile = dirname(__DIR__).'/framework/initialize.php'; |
|
| 20 |
if (!defined('SYSTEM_RUN')) { require($sStartFile); }
|
|
| 21 |
require_once($oReg->AppPath.'framework/functions.php'); |
|
| 24 | 22 |
|
| 25 |
//if(!class_exists('login', false)){ include(WB_PATH.'/framework/class.login.php'); }
|
|
| 26 |
//if(!class_exists('frontend', false)){ include(WB_PATH.'/framework/class.frontend.php'); }
|
|
| 27 |
|
|
| 28 |
require_once(WB_PATH.'/framework/functions.php'); |
|
| 29 |
|
|
| 30 | 23 |
$wb = new frontend(false); |
| 31 | 24 |
|
| 32 | 25 |
// Make sure the login is enabled |
| 33 |
if(!FRONTEND_LOGIN) {
|
|
| 34 |
header('Location: '.WB_URL.'/');
|
|
| 35 |
exit(0); |
|
| 36 |
// if(INTRO_PAGE) {
|
|
| 37 |
// header('Location: '.WB_URL.PAGES_DIRECTORY.'/index.php');
|
|
| 38 |
// exit(0); |
|
| 39 |
// } else {
|
|
| 40 |
// } |
|
| 26 |
if(!$oReg->FrontendLogin) {
|
|
| 27 |
header('Location: '.$oReg->AppUrl);
|
|
| 28 |
exit; |
|
| 41 | 29 |
} |
| 30 |
$page_id = |
|
| 31 |
isset($oReg->ReferrerId) |
|
| 32 |
? $oReg->ReferrerId |
|
| 33 |
: isset($_SESSION['PAGE_ID']) ? $_SESSION['PAGE_ID'] : 0; |
|
| 42 | 34 |
|
| 43 |
$page_id = defined('REFERRER_ID') ? REFERRER_ID : isset($_SESSION['PAGE_ID']) ? $_SESSION['PAGE_ID'] : 0;
|
|
| 44 |
|
|
| 45 | 35 |
// Required page details |
| 46 | 36 |
$page_description = ''; |
| 47 | 37 |
$page_keywords = ''; |
| 48 | 38 |
// Work out level |
| 49 |
$level = ($page_id > 0 )? level_count($page_id): $page_id;
|
|
| 39 |
$level = ($page_id > 0 ) ? level_count($page_id) : $page_id;
|
|
| 50 | 40 |
// Work out root parent |
| 51 |
$root_parent = ($page_id > 0 )? root_parent($page_id): $page_id;
|
|
| 41 |
$root_parent = ($page_id > 0 ) ? root_parent($page_id) : $page_id;
|
|
| 52 | 42 |
|
| 53 | 43 |
define('PAGE_ID', $page_id);
|
| 54 | 44 |
define('ROOT_PARENT', $root_parent);
|
| 55 | 45 |
define('PARENT', 0);
|
| 56 | 46 |
define('LEVEL', $level);
|
| 57 | 47 |
|
| 58 |
define('PAGE_TITLE', $TEXT['PLEASE_LOGIN']);
|
|
| 59 |
define('MENU_TITLE', $TEXT['PLEASE_LOGIN']);
|
|
| 48 |
define('PAGE_TITLE', $oTrans->TEXT_PLEASE_LOGIN);
|
|
| 49 |
define('MENU_TITLE', $oTrans->TEXT_PLEASE_LOGIN);
|
|
| 60 | 50 |
define('VISIBILITY', 'public');
|
| 61 | 51 |
// Set the page content include file |
| 62 |
define('PAGE_CONTENT', WB_PATH.'/account/login_form.php');
|
|
| 52 |
define('PAGE_CONTENT', $oReg->AppPath.'account/login_form.php');
|
|
| 63 | 53 |
|
| 64 | 54 |
// Create new login app |
| 65 | 55 |
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']); |
| 66 |
$redirect = strip_tags(isset(${$requestMethod}['redirect']) ? ${$requestMethod}['redirect'] : '');
|
|
| 56 |
$sRedirect = strip_tags(isset(${$requestMethod}['redirect']) ? ${$requestMethod}['redirect'] : '');
|
|
| 67 | 57 |
//$redirect = ( (empty($redirect)) ? $_SERVER['HTTP_REFERER'] : $redirect); |
| 68 |
$_SESSION['HTTP_REFERER'] = str_replace(WB_URL,'',$redirect);
|
|
| 58 |
$_SESSION['HTTP_REFERER'] = str_replace($oReg->AppUrl,'/',$sRedirect);
|
|
| 69 | 59 |
|
| 70 |
$loginUrl = WB_URL.'/account/login.php';
|
|
| 71 |
$loginUrl .= (!empty($redirect) ? '?redirect=' .$_SESSION['HTTP_REFERER'] : '');
|
|
| 60 |
$sLoginUrl = $oReg->AppUrl.'account/login.php';
|
|
| 61 |
$sLoginUrl .= (!empty($sRedirect) ? '?redirect=' .$_SESSION['HTTP_REFERER'] : '');
|
|
| 72 | 62 |
|
| 73 |
$WarningUrl = str_replace(WB_PATH,WB_URL,$wb->correct_theme_source('warning.html'));
|
|
| 63 |
$sWarningUrl = str_replace($oReg->AppPath, $oReg->AppUrl, $wb->correct_theme_source('warning.html'));
|
|
| 74 | 64 |
// Setup template object, parse vars to it, then parse it |
| 75 |
$ThemePath = realpath(WB_PATH.$wb->correct_theme_source('loginBox.htt'));
|
|
| 65 |
$sThemePath = realpath($oReg->AppPath . ltrim($wb->correct_theme_source('loginBox.htt'), '/'));
|
|
| 76 | 66 |
|
| 77 | 67 |
$thisApp = new Login( |
| 78 |
array( |
|
| 79 |
"MAX_ATTEMPS" => "3", |
|
| 80 |
"WARNING_URL" => $WarningUrl, |
|
| 81 |
"USERNAME_FIELDNAME" => 'username', |
|
| 82 |
"PASSWORD_FIELDNAME" => 'password', |
|
| 83 |
"REMEMBER_ME_OPTION" => SMART_LOGIN, |
|
| 84 |
"MIN_USERNAME_LEN" => "2", |
|
| 85 |
"MIN_PASSWORD_LEN" => "2", |
|
| 86 |
"MAX_USERNAME_LEN" => "30", |
|
| 87 |
"MAX_PASSWORD_LEN" => "30", |
|
| 88 |
"LOGIN_URL" => $loginUrl, |
|
| 89 |
"DEFAULT_URL" => WB_URL."/index.php", |
|
| 90 |
"TEMPLATE_DIR" => $ThemePath, |
|
| 91 |
"TEMPLATE_FILE" => "login.htt", |
|
| 92 |
"FRONTEND" => true, |
|
| 93 |
"FORGOTTEN_DETAILS_APP" => WB_URL."/account/forgot.php", |
|
| 94 |
"USERS_TABLE" => TABLE_PREFIX."users", |
|
| 95 |
"GROUPS_TABLE" => TABLE_PREFIX."groups", |
|
| 96 |
"REDIRECT_URL" => $redirect |
|
| 97 |
) |
|
| 98 |
); |
|
| 99 |
|
|
| 68 |
array( |
|
| 69 |
'MAX_ATTEMPS' => 3, |
|
| 70 |
'WARNING_URL' => $sWarningUrl, |
|
| 71 |
'USERNAME_FIELDNAME' => 'username', |
|
| 72 |
'PASSWORD_FIELDNAME' => 'password', |
|
| 73 |
'REMEMBER_ME_OPTION' => $oReg->SmartLogin, |
|
| 74 |
'MIN_USERNAME_LEN' => 2, |
|
| 75 |
'MIN_PASSWORD_LEN' => 3, |
|
| 76 |
'MAX_USERNAME_LEN' => 100, |
|
| 77 |
'MAX_PASSWORD_LEN' => 100, |
|
| 78 |
'LOGIN_URL' => $sLoginUrl, |
|
| 79 |
'DEFAULT_URL' => $oReg->AppUrl.'index.php', |
|
| 80 |
'TEMPLATE_DIR' => $sThemePath, |
|
| 81 |
'TEMPLATE_FILE' => 'login.htt', |
|
| 82 |
'FRONTEND' => true, |
|
| 83 |
'FORGOTTEN_DETAILS_APP' => $oReg->AppUrl.'/account/forgot.php', |
|
| 84 |
'USERS_TABLE' => $oDb->TablePrefix.'users', |
|
| 85 |
'GROUPS_TABLE' => $oDb->TablePrefix.'groups', |
|
| 86 |
'REDIRECT_URL' => $sRedirect |
|
| 87 |
) |
|
| 88 |
); |
|
| 100 | 89 |
// Set extra outsider var |
| 101 | 90 |
$globals[] = 'thisApp'; |
| 102 |
|
|
| 103 | 91 |
// Include the index (wrapper) file |
| 104 |
require(WB_PATH.'/index.php'); |
|
| 92 |
require($oReg->AppPath.'index.php'); |
|
| branches/2.8.x/wb/framework/class.Login.php | ||
|---|---|---|
| 14 | 14 |
* @lastmodified $Date$ |
| 15 | 15 |
* |
| 16 | 16 |
*/ |
| 17 |
/* -------------------------------------------------------- */ |
|
| 18 |
// Must include code to stop this file being accessed directly |
|
| 19 |
if(!defined('WB_PATH')) {
|
|
| 20 |
require_once(dirname(__FILE__).'/globalExceptionHandler.php'); |
|
| 21 |
throw new IllegalFileException(); |
|
| 22 |
} |
|
| 23 |
/* -------------------------------------------------------- */ |
|
| 24 | 17 |
define('LOGIN_CLASS_LOADED', true);
|
| 25 | 18 |
|
| 26 | 19 |
// Get WB version |
| 27 | 20 |
require_once(ADMIN_PATH.'/interface/version.php'); |
| 28 | 21 |
|
| 29 | 22 |
class Login extends admin {
|
| 30 |
public function __construct($config_array) {
|
|
| 31 |
// Get language vars |
|
| 32 |
global $MESSAGE, $database; |
|
| 33 |
parent::__construct(); |
|
| 34 |
// Get configuration values |
|
| 35 |
while(list($key, $value) = each($config_array)) {
|
|
| 36 |
$this->{(strtolower($key))} = $value;
|
|
| 37 |
} |
|
| 38 |
if(!isset($this->redirect_url)) { $this->redirect_url = ''; }
|
|
| 39 |
// Get the supplied username and password |
|
| 40 |
if ($this->get_post('username_fieldname') != ''){
|
|
| 41 |
$username_fieldname = $this->get_post('username_fieldname');
|
|
| 42 |
$password_fieldname = $this->get_post('password_fieldname');
|
|
| 43 |
} else {
|
|
| 44 |
$username_fieldname = 'username'; |
|
| 45 |
$password_fieldname = 'password'; |
|
| 46 |
} |
|
| 47 | 23 |
|
| 48 |
if( is_array($this->get_post($username_fieldname) ) ) {
|
|
| 49 |
$_POST[$username_fieldname]=implode(',',$this->get_post($username_fieldname));
|
|
| 50 |
} |
|
| 51 |
$this->username = htmlspecialchars (strtolower( $this->get_post($username_fieldname) ), ENT_QUOTES); |
|
| 24 |
const PASS_CHARS = '\w!#$%&*+\-.:=?@\|'; |
|
| 25 |
const USER_CHARS = 'a-z0-9&\-.=@_'; |
|
| 52 | 26 |
|
| 53 |
if( is_array($this->get_post($password_fieldname) ) ) {
|
|
| 54 |
$_POST[$password_fieldname]=implode(',',$this->get_post($password_fieldname));
|
|
| 55 |
}
|
|
| 56 |
$this->password = $this->get_post($password_fieldname);
|
|
| 27 |
protected $oReg = null;
|
|
| 28 |
protected $oDb = null;
|
|
| 29 |
protected $oTrans = null;
|
|
| 30 |
protected $message = '';
|
|
| 57 | 31 |
|
| 58 |
// Figure out if the "remember me" option has been checked |
|
| 59 |
if($this->get_post('remember') == 'true') {
|
|
| 60 |
$this->remember = $this->get_post('remember');
|
|
| 61 |
} else {
|
|
| 62 |
$this->remember = false; |
|
| 63 |
} |
|
| 64 |
// Get the length of the supplied username and password |
|
| 65 |
if($this->get_post($username_fieldname) != '') {
|
|
| 66 |
$this->username_len = strlen($this->username); |
|
| 67 |
$this->password_len = strlen($this->password); |
|
| 68 |
} |
|
| 32 |
public function __construct($config_array) |
|
| 33 |
{
|
|
| 34 |
$this->oReg = WbAdaptor::getInstance(); |
|
| 35 |
$this->oDb = $this->oReg->Db; |
|
| 36 |
$this->oTrans = $this->oReg->Trans; |
|
| 69 | 37 |
|
| 70 |
$aServerUrl = $this->mb_parse_url(WB_URL); |
|
| 71 |
|
|
| 72 |
$sServerUrl = $_SERVER['SERVER_NAME']; |
|
| 73 |
$sServerScheme = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : isset($aServerUrl['scheme']) ? $aServerUrl['scheme'] : ' http'; |
|
| 74 |
$sServerPath = $_SERVER['SCRIPT_NAME']; |
|
| 75 |
// If the url is blank, set it to the default url |
|
| 76 |
$this->url = $this->get_post('url');
|
|
| 38 |
parent::__construct(); |
|
| 39 |
// Get configuration values |
|
| 40 |
while(list($key, $value) = each($config_array)) {
|
|
| 41 |
$this->{(strtolower($key))} = $value;
|
|
| 42 |
} |
|
| 43 |
// calculate redirect URL |
|
| 44 |
if(!isset($this->redirect_url)) { $this->redirect_url = ''; }
|
|
| 45 |
$aServerUrl = $this->mb_parse_url($this->oReg->AppUrl); |
|
| 46 |
$sServerUrl = $_SERVER['SERVER_NAME']; |
|
| 47 |
$sServerScheme = |
|
| 48 |
isset($_SERVER['REQUEST_SCHEME']) |
|
| 49 |
? $_SERVER['REQUEST_SCHEME'] |
|
| 50 |
: isset($aServerUrl['scheme']) ? $aServerUrl['scheme'] : ' http'; |
|
| 51 |
$sServerPath = $_SERVER['SCRIPT_NAME']; |
|
| 52 |
// If the url is blank, set it to the default url |
|
| 53 |
$this->url = $this->get_post('url');
|
|
| 54 |
if (preg_match('/%0d|%0a|\s/i', $this->url)) {
|
|
| 55 |
throw new Exception('Warning: possible intruder detected on login');
|
|
| 56 |
} |
|
| 77 | 57 |
$aUrl = $this->mb_parse_url( $this->url ); |
| 78 |
$this->url = isset($aRedirecthUrl['host']) &&($sServerUrl==$aUrl['host']) ? $this->url:ADMIN_URL.'/start/index.php'; |
|
| 79 |
if ($this->redirect_url!='') {
|
|
| 58 |
$this->url = |
|
| 59 |
isset($aRedirecthUrl['host']) &&($sServerUrl == $aUrl['host']) |
|
| 60 |
? $this->url |
|
| 61 |
: $this->oReg->AcpUrl.'start/index.php'; |
|
| 62 |
if ($this->redirect_url!='') {
|
|
| 80 | 63 |
$aRedirecthUrl = $this->mb_parse_url( $this->redirect_url ); |
| 81 |
$this->redirect_url = isset($aRedirecthUrl['host']) &&($sServerUrl==$aRedirecthUrl['host']) ? $this->redirect_url:$sServerScheme.'://'.$sServerUrl; |
|
| 82 |
$this->url = $this->redirect_url; |
|
| 83 |
} |
|
| 84 |
if(strlen($this->url) < 2) {
|
|
| 64 |
$this->redirect_url = |
|
| 65 |
isset($aRedirecthUrl['host']) &&($sServerUrl==$aRedirecthUrl['host']) |
|
| 66 |
? $this->redirect_url |
|
| 67 |
: $sServerScheme.'://'.$sServerUrl; |
|
| 68 |
$this->url = $this->redirect_url; |
|
| 69 |
} |
|
| 70 |
if(strlen($this->url) < 2) {
|
|
| 85 | 71 |
$aDefaultUrl = $this->mb_parse_url( $this->default_url ); |
| 86 |
$this->default_url = isset($aDefaultUrl['host']) &&($sServerUrl==$aDefaultUrl['host']) ? $this->default_url:$sServerScheme.'://'.$sServerUrl; |
|
| 87 |
$this->url = $this->default_url; |
|
| 88 |
} |
|
| 72 |
$this->default_url = |
|
| 73 |
isset($aDefaultUrl['host']) &&($sServerUrl==$aDefaultUrl['host']) |
|
| 74 |
? $this->default_url |
|
| 75 |
: $sServerScheme.'://'.$sServerUrl; |
|
| 76 |
$this->url = $this->default_url; |
|
| 77 |
} |
|
| 78 |
// get username & password and validate it |
|
| 79 |
$username_fieldname = (string)$this->get_post('username_fieldname');
|
|
| 80 |
$username_fieldname = (preg_match('/^_?[a-z][\w]+$/i', $username_fieldname) ? $username_fieldname : 'username');
|
|
| 81 |
$sUsername = strtolower(trim((string)$this->get_post($username_fieldname))); |
|
| 82 |
$this->username = (preg_match( |
|
| 83 |
'/^['.self::USER_CHARS.']{'.$this->min_username_len.','.$this->max_username_len.'}$/is',
|
|
| 84 |
$sUsername |
|
| 85 |
) ? $sUsername : ''); |
|
| 86 |
$password_fieldname = (string)$this->get_post('password_fieldname');
|
|
| 87 |
$password_fieldname = (preg_match('/^_?[a-z][\w]+$/i', $password_fieldname) ? $password_fieldname : 'password');
|
|
| 89 | 88 |
|
| 90 |
if($this->is_authenticated() == true) {
|
|
| 91 |
// User already logged-in, so redirect to default url |
|
| 92 |
$this->send_header($this->url); |
|
| 93 |
} elseif($this->is_remembered() == true) {
|
|
| 94 |
// User has been "remembered" |
|
| 95 |
// Get the users password |
|
| 96 |
// $database = new database(); |
|
| 97 |
$sql = 'SELECT * FROM `'.$this->users_table.'` '; |
|
| 98 |
$sql .= 'WHERE `user_id`=\''.$this->get_safe_remember_key().'\''; |
|
| 99 |
$query_details = $database->query($sql); |
|
| 100 |
$fetch_details = $query_details->fetchRow(MYSQL_ASSOC); |
|
| 101 |
$this->username = $fetch_details['username']; |
|
| 102 |
$this->password = $fetch_details['password']; |
|
| 103 |
// Check if the user exists (authenticate them) |
|
| 104 |
if($this->authenticate()) {
|
|
| 105 |
// Authentication successful |
|
| 106 |
$this->send_header($this->url); |
|
| 107 |
} else {
|
|
| 108 |
$this->message = $MESSAGE['LOGIN_AUTHENTICATION_FAILED']; |
|
| 109 |
$this->increase_attemps(); |
|
| 110 |
} |
|
| 111 |
} elseif($this->username == '' AND $this->password == '') {
|
|
| 112 |
$this->message = $MESSAGE['LOGIN_BOTH_BLANK']; |
|
| 113 |
$this->display_login(); |
|
| 114 |
} elseif($this->username == '') {
|
|
| 115 |
$this->message = $MESSAGE['LOGIN_USERNAME_BLANK']; |
|
| 116 |
$this->increase_attemps(); |
|
| 117 |
} elseif($this->password == '') {
|
|
| 118 |
$this->message = $MESSAGE['LOGIN_PASSWORD_BLANK']; |
|
| 119 |
$this->increase_attemps(); |
|
| 120 |
} elseif($this->username_len < $config_array['MIN_USERNAME_LEN']) {
|
|
| 121 |
$this->message = $MESSAGE['LOGIN_USERNAME_TOO_SHORT']; |
|
| 122 |
$this->increase_attemps(); |
|
| 123 |
} elseif($this->password_len < $config_array['MIN_PASSWORD_LEN']) {
|
|
| 124 |
$this->message = $MESSAGE['LOGIN_PASSWORD_TOO_SHORT']; |
|
| 125 |
$this->increase_attemps(); |
|
| 126 |
} elseif($this->username_len > $config_array['MAX_USERNAME_LEN']) {
|
|
| 127 |
$this->message = $MESSAGE['LOGIN_USERNAME_TOO_LONG']; |
|
| 128 |
$this->increase_attemps(); |
|
| 129 |
} elseif($this->password_len > $config_array['MAX_PASSWORD_LEN']) {
|
|
| 130 |
$this->message = $MESSAGE['LOGIN_PASSWORD_TOO_LONG']; |
|
| 131 |
$this->increase_attemps(); |
|
| 132 |
} else {
|
|
| 133 |
// Check if the user exists (authenticate them) |
|
| 134 |
$this->password = md5($this->password); |
|
| 135 |
if($this->authenticate()) {
|
|
| 136 |
// Authentication successful |
|
| 137 |
$this->send_header($this->url); |
|
| 138 |
} else {
|
|
| 139 |
$this->message = $MESSAGE['LOGIN_AUTHENTICATION_FAILED']; |
|
| 140 |
$this->increase_attemps(); |
|
| 141 |
} |
|
| 142 |
} |
|
| 143 |
} |
|
| 89 |
if ($this->username) {
|
|
| 90 |
/** @TODO implement crypting */ |
|
| 91 |
$this->password = md5(trim((string)$this->get_post($password_fieldname))); |
|
| 92 |
// Figure out if the "remember me" option has been checked |
|
| 93 |
$this->remember = (@$_POST['remember'] == 'true' ? true : false); |
|
| 94 |
// try to authenticate |
|
| 95 |
$bSuccess = false; |
|
| 96 |
if (!($bSuccess = $this->is_authenticated())) {
|
|
| 97 |
if ($this->is_remembered()) {
|
|
| 98 |
$sql = 'SELECT * FROM `'.$this->oDb->TablePrefix.'users` ' |
|
| 99 |
. 'WHERE `user_id`='.$this->get_safe_remember_key(); |
|
| 100 |
if (($oUsers = $this->oDb->doQuery($sql))) {
|
|
| 101 |
if (($aUser = $oUsers->fetchArray())) {
|
|
| 102 |
$this->username = $aUser['username']; |
|
| 103 |
$this->password = $aUser['password']; |
|
| 104 |
// Check if the user exists (authenticate them) |
|
| 105 |
$bSuccess = $this->authenticate(); |
|
| 106 |
} |
|
| 107 |
} |
|
| 108 |
} else {
|
|
| 109 |
// Check if the user exists (authenticate them) |
|
| 110 |
$bSuccess = $this->authenticate(); |
|
| 111 |
} |
|
| 112 |
} |
|
| 113 |
if ($bSuccess) {
|
|
| 114 |
// Authentication successful |
|
| 115 |
$this->send_header($this->url); |
|
| 116 |
} else {
|
|
| 117 |
$this->message = $this->oTrans->MESSAGE_LOGIN_AUTHENTICATION_FAILED; |
|
| 118 |
$this->increase_attemps(); |
|
| 119 |
} |
|
| 120 |
} else {
|
|
| 121 |
$this->display_login(); |
|
| 122 |
} |
|
| 123 |
} |
|
| 144 | 124 |
|
| 145 |
// Authenticate the user (check if they exist in the database) |
|
| 146 |
function authenticate() {
|
|
| 147 |
global $database; |
|
| 148 |
// Get user information |
|
| 149 |
// $database = new database(); |
|
| 150 |
// $query = 'SELECT * FROM `'.$this->users_table.'` WHERE MD5(`username`) = "'.md5($this->username).'" AND `password` = "'.$this->password.'" AND `active` = 1'; |
|
| 151 |
$loginname = ( preg_match('/[\;\=\&\|\<\> ]/',$this->username) ? '' : $this->username );
|
|
| 152 |
$sql = 'SELECT * FROM `'.$this->users_table.'` '; |
|
| 153 |
$sql .= 'WHERE `username`=\''.$loginname.'\' AND `password`=\''.$this->password.'\' AND `active`=1'; |
|
| 154 |
$results = $database->query($sql); |
|
| 155 |
$results_array = $results->fetchRow(MYSQL_ASSOC); |
|
| 156 |
$num_rows = $results->numRows(); |
|
| 157 |
if($num_rows == 1) {
|
|
| 158 |
$user_id = $results_array['user_id']; |
|
| 159 |
$this->user_id = $user_id; |
|
| 160 |
$_SESSION['USER_ID'] = $user_id; |
|
| 161 |
$_SESSION['GROUP_ID'] = $results_array['group_id']; |
|
| 162 |
$_SESSION['GROUPS_ID'] = $results_array['groups_id']; |
|
| 163 |
$_SESSION['USERNAME'] = $results_array['username']; |
|
| 164 |
$_SESSION['DISPLAY_NAME'] = $results_array['display_name']; |
|
| 165 |
$_SESSION['EMAIL'] = $results_array['email']; |
|
| 166 |
$_SESSION['HOME_FOLDER'] = $results_array['home_folder']; |
|
| 167 |
// Run remember function if needed |
|
| 168 |
if($this->remember == true) {
|
|
| 169 |
$this->remember($this->user_id); |
|
| 170 |
} |
|
| 171 |
// Set language |
|
| 172 |
if($results_array['language'] != '') {
|
|
| 173 |
$_SESSION['LANGUAGE'] = $results_array['language']; |
|
| 174 |
} |
|
| 175 |
// Set timezone |
|
| 176 |
if($results_array['timezone'] != '-72000') {
|
|
| 177 |
$_SESSION['TIMEZONE'] = $results_array['timezone']; |
|
| 178 |
} else {
|
|
| 179 |
// Set a session var so apps can tell user is using default tz |
|
| 180 |
$_SESSION['USE_DEFAULT_TIMEZONE'] = true; |
|
| 181 |
} |
|
| 182 |
// Set date format |
|
| 183 |
if($results_array['date_format'] != '') {
|
|
| 184 |
$_SESSION['DATE_FORMAT'] = $results_array['date_format']; |
|
| 185 |
} else {
|
|
| 186 |
// Set a session var so apps can tell user is using default date format |
|
| 187 |
$_SESSION['USE_DEFAULT_DATE_FORMAT'] = true; |
|
| 188 |
} |
|
| 189 |
// Set time format |
|
| 190 |
if($results_array['time_format'] != '') {
|
|
| 191 |
$_SESSION['TIME_FORMAT'] = $results_array['time_format']; |
|
| 192 |
} else {
|
|
| 193 |
// Set a session var so apps can tell user is using default time format |
|
| 194 |
$_SESSION['USE_DEFAULT_TIME_FORMAT'] = true; |
|
| 195 |
} |
|
| 125 |
// Authenticate the user (check if they exist in the database) |
|
| 126 |
function authenticate() |
|
| 127 |
{
|
|
| 128 |
// Get user information |
|
| 129 |
$loginname = ( preg_match('/^['.self::USER_CHARS.']+$/s',$this->username) ? $this->username : '0');
|
|
| 130 |
$aSettings = array(); |
|
| 131 |
$aSettings['SYSTEM_PERMISSIONS'] = array(); |
|
| 132 |
$aSettings['MODULE_PERMISSIONS'] = array(); |
|
| 133 |
$aSettings['TEMPLATE_PERMISSIONS'] = array(); |
|
| 134 |
$bRetval = false; |
|
| 196 | 135 |
|
| 197 |
// Get group information |
|
| 198 |
$_SESSION['SYSTEM_PERMISSIONS'] = array(); |
|
| 199 |
$_SESSION['MODULE_PERMISSIONS'] = array(); |
|
| 200 |
$_SESSION['TEMPLATE_PERMISSIONS'] = array(); |
|
| 201 |
$_SESSION['GROUP_NAME'] = array(); |
|
| 202 |
|
|
| 203 |
$aGroupsIds = ((explode(',', $this->get_session('GROUPS_ID'))));
|
|
| 204 |
$bOnlyAdminGroup = $this->ami_group_member('1') && (sizeof($aGroupsIds) == 1);
|
|
| 205 |
$first_group = true; |
|
| 206 |
|
|
| 207 |
foreach ( $aGroupsIds as $cur_group_id) |
|
| 208 |
{
|
|
| 209 |
$sql = 'SELECT * FROM `'.$this->groups_table.'` WHERE `group_id`=\''.$cur_group_id.'\''; |
|
| 210 |
if($results = $database->query($sql)) {
|
|
| 211 |
$results_array = $results->fetchRow(MYSQL_ASSOC); |
|
| 212 |
$_SESSION['GROUP_NAME'][$cur_group_id] = $results_array['name']; |
|
| 213 |
} |
|
| 214 |
|
|
| 215 |
// Set system permissions |
|
| 216 |
if( ($results_array['system_permissions'] != '') ) {
|
|
| 217 |
switch ($cur_group_id) : |
|
| 218 |
case 1: |
|
| 219 |
if( $this->user_id == 1) {
|
|
| 220 |
$_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $results_array['system_permissions']));
|
|
| 136 |
$sql = 'SELECT * FROM `'.$this->oDb->TablePrefix.'users` ' |
|
| 137 |
. 'WHERE `username`=\''.$this->oDb->escapeString($loginname).'\''; |
|
| 138 |
if (($oUser = $this->oDb->doQuery($sql))) {
|
|
| 139 |
if (($aUser = $oUser->fetchArray())) {
|
|
| 140 |
if ( |
|
| 141 |
$aUser['password'] == $this->password && |
|
| 142 |
$aUser['active'] == 1 |
|
| 143 |
) {
|
|
| 144 |
// valide authentcation !! |
|
| 145 |
$user_id = $aUser['user_id']; |
|
| 146 |
$this->user_id = $user_id; |
|
| 147 |
$aSettings['USER_ID'] = $user_id; |
|
| 148 |
$aSettings['GROUP_ID'] = $aUser['group_id']; |
|
| 149 |
$aSettings['GROUPS_ID'] = $aUser['groups_id']; |
|
| 150 |
$aSettings['USERNAME'] = $aUser['username']; |
|
| 151 |
$aSettings['DISPLAY_NAME'] = $aUser['display_name']; |
|
| 152 |
$aSettings['EMAIL'] = $aUser['email']; |
|
| 153 |
$aSettings['HOME_FOLDER'] = $aUser['home_folder']; |
|
| 154 |
// Run remember function if needed |
|
| 155 |
if($this->remember == true) {
|
|
| 156 |
$this->remember($this->user_id); |
|
| 157 |
} |
|
| 158 |
// Set language |
|
| 159 |
if($aUser['language'] != '') {
|
|
| 160 |
$aSettings['LANGUAGE'] = $aUser['language']; |
|
| 161 |
} |
|
| 162 |
// Set timezone |
|
| 163 |
if($aUser['timezone'] != '-72000') {
|
|
| 164 |
$aSettings['TIMEZONE'] = $aUser['timezone']; |
|
| 165 |
} else {
|
|
| 166 |
// Set a session var so apps can tell user is using default tz |
|
| 167 |
$aSettings['USE_DEFAULT_TIMEZONE'] = true; |
|
| 168 |
} |
|
| 169 |
// Set date format |
|
| 170 |
if($aUser['date_format'] != '') {
|
|
| 171 |
$aSettings['DATE_FORMAT'] = $aUser['date_format']; |
|
| 172 |
} else {
|
|
| 173 |
// Set a session var so apps can tell user is using default date format |
|
| 174 |
$aSettings['USE_DEFAULT_DATE_FORMAT'] = true; |
|
| 175 |
} |
|
| 176 |
// Set time format |
|
| 177 |
if($aUser['time_format'] != '') {
|
|
| 178 |
$aSettings['TIME_FORMAT'] = $aUser['time_format']; |
|
| 179 |
} else {
|
|
| 180 |
// Set a session var so apps can tell user is using default time format |
|
| 181 |
$aSettings['USE_DEFAULT_TIME_FORMAT'] = true; |
|
| 182 |
} |
|
| 183 |
// Get group information |
|
| 184 |
$aSettings['GROUP_NAME'] = array(); |
|
| 185 |
$bOnlyAdminGroup = $this->ami_group_member('1') && (sizeof($aGroupsIds) == 1);
|
|
| 186 |
$sql = 'SELECT * FROM `'.$this->oDb->TablePrefix.'groups` ' |
|
| 187 |
. 'WHERE `group_id` IN (\''.$aUser['groups_id'].',0\') ' |
|
| 188 |
. 'ORDER BY `group_id`'; |
|
| 189 |
if (($oGroups = $this->oDb->doQuery($sql))) {
|
|
| 190 |
while (($aGroup = $oGroups->fetchArray())) {
|
|
| 191 |
$aSettings['GROUP_NAME'][$aGroup['group_id']] = $aGroup['name']; |
|
| 192 |
// collect system_permissions (additively) |
|
| 193 |
$aSettings['SYSTEM_PERMISSIONS'] = array_merge( |
|
| 194 |
$aSettings['SYSTEM_PERMISSIONS'], |
|
| 195 |
explode(',', $aGroup['system_permissions'])
|
|
| 196 |
); |
|
| 197 |
// collect module_permission (subtractive) |
|
| 198 |
if (!sizeof($aSettings['MODULE_PERMISSIONS'])) {
|
|
| 199 |
$aSettings['MODULE_PERMISSIONS'] = explode(',', $aGroup['module_permissions']);
|
|
| 221 | 200 |
} else {
|
| 222 |
$_SESSION['SYSTEM_PERMISSIONS'] = explode(',', $results_array['system_permissions']);
|
|
| 201 |
$aSettings['MODULE_PERMISSIONS'] = array_intersect( |
|
| 202 |
$aSettings['MODULE_PERMISSIONS'], |
|
| 203 |
preg_split('/\s*[,;\|\+]/', $aGroup['module_permissions'], -1, PREG_SPLIT_NO_EMPTY)
|
|
| 204 |
); |
|
| 223 | 205 |
} |
| 206 |
// collect template_permission (subtractive) |
|
| 207 |
if (!sizeof($aSettings['TEMPLATE_PERMISSIONS'])) {
|
|
| 208 |
$aSettings['TEMPLATE_PERMISSIONS'] = explode(',', $aGroup['template_permissions']);
|
|
| 209 |
} else {
|
|
| 210 |
$aSettings['TEMPLATE_PERMISSIONS'] = array_intersect( |
|
| 211 |
$aSettings['TEMPLATE_PERMISSIONS'], |
|
| 212 |
preg_split('/\s*[,;\|\+]/', $aGroup['template_permissions'], -1, PREG_SPLIT_NO_EMPTY)
|
|
| 213 |
); |
|
| 214 |
} |
|
| 215 |
} |
|
| 216 |
} |
|
| 217 |
// Update the users table with current ip and timestamp |
|
| 218 |
$sRemoteAddress = @$_SERVER['REMOTE_ADDR'] ?: 'unknown'; |
|
| 219 |
$sql = 'UPDATE `'.$this->oDb->TablePrefix.'users` ' |
|
| 220 |
. 'SET `login_when`='.time().', ' |
|
| 221 |
. '`login_ip`=\''.$sRemoteAddress.'\' ' |
|
| 222 |
. 'WHERE `user_id`=\''.$user_id.'\''; |
|
| 223 |
$this->oDb->doQuery($sql); |
|
| 224 |
$bRetval = true; |
|
| 225 |
} |
|
| 226 |
} |
|
| 227 |
} |
|
| 228 |
// merge settings into $_SESSION and overwrite older one values |
|
| 229 |
$_SESSION = array_merge($_SESSION, $aSettings); |
|
| 230 |
// Return if the user exists or not |
|
| 231 |
return $bRetval; |
|
| 232 |
} |
|
| 224 | 233 |
|
| 225 |
break; |
|
| 226 |
default: |
|
| 227 |
$_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $results_array['system_permissions']));
|
|
| 228 |
endswitch; |
|
| 229 |
} |
|
| 234 |
// Increase the count for login attemps |
|
| 235 |
function increase_attemps() |
|
| 236 |
{
|
|
| 237 |
$_SESSION['ATTEMPS'] = (isset($_SESSION['ATTEMPS']) ? $_SESSION['ATTEMPS']++ : 0); |
|
| 238 |
$this->display_login(); |
|
| 239 |
} |
|
| 230 | 240 |
|
| 231 |
// Set module permissions |
|
| 232 |
if( $results_array['module_permissions'] != '' ) {
|
|
| 233 |
if ($first_group) {
|
|
| 234 |
$_SESSION['MODULE_PERMISSIONS'] = explode(',', $results_array['module_permissions']);
|
|
| 235 |
} else {
|
|
| 236 |
$_SESSION['MODULE_PERMISSIONS'] = array_intersect($_SESSION['MODULE_PERMISSIONS'], explode(',', $results_array['module_permissions']));
|
|
| 237 |
} |
|
| 238 |
} |
|
| 239 |
// Set template permissions |
|
| 240 |
if($results_array['template_permissions'] != '') {
|
|
| 241 |
if ($first_group) {
|
|
| 242 |
$_SESSION['TEMPLATE_PERMISSIONS'] = explode(',', $results_array['template_permissions']);
|
|
| 243 |
} else {
|
|
| 244 |
$_SESSION['TEMPLATE_PERMISSIONS'] = array_intersect($_SESSION['TEMPLATE_PERMISSIONS'], explode(',', $results_array['template_permissions']));
|
|
| 245 |
} |
|
| 246 |
} |
|
| 247 |
$first_group = false; |
|
| 248 |
} |
|
| 241 |
// Function to set a "remembering" cookie for the user - removed |
|
| 242 |
function remember($user_id) |
|
| 243 |
{
|
|
| 244 |
return true; |
|
| 245 |
} |
|
| 249 | 246 |
|
| 250 |
// if( $$bOnlyAdminGroup ) {
|
|
| 251 |
// $_SESSION['MODULE_PERMISSIONS'] = array(); |
|
| 252 |
// $_SESSION['TEMPLATE_PERMISSIONS'] = array(); |
|
| 253 |
// } |
|
| 247 |
// Function to check if a user has been remembered - removed |
|
| 248 |
function is_remembered() |
|
| 249 |
{
|
|
| 250 |
return false; |
|
| 251 |
} |
|
| 254 | 252 |
|
| 255 |
// Update the users table with current ip and timestamp |
|
| 256 |
$get_ts = time(); |
|
| 257 |
$get_ip = $_SERVER['REMOTE_ADDR']; |
|
| 258 |
$sql = 'UPDATE `'.$this->users_table.'` '; |
|
| 259 |
$sql .= 'SET `login_when`=\''.$get_ts.'\', `login_ip`=\''.$get_ip.'\' '; |
|
| 260 |
$sql .= 'WHERE `user_id`=\''.$user_id.'\''; |
|
| 261 |
$database->query($sql); |
|
| 262 |
}else {
|
|
| 263 |
$num_rows = 0; |
|
| 264 |
} |
|
| 265 |
// Return if the user exists or not |
|
| 266 |
return $num_rows; |
|
| 267 |
} |
|
| 253 |
// Display the login screen |
|
| 254 |
function display_login() |
|
| 255 |
{
|
|
| 256 |
// If attemps more than allowed, warn the user |
|
| 257 |
if($this->get_session('ATTEMPS') > $this->max_attemps) {
|
|
| 258 |
$this->warn(); |
|
| 259 |
} |
|
| 260 |
// Show the login form |
|
| 261 |
if($this->frontend != true) {
|
|
| 262 |
$template = new Template(dirname($this->correct_theme_source($this->template_file))); |
|
| 263 |
$template->set_file('page', $this->template_file);
|
|
| 264 |
$template->set_block('page', 'mainBlock', 'main');
|
|
| 265 |
$template->set_var('DISPLAY_REMEMBER_ME', ($this->remember_me_option ? '' : 'display: none;'));
|
|
| 266 |
$template->set_var($this->oTrans->getLangArray()); |
|
| 267 |
$template->set_var( |
|
| 268 |
array( |
|
| 269 |
'TITLE_LOGOUT' => $this->oTrans->MENU_LOGIN, |
|
| 270 |
'TITLE_VIEW' => $this->oTrans->TEXT_WEBSITE, |
|
| 271 |
'SECTION_NAME' => $this->oTrans->MENU_LOGIN, |
|
| 272 |
'SECTION_LOGIN' => $this->oTrans->MENU_LOGIN, |
|
| 273 |
'ACTION_URL' => $this->login_url, |
|
| 274 |
'URL' => $this->default_url, |
|
| 275 |
'ATTEMPS' => $this->get_session('ATTEMPS'),
|
|
| 276 |
'USERNAME' => $this->username, |
|
| 277 |
'USERNAME_FIELDNAME' => $this->username_fieldname, |
|
| 278 |
'PASSWORD_FIELDNAME' => $this->password_fieldname, |
|
| 279 |
'MESSAGE' => $this->message, |
|
| 280 |
'WEBSITE_TITLE' => $this->oReg->WebsiteTitle, |
|
| 281 |
'INTERFACE_DIR_URL' => $this->oReg->AcpUrl.'interface', |
|
| 282 |
'MAX_USERNAME_LEN' => $this->max_username_len, |
|
| 283 |
'MAX_PASSWORD_LEN' => $this->max_password_len, |
|
| 284 |
'ADMIN_URL' => $this->oReg->AcpUrl, |
|
| 285 |
'WB_URL' => $this->oReg->AppUrl, |
|
| 286 |
'URL_VIEW' => $this->oReg->AppUrl, |
|
| 287 |
'THEME_URL' => $this->oReg->ThemeUrl, |
|
| 288 |
'VERSION' => $this->oReg->Version, |
|
| 289 |
'SP' => (isset($this->oReg->Sp) ? $this->oReg->Sp : ''), |
|
| 290 |
'REVISION' => $this->oReg->Revision, |
|
| 291 |
'LANGUAGE' => strtolower($this->oReg->Language), |
|
| 292 |
'FORGOTTEN_DETAILS_APP' => $this->forgotten_details_app, |
|
| 293 |
'PAGES_DIRECTORY' => $this->oReg->PagesDir, |
|
| 294 |
'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '', |
|
| 295 |
'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '', |
|
| 296 |
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'], |
|
| 297 |
'LOGIN_ICON' => 'login', |
|
| 298 |
'START_ICON' => 'blank', |
|
| 299 |
'URL_HELP' => 'http://wiki.websitebaker.org/', |
|
| 300 |
) |
|
| 301 |
); |
|
| 302 |
$template->set_var('CHARSET', (isset($this->oReg->DefaultCharset) ? $this->oReg->DefaultCharset : 'utf-8'));
|
|
| 303 |
$template->parse('main', 'mainBlock', false);
|
|
| 304 |
$template->pparse('output', 'page');
|
|
| 305 |
} |
|
| 306 |
} |
|
| 307 |
// sanities the REMEMBER_KEY cookie to avoid SQL injection |
|
| 308 |
function get_safe_remember_key() |
|
| 309 |
{
|
|
| 310 |
$iMatches = 0; |
|
| 311 |
if (isset($_COOKIE['REMEMBER_KEY'])) {
|
|
| 312 |
$sRetval = preg_replace( |
|
| 313 |
'/^([0-9]{11})_([0-9a-f]{11})$/i',
|
|
| 314 |
'\1\2', |
|
| 315 |
$_COOKIE['REMEMBER_KEY'], -1, $iMatches |
|
| 316 |
); |
|
| 317 |
} |
|
| 318 |
return ($iMatches ? $sRetval : ''); |
|
| 319 |
} |
|
| 320 |
// Warn user that they have had to many login attemps |
|
| 321 |
function warn() |
|
| 322 |
{
|
|
| 323 |
$this->send_header($this->warning_url); |
|
| 324 |
exit; |
|
| 325 |
} |
|
| 268 | 326 |
|
| 269 |
// Increase the count for login attemps |
|
| 270 |
function increase_attemps() {
|
|
| 271 |
if(!isset($_SESSION['ATTEMPS'])) {
|
|
| 272 |
$_SESSION['ATTEMPS'] = 0; |
|
| 273 |
} else {
|
|
| 274 |
$_SESSION['ATTEMPS'] = $this->get_session('ATTEMPS')+1;
|
|
| 275 |
} |
|
| 276 |
$this->display_login(); |
|
| 277 |
} |
|
| 278 |
|
|
| 279 |
// Function to set a "remembering" cookie for the user - removed |
|
| 280 |
function remember($user_id) {
|
|
| 281 |
return true; |
|
| 282 |
} |
|
| 283 |
|
|
| 284 |
// Function to check if a user has been remembered - removed |
|
| 285 |
function is_remembered() |
|
| 286 |
{
|
|
| 287 |
return false; |
|
| 288 |
} |
|
| 289 |
|
|
| 290 |
// Display the login screen |
|
| 291 |
function display_login() {
|
|
| 292 |
// Get language vars |
|
| 293 |
global $MESSAGE, $MENU, $TEXT; |
|
| 294 |
// If attemps more than allowed, warn the user |
|
| 295 |
if($this->get_session('ATTEMPS') > $this->max_attemps) {
|
|
| 296 |
$this->warn(); |
|
| 297 |
} |
|
| 298 |
// Show the login form |
|
| 299 |
if($this->frontend != true) {
|
|
| 300 |
//require_once(WB_PATH.'/include/phplib/template.inc'); |
|
| 301 |
// $template = new Template($this->template_dir); |
|
| 302 |
// Setup template object, parse vars to it, then parse it |
|
| 303 |
$template = new Template(dirname($this->correct_theme_source($this->template_file))); |
|
| 304 |
$template->set_file('page', $this->template_file);
|
|
| 305 |
$template->set_block('page', 'mainBlock', 'main');
|
|
| 306 |
if($this->remember_me_option != true) {
|
|
| 307 |
$template->set_var('DISPLAY_REMEMBER_ME', 'display: none;');
|
|
| 308 |
} else {
|
|
| 309 |
$template->set_var('DISPLAY_REMEMBER_ME', '');
|
|
| 310 |
} |
|
| 311 |
$template->set_var(array( |
|
| 312 |
'ACTION_URL' => $this->login_url, |
|
| 313 |
'URL' => $this->default_url, |
|
| 314 |
'ATTEMPS' => $this->get_session('ATTEMPS'),
|
|
| 315 |
'USERNAME' => $this->username, |
|
| 316 |
'USERNAME_FIELDNAME' => $this->username_fieldname, |
|
| 317 |
'PASSWORD_FIELDNAME' => $this->password_fieldname, |
|
| 318 |
'MESSAGE' => $this->message, |
|
| 319 |
'WEBSITE_TITLE' => WEBSITE_TITLE, |
|
| 320 |
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'], |
|
| 321 |
'INTERFACE_DIR_URL' => ADMIN_URL.'/interface', |
|
| 322 |
'MAX_USERNAME_LEN' => $this->max_username_len, |
|
| 323 |
'MAX_PASSWORD_LEN' => $this->max_password_len, |
|
| 324 |
'ADMIN_URL' => ADMIN_URL, |
|
| 325 |
'WB_URL' => WB_URL, |
|
| 326 |
'URL_VIEW' => WB_URL, |
|
| 327 |
'THEME_URL' => THEME_URL, |
|
| 328 |
'VERSION' => VERSION, |
|
| 329 |
'SP' => (defined('SP') ? SP : ''),
|
|
| 330 |
'REVISION' => REVISION, |
|
| 331 |
'LANGUAGE' => strtolower(LANGUAGE), |
|
| 332 |
'FORGOTTEN_DETAILS_APP' => $this->forgotten_details_app, |
|
| 333 |
'TEXT_FORGOTTEN_DETAILS' => $TEXT['FORGOTTEN_DETAILS'], |
|
| 334 |
'TEXT_USERNAME' => $TEXT['USERNAME'], |
|
| 335 |
'TEXT_PASSWORD' => $TEXT['PASSWORD'], |
|
| 336 |
'TEXT_REMEMBER_ME' => $TEXT['REMEMBER_ME'], |
|
| 337 |
'TEXT_LOGIN' => $TEXT['LOGIN'], |
|
| 338 |
'TITLE_LOGOUT' => $MENU['LOGIN'], |
|
| 339 |
'TEXT_RESET' => $TEXT['RESET'], |
|
| 340 |
'TEXT_HOME' => $TEXT['HOME'], |
|
| 341 |
'TITLE_VIEW' => $TEXT['WEBSITE'], |
|
| 342 |
'PAGES_DIRECTORY' => PAGES_DIRECTORY, |
|
| 343 |
'SECTION_NAME' => $MENU['LOGIN'], |
|
| 344 |
'SECTION_LOGIN' => $MENU['LOGIN'], |
|
| 345 |
'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '', |
|
| 346 |
'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '', |
|
| 347 |
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'], |
|
| 348 |
'LOGIN_ICON' => 'login', |
|
| 349 |
'START_ICON' => 'blank', |
|
| 350 |
'URL_HELP' => 'http://www.websitebaker.org/', |
|
| 351 |
) |
|
| 352 |
); |
|
| 353 |
if(defined('DEFAULT_CHARSET')) {
|
|
| 354 |
$charset=DEFAULT_CHARSET; |
|
| 355 |
} else {
|
|
| 356 |
$charset='utf-8'; |
|
| 357 |
} |
|
| 358 |
|
|
| 359 |
$template->set_var('CHARSET', $charset);
|
|
| 360 |
|
|
| 361 |
$template->parse('main', 'mainBlock', false);
|
|
| 362 |
$template->pparse('output', 'page');
|
|
| 363 |
} |
|
| 364 |
} |
|
| 365 |
|
|
| 366 |
// sanities the REMEMBER_KEY cookie to avoid SQL injection |
|
| 367 |
function get_safe_remember_key() {
|
|
| 368 |
if (!((strlen($_COOKIE['REMEMBER_KEY']) == 23) && (substr($_COOKIE['REMEMBER_KEY'], 11, 1) == '_'))) return ''; |
|
| 369 |
// create a clean cookie (XXXXXXXXXXX_YYYYYYYYYYY) where X:= numeric, Y:= hash |
|
| 370 |
$clean_cookie = sprintf('%011d', (int) substr($_COOKIE['REMEMBER_KEY'], 0, 11)) . substr($_COOKIE['REMEMBER_KEY'], 11);
|
|
| 371 |
return ($clean_cookie == $_COOKIE['REMEMBER_KEY']) ? $this->add_slashes($clean_cookie) : ''; |
|
| 372 |
} |
|
| 373 |
|
|
| 374 |
// Warn user that they have had to many login attemps |
|
| 375 |
function warn() {
|
|
| 376 |
// header('Location: '.$this->warning_url);
|
|
| 377 |
$this->send_header($this->warning_url); |
|
| 378 |
exit(0); |
|
| 379 |
} |
|
| 380 |
|
|
| 381 | 327 |
} |
Also available in: Unified diff
! /framework/class.Login.php
! /account/ ~login_form.php ~login.php
! /admin/login/index.php
fixed some possible intruder vectors and complete 2.8.4 adaption