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 SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
799 XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
800 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
801 $op = 'list';
802 $page->trigSuccess('Email envoyé à ' . $forlife . ', alias supprimé.');
803 break;
804 }
805 }
806
807 if ($op == 'list') {
808 $res = XDB::iterator(
809 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
810 promo,prenom,nom,
811 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
812 IF(h.homonyme_id=s.id, a.type, NULL) AS type
813 FROM aliases AS a
814 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
815 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
816 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
817 WHERE a.type='homonyme' OR a.expire!=''
818 ORDER BY a.alias,promo");
819 $hnymes = Array();
820 while ($tab = $res->next()) {
821 $hnymes[$tab['homonyme']][] = $tab;
822 }
823 $page->assign_by_ref('hnymes',$hnymes);
824 }
825 }
826
827 function handler_ax_xorg(&$page) {
828 $page->changeTpl('admin/ax-xorg.tpl');
829 $page->setTitle('Administration - AX/X.org');
830
831 // liste des différences
832 $res = XDB::query(
833 '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
834 FROM auth_user_md5 AS u
835 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
836 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
837 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
838 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
839 ORDER BY u.promo,u.nom,u.prenom');
840 $page->assign('diffs', $res->fetchAllAssoc());
841
842 // gens à l'ax mais pas chez nous
843 $res = XDB::query(
844 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
845 FROM identification_ax as ia
846 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
847 WHERE u.nom IS NULL');
848 $page->assign('mank', $res->fetchAllAssoc());
849
850 // gens chez nous et pas à l'ax
851 $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
852 $page->assign('plus', $res->fetchAllAssoc());
853 }
854
855 function handler_deaths(&$page, $promo = 0, $validate = false) {
856 $page->changeTpl('admin/deces_promo.tpl');
857 $page->setTitle('Administration - Deces');
858
859 if (!$promo)
860 $promo = Env::i('promo');
861 if (Env::has('sub10')) $promo -= 10;
862 if (Env::has('sub01')) $promo -= 1;
863 if (Env::has('add01')) $promo += 1;
864 if (Env::has('add10')) $promo += 10;
865
866 $page->assign('promo',$promo);
867
868 if ($validate) {
869 S::assert_xsrf_token();
870
871 $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
872 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
873 $val = Env::v($mat);
874 if($val == $deces || empty($val)) {
875 continue;
876 }
877
878 XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
879 $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.');
880 if($deces == '0000-00-00' || empty($deces)) {
881 require_once('notifs.inc.php');
882 register_watch_op($uid, WATCH_DEATH, $val);
883 require_once('user.func.inc.php');
884 user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
885 }
886 }
887 }
888
889 $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
890 $page->assign('decedes', $res);
891 }
892
893 function handler_dead_but_active(&$page) {
894 $page->changeTpl('admin/dead_but_active.tpl');
895 $page->setTitle('Administration - Décédés');
896
897 $res = XDB::iterator(
898 "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, u.hruid, DATE(MAX(s.start)) AS last
899 FROM auth_user_md5 AS u
900 LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0)
901 WHERE perms IN ('admin', 'user') AND deces <> 0
902 GROUP BY u.user_id
903 ORDER BY u.promo, u.nom");
904 $page->assign('dead', $res);
905 }
906
907 function handler_synchro_ax(&$page, $login = null, $action = null) {
908 $page->changeTpl('admin/synchro_ax.tpl');
909 $page->setTitle('Administration - Synchro AX');
910
911 // Checks for synchronization requirements.
912 require_once('synchro_ax.inc.php');
913 if (is_ax_key_missing()) {
914 $page->assign('no_private_key', true);
915 $page->run();
916 }
917
918 // Determines user identity using environment.
919 if ($login) {
920 $user = User::get($login);
921 } else if (Env::has('user')) {
922 $user = User::get(Env::v('user'));
923 } else if (Env::has('mat')) {
924 $res = XDB::query("SELECT user_id FROM auth_user_md5 WHERE matricule = {?}", Env::i('mat'));
925 $user = User::get($res->fetchOneCell());
926 } else {
927 return;
928 }
929
930 // Finally synchronizes the AX and plat/al information.
931 if ($action == 'import') {
932 ax_synchronize($user->login(), S::v('uid'));
933 }
934
935 require_once 'profil.func.inc.php';
936 $userxorg = get_user_details($user->login(), S::v('uid'), 'ax');
937 $userax = get_user_ax($userxorg['matricule_ax']);
938 $diff = diff_user_details($userax, $userxorg, 'ax');
939
940 $page->assign('x', $userxorg);
941 $page->assign('diff', $diff);
942 }
943
944 function handler_validate(&$page, $action = 'list', $id = null)
945 {
946 $page->changeTpl('admin/valider.tpl');
947 $page->setTitle('Administration - Valider une demande');
948 $page->addCssLink('nl.css');
949 $page->addJsLink('ajax.js');
950 require_once("validations.inc.php");
951
952
953 if ($action == 'edit' and !is_null($id)) {
954 $page->assign('preview_id', $id);
955 }
956
957 if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
958 S::assert_xsrf_token();
959
960 $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
961 if ($req) {
962 $req->handle_formu();
963 } else {
964 $page->trigWarning('La validation a déjà été effectuée.');
965 }
966 }
967
968 $r = XDB::iterator('SHOW COLUMNS FROM requests_answers');
969 while (($a = $r->next()) && $a['Field'] != 'category');
970 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
971
972 $hidden = array();
973 $res = XDB::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S::v('uid'));
974 $hide_requests = $res->fetchOneCell();
975 if (Post::has('hide')) {
976 $hide = array();
977 foreach ($categories as $cat)
978 if (!Post::v($cat)) {
979 $hidden[$cat] = 1;
980 $hide[] = $cat;
981 }
982 $hide_requests = join(',', $hide);
983 XDB::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
984 S::v('uid'), $hide_requests);
985 } elseif ($hide_requests) {
986 foreach (explode(',', $hide_requests) as $hide_type)
987 $hidden[$hide_type] = true;
988 }
989 $page->assign('hide_requests', $hidden);
990
991 // Update the count of item to validate here... useful in development configuration
992 // where several copies of the site use the same DB, but not the same "dynamic configuration"
993 global $globals;
994 $globals->updateNbValid();
995 $page->assign('vit', new ValidateIterator());
996 }
997
998 function handler_validate_answers(&$page, $action = 'list', $id = null) {
999 $page->setTitle('Administration - Réponses automatiques de validation');
1000 $page->assign('title', 'Gestion des réponses automatiques');
1001 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
1002 $table_editor->describe('category','catégorie',true);
1003 $table_editor->describe('title','titre',true);
1004 $table_editor->describe('answer','texte',false);
1005 $table_editor->apply($page, $action, $id);
1006 }
1007 function handler_skins(&$page, $action = 'list', $id = null) {
1008 $page->setTitle('Administration - Skins');
1009 $page->assign('title', 'Gestion des skins');
1010 $table_editor = new PLTableEditor('admin/skins','skins','id');
1011 $table_editor->describe('name','nom',true);
1012 $table_editor->describe('skin_tpl','nom du template',true);
1013 $table_editor->describe('auteur','auteur',false);
1014 $table_editor->describe('comment','commentaire',true);
1015 $table_editor->describe('date','date',false);
1016 $table_editor->describe('ext','extension du screenshot',false);
1017 $table_editor->apply($page, $action, $id);
1018 }
1019
1020 function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
1021 $page->setTitle('Administration - Postfix : Blacklist');
1022 $page->assign('title', 'Blacklist de postfix');
1023 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
1024 $table_editor->describe('reject_text','Texte de rejet',true);
1025 $table_editor->describe('email','email',true);
1026 $table_editor->apply($page, $action, $id);
1027 }
1028 function handler_postfix_whitelist(&$page, $action = 'list', $id = null) {
1029 $page->setTitle('Administration - Postfix : Whitelist');
1030 $page->assign('title', 'Whitelist de postfix');
1031 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
1032 $table_editor->describe('email','email',true);
1033 $table_editor->apply($page, $action, $id);
1034 }
1035 function handler_mx_broken(&$page, $action = 'list', $id = null) {
1036 $page->setTitle('Administration - MX Défaillants');
1037 $page->assign('title', 'MX Défaillant');
1038 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true);
1039 $table_editor->describe('host', 'Masque', true);
1040 $table_editor->describe('state', 'Niveau', true);
1041 $table_editor->describe('text', 'Description du problème', false);
1042 $table_editor->apply($page, $action, $id);
1043 }
1044 function handler_logger_actions(&$page, $action = 'list', $id = null) {
1045 $page->setTitle('Administration - Actions');
1046 $page->assign('title', 'Gestion des actions de logger');
1047 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
1048 $table_editor->describe('text','intitulé',true);
1049 $table_editor->describe('description','description',true);
1050 $table_editor->apply($page, $action, $id);
1051 }
1052 function handler_downtime(&$page, $action = 'list', $id = null) {
1053 $page->setTitle('Administration - Coupures');
1054 $page->assign('title', 'Gestion des coupures');
1055 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
1056 $table_editor->describe('debut','date',true);
1057 $table_editor->describe('duree','durée',false);
1058 $table_editor->describe('resume','résumé',true);
1059 $table_editor->describe('services','services affectés',true);
1060 $table_editor->describe('description','description',false);
1061 $table_editor->apply($page, $action, $id);
1062 }
1063
1064 function handler_wiki(&$page, $action = 'list', $wikipage = null, $wikipage2 = null)
1065 {
1066 if (S::hasAuthToken()) {
1067 $page->setRssLink('Changement Récents',
1068 '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('token'));
1069 }
1070
1071 // update wiki perms
1072 if ($action == 'update') {
1073 S::assert_xsrf_token();
1074
1075 $perms_read = Post::v('read');
1076 $perms_edit = Post::v('edit');
1077 if ($perms_read || $perms_edit) {
1078 foreach ($_POST as $wiki_page => $val) {
1079 if ($val == 'on') {
1080 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1081 if ($wp->setPerms($perms_read ? $perms_read : $wp->readPerms(),
1082 $perms_edit ? $perms_edit : $wp->writePerms())) {
1083 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1084 } else {
1085 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1086 }
1087 }
1088 }
1089 }
1090 } else if ($action != 'list' && !empty($wikipage)) {
1091 $wp = new PlWikiPage($wikipage);
1092 S::assert_xsrf_token();
1093
1094 if ($action == 'delete') {
1095 if ($wp->delete()) {
1096 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1097 } else {
1098 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1099 }
1100 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1101 if ($changedLinks = $wp->rename($wikipage2)) {
1102 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1103 if (is_numeric($changedLinks)) {
1104 $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.');
1105 }
1106 $page->trigSuccess($s);
1107 } else {
1108 $page->trigError("Impossible de déplacer la page ".$wikipage);
1109 }
1110 }
1111 }
1112
1113 $perms = PlWikiPage::permOptions();
1114
1115 // list wiki pages and their perms
1116 $wiki_pages = PlWikiPage::listPages();
1117 ksort($wiki_pages);
1118 $wiki_tree = array();
1119 foreach ($wiki_pages as $file => $desc) {
1120 list($cat, $name) = explode('.', $file);
1121 if (!isset($wiki_tree[$cat])) {
1122 $wiki_tree[$cat] = array();
1123 }
1124 $wiki_tree[$cat][$name] = $desc;
1125 }
1126
1127 $page->changeTpl('admin/wiki.tpl');
1128 $page->addJsLink('jquery.js');
1129 $page->assign('wiki_pages', $wiki_tree);
1130 $page->assign('perms_opts', $perms);
1131 }
1132
1133 function handler_ipwatch(&$page, $action = 'list', $ip = null)
1134 {
1135 $page->changeTpl('admin/ipwatcher.tpl');
1136
1137 $states = array('safe' => 'Ne pas surveiller',
1138 'unsafe' => 'Surveiller les inscriptions',
1139 'dangerous' => 'Surveiller tous les accès',
1140 'ban' => 'Bannir cette adresse');
1141 $page->assign('states', $states);
1142
1143 switch (Post::v('action')) {
1144 case 'create':
1145 if (trim(Post::v('ipN')) != '') {
1146 S::assert_xsrf_token();
1147 Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1148 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1149 ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))),
1150 Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
1151 };
1152 break;
1153
1154 case 'edit':
1155 S::assert_xsrf_token();
1156 Xdb::execute('UPDATE ip_watch
1157 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1158 WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'),
1159 ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN')));
1160 break;
1161
1162 default:
1163 if ($action == 'delete' && !is_null($ip)) {
1164 S::assert_xsrf_token();
1165 Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1166 }
1167 }
1168 if ($action != 'create' && $action != 'edit') {
1169 $action = 'list';
1170 }
1171 $page->assign('action', $action);
1172
1173 if ($action == 'list') {
1174 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1175 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1176 IF(w.ip = s.ip, s.host, s.forward_host)),
1177 w.mask, w.detection, w.state, u.hruid
1178 FROM ip_watch AS w
1179 LEFT JOIN logger.sessions AS s ON (s.ip = w.ip)
1180 LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip)
1181 LEFT JOIN auth_user_md5 AS u ON (u.user_id = s.uid)
1182 GROUP BY w.ip, u.hruid
1183 ORDER BY w.state, w.ip, u.hruid";
1184 $it = Xdb::iterRow($sql);
1185
1186 $table = array();
1187 $props = array();
1188 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1189 $ip = uint_to_ip($ip);
1190 $mask = uint_to_ip($mask);
1191 if (count($props) == 0 || $props['ip'] != $ip) {
1192 if (count($props) > 0) {
1193 $table[] = $props;
1194 }
1195 $props = array('ip' => $ip,
1196 'mask' => $mask,
1197 'host' => $host,
1198 'detection' => $date,
1199 'state' => $state,
1200 'users' => array($hruid));
1201 } else {
1202 $props['users'][] = $hruid;
1203 }
1204 }
1205 if (count($props) > 0) {
1206 $table[] = $props;
1207 }
1208 $page->assign('table', $table);
1209 } elseif ($action == 'edit') {
1210 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1211 u1.hruid AS edit, u2.hruid AS hruid, s.host
1212 FROM ip_watch AS w
1213 LEFT JOIN auth_user_md5 AS u1 ON (u1.user_id = w.uid)
1214 LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
1215 LEFT JOIN auth_user_md5 AS u2 ON (u2.user_id = s.uid)
1216 WHERE w.ip = {?}
1217 GROUP BY u2.hruid
1218 ORDER BY u2.hruid";
1219 $it = Xdb::iterRow($sql, ip_to_uint($ip));
1220
1221 $props = array();
1222 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1223 if (count($props) == 0) {
1224 $props = array('ip' => $ip,
1225 'mask' => uint_to_ip($mask),
1226 'host' => $host,
1227 'detection' => $detection,
1228 'state' => $state,
1229 'last' => $last,
1230 'description' => $description,
1231 'edit' => $edit,
1232 'users' => array($hruid));
1233 } else {
1234 $props['users'][] = $hruid;
1235 }
1236 }
1237 $page->assign('ip', $props);
1238 }
1239 }
1240
1241 function handler_icons(&$page)
1242 {
1243 $page->changeTpl('admin/icons.tpl');
1244 $dh = opendir('../htdocs/images/icons');
1245 if (!$dh) {
1246 $page->trigError('Dossier des icones introuvables.');
1247 }
1248 $icons = array();
1249 while (($file = readdir($dh)) !== false) {
1250 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1251 array_push($icons, substr($file, 0, -4));
1252 }
1253 }
1254 sort($icons);
1255 $page->assign('icons', $icons);
1256 }
1257
1258 function handler_accounts(&$page)
1259 {
1260 $page->changeTpl('admin/accounts.tpl');
1261 $page->assign('disabled', XDB::iterator('SELECT u.nom, u.prenom, u.promo, u.comment, u.hruid
1262 FROM auth_user_md5 AS u
1263 WHERE perms = \'disabled\'
1264 ORDER BY nom, prenom'));
1265 $page->assign('admins', XDB::iterator('SELECT u.nom, u.prenom, u.promo, u.hruid
1266 FROM auth_user_md5 AS u
1267 WHERE perms = \'admin\'
1268 ORDER BY nom, prenom'));
1269 }
1270 }
1271
1272 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1273 ?>