public static function init() {
S::init();
- if (!S::has('uid')) {
- try_cookie();
+ if (!S::has('uid')) {
+ try_cookie();
}
}
public static function doAuth($new_name = false)
{
- global $globals;
- if (S::identified()) { // ok, c'est bon, on n'a rien à faire
- return true;
- }
+ global $globals;
+ if (S::identified()) { // ok, c'est bon, on n'a rien à faire
+ return true;
+ }
if (!Env::has('username') || !Env::has('response')
|| !S::has('challenge'))
// si on vient de recevoir une identification par passwordpromptscreen.tpl
// ou passwordpromptscreenlogged.tpl
- $uname = Env::v('username');
-
- if (Env::v('domain') == "alias") {
-
- $res = XDB::query(
- "SELECT redirect
- FROM virtual
- INNER JOIN virtual_redirect USING(vid)
- WHERE alias LIKE {?}", $uname."@".$globals->mail->alias_dom);
- $redirect = $res->fetchOneCell();
- if ($redirect) {
- $login = substr($redirect, 0, strpos($redirect, '@'));
+ if (S::has('suid')) {
+ $suid = S::v('suid');
+ $login = $uname = $suid['forlife'];
+ $redirect = false;
+ } else {
+ $uname = Env::v('username');
+
+ if (Env::v('domain') == "alias") {
+ $res = XDB::query(
+ "SELECT redirect
+ FROM virtual
+ INNER JOIN virtual_redirect USING(vid)
+ WHERE alias LIKE {?}", $uname."@".$globals->mail->alias_dom);
+ $redirect = $res->fetchOneCell();
+ if ($redirect) {
+ $login = substr($redirect, 0, strpos($redirect, '@'));
+ } else {
+ $login = "";
+ }
} else {
- $login = "";
+ $login = $uname;
+ $redirect = false;
}
- } else {
- $login = $uname;
- $redirect = false;
}
$field = (!$redirect && preg_match('/^\d*$/', $uname)) ? 'id' : 'alias';
$logger = S::v('log');
if (list($uid, $password) = $res->fetchOneRow()) {
- require_once('secure_hash.inc.php');
- $expected_response = hash_encrypt("$uname:$password:".S::v('challenge'));
- // le password de la base est peut-être encore encodé en md5
- if (Env::v('response') != $expected_response) {
- $new_password = hash_xor(Env::v('xorpass'), $password);
- $expected_response = hash_encrypt("$uname:$new_password:".S::v('challenge'));
- if (Env::v('response') == $expected_response) {
- XDB::execute("UPDATE auth_user_md5 SET password = {?} WHERE user_id = {?}",
- $new_password, $uid);
- }
- }
- if (Env::v('response') == $expected_response) {
+ require_once('secure_hash.inc.php');
+ $expected_response = hash_encrypt("$uname:$password:".S::v('challenge'));
+ // le password de la base est peut-être encore encodé en md5
+ if (Env::v('response') != $expected_response) {
+ $new_password = hash_xor(Env::v('xorpass'), $password);
+ $expected_response = hash_encrypt("$uname:$new_password:".S::v('challenge'));
+ if (Env::v('response') == $expected_response) {
+ XDB::execute("UPDATE auth_user_md5 SET password = {?} WHERE user_id = {?}",
+ $new_password, $uid);
+ }
+ }
+ if (Env::v('response') == $expected_response) {
if (Env::has('domain')) {
if (($domain = Env::v('domain', 'login')) == 'alias') {
setcookie('ORGdomain', "alias", (time()+25920000), '/', '', 0);
if ($logger) {
$logger->log('auth_ok');
}
- start_connexion($uid, true);
+ start_connexion($uid, true);
if (Env::v('remember', 'false') == 'true') {
$cookie = hash_encrypt(S::v('password'));
setcookie('ORGaccess',$cookie,(time()+25920000),'/','',0);
$logger->log("cookie_off");
}
}
- return true;
- } elseif ($logger) {
+ return true;
+ } elseif ($logger) {
$logger->log('auth_fail','bad password');
}
} elseif ($logger) {
*/
public static function doAuthCookie()
{
- if (S::logged()) {
- return true;
+ if (S::logged()) {
+ return true;
}
- if (Env::has('username') and Env::has('response')) {
- return XorgSession::doAuth();
+ if (Env::has('username') and Env::has('response')) {
+ return XorgSession::doAuth();
}
- if ($r = try_cookie()) {
- return XorgSession::doAuth(($r > 0));
+ if ($r = try_cookie()) {
+ return XorgSession::doAuth(($r > 0));
}
return false;
function try_cookie()
{
if (Cookie::v('ORGaccess') == '' or !Cookie::has('ORGuid')) {
- return -1;
+ return -1;
}
$res = @XDB::query(
Cookie::i('ORGuid'));
if ($res->numRows() != 0) {
- list($uid, $password) = $res->fetchOneRow();
- require_once('secure_hash.inc.php');
- $expected_value = hash_encrypt($password);
- if ($expected_value == Cookie::v('ORGaccess')) {
- start_connexion($uid, false);
- return 0;
- } else {
+ list($uid, $password) = $res->fetchOneRow();
+ require_once('secure_hash.inc.php');
+ $expected_value = hash_encrypt($password);
+ if ($expected_value == Cookie::v('ORGaccess')) {
+ start_connexion($uid, false);
+ return 0;
+ } else {
return 1;
}
}
function start_connexion ($uid, $identified)
{
$res = XDB::query("
- SELECT u.user_id AS uid, prenom, nom, perms, promo, matricule, password, FIND_IN_SET('femme', u.flags) AS femme,
+ SELECT u.user_id AS uid, prenom, nom, perms, promo, matricule, password, FIND_IN_SET('femme', u.flags) AS femme,
UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, a.alias AS forlife, a2.alias AS bestalias,
q.core_mail_fmt AS mail_fmt, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last, q.core_rss_hash
FROM auth_user_md5 AS u
INNER JOIN auth_user_quick AS q USING(user_id)
- INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
- INNER JOIN aliases AS a2 ON (u.user_id = a2.id AND FIND_IN_SET('bestalias',a2.flags))
+ INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
+ INNER JOIN aliases AS a2 ON (u.user_id = a2.id AND FIND_IN_SET('bestalias',a2.flags))
LEFT JOIN logger.sessions AS s ON (s.uid=u.user_id AND s.suid=0)
WHERE u.user_id = {?} AND u.perms IN('admin','user')
ORDER BY s.start DESC
$suid = S::v('suid');
if ($suid) {
- $logger = new CoreLogger($uid, $suid);
- $logger->log("suid_start", S::v('forlife')." by {$suid['uid']}");
+ $logger = new CoreLogger($uid, $suid);
+ $logger->log("suid_start", S::v('forlife')." by {$suid['uid']}");
$sess['suid'] = $suid;
+ $sess['perms'] = $_SESSION['perms'];
} else {
$logger = S::v('log', new CoreLogger($uid));
$logger->log("connexion", Env::v('n'));
global $globals;
if (S::logged() && !S::has('skin')) {
$uid = S::v('uid');
- $res = XDB::query("SELECT skin_tpl
+ $res = XDB::query("SELECT skin_tpl
FROM auth_user_quick AS a
INNER JOIN skins AS s ON a.skin = s.id
WHERE user_id = {?} AND skin_tpl != ''", $uid);
- if ($_SESSION['skin'] = $res->fetchOneCell()) {
+ if ($_SESSION['skin'] = $res->fetchOneCell()) {
return;
}
}