Merge commit 'origin/fusionax' into account
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 21 Dec 2008 17:37:02 +0000 (18:37 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 21 Dec 2008 17:37:02 +0000 (18:37 +0100)
Conflicts:

modules/platal.php
modules/register.php

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/xorgsession.php
core
include/marketing.inc.php
include/secure_hash.inc.php [deleted file]
modules/admin.php
modules/platal.php
modules/register.php
modules/register/register.inc.php
templates/events/index.tpl
upgrade/account/00_account.sql [new file with mode: 0644]
upgrade/account/01_account_insertion.sql [new file with mode: 0644]

index 91cda51..6a92d90 100644 (file)
@@ -51,14 +51,13 @@ class XorgSession extends PlSession
             return -1;
         }
 
-        $res = XDB::query('SELECT  user_id, password
-                             FROM  auth_user_md5
-                            WHERE  user_id = {?} AND perms IN(\'admin\', \'user\')',
+        $res = XDB::query('SELECT  uid, password
+                             FROM  accounts
+                            WHERE  uid = {?} AND state = \'active\'',
                          Cookie::i('ORGuid'));
         if ($res->numRows() != 0) {
             list($uid, $password) = $res->fetchOneRow();
-            require_once 'secure_hash.inc.php';
-            $expected_value = hash_encrypt($password);
+            $expected_value = sha1($password);
             if ($expected_value == Cookie::v('ORGaccess')) {
                 S::set('auth_by_cookie', $uid);
                 return 0;
@@ -71,36 +70,14 @@ class XorgSession extends PlSession
 
     private function checkPassword($uname, $login, $response, $login_type)
     {
-        $res = XDB::query('SELECT  u.user_id, u.password
-                             FROM  auth_user_md5 AS u
-                       INNER JOIN  aliases       AS a ON (a.id = u.user_id AND type != \'homonyme\')
-                             WHERE  a.' . $login_type . ' = {?} AND u.perms IN(\'admin\', \'user\')',
+        $res = XDB::query('SELECT  a.uid, a.password
+                             FROM  accounts AS a
+                       INNER JOIN  aliases  AS l ON (l.id = a.uid AND l.type != \'homonyme\')
+                            WHERE  l.' . $login_type . ' = {?} AND a.state = \'active\'',
                           $login);
         if (list($uid, $password) = $res->fetchOneRow()) {
-            require_once 'secure_hash.inc.php';
-            $expected_response = hash_encrypt("$uname:$password:" . S::v('challenge'));
-            if ($response != $expected_response && Env::has('xorpass')
-                && !preg_match('/^0*$/', Env::v('xorpass'))) {
-                $new_password = hash_xor(Env::v('xorpass'), $password);
-                $expected_response = hash_encrypt("$uname:$new_password:" . S::v('challenge'));
-                if ($response == $expected_response) {
-                    XDB::execute('UPDATE  auth_user_md5
-                                     SET  password = {?}
-                                   WHERE  user_id = {?}',
-                                 $new_password, $uid);
-
-                    // Update the GoogleApps password as well, if required.
-                    global $globals;
-                    if ($globals->mailstorage->googleapps_domain) {
-                        require_once 'googleapps.inc.php';
-                        $user = User::getSilent($uid);
-                        $account = new GoogleAppsAccount($user);
-                        if ($account->active() && $account->sync_password) {
-                            $account->set_password($new_password);
-                        }
-                    }
-                }
-            }
+            $expected_response = sha1("$uname:$password:" . S::v('challenge'));
+            /* XXX: Deprecates len(password) > 10 conversion */
             if ($response != $expected_response) {
                 S::logger($uid)->log('auth_fail', 'bad password');
                 return null;
@@ -203,17 +180,23 @@ class XorgSession extends PlSession
         }
 
         // Retrieves main user properties.
-        $res  = XDB::query("SELECT  u.user_id AS uid, u.hruid, prenom, prenom_ini, nom, nom_ini, nom_usage, perms, promo, promo_sortie,
-                                    matricule, password, FIND_IN_SET('femme', u.flags) AS femme,
-                                    q.core_mail_fmt AS mail_fmt, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last, q.core_rss_hash,
-                                    FIND_IN_SET('watch', u.flags) AS watch_account, q.last_version, g.g_account_name IS NOT NULL AS googleapps,
-                                    UNIX_TIMESTAMP(s.start) AS lastlogin, s.host
-                              FROM  auth_user_md5   AS u
-                        INNER JOIN  auth_user_quick AS q  USING(user_id)
-                         LEFT JOIN  gapps_accounts  AS g  ON (u.user_id = g.l_userid AND g.g_status = 'active')
-                         LEFT JOIN  logger.last_sessions AS ls ON (ls.uid = u.user_id)
+        /** TODO: Move needed informations to account tables */
+        /** TODO: Currently suppressed data are matricule, promo */
+        /** TODO: Data to move are: banana_last, watch_last, last_version */
+        /** TODO: Switch to new permission system */
+        $res  = XDB::query("SELECT  a.uid, a.hruid, a.display_name, a.full_name, a.password,
+                                    a.sex = 'female' AS femme, a.mail_format as mail_fmt,
+                                    a.token, FIND_IN_SET('watch', a.flags) AS watch_account,
+                                    UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last,
+                                    q.last_version, g.g_account_name IS NOT NULL AS googleapps,
+                                    UNIX_TIMESTAMP(s.start) AS lastlogin, s.host,
+                                    IF(a.is_admin, 'admin', 'user') AS perms
+                              FROM  accounts        AS a
+                        INNER JOIN  auth_user_quick AS q  ON(a.uid = q.user_id)
+                         LEFT JOIN  gapps_accounts  AS g  ON(a.uid = g.l_userid AND g.g_status = 'active')
+                         LEFT JOIN  logger.last_sessions AS ls ON (ls.uid = a.uid)
                          LEFT JOIN  logger.sessions AS s  ON(s.id = ls.id)
-                             WHERE  u.user_id = {?} AND u.perms IN('admin', 'user')", $uid);
+                             WHERE  a.uid = {?} AND a.state = 'active'", $uid);
         $sess = $res->fetchOneAssoc();
         $perms = $sess['perms'];
         unset($sess['perms']);
@@ -232,7 +215,7 @@ class XorgSession extends PlSession
             setcookie('ORGuid', $uid, (time() + 25920000), '/', '', 0);
 
             if (S::i('auth_by_cookie') == $uid || Post::v('remember', 'false') == 'true') {
-                $cookie = hash_encrypt($sess['password']);
+                $cookie = sha1($sess['password']);
                 setcookie('ORGaccess', $cookie, (time() + 25920000), '/', '', 0);
                 if (S::i('auth_by_cookie') != $uid) {
                     $logger->log("cookie_on");
@@ -279,11 +262,11 @@ class XorgSession extends PlSession
 
     public function tokenAuth($login, $token)
     {
-        $res = XDB::query('SELECT  u.hruid
-                             FROM  aliases         AS a
-                       INNER JOIN  auth_user_md5   AS u ON (a.id = u.user_id AND u.perms IN ("admin", "user"))
-                       INNER JOIN  auth_user_quick AS q ON (a.id = q.user_id AND q.core_rss_hash = {?})
-                            WHERE  a.alias = {?} AND a.type != "homonyme"', $token, $login);
+        $res = XDB::query('SELECT  a.hruid
+                             FROM  aliases  AS l
+                       INNER JOIN  accounts AS a ON (l.id = a.uid AND a.state = \'active\')
+                            WHERE  a.token = {?} AND l.alias = {?} AND l.type != \'homonyme\'',
+                           $token, $login);
         if ($res->numRows() == 1) {
             $data = $res->fetchOneAssoc();
             return new User($data['hruid'], $data);
@@ -309,10 +292,10 @@ class XorgSession extends PlSession
     {
         if (S::logged() && (!S::has('skin') || S::has('suid'))) {
             $uid = S::v('uid');
-            $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);
+            $res = XDB::query('SELECT  skin_tpl
+                                 FROM  accounts AS a
+                           INNER JOIN  skins    AS s on (a.skin = s.id)
+                                WHERE  a.uid = {?} AND skin_tpl != \'\'', S::i('uid'));
             S::set('skin', $res->fetchOneCell());
         }
     }
diff --git a/core b/core
index d7dfb18..eec9962 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit d7dfb18e275c1ed834ea8f0f4001399b0a17ce9f
+Subproject commit eec996233a443d9d024786583c0370a54d639dde
index d488843..785335a 100644 (file)
@@ -202,10 +202,9 @@ class Marketing
             return false;
         }
 
-        require_once('secure_hash.inc.php');
         $hash     = rand_url_id(12);
         $pass     = rand_pass();
-        $pass_encrypted = hash_encrypt($pass);
+        $pass_encrypted = sha1($pass);
         $fdate    = strftime('%d %B %Y', strtotime($date));
 
         $mymail = new PlMailer('marketing/relance.mail.tpl');
diff --git a/include/secure_hash.inc.php b/include/secure_hash.inc.php
deleted file mode 100644 (file)
index 52a62cf..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
- *  GNU General Public License for more details.                           *
- *                                                                         *
- *  You should have received a copy of the GNU General Public License      *
- *  along with this program; if not, write to the Free Software            *
- *  Foundation, Inc.,                                                      *
- *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
- ***************************************************************************/
-
-function hash_encrypt($s) {
-    return sha1($s);
-}
-
-function hash_xor($a, $b) {
-    $c = "";
-    $i = strlen($a);
-    $j = strlen($b);
-    if ($i < $j) {
-        $d = $a; $a = $b; $b = $d;
-        $k = $i; $i = $j; $j = $k;
-    }
-    for ($k = 0; $k < $j; $k++)
-        $c .= dechex(hexdec($a{$k}) ^ hexdec($b{$k}));
-    for (; $k < $i; $k++)
-        $c .= $a{$k};
-    return $c;
-}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
index b0bad9a..1cb33af 100644 (file)
@@ -518,8 +518,7 @@ class AdminModule extends PLModule
                 // Profile edition.
                 case "u_edit":
                     // Loads new values from environment.
-                    require_once('secure_hash.inc.php');
-                    $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw');
+                    $pass_encrypted = Env::v('newpass_clair') != "********" ? sha1(Env::v('newpass_clair')) : Env::v('passw');
                     $naiss    = Env::v('naissanceN');
                     $deces    = Env::v('decesN');
                     $perms    = Env::v('permsN');
index cf73869..123a1c0 100644 (file)
@@ -209,7 +209,6 @@ class PlatalModule extends PLModule
         global $globals;
 
         if (Post::has('response2'))  {
-            require_once 'secure_hash.inc.php';
             S::assert_xsrf_token();
 
             $_SESSION['password'] = $password = Post::v('response2');
@@ -233,7 +232,7 @@ class PlatalModule extends PLModule
             S::logger()->log('passwd', '');
 
             if (Cookie::v('ORGaccess')) {
-                setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0);
+                setcookie('ORGaccess', sha1($password), (time()+25920000), '/', '' ,0);
                 S::logger()->log('cookie_on', '');
             }
 
index 9089244..0c3e0e3 100644 (file)
@@ -444,8 +444,7 @@ class RegisterModule extends PLModule
             S::logger()->log('passwd', '');
 
             if (Cookie::v('ORGaccess')) {
-                require_once('secure_hash.inc.php');
-                setcookie('ORGaccess', hash_encrypt($password), (time()+25920000), '/', '' ,0);
+                setcookie('ORGaccess', sha1($password), (time()+25920000), '/', '' ,0);
                 S::logger()->log('cookie_on', '');
             }
 
index d16c2cf..9bc05b4 100644 (file)
@@ -225,10 +225,9 @@ function finish_ins($sub_state)
 {
     global $globals;
     extract($sub_state);
-    require_once('secure_hash.inc.php');
 
     $pass     = rand_pass();
-    $pass_encrypted = hash_encrypt($pass);
+    $pass_encrypted = sha1($pass);
     $hash     = rand_url_id(12);
 
     XDB::execute('UPDATE auth_user_md5 SET last_known_email={?} WHERE matricule = {?}', $email, $mat);
index 2185957..e0f35b8 100644 (file)
@@ -27,7 +27,7 @@
 {else}
 
 <h1 id='pagetop'>
-Bienvenue {$smarty.session.yourself_name}{if $birthday}
+Bienvenue {$smarty.session.display_name}{if $birthday}
   &nbsp;et joyeux anniversaire de la part de toute l'équipe !
 {else},
 {/if}
diff --git a/upgrade/account/00_account.sql b/upgrade/account/00_account.sql
new file mode 100644 (file)
index 0000000..678a4dc
--- /dev/null
@@ -0,0 +1,51 @@
+CREATE TABLE accounts (
+  # Account identifier and type
+  uid int(6) not null auto_increment,
+  hruid varchar(255) not NULL,
+
+  # Account type and state
+  type varchar(16) default null,
+  is_admin bool default false,
+  state enum('pending', 'active', 'disabled') not null default 'pending',
+
+  # Access
+  password char(40) default null,
+  token varchar(32) default null,
+  registration_date datetime not null,
+
+  # Administrative tools
+  flags set('watch') not null default '',
+  comment varchar(255) default null,
+
+  # User settings
+  full_name varchar(255) default null,
+  display_name varchar(255) default null,
+  sex enum('female', 'male') not null default 'male',
+  mail_format enum('plain', 'html') not null default 'html',
+  skin varchar(32) default null,
+
+  primary key uid (uid),
+  unique key hruid (hruid),
+  key full_name (full_name),
+  key state (state),
+  key type (type)
+);
+
+CREATE TABLE account_types (
+  type varchar(16) not null,
+  perms set('mail', 'groups', 'forums', 'list', 'search', 'portal') default '',
+
+  primary key type (type)
+);
+
+CREATE TABLE account_profiles (
+  uid int(6) not null,
+  pid int(6) not null,
+  perms set('owner') not null default '',
+
+  primary key id (uid, pid),
+  key uid (uid),
+  key pid (pid)
+);
+
+# vim:set syntax=mysql:
diff --git a/upgrade/account/01_account_insertion.sql b/upgrade/account/01_account_insertion.sql
new file mode 100644 (file)
index 0000000..53dc24b
--- /dev/null
@@ -0,0 +1,27 @@
+insert into account_types
+     values ('x', 'mail,groups,forums,list,search,portal');
+
+insert into accounts
+     select u.user_id AS uid, hruid AS hruid, 'x' AS type,
+            perms = 'admin' AS is_admin,
+            IF(perms = 'admin' or perms = 'user', 'active', perms) AS state,
+            IF(LENGTH(password) = 40, password, NULL) AS password,
+            IF(LENGTH(q.core_rss_hash) > 0, q.core_rss_hash, NULL) AS token,
+            date_ins AS registration_date,
+            IF(FIND_IN_SET('watch', flags), 'watch', '') AS flags,
+            IF(LENGTH(comment) > 0, comment, NULL) AS comment,
+            CONCAT(prenom, ' ', IF (nom_usage != '' and nom_usage IS NOT NULL, nom_usage, nom)) AS full_name,
+            prenom AS display_name,
+            IF(FIND_IN_SET('femme', flags), 'female', 'male') AS sex,
+            IF(q.core_mail_fmt = 'html', 'html', 'plain') AS mail_format,
+            q.skin AS skin
+       from auth_user_md5 as u
+  left join auth_user_quick as q on (q.user_id = u.user_id)
+      where hruid is not null;
+
+insert into account_profiles
+     select user_id AS uid, user_id AS pid, 'owner' AS perms
+       from auth_user_md5
+      where hruid is not null;
+
+# vim:set syntax=mysql: