Commit | Line | Data |
---|---|---|
86f0a6af | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 Polytechnique.org * |
86f0a6af | 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 | ||
22 | class AdminModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
5f9a40b4 | 27 | 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'), |
866bd535 | 28 | 'get_rights' => $this->make_hook('get_rights', AUTH_MDP, 'admin'), |
5f9a40b4 | 29 | 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), |
86f0a6af | 30 | 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), |
1c48c2a9 | 31 | 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP, 'admin'), |
86f0a6af | 32 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), |
e7ae7df9 | 33 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
e7ae7df9 | 34 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
e7ae7df9 | 35 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
36 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), | |
e7ae7df9 | 37 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
38 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), | |
39 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), | |
40 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), | |
ccdbc270 | 41 | 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'), |
e7ae7df9 | 42 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
43 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), | |
e7ae7df9 | 44 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
1f53925a | 45 | 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), |
e7ae7df9 | 46 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
e18888f4 | 47 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), |
3aec1c21 | 48 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
5480a216 | 49 | 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), |
f141945d | 50 | 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), |
fd1ce8c5 | 51 | 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP, 'admin'), |
8f2104cb | 52 | 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP, 'admin'), |
4d336f59 | 53 | 'admin/jobs' => $this->make_hook('jobs', AUTH_MDP, 'admin'), |
86f0a6af | 54 | ); |
55 | } | |
56 | ||
5f9a40b4 | 57 | function handler_phpinfo(&$page) |
58 | { | |
59 | phpinfo(); | |
60 | exit; | |
61 | } | |
62 | ||
866bd535 FB |
63 | function handler_get_rights(&$page, $level) |
64 | { | |
65 | if (S::suid()) { | |
66 | $page->kill('Déjà en SUID'); | |
67 | } | |
68 | $user =& S::user(); | |
69 | Platal::session()->startSUID($user, $level); | |
70 | ||
71 | pl_redirect('/'); | |
72 | } | |
73 | ||
86f0a6af | 74 | function handler_default(&$page) |
75 | { | |
76 | $page->changeTpl('admin/index.tpl'); | |
46f272fe | 77 | $page->setTitle('Administration'); |
86f0a6af | 78 | } |
79 | ||
80 | function handler_postfix_delayed(&$page) | |
81 | { | |
82 | $page->changeTpl('admin/postfix_delayed.tpl'); | |
46f272fe | 83 | $page->setTitle('Administration - Postfix : Retardés'); |
86f0a6af | 84 | |
85 | if (Env::has('del')) { | |
86 | $crc = Env::v('crc'); | |
87 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); | |
faefdbb7 | 88 | $page->trigSuccess($crc." verra tous ses emails supprimés !"); |
86f0a6af | 89 | } elseif (Env::has('ok')) { |
90 | $crc = Env::v('crc'); | |
91 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); | |
a7d35093 | 92 | $page->trigSuccess($crc." a le droit de passer !"); |
86f0a6af | 93 | } |
94 | ||
95 | $sql = XDB::iterator( | |
96 | "SELECT crc, nb, update_time, create_time, | |
97 | FIND_IN_SET('del', release) AS del, | |
98 | FIND_IN_SET('ok', release) AS ok | |
99 | FROM postfix_mailseen | |
100 | WHERE nb >= 30 | |
101 | ORDER BY release != ''"); | |
102 | ||
103 | $page->assign_by_ref('mails', $sql); | |
104 | } | |
105 | ||
106 | function handler_postfix_regexpsbounces(&$page, $new = null) { | |
107 | $page->changeTpl('admin/emails_bounces_re.tpl'); | |
46f272fe | 108 | $page->setTitle('Administration - Postfix : Regexps Bounces'); |
86f0a6af | 109 | $page->assign('new', $new); |
110 | ||
111 | if (Post::has('submit')) { | |
112 | foreach (Env::v('lvl') as $id=>$val) { | |
113 | XDB::query( | |
114 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", | |
115 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] | |
116 | ); | |
117 | } | |
118 | } | |
119 | ||
120 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); | |
121 | } | |
122 | ||
441e9e98 | 123 | // {{{ logger view |
86f0a6af | 124 | |
441e9e98 | 125 | /** Retrieves the available days for a given year and month. |
126 | * Obtain a list of days of the given month in the given year | |
127 | * that are within the range of dates that we have log entries for. | |
128 | * | |
129 | * @param integer year | |
130 | * @param integer month | |
131 | * @return array days in that month we have log entries covering. | |
132 | * @private | |
133 | */ | |
134 | function _getDays($year, $month) | |
135 | { | |
136 | // give a 'no filter' option | |
137 | $months[0] = "----"; | |
138 | ||
139 | if ($year && $month) { | |
140 | $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, | |
141 | 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
142 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), | |
143 | MONTH(MAX(start)), MONTH(MIN(start)), | |
144 | DAYOFMONTH(MAX(start)), | |
145 | DAYOFMONTH(MIN(start)) | |
146 | FROM logger.sessions"); | |
147 | list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow(); | |
148 | ||
149 | if (($year < $ymin) || ($year == $ymin && $month < $mmin)) { | |
150 | return array(); | |
151 | } | |
152 | ||
153 | if (($year > $ymax) || ($year == $ymax && $month > $mmax)) { | |
154 | return array(); | |
155 | } | |
156 | ||
157 | $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1; | |
158 | $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month]; | |
159 | ||
160 | for($i = $min; $i<=$max; $i++) { | |
161 | $days[$i] = $i; | |
162 | } | |
163 | } | |
164 | return $days; | |
165 | } | |
166 | ||
167 | ||
168 | /** Retrieves the available months for a given year. | |
169 | * Obtains a list of month numbers that are within the timeframe that | |
170 | * we have log entries for. | |
171 | * | |
172 | * @param integer year | |
173 | * @return array List of month numbers we have log info for. | |
174 | * @private | |
175 | */ | |
176 | function _getMonths($year) | |
177 | { | |
178 | // give a 'no filter' option | |
179 | $months[0] = "----"; | |
180 | ||
181 | if ($year) { | |
182 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), | |
183 | MONTH(MAX(start)), MONTH(MIN(start)) | |
184 | FROM logger.sessions"); | |
185 | list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow(); | |
186 | ||
187 | if (($year < $ymin) || ($year > $ymax)) { | |
188 | return array(); | |
189 | } | |
190 | ||
191 | $min = $year == $ymin ? intval($mmin) : 1; | |
192 | $max = $year == $ymax ? intval($mmax) : 12; | |
193 | ||
194 | for($i = $min; $i<=$max; $i++) { | |
195 | $months[$i] = $i; | |
196 | } | |
197 | } | |
198 | return $months; | |
199 | } | |
200 | ||
201 | ||
202 | /** Retrieves the available years. | |
203 | * Obtains a list of years that we have log entries covering. | |
204 | * | |
205 | * @return array years we have log entries for. | |
206 | * @private | |
207 | */ | |
208 | function _getYears() | |
209 | { | |
210 | // give a 'no filter' option | |
211 | $years[0] = "----"; | |
212 | ||
213 | // retrieve available years | |
214 | $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions"); | |
215 | list($max, $min) = $res->fetchOneRow(); | |
216 | ||
217 | for($i = intval($min); $i<=$max; $i++) { | |
218 | $years[$i] = $i; | |
219 | } | |
220 | return $years; | |
221 | } | |
222 | ||
223 | ||
224 | /** Make a where clause to get a user's sessions. | |
225 | * Prepare the where clause request that will retrieve the sessions. | |
226 | * | |
227 | * @param $year INTEGER Only get log entries made during the given year. | |
228 | * @param $month INTEGER Only get log entries made during the given month. | |
229 | * @param $day INTEGER Only get log entries made during the given day. | |
230 | * @param $uid INTEGER Only get log entries referring to the given user ID. | |
231 | * | |
232 | * @return STRING the WHERE clause of a query, including the 'WHERE' keyword | |
233 | * @private | |
234 | */ | |
235 | function _makeWhere($year, $month, $day, $uid) | |
236 | { | |
237 | // start constructing the "where" clause | |
238 | $where = array(); | |
239 | ||
240 | if ($uid) | |
241 | array_push($where, "uid='$uid'"); | |
242 | ||
243 | // we were given at least a year | |
244 | if ($year) { | |
245 | if ($day) { | |
246 | $dmin = mktime(0, 0, 0, $month, $day, $year); | |
247 | $dmax = mktime(0, 0, 0, $month, $day+1, $year); | |
248 | } elseif ($month) { | |
249 | $dmin = mktime(0, 0, 0, $month, 1, $year); | |
250 | $dmax = mktime(0, 0, 0, $month+1, 1, $year); | |
251 | } else { | |
252 | $dmin = mktime(0, 0, 0, 1, 1, $year); | |
253 | $dmax = mktime(0, 0, 0, 1, 1, $year+1); | |
254 | } | |
255 | $where[] = "start >= " . date("Ymd000000", $dmin); | |
256 | $where[] = "start < " . date("Ymd000000", $dmax); | |
257 | } | |
258 | ||
259 | if (!empty($where)) { | |
260 | return ' WHERE ' . implode($where, " AND "); | |
261 | } else { | |
262 | return ''; | |
263 | } | |
264 | // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC | |
265 | } | |
266 | ||
267 | // }}} | |
268 | ||
269 | function handler_logger(&$page, $action = null, $arg = null) { | |
270 | if ($action == 'session') { | |
271 | ||
272 | // we are viewing a session | |
273 | $res = XDB::query("SELECT ls.*, a.alias AS username, sa.alias AS suer | |
274 | FROM logger.sessions AS ls | |
275 | LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie') | |
276 | LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie') | |
277 | WHERE ls.id = {?}", $arg); | |
278 | ||
279 | $page->assign('session', $a = $res->fetchOneAssoc()); | |
280 | ||
504ccd57 | 281 | $res = XDB::iterator('SELECT a.text, e.data, e.stamp |
441e9e98 | 282 | FROM logger.events AS e |
283 | LEFT JOIN logger.actions AS a ON e.action=a.id | |
284 | WHERE e.session={?}', $arg); | |
285 | while ($myarr = $res->next()) { | |
286 | $page->append('events', $myarr); | |
287 | } | |
288 | ||
289 | } else { | |
290 | $loguser = $action == 'user' ? $arg : Env::v('loguser'); | |
291 | ||
292 | $res = XDB::query('SELECT id FROM aliases WHERE alias={?}', | |
293 | $loguser); | |
294 | $loguid = $res->fetchOneCell(); | |
295 | ||
296 | if ($loguid) { | |
297 | $year = Env::i('year'); | |
298 | $month = Env::i('month'); | |
299 | $day = Env::i('day'); | |
300 | } else { | |
301 | $year = Env::i('year', intval(date('Y'))); | |
302 | $month = Env::i('month', intval(date('m'))); | |
303 | $day = Env::i('day', intval(date('d'))); | |
304 | } | |
305 | ||
306 | if (!$year) | |
307 | $month = 0; | |
308 | if (!$month) | |
309 | $day = 0; | |
310 | ||
311 | // smarty assignments | |
312 | // retrieve available years | |
313 | $page->assign('years', $this->_getYears()); | |
314 | $page->assign('year', $year); | |
315 | ||
316 | // retrieve available months for the current year | |
317 | $page->assign('months', $this->_getMonths($year)); | |
318 | $page->assign('month', $month); | |
319 | ||
320 | // retrieve available days for the current year and month | |
321 | $page->assign('days', $this->_getDays($year, $month)); | |
322 | $page->assign('day', $day); | |
323 | ||
324 | $page->assign('loguser', $loguser); | |
325 | // smarty assignments | |
326 | ||
327 | if ($loguid || $year) { | |
328 | ||
329 | // get the requested sessions | |
330 | $where = $this->_makeWhere($year, $month, $day, $loguid); | |
504ccd57 | 331 | $select = "SELECT s.id, s.start, s.uid, |
441e9e98 | 332 | a.alias as username |
333 | FROM logger.sessions AS s | |
334 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie') | |
335 | $where | |
336 | ORDER BY start DESC"; | |
337 | $res = XDB::iterator($select); | |
338 | ||
339 | $sessions = array(); | |
340 | while ($mysess = $res->next()) { | |
341 | $mysess['events'] = array(); | |
342 | $sessions[$mysess['id']] = $mysess; | |
343 | } | |
344 | array_reverse($sessions); | |
345 | ||
346 | // attach events | |
347 | $sql = "SELECT s.id, a.text | |
348 | FROM logger.sessions AS s | |
349 | LEFT JOIN logger.events AS e ON(e.session=s.id) | |
350 | INNER JOIN logger.actions AS a ON(a.id=e.action) | |
351 | $where"; | |
352 | ||
353 | $res = XDB::iterator($sql); | |
354 | while ($event = $res->next()) { | |
355 | array_push($sessions[$event['id']]['events'], $event['text']); | |
356 | } | |
357 | $page->assign_by_ref('sessions', $sessions); | |
358 | } else { | |
a7de4ef7 | 359 | $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur"); |
441e9e98 | 360 | } |
86f0a6af | 361 | } |
362 | ||
8b1f8e12 | 363 | $page->changeTpl('admin/logger-view.tpl'); |
86f0a6af | 364 | |
46f272fe | 365 | $page->setTitle('Administration - Logs des sessions'); |
86f0a6af | 366 | } |
367 | ||
f97f90f0 | 368 | function handler_user(&$page, $login = false) |
369 | { | |
84270653 | 370 | global $globals; |
86f0a6af | 371 | $page->changeTpl('admin/utilisateurs.tpl'); |
f9743cf1 | 372 | $page->setTitle('Administration - Compte'); |
86f0a6af | 373 | |
0c02607e | 374 | if (S::suid()) { |
7cbf5d4b | 375 | $page->kill("Déjà en SUID !!!"); |
86f0a6af | 376 | } |
377 | ||
d5fbeef6 | 378 | // Loads the user identity using the environment. |
4f903ea6 FB |
379 | $user = User::get($login); |
380 | $login = $user->login(); | |
381 | $registered = ($user->state != 'pending'); | |
86f0a6af | 382 | |
4f903ea6 FB |
383 | // Form processing |
384 | if (!empty($_POST)) { | |
385 | S::assert_xsrf_token(); | |
386 | if (Post::has('uid') && Post::i('uid') != $user->id()) { | |
387 | $page->kill('Une erreur s\'est produite'); | |
388 | } | |
86f0a6af | 389 | } |
390 | ||
d5fbeef6 | 391 | // Handles specific requests (AX sync, su, ...). |
4f903ea6 | 392 | if(Post::has('logs_account')) { |
d5fbeef6 | 393 | pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); |
86f0a6af | 394 | } |
395 | ||
4f903ea6 | 396 | if(Post::has('su_button') && $registered) { |
866bd535 | 397 | if (!Platal::session()->startSUID($user)) { |
83752d10 | 398 | $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login()); |
f97f90f0 | 399 | } else { |
d5fbeef6 | 400 | pl_redirect(""); |
eaf30d86 | 401 | } |
d5fbeef6 | 402 | } |
86f0a6af | 403 | |
f9743cf1 | 404 | // Account Form {{{ |
83752d10 | 405 | $to_update = array(); |
4f903ea6 | 406 | if (Post::has('disable_weak_access')) { |
83752d10 | 407 | $to_update['weak_password'] = null; |
4f903ea6 FB |
408 | } else if (Post::has('update_account')) { |
409 | if (Post::s('full_name') != $user->fullName()) { | |
410 | // XXX: Update profile if a profile is associated | |
411 | $to_update['full_name'] = Post::s('full_name'); | |
83752d10 | 412 | } |
4f903ea6 FB |
413 | if (Post::s('display_name') != $user->displayName()) { |
414 | // XXX: Update profile if a profile is associated | |
415 | $to_update['display_name'] = Post::s('display_name'); | |
83752d10 | 416 | } |
4f903ea6 FB |
417 | if (Post::s('sex') != ($user->isFemale() ? 'female' : 'male')) { |
418 | $to_update['sex'] = Post::s('sex'); | |
83752d10 | 419 | } |
4f903ea6 FB |
420 | if (!Post::blank('hashpass')) { |
421 | $to_update['password'] = Post::s('hashpass'); | |
7679a55a VZ |
422 | // TODO: Propagate the password update to GoogleApps, when required. Eg: |
423 | // $account = new GoogleAppsAccount($user); | |
424 | // if ($account->active() && $account->sync_password) { | |
425 | // $account->set_password($pass_encrypted); | |
426 | // } | |
83752d10 | 427 | } |
4f903ea6 FB |
428 | if (!Post::blank('weak_password')) { |
429 | $to_update['weak_password'] = Post::s('weak_password'); | |
83752d10 | 430 | } |
4f903ea6 FB |
431 | if (Post::i('token_access', 0) != ($user->token_access ? 1 : 0)) { |
432 | $to_update['token'] = Post::i('token_access') ? rand_url_id(16) : null; | |
83752d10 | 433 | } |
4f903ea6 FB |
434 | if (Post::i('skin', 0) != $user->skin) { |
435 | $to_update['skin'] = Post::i('skin', 0); | |
83752d10 FB |
436 | if ($to_update['skin'] == 0) { |
437 | $to_update['skin'] = null; | |
438 | } | |
439 | } | |
4f903ea6 FB |
440 | if (Post::s('state') != $user->state) { |
441 | $to_update['state'] = Post::s('state'); | |
83752d10 | 442 | } |
4f903ea6 FB |
443 | if (Post::i('is_admin', 0) != ($user->is_admin ? 1 : 0)) { |
444 | $to_update['is_admin'] = Post::b('is_admin'); | |
83752d10 | 445 | } |
4f903ea6 FB |
446 | if (Post::s('type') != $user->type) { |
447 | $to_update['type'] = Post::s('type'); | |
83752d10 | 448 | } |
4f903ea6 | 449 | if (Post::i('watch', 0) != ($user->watch ? 1 : 0)) { |
83752d10 | 450 | $to_update['flags'] = new PlFlagset(); |
4f903ea6 | 451 | $to_update['flags']->addFlag('watch', Post::i('watch')); |
83752d10 | 452 | } |
4f903ea6 FB |
453 | if (Post::t('comment') != $user->comment) { |
454 | $to_update['comment'] = Post::blank('comment') ? null : Post::t('comment'); | |
83752d10 FB |
455 | } |
456 | } | |
457 | if (!empty($to_update)) { | |
7679a55a VZ |
458 | // TODO: fetch the initial values of the fields, and eventually send |
459 | // a summary of the changes to an admin. | |
83752d10 FB |
460 | $set = array(); |
461 | foreach ($to_update as $k => $value) { | |
462 | $set[] = XDB::format($k . ' = {?}', $value); | |
463 | } | |
464 | XDB::execute('UPDATE accounts | |
465 | SET ' . implode(', ', $set) . ' | |
466 | WHERE uid = ' . XDB::format('{?}', $user->id())); | |
467 | $page->trigSuccess('Données du compte mise à jour avec succès'); | |
468 | $user = User::getWithUID($user->id()); | |
469 | } | |
f9743cf1 | 470 | // }}} |
4f903ea6 | 471 | |
f9743cf1 | 472 | // Profile form {{{ |
4f903ea6 FB |
473 | if (Post::has('add_profile') || Post::has('del_profile') || Post::has('owner')) { |
474 | if (Post::i('del_profile', 0) != 0) { | |
f9743cf1 FB |
475 | XDB::execute('DELETE FROM account_profiles |
476 | WHERE uid = {?} AND pid = {?}', | |
4f903ea6 FB |
477 | $user->id(), Post::i('del_profile')); |
478 | } else if (!Post::blank('new_profile')) { | |
479 | $profile = Profile::get(Post::t('new_profile')); | |
f9743cf1 | 480 | if (!$profile) { |
4f903ea6 | 481 | $page->trigError('Le profil ' . Post::t('new_profile') . ' n\'existe pas'); |
f9743cf1 FB |
482 | } else { |
483 | XDB::execute('INSERT IGNORE INTO account_profiles (uid, pid) | |
484 | VALUES ({?}, {?})', | |
485 | $user->id(), $profile->id()); | |
486 | } | |
487 | } | |
488 | XDB::execute('UPDATE account_profiles | |
489 | SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\')) | |
490 | WHERE uid = {?}', | |
4f903ea6 | 491 | Post::i('owner'), $user->id()); |
f9743cf1 | 492 | } |
f9743cf1 FB |
493 | // }}} |
494 | ||
4f903ea6 FB |
495 | // Email forwards form {{{ |
496 | require_once("emails.inc.php"); | |
497 | $redirect = ($registered ? new Redirect($user) : null); | |
498 | if (Post::has('add_fwd')) { | |
499 | $email = Post::t('email'); | |
500 | if (!isvalid_email_redirection($email)) { | |
501 | $page->trigError("Email non valide: $email"); | |
502 | } else { | |
503 | $redirect->add_email($email); | |
504 | $page->trigSuccess("Ajout de $email effectué"); | |
505 | } | |
506 | } else if (!Post::blank('del_fwd')) { | |
507 | $redirect->delete_email(Post::t('del_fwd')); | |
508 | } else if (!Post::blank('activate_fwd')) { | |
509 | $redirect->modify_one_email(Post::t('activate_fwd', true)); | |
510 | } else if (!Post::blank('deactivate_fwd')) { | |
511 | $redirect->modify_one_email(Post::t('deactivate_fwd', false)); | |
512 | } else if (Post::has('disable_fwd')) { | |
513 | $redirect->disable(); | |
514 | } else if (Post::has('enable_fwd')) { | |
515 | $redirect->enable(); | |
516 | } else if (!Post::blank('clean_fwd')) { | |
517 | $redirect->clean_errors(Post::t('clean_fwd')); | |
518 | } | |
519 | // }}} | |
d5fbeef6 | 520 | |
4f903ea6 FB |
521 | // Email alias form {{{ |
522 | if (Post::has('add_alias')) { | |
523 | // Splits new alias in user and fqdn. | |
524 | $alias = Env::t('email'); | |
525 | if (strpos($alias, '@') !== false) { | |
526 | list($alias, $domain) = explode('@', $alias); | |
527 | } else { | |
528 | $domain = $globals->mail->domain; | |
529 | } | |
84270653 | 530 | |
4f903ea6 FB |
531 | // Checks for alias' user validity. |
532 | if (!preg_match('/[-a-z0-9\.]+/s', $alias)) { | |
533 | $page->trigError("'$alias' n'est pas un alias valide"); | |
534 | } | |
86f0a6af | 535 | |
4f903ea6 FB |
536 | // Eventually adds the alias to the right domain. |
537 | if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { | |
538 | $req = new AliasReq($user, $alias, 'Admin request', false); | |
539 | if ($req->commit()) { | |
540 | $page->trigSuccess("Nouvel alias '$alias@$domain' attribué"); | |
541 | } else { | |
542 | $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué"); | |
543 | } | |
544 | } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { | |
545 | $res = XDB::execute("INSERT INTO aliases (id, alias, type) | |
546 | VALUES ({?}, {?}, 'alias')", | |
547 | $user->id(), $alias); | |
548 | $page->trigSuccess("Nouvel alias '$alias' ajouté"); | |
549 | } else { | |
550 | $page->trigError("Le domaine '$domain' n'est pas valide"); | |
551 | } | |
552 | } else if (!Post::blank('del_alias')) { | |
553 | XDB::execute("DELETE FROM aliases | |
554 | WHERE id = {?} AND alias = {?} AND | |
555 | type NOT IN ('a_vie', 'homonyme')", | |
556 | $user->id(), $val); | |
557 | XDB::execute("UPDATE emails | |
558 | SET rewrite = '' | |
559 | WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", | |
560 | $user->id(), $val); | |
561 | fix_bestalias($user); | |
562 | $page->trigSuccess("L'alias '$val' a été supprimé"); | |
563 | } else if (!Post::blank('best')) { | |
564 | XDB::execute("UPDATE aliases | |
565 | SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) | |
566 | WHERE id = {?}", $user->id()); | |
567 | XDB::execute("UPDATE aliases | |
568 | SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') | |
569 | WHERE id = {?} AND alias = {?}", $user->id(), $val); | |
570 | // As having a non-null bestalias value is critical in | |
571 | // plat/al's code, we do an a posteriori check on the | |
572 | // validity of the bestalias. | |
573 | fix_bestalias($user); | |
574 | } | |
575 | // }}} | |
669cb0e0 | 576 | |
4f903ea6 FB |
577 | // Forum form {{{ |
578 | if (Post::has('b_edit')) { | |
579 | XDB::execute("DELETE FROM forum_innd | |
580 | WHERE uid = {?}", $user->id()); | |
581 | if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) { | |
582 | XDB::execute("INSERT INTO forum_innd | |
583 | SET ipmin = '0', ipmax = '4294967295', | |
584 | write_perm = {?}, read_perm = {?}, | |
585 | comment = {?}, priority = '200', uid = {?}", | |
586 | Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $user->id()); | |
587 | } | |
588 | } | |
589 | // }}} | |
86f0a6af | 590 | |
86f0a6af | 591 | |
4f903ea6 FB |
592 | $page->addJsLink('ui.core.js'); |
593 | $page->addJsLink('ui.tabs.js'); | |
669cb0e0 | 594 | |
d5fbeef6 VZ |
595 | |
596 | // Displays last login and last host information. | |
597 | $res = XDB::query("SELECT start, host | |
598 | FROM logger.sessions | |
599 | WHERE uid = {?} AND suid = 0 | |
600 | ORDER BY start DESC | |
601 | LIMIT 1", $user->id()); | |
602 | list($lastlogin,$host) = $res->fetchOneRow(); | |
603 | $page->assign('lastlogin', $lastlogin); | |
604 | $page->assign('host', $host); | |
605 | ||
606 | // Display active aliases. | |
8f2104cb | 607 | $page->assign('virtuals', $user->emailAliases()); |
4f903ea6 FB |
608 | $page->assign('aliases', XDB::iterator("SELECT alias, type='a_vie' AS for_life, |
609 | FIND_IN_SET('bestalias',flags) AS best, expire | |
610 | FROM aliases | |
611 | WHERE id = {?} AND type != 'homonyme' | |
612 | ORDER BY type != 'a_vie'", $user->id())); | |
8f2104cb FB |
613 | $page->assign('account_types', XDB::iterator('SELECT * FROM account_types ORDER BY type')); |
614 | $page->assign('skins', XDB::iterator('SELECT id, name FROM skins ORDER BY name')); | |
f9743cf1 FB |
615 | $page->assign('profiles', XDB::iterator('SELECT p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner |
616 | FROM account_profiles AS ap | |
617 | INNER JOIN profiles AS p ON (ap.pid = p.pid) | |
618 | WHERE ap.uid = {?}', $user->id())); | |
d5fbeef6 VZ |
619 | |
620 | // Displays email redirection and the general profile. | |
621 | if ($registered && $redirect) { | |
622 | $page->assign('emails', $redirect->emails); | |
623 | } | |
624 | ||
d5fbeef6 VZ |
625 | $page->assign('user', $user); |
626 | ||
627 | // Displays forum bans. | |
628 | $res = XDB::query("SELECT write_perm, read_perm, comment | |
7d15f750 | 629 | FROM forum_innd |
d5fbeef6 VZ |
630 | WHERE uid = {?}", $user->id()); |
631 | $bans = $res->fetchOneAssoc(); | |
632 | $page->assign('bans', $bans); | |
86f0a6af | 633 | } |
1f53925a | 634 | |
1e865041 | 635 | function getHruid($line, $partial_result, $key) |
7c5200a5 | 636 | { |
1e865041 VZ |
637 | if (!isset($partial_result['nom']) || |
638 | !isset($partial_result['prenom']) || | |
639 | !isset($partial_result['promo'])) { | |
7c5200a5 VZ |
640 | return null; |
641 | } | |
1e865041 | 642 | return make_forlife($partial_result['prenom'], $partial_result['nom'], $partial_result['promo']); |
7c5200a5 VZ |
643 | } |
644 | ||
1f53925a | 645 | function getMatricule($line, $key) |
646 | { | |
647 | $mat = $line['matricule']; | |
648 | $year = intval(substr($mat, 0, 3)); | |
649 | $rang = intval(substr($mat, 3, 3)); | |
650 | if ($year > 200) { $year /= 10; }; | |
651 | if ($year < 96) { | |
652 | return null; | |
653 | } else { | |
654 | return sprintf('%04u%04u', 1900+$year, $rang); | |
655 | } | |
656 | } | |
657 | ||
658 | function handler_promo(&$page, $action = null, $promo = null) | |
659 | { | |
660 | if (Env::has('promo')) { | |
661 | if(Env::i('promo') > 1900 && Env::i('promo') < 2050) { | |
eaf30d86 | 662 | $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax'; |
1f53925a | 663 | pl_redirect('admin/promo/' . $action . '/' . Env::i('promo')); |
664 | } else { | |
fb2c09c9 | 665 | $page->trigError('Promotion non valide.'); |
1f53925a | 666 | } |
667 | } | |
668 | ||
669 | $page->changeTpl('admin/promo.tpl'); | |
670 | if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) { | |
671 | $page->assign('promo', $promo); | |
672 | } else { | |
673 | return; | |
674 | } | |
675 | ||
676 | $importer = new CSVImporter('auth_user_md5', 'matricule'); | |
7c5200a5 | 677 | $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule')); |
1f53925a | 678 | switch ($action) { |
679 | case 'add': | |
7c5200a5 | 680 | $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini', |
1f53925a | 681 | 'prenom_ini', 'promo', 'promo_sortie', 'flags', |
682 | 'matricule', 'matricule_ax', 'perms'); | |
683 | $importer->forceValue('promo', $promo); | |
684 | $importer->forceValue('promo_sortie', $promo + 3); | |
1e865041 VZ |
685 | // The hruid generation callback is set last, so that it is called once 'promo' |
686 | // has already been computed for that line. | |
687 | $importer->forceValue('hruid', array($this, 'getHruid')); | |
1f53925a | 688 | break; |
689 | case 'ax': | |
690 | $fields = array('matricule', 'matricule_ax'); | |
691 | break; | |
692 | } | |
693 | $importer->apply($page, "admin/promo/$action/$promo", $fields); | |
694 | } | |
695 | ||
7c5200a5 VZ |
696 | function handler_homonyms(&$page, $op = 'list', $target = null) |
697 | { | |
86f0a6af | 698 | $page->changeTpl('admin/homonymes.tpl'); |
46f272fe | 699 | $page->setTitle('Administration - Homonymes'); |
191711d5 | 700 | $this->load("homonyms.inc.php"); |
74c55fd6 | 701 | |
86f0a6af | 702 | if ($target) { |
191711d5 FB |
703 | $user = User::getSilent($target); |
704 | if (!$user || !($loginbis = select_if_homonyme($user))) { | |
705 | $target = 0; | |
86f0a6af | 706 | } else { |
191711d5 | 707 | $page->assign('user', $user); |
86f0a6af | 708 | $page->assign('loginbis',$loginbis); |
709 | } | |
710 | } | |
74c55fd6 | 711 | |
839a80cf VZ |
712 | $page->assign('op', $op); |
713 | $page->assign('target', $target); | |
74c55fd6 | 714 | |
86f0a6af | 715 | // on a un $target valide, on prepare les mails |
716 | if ($target) { | |
86f0a6af | 717 | // on examine l'op a effectuer |
718 | switch ($op) { | |
719 | case 'mail': | |
40d428d8 VZ |
720 | S::assert_xsrf_token(); |
721 | ||
191711d5 FB |
722 | send_warning_homonyme($user, $loginbis); |
723 | switch_bestalias($user, $loginbis); | |
86f0a6af | 724 | $op = 'list'; |
191711d5 | 725 | $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.'); |
86f0a6af | 726 | break; |
839a80cf | 727 | |
86f0a6af | 728 | case 'correct': |
40d428d8 VZ |
729 | S::assert_xsrf_token(); |
730 | ||
191711d5 | 731 | switch_bestalias($user, $loginbis); |
32b3ac78 FB |
732 | XDB::execute("UPDATE aliases |
733 | SET type = 'homonyme', expire=NOW() | |
734 | WHERE alias = {?}", $loginbis); | |
735 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) | |
191711d5 FB |
736 | VALUES ({?}, {?})", $target, $target); |
737 | send_robot_homonyme($user, $loginbis); | |
86f0a6af | 738 | $op = 'list'; |
191711d5 | 739 | $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.'); |
86f0a6af | 740 | break; |
741 | } | |
742 | } | |
74c55fd6 | 743 | |
86f0a6af | 744 | if ($op == 'list') { |
745 | $res = XDB::iterator( | |
32b3ac78 FB |
746 | "SELECT a.alias AS homonyme, s.alias AS forlife, |
747 | IF(h.homonyme_id = s.id, a.expire, NULL) AS expire, | |
748 | IF(h.homonyme_id = s.id, a.type, NULL) AS type, | |
191711d5 | 749 | ac.uid AS user_id |
86f0a6af | 750 | FROM aliases AS a |
751 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) | |
752 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') | |
32b3ac78 FB |
753 | INNER JOIN accounts AS ac ON (ac.uid = a.id) |
754 | WHERE a.type = 'homonyme' OR a.expire != '' | |
755 | ORDER BY a.alias, forlife"); | |
86f0a6af | 756 | $hnymes = Array(); |
757 | while ($tab = $res->next()) { | |
758 | $hnymes[$tab['homonyme']][] = $tab; | |
759 | } | |
760 | $page->assign_by_ref('hnymes',$hnymes); | |
761 | } | |
762 | } | |
74c55fd6 | 763 | |
32b3ac78 FB |
764 | function handler_deaths(&$page, $promo = 0, $validate = false) |
765 | { | |
86f0a6af | 766 | $page->changeTpl('admin/deces_promo.tpl'); |
46f272fe | 767 | $page->setTitle('Administration - Deces'); |
74c55fd6 | 768 | |
dcefa8f7 FB |
769 | if (!$promo) { |
770 | $promo = Env::t('promo', 'X1923'); | |
771 | } | |
772 | $page->assign('promo', $promo); | |
773 | if (!$promo) { | |
774 | return; | |
775 | } | |
74c55fd6 | 776 | |
40d428d8 VZ |
777 | if ($validate) { |
778 | S::assert_xsrf_token(); | |
779 | ||
dcefa8f7 FB |
780 | $res = XDB::iterRow('SELECT p.hrpid, pd.directory_name, p.deathdate |
781 | FROM profiles AS p | |
782 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
783 | WHERE pd.promo = {?}', $promo); | |
784 | while (list($pid, $name, $death) = $res->next()) { | |
785 | $val = Env::v($pid); | |
e61326ed VZ |
786 | if($val == $deces || empty($val)) { |
787 | continue; | |
788 | } | |
789 | ||
dcefa8f7 FB |
790 | XDB::execute('UPDATE profiles |
791 | SET deathdate = {?}, deathdate_rec = NOW() | |
792 | WHERE hrpid = {?}', $val, $pid); | |
793 | $page->trigSuccess('Ajout du décès de ' . $name . ' le ' . $val . '.'); | |
794 | if($death == '0000-00-00' || empty($death)) { | |
795 | // TODO: FIX THIS DEPRECATED CALL | |
e61326ed VZ |
796 | require_once('user.func.inc.php'); |
797 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email | |
798 | } | |
86f0a6af | 799 | } |
86f0a6af | 800 | } |
74c55fd6 | 801 | |
dcefa8f7 FB |
802 | $res = XDB::iterator('SELECT p.hrpid, pd.directory_name, p.deathdate |
803 | FROM profiles AS p | |
804 | INNER JOIN profile_display AS pd ON (p.pid = pd.pid) | |
805 | WHERE pd.promo = {?} | |
806 | ORDER BY pd.sort_name', $promo); | |
86f0a6af | 807 | $page->assign('decedes', $res); |
808 | } | |
74c55fd6 | 809 | |
32b3ac78 FB |
810 | function handler_dead_but_active(&$page) |
811 | { | |
1c48c2a9 | 812 | $page->changeTpl('admin/dead_but_active.tpl'); |
46f272fe | 813 | $page->setTitle('Administration - Décédés'); |
1c48c2a9 VZ |
814 | |
815 | $res = XDB::iterator( | |
dcefa8f7 FB |
816 | 'SELECT a.hruid, pd.promo, p.ax_id, pd.directory_name, p.deathdate, DATE(MAX(s.start)) AS last |
817 | FROM accounts AS a | |
818 | INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms)) | |
819 | INNER JOIN profiles AS p ON (p.pid = ap.pid) | |
820 | INNER JOIN profile_display AS pd ON (pd.pid = p.pid) | |
821 | LEFT JOIN logger.sessions AS s ON (s.uid = a.uid AND suid = 0) | |
822 | WHERE a.state = \'active\' AND p.deathdate IS NOT NULL | |
823 | GROUP BY a.uid | |
824 | ORDER BY pd.promo, pd.sort_name'); | |
1c48c2a9 VZ |
825 | $page->assign('dead', $res); |
826 | } | |
827 | ||
e654517d | 828 | function handler_validate(&$page, $action = 'list', $id = null) |
829 | { | |
86f0a6af | 830 | $page->changeTpl('admin/valider.tpl'); |
46f272fe | 831 | $page->setTitle('Administration - Valider une demande'); |
441c2451 | 832 | $page->addCssLink('nl.css'); |
3ad44e08 | 833 | $page->addJsLink('ajax.js'); |
e654517d | 834 | require_once("validations.inc.php"); |
835 | ||
74c55fd6 | 836 | |
ed5b9703 | 837 | if ($action == 'edit' and !is_null($id)) { |
838 | $page->assign('preview_id', $id); | |
839 | } | |
840 | ||
86f0a6af | 841 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
40d428d8 VZ |
842 | S::assert_xsrf_token(); |
843 | ||
20d7932b | 844 | $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
343e22c2 FB |
845 | if ($req) { |
846 | $req->handle_formu(); | |
847 | } else { | |
848 | $page->trigWarning('La validation a déjà été effectuée.'); | |
849 | } | |
86f0a6af | 850 | } |
74c55fd6 | 851 | |
cfb96867 | 852 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
853 | while (($a = $r->next()) && $a['Field'] != 'category'); | |
854 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); | |
74c55fd6 | 855 | |
cfb96867 | 856 | $hidden = array(); |
e0d7c076 SJ |
857 | $res = XDB::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S::v('uid')); |
858 | $hide_requests = $res->fetchOneCell(); | |
cfb96867 | 859 | if (Post::has('hide')) { |
74c55fd6 | 860 | $hide = array(); |
861 | foreach ($categories as $cat) | |
cfb96867 | 862 | if (!Post::v($cat)) { |
863 | $hidden[$cat] = 1; | |
864 | $hide[] = $cat; | |
865 | } | |
e0d7c076 SJ |
866 | $hide_requests = join(',', $hide); |
867 | XDB::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})', | |
868 | S::v('uid'), $hide_requests); | |
869 | } elseif ($hide_requests) { | |
870 | foreach (explode(',', $hide_requests) as $hide_type) | |
cfb96867 | 871 | $hidden[$hide_type] = true; |
872 | } | |
873 | $page->assign('hide_requests', $hidden); | |
74c55fd6 | 874 | |
90df2530 FB |
875 | // Update the count of item to validate here... useful in development configuration |
876 | // where several copies of the site use the same DB, but not the same "dynamic configuration" | |
ebfdf077 FB |
877 | global $globals; |
878 | $globals->updateNbValid(); | |
86f0a6af | 879 | $page->assign('vit', new ValidateIterator()); |
880 | } | |
e654517d | 881 | |
32b3ac78 FB |
882 | function handler_validate_answers(&$page, $action = 'list', $id = null) |
883 | { | |
46f272fe | 884 | $page->setTitle('Administration - Réponses automatiques de validation'); |
a7de4ef7 | 885 | $page->assign('title', 'Gestion des réponses automatiques'); |
e18888f4 | 886 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
a7de4ef7 | 887 | $table_editor->describe('category','catégorie',true); |
e18888f4 | 888 | $table_editor->describe('title','titre',true); |
889 | $table_editor->describe('answer','texte',false); | |
890 | $table_editor->apply($page, $action, $id); | |
891 | } | |
32b3ac78 FB |
892 | |
893 | function handler_skins(&$page, $action = 'list', $id = null) | |
894 | { | |
46f272fe | 895 | $page->setTitle('Administration - Skins'); |
e7ae7df9 | 896 | $page->assign('title', 'Gestion des skins'); |
897 | $table_editor = new PLTableEditor('admin/skins','skins','id'); | |
898 | $table_editor->describe('name','nom',true); | |
899 | $table_editor->describe('skin_tpl','nom du template',true); | |
900 | $table_editor->describe('auteur','auteur',false); | |
901 | $table_editor->describe('comment','commentaire',true); | |
902 | $table_editor->describe('date','date',false); | |
903 | $table_editor->describe('ext','extension du screenshot',false); | |
904 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 905 | } |
669cb0e0 | 906 | |
32b3ac78 FB |
907 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) |
908 | { | |
46f272fe | 909 | $page->setTitle('Administration - Postfix : Blacklist'); |
e7ae7df9 | 910 | $page->assign('title', 'Blacklist de postfix'); |
911 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); | |
912 | $table_editor->describe('reject_text','Texte de rejet',true); | |
913 | $table_editor->describe('email','email',true); | |
914 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 915 | } |
32b3ac78 FB |
916 | |
917 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) | |
918 | { | |
46f272fe | 919 | $page->setTitle('Administration - Postfix : Whitelist'); |
e7ae7df9 | 920 | $page->assign('title', 'Whitelist de postfix'); |
921 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); | |
922 | $table_editor->describe('email','email',true); | |
923 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 924 | } |
32b3ac78 FB |
925 | |
926 | function handler_mx_broken(&$page, $action = 'list', $id = null) | |
927 | { | |
46f272fe | 928 | $page->setTitle('Administration - MX Défaillants'); |
a7de4ef7 | 929 | $page->assign('title', 'MX Défaillant'); |
ccdbc270 | 930 | $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); |
931 | $table_editor->describe('host', 'Masque', true); | |
932 | $table_editor->describe('state', 'Niveau', true); | |
a7de4ef7 | 933 | $table_editor->describe('text', 'Description du problème', false); |
ccdbc270 | 934 | $table_editor->apply($page, $action, $id); |
935 | } | |
32b3ac78 FB |
936 | |
937 | function handler_logger_actions(&$page, $action = 'list', $id = null) | |
938 | { | |
46f272fe | 939 | $page->setTitle('Administration - Actions'); |
e7ae7df9 | 940 | $page->assign('title', 'Gestion des actions de logger'); |
941 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); | |
a7de4ef7 | 942 | $table_editor->describe('text','intitulé',true); |
e7ae7df9 | 943 | $table_editor->describe('description','description',true); |
944 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 945 | } |
32b3ac78 | 946 | |
8f2104cb FB |
947 | function handler_downtime(&$page, $action = 'list', $id = null) |
948 | { | |
46f272fe | 949 | $page->setTitle('Administration - Coupures'); |
e7ae7df9 | 950 | $page->assign('title', 'Gestion des coupures'); |
951 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); | |
952 | $table_editor->describe('debut','date',true); | |
a7de4ef7 | 953 | $table_editor->describe('duree','durée',false); |
954 | $table_editor->describe('resume','résumé',true); | |
955 | $table_editor->describe('services','services affectés',true); | |
e7ae7df9 | 956 | $table_editor->describe('description','description',false); |
957 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 958 | } |
bc0903c7 | 959 | |
8f2104cb FB |
960 | function handler_account_types(&$page, $action = 'list', $id = null) |
961 | { | |
962 | $page->setTitle('Administration - Types de comptes'); | |
963 | $page->assign('title', 'Gestion des types de comptes'); | |
964 | $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true); | |
965 | $table_editor->describe('type', 'Catégorie', true); | |
966 | $table_editor->describe('perms', 'Permissions associées', true); | |
967 | $table_editor->apply($page, $action, $id); | |
968 | } | |
969 | ||
8f201b69 | 970 | function handler_wiki(&$page, $action = 'list', $wikipage = null, $wikipage2 = null) |
bc0903c7 | 971 | { |
84fc72ff | 972 | if (S::hasAuthToken()) { |
a2b461ce | 973 | $page->setRssLink('Changement Récents', |
84fc72ff | 974 | '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('token')); |
a2b461ce | 975 | } |
e61326ed | 976 | |
3aec1c21 | 977 | // update wiki perms |
40d428d8 VZ |
978 | if ($action == 'update') { |
979 | S::assert_xsrf_token(); | |
980 | ||
3aec1c21 | 981 | $perms_read = Post::v('read'); |
8f201b69 | 982 | $perms_edit = Post::v('edit'); |
3aec1c21 | 983 | if ($perms_read || $perms_edit) { |
8f201b69 FB |
984 | foreach ($_POST as $wiki_page => $val) { |
985 | if ($val == 'on') { | |
986 | $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page)); | |
987 | if ($wp->setPerms($perms_read ? $perms_read : $wp->readPerms(), | |
988 | $perms_edit ? $perms_edit : $wp->writePerms())) { | |
989 | $page->trigSuccess("Permission de la page $wiki_page mises à jour"); | |
990 | } else { | |
991 | $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour"); | |
992 | } | |
993 | } | |
3aec1c21 | 994 | } |
995 | } | |
8f201b69 FB |
996 | } else if ($action != 'list' && !empty($wikipage)) { |
997 | $wp = new PlWikiPage($wikipage); | |
40d428d8 VZ |
998 | S::assert_xsrf_token(); |
999 | ||
8f201b69 FB |
1000 | if ($action == 'delete') { |
1001 | if ($wp->delete()) { | |
1002 | $page->trigSuccess("La page ".$wikipage." a été supprimée."); | |
1003 | } else { | |
1004 | $page->trigError("Impossible de supprimer la page ".$wikipage."."); | |
1005 | } | |
1006 | } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) { | |
1007 | if ($changedLinks = $wp->rename($wikipage2)) { | |
1008 | $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.'; | |
1009 | if (is_numeric($changedLinks)) { | |
1010 | $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.'); | |
1011 | } | |
1012 | $page->trigSuccess($s); | |
1013 | } else { | |
1014 | $page->trigError("Impossible de déplacer la page ".$wikipage); | |
9162f4ed | 1015 | } |
9162f4ed | 1016 | } |
1017 | } | |
74c55fd6 | 1018 | |
8f201b69 | 1019 | $perms = PlWikiPage::permOptions(); |
74c55fd6 | 1020 | |
3aec1c21 | 1021 | // list wiki pages and their perms |
8f201b69 | 1022 | $wiki_pages = PlWikiPage::listPages(); |
3aec1c21 | 1023 | ksort($wiki_pages); |
bc0903c7 | 1024 | $wiki_tree = array(); |
1025 | foreach ($wiki_pages as $file => $desc) { | |
1026 | list($cat, $name) = explode('.', $file); | |
1027 | if (!isset($wiki_tree[$cat])) { | |
1028 | $wiki_tree[$cat] = array(); | |
1029 | } | |
1030 | $wiki_tree[$cat][$name] = $desc; | |
1031 | } | |
1032 | ||
3aec1c21 | 1033 | $page->changeTpl('admin/wiki.tpl'); |
bc0903c7 | 1034 | $page->assign('wiki_pages', $wiki_tree); |
3aec1c21 | 1035 | $page->assign('perms_opts', $perms); |
1036 | } | |
5480a216 | 1037 | |
1038 | function handler_ipwatch(&$page, $action = 'list', $ip = null) | |
eaf30d86 | 1039 | { |
5480a216 | 1040 | $page->changeTpl('admin/ipwatcher.tpl'); |
eaf30d86 | 1041 | |
5480a216 | 1042 | $states = array('safe' => 'Ne pas surveiller', |
c339246f | 1043 | 'unsafe' => 'Surveiller les inscriptions', |
a7de4ef7 | 1044 | 'dangerous' => 'Surveiller tous les accès', |
5480a216 | 1045 | 'ban' => 'Bannir cette adresse'); |
1046 | $page->assign('states', $states); | |
1047 | ||
1048 | switch (Post::v('action')) { | |
e61326ed | 1049 | case 'create': |
5480a216 | 1050 | if (trim(Post::v('ipN')) != '') { |
40d428d8 | 1051 | S::assert_xsrf_token(); |
61c98f4b FB |
1052 | Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description) |
1053 | VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})', | |
1054 | ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))), | |
1055 | Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); | |
eaf30d86 PH |
1056 | }; |
1057 | break; | |
1058 | ||
e61326ed | 1059 | case 'edit': |
40d428d8 | 1060 | S::assert_xsrf_token(); |
eaf30d86 | 1061 | Xdb::execute('UPDATE ip_watch |
61c98f4b | 1062 | SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?} |
9797734d | 1063 | WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), |
61c98f4b | 1064 | ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN'))); |
5480a216 | 1065 | break; |
eaf30d86 | 1066 | |
e61326ed | 1067 | default: |
5480a216 | 1068 | if ($action == 'delete' && !is_null($ip)) { |
40d428d8 VZ |
1069 | S::assert_xsrf_token(); |
1070 | Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip)); | |
5480a216 | 1071 | } |
1072 | } | |
1073 | if ($action != 'create' && $action != 'edit') { | |
1074 | $action = 'list'; | |
1075 | } | |
1076 | $page->assign('action', $action); | |
1077 | ||
1078 | if ($action == 'list') { | |
9797734d FB |
1079 | $sql = "SELECT w.ip, IF(s.ip IS NULL, |
1080 | IF(w.ip = s2.ip, s2.host, s2.forward_host), | |
1081 | IF(w.ip = s.ip, s.host, s.forward_host)), | |
32b3ac78 | 1082 | w.mask, w.detection, w.state, a.hruid |
5480a216 | 1083 | FROM ip_watch AS w |
9797734d FB |
1084 | LEFT JOIN logger.sessions AS s ON (s.ip = w.ip) |
1085 | LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip) | |
32b3ac78 FB |
1086 | LEFT JOIN accounts AS a ON (a.uid = s.uid) |
1087 | GROUP BY w.ip, a.hruid | |
1088 | ORDER BY w.state, w.ip, a.hruid"; | |
5480a216 | 1089 | $it = Xdb::iterRow($sql); |
1090 | ||
1091 | $table = array(); | |
1092 | $props = array(); | |
90c614cd | 1093 | while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) { |
9797734d | 1094 | $ip = uint_to_ip($ip); |
61c98f4b | 1095 | $mask = uint_to_ip($mask); |
5480a216 | 1096 | if (count($props) == 0 || $props['ip'] != $ip) { |
1097 | if (count($props) > 0) { | |
1098 | $table[] = $props; | |
1099 | } | |
1100 | $props = array('ip' => $ip, | |
61c98f4b | 1101 | 'mask' => $mask, |
5480a216 | 1102 | 'host' => $host, |
1103 | 'detection' => $date, | |
1104 | 'state' => $state, | |
90c614cd | 1105 | 'users' => array($hruid)); |
5480a216 | 1106 | } else { |
90c614cd | 1107 | $props['users'][] = $hruid; |
5480a216 | 1108 | } |
1109 | } | |
1110 | if (count($props) > 0) { | |
1111 | $table[] = $props; | |
1112 | } | |
1113 | $page->assign('table', $table); | |
1114 | } elseif ($action == 'edit') { | |
61c98f4b | 1115 | $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask, |
32b3ac78 | 1116 | a1.hruid AS edit, a2.hruid AS hruid, s.host |
5480a216 | 1117 | FROM ip_watch AS w |
32b3ac78 | 1118 | LEFT JOIN accounts AS a1 ON (a1.uid = w.uid) |
5480a216 | 1119 | LEFT JOIN logger.sessions AS s ON (w.ip = s.ip) |
32b3ac78 | 1120 | LEFT JOIN accounts AS a2 ON (a2.uid = s.uid) |
5480a216 | 1121 | WHERE w.ip = {?} |
32b3ac78 FB |
1122 | GROUP BY a2.hruid |
1123 | ORDER BY a2.hruid"; | |
9797734d | 1124 | $it = Xdb::iterRow($sql, ip_to_uint($ip)); |
5480a216 | 1125 | |
1126 | $props = array(); | |
90c614cd | 1127 | while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) { |
5480a216 | 1128 | if (count($props) == 0) { |
1129 | $props = array('ip' => $ip, | |
61c98f4b | 1130 | 'mask' => uint_to_ip($mask), |
5480a216 | 1131 | 'host' => $host, |
1132 | 'detection' => $detection, | |
1133 | 'state' => $state, | |
1134 | 'last' => $last, | |
1135 | 'description' => $description, | |
1136 | 'edit' => $edit, | |
90c614cd | 1137 | 'users' => array($hruid)); |
5480a216 | 1138 | } else { |
90c614cd | 1139 | $props['users'][] = $hruid; |
5480a216 | 1140 | } |
1141 | } | |
1142 | $page->assign('ip', $props); | |
1143 | } | |
1144 | } | |
eaf30d86 | 1145 | |
04148a2c | 1146 | function handler_icons(&$page) |
f141945d | 1147 | { |
1148 | $page->changeTpl('admin/icons.tpl'); | |
1149 | $dh = opendir('../htdocs/images/icons'); | |
1150 | if (!$dh) { | |
a7d35093 | 1151 | $page->trigError('Dossier des icones introuvables.'); |
f141945d | 1152 | } |
1153 | $icons = array(); | |
1154 | while (($file = readdir($dh)) !== false) { | |
1155 | if (strlen($file) > 4 && substr($file,-4) == '.gif') { | |
1156 | array_push($icons, substr($file, 0, -4)); | |
1157 | } | |
1158 | } | |
1159 | sort($icons); | |
1160 | $page->assign('icons', $icons); | |
04148a2c | 1161 | } |
fd1ce8c5 FB |
1162 | |
1163 | function handler_accounts(&$page) | |
1164 | { | |
1165 | $page->changeTpl('admin/accounts.tpl'); | |
32b3ac78 FB |
1166 | $page->assign('disabled', XDB::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch, |
1167 | a.state = \'disabled\' AS disabled, a.comment | |
1168 | FROM accounts AS a | |
1169 | WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags) | |
1170 | ORDER BY a.hruid')); | |
1171 | $page->assign('admins', XDB::iterator('SELECT a.hruid | |
1172 | FROM accounts AS a | |
1173 | WHERE a.is_admin | |
1174 | ORDER BY a.hruid')); | |
fd1ce8c5 | 1175 | } |
4d336f59 SJ |
1176 | |
1177 | function handler_jobs(&$page, $id = -1) | |
1178 | { | |
1179 | $page->changeTpl('admin/jobs.tpl'); | |
1180 | ||
1181 | if (Env::has('search')) { | |
1182 | $res = XDB::query("SELECT e.id, e.name, e.acronym | |
1183 | FROM profile_job_enum AS e | |
1184 | WHERE e.name LIKE CONCAT('% ', {?}, '%') OR e.acronym LIKE CONCAT('% ', {?}, '%')", | |
1185 | Env::t('job'), Env::t('job')); | |
1186 | ||
1187 | if ($res->numRows() <= 20) { | |
1188 | $page->assign('jobs', $res->fetchAllAssoc()); | |
1189 | } else { | |
1190 | $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !"); | |
1191 | } | |
1192 | ||
1193 | $page->assign('askedJob', Env::v('job')); | |
1194 | return; | |
1195 | } | |
1196 | ||
1197 | if (Env::has('edit')) { | |
1198 | S::assert_xsrf_token(); | |
1199 | $selectedJob = Env::has('selectedJob'); | |
1200 | ||
1201 | if (Env::has('change')) { | |
1202 | XDB::execute('UPDATE profile_job | |
1203 | SET jobid = {?} | |
1204 | WHERE jobid = {?}', | |
1205 | Env::i('newJobId'), $id); | |
1206 | XDB::execute('DELETE FROM profile_job_enum | |
1207 | WHERE id = {?}', | |
1208 | $id); | |
1209 | ||
1210 | $page->trigSuccess("L'entreprise a bien été remplacée."); | |
1211 | } else { | |
1212 | XDB::execute('UPDATE profile_job_enum | |
1213 | SET name = {?}, acronym = {?}, url = {?}, email = {?}, | |
1214 | NAF_code = {?}, AX_code = {?}, holdingid = {?} | |
1215 | WHERE id = {?}', | |
1216 | Env::t('name'), Env::t('acronym'), Env::t('url'), Env::t('email'), | |
1217 | Env::t('NAF_code'), Env::i('AX_code'), Env::i('holdingId'), $id); | |
1218 | ||
1219 | $page->trigSuccess("L'entreprise a bien été mise à jour."); | |
1220 | } | |
1221 | } | |
1222 | ||
1223 | if (!Env::has('change') && $id != -1) { | |
1224 | $res = XDB::query('SELECT e.id, e.name, e.acronym, e.url, e.email, e.NAF_code, e.AX_code, | |
1225 | h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym | |
1226 | FROM profile_job_enum AS e | |
1227 | LEFT JOIN profile_job_enum AS h ON (e.holdingid = h.id) | |
1228 | WHERE e.id = {?}', | |
1229 | $id); | |
1230 | ||
1231 | if ($res->numRows() == 0) { | |
1232 | $page->trigError('Auncune entreprise ne correspond à cet identifiant.'); | |
1233 | } else { | |
1234 | $page->assign('selectedJob', $res->fetchOneAssoc()); | |
1235 | } | |
1236 | } | |
1237 | } | |
86f0a6af | 1238 | } |
1239 | ||
a7de4ef7 | 1240 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
86f0a6af | 1241 | ?> |