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