2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class AdminModule
extends PLModule
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'),
53 function handler_phpinfo(&$page)
59 function handler_default(&$page)
61 $page->changeTpl('admin/index.tpl');
62 $page->setTitle('Administration');
65 function handler_postfix_delayed(&$page)
67 $page->changeTpl('admin/postfix_delayed.tpl');
68 $page->setTitle('Administration - Postfix : Retardés');
70 if (Env
::has('del')) {
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')) {
76 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
77 $page->trigSuccess($crc." a le droit de passer !");
81 "SELECT crc, nb, update_time, create_time,
82 FIND_IN_SET('del', release) AS del,
83 FIND_IN_SET('ok', release) AS ok
86 ORDER BY release != ''");
88 $page->assign_by_ref('mails', $sql);
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);
96 if (Post
::has('submit')) {
97 foreach (Env
::v('lvl') as $id=>$val) {
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]
105 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
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.
114 * @param integer year
115 * @param integer month
116 * @return array days in that month we have log entries covering.
119 function _getDays($year, $month)
121 // give a 'no filter' option
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();
134 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
138 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
142 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
143 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
145 for($i = $min; $i<=$max; $i++
) {
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.
157 * @param integer year
158 * @return array List of month numbers we have log info for.
161 function _getMonths($year)
163 // give a 'no filter' option
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();
172 if (($year < $ymin) ||
($year > $ymax)) {
176 $min = $year == $ymin ?
intval($mmin) : 1;
177 $max = $year == $ymax ?
intval($mmax) : 12;
179 for($i = $min; $i<=$max; $i++
) {
187 /** Retrieves the available years.
188 * Obtains a list of years that we have log entries covering.
190 * @return array years we have log entries for.
195 // give a 'no filter' option
198 // retrieve available years
199 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions");
200 list($max, $min) = $res->fetchOneRow();
202 for($i = intval($min); $i<=$max; $i++
) {
209 /** Make a where clause to get a user's sessions.
210 * Prepare the where clause request that will retrieve the sessions.
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.
217 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
220 function _makeWhere($year, $month, $day, $uid)
222 // start constructing the "where" clause
226 array_push($where, "uid='$uid'");
228 // we were given at least a year
231 $dmin = mktime(0, 0, 0, $month, $day, $year);
232 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
234 $dmin = mktime(0, 0, 0, $month, 1, $year);
235 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
237 $dmin = mktime(0, 0, 0, 1, 1, $year);
238 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
240 $where[] = "start >= " . date("Ymd000000", $dmin);
241 $where[] = "start < " . date("Ymd000000", $dmax);
244 if (!empty($where)) {
245 return ' WHERE ' . implode($where, " AND ");
249 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
254 function handler_logger(&$page, $action = null
, $arg = null
) {
255 if ($action == 'session') {
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);
264 $page->assign('session', $a = $res->fetchOneAssoc());
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);
275 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
277 $res = XDB
::query('SELECT id FROM aliases WHERE alias={?}',
279 $loguid = $res->fetchOneCell();
282 $year = Env
::i('year');
283 $month = Env
::i('month');
284 $day = Env
::i('day');
286 $year = Env
::i('year', intval(date('Y')));
287 $month = Env
::i('month', intval(date('m')));
288 $day = Env
::i('day', intval(date('d')));
296 // smarty assignments
297 // retrieve available years
298 $page->assign('years', $this->_getYears());
299 $page->assign('year', $year);
301 // retrieve available months for the current year
302 $page->assign('months', $this->_getMonths($year));
303 $page->assign('month', $month);
305 // retrieve available days for the current year and month
306 $page->assign('days', $this->_getDays($year, $month));
307 $page->assign('day', $day);
309 $page->assign('loguser', $loguser);
310 // smarty assignments
312 if ($loguid ||
$year) {
314 // get the requested sessions
315 $where = $this->_makeWhere($year, $month, $day, $loguid);
316 $select = "SELECT s.id, s.start, s.uid,
318 FROM logger.sessions AS s
319 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie')
321 ORDER BY start DESC";
322 $res = XDB
::iterator($select);
325 while ($mysess = $res->next()) {
326 $mysess['events'] = array();
327 $sessions[$mysess['id']] = $mysess;
329 array_reverse($sessions);
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)
338 $res = XDB
::iterator($sql);
339 while ($event = $res->next()) {
340 array_push($sessions[$event['id']]['events'], $event['text']);
342 $page->assign_by_ref('sessions', $sessions);
344 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
348 $page->changeTpl('admin/logger-view.tpl');
350 $page->setTitle('Administration - Logs des sessions');
353 function handler_user(&$page, $login = false
)
356 $page->changeTpl('admin/utilisateurs.tpl');
357 $page->setTitle('Administration - Edit/Su/Log');
358 require_once("emails.inc.php");
359 require_once("user.func.inc.php");
361 if (S
::has('suid')) {
362 $page->kill("Déjà en SUID !!!");
365 if (Env
::has('user_id')) {
366 $login = get_user_forlife(Env
::i('user_id'));
368 $login = Env
::i('user_id');
370 } elseif (Env
::has('login')) {
371 $login = get_user_forlife(Env
::v('login'));
374 if(Env
::has('logs_button') && $login) {
375 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
378 if (Env
::has('ax_button') && $login) {
379 pl_redirect("admin/synchro_ax/$login");
382 if(Env
::has('suid_button') && $login) {
383 S
::logger()->log("suid_start", "login by ".S
::v('forlife'));
384 $r = XDB
::query("SELECT id
386 WHERE alias={?}", $login);
387 if($uid = $r->fetchOneCell()) {
388 if (!Platal
::session()->startSUID($uid)) {
389 $page->trigError('Impossible d\'effectuer un SUID sur ' . $uid);
391 $page->kill("coucou");
398 if (is_numeric($login)) {
399 $r = XDB
::query("SELECT *, a.alias AS forlife,
400 FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe,
401 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
402 FROM auth_user_md5 AS u
403 LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie')
404 WHERE u.user_id = {?}", $login);
406 $r = XDB
::query("SELECT *, a.alias AS forlife,
407 FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe,
408 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
409 FROM auth_user_md5 AS u
410 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
412 $mr = $r->fetchOneAssoc();
414 // Checks the user has a forlife, as non-registered user can't have redirections.
415 if ($mr['forlife']) {
416 $redirect = new Redirect($mr['user_id']);
419 // Check if there was a submission
420 foreach($_POST as $key => $val) {
421 S
::assert_xsrf_token();
425 $email = trim(Env
::v('email'));
426 if (!isvalid_email_redirection($email)) {
427 $page->trigError("Email non valide: $email");
429 $redirect->add_email($email);
430 $page->trigSuccess("Ajout de $email effectué");
436 $redirect->delete_email($val);
442 XDB
::execute("DELETE FROM aliases
443 WHERE id={?} AND alias={?}
444 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
445 XDB
::execute("UPDATE emails
447 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
448 $mr['user_id'], $val);
449 fix_bestalias($mr['user_id']);
450 $page->trigSuccess($val." a été supprimé");
455 $redirect->modify_one_email($val, true
);
458 case "deactivate_fwd":
460 $redirect->modify_one_email($val, false
);
464 $redirect->disable();
471 $redirect->clean_errors($val);
476 $alias = trim(Env
::v('email'));
477 if (strpos($alias, '@') !== false
) {
478 list($alias, $domain) = explode('@', $alias);
480 $domain = $globals->mail
->domain
;
482 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
483 $page->trigError("'$alias' n'est pas un alias valide");
485 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
486 $req = new AliasReq($mr['user_id'], $alias, 'Admin request', false
);
487 if ($req->commit()) {
488 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
490 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
492 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
493 if (XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
494 $mr['user_id'], $alias)) {
495 $page->trigSuccess("Nouvel alias '$alias' ajouté");
497 $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué");
500 $page->trigError("Le domaine '$domain' n'est pas valide");
505 // 'bestalias' is the first bit of the set : 1
506 // 255 is the max for flags (8 sets max)
507 XDB
::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
508 XDB
::execute("UPDATE aliases
510 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
516 require_once('secure_hash.inc.php');
517 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
hash_encrypt(Env
::v('newpass_clair')) : Env
::v('passw');
518 $naiss = Env
::v('naissanceN');
519 $deces = Env
::v('decesN');
520 $perms = Env
::v('permsN');
521 $prenm = Env
::v('prenomN');
522 $nom = Env
::v('nomN');
523 $nomusage = Env
::v('nomusageN');
524 $promo = Env
::i('promoN');
525 $sexe = Env
::v('sexeN');
526 $comm = trim(Env
::v('commentN'));
527 $watch = Env
::v('watchN');
539 if ($watch && !$comm) {
540 $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte");
544 $watch = 'SELECT naissance, deces, password, perms, nom_usage,
545 prenom, nom, flags, promo, comment
547 WHERE user_id = ' . $mr['user_id'];
548 $res = XDB
::query($watch);
549 $old_fields = $res->fetchOneAssoc();
550 $query = "UPDATE auth_user_md5 SET
551 naissance = '$naiss',
553 password = '$pass_encrypted',
555 prenom = '".addslashes($prenm)."',
556 nom = '".addslashes($nom)."',
557 nom_usage = '".addslashes($nomusage)."',
560 comment = '".addslashes($comm)."'
561 WHERE user_id = '{$mr['user_id']}'";
562 if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') {
563 // A user has been banned ==> ensure his php session has been killed
564 // This solution is ugly and overkill, but, it should be efficient.
567 if (XDB
::execute($query)) {
568 user_reindex($mr['user_id']);
570 $res = XDB
::query($watch);
571 $new_fields = $res->fetchOneAssoc();
573 $mailer = new PlMailer("admin/useredit.mail.tpl");
574 $mailer->assign("admin", S
::v('forlife'));
575 $mailer->assign("user", $mr['forlife']);
576 $mailer->assign('old', $old_fields);
577 $mailer->assign('new', $new_fields);
580 // update number of subscribers (perms or deceased may have changed)
581 $globals->updateNbIns();
583 $page->trigSuccess("updaté correctement.");
585 if (Env
::v('nomusageN') != $mr['nom_usage']) {
586 set_new_usage($mr['user_id'], Env
::v('nomusageN'), make_username(Env
::v('prenomN'), Env
::v('nomusageN')));
588 if (Env
::v('decesN') != $mr['deces']) {
589 require_once 'notifs.inc.php';
590 register_watch_op($mr['user_id'], WATCH_DEATH
, $mr['deces']);
591 user_clear_all_subs($mr['user_id'], false
);
593 $r = XDB
::query("SELECT *, a.alias AS forlife,
594 FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe
595 FROM auth_user_md5 AS u
596 LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie')
597 WHERE u.user_id = {?}", $mr['user_id']);
598 $mr = $r->fetchOneAssoc();
600 // If GoogleApps is enabled, the user did choose to use synchronized passwords,
601 // and the password was changed, updates the Google Apps password as well.
602 if ($globals->mailstorage
->googleapps_domain
&& Env
::v('newpass_clair') != "********") {
603 require_once 'googleapps.inc.php';
604 $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']);
605 if ($account->active() && $account->sync_password
) {
606 $account->set_password($pass_encrypted);
610 // If GoogleApps is enabled, and the user is now disabled, disables the Google Apps account as well.
611 if ($globals->mailstorage
->googleapps_domain
&&
612 $new_fields['perms'] == 'disabled' &&
613 $new_fields['perms'] != $old_fields['perms']) {
614 require_once 'googleapps.inc.php';
615 $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']);
620 // DELETE FROM auth_user_md5
622 user_clear_all_subs($mr['user_id']);
623 // update number of subscribers (perms or deceased may have changed)
624 $globals->updateNbIns();
625 $page->trigSuccess("'{$mr['user_id']}' a été désinscrit !");
626 $mailer = new PlMailer("admin/useredit.mail.tpl");
627 $mailer->assign("admin", S
::v('forlife'));
628 $mailer->assign("user", $mr['forlife']);
629 $mailer->assign("deletion", true
);
634 XDB
::execute("DELETE FROM forums.innd WHERE uid = {?}", $mr['user_id']);
635 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
636 XDB
::execute("INSERT INTO forums.innd
638 ipmax = '4294967295',
644 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $mr['user_id']);
650 $res = XDB
::query("SELECT start, host
652 WHERE uid={?} AND suid=0
654 LIMIT 1", $mr['user_id']);
655 list($lastlogin,$host) = $res->fetchOneRow();
656 $page->assign('lastlogin', $lastlogin);
657 $page->assign('host', $host);
659 $res = XDB
::iterator("SELECT alias
661 INNER JOIN virtual_redirect USING(vid)
662 WHERE type = 'user' AND redirect LIKE '" . $mr['forlife'] . "@%'");
663 $page->assign('virtuals', $res);
665 $page->assign('aliases', XDB
::iterator(
666 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
668 WHERE id = {?} AND type!='homonyme'
669 ORDER BY type!= 'a_vie'", $mr["user_id"]));
670 if ($mr['perms'] != 'pending' && isset($redirect)) {
671 $page->assign('emails', $redirect->emails
);
674 $page->assign('mr',$mr);
677 $res = XDB
::query("SELECT write_perm, read_perm, comment
679 WHERE uid = {?}", $mr['user_id']);
680 $bans = $res->fetchOneAssoc();
681 $page->assign('bans', $bans);
685 function getMatricule($line, $key)
687 $mat = $line['matricule'];
688 $year = intval(substr($mat, 0, 3));
689 $rang = intval(substr($mat, 3, 3));
690 if ($year > 200) { $year /= 10; };
694 return sprintf('%04u%04u', 1900+
$year, $rang);
698 function handler_promo(&$page, $action = null
, $promo = null
)
700 if (Env
::has('promo')) {
701 if(Env
::i('promo') > 1900 && Env
::i('promo') < 2050) {
702 $action = Env
::v('valid_promo') == 'Ajouter des membres' ?
'add' : 'ax';
703 pl_redirect('admin/promo/' . $action . '/' . Env
::i('promo'));
705 $page->trigError('Promo non valide');
709 $page->changeTpl('admin/promo.tpl');
710 if ($promo > 1900 && $promo < 2050 && ($action == 'add' ||
$action == 'ax')) {
711 $page->assign('promo', $promo);
716 $importer = new CSVImporter('auth_user_md5', 'matricule');
717 $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule'));
720 $fields = array('nom', 'nom_ini', 'prenom', 'naissance_ini',
721 'prenom_ini', 'promo', 'promo_sortie', 'flags',
722 'matricule', 'matricule_ax', 'perms');
723 $importer->forceValue('promo', $promo);
724 $importer->forceValue('promo_sortie', $promo +
3);
727 $fields = array('matricule', 'matricule_ax');
730 $importer->apply($page, "admin/promo/$action/$promo", $fields);
733 function handler_homonyms(&$page, $op = 'list', $target = null
) {
734 $page->changeTpl('admin/homonymes.tpl');
735 $page->setTitle('Administration - Homonymes');
736 require_once("homonymes.inc.php");
739 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
742 $page->assign('nom',$nom);
743 $page->assign('prenom',$prenom);
744 $page->assign('forlife',$forlife);
745 $page->assign('loginbis',$loginbis);
749 $page->assign('op', $op);
750 $page->assign('target', $target);
752 // on a un $target valide, on prepare les mails
754 // on examine l'op a effectuer
757 S
::assert_xsrf_token();
759 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
760 switch_bestalias($target, $loginbis);
762 $page->trigSuccess('Email envoyé à ' . $forlife . '.');
766 S
::assert_xsrf_token();
768 switch_bestalias($target, $loginbis);
769 XDB
::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
770 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
771 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
773 $page->trigSuccess('Email envoyé à ' . $forlife . ', alias supprimé.');
779 $res = XDB
::iterator(
780 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
782 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
783 IF(h.homonyme_id=s.id, a.type, NULL) AS type
785 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
786 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
787 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
788 WHERE a.type='homonyme' OR a.expire!=''
789 ORDER BY a.alias,promo");
791 while ($tab = $res->next()) {
792 $hnymes[$tab['homonyme']][] = $tab;
794 $page->assign_by_ref('hnymes',$hnymes);
798 function handler_ax_xorg(&$page) {
799 $page->changeTpl('admin/ax-xorg.tpl');
800 $page->setTitle('Administration - AX/X.org');
802 // liste des différences
804 '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
805 FROM auth_user_md5 AS u
806 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
807 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
808 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
809 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
810 ORDER BY u.promo,u.nom,u.prenom');
811 $page->assign('diffs', $res->fetchAllAssoc());
813 // gens à l'ax mais pas chez nous
815 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
816 FROM identification_ax as ia
817 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
818 WHERE u.nom IS NULL');
819 $page->assign('mank', $res->fetchAllAssoc());
821 // gens chez nous et pas à l'ax
822 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
823 $page->assign('plus', $res->fetchAllAssoc());
826 function handler_deaths(&$page, $promo = 0, $validate = false
) {
827 $page->changeTpl('admin/deces_promo.tpl');
828 $page->setTitle('Administration - Deces');
831 $promo = Env
::i('promo');
832 if (Env
::has('sub10')) $promo -= 10;
833 if (Env
::has('sub01')) $promo -= 1;
834 if (Env
::has('add01')) $promo +
= 1;
835 if (Env
::has('add10')) $promo +
= 10;
837 $page->assign('promo',$promo);
840 S
::assert_xsrf_token();
842 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
843 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
845 if($val == $deces ||
empty($val)) {
849 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
850 $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.');
851 if($deces == '0000-00-00' ||
empty($deces)) {
852 require_once('notifs.inc.php');
853 register_watch_op($uid, WATCH_DEATH
, $val);
854 require_once('user.func.inc.php');
855 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
860 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
861 $page->assign('decedes', $res);
864 function handler_dead_but_active(&$page) {
865 $page->changeTpl('admin/dead_but_active.tpl');
866 $page->setTitle('Administration - Décédés');
868 $res = XDB
::iterator(
869 "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, a.alias, DATE(MAX(s.start)) AS last
870 FROM auth_user_md5 AS u
871 LEFT JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
872 LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0)
873 WHERE perms IN ('admin', 'user') AND deces <> 0
875 ORDER BY u.promo, u.nom");
876 $page->assign('dead', $res);
879 function handler_synchro_ax(&$page, $user = null
, $action = null
) {
880 $page->changeTpl('admin/synchro_ax.tpl');
881 $page->setTitle('Administration - Synchro AX');
883 require_once('synchro_ax.inc.php');
885 if (is_ax_key_missing()) {
886 $page->assign('no_private_key', true
);
890 require_once('user.func.inc.php');
893 $login = get_user_forlife($user);
895 if (Env
::has('user')) {
896 $login = get_user_forlife(Env
::v('user'));
897 if ($login === false
) {
902 if (Env
::has('mat')) {
906 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
907 WHERE matricule={?}", Env
::i('mat'));
908 $login = $res->fetchOneCell();
912 if ($action == 'import') {
913 ax_synchronize($login, S
::v('uid'));
915 // get details from user, but looking only info that can be seen by ax
916 $user = get_user_details($login, S
::v('uid'), 'ax');
917 $userax= get_user_ax($user['matricule_ax']);
918 require_once 'profil.func.inc.php';
919 $diff = diff_user_details($userax, $user, 'ax');
921 $page->assign('x', $user);
922 $page->assign('diff', $diff);
926 function handler_validate(&$page, $action = 'list', $id = null
)
928 $page->changeTpl('admin/valider.tpl');
929 $page->setTitle('Administration - Valider une demande');
930 $page->addCssLink('nl.css');
931 $page->addJsLink('ajax.js');
932 require_once("validations.inc.php");
935 if ($action == 'edit' and !is_null($id)) {
936 $page->assign('preview_id', $id);
939 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
940 S
::assert_xsrf_token();
942 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
944 $req->handle_formu();
946 $page->trigWarning('La validation a déjà été effectuée.');
950 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
951 while (($a = $r->next()) && $a['Field'] != 'category');
952 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
955 $res = XDB
::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S
::v('uid'));
956 $hide_requests = $res->fetchOneCell();
957 if (Post
::has('hide')) {
959 foreach ($categories as $cat)
960 if (!Post
::v($cat)) {
964 $hide_requests = join(',', $hide);
965 XDB
::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
966 S
::v('uid'), $hide_requests);
967 } elseif ($hide_requests) {
968 foreach (explode(',', $hide_requests) as $hide_type)
969 $hidden[$hide_type] = true
;
971 $page->assign('hide_requests', $hidden);
973 // Update the count of item to validate here... useful in development configuration
974 // where several copies of the site use the same DB, but not the same "dynamic configuration"
976 $globals->updateNbValid();
977 $page->assign('vit', new ValidateIterator());
980 function handler_validate_answers(&$page, $action = 'list', $id = null
) {
981 $page->setTitle('Administration - Réponses automatiques de validation');
982 $page->assign('title', 'Gestion des réponses automatiques');
983 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
984 $table_editor->describe('category','catégorie',true
);
985 $table_editor->describe('title','titre',true
);
986 $table_editor->describe('answer','texte',false
);
987 $table_editor->apply($page, $action, $id);
989 function handler_skins(&$page, $action = 'list', $id = null
) {
990 $page->setTitle('Administration - Skins');
991 $page->assign('title', 'Gestion des skins');
992 $table_editor = new PLTableEditor('admin/skins','skins','id');
993 $table_editor->describe('name','nom',true
);
994 $table_editor->describe('skin_tpl','nom du template',true
);
995 $table_editor->describe('auteur','auteur',false
);
996 $table_editor->describe('comment','commentaire',true
);
997 $table_editor->describe('date','date',false
);
998 $table_editor->describe('ext','extension du screenshot',false
);
999 $table_editor->apply($page, $action, $id);
1002 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
) {
1003 $page->setTitle('Administration - Postfix : Blacklist');
1004 $page->assign('title', 'Blacklist de postfix');
1005 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
1006 $table_editor->describe('reject_text','Texte de rejet',true
);
1007 $table_editor->describe('email','email',true
);
1008 $table_editor->apply($page, $action, $id);
1010 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
) {
1011 $page->setTitle('Administration - Postfix : Whitelist');
1012 $page->assign('title', 'Whitelist de postfix');
1013 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
1014 $table_editor->describe('email','email',true
);
1015 $table_editor->apply($page, $action, $id);
1017 function handler_mx_broken(&$page, $action = 'list', $id = null
) {
1018 $page->setTitle('Administration - MX Défaillants');
1019 $page->assign('title', 'MX Défaillant');
1020 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
1021 $table_editor->describe('host', 'Masque', true
);
1022 $table_editor->describe('state', 'Niveau', true
);
1023 $table_editor->describe('text', 'Description du problème', false
);
1024 $table_editor->apply($page, $action, $id);
1026 function handler_logger_actions(&$page, $action = 'list', $id = null
) {
1027 $page->setTitle('Administration - Actions');
1028 $page->assign('title', 'Gestion des actions de logger');
1029 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
1030 $table_editor->describe('text','intitulé',true
);
1031 $table_editor->describe('description','description',true
);
1032 $table_editor->apply($page, $action, $id);
1034 function handler_downtime(&$page, $action = 'list', $id = null
) {
1035 $page->setTitle('Administration - Coupures');
1036 $page->assign('title', 'Gestion des coupures');
1037 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
1038 $table_editor->describe('debut','date',true
);
1039 $table_editor->describe('duree','durée',false
);
1040 $table_editor->describe('resume','résumé',true
);
1041 $table_editor->describe('services','services affectés',true
);
1042 $table_editor->describe('description','description',false
);
1043 $table_editor->apply($page, $action, $id);
1046 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
1048 if (S
::v('core_rss_hash')) {
1049 $page->setRssLink('Changement Récents',
1050 '/Site/AllRecentChanges?action=rss&user=' . S
::v('forlife') . '&hash=' . S
::v('core_rss_hash'));
1053 // update wiki perms
1054 if ($action == 'update') {
1055 S
::assert_xsrf_token();
1057 $perms_read = Post
::v('read');
1058 $perms_edit = Post
::v('edit');
1059 if ($perms_read ||
$perms_edit) {
1060 foreach ($_POST as $wiki_page => $val) {
1062 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1063 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1064 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1065 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1067 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1072 } else if ($action != 'list' && !empty($wikipage)) {
1073 $wp = new PlWikiPage($wikipage);
1074 S
::assert_xsrf_token();
1076 if ($action == 'delete') {
1077 if ($wp->delete()) {
1078 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1080 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1082 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1083 if ($changedLinks = $wp->rename($wikipage2)) {
1084 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1085 if (is_numeric($changedLinks)) {
1086 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1088 $page->trigSuccess($s);
1090 $page->trigError("Impossible de déplacer la page ".$wikipage);
1095 $perms = PlWikiPage
::permOptions();
1097 // list wiki pages and their perms
1098 $wiki_pages = PlWikiPage
::listPages();
1100 $wiki_tree = array();
1101 foreach ($wiki_pages as $file => $desc) {
1102 list($cat, $name) = explode('.', $file);
1103 if (!isset($wiki_tree[$cat])) {
1104 $wiki_tree[$cat] = array();
1106 $wiki_tree[$cat][$name] = $desc;
1109 $page->changeTpl('admin/wiki.tpl');
1110 $page->addJsLink('jquery.js');
1111 $page->assign('wiki_pages', $wiki_tree);
1112 $page->assign('perms_opts', $perms);
1115 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1117 $page->changeTpl('admin/ipwatcher.tpl');
1119 $states = array('safe' => 'Ne pas surveiller',
1120 'unsafe' => 'Surveiller les inscriptions',
1121 'dangerous' => 'Surveiller tous les accès',
1122 'ban' => 'Bannir cette adresse');
1123 $page->assign('states', $states);
1125 switch (Post
::v('action')) {
1127 if (trim(Post
::v('ipN')) != '') {
1128 S
::assert_xsrf_token();
1129 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1130 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1131 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1132 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1137 S
::assert_xsrf_token();
1138 Xdb
::execute('UPDATE ip_watch
1139 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1140 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1141 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1145 if ($action == 'delete' && !is_null($ip)) {
1146 S
::assert_xsrf_token();
1147 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1150 if ($action != 'create' && $action != 'edit') {
1153 $page->assign('action', $action);
1155 if ($action == 'list') {
1156 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1157 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1158 IF(w.ip = s.ip, s.host, s.forward_host)),
1159 w.mask, w.detection, w.state, a.alias AS forlife
1161 LEFT JOIN logger.sessions AS s ON (s.ip = w.ip)
1162 LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip)
1163 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type = 'a_vie')
1164 GROUP BY w.ip, a.alias
1165 ORDER BY w.state, w.ip, a.alias";
1166 $it = Xdb
::iterRow($sql);
1170 while (list($ip, $host, $mask, $date, $state, $forlife) = $it->next()) {
1171 $ip = uint_to_ip($ip);
1172 $mask = uint_to_ip($mask);
1173 if (count($props) == 0 ||
$props['ip'] != $ip) {
1174 if (count($props) > 0) {
1177 $props = array('ip' => $ip,
1180 'detection' => $date,
1182 'users' => array($forlife));
1184 $props['users'][] = $forlife;
1187 if (count($props) > 0) {
1190 $page->assign('table', $table);
1191 } elseif ($action == 'edit') {
1192 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1193 a1.alias AS edit, a2.alias AS forlife, s.host
1195 LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
1196 LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
1197 LEFT JOIN aliases AS a2 ON (a2.id = s.uid AND a2.type = 'a_vie')
1201 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1204 while (list($detection, $state, $last, $description, $mask, $edit, $forlife, $host) = $it->next()) {
1205 if (count($props) == 0) {
1206 $props = array('ip' => $ip,
1207 'mask' => uint_to_ip($mask),
1209 'detection' => $detection,
1212 'description' => $description,
1214 'users' => array($forlife));
1216 $props['users'][] = $forlife;
1219 $page->assign('ip', $props);
1223 function handler_icons(&$page)
1225 $page->changeTpl('admin/icons.tpl');
1226 $dh = opendir('../htdocs/images/icons');
1228 $page->trigError('Dossier des icones introuvables.');
1231 while (($file = readdir($dh)) !== false
) {
1232 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1233 array_push($icons, substr($file, 0, -4));
1237 $page->assign('icons', $icons);
1241 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: