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