Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 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 | ||
ef0c3d8b | 22 | class XnetSession extends XorgSession |
0337d704 | 23 | { |
6b79b8ef FB |
24 | public function __construct() |
25 | { | |
ab694eb5 | 26 | parent::__construct(); |
6b79b8ef FB |
27 | } |
28 | ||
ab694eb5 | 29 | public function startAvailableAuth() |
1490093c | 30 | { |
6b79b8ef | 31 | if (!S::logged() && Get::has('auth')) { |
ab694eb5 FB |
32 | if (!$this->start(AUTH_MDP)) { |
33 | return false; | |
34 | } | |
6b79b8ef FB |
35 | } |
36 | ||
ab694eb5 | 37 | global $globals; |
7a05c64d | 38 | if (!S::logged() && $globals->xnet->auth_baseurl) { |
ab694eb5 | 39 | // prevent connection to be linked to disconnection |
71fe935c | 40 | if (($i = strpos($_SERVER['REQUEST_URI'], 'exit')) !== false) |
0337d704 | 41 | $returl = "http://{$_SERVER['SERVER_NAME']}".substr($_SERVER['REQUEST_URI'], 0, $i); |
42 | else | |
43 | $returl = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; | |
7a05c64d | 44 | $url = $globals->xnet->auth_baseurl; |
0337d704 | 45 | $url .= "?session=" . session_id(); |
cab08090 | 46 | $url .= "&challenge=" . S::v('challenge'); |
47 | $url .= "&pass=" . md5(S::v('challenge') . $globals->xnet->secret); | |
0337d704 | 48 | $url .= "&url=".urlencode($returl); |
ab694eb5 | 49 | S::set('loginX', $url); |
0337d704 | 50 | } |
bf517daf | 51 | |
52 | if (S::logged() && $globals->asso()) { | |
53 | $perms = S::v('perms'); | |
54 | $perms->rmFlag('groupadmin'); | |
55 | $perms->rmFlag('groupmember'); | |
35fa92e8 | 56 | $perms->rmFlag('groupannu'); |
bf517daf | 57 | if (may_update()) { |
58 | $perms->addFlag('groupadmin'); | |
59 | $perms->addFlag('groupmember'); | |
35fa92e8 | 60 | $perms->addFlag('groupannu'); |
bf517daf | 61 | } |
62 | if (is_member()) { | |
63 | $perms->addFlag('groupmember'); | |
2c86d368 | 64 | if ($globals->asso('pub') != 'private') { |
35fa92e8 | 65 | $perms->addFlag('groupannu'); |
66 | } | |
e5539fd7 PC |
67 | } else if ($globals->asso('pub') == 'public') { |
68 | $perms->addFlag('groupannu'); | |
35fa92e8 | 69 | } |
70 | if ($globals->asso('cat') == 'Promotions') { | |
71 | $perms->addFlag('groupannu'); | |
bf517daf | 72 | } |
ab694eb5 | 73 | S::set('perms', $perms); |
bf517daf | 74 | } |
ab694eb5 | 75 | return true; |
0337d704 | 76 | } |
cab08090 | 77 | |
ab694eb5 | 78 | protected function doAuth($level) |
0337d704 | 79 | { |
ab694eb5 | 80 | if (S::identified()) { // ok, c'est bon, on n'a rien à faire |
1bf36cd1 | 81 | return User::getSilentWithValues(null, array('uid' => S::i('uid'))); |
0337d704 | 82 | } |
ab694eb5 FB |
83 | if (!Get::has('auth')) { |
84 | return null; | |
85 | } | |
86 | global $globals; | |
87 | if (md5('1' . S::v('challenge') . $globals->xnet->secret . Get::i('uid') . '1') != Get::v('auth')) { | |
88 | return null; | |
89 | } | |
90 | Get::kill('auth'); | |
91 | S::set('auth', AUTH_MDP); | |
1bf36cd1 | 92 | return User::getSilentWithValues(null, array('uid' => Get::i('uid'))); |
c0d6753f | 93 | } |
94 | ||
ab694eb5 | 95 | protected function startSessionAs($user, $level) |
bf517daf | 96 | { |
6d1e6661 | 97 | if ($level == AUTH_SUID) { |
ab694eb5 | 98 | S::set('auth', AUTH_MDP); |
0337d704 | 99 | } |
1f759655 | 100 | $res = XDB::query("SELECT a.uid, a.hruid, a.display_name, a.full_name, |
6d1e6661 FB |
101 | a.sex = 'female' AS femme, |
102 | a.email_format, a.token, | |
103 | at.perms, a.is_admin | |
104 | FROM accounts AS a | |
105 | INNER JOIN account_types AS at ON (at.type = a.type) | |
106 | WHERE a.uid = {?} AND a.state = 'active' | |
107 | LIMIT 1", $user->id()); | |
ab694eb5 | 108 | $sess = $res->fetchOneAssoc(); |
ab694eb5 | 109 | $_SESSION = array_merge($_SESSION, $sess); |
6d1e6661 | 110 | $this->makePerms(S::s('perms'), S::b('is_admin')); |
cab08090 | 111 | S::kill('challenge'); |
112 | S::kill('loginX'); | |
0afc7e1e | 113 | S::kill('may_update'); |
114 | S::kill('is_member'); | |
0337d704 | 115 | Get::kill('uid'); |
63528107 | 116 | Get::kill('PHPSESSID'); |
b0b937fd | 117 | |
fd834b4b | 118 | $args = array(); |
b0b937fd | 119 | foreach($_GET as $key => $val) { |
ab694eb5 | 120 | $args[] = urlencode($key). '=' .urlencode($val); |
0337d704 | 121 | } |
ab694eb5 | 122 | return true; |
0337d704 | 123 | } |
124 | ||
ab694eb5 | 125 | public function doSelfSuid() |
0deaff1d | 126 | { |
866bd535 FB |
127 | $user =& S::user(); |
128 | if (!$this->startSUID($user)) { | |
ab694eb5 | 129 | return false; |
0deaff1d | 130 | } |
50d5ec0b | 131 | S::set('perms', User::makePerms('user')); |
ab694eb5 | 132 | return true; |
b8e265bf | 133 | } |
b8e265bf | 134 | |
ab694eb5 | 135 | public function stopSUID() |
eaf30d86 | 136 | { |
0c02607e | 137 | $perms = S::suid('perms'); |
ab694eb5 FB |
138 | if (!parent::stopSUID()) { |
139 | return false; | |
140 | } | |
0deaff1d | 141 | S::kill('may_update'); |
142 | S::kill('is_member'); | |
0c02607e | 143 | S::set('perms', $perms); |
ab694eb5 | 144 | return true; |
b8e265bf | 145 | } |
b8e265bf | 146 | } |
147 | ||
0deaff1d | 148 | // {{{ function may_update |
0337d704 | 149 | |
0deaff1d | 150 | /** Return administration rights for the current asso |
151 | * @param force Force administration rights to be read from database | |
152 | * @param lose Force administration rights to be false | |
153 | */ | |
b8e265bf | 154 | function may_update($force = false, $lose = false) |
155 | { | |
156 | if (!isset($_SESSION['may_update'])) { | |
157 | $_SESSION['may_update'] = array(); | |
158 | } | |
159 | $may_update =& $_SESSION['may_update']; | |
160 | ||
0337d704 | 161 | global $globals; |
b8e265bf | 162 | $asso_id = $globals->asso('id'); |
0deaff1d | 163 | if (!$asso_id) { |
164 | return false; | |
165 | } elseif ($lose) { | |
166 | $may_update[$asso_id] = false; | |
0c02607e | 167 | } elseif (S::admin() || (S::suid() && $force)) { |
0deaff1d | 168 | $may_update[$asso_id] = true; |
169 | } elseif (!isset($may_update[$asso_id]) || $force) { | |
b8e265bf | 170 | $res = XDB::query("SELECT perms |
eb41eda9 | 171 | FROM group_members |
b8e265bf | 172 | WHERE uid={?} AND asso_id={?}", |
a14159bf | 173 | S::v('uid'), $asso_id); |
b8e265bf | 174 | $may_update[$asso_id] = ($res->fetchOneCell() == 'admin'); |
b8e265bf | 175 | } |
176 | return $may_update[$asso_id]; | |
0337d704 | 177 | } |
178 | ||
179 | // }}} | |
0deaff1d | 180 | // {{{ function is_member |
0337d704 | 181 | |
0deaff1d | 182 | /** Get membership informations for the current asso |
183 | * @param force Force membership to be read from database | |
184 | * @param lose Force membership to be false | |
eaf30d86 | 185 | */ |
b8e265bf | 186 | function is_member($force = false, $lose = false) |
c1863ee9 | 187 | { |
b8e265bf | 188 | if (!isset($_SESSION['is_member'])) { |
189 | $_SESSION['is_member'] = array(); | |
190 | } | |
191 | $is_member =& $_SESSION['is_member']; | |
192 | ||
0337d704 | 193 | global $globals; |
258b9710 | 194 | $asso_id = $globals->asso('id'); |
0deaff1d | 195 | if (!$asso_id) { |
196 | return false; | |
b8e265bf | 197 | } elseif ($lose) { |
198 | $is_member[$asso_id] = false; | |
0c02607e | 199 | } elseif (S::suid() && $force) { |
0deaff1d | 200 | $is_member[$asso_id] = true; |
201 | } elseif (!isset($is_member[$asso_id]) || $force) { | |
202 | $res = XDB::query("SELECT COUNT(*) | |
eb41eda9 | 203 | FROM group_members |
0deaff1d | 204 | WHERE uid={?} AND asso_id={?}", |
205 | S::v('uid'), $asso_id); | |
206 | $is_member[$asso_id] = ($res->fetchOneCell() == 1); | |
258b9710 | 207 | } |
208 | return $is_member[$asso_id]; | |
0337d704 | 209 | } |
210 | ||
211 | // }}} | |
a7de4ef7 | 212 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 213 | ?> |