Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
0337d704 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
4869f665 | 22 | class XnetSession |
0337d704 | 23 | { |
0337d704 | 24 | // {{{ function init |
cab08090 | 25 | |
eaf30d86 | 26 | public static function init() |
1490093c | 27 | { |
0337d704 | 28 | global $globals; |
29 | ||
cab08090 | 30 | S::init(); |
31 | ||
cab08090 | 32 | if (!S::logged()) { |
0337d704 | 33 | // prevent connexion to be linked to deconnexion |
71fe935c | 34 | if (($i = strpos($_SERVER['REQUEST_URI'], 'exit')) !== false) |
0337d704 | 35 | $returl = "http://{$_SERVER['SERVER_NAME']}".substr($_SERVER['REQUEST_URI'], 0, $i); |
36 | else | |
37 | $returl = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; | |
1fd4da04 | 38 | $url = "https://www.polytechnique.org/auth-groupex"; |
0337d704 | 39 | $url .= "?session=" . session_id(); |
cab08090 | 40 | $url .= "&challenge=" . S::v('challenge'); |
41 | $url .= "&pass=" . md5(S::v('challenge') . $globals->xnet->secret); | |
0337d704 | 42 | $url .= "&url=".urlencode($returl); |
cab08090 | 43 | $_SESSION['loginX'] = $url; |
0337d704 | 44 | } |
bf517daf | 45 | |
46 | if (S::logged() && $globals->asso()) { | |
47 | $perms = S::v('perms'); | |
48 | $perms->rmFlag('groupadmin'); | |
49 | $perms->rmFlag('groupmember'); | |
35fa92e8 | 50 | $perms->rmFlag('groupannu'); |
bf517daf | 51 | if (may_update()) { |
52 | $perms->addFlag('groupadmin'); | |
53 | $perms->addFlag('groupmember'); | |
35fa92e8 | 54 | $perms->addFlag('groupannu'); |
bf517daf | 55 | } |
56 | if (is_member()) { | |
57 | $perms->addFlag('groupmember'); | |
2c86d368 | 58 | if ($globals->asso('pub') != 'private') { |
35fa92e8 | 59 | $perms->addFlag('groupannu'); |
60 | } | |
61 | } | |
62 | if ($globals->asso('cat') == 'Promotions') { | |
63 | $perms->addFlag('groupannu'); | |
bf517daf | 64 | } |
65 | $_SESSION['perms'] = $perms; | |
66 | } | |
0337d704 | 67 | } |
cab08090 | 68 | |
0337d704 | 69 | // }}} |
6995a9b9 | 70 | // {{{ public static function destroy() |
cab08090 | 71 | |
6995a9b9 | 72 | public static function destroy() { |
cab08090 | 73 | S::destroy(); |
0337d704 | 74 | XnetSession::init(); |
75 | } | |
cab08090 | 76 | |
0337d704 | 77 | // }}} |
6995a9b9 | 78 | // {{{ public static function doAuth() |
0337d704 | 79 | |
80 | /** Try to do an authentication. | |
81 | * | |
82 | * @param page the calling page (by reference) | |
83 | */ | |
6995a9b9 | 84 | public static function doAuth() |
0337d704 | 85 | { |
a7de4ef7 | 86 | if (S::identified()) { // ok, c'est bon, on n'a rien à faire |
0deaff1d | 87 | return true; |
88 | } | |
0337d704 | 89 | |
90 | if (Get::has('auth')) { | |
b0b937fd | 91 | return XnetSession::doAuthX(); |
0337d704 | 92 | } |
63528107 | 93 | |
94 | return false; | |
0337d704 | 95 | } |
96 | ||
97 | // }}} | |
c0d6753f | 98 | // {{{ doAuthCookie |
99 | ||
6995a9b9 | 100 | public static function doAuthCookie() { |
c0d6753f | 101 | return XnetSession::doAuth(); |
102 | } | |
103 | ||
104 | // }}} | |
0337d704 | 105 | // {{{ doAuthX |
106 | ||
eaf30d86 | 107 | public static function doAuthX() |
bf517daf | 108 | { |
b0b937fd | 109 | global $globals, $page; |
0337d704 | 110 | |
5e2307dc | 111 | if (md5('1'.S::v('challenge').$globals->xnet->secret.Get::i('uid').'1') != Get::v('auth')) { |
9fcc6565 | 112 | Get::kill('auth'); |
7e1efe61 FB |
113 | if (!$page) { |
114 | require_once 'xnet.inc.php'; | |
115 | new_skinned_page('platal/index.tpl'); | |
116 | } | |
0337d704 | 117 | $page->kill("Erreur d'authentification avec polytechnique.org !"); |
118 | } | |
119 | ||
08cce2ff | 120 | $res = XDB::query(" |
0337d704 | 121 | SELECT u.user_id AS uid, prenom, nom, perms, promo, password, FIND_IN_SET('femme', u.flags) AS femme, |
122 | a.alias AS forlife, a2.alias AS bestalias, q.core_mail_fmt AS mail_fmt, q.core_rss_hash | |
123 | FROM auth_user_md5 AS u | |
124 | INNER JOIN auth_user_quick AS q USING(user_id) | |
125 | INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') | |
126 | INNER JOIN aliases AS a2 ON (u.user_id = a2.id AND FIND_IN_SET('bestalias',a2.flags)) | |
127 | WHERE u.user_id = {?} AND u.perms IN('admin','user') | |
5e2307dc | 128 | LIMIT 1", Get::i('uid')); |
0337d704 | 129 | $_SESSION = array_merge($_SESSION, $res->fetchOneAssoc()); |
130 | $_SESSION['auth'] = AUTH_MDP; | |
bf517daf | 131 | require_once 'xorg/session.inc.php'; |
132 | $_SESSION['perms'] =& XorgSession::make_perms(S::v('perms')); | |
cab08090 | 133 | S::kill('challenge'); |
134 | S::kill('loginX'); | |
0afc7e1e | 135 | S::kill('may_update'); |
136 | S::kill('is_member'); | |
0337d704 | 137 | Get::kill('auth'); |
138 | Get::kill('uid'); | |
27472b85 | 139 | $path = Get::v('n'); |
140 | Get::kill('n'); | |
63528107 | 141 | Get::kill('PHPSESSID'); |
b0b937fd | 142 | |
fd834b4b | 143 | $args = array(); |
b0b937fd | 144 | foreach($_GET as $key => $val) { |
0337d704 | 145 | $args[] = urlencode($key).'='.urlencode($val); |
146 | } | |
63528107 | 147 | |
fd834b4b | 148 | http_redirect($globals->baseurl . '/' . $path, join('&', $args)); |
0337d704 | 149 | } |
150 | ||
151 | // }}} | |
0deaff1d | 152 | // {{{ doSelfSuid |
b8e265bf | 153 | |
0deaff1d | 154 | public static function doSelfSuid() |
155 | { | |
156 | if (!S::has('suid')) { | |
157 | $_SESSION['suid'] = $_SESSION; | |
158 | } | |
bf517daf | 159 | require_once 'xorg/session.inc.php'; |
160 | $_SESSION['perms'] =& XorgSession::make_perms('user'); | |
b8e265bf | 161 | } |
b8e265bf | 162 | |
0deaff1d | 163 | // }}} |
164 | // {{{ killSuid | |
b8e265bf | 165 | |
0deaff1d | 166 | public static function killSuid() |
eaf30d86 | 167 | { |
0deaff1d | 168 | if (!S::has('suid')) { |
169 | return; | |
170 | } | |
171 | $suid = S::v('suid'); | |
172 | S::kill('suid'); | |
173 | S::kill('may_update'); | |
174 | S::kill('is_member'); | |
175 | $_SESSION['perms'] = $suid['perms']; | |
b8e265bf | 176 | } |
0deaff1d | 177 | |
178 | // }}} | |
b8e265bf | 179 | } |
180 | ||
181 | // }}} | |
0deaff1d | 182 | // {{{ function may_update |
0337d704 | 183 | |
0deaff1d | 184 | /** Return administration rights for the current asso |
185 | * @param force Force administration rights to be read from database | |
186 | * @param lose Force administration rights to be false | |
187 | */ | |
b8e265bf | 188 | function may_update($force = false, $lose = false) |
189 | { | |
190 | if (!isset($_SESSION['may_update'])) { | |
191 | $_SESSION['may_update'] = array(); | |
192 | } | |
193 | $may_update =& $_SESSION['may_update']; | |
194 | ||
0337d704 | 195 | global $globals; |
b8e265bf | 196 | $asso_id = $globals->asso('id'); |
0deaff1d | 197 | if (!$asso_id) { |
198 | return false; | |
199 | } elseif ($lose) { | |
200 | $may_update[$asso_id] = false; | |
201 | } elseif (S::has_perms() || (S::has('suid') && $force)) { | |
202 | $may_update[$asso_id] = true; | |
203 | } elseif (!isset($may_update[$asso_id]) || $force) { | |
b8e265bf | 204 | $res = XDB::query("SELECT perms |
205 | FROM groupex.membres | |
206 | WHERE uid={?} AND asso_id={?}", | |
a14159bf | 207 | S::v('uid'), $asso_id); |
b8e265bf | 208 | $may_update[$asso_id] = ($res->fetchOneCell() == 'admin'); |
b8e265bf | 209 | } |
210 | return $may_update[$asso_id]; | |
0337d704 | 211 | } |
212 | ||
213 | // }}} | |
0deaff1d | 214 | // {{{ function is_member |
0337d704 | 215 | |
0deaff1d | 216 | /** Get membership informations for the current asso |
217 | * @param force Force membership to be read from database | |
218 | * @param lose Force membership to be false | |
eaf30d86 | 219 | */ |
b8e265bf | 220 | function is_member($force = false, $lose = false) |
c1863ee9 | 221 | { |
b8e265bf | 222 | if (!isset($_SESSION['is_member'])) { |
223 | $_SESSION['is_member'] = array(); | |
224 | } | |
225 | $is_member =& $_SESSION['is_member']; | |
226 | ||
0337d704 | 227 | global $globals; |
258b9710 | 228 | $asso_id = $globals->asso('id'); |
0deaff1d | 229 | if (!$asso_id) { |
230 | return false; | |
b8e265bf | 231 | } elseif ($lose) { |
232 | $is_member[$asso_id] = false; | |
0deaff1d | 233 | } elseif (S::has('suid') && $force) { |
234 | $is_member[$asso_id] = true; | |
235 | } elseif (!isset($is_member[$asso_id]) || $force) { | |
236 | $res = XDB::query("SELECT COUNT(*) | |
237 | FROM groupex.membres | |
238 | WHERE uid={?} AND asso_id={?}", | |
239 | S::v('uid'), $asso_id); | |
240 | $is_member[$asso_id] = ($res->fetchOneCell() == 1); | |
258b9710 | 241 | } |
242 | return $is_member[$asso_id]; | |
0337d704 | 243 | } |
244 | ||
245 | // }}} | |
a7de4ef7 | 246 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 247 | ?> |