put auth-*.php into auth module
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 10 Jul 2006 20:09:15 +0000 (20:09 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 10 Jul 2006 20:09:15 +0000 (20:09 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@421 839d8a87-29fc-0310-9880-83ba4fa771e5

htdocs/auth-redirect.php [deleted file]
modules/auth.php [new file with mode: 0644]
modules/auth/methods.inc.php [moved from htdocs/auth-groupex.php with 55% similarity]

diff --git a/htdocs/auth-redirect.php b/htdocs/auth-redirect.php
deleted file mode 100644 (file)
index f0b375e..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_skinned_page('index.tpl',AUTH_COOKIE);
-
-redirect(Env::get('dest', '/'));
-?>
diff --git a/modules/auth.php b/modules/auth.php
new file mode 100644 (file)
index 0000000..b1dae86
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2006 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                *
+ ***************************************************************************/
+
+class AuthModule extends PLModule
+{
+    function handlers()
+    {
+        return array(
+            'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE),
+            'auth-groupex.php'  => $this->make_hook('groupex',  AUTH_COOKIE),
+        );
+    }
+
+    function handler_redirect(&$page)
+    {
+        redirect(Env::get('dest', '/'));
+    }
+
+    function handler_groupex(&$page)
+    {
+        global $globals;
+
+        require_once dirname(__FILE__).'/auth/methods.inc.php';
+
+        $gpex_pass = $_GET["pass"];
+        $gpex_url  = urldecode($_GET["url"]);
+        if (strpos($gpex_url, '?') === false) {
+            $gpex_url .= "?PHPSESSID=" . $_GET["session"];
+        } else {
+            $gpex_url .= "&PHPSESSID=" . $_GET["session"];
+        }
+
+        /* a-t-on besoin d'ajouter le http:// ? */
+        if (!preg_match("/^(http|https):\/\/.*/",$gpex_url))
+            $gpex_url = "http://$gpex_url";
+        $gpex_challenge = $_GET["challenge"];
+
+        // mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid
+        if (!isset($_SESSION['suid'])) {
+            $logger = (isset($_SESSION['log']) && $_SESSION['log']->uid == $uid)
+                      ? $_SESSION['log']
+                      : new DiogenesCoreLogger($uid);
+            $logger->log('connexion_auth_ext', $_SERVER['PHP_SELF']);
+        }
+
+        /* on parcourt les entrees de groupes_auth */
+        $res = $globals->xdb->iterRow('select privkey,name,datafields from groupesx_auth');
+
+        while (list($privkey,$name,$datafields) = $res->next()) {
+            if (md5($gpex_challenge.$privkey) == $gpex_pass) {
+                $returl = $gpex_url.gpex_make_params($gpex_challenge,$privkey,$datafields);
+                redirect($returl);
+            }
+        }
+
+        /* si on n'a pas trouvé, on renvoit sur x.org */
+        redirect('https://www.polytechnique.org/');
+    }
+}
+
+?>
similarity index 55%
rename from htdocs/auth-groupex.php
rename to modules/auth/methods.inc.php
index 84144ea..64aa66e 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-$gpex_pass = $_GET["pass"];
-$gpex_url = urldecode($_GET["url"]);
-if (strpos($gpex_url, '?') === false) {
-    $gpex_url .= "?PHPSESSID=" . $_GET["session"];
-} else {
-    $gpex_url .= "&PHPSESSID=" . $_GET["session"];
-}
-/* a-t-on besoin d'ajouter le http:// ? */
-if (!preg_match("/^(http|https):\/\/.*/",$gpex_url))
-    $gpex_url = "http://$gpex_url";
-$gpex_challenge = $_GET["challenge"];
-
-require_once("xorg.inc.php");
-new_skinned_page('index.tpl',AUTH_COOKIE);
-
-// mise à jour de l'heure et de la machine de dernier login sauf quand on est en suid
-if (!isset($_SESSION['suid'])) {
-    $logger = (isset($_SESSION['log']) && $_SESSION['log']->uid==$uid) ? $_SESSION['log'] : new DiogenesCoreLogger($uid);
-    $logger->log("connexion_auth_ext",$_SERVER['PHP_SELF']);
-}
-
 /* cree le champs "auth" renvoye au Groupe X */
 function gpex_make_auth($chlg, $privkey, $datafields) {
     global $globals;
     $fieldarr = explode(",",$datafields);
     $tohash   = "1$chlg$privkey";
 
-    $res = $globals->xdb->query("SELECT matricule,matricule_ax,promo,promo_sortie,flags,deces,nom,prenom,nationalite,section,naissance FROM auth_user_md5 WHERE user_id = {?}", Session::getInt('uid'));
+    $res = $globals->xdb->query("SELECT matricule, matricule_ax, promo,
+                                        promo_sortie, flags, deces, nom,
+                                        prenom, nationalite, section,
+                                        naissance
+                                   FROM auth_user_md5 WHERE user_id = {?}",
+                                Session::getInt('uid'));
     $personnal_data = $res->fetchOneAssoc();
-    
-    while (list(,$val) = each($fieldarr)) {
-        /* on verifie qu'on n'a pas demandé une
-           variable inexistante ! */
-        if (isset($_SESSION[$val])) {
-            $tohash .= $_SESSION[$val];
+
+    foreach ($fieldarr as $val) {
+        /* on verifie qu'on n'a pas demandé une variable inexistante ! */
+        if (Session::has($val)) {
+            $tohash .= Session::get($val);
         } else if (isset($personnal_data[$val])) {
             $tohash .= $personnal_data[$val];
         } else if ($val == 'username') {
-            $res = $globals->xdb->query("SELECT alias FROM aliases WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", Session::getInt('uid'));
+            $res = $globals->xdb->query("SELECT alias FROM aliases
+                                          WHERE id = {?} AND FIND_IN_SET('bestalias', flags)",
+                                        Session::getInt('uid'));
             $min_username = $res->fetchOneCell();
             $tohash      .= $min_username;
-       }
+        }
     }
     $tohash .= "1";
     return md5($tohash);
@@ -70,36 +55,31 @@ function gpex_make_auth($chlg, $privkey, $datafields) {
 function gpex_make_params($chlg, $privkey, $datafields) {
     global $globals;
     $params   = "&auth=".gpex_make_auth($chlg, $privkey, $datafields);
-    
-    $res = $globals->xdb->query("SELECT matricule,matricule_ax,promo,promo_sortie,flags,deces,nom,prenom,nationalite,section,naissance FROM auth_user_md5 WHERE user_id = {?}", Session::getInt('uid'));
+
+    $res = $globals->xdb->query("SELECT matricule, matricule_ax, promo,
+                                        promo_sortie, flags, deces, nom,
+                                        prenom, nationalite, section,
+                                        naissance
+                                   FROM auth_user_md5 WHERE user_id = {?}",
+                                Session::getInt('uid'));
     $personnal_data = $res->fetchOneAssoc();
-    
+
     $fieldarr = explode(",",$datafields);
-    while (list(,$val) = each($fieldarr)) {
-        if (isset($_SESSION[$val])) {
-            $params .= "&$val=".$_SESSION[$val];
+
+    foreach ($fieldarr as $val) {
+        if (Session::has($val)) {
+            $tohash .= Session::get($val);
         } else if (isset($personnal_data[$val])) {
             $params .= "&$val=".$personnal_data[$val];
         } else if ($val == 'username') {
-            $res = $globals->xdb->query("SELECT alias FROM aliases WHERE id = {?} AND FIND_IN_SET('bestalias', flags)", Session::getInt('uid'));
+            $res = $globals->xdb->query("SELECT alias FROM aliases 
+                                          WHERE id = {?} AND FIND_IN_SET('bestalias', flags)",
+                                        Session::getInt('uid'));
             $min_username = $res->fetchOneCell();
             $params      .= "&$val=".$min_username;
-       }
+        }
     }
     return $params;
 }
 
-/* on parcourt les entrees de groupes_auth */
-$res = $globals->xdb->iterRow('select privkey,name,datafields from groupesx_auth');
-
-while (list($privkey,$name,$datafields) = $res->next()) {
-    if (md5($gpex_challenge.$privkey) == $gpex_pass) {
-        $returl = $gpex_url.gpex_make_params($gpex_challenge,$privkey,$datafields);
-        redirect($returl);
-    }
-}
-
-/* si on n'a pas trouvé, on renvoit sur x.org */
-redirect('https://www.polytechnique.org/');
-
 ?>