Not groups managers on member unsubscription (Closes #807)
[platal.git] / modules / admin.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
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(
27 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'),
28 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'),
29 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'),
30 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP, 'admin'),
31 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'),
32 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'),
33 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'),
34 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'),
35 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'),
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'),
40 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'),
41 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'),
42 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'),
43 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'),
44 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'),
45 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'),
46 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'),
47 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'),
48 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'),
49 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'),
50 );
51 }
52
53 function handler_phpinfo(&$page)
54 {
55 phpinfo();
56 exit;
57 }
58
59 function handler_default(&$page)
60 {
61 $page->changeTpl('admin/index.tpl');
62 $page->assign('xorg_title','Polytechnique.org - Administration');
63 }
64
65 function handler_postfix_delayed(&$page)
66 {
67 $page->changeTpl('admin/postfix_delayed.tpl');
68 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
69
70 if (Env::has('del')) {
71 $crc = Env::v('crc');
72 XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
73 $page->trigSuccess($crc." verra tous ses mails supprimés !");
74 } elseif (Env::has('ok')) {
75 $crc = Env::v('crc');
76 XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
77 $page->trigSuccess($crc." a le droit de passer !");
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');
93 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces');
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
108 // {{{ logger view
109
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
266 $res = XDB::iterator('SELECT a.text, e.data, e.stamp
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);
316 $select = "SELECT s.id, s.start, s.uid,
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 {
344 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
345 }
346 }
347
348 $page->changeTpl('admin/logger-view.tpl');
349
350 $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
351 }
352
353 function handler_user(&$page, $login = false)
354 {
355 global $globals;
356 $page->changeTpl('admin/utilisateurs.tpl');
357 $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log');
358 require_once("emails.inc.php");
359 require_once("user.func.inc.php");
360
361 if (S::has('suid')) {
362 $page->kill("Déjà en SUID !!!");
363 }
364
365 if (Env::has('user_id')) {
366 $login = get_user_forlife(Env::i('user_id'));
367 if (empty($login)) {
368 $login = Env::i('user_id');
369 }
370 } elseif (Env::has('login')) {
371 $login = get_user_forlife(Env::v('login'));
372 }
373
374 if(Env::has('logs_button') && $login) {
375 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
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) {
383 $_SESSION['log']->log("suid_start", "login by ".S::v('forlife'));
384 $_SESSION['suid'] = $_SESSION;
385 $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login);
386 if($uid = $r->fetchOneCell()) {
387 start_connexion($uid, true);
388 pl_redirect("");
389 }
390 }
391
392 if ($login) {
393 if (is_numeric($login)) {
394 $r = XDB::query("SELECT *, a.alias AS forlife,
395 FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe,
396 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
397 FROM auth_user_md5 AS u
398 LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie')
399 WHERE u.user_id = {?}", $login);
400 } else {
401 $r = XDB::query("SELECT *, a.alias AS forlife,
402 FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe,
403 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
404 FROM auth_user_md5 AS u
405 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
406 }
407 $mr = $r->fetchOneAssoc();
408
409 // Checks the user has a forlife, as non-registered user can't have redirections.
410 if ($mr['forlife']) {
411 $redirect = new Redirect($mr['user_id']);
412 }
413
414 // Check if there was a submission
415 foreach($_POST as $key => $val) {
416 S::assert_xsrf_token();
417
418 switch ($key) {
419 case "add_fwd":
420 $email = trim(Env::v('email'));
421 if (!isvalid_email_redirection($email)) {
422 $page->trigError("Email non valide: $email");
423 } else {
424 $redirect->add_email($email);
425 $page->trigSuccess("Ajout de $email effectué");
426 }
427 break;
428
429 case "del_fwd":
430 if (!empty($val)) {
431 $redirect->delete_email($val);
432 }
433 break;
434
435 case "del_alias":
436 if (!empty($val)) {
437 XDB::execute("DELETE FROM aliases
438 WHERE id={?} AND alias={?}
439 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
440 XDB::execute("UPDATE emails
441 SET rewrite = ''
442 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
443 $mr['user_id'], $val);
444 fix_bestalias($mr['user_id']);
445 $page->trigSuccess($val." a été supprimé");
446 }
447 break;
448 case "activate_fwd":
449 if (!empty($val)) {
450 $redirect->modify_one_email($val, true);
451 }
452 break;
453 case "deactivate_fwd":
454 if (!empty($val)) {
455 $redirect->modify_one_email($val, false);
456 }
457 break;
458 case "disable_fwd":
459 $redirect->disable();
460 break;
461 case "enable_fwd":
462 $redirect->enable();
463 break;
464 case "clean_fwd":
465 if (!empty($val)) {
466 $redirect->clean_errors($val);
467 }
468 break;
469 case "add_alias":
470 global $globals;
471 $alias = trim(Env::v('email'));
472 if (strpos($alias, '@') !== false) {
473 list($alias, $domain) = explode('@', $alias);
474 } else {
475 $domain = $globals->mail->domain;
476 }
477 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
478 $page->trigError("'$alias' n'est pas un alias valide");
479 }
480 if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) {
481 $req = new AliasReq($mr['user_id'], $alias, 'Admin request', false);
482 if ($req->commit()) {
483 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
484 } else {
485 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
486 }
487 } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
488 if (XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
489 $mr['user_id'], $alias)) {
490 $page->trigSuccess("Nouvel alias '$alias' ajouté");
491 } else {
492 $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué");
493 }
494 } else {
495 $page->trigError("Le domaine '$domain' n'est pas valide");
496 }
497 break;
498
499 case "best":
500 // 'bestalias' is the first bit of the set : 1
501 // 255 is the max for flags (8 sets max)
502 XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
503 XDB::execute("UPDATE aliases
504 SET flags= flags | 1
505 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
506 break;
507
508
509 // Editer un profil
510 case "u_edit":
511 require_once('secure_hash.inc.php');
512 $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw');
513 $naiss = Env::v('naissanceN');
514 $deces = Env::v('decesN');
515 $perms = Env::v('permsN');
516 $prenm = Env::v('prenomN');
517 $nom = Env::v('nomN');
518 $nomusage = Env::v('nomusageN');
519 $promo = Env::i('promoN');
520 $sexe = Env::v('sexeN');
521 $comm = trim(Env::v('commentN'));
522 $watch = Env::v('watchN');
523 $flags = '';
524 if ($sexe) {
525 $flags = 'femme';
526 }
527 if ($watch) {
528 if ($flags) {
529 $flags .= ',';
530 }
531 $flags .= 'watch';
532 }
533
534 if ($watch && !$comm) {
535 $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte");
536 break;
537 }
538
539 $watch = 'SELECT naissance, deces, password, perms, nom_usage,
540 prenom, nom, flags, promo, comment
541 FROM auth_user_md5
542 WHERE user_id = ' . $mr['user_id'];
543 $res = XDB::query($watch);
544 $old_fields = $res->fetchOneAssoc();
545 $query = "UPDATE auth_user_md5 SET
546 naissance = '$naiss',
547 deces = '$deces',
548 password = '$pass_encrypted',
549 perms = '$perms',
550 prenom = '".addslashes($prenm)."',
551 nom = '".addslashes($nom)."',
552 nom_usage = '".addslashes($nomusage)."',
553 flags = '$flags',
554 promo = $promo,
555 comment = '".addslashes($comm)."'
556 WHERE user_id = '{$mr['user_id']}'";
557 if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') {
558 // A user has been banned ==> ensure his php session has been killed
559 // This solution is ugly and overkill, but, it should be efficient.
560 kill_sessions();
561 }
562 if (XDB::execute($query)) {
563 user_reindex($mr['user_id']);
564
565 $res = XDB::query($watch);
566 $new_fields = $res->fetchOneAssoc();
567
568 $mailer = new PlMailer("admin/useredit.mail.tpl");
569 $mailer->assign("admin", S::v('forlife'));
570 $mailer->assign("user", $mr['forlife']);
571 $mailer->assign('old', $old_fields);
572 $mailer->assign('new', $new_fields);
573 $mailer->send();
574
575 // update number of subscribers (perms or deceased may have changed)
576 update_NbIns();
577
578 $page->trigSuccess("updaté correctement.");
579 }
580 if (Env::v('nomusageN') != $mr['nom_usage']) {
581 require_once "xorg.misc.inc.php";
582 set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN')));
583 }
584 if (Env::v('decesN') != $mr['deces']) {
585 require_once 'notifs.inc.php';
586 register_watch_op($mr['user_id'], WATCH_DEATH, $mr['deces']);
587 user_clear_all_subs($mr['user_id'], false);
588 }
589 $r = XDB::query("SELECT *, a.alias AS forlife,
590 FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe
591 FROM auth_user_md5 AS u
592 LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie')
593 WHERE u.user_id = {?}", $mr['user_id']);
594 $mr = $r->fetchOneAssoc();
595
596 // If GoogleApps is enabled, the user did choose to use synchronized passwords,
597 // and the password was changed, updates the Google Apps password as well.
598 if ($globals->mailstorage->googleapps_domain && Env::v('newpass_clair') != "********") {
599 require_once 'googleapps.inc.php';
600 $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']);
601 if ($account->active() && $account->sync_password) {
602 $account->set_password($pass_encrypted);
603 }
604 }
605
606 // If GoogleApps is enabled, and the user is now disabled, disables the Google Apps account as well.
607 if ($globals->mailstorage->googleapps_domain &&
608 $new_fields['perms'] == 'disabled' &&
609 $new_fields['perms'] != $old_fields['perms']) {
610 require_once 'googleapps.inc.php';
611 $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']);
612 $account->suspend();
613 }
614 break;
615
616 // DELETE FROM auth_user_md5
617 case "u_kill":
618 user_clear_all_subs($mr['user_id']);
619 // update number of subscribers (perms or deceased may have changed)
620 update_NbIns();
621 $page->trigSuccess("'{$mr['user_id']}' a été désinscrit !");
622 $mailer = new PlMailer("admin/useredit.mail.tpl");
623 $mailer->assign("admin", S::v('forlife'));
624 $mailer->assign("user", $mr['forlife']);
625 $mailer->assign("deletion", true);
626 $mailer->send();
627 break;
628
629 case "b_edit":
630 XDB::execute("DELETE FROM forums.innd WHERE uid = {?}", $mr['user_id']);
631 if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) {
632 XDB::execute("INSERT INTO forums.innd
633 SET ipmin = '0',
634 ipmax = '4294967295',
635 write_perm = {?},
636 read_perm = {?},
637 comment = {?},
638 priority = '200',
639 uid = {?}",
640 Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $mr['user_id']);
641 }
642 break;
643 }
644 }
645
646 $res = XDB::query("SELECT start, host
647 FROM logger.sessions
648 WHERE uid={?} AND suid=0
649 ORDER BY start DESC
650 LIMIT 1", $mr['user_id']);
651 list($lastlogin,$host) = $res->fetchOneRow();
652 $page->assign('lastlogin', $lastlogin);
653 $page->assign('host', $host);
654
655 $res = XDB::iterator("SELECT alias
656 FROM virtual
657 INNER JOIN virtual_redirect USING(vid)
658 WHERE type = 'user' AND redirect LIKE '" . $mr['forlife'] . "@%'");
659 $page->assign('virtuals', $res);
660
661 $page->assign('aliases', XDB::iterator(
662 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
663 FROM aliases
664 WHERE id = {?} AND type!='homonyme'
665 ORDER BY type!= 'a_vie'", $mr["user_id"]));
666 if ($mr['perms'] != 'pending' && isset($redirect)) {
667 $page->assign('emails', $redirect->emails);
668 }
669
670 $page->assign('mr',$mr);
671
672 // Bans forums
673 $res = XDB::query("SELECT write_perm, read_perm, comment
674 FROM forums.innd
675 WHERE uid = {?}", $mr['user_id']);
676 $bans = $res->fetchOneAssoc();
677 $page->assign('bans', $bans);
678 }
679 }
680
681 function getMatricule($line, $key)
682 {
683 $mat = $line['matricule'];
684 $year = intval(substr($mat, 0, 3));
685 $rang = intval(substr($mat, 3, 3));
686 if ($year > 200) { $year /= 10; };
687 if ($year < 96) {
688 return null;
689 } else {
690 return sprintf('%04u%04u', 1900+$year, $rang);
691 }
692 }
693
694 function handler_promo(&$page, $action = null, $promo = null)
695 {
696 if (Env::has('promo')) {
697 if(Env::i('promo') > 1900 && Env::i('promo') < 2050) {
698 $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax';
699 pl_redirect('admin/promo/' . $action . '/' . Env::i('promo'));
700 } else {
701 $page->trigError('Promo non valide');
702 }
703 }
704
705 $page->changeTpl('admin/promo.tpl');
706 if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) {
707 $page->assign('promo', $promo);
708 } else {
709 return;
710 }
711
712 $importer = new CSVImporter('auth_user_md5', 'matricule');
713 $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule'));
714 switch ($action) {
715 case 'add':
716 $fields = array('nom', 'nom_ini', 'prenom', 'naissance_ini',
717 'prenom_ini', 'promo', 'promo_sortie', 'flags',
718 'matricule', 'matricule_ax', 'perms');
719 $importer->forceValue('promo', $promo);
720 $importer->forceValue('promo_sortie', $promo + 3);
721 break;
722 case 'ax':
723 $fields = array('matricule', 'matricule_ax');
724 break;
725 }
726 $importer->apply($page, "admin/promo/$action/$promo", $fields);
727 }
728
729 function handler_homonyms(&$page, $op = 'list', $target = null) {
730 $page->changeTpl('admin/homonymes.tpl');
731 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
732 require_once("homonymes.inc.php");
733
734 if ($target) {
735 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
736 $target=0;
737 } else {
738 $page->assign('nom',$nom);
739 $page->assign('prenom',$prenom);
740 $page->assign('forlife',$forlife);
741 $page->assign('loginbis',$loginbis);
742 }
743 }
744
745 $page->assign('op', $op);
746 $page->assign('target', $target);
747
748 // on a un $target valide, on prepare les mails
749 if ($target) {
750 // on examine l'op a effectuer
751 switch ($op) {
752 case 'mail':
753 S::assert_xsrf_token();
754
755 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
756 switch_bestalias($target, $loginbis);
757 $op = 'list';
758 break;
759
760 case 'correct':
761 S::assert_xsrf_token();
762
763 switch_bestalias($target, $loginbis);
764 XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
765 XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
766 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
767 $op = 'list';
768 break;
769 }
770 }
771
772 if ($op == 'list') {
773 $res = XDB::iterator(
774 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
775 promo,prenom,nom,
776 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
777 IF(h.homonyme_id=s.id, a.type, NULL) AS type
778 FROM aliases AS a
779 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
780 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
781 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
782 WHERE a.type='homonyme' OR a.expire!=''
783 ORDER BY a.alias,promo");
784 $hnymes = Array();
785 while ($tab = $res->next()) {
786 $hnymes[$tab['homonyme']][] = $tab;
787 }
788 $page->assign_by_ref('hnymes',$hnymes);
789 }
790 }
791
792 function handler_ax_xorg(&$page) {
793 $page->changeTpl('admin/ax-xorg.tpl');
794 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
795
796 // liste des différences
797 $res = XDB::query(
798 '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
799 FROM auth_user_md5 AS u
800 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
801 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
802 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
803 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
804 ORDER BY u.promo,u.nom,u.prenom');
805 $page->assign('diffs', $res->fetchAllAssoc());
806
807 // gens à l'ax mais pas chez nous
808 $res = XDB::query(
809 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
810 FROM identification_ax as ia
811 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
812 WHERE u.nom IS NULL');
813 $page->assign('mank', $res->fetchAllAssoc());
814
815 // gens chez nous et pas à l'ax
816 $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
817 $page->assign('plus', $res->fetchAllAssoc());
818 }
819
820 function handler_deaths(&$page, $promo = 0, $validate = false) {
821 $page->changeTpl('admin/deces_promo.tpl');
822 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
823
824 if (!$promo)
825 $promo = Env::i('promo');
826 if (Env::has('sub10')) $promo -= 10;
827 if (Env::has('sub01')) $promo -= 1;
828 if (Env::has('add01')) $promo += 1;
829 if (Env::has('add10')) $promo += 10;
830
831 $page->assign('promo',$promo);
832
833 if ($validate) {
834 S::assert_xsrf_token();
835
836 $new_deces = array();
837 $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
838 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
839 $val = Env::v($mat);
840 if($val == $deces || empty($val)) {
841 continue;
842 }
843
844 XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
845 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
846 if($deces == '0000-00-00' || empty($deces)) {
847 require_once('notifs.inc.php');
848 register_watch_op($uid, WATCH_DEATH, $val);
849 require_once('user.func.inc.php');
850 user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
851 }
852 }
853 $page->assign('new_deces',$new_deces);
854 }
855
856 $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
857 $page->assign('decedes', $res);
858 }
859
860 function handler_dead_but_active(&$page) {
861 $page->changeTpl('admin/dead_but_active.tpl');
862 $page->assign('xorg_title','Polytechnique.org - Administration - Décédés');
863
864 $res = XDB::iterator(
865 "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, a.alias, DATE(MAX(s.start)) AS last
866 FROM auth_user_md5 AS u
867 LEFT JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
868 LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0)
869 WHERE perms IN ('admin', 'user') AND deces <> 0
870 GROUP BY u.user_id
871 ORDER BY u.promo, u.nom");
872 $page->assign('dead', $res);
873 }
874
875 function handler_synchro_ax(&$page, $user = null, $action = null) {
876 $page->changeTpl('admin/synchro_ax.tpl');
877 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
878
879 require_once('synchro_ax.inc.php');
880
881 if (is_ax_key_missing()) {
882 $page->assign('no_private_key', true);
883 $page->run();
884 }
885
886 require_once('user.func.inc.php');
887
888 if ($user)
889 $login = get_user_forlife($user);
890
891 if (Env::has('user')) {
892 $login = get_user_forlife(Env::v('user'));
893 if ($login === false) {
894 return;
895 }
896 }
897
898 if (Env::has('mat')) {
899 $res = XDB::query(
900 "SELECT alias
901 FROM aliases AS a
902 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
903 WHERE matricule={?}", Env::i('mat'));
904 $login = $res->fetchOneCell();
905 }
906
907 if ($login) {
908 if ($action == 'import') {
909 ax_synchronize($login, S::v('uid'));
910 }
911 // get details from user, but looking only info that can be seen by ax
912 $user = get_user_details($login, S::v('uid'), 'ax');
913 $userax= get_user_ax($user['matricule_ax']);
914 require_once 'profil.func.inc.php';
915 $diff = diff_user_details($userax, $user, 'ax');
916
917 $page->assign('x', $user);
918 $page->assign('diff', $diff);
919 }
920 }
921
922 function handler_validate(&$page, $action = 'list', $id = null)
923 {
924 $page->changeTpl('admin/valider.tpl');
925 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
926 $page->addCssLink('nl.css');
927 $page->addJsLink('ajax.js');
928 require_once("validations.inc.php");
929
930
931 if ($action == 'edit' and !is_null($id)) {
932 $page->assign('preview_id', $id);
933 }
934
935 if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
936 S::assert_xsrf_token();
937
938 $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
939 $req->handle_formu();
940 }
941
942 $r = XDB::iterator('SHOW COLUMNS FROM requests_answers');
943 while (($a = $r->next()) && $a['Field'] != 'category');
944 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
945
946 $hidden = array();
947 $res = XDB::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S::v('uid'));
948 $hide_requests = $res->fetchOneCell();
949 if (Post::has('hide')) {
950 $hide = array();
951 foreach ($categories as $cat)
952 if (!Post::v($cat)) {
953 $hidden[$cat] = 1;
954 $hide[] = $cat;
955 }
956 $hide_requests = join(',', $hide);
957 XDB::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
958 S::v('uid'), $hide_requests);
959 } elseif ($hide_requests) {
960 foreach (explode(',', $hide_requests) as $hide_type)
961 $hidden[$hide_type] = true;
962 }
963 $page->assign('hide_requests', $hidden);
964
965 // Update the count of item to validate here... useful in development configuration
966 // where several copies of the site use the same DB, but not the same "dynamic configuration"
967 update_NbValid();
968 $page->assign('vit', new ValidateIterator());
969 }
970
971 function handler_validate_answers(&$page, $action = 'list', $id = null) {
972 $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
973 $page->assign('title', 'Gestion des réponses automatiques');
974 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
975 $table_editor->describe('category','catégorie',true);
976 $table_editor->describe('title','titre',true);
977 $table_editor->describe('answer','texte',false);
978 $table_editor->apply($page, $action, $id);
979 }
980 function handler_skins(&$page, $action = 'list', $id = null) {
981 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
982 $page->assign('title', 'Gestion des skins');
983 $table_editor = new PLTableEditor('admin/skins','skins','id');
984 $table_editor->describe('name','nom',true);
985 $table_editor->describe('skin_tpl','nom du template',true);
986 $table_editor->describe('auteur','auteur',false);
987 $table_editor->describe('comment','commentaire',true);
988 $table_editor->describe('date','date',false);
989 $table_editor->describe('ext','extension du screenshot',false);
990 $table_editor->apply($page, $action, $id);
991 }
992
993 function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
994 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
995 $page->assign('title', 'Blacklist de postfix');
996 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
997 $table_editor->describe('reject_text','Texte de rejet',true);
998 $table_editor->describe('email','email',true);
999 $table_editor->apply($page, $action, $id);
1000 }
1001 function handler_postfix_whitelist(&$page, $action = 'list', $id = null) {
1002 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
1003 $page->assign('title', 'Whitelist de postfix');
1004 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
1005 $table_editor->describe('email','email',true);
1006 $table_editor->apply($page, $action, $id);
1007 }
1008 function handler_mx_broken(&$page, $action = 'list', $id = null) {
1009 $page->assign('xorg_title', 'Polytechnique.org - Administration - MX Défaillants');
1010 $page->assign('title', 'MX Défaillant');
1011 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true);
1012 $table_editor->describe('host', 'Masque', true);
1013 $table_editor->describe('state', 'Niveau', true);
1014 $table_editor->describe('text', 'Description du problème', false);
1015 $table_editor->apply($page, $action, $id);
1016 }
1017 function handler_logger_actions(&$page, $action = 'list', $id = null) {
1018 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
1019 $page->assign('title', 'Gestion des actions de logger');
1020 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
1021 $table_editor->describe('text','intitulé',true);
1022 $table_editor->describe('description','description',true);
1023 $table_editor->apply($page, $action, $id);
1024 }
1025 function handler_downtime(&$page, $action = 'list', $id = null) {
1026 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
1027 $page->assign('title', 'Gestion des coupures');
1028 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
1029 $table_editor->describe('debut','date',true);
1030 $table_editor->describe('duree','durée',false);
1031 $table_editor->describe('resume','résumé',true);
1032 $table_editor->describe('services','services affectés',true);
1033 $table_editor->describe('description','description',false);
1034 $table_editor->apply($page, $action, $id);
1035 }
1036
1037 function handler_wiki(&$page, $action='list', $wikipage='', $wikipage2='')
1038 {
1039 require_once 'wiki.inc.php';
1040
1041 if (S::v('core_rss_hash')) {
1042 $page->setRssLink('Changement Récents',
1043 '/Site/AllRecentChanges?action=rss&user=' . S::v('forlife') . '&hash=' . S::v('core_rss_hash'));
1044 }
1045
1046 // update wiki perms
1047 if ($action == 'update') {
1048 S::assert_xsrf_token();
1049
1050 $perms_read = Post::v('read');
1051 $perms_edot = Post::v('edit');
1052 if ($perms_read || $perms_edit) {
1053 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
1054 $wiki_page = str_replace('_', '/', $wiki_page);
1055 if (!$perms_read || !$perms_edit)
1056 list($perms0, $perms1) = wiki_get_perms($wiki_page);
1057 if ($perms_read)
1058 $perms0 = $perms_read;
1059 if ($perms_edit)
1060 $perms1 = $perms_edit;
1061 wiki_set_perms($wiki_page, $perms0, $perms1);
1062 }
1063 }
1064 }
1065
1066 if ($action == 'delete' && $wikipage != '') {
1067 S::assert_xsrf_token();
1068
1069 if (wiki_delete_page($wikipage)) {
1070 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1071 } else {
1072 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1073 }
1074 }
1075
1076 if ($action == 'rename' && $wikipage != '' && $wikipage2 != '' && $wikipage != $wikipage2) {
1077 S::assert_xsrf_token();
1078
1079 if ($changedLinks = wiki_rename_page($wikipage, $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);
1087 }
1088 }
1089
1090 $perms = wiki_perms_options();
1091
1092 // list wiki pages and their perms
1093 $wiki_pages = array();
1094 $dir = wiki_work_dir();
1095 if (is_dir($dir)) {
1096 if ($dh = opendir($dir)) {
1097 while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
1098 list($read,$edit) = wiki_get_perms($file);
1099 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
1100 if (is_file($dir . '/cache_' . wiki_filename($file) . '.tpl')) {
1101 $wiki_pages[$file]['cached'] = true;
1102 }
1103 }
1104 closedir($dh);
1105 }
1106 }
1107 ksort($wiki_pages);
1108 $wiki_tree = array();
1109 foreach ($wiki_pages as $file => $desc) {
1110 list($cat, $name) = explode('.', $file);
1111 if (!isset($wiki_tree[$cat])) {
1112 $wiki_tree[$cat] = array();
1113 }
1114 $wiki_tree[$cat][$name] = $desc;
1115 }
1116
1117 $page->changeTpl('admin/wiki.tpl');
1118 $page->addJsLink('jquery.js');
1119 $page->assign('wiki_pages', $wiki_tree);
1120 $page->assign('perms_opts', $perms);
1121 }
1122
1123 function handler_ipwatch(&$page, $action = 'list', $ip = null)
1124 {
1125 $page->changeTpl('admin/ipwatcher.tpl');
1126
1127 $states = array('safe' => 'Ne pas surveiller',
1128 'unsafe' => 'Surveiller les inscriptions',
1129 'dangerous' => 'Surveiller tous les accès',
1130 'ban' => 'Bannir cette adresse');
1131 $page->assign('states', $states);
1132
1133 switch (Post::v('action')) {
1134 case 'create':
1135 if (trim(Post::v('ipN')) != '') {
1136 S::assert_xsrf_token();
1137 Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1138 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1139 ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))),
1140 Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
1141 };
1142 break;
1143
1144 case 'edit':
1145 S::assert_xsrf_token();
1146 Xdb::execute('UPDATE ip_watch
1147 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1148 WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'),
1149 ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN')));
1150 break;
1151
1152 default:
1153 if ($action == 'delete' && !is_null($ip)) {
1154 S::assert_xsrf_token();
1155 Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1156 }
1157 }
1158 if ($action != 'create' && $action != 'edit') {
1159 $action = 'list';
1160 }
1161 $page->assign('action', $action);
1162
1163 if ($action == 'list') {
1164 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1165 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1166 IF(w.ip = s.ip, s.host, s.forward_host)),
1167 w.mask, w.detection, w.state, a.alias AS forlife
1168 FROM ip_watch AS w
1169 LEFT JOIN logger.sessions AS s ON (s.ip = w.ip)
1170 LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip)
1171 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type = 'a_vie')
1172 GROUP BY w.ip, a.alias
1173 ORDER BY w.state, w.ip, a.alias";
1174 $it = Xdb::iterRow($sql);
1175
1176 $table = array();
1177 $props = array();
1178 while (list($ip, $host, $mask, $date, $state, $forlife) = $it->next()) {
1179 $ip = uint_to_ip($ip);
1180 $mask = uint_to_ip($mask);
1181 if (count($props) == 0 || $props['ip'] != $ip) {
1182 if (count($props) > 0) {
1183 $table[] = $props;
1184 }
1185 $props = array('ip' => $ip,
1186 'mask' => $mask,
1187 'host' => $host,
1188 'detection' => $date,
1189 'state' => $state,
1190 'users' => array($forlife));
1191 } else {
1192 $props['users'][] = $forlife;
1193 }
1194 }
1195 if (count($props) > 0) {
1196 $table[] = $props;
1197 }
1198 $page->assign('table', $table);
1199 } elseif ($action == 'edit') {
1200 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1201 a1.alias AS edit, a2.alias AS forlife, s.host
1202 FROM ip_watch AS w
1203 LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
1204 LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
1205 LEFT JOIN aliases AS a2 ON (a2.id = s.uid AND a2.type = 'a_vie')
1206 WHERE w.ip = {?}
1207 GROUP BY a2.alias
1208 ORDER BY a2.alias";
1209 $it = Xdb::iterRow($sql, ip_to_uint($ip));
1210
1211 $props = array();
1212 while (list($detection, $state, $last, $description, $mask, $edit, $forlife, $host) = $it->next()) {
1213 if (count($props) == 0) {
1214 $props = array('ip' => $ip,
1215 'mask' => uint_to_ip($mask),
1216 'host' => $host,
1217 'detection' => $detection,
1218 'state' => $state,
1219 'last' => $last,
1220 'description' => $description,
1221 'edit' => $edit,
1222 'users' => array($forlife));
1223 } else {
1224 $props['users'][] = $forlife;
1225 }
1226 }
1227 $page->assign('ip', $props);
1228 }
1229 }
1230
1231 function handler_icons(&$page)
1232 {
1233 $page->changeTpl('admin/icons.tpl');
1234 $dh = opendir('../htdocs/images/icons');
1235 if (!$dh) {
1236 $page->trigError('Dossier des icones introuvables.');
1237 }
1238 $icons = array();
1239 while (($file = readdir($dh)) !== false) {
1240 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1241 array_push($icons, substr($file, 0, -4));
1242 }
1243 }
1244 sort($icons);
1245 $page->assign('icons', $icons);
1246 }
1247 }
1248
1249 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1250 ?>