X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fauth.php;h=85d86d0653a1092f0c756bc10ae9e868c9786685;hb=c92e5c6c278791b3424f6258dde0466d1d5cf9e1;hp=2ca51c9fda37c89dee3bd96e081c4152e8e2995f;hpb=d2f8addb4c0b316f828a0e47c2894ab582e2f7a8;p=platal.git diff --git a/modules/auth.php b/modules/auth.php index 2ca51c9..85d86d0 100644 --- a/modules/auth.php +++ b/modules/auth.php @@ -1,6 +1,6 @@ $this->make_hook('manageurs', AUTH_PUBLIC, 'user', NO_HTTPS), - 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE), - 'auth-groupex.php' => $this->make_hook('groupex_old', AUTH_COOKIE), - 'auth-groupex' => $this->make_hook('groupex', AUTH_COOKIE), + 'auth-redirect.php' => $this->make_hook('redirect', AUTH_COOKIE, 'user'), + 'auth-groupex.php' => $this->make_hook('groupex_old', AUTH_COOKIE, 'user'), + 'auth-groupex' => $this->make_hook('groupex', AUTH_PUBLIC), 'admin/auth-groupes-x' => $this->make_hook('admin_authgroupesx', AUTH_MDP, 'admin'), ); } - function handler_chall(&$page) + function handler_chall($page) { $_SESSION["chall"] = uniqid(rand(), 1); echo $_SESSION["chall"] . "\n" . session_id(); exit; } - function handler_econf(&$page) + function handler_econf($page) { global $globals; @@ -51,7 +51,7 @@ class AuthModule extends PLModule $res = "\n\n\n\n"; - if (S::v('chall') && $_GET['PASS'] == md5(S::v('chall').$cle)) { + if (S::v('chall') && Get::s('PASS') == md5(S::v('chall').$cle)) { $list = new MMList(User::getWithUID(10154), "x-econfiance.polytechnique.org"); $members = $list->get_members('membres'); if (is_array($members)) { @@ -76,7 +76,7 @@ class AuthModule extends PLModule exit; } - function handler_manageurs(&$page) + function handler_manageurs($page) { global $globals; @@ -99,34 +99,47 @@ class AuthModule extends PLModule exit; } - function handler_redirect(&$page) + function handler_redirect($page) { http_redirect(Env::v('dest', '/')); } - function handler_groupex_old(&$page) + function handler_groupex_old($page) { return $this->handler_groupex($page, 'iso-8859-1'); } - function handler_groupex(&$page, $charset = 'utf8') + /** Handles the 'auth-groupe-x' authentication. + * Expects the following GET parameters: + * - pass: the 'password' for the authentication + * - challenge: the authentication challenge + * - url: the return URL + * - session: the remote PHP session ID + */ + function handler_groupex($page, $charset = 'utf8') { + if (!S::logged()) { + $page->assign('referer', true); + return PL_DO_AUTH; + } + $this->load('auth.inc.php'); - $page->assign('referer', true); - - $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"]; + + $gpex_pass = Get::s('pass'); + $gpex_url = urldecode(Get::s('url')); + if (Get::has('session')) { + if (strpos($gpex_url, '?') === false) { + $gpex_url .= "?PHPSESSID=" . Get::s('session'); + } else { + $gpex_url .= "&PHPSESSID=" . Get::s('session'); + } } // Normalize the return URL. if (!preg_match("/^(http|https):\/\/.*/",$gpex_url)) { $gpex_url = "http://$gpex_url"; } - $gpex_challenge = $_GET["challenge"]; + $gpex_challenge = Get::s('challenge'); // Update the last login information (unless the user is in SUID). $uid = S::i('uid'); @@ -137,7 +150,7 @@ class AuthModule extends PLModule // Iterate over the auth token to find which one did sign the request. $res = XDB::iterRow('SELECT privkey, name, datafields, returnurls FROM group_auth'); - while (list($privkey,$name,$datafields,$returnurls) = $res->next()) { + while (list($privkey, $name, $datafields, $returnurls) = $res->next()) { if (md5($gpex_challenge.$privkey) == $gpex_pass) { $returnurls = trim($returnurls); // We check that the return url matches a per-key regexp to prevent @@ -145,6 +158,10 @@ class AuthModule extends PLModule // the user to the real GroupeX website, which defeats the attack). if (empty($returnurls) || @preg_match($returnurls, $gpex_url)) { $returl = $gpex_url . gpex_make_params($gpex_challenge, $privkey, $datafields, $charset); + XDB::execute('UPDATE group_auth + SET last_used = DATE(NOW()) + WHERE name = {?}', + $name); http_redirect($returl); } else if (S::admin()) { $page->kill("La requête d'authentification a échouée (url de retour invalide)."); @@ -157,15 +174,16 @@ class AuthModule extends PLModule pl_redirect('/'); } - function handler_admin_authgroupesx(&$page, $action = 'list', $id = null) + function handler_admin_authgroupesx($page, $action = 'list', $id = null) { $page->setTitle('Administration - Auth groupes X'); $page->assign('title', 'Gestion de l\'authentification centralisée'); $table_editor = new PLTableEditor('admin/auth-groupes-x','group_auth','id'); $table_editor->describe('name','nom',true); - $table_editor->describe('privkey','clé privée',false); + $table_editor->describe('privkey','clé privée',false, true); $table_editor->describe('datafields','champs renvoyés',true); $table_editor->describe('returnurls','urls de retour',true); + $table_editor->describe('last_used', 'dernière utilisation', true); $table_editor->apply($page, $action, $id); } }