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'),
50 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP
, 'admin'),
54 function handler_phpinfo(&$page)
60 function handler_default(&$page)
62 $page->changeTpl('admin/index.tpl');
63 $page->setTitle('Administration');
66 function handler_postfix_delayed(&$page)
68 $page->changeTpl('admin/postfix_delayed.tpl');
69 $page->setTitle('Administration - Postfix : Retardés');
71 if (Env
::has('del')) {
73 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
74 $page->trigSuccess($crc." verra tous ses emails supprimés !");
75 } elseif (Env
::has('ok')) {
77 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
78 $page->trigSuccess($crc." a le droit de passer !");
82 "SELECT crc, nb, update_time, create_time,
83 FIND_IN_SET('del', release) AS del,
84 FIND_IN_SET('ok', release) AS ok
87 ORDER BY release != ''");
89 $page->assign_by_ref('mails', $sql);
92 function handler_postfix_regexpsbounces(&$page, $new = null
) {
93 $page->changeTpl('admin/emails_bounces_re.tpl');
94 $page->setTitle('Administration - Postfix : Regexps Bounces');
95 $page->assign('new', $new);
97 if (Post
::has('submit')) {
98 foreach (Env
::v('lvl') as $id=>$val) {
100 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
101 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
106 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
111 /** Retrieves the available days for a given year and month.
112 * Obtain a list of days of the given month in the given year
113 * that are within the range of dates that we have log entries for.
115 * @param integer year
116 * @param integer month
117 * @return array days in that month we have log entries covering.
120 function _getDays($year, $month)
122 // give a 'no filter' option
125 if ($year && $month) {
126 $day_max = Array(-1, 31, checkdate(2, 29, $year) ?
29 : 28 , 31,
127 30, 31, 30, 31, 31, 30, 31, 30, 31);
128 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
129 MONTH(MAX(start)), MONTH(MIN(start)),
130 DAYOFMONTH(MAX(start)),
131 DAYOFMONTH(MIN(start))
132 FROM logger.sessions");
133 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
135 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
139 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
143 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
144 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
146 for($i = $min; $i<=$max; $i++
) {
154 /** Retrieves the available months for a given year.
155 * Obtains a list of month numbers that are within the timeframe that
156 * we have log entries for.
158 * @param integer year
159 * @return array List of month numbers we have log info for.
162 function _getMonths($year)
164 // give a 'no filter' option
168 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
169 MONTH(MAX(start)), MONTH(MIN(start))
170 FROM logger.sessions");
171 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
173 if (($year < $ymin) ||
($year > $ymax)) {
177 $min = $year == $ymin ?
intval($mmin) : 1;
178 $max = $year == $ymax ?
intval($mmax) : 12;
180 for($i = $min; $i<=$max; $i++
) {
188 /** Retrieves the available years.
189 * Obtains a list of years that we have log entries covering.
191 * @return array years we have log entries for.
196 // give a 'no filter' option
199 // retrieve available years
200 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions");
201 list($max, $min) = $res->fetchOneRow();
203 for($i = intval($min); $i<=$max; $i++
) {
210 /** Make a where clause to get a user's sessions.
211 * Prepare the where clause request that will retrieve the sessions.
213 * @param $year INTEGER Only get log entries made during the given year.
214 * @param $month INTEGER Only get log entries made during the given month.
215 * @param $day INTEGER Only get log entries made during the given day.
216 * @param $uid INTEGER Only get log entries referring to the given user ID.
218 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
221 function _makeWhere($year, $month, $day, $uid)
223 // start constructing the "where" clause
227 array_push($where, "uid='$uid'");
229 // we were given at least a year
232 $dmin = mktime(0, 0, 0, $month, $day, $year);
233 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
235 $dmin = mktime(0, 0, 0, $month, 1, $year);
236 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
238 $dmin = mktime(0, 0, 0, 1, 1, $year);
239 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
241 $where[] = "start >= " . date("Ymd000000", $dmin);
242 $where[] = "start < " . date("Ymd000000", $dmax);
245 if (!empty($where)) {
246 return ' WHERE ' . implode($where, " AND ");
250 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
255 function handler_logger(&$page, $action = null
, $arg = null
) {
256 if ($action == 'session') {
258 // we are viewing a session
259 $res = XDB
::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
260 FROM logger.sessions AS ls
261 LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie')
262 LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie')
263 WHERE ls.id = {?}", $arg);
265 $page->assign('session', $a = $res->fetchOneAssoc());
267 $res = XDB
::iterator('SELECT a.text, e.data, e.stamp
268 FROM logger.events AS e
269 LEFT JOIN logger.actions AS a ON e.action=a.id
270 WHERE e.session={?}', $arg);
271 while ($myarr = $res->next()) {
272 $page->append('events', $myarr);
276 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
278 $res = XDB
::query('SELECT id FROM aliases WHERE alias={?}',
280 $loguid = $res->fetchOneCell();
283 $year = Env
::i('year');
284 $month = Env
::i('month');
285 $day = Env
::i('day');
287 $year = Env
::i('year', intval(date('Y')));
288 $month = Env
::i('month', intval(date('m')));
289 $day = Env
::i('day', intval(date('d')));
297 // smarty assignments
298 // retrieve available years
299 $page->assign('years', $this->_getYears());
300 $page->assign('year', $year);
302 // retrieve available months for the current year
303 $page->assign('months', $this->_getMonths($year));
304 $page->assign('month', $month);
306 // retrieve available days for the current year and month
307 $page->assign('days', $this->_getDays($year, $month));
308 $page->assign('day', $day);
310 $page->assign('loguser', $loguser);
311 // smarty assignments
313 if ($loguid ||
$year) {
315 // get the requested sessions
316 $where = $this->_makeWhere($year, $month, $day, $loguid);
317 $select = "SELECT s.id, s.start, s.uid,
319 FROM logger.sessions AS s
320 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie')
322 ORDER BY start DESC";
323 $res = XDB
::iterator($select);
326 while ($mysess = $res->next()) {
327 $mysess['events'] = array();
328 $sessions[$mysess['id']] = $mysess;
330 array_reverse($sessions);
333 $sql = "SELECT s.id, a.text
334 FROM logger.sessions AS s
335 LEFT JOIN logger.events AS e ON(e.session=s.id)
336 INNER JOIN logger.actions AS a ON(a.id=e.action)
339 $res = XDB
::iterator($sql);
340 while ($event = $res->next()) {
341 array_push($sessions[$event['id']]['events'], $event['text']);
343 $page->assign_by_ref('sessions', $sessions);
345 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
349 $page->changeTpl('admin/logger-view.tpl');
351 $page->setTitle('Administration - Logs des sessions');
354 function handler_user(&$page, $login = false
)
357 $page->changeTpl('admin/utilisateurs.tpl');
358 $page->setTitle('Administration - Edit/Su/Log');
359 require_once("emails.inc.php");
361 if (S
::has('suid')) {
362 $page->kill("Déjà en SUID !!!");
365 // Loads the user identity using the environment.
367 $user = User
::get($login);
368 } else if (Env
::has('user_id')) {
369 $user = User
::get(Env
::i('user_id'));
370 } else if (Env
::has('login')) {
371 $user = User
::get(Env
::v('login'));
375 $login = $user->login();
376 $registered = ($user->forlifeEmail() != null
);
381 // Handles specific requests (AX sync, su, ...).
382 if(Env
::has('logs_button') && $registered) {
383 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
386 if (Env
::has('ax_button') && $registered) {
387 pl_redirect("admin/synchro_ax/" . $user->login());
390 if(Env
::has('suid_button') && $registered) {
391 S
::logger()->log("suid_start", "login on " . $user->login());
392 if (!Platal
::session()->startSUID($user->id())) {
393 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->id());
399 // Fetches user data.
400 $userinfo_query = "SELECT *, FIND_IN_SET('watch', flags) AS watch, FIND_IN_SET('femme', flags) AS sexe,
401 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
403 WHERE user_id = {?}";
404 $mr = XDB
::query($userinfo_query, $user->id())->fetchOneAssoc();
405 $redirect = ($registered ?
new Redirect($user) : null
);
407 // Processes admin requests, if any.
408 foreach($_POST as $key => $val) {
409 S
::assert_xsrf_token();
412 // Email redirection actions.
414 $email = trim(Env
::v('email'));
415 if (!isvalid_email_redirection($email)) {
416 $page->trigError("Email non valide: $email");
418 $redirect->add_email($email);
419 $page->trigSuccess("Ajout de $email effectué");
425 $redirect->delete_email($val);
431 $redirect->modify_one_email($val, true
);
434 case "deactivate_fwd":
436 $redirect->modify_one_email($val, false
);
440 $redirect->disable();
447 $redirect->clean_errors($val);
455 // Splits new alias in user and fqdn.
456 $alias = trim(Env
::v('email'));
457 if (strpos($alias, '@') !== false
) {
458 list($alias, $domain) = explode('@', $alias);
460 $domain = $globals->mail
->domain
;
463 // Checks for alias' user validity.
464 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
465 $page->trigError("'$alias' n'est pas un alias valide");
468 // Eventually adds the alias to the right domain.
469 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
470 $req = new AliasReq($user, $alias, 'Admin request', false
);
471 if ($req->commit()) {
472 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
474 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
476 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
477 $res = XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
478 $user->id(), $alias);
480 $page->trigSuccess("Nouvel alias '$alias' ajouté");
482 $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué");
485 $page->trigError("Le domaine '$domain' n'est pas valide");
491 XDB
::execute("DELETE FROM aliases
492 WHERE id = {?} AND alias = {?} AND
493 type NOT IN ('a_vie', 'homonyme')",
495 XDB
::execute("UPDATE emails
497 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
499 fix_bestalias($user);
500 $page->trigSuccess("L'alias '$val' a été supprimé");
505 XDB
::execute("UPDATE aliases
506 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
507 WHERE id = {?}", $user->id());
508 XDB
::execute("UPDATE aliases
509 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
510 WHERE id = {?} AND alias = {?}", $user->id(), $val);
512 // As having a non-null bestalias value is critical in
513 // plat/al's code, we do an a posteriori check on the
514 // validity of the bestalias.
515 fix_bestalias($user);
520 // Loads new values from environment.
521 require_once('secure_hash.inc.php');
522 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
hash_encrypt(Env
::v('newpass_clair')) : Env
::v('passw');
523 $naiss = Env
::v('naissanceN');
524 $deces = Env
::v('decesN');
525 $perms = Env
::v('permsN');
526 $prenom = Env
::v('prenomN');
527 $nom = Env
::v('nomN');
528 $nomusage = Env
::v('nomusageN');
529 $promo = Env
::i('promoN');
530 $sexe = Env
::v('sexeN');
531 $comm = trim(Env
::v('commentN'));
532 $watch = Env
::v('watchN');
534 $flags = ($sexe ?
'femme' : '');
536 $flags .= ($flags ?
',watch' : 'watch');
538 if ($watch && !$comm) {
539 $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte");
543 // Fetches fields to watch for changes.
544 $watch_query = "SELECT naissance, deces, password, perms, nom_usage,
545 prenom, nom, flags, promo, comment
547 WHERE user_id = {?}";
548 $old_fields = XDB
::query($watch_query, $user->id())->fetchOneAssoc();
550 // If user was newly banned, we need to ensure her php session
551 // is killed. This hack is ugly (and largely overkill); it should
552 // however suits our needs.
553 if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') {
557 // Updates the user profile with the new values.
558 $res = XDB
::execute("UPDATE auth_user_md5
559 SET naissance = {?}, deces = {?}, password = {?},
560 perms = {?}, prenom = {?}, nom = {?}, nom_usage = {?},
561 flags = {?}, promo = {?}, comment = {?}
562 WHERE user_id = {?}",
563 $naiss, $deces, $pass_encrypted,
564 $perms, $prenom, $nom, $nomusage,
565 $flags, $promo, $comm, $user->id());
567 require_once("user.func.inc.php");
568 user_reindex($user->id());
569 $new_fields = XDB
::query($watch_query, $user->id())->fetchOneAssoc();
571 $mailer = new PlMailer("admin/useredit.mail.tpl");
572 $mailer->assign("admin", S
::user()->login());
573 $mailer->assign("user", $user->login());
574 $mailer->assign('old', $old_fields);
575 $mailer->assign('new', $new_fields);
578 $globals->updateNbIns();
579 $page->trigSuccess("Update was successful.");
581 $page->trigError("Update failed, please double check your values.");
584 // Checks for changes, and updates other tables of plat/al.
585 if (Env
::v('nomusageN') != $mr['nom_usage']) {
586 set_new_usage($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($user->id(), WATCH_DEATH
, $mr['deces']);
591 user_clear_all_subs($user->id(), false
);
594 // Eventually updates the Google Apps account.
595 if ($globals->mailstorage
->googleapps_domain
) {
596 // If the user did choose to use synchronized passwords,
597 // and the password was changed, updates the Google Apps
599 if (Env
::v('newpass_clair') != "********") {
600 require_once 'googleapps.inc.php';
601 $account = new GoogleAppsAccount($user);
602 if ($account->active() && $account->sync_password
) {
603 $account->set_password($pass_encrypted);
607 // If the update did disable the user account, disables
608 // the Google Apps account as well.
609 if ($new_fields['perms'] == 'disabled' && $new_fields['perms'] != $old_fields['perms']) {
610 require_once 'googleapps.inc.php';
611 $account = new GoogleAppsAccount($user);
617 // Reloads the user profile, to ensure the latest version will
618 // be served to the administrator.
619 $mr = XDB
::query($userinfo_query, $user->id())->fetchOneAssoc();
623 // User re-registration.
625 user_clear_all_subs($user->id());
626 $globals->updateNbIns();
627 $page->trigSuccess("'" . $user->id() . "' a été désinscrit !");
629 $mailer = new PlMailer("admin/useredit.mail.tpl");
630 $mailer->assign("admin", S
::user()->login());
631 $mailer->assign("user", $user->login());
632 $mailer->assign("deletion", true
);
638 XDB
::execute("DELETE FROM forums.innd WHERE uid = {?}", $user->id());
639 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
640 XDB
::execute("INSERT INTO forums.innd
641 SET ipmin = '0', ipmax = '4294967295',
642 write_perm = {?}, read_perm = {?},
643 comment = {?}, priority = '200', uid = {?}",
644 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $user->id());
650 // Displays last login and last host information.
651 $res = XDB
::query("SELECT start, host
653 WHERE uid = {?} AND suid = 0
655 LIMIT 1", $user->id());
656 list($lastlogin,$host) = $res->fetchOneRow();
657 $page->assign('lastlogin', $lastlogin);
658 $page->assign('host', $host);
660 // Display active aliases.
661 $page->assign('virtuals', XDB
::iterator(
664 INNER JOIN virtual_redirect USING (vid)
665 WHERE type = 'user' AND redirect LIKE CONCAT({?}, '@%')", $user->id()));
667 $page->assign('aliases', XDB
::iterator(
668 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
670 WHERE id = {?} AND type != 'homonyme'
671 ORDER BY type != 'a_vie'", $user->id()));
673 // Displays email redirection and the general profile.
674 if ($registered && $redirect) {
675 $page->assign('emails', $redirect->emails
);
678 $page->assign('mr', $mr);
679 $page->assign('user', $user);
681 // Displays forum bans.
682 $res = XDB
::query("SELECT write_perm, read_perm, comment
684 WHERE uid = {?}", $user->id());
685 $bans = $res->fetchOneAssoc();
686 $page->assign('bans', $bans);
689 function getHruid($line, $key)
692 if (!isset($line['nom']) ||
!isset($line['prenom']) ||
!isset($line['promo'])) {
695 return make_forlife($line['prenom'], $line['nom'], $line['promo']);
698 function getMatricule($line, $key)
700 $mat = $line['matricule'];
701 $year = intval(substr($mat, 0, 3));
702 $rang = intval(substr($mat, 3, 3));
703 if ($year > 200) { $year /= 10; };
707 return sprintf('%04u%04u', 1900+
$year, $rang);
711 function handler_promo(&$page, $action = null
, $promo = null
)
713 if (Env
::has('promo')) {
714 if(Env
::i('promo') > 1900 && Env
::i('promo') < 2050) {
715 $action = Env
::v('valid_promo') == 'Ajouter des membres' ?
'add' : 'ax';
716 pl_redirect('admin/promo/' . $action . '/' . Env
::i('promo'));
718 $page->trigError('Promo non valide');
722 $page->changeTpl('admin/promo.tpl');
723 if ($promo > 1900 && $promo < 2050 && ($action == 'add' ||
$action == 'ax')) {
724 $page->assign('promo', $promo);
729 $importer = new CSVImporter('auth_user_md5', 'matricule');
730 $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule'));
733 $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini',
734 'prenom_ini', 'promo', 'promo_sortie', 'flags',
735 'matricule', 'matricule_ax', 'perms');
736 $importer->forceValue('hruid', array($this, 'getHruid'));
737 $importer->forceValue('promo', $promo);
738 $importer->forceValue('promo_sortie', $promo +
3);
741 $fields = array('matricule', 'matricule_ax');
744 $importer->apply($page, "admin/promo/$action/$promo", $fields);
747 function handler_homonyms(&$page, $op = 'list', $target = null
)
749 $page->changeTpl('admin/homonymes.tpl');
750 $page->setTitle('Administration - Homonymes');
751 require_once("homonymes.inc.php");
754 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
757 $page->assign('nom',$nom);
758 $page->assign('prenom',$prenom);
759 $page->assign('forlife',$forlife);
760 $page->assign('loginbis',$loginbis);
764 $page->assign('op', $op);
765 $page->assign('target', $target);
767 // on a un $target valide, on prepare les mails
769 // on examine l'op a effectuer
772 S
::assert_xsrf_token();
774 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
775 switch_bestalias($target, $loginbis);
777 $page->trigSuccess('Email envoyé à ' . $forlife . '.');
781 S
::assert_xsrf_token();
783 switch_bestalias($target, $loginbis);
784 XDB
::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
785 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
786 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
788 $page->trigSuccess('Email envoyé à ' . $forlife . ', alias supprimé.');
794 $res = XDB
::iterator(
795 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
797 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
798 IF(h.homonyme_id=s.id, a.type, NULL) AS type
800 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
801 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
802 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
803 WHERE a.type='homonyme' OR a.expire!=''
804 ORDER BY a.alias,promo");
806 while ($tab = $res->next()) {
807 $hnymes[$tab['homonyme']][] = $tab;
809 $page->assign_by_ref('hnymes',$hnymes);
813 function handler_ax_xorg(&$page) {
814 $page->changeTpl('admin/ax-xorg.tpl');
815 $page->setTitle('Administration - AX/X.org');
817 // liste des différences
819 '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
820 FROM auth_user_md5 AS u
821 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
822 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
823 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
824 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
825 ORDER BY u.promo,u.nom,u.prenom');
826 $page->assign('diffs', $res->fetchAllAssoc());
828 // gens à l'ax mais pas chez nous
830 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
831 FROM identification_ax as ia
832 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
833 WHERE u.nom IS NULL');
834 $page->assign('mank', $res->fetchAllAssoc());
836 // gens chez nous et pas à l'ax
837 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
838 $page->assign('plus', $res->fetchAllAssoc());
841 function handler_deaths(&$page, $promo = 0, $validate = false
) {
842 $page->changeTpl('admin/deces_promo.tpl');
843 $page->setTitle('Administration - Deces');
846 $promo = Env
::i('promo');
847 if (Env
::has('sub10')) $promo -= 10;
848 if (Env
::has('sub01')) $promo -= 1;
849 if (Env
::has('add01')) $promo +
= 1;
850 if (Env
::has('add10')) $promo +
= 10;
852 $page->assign('promo',$promo);
855 S
::assert_xsrf_token();
857 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
858 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
860 if($val == $deces ||
empty($val)) {
864 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
865 $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.');
866 if($deces == '0000-00-00' ||
empty($deces)) {
867 require_once('notifs.inc.php');
868 register_watch_op($uid, WATCH_DEATH
, $val);
869 require_once('user.func.inc.php');
870 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
875 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
876 $page->assign('decedes', $res);
879 function handler_dead_but_active(&$page) {
880 $page->changeTpl('admin/dead_but_active.tpl');
881 $page->setTitle('Administration - Décédés');
883 $res = XDB
::iterator(
884 "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, u.hruid, DATE(MAX(s.start)) AS last
885 FROM auth_user_md5 AS u
886 LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0)
887 WHERE perms IN ('admin', 'user') AND deces <> 0
889 ORDER BY u.promo, u.nom");
890 $page->assign('dead', $res);
893 function handler_synchro_ax(&$page, $login = null
, $action = null
) {
894 $page->changeTpl('admin/synchro_ax.tpl');
895 $page->setTitle('Administration - Synchro AX');
897 // Checks for synchronization requirements.
898 require_once('synchro_ax.inc.php');
899 if (is_ax_key_missing()) {
900 $page->assign('no_private_key', true
);
904 // Determines user identity using environment.
906 $user = User
::get($login);
907 } else if (Env
::has('user')) {
908 $user = User
::get(Env
::v('user'));
909 } else if (Env
::has('mat')) {
910 $res = XDB
::query("SELECT user_id FROM auth_user_md5 WHERE matricule = {?}", Env
::i('mat'));
911 $user = User
::get($res->fetchOneCell());
916 // Finally synchronizes the AX and plat/al information.
917 if ($action == 'import') {
918 ax_synchronize($user->login(), S
::v('uid'));
921 require_once 'profil.func.inc.php';
922 $userxorg = get_user_details($user->login(), S
::v('uid'), 'ax');
923 $userax = get_user_ax($userxorg['matricule_ax']);
924 $diff = diff_user_details($userax, $userxorg, 'ax');
926 $page->assign('x', $userxorg);
927 $page->assign('diff', $diff);
930 function handler_validate(&$page, $action = 'list', $id = null
)
932 $page->changeTpl('admin/valider.tpl');
933 $page->setTitle('Administration - Valider une demande');
934 $page->addCssLink('nl.css');
935 $page->addJsLink('ajax.js');
936 require_once("validations.inc.php");
939 if ($action == 'edit' and !is_null($id)) {
940 $page->assign('preview_id', $id);
943 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
944 S
::assert_xsrf_token();
946 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
948 $req->handle_formu();
950 $page->trigWarning('La validation a déjà été effectuée.');
954 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
955 while (($a = $r->next()) && $a['Field'] != 'category');
956 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
959 $res = XDB
::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S
::v('uid'));
960 $hide_requests = $res->fetchOneCell();
961 if (Post
::has('hide')) {
963 foreach ($categories as $cat)
964 if (!Post
::v($cat)) {
968 $hide_requests = join(',', $hide);
969 XDB
::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
970 S
::v('uid'), $hide_requests);
971 } elseif ($hide_requests) {
972 foreach (explode(',', $hide_requests) as $hide_type)
973 $hidden[$hide_type] = true
;
975 $page->assign('hide_requests', $hidden);
977 // Update the count of item to validate here... useful in development configuration
978 // where several copies of the site use the same DB, but not the same "dynamic configuration"
980 $globals->updateNbValid();
981 $page->assign('vit', new ValidateIterator());
984 function handler_validate_answers(&$page, $action = 'list', $id = null
) {
985 $page->setTitle('Administration - Réponses automatiques de validation');
986 $page->assign('title', 'Gestion des réponses automatiques');
987 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
988 $table_editor->describe('category','catégorie',true
);
989 $table_editor->describe('title','titre',true
);
990 $table_editor->describe('answer','texte',false
);
991 $table_editor->apply($page, $action, $id);
993 function handler_skins(&$page, $action = 'list', $id = null
) {
994 $page->setTitle('Administration - Skins');
995 $page->assign('title', 'Gestion des skins');
996 $table_editor = new PLTableEditor('admin/skins','skins','id');
997 $table_editor->describe('name','nom',true
);
998 $table_editor->describe('skin_tpl','nom du template',true
);
999 $table_editor->describe('auteur','auteur',false
);
1000 $table_editor->describe('comment','commentaire',true
);
1001 $table_editor->describe('date','date',false
);
1002 $table_editor->describe('ext','extension du screenshot',false
);
1003 $table_editor->apply($page, $action, $id);
1006 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
) {
1007 $page->setTitle('Administration - Postfix : Blacklist');
1008 $page->assign('title', 'Blacklist de postfix');
1009 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
1010 $table_editor->describe('reject_text','Texte de rejet',true
);
1011 $table_editor->describe('email','email',true
);
1012 $table_editor->apply($page, $action, $id);
1014 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
) {
1015 $page->setTitle('Administration - Postfix : Whitelist');
1016 $page->assign('title', 'Whitelist de postfix');
1017 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
1018 $table_editor->describe('email','email',true
);
1019 $table_editor->apply($page, $action, $id);
1021 function handler_mx_broken(&$page, $action = 'list', $id = null
) {
1022 $page->setTitle('Administration - MX Défaillants');
1023 $page->assign('title', 'MX Défaillant');
1024 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
1025 $table_editor->describe('host', 'Masque', true
);
1026 $table_editor->describe('state', 'Niveau', true
);
1027 $table_editor->describe('text', 'Description du problème', false
);
1028 $table_editor->apply($page, $action, $id);
1030 function handler_logger_actions(&$page, $action = 'list', $id = null
) {
1031 $page->setTitle('Administration - Actions');
1032 $page->assign('title', 'Gestion des actions de logger');
1033 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
1034 $table_editor->describe('text','intitulé',true
);
1035 $table_editor->describe('description','description',true
);
1036 $table_editor->apply($page, $action, $id);
1038 function handler_downtime(&$page, $action = 'list', $id = null
) {
1039 $page->setTitle('Administration - Coupures');
1040 $page->assign('title', 'Gestion des coupures');
1041 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
1042 $table_editor->describe('debut','date',true
);
1043 $table_editor->describe('duree','durée',false
);
1044 $table_editor->describe('resume','résumé',true
);
1045 $table_editor->describe('services','services affectés',true
);
1046 $table_editor->describe('description','description',false
);
1047 $table_editor->apply($page, $action, $id);
1050 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
1052 if (S
::v('core_rss_hash')) {
1053 $page->setRssLink('Changement Récents',
1054 '/Site/AllRecentChanges?action=rss&user=' . S
::v('hruid') . '&hash=' . S
::v('core_rss_hash'));
1057 // update wiki perms
1058 if ($action == 'update') {
1059 S
::assert_xsrf_token();
1061 $perms_read = Post
::v('read');
1062 $perms_edit = Post
::v('edit');
1063 if ($perms_read ||
$perms_edit) {
1064 foreach ($_POST as $wiki_page => $val) {
1066 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1067 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1068 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1069 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1071 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1076 } else if ($action != 'list' && !empty($wikipage)) {
1077 $wp = new PlWikiPage($wikipage);
1078 S
::assert_xsrf_token();
1080 if ($action == 'delete') {
1081 if ($wp->delete()) {
1082 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1084 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1086 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1087 if ($changedLinks = $wp->rename($wikipage2)) {
1088 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1089 if (is_numeric($changedLinks)) {
1090 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1092 $page->trigSuccess($s);
1094 $page->trigError("Impossible de déplacer la page ".$wikipage);
1099 $perms = PlWikiPage
::permOptions();
1101 // list wiki pages and their perms
1102 $wiki_pages = PlWikiPage
::listPages();
1104 $wiki_tree = array();
1105 foreach ($wiki_pages as $file => $desc) {
1106 list($cat, $name) = explode('.', $file);
1107 if (!isset($wiki_tree[$cat])) {
1108 $wiki_tree[$cat] = array();
1110 $wiki_tree[$cat][$name] = $desc;
1113 $page->changeTpl('admin/wiki.tpl');
1114 $page->addJsLink('jquery.js');
1115 $page->assign('wiki_pages', $wiki_tree);
1116 $page->assign('perms_opts', $perms);
1119 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1121 $page->changeTpl('admin/ipwatcher.tpl');
1123 $states = array('safe' => 'Ne pas surveiller',
1124 'unsafe' => 'Surveiller les inscriptions',
1125 'dangerous' => 'Surveiller tous les accès',
1126 'ban' => 'Bannir cette adresse');
1127 $page->assign('states', $states);
1129 switch (Post
::v('action')) {
1131 if (trim(Post
::v('ipN')) != '') {
1132 S
::assert_xsrf_token();
1133 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1134 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1135 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1136 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1141 S
::assert_xsrf_token();
1142 Xdb
::execute('UPDATE ip_watch
1143 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1144 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1145 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1149 if ($action == 'delete' && !is_null($ip)) {
1150 S
::assert_xsrf_token();
1151 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1154 if ($action != 'create' && $action != 'edit') {
1157 $page->assign('action', $action);
1159 if ($action == 'list') {
1160 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1161 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1162 IF(w.ip = s.ip, s.host, s.forward_host)),
1163 w.mask, w.detection, w.state, u.hruid
1165 LEFT JOIN logger.sessions AS s ON (s.ip = w.ip)
1166 LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip)
1167 LEFT JOIN auth_user_md5 AS u ON (u.user_id = s.uid)
1168 GROUP BY w.ip, u.hruid
1169 ORDER BY w.state, w.ip, u.hruid";
1170 $it = Xdb
::iterRow($sql);
1174 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1175 $ip = uint_to_ip($ip);
1176 $mask = uint_to_ip($mask);
1177 if (count($props) == 0 ||
$props['ip'] != $ip) {
1178 if (count($props) > 0) {
1181 $props = array('ip' => $ip,
1184 'detection' => $date,
1186 'users' => array($hruid));
1188 $props['users'][] = $hruid;
1191 if (count($props) > 0) {
1194 $page->assign('table', $table);
1195 } elseif ($action == 'edit') {
1196 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1197 u1.hruid AS edit, u2.hruid AS hruid, s.host
1199 LEFT JOIN auth_user_md5 AS u1 ON (u1.user_id = w.uid)
1200 LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
1201 LEFT JOIN auth_user_md5 AS u2 ON (u2.user_id = s.uid)
1205 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1208 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1209 if (count($props) == 0) {
1210 $props = array('ip' => $ip,
1211 'mask' => uint_to_ip($mask),
1213 'detection' => $detection,
1216 'description' => $description,
1218 'users' => array($hruid));
1220 $props['users'][] = $hruid;
1223 $page->assign('ip', $props);
1227 function handler_icons(&$page)
1229 $page->changeTpl('admin/icons.tpl');
1230 $dh = opendir('../htdocs/images/icons');
1232 $page->trigError('Dossier des icones introuvables.');
1235 while (($file = readdir($dh)) !== false
) {
1236 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1237 array_push($icons, substr($file, 0, -4));
1241 $page->assign('icons', $icons);
1244 function handler_accounts(&$page)
1246 $page->changeTpl('admin/accounts.tpl');
1247 $page->assign('disabled', XDB
::iterator('SELECT u.nom, u.prenom, u.promo, u.comment, u.hruid
1248 FROM auth_user_md5 AS u
1249 WHERE perms = \'disabled\'
1250 ORDER BY nom, prenom'));
1251 $page->assign('admins', XDB
::iterator('SELECT u.nom, u.prenom, u.promo, u.hruid
1252 FROM auth_user_md5 AS u
1253 WHERE perms = \'admin\'
1254 ORDER BY nom, prenom'));
1258 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: