From 8fc4efa394721853bca6ee0e4f2028f33ed0867d Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Sun, 19 Aug 2007 09:35:54 +0000 Subject: [PATCH] Auto-redirects HTML pages to HTTPS 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 --- 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(-) diff --git a/ChangeLog b/ChangeLog index a0a1856..7da9302 100644 --- 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 diff --git a/Makefile b/Makefile index 768d9ca..a32cc3e 100644 --- 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) diff --git a/classes/platal.php b/classes/platal.php index 55e9ada..620f217 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -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); diff --git a/classes/plmodule.php b/classes/plmodule.php index 9f31cbe..697b4ef 100644 --- a/classes/plmodule.php +++ b/classes/plmodule.php @@ -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) { diff --git a/classes/plwizard.php b/classes/plwizard.php index 26381e4..9a58afe 100644 --- a/classes/plwizard.php +++ b/classes/plwizard.php @@ -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); diff --git a/classes/xnet.php b/classes/xnet.php index f3da66f..58d1375 100644 --- a/classes/xnet.php +++ b/classes/xnet.php @@ -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); diff --git a/htdocs/webredirect.php b/htdocs/webredirect.php index 5246d81..dfecc26 100644 --- a/htdocs/webredirect.php +++ b/htdocs/webredirect.php @@ -21,12 +21,16 @@ 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); diff --git a/include/platal.inc.php b/include/platal.inc.php index f72c3a8..073479c 100644 --- a/include/platal.inc.php +++ b/include/platal.inc.php @@ -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); diff --git a/modules/bandeau.php b/modules/bandeau.php index b9269b6..4f77b0c 100644 --- a/modules/bandeau.php +++ b/modules/bandeau.php @@ -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), ); } diff --git a/modules/carnet.php b/modules/carnet.php index 9c9172b..dfc2d6d 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -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), ); } diff --git a/modules/events.php b/modules/events.php index 2ccd14a..e29b7f2 100644 --- a/modules/events.php +++ b/modules/events.php @@ -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), diff --git a/modules/lists.php b/modules/lists.php index 4ce37e1..9c584dd 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -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), diff --git a/modules/profile.php b/modules/profile.php index ac9d002..013199d 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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'), diff --git a/modules/xnetevents.php b/modules/xnetevents.php index db91a51..cd9b550 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -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'), ); diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index c8754d1..918101e 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -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'), -- 2.1.4