fixes
[platal.git] / modules / platal.php
index fe02ded..9e2f0f2 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
+function bugize($list)
+{
+    $list = split(',', $list);
+    $ans  = array();
+
+    foreach ($list as $bug) {
+        $clean = str_replace('#', '', $bug);
+        $ans[] = "<a href='http://trackers.polytechnique.org/task/$clean'>$bug</a>";
+    }
+
+    return join(',', $ans);
+}
+
+
 class PlatalModule extends PLModule
 {
     function handlers()
     {
         return array(
+            'index'       => $this->make_hook('index',     AUTH_PUBLIC),
+            'cacert.pem'  => $this->make_hook('cacert',    AUTH_PUBLIC),
+            'changelog'   => $this->make_hook('changelog', AUTH_PUBLIC),
+
             // Preferences thingies
             'prefs'     => $this->make_hook('prefs',     AUTH_COOKIE),
             'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE),
+            'prefs/webredirect'
+                        => $this->make_hook('webredir',  AUTH_MDP),
             'skin'      => $this->make_hook('skin',      AUTH_COOKIE),
 
             // password related thingies
@@ -34,12 +54,38 @@ class PlatalModule extends PLModule
             'tmpPWD'        => $this->make_hook('tmpPWD',    AUTH_PUBLIC),
             'password/smtp' => $this->make_hook('smtppass',  AUTH_MDP),
             'recovery'      => $this->make_hook('recovery',  AUTH_PUBLIC),
+            'exit'          => $this->make_hook('exit', AUTH_PUBLIC),
 
             // happenings related thingies
             'rss'         => $this->make_hook('rss',       AUTH_PUBLIC),
         );
     }
 
+    function handler_index(&$page)
+    {
+        if (logged()) {
+            redirect("events");
+        }
+    }
+
+    function handler_cacert(&$page)
+    {
+        $data = file_get_contents('/etc/ssl/xorgCA/cacert.pem');
+        header('Content-Type: application/x-x509-ca-cert');
+        header('Content-Length: '.strlen($data));
+        echo $data;
+        exit;
+    }
+
+    function handler_changelog(&$page)
+    {
+        $page->changeTpl('changeLog.tpl');
+
+        $clog = htmlentities(file_get_contents(dirname(__FILE__).'/../ChangeLog'));
+        $clog = preg_replace('!(#[0-9]+(,[0-9]+)*)!e', 'bugize("\1")', $clog);
+        $page->assign('ChangeLog', $clog);
+    }
+
     function __set_rss_state($state)
     {
         global $globals;
@@ -73,7 +119,7 @@ class PlatalModule extends PLModule
                                      WHERE user_id = {?}",
                                      Session::getInt('uid'));
             $_SESSION['mail_fmt'] = $fmt;
-            redirect('preferences');
+            redirect($globals->baseurl.'/preferences');
         }
 
         if (Env::has('rss')) {
@@ -81,8 +127,40 @@ class PlatalModule extends PLModule
         }
 
         $page->assign('prefs', $globals->hook->prefs());
+    }
+
+    function handler_webredir(&$page)
+    {
+        global $globals;
+
+        $page->changeTpl('webredirect.tpl');
+
+        $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
+
+        $log =& Session::getMixed('log');
+        $url = Env::get('url');
+
+        if (Env::get('submit') == 'Valider' and Env::has('url')) {
+            $globals->xdb->execute('UPDATE auth_user_quick
+                                       SET redirecturl = {?} WHERE user_id = {?}',
+                                   $url, Session::getInt('uid'));
+            $log->log('carva_add', 'http://'.Env::get('url'));
+            $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
+        } elseif (Env::get('submit') == "Supprimer") {
+            $globals->xdb->execute("UPDATE auth_user_quick
+                                       SET redirecturl = ''
+                                     WHERE user_id = {?}",
+                                   Session::getInt('uid'));
+            $log->log("carva_del", $url);
+            Post::kill('url');
+            $page->trig('Redirection supprimée');
+        }
 
-        return PL_OK;
+        $res = $globals->xdb->query('SELECT redirecturl
+                                       FROM auth_user_quick
+                                      WHERE user_id = {?}',
+                                    Session::getInt('uid'));
+        $page->assign('carva', $res->fetchOneCell());
     }
 
     function handler_prefs_rss(&$page)
