Auto-redirects HTML pages to HTTPS
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 19 Aug 2007 09:35:54 +0000 (09:35 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 19 Aug 2007 09:35:54 +0000 (09:35 +0000)
 ChangeLog              |    3 +++
 Makefile               |    4 +++-
 classes/platal.php     |   14 +++++++++-----
 classes/plmodule.php   |    3 ++-
 classes/plwizard.php   |   15 +++++++++------
 classes/xnet.php       |    1 +
 htdocs/webredirect.php |   12 ++++++++----
 include/platal.inc.php |    1 +
 modules/bandeau.php    |    6 +++---
 modules/carnet.php     |    8 ++++----
 modules/events.php     |    2 +-
 modules/lists.php      |    2 +-
 modules/profile.php    |    2 +-
 modules/xnetevents.php |    4 ++--
 modules/xnetgrp.php    |    4 ++--
 15 files changed, 50 insertions(+), 31 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1921 839d8a87-29fc-0310-9880-83ba4fa771e5

15 files changed:
ChangeLog
Makefile
classes/platal.php
classes/plmodule.php
classes/plwizard.php
classes/xnet.php
htdocs/webredirect.php
include/platal.inc.php
modules/bandeau.php
modules/carnet.php
modules/events.php
modules/lists.php
modules/profile.php
modules/xnetevents.php
modules/xnetgrp.php

index a0a1856..7da9302 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@ VERSION 0.9.15                                                        XX XX 2007
 
 New:
 
+    * Core:
+        - Auto-redirect HTML pages to HTTPS                                -FRU
+
     * Search:
         - Shortcuts to open profiles or search in documentation            -FRU
 
index 768d9ca..a32cc3e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,9 @@
 ################################################################################
 # definitions
 
-VERSION := $(shell grep VERSION ChangeLog | head -1 | sed -e "s/VERSION //;s/\t.*//;s/ .*//")
+VERSNUM := $(shell grep VERSION ChangeLog | head -1 | sed -e "s/VERSION //;s/ .*//")
+VERSTAG := $(shell grep VERSION ChangeLog | head -1 | grep 'XX' > /dev/null 2> /dev/null && echo 'beta')
+VERSION = $(VERSNUM)$(VERSTAG)
 
 PKG_NAME = platal
 PKG_DIST = $(PKG_NAME)-$(VERSION)
index 55e9ada..620f217 100644 (file)
@@ -28,6 +28,8 @@ class Platal
     private $__mods;
     private $__hooks;
 
+    protected $https;
+
     public $ns;
     public $path;
     public $argv;
@@ -86,6 +88,7 @@ class Platal
             return null;
         }
 
+        $this->https = ($hook['type'] & NO_HTTPS) ? false : true;
         $this->argv    = explode('/', substr($this->path, strlen($p)));
         $this->argv[0] = $p;
 
@@ -191,14 +194,16 @@ class Platal
         if (empty($hook)) {
             return PL_NOT_FOUND;
         }
