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