@@ -97,8 +175,6 @@ class PlatalModule extends PLModule
             $this->__set_rss_state(true);
             $page->trig("Ton Fil RSS est activé.");
         }
-
-        return PL_OK;
     }
 
     function handler_password(&$page)
@@ -129,8 +205,6 @@ class PlatalModule extends PLModule
         $page->changeTpl('motdepasse.tpl');
         $page->addJsLink('javascript/motdepasse.js');
         $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
-
-        return PL_OK;
     }
 
     function handler_smtppass(&$page)
@@ -162,8 +236,6 @@ class PlatalModule extends PLModule
                                        FROM auth_user_md5
                                       WHERE user_id = {?}", $uid);
         $page->assign('actif', $res->fetchOneCell());
-
-        return PL_OK;
     }
 
     function handler_recovery(&$page)
@@ -173,7 +245,7 @@ class PlatalModule extends PLModule
         $page->changeTpl('recovery.tpl');
 
         if (!Env::has('login') || !Env::has('birth')) {
-            return PL_OK;
+            return;
         }
 
         if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) {
@@ -227,8 +299,6 @@ Mail envoy
         } else {
             $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
         }
-
-        return PL_OK;
     }
 
     function handler_tmpPWD(&$page, $certif = null)
@@ -259,8 +329,6 @@ Mail envoy
             $page->changeTpl('motdepasse.tpl');
             $page->addJsLink('javascript/motdepasse.js');
         }
-
-        return PL_OK;
     }
 
     function handler_skin(&$page)
@@ -288,7 +356,50 @@ Mail envoy
                  WHERE skin_tpl != '' AND ext != ''
               GROUP BY id ORDER BY s.date DESC";
         $page->assign_by_ref('skins', $globals->xdb->iterator($sql));
-        return PL_OK;
+    }
+
+    function handler_exit(&$page, $level = null)
+    {
+        if (Session::has('suid')) {
+            if (Session::has('suid')) {
+                $a4l  = Session::get('forlife');
+                $suid = Session::getMixed('suid');
+                $log  = Session::getMixed('log');
+                $log->log("suid_stop", Session::get('forlife') . " by " . $suid['forlife']);
+                $_SESSION = $suid;
+                Session::kill('suid');
+                redirect($globals->baseurl.'/admin/utilisateurs.php?login='.$a4l);
+            } else {
+                redirect("events");
+            }
+        }
+
+        if ($level == 'forget' || $level == 'forgetall') {
+            setcookie('ORGaccess', '', time() - 3600, '/', '', 0);
+            Cookie::kill('ORGaccess');
+            if (isset($_SESSION['log']))
+                $_SESSION['log']->log("cookie_off");
+        }
+
+        if ($level == 'forgetuid' || $level == 'forgetall') {
+            setcookie('ORGuid', '', time() - 3600, '/', '', 0);
+            Cookie::kill('ORGuid');
+            setcookie('ORGdomain', '', time() - 3600, '/', '', 0);
+            Cookie::kill('ORGdomain');
+        }
+
+        if (isset($_SESSION['log'])) {
+            $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
+            $_SESSION['log']->log('deconnexion',$ref);
+        }
+
+        XorgSession::destroy();
+
+        if (Get::has('redirect')) {
+            redirect(rawurldecode(Get::get('redirect')));
+        } else {
+            $page->changeTpl('exit.tpl');
+        }
     }
 
     function handler_rss(&$page, $user = null, $hash = null)
@@ -307,8 +418,6 @@ Mail envoy
                   WHERE  u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
                                          AND peremption >= NOW()', $uid);
         $page->assign('rss', $rss);
-
-        return PL_OK;
     }
 }