+        global $globals;
+        if ($this->https && !$_SERVER['HTTPS'] && $globals->core->secure_domain) {
+            http_redirect('https://' . $globals->core->secure_domain . $_SERVER['REQUEST_URI']);
+        }
 
         $args    = $this->argv;
         $args[0] = &$page;
 
         if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) {
-            if ($hook['type'] == DO_AUTH) {
-                global $globals;
-    
+            if ($hook['type'] & DO_AUTH) {
                 if (!call_user_func(array($globals->session, 'doAuth'))) {
                     $this->force_login($page);
                 }
@@ -211,8 +216,7 @@ class Platal
         }
 
         $val = call_user_func_array($hook['hook'], $args);
-        if ($val == PL_DO_AUTH) {
-            global $globals;
+        if ($val & PL_DO_AUTH) {
             // The handler need a better auth with the current args
             if (!call_user_func(array($globals->session, 'doAuth'))) {
                 $this->force_login($page);
index 9f31cbe..697b4ef 100644 (file)
@@ -35,7 +35,8 @@ abstract class PLModule
      * right is an atomic right permission (like 'admin', 'user', 'groupadmin', 'groupmember'...)
      *
      * If type is set to NO_AUTH, the system will return 403 instead of asking auth data
-     * this is useful for Ajax handlers
+     * this is useful for Ajax handler
+     * If type is not set to NO_SKIN, the system will consider redirecting the user to https
      */
     public function make_hook($fun, $auth, $perms = 'user', $type = DO_AUTH)
     {
index 26381e4..9a58afe 100644 (file)
@@ -58,11 +58,11 @@ interface PlWizardPage
  */
 class PlWizard
 {
-    const FIRST_PAGE    = "bt_first";
-    const NEXT_PAGE     = "bt_next";
-    const CURRENT_PAGE  = "bt_current";
-    const PREVIOUS_PAGE = "bt_previous";
-    const LAST_PAGE     = "bt_last";
+    const FIRST_PAGE    = 'bt_first';
+    const NEXT_PAGE     = 'bt_next';
+    const CURRENT_PAGE  = 'bt_current';
+    const PREVIOUS_PAGE = 'bt_previous';
+    const LAST_PAGE     = 'bt_last';
 
     protected $name;
     protected $layout;
@@ -129,7 +129,7 @@ class PlWizard
         return new $page($this);
     }
 
-    public function apply(PlatalPage &$smarty, $baseurl)
+    public function apply(PlatalPage &$smarty, $baseurl, $pgid = null)
     {
         $curpage =& $_SESSION[$this->name . '_page'];
 
@@ -158,6 +158,9 @@ class PlWizard
         } else {
             $curpage = 0;
         }
+        if ($this->stateless && (in_array($pgid, $this->lookup) || isset($this->pages[$pgid]))) {
+            $curpage = $pgid;
+        }
 
         // Prepare the page
         $page = $this->getPage($curpage);
index f3da66f..58d1375 100644 (file)
@@ -60,6 +60,7 @@ class Xnet extends Platal
     protected function find_hook()
     {
         $ans = parent::find_hook();
+        $this->https = false;
         if ($ans && $this->ns) {
             $this->path    = $this->ns . substr($this->path, 5);
             $this->argv[0] = $this->ns . substr($this->argv[0], 5);
index 5246d81..dfecc26 100644 (file)
 
 require_once dirname(__FILE__).'/../include/xorg.inc.php';
 
+global $globals;
 list($username, $path) = preg_split('/\//', $_SERVER["REQUEST_URI"], 2, PREG_SPLIT_NO_EMPTY);
 $res = XDB::query(
-        "SELECT  redirecturl
-           FROM  auth_user_quick AS a
-     INNER JOIN  aliases         AS al ON (al.id = a.user_id AND (al.type='a_vie' OR al.type='alias'))
-          WHERE  al.alias = {?}", $username);
+        "SELECT  redirecturl 
+           FROM  auth_user_quick AS a 
+     INNER JOIN  aliases         AS al ON (al.id = a.user_id AND (al.type='a_vie' OR al.type='alias')) 
+      LEFT JOIN  virtuals_redirect AS vr ON (vr.redirect LIKE CONCAT(al.alias, '@%')
+     INNER JOIN  virtuals        AS v ON (v.vid = vr.vid)
+          WHERE  al.alias = {?} OR v.alias = CONCAT({?}, '@', {?})
+       GROUP BY  redirecturl", $username, $username, $globals->mail->alias_dom);
 
 if ($url = $res->fetchOneCell()) {
     $url = preg_replace('@/+$@', '', $url);
index f72c3a8..073479c 100644 (file)
@@ -35,6 +35,7 @@ define('NO_SKIN', 2);
 
 define('NO_AUTH', 0);
 define('DO_AUTH', 1);
+define('NO_HTTPS', 2);
 
 define('DEBUG_BT', 1);
 define('DEBUG_VALID', 2);
index b9269b6..4f77b0c 100644 (file)
@@ -24,9 +24,9 @@ class BandeauModule extends PLModule
     function handlers()
     {
         return array(
-            'bandeau/icone.png'  => $this->make_hook('icone',AUTH_PUBLIC),
-            'bandeau'            => $this->make_hook('html', AUTH_PUBLIC),
-            'bandeau.css'                               => $this->make_hook('css', AUTH_PUBLIC),
+            'bandeau/icone.png'  => $this->make_hook('icone',AUTH_PUBLIC, 'user', NO_HTTPS),
+            'bandeau'            => $this->make_hook('html', AUTH_PUBLIC, 'user', NO_HTTPS),
+            'bandeau.css'                               => $this->make_hook('css', AUTH_PUBLIC, 'user', NO_HTTPS),
         );
     }
 
index 9c9172b..dfc2d6d 100644 (file)
@@ -29,11 +29,11 @@ class CarnetModule extends PLModule
             'carnet/notifs'         => $this->make_hook('notifs',   AUTH_COOKIE),
 
             'carnet/contacts'       => $this->make_hook('contacts', AUTH_COOKIE),
-            'carnet/contacts/pdf'   => $this->make_hook('pdf',      AUTH_COOKIE),
-            'carnet/contacts/ical'  => $this->make_hook('ical',     AUTH_PUBLIC),
-            'carnet/contacts/vcard' => $this->make_hook('vcard',    AUTH_COOKIE),
+            'carnet/contacts/pdf'   => $this->make_hook('pdf',      AUTH_COOKIE, 'user', NO_HTTPS),
+            'carnet/contacts/ical'  => $this->make_hook('ical',     AUTH_PUBLIC, 'user', NO_HTTPS),
+            'carnet/contacts/vcard' => $this->make_hook('vcard',    AUTH_COOKIE, 'user', NO_HTTPS),
 
-            'carnet/rss'            => $this->make_hook('rss',      AUTH_PUBLIC),
+            'carnet/rss'            => $this->make_hook('rss',      AUTH_PUBLIC, 'user', NO_HTTPS),
         );
     }
 
index 2ccd14a..e29b7f2 100644 (file)
@@ -25,7 +25,7 @@ class EventsModule extends PLModule
     {
         return array(
             'events'         => $this->make_hook('ev',        AUTH_COOKIE),
-            'rss'            => $this->make_hook('rss', AUTH_PUBLIC),
+            'rss'            => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
             'events/preview' => $this->make_hook('preview', AUTH_PUBLIC, 'user', NO_AUTH),
             'events/photo'   => $this->make_hook('photo', AUTH_PUBLIC),
             'events/submit'  => $this->make_hook('ev_submit', AUTH_MDP),
index 4ce37e1..9c584dd 100644 (file)
@@ -33,7 +33,7 @@ class ListsModule extends PLModule
             'lists/members'   => $this->make_hook('members',   AUTH_COOKIE),
             'lists/annu'      => $this->make_hook('annu',      AUTH_COOKIE),
             'lists/archives'  => $this->make_hook('archives',  AUTH_COOKIE),
-            'lists/archives/rss' => $this->make_hook('rss',    AUTH_PUBLIC),
+            'lists/archives/rss' => $this->make_hook('rss',    AUTH_PUBLIC, 'user', NO_HTTPS),
 
             'lists/moderate'  => $this->make_hook('moderate',  AUTH_MDP),
             'lists/admin'     => $this->make_hook('admin',     AUTH_MDP),
index ac9d002..013199d 100644 (file)
@@ -43,7 +43,7 @@ class ProfileModule extends PLModule
 
             'groupes-x'        => $this->make_hook('xnet',      AUTH_COOKIE),
 
-            'vcard'   => $this->make_hook('vcard',  AUTH_COOKIE),
+            'vcard'   => $this->make_hook('vcard',  AUTH_COOKIE, 'user', NO_HTTPS),
             'admin/binets'     => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
             'admin/medals'     => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
             'admin/formations' => $this->make_hook('admin_formations', AUTH_MDP, 'admin'),
index db91a51..cd9b550 100644 (file)
@@ -28,8 +28,8 @@ class XnetEventsModule extends PLModule
         return array(
             '%grp/events'       => $this->make_hook('events',  AUTH_MDP),
             '%grp/events/sub'   => $this->make_hook('sub',     AUTH_MDP),
-            '%grp/events/csv'   => $this->make_hook('csv',     AUTH_MDP),
-            '%grp/events/ical'  => $this->make_hook('ical',    AUTH_MDP),
+            '%grp/events/csv'   => $this->make_hook('csv',     AUTH_MDP, 'user', NO_HTTPS),
+            '%grp/events/ical'  => $this->make_hook('ical',    AUTH_MDP, 'user', NO_HTTPS),
             '%grp/events/edit'  => $this->make_hook('edit',    AUTH_MDP, 'groupadmin'),
             '%grp/events/admin' => $this->make_hook('admin',   AUTH_MDP, 'groupmember'),
         );
index c8754d1..918101e 100644 (file)
@@ -97,11 +97,11 @@ class XnetGrpModule extends PLModule
             '%grp/member/new'
                  => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'),
             '%grp/member/new/ajax'
-                 => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH),         
+                 => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH),
             '%grp/member/del'
                  => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'),
 
-            '%grp/rss'             => $this->make_hook('rss', AUTH_PUBLIC),         
+            '%grp/rss'             => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
             '%grp/announce/new'    => $this->make_hook('edit_announce', AUTH_MDP,  'groupadmin'),
             '%grp/announce/edit'   => $this->make_hook('edit_announce', AUTH_MDP,  'groupadmin'),
             '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'),