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 'get_rights' => $this->make_hook('get_rights', AUTH_MDP
, 'admin'),
29 'admin' => $this->make_hook('default', AUTH_MDP
, 'admin'),
30 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP
, 'admin'),
31 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP
, 'admin'),
32 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP
, 'admin'),
33 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP
, 'admin'),
34 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP
, 'admin'),
35 'admin/logger' => $this->make_hook('logger', AUTH_MDP
, 'admin'),
36 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP
, 'admin'),
37 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP
, 'admin'),
38 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP
, 'admin'),
39 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP
, 'admin'),
40 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP
, 'admin'),
41 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP
, 'admin'),
42 'admin/skins' => $this->make_hook('skins', AUTH_MDP
, 'admin'),
43 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP
, 'admin'),
44 'admin/user' => $this->make_hook('user', AUTH_MDP
, 'admin'),
45 'admin/promo' => $this->make_hook('promo', AUTH_MDP
, 'admin'),
46 'admin/validate' => $this->make_hook('validate', AUTH_MDP
, 'admin'),
47 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP
, 'admin'),
48 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP
, 'admin'),
49 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP
, 'admin'),
50 'admin/icons' => $this->make_hook('icons', AUTH_MDP
, 'admin'),
51 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP
, 'admin'),
55 function handler_phpinfo(&$page)
61 function handler_get_rights(&$page, $level)
64 $page->kill('Déjà en SUID');
67 Platal
::session()->startSUID($user, $level);
72 function handler_default(&$page)
74 $page->changeTpl('admin/index.tpl');
75 $page->setTitle('Administration');
78 function handler_postfix_delayed(&$page)
80 $page->changeTpl('admin/postfix_delayed.tpl');
81 $page->setTitle('Administration - Postfix : Retardés');
83 if (Env
::has('del')) {
85 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
86 $page->trigSuccess($crc." verra tous ses emails supprimés !");
87 } elseif (Env
::has('ok')) {
89 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
90 $page->trigSuccess($crc." a le droit de passer !");
94 "SELECT crc, nb, update_time, create_time,
95 FIND_IN_SET('del', release) AS del,
96 FIND_IN_SET('ok', release) AS ok
99 ORDER BY release != ''");
101 $page->assign_by_ref('mails', $sql);
104 function handler_postfix_regexpsbounces(&$page, $new = null
) {
105 $page->changeTpl('admin/emails_bounces_re.tpl');
106 $page->setTitle('Administration - Postfix : Regexps Bounces');
107 $page->assign('new', $new);
109 if (Post
::has('submit')) {
110 foreach (Env
::v('lvl') as $id=>$val) {
112 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
113 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
118 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
123 /** Retrieves the available days for a given year and month.
124 * Obtain a list of days of the given month in the given year
125 * that are within the range of dates that we have log entries for.
127 * @param integer year
128 * @param integer month
129 * @return array days in that month we have log entries covering.
132 function _getDays($year, $month)
134 // give a 'no filter' option
137 if ($year && $month) {
138 $day_max = Array(-1, 31, checkdate(2, 29, $year) ?
29 : 28 , 31,
139 30, 31, 30, 31, 31, 30, 31, 30, 31);
140 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
141 MONTH(MAX(start)), MONTH(MIN(start)),
142 DAYOFMONTH(MAX(start)),
143 DAYOFMONTH(MIN(start))
144 FROM logger.sessions");
145 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
147 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
151 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
155 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
156 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
158 for($i = $min; $i<=$max; $i++
) {
166 /** Retrieves the available months for a given year.
167 * Obtains a list of month numbers that are within the timeframe that
168 * we have log entries for.
170 * @param integer year
171 * @return array List of month numbers we have log info for.
174 function _getMonths($year)
176 // give a 'no filter' option
180 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
181 MONTH(MAX(start)), MONTH(MIN(start))
182 FROM logger.sessions");
183 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
185 if (($year < $ymin) ||
($year > $ymax)) {
189 $min = $year == $ymin ?
intval($mmin) : 1;
190 $max = $year == $ymax ?
intval($mmax) : 12;
192 for($i = $min; $i<=$max; $i++
) {
200 /** Retrieves the available years.
201 * Obtains a list of years that we have log entries covering.
203 * @return array years we have log entries for.
208 // give a 'no filter' option
211 // retrieve available years
212 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions");
213 list($max, $min) = $res->fetchOneRow();
215 for($i = intval($min); $i<=$max; $i++
) {
222 /** Make a where clause to get a user's sessions.
223 * Prepare the where clause request that will retrieve the sessions.
225 * @param $year INTEGER Only get log entries made during the given year.
226 * @param $month INTEGER Only get log entries made during the given month.
227 * @param $day INTEGER Only get log entries made during the given day.
228 * @param $uid INTEGER Only get log entries referring to the given user ID.
230 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
233 function _makeWhere($year, $month, $day, $uid)
235 // start constructing the "where" clause
239 array_push($where, "uid='$uid'");
241 // we were given at least a year
244 $dmin = mktime(0, 0, 0, $month, $day, $year);
245 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
247 $dmin = mktime(0, 0, 0, $month, 1, $year);
248 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
250 $dmin = mktime(0, 0, 0, 1, 1, $year);
251 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
253 $where[] = "start >= " . date("Ymd000000", $dmin);
254 $where[] = "start < " . date("Ymd000000", $dmax);
257 if (!empty($where)) {
258 return ' WHERE ' . implode($where, " AND ");
262 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
267 function handler_logger(&$page, $action = null
, $arg = null
) {
268 if ($action == 'session') {
270 // we are viewing a session
271 $res = XDB
::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
272 FROM logger.sessions AS ls
273 LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie')
274 LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie')
275 WHERE ls.id = {?}", $arg);
277 $page->assign('session', $a = $res->fetchOneAssoc());
279 $res = XDB
::iterator('SELECT a.text, e.data, e.stamp
280 FROM logger.events AS e
281 LEFT JOIN logger.actions AS a ON e.action=a.id
282 WHERE e.session={?}', $arg);
283 while ($myarr = $res->next()) {
284 $page->append('events', $myarr);
288 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
290 $res = XDB
::query('SELECT id FROM aliases WHERE alias={?}',
292 $loguid = $res->fetchOneCell();
295 $year = Env
::i('year');
296 $month = Env
::i('month');
297 $day = Env
::i('day');
299 $year = Env
::i('year', intval(date('Y')));
300 $month = Env
::i('month', intval(date('m')));
301 $day = Env
::i('day', intval(date('d')));
309 // smarty assignments
310 // retrieve available years
311 $page->assign('years', $this->_getYears());
312 $page->assign('year', $year);
314 // retrieve available months for the current year
315 $page->assign('months', $this->_getMonths($year));
316 $page->assign('month', $month);
318 // retrieve available days for the current year and month
319 $page->assign('days', $this->_getDays($year, $month));
320 $page->assign('day', $day);
322 $page->assign('loguser', $loguser);
323 // smarty assignments
325 if ($loguid ||
$year) {
327 // get the requested sessions
328 $where = $this->_makeWhere($year, $month, $day, $loguid);
329 $select = "SELECT s.id, s.start, s.uid,
331 FROM logger.sessions AS s
332 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie')
334 ORDER BY start DESC";
335 $res = XDB
::iterator($select);
338 while ($mysess = $res->next()) {
339 $mysess['events'] = array();
340 $sessions[$mysess['id']] = $mysess;
342 array_reverse($sessions);
345 $sql = "SELECT s.id, a.text
346 FROM logger.sessions AS s
347 LEFT JOIN logger.events AS e ON(e.session=s.id)
348 INNER JOIN logger.actions AS a ON(a.id=e.action)
351 $res = XDB
::iterator($sql);
352 while ($event = $res->next()) {
353 array_push($sessions[$event['id']]['events'], $event['text']);
355 $page->assign_by_ref('sessions', $sessions);
357 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
361 $page->changeTpl('admin/logger-view.tpl');
363 $page->setTitle('Administration - Logs des sessions');
366 function handler_user(&$page, $login = false
)
369 $page->changeTpl('admin/utilisateurs.tpl');
370 $page->setTitle('Administration - Edit/Su/Log');
371 require_once("emails.inc.php");
374 $page->kill("Déjà en SUID !!!");
377 // Loads the user identity using the environment.
379 $user = User
::get($login);
380 } else if (Env
::has('user_id')) {
381 $user = User
::get(Env
::i('user_id'));
382 } else if (Env
::has('login')) {
383 $user = User
::get(Env
::v('login'));
387 $login = $user->login();
388 $registered = ($user->forlifeEmail() != null
);
393 // Handles specific requests (AX sync, su, ...).
394 if(Env
::has('logs_button') && $registered) {
395 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
398 if (Env
::has('ax_button') && $registered) {
399 pl_redirect("admin/synchro_ax/" . $user->login());
402 if(Env
::has('suid_button') && $registered) {
403 if (!Platal
::session()->startSUID($user)) {
404 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->id());
410 // Fetches user data.
411 $userinfo_query = "SELECT *, FIND_IN_SET('watch', flags) AS watch, FIND_IN_SET('femme', flags) AS sexe,
412 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
414 WHERE user_id = {?}";
415 $mr = XDB
::query($userinfo_query, $user->id())->fetchOneAssoc();
416 $redirect = ($registered ?
new Redirect($user) : null
);
418 // Processes admin requests, if any.
419 foreach($_POST as $key => $val) {
420 S
::assert_xsrf_token();
423 // Email redirection actions.
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 $redirect->modify_one_email($val, true
);
445 case "deactivate_fwd":
447 $redirect->modify_one_email($val, false
);
451 $redirect->disable();
458 $redirect->clean_errors($val);
466 // Splits new alias in user and fqdn.
467 $alias = trim(Env
::v('email'));
468 if (strpos($alias, '@') !== false
) {
469 list($alias, $domain) = explode('@', $alias);
471 $domain = $globals->mail
->domain
;
474 // Checks for alias' user validity.
475 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
476 $page->trigError("'$alias' n'est pas un alias valide");
479 // Eventually adds the alias to the right domain.
480 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
481 $req = new AliasReq($user, $alias, 'Admin request', false
);
482 if ($req->commit()) {
483 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
485 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
487 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
488 $res = XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
489 $user->id(), $alias);
491 $page->trigSuccess("Nouvel alias '$alias' ajouté");
493 $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué");
496 $page->trigError("Le domaine '$domain' n'est pas valide");
502 XDB
::execute("DELETE FROM aliases
503 WHERE id = {?} AND alias = {?} AND
504 type NOT IN ('a_vie', 'homonyme')",
506 XDB
::execute("UPDATE emails
508 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
510 fix_bestalias($user);
511 $page->trigSuccess("L'alias '$val' a été supprimé");
516 XDB
::execute("UPDATE aliases
517 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
518 WHERE id = {?}", $user->id());
519 XDB
::execute("UPDATE aliases
520 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
521 WHERE id = {?} AND alias = {?}", $user->id(), $val);
523 // As having a non-null bestalias value is critical in
524 // plat/al's code, we do an a posteriori check on the
525 // validity of the bestalias.
526 fix_bestalias($user);
531 // Loads new values from environment.
532 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
sha1(Env
::v('newpass_clair')) : Env
::v('passw');
533 $naiss = Env
::v('naissanceN');
534 $deces = Env
::v('decesN');
535 $perms = Env
::v('permsN');
536 $prenom = Env
::v('prenomN');
537 $nom = Env
::v('nomN');
538 $nomusage = Env
::v('nomusageN');
539 $promo = Env
::i('promoN');
540 $sexe = Env
::v('sexeN');
541 $comm = trim(Env
::v('commentN'));
542 $watch = Env
::v('watchN');
544 $flags = ($sexe ?
'femme' : '');
546 $flags .= ($flags ?
',watch' : 'watch');
548 if ($watch && !$comm) {
549 $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte");
553 // Fetches fields to watch for changes.
554 $watch_query = "SELECT naissance, deces, password, perms, nom_usage,
555 prenom, nom, flags, promo, comment
557 WHERE user_id = {?}";
558 $old_fields = XDB
::query($watch_query, $user->id())->fetchOneAssoc();
560 // If user was newly banned, we need to ensure her php session
561 // is killed. This hack is ugly (and largely overkill); it should
562 // however suits our needs.
563 if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') {
567 // Updates the user profile with the new values.
568 $res = XDB
::execute("UPDATE auth_user_md5
569 SET naissance = {?}, deces = {?}, password = {?},
570 perms = {?}, prenom = {?}, nom = {?}, nom_usage = {?},
571 flags = {?}, promo = {?}, comment = {?}
572 WHERE user_id = {?}",
573 $naiss, $deces, $pass_encrypted,
574 $perms, $prenom, $nom, $nomusage,
575 $flags, $promo, $comm, $user->id());
577 require_once("user.func.inc.php");
578 user_reindex($user->id());
579 $new_fields = XDB
::query($watch_query, $user->id())->fetchOneAssoc();
581 $mailer = new PlMailer("admin/useredit.mail.tpl");
582 $mailer->assign("admin", S
::user()->login());
583 $mailer->assign("user", $user->login());
584 $mailer->assign('old', $old_fields);
585 $mailer->assign('new', $new_fields);
588 $globals->updateNbIns();
589 $page->trigSuccess("Update was successful.");
591 $page->trigError("Update failed, please double check your values.");
594 // Checks for changes, and updates other tables of plat/al.
595 if (Env
::v('nomusageN') != $mr['nom_usage']) {
596 set_new_usage($user->id(), Env
::v('nomusageN'), make_username(Env
::v('prenomN'), Env
::v('nomusageN')));
598 if (Env
::v('decesN') != $mr['deces']) {
599 require_once 'notifs.inc.php';
600 register_watch_op($user->id(), WATCH_DEATH
, $mr['deces']);
601 user_clear_all_subs($user->id(), false
);
604 // Eventually updates the Google Apps account.
605 if ($globals->mailstorage
->googleapps_domain
) {
606 // If the user did choose to use synchronized passwords,
607 // and the password was changed, updates the Google Apps
609 if (Env
::v('newpass_clair') != "********") {
610 require_once 'googleapps.inc.php';
611 $account = new GoogleAppsAccount($user);
612 if ($account->active() && $account->sync_password
) {
613 $account->set_password($pass_encrypted);
617 // If the update did disable the user account, disables
618 // the Google Apps account as well.
619 if ($new_fields['perms'] == 'disabled' && $new_fields['perms'] != $old_fields['perms']) {
620 require_once 'googleapps.inc.php';
621 $account = new GoogleAppsAccount($user);
627 // Reloads the user profile, to ensure the latest version will
628 // be served to the administrator.
629 $mr = XDB
::query($userinfo_query, $user->id())->fetchOneAssoc();
633 // User re-registration.
635 user_clear_all_subs($user->id());
636 $globals->updateNbIns();
637 $page->trigSuccess("'" . $user->id() . "' a été désinscrit !");
639 $mailer = new PlMailer("admin/useredit.mail.tpl");
640 $mailer->assign("admin", S
::user()->login());
641 $mailer->assign("user", $user->login());
642 $mailer->assign("deletion", true
);
648 XDB
::execute("DELETE FROM forum_innd WHERE uid = {?}", $user->id());
649 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
650 XDB
::execute("INSERT INTO forum_innd
651 SET ipmin = '0', ipmax = '4294967295',
652 write_perm = {?}, read_perm = {?},
653 comment = {?}, priority = '200', uid = {?}",
654 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $user->id());
660 // Displays last login and last host information.
661 $res = XDB
::query("SELECT start, host
663 WHERE uid = {?} AND suid = 0
665 LIMIT 1", $user->id());
666 list($lastlogin,$host) = $res->fetchOneRow();
667 $page->assign('lastlogin', $lastlogin);
668 $page->assign('host', $host);
670 // Display active aliases.
671 $page->assign('virtuals', XDB
::iterator(
674 INNER JOIN virtual_redirect USING (vid)
675 WHERE type = 'user' AND (redirect = {?} OR redirect = {?})",
676 $user->forlifeEmail(),
677 // TODO: remove this über-ugly hack. The issue is that you need
678 // to remove all @m4x.org addresses in virtual_redirect first.
679 $user->login() . '@' . $globals->mail
->domain2
));
681 $page->assign('aliases', XDB
::iterator(
682 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
684 WHERE id = {?} AND type != 'homonyme'
685 ORDER BY type != 'a_vie'", $user->id()));
687 // Displays email redirection and the general profile.
688 if ($registered && $redirect) {
689 $page->assign('emails', $redirect->emails
);
692 $page->assign('mr', $mr);
693 $page->assign('user', $user);
695 // Displays forum bans.
696 $res = XDB
::query("SELECT write_perm, read_perm, comment
698 WHERE uid = {?}", $user->id());
699 $bans = $res->fetchOneAssoc();
700 $page->assign('bans', $bans);
703 function getHruid($line, $key)
706 if (!isset($line['nom']) ||
!isset($line['prenom']) ||
!isset($line['promo'])) {
709 return make_forlife($line['prenom'], $line['nom'], $line['promo']);
712 function getMatricule($line, $key)
714 $mat = $line['matricule'];
715 $year = intval(substr($mat, 0, 3));
716 $rang = intval(substr($mat, 3, 3));
717 if ($year > 200) { $year /= 10; };
721 return sprintf('%04u%04u', 1900+
$year, $rang);
725 function handler_promo(&$page, $action = null
, $promo = null
)
727 if (Env
::has('promo')) {
728 if(Env
::i('promo') > 1900 && Env
::i('promo') < 2050) {
729 $action = Env
::v('valid_promo') == 'Ajouter des membres' ?
'add' : 'ax';
730 pl_redirect('admin/promo/' . $action . '/' . Env
::i('promo'));
732 $page->trigError('Promotion non valide.');
736 $page->changeTpl('admin/promo.tpl');
737 if ($promo > 1900 && $promo < 2050 && ($action == 'add' ||
$action == 'ax')) {
738 $page->assign('promo', $promo);
743 $importer = new CSVImporter('auth_user_md5', 'matricule');
744 $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule'));
747 $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini',
748 'prenom_ini', 'promo', 'promo_sortie', 'flags',
749 'matricule', 'matricule_ax', 'perms');
750 $importer->forceValue('hruid', array($this, 'getHruid'));
751 $importer->forceValue('promo', $promo);
752 $importer->forceValue('promo_sortie', $promo +
3);
755 $fields = array('matricule', 'matricule_ax');
758 $importer->apply($page, "admin/promo/$action/$promo", $fields);
761 function handler_homonyms(&$page, $op = 'list', $target = null
)
763 $page->changeTpl('admin/homonymes.tpl');
764 $page->setTitle('Administration - Homonymes');
765 $this->load("homonyms.inc.php");
768 $user = User
::getSilent($target);
769 if (!$user ||
!($loginbis = select_if_homonyme($user))) {
772 $page->assign('user', $user);
773 $page->assign('loginbis',$loginbis);
777 $page->assign('op', $op);
778 $page->assign('target', $target);
780 // on a un $target valide, on prepare les mails
782 // on examine l'op a effectuer
785 S
::assert_xsrf_token();
787 send_warning_homonyme($user, $loginbis);
788 switch_bestalias($user, $loginbis);
790 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.');
794 S
::assert_xsrf_token();
796 switch_bestalias($user, $loginbis);
797 XDB
::execute("UPDATE aliases
798 SET type = 'homonyme', expire=NOW()
799 WHERE alias = {?}", $loginbis);
800 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id)
801 VALUES ({?}, {?})", $target, $target);
802 send_robot_homonyme($user, $loginbis);
804 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.');
810 $res = XDB
::iterator(
811 "SELECT a.alias AS homonyme, s.alias AS forlife,
812 IF(h.homonyme_id = s.id, a.expire, NULL) AS expire,
813 IF(h.homonyme_id = s.id, a.type, NULL) AS type,
816 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
817 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
818 INNER JOIN accounts AS ac ON (ac.uid = a.id)
819 WHERE a.type = 'homonyme' OR a.expire != ''
820 ORDER BY a.alias, forlife");
822 while ($tab = $res->next()) {
823 $hnymes[$tab['homonyme']][] = $tab;
825 $page->assign_by_ref('hnymes',$hnymes);
829 function handler_ax_xorg(&$page)
831 $page->changeTpl('admin/ax-xorg.tpl');
832 $page->setTitle('Administration - AX/X.org');
834 // liste des différences
836 'SELECT u.promo,u.nom AS nom, u.prenom AS prenom, ia.nom AS nomax,
837 ia.prenom AS prenomax, u.matricule AS mat, ia.matricule_ax AS matax
838 FROM auth_user_md5 AS u
839 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
840 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
841 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
842 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
843 ORDER BY u.promo,u.nom,u.prenom');
844 $page->assign('diffs', $res->fetchAllAssoc());
846 // gens à l'ax mais pas chez nous
848 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
849 FROM identification_ax as ia
850 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
851 WHERE u.nom IS NULL');
852 $page->assign('mank', $res->fetchAllAssoc());
854 // gens chez nous et pas à l'ax
855 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
856 $page->assign('plus', $res->fetchAllAssoc());
859 function handler_deaths(&$page, $promo = 0, $validate = false
)
861 $page->changeTpl('admin/deces_promo.tpl');
862 $page->setTitle('Administration - Deces');
865 $promo = Env
::i('promo');
866 if (Env
::has('sub10')) $promo -= 10;
867 if (Env
::has('sub01')) $promo -= 1;
868 if (Env
::has('add01')) $promo +
= 1;
869 if (Env
::has('add10')) $promo +
= 10;
871 $page->assign('promo',$promo);
874 S
::assert_xsrf_token();
876 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
877 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
879 if($val == $deces ||
empty($val)) {
883 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
884 $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.');
885 if($deces == '0000-00-00' ||
empty($deces)) {
886 require_once('notifs.inc.php');
887 register_watch_op($uid, WATCH_DEATH
, $val);
888 require_once('user.func.inc.php');
889 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
894 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
895 $page->assign('decedes', $res);
898 function handler_dead_but_active(&$page)
900 $page->changeTpl('admin/dead_but_active.tpl');
901 $page->setTitle('Administration - Décédés');
903 $res = XDB
::iterator(
904 "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, u.hruid, DATE(MAX(s.start)) AS last
905 FROM auth_user_md5 AS u
906 LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0)
907 WHERE perms IN ('admin', 'user') AND deces <> 0
909 ORDER BY u.promo, u.nom");
910 $page->assign('dead', $res);
913 function handler_synchro_ax(&$page, $login = null
, $action = null
)
915 $page->changeTpl('admin/synchro_ax.tpl');
916 $page->setTitle('Administration - Synchro AX');
918 // Checks for synchronization requirements.
919 require_once('synchro_ax.inc.php');
920 if (is_ax_key_missing()) {
921 $page->assign('no_private_key', true
);
925 // Determines user identity using environment.
927 $user = User
::get($login);
928 } else if (Env
::has('user')) {
929 $user = User
::get(Env
::v('user'));
930 } else if (Env
::has('mat')) {
931 $res = XDB
::query("SELECT user_id
933 WHERE matricule = {?}",
935 $user = User
::get($res->fetchOneCell());
940 // Finally synchronizes the AX and plat/al information.
941 if ($action == 'import') {
942 ax_synchronize($user->login(), S
::v('uid'));
945 require_once 'profil.func.inc.php';
946 $userxorg = get_user_details($user->login(), S
::v('uid'), 'ax');
947 $userax = get_user_ax($userxorg['matricule_ax']);
948 $diff = diff_user_details($userax, $userxorg, 'ax');
950 $page->assign('x', $userxorg);
951 $page->assign('diff', $diff);
954 function handler_validate(&$page, $action = 'list', $id = null
)
956 $page->changeTpl('admin/valider.tpl');
957 $page->setTitle('Administration - Valider une demande');
958 $page->addCssLink('nl.css');
959 $page->addJsLink('ajax.js');
960 require_once("validations.inc.php");
963 if ($action == 'edit' and !is_null($id)) {
964 $page->assign('preview_id', $id);
967 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
968 S
::assert_xsrf_token();
970 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
972 $req->handle_formu();
974 $page->trigWarning('La validation a déjà été effectuée.');
978 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
979 while (($a = $r->next()) && $a['Field'] != 'category');
980 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
983 $res = XDB
::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S
::v('uid'));
984 $hide_requests = $res->fetchOneCell();
985 if (Post
::has('hide')) {
987 foreach ($categories as $cat)
988 if (!Post
::v($cat)) {
992 $hide_requests = join(',', $hide);
993 XDB
::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
994 S
::v('uid'), $hide_requests);
995 } elseif ($hide_requests) {
996 foreach (explode(',', $hide_requests) as $hide_type)
997 $hidden[$hide_type] = true
;
999 $page->assign('hide_requests', $hidden);
1001 // Update the count of item to validate here... useful in development configuration
1002 // where several copies of the site use the same DB, but not the same "dynamic configuration"
1004 $globals->updateNbValid();
1005 $page->assign('vit', new ValidateIterator());
1008 function handler_validate_answers(&$page, $action = 'list', $id = null
)
1010 $page->setTitle('Administration - Réponses automatiques de validation');
1011 $page->assign('title', 'Gestion des réponses automatiques');
1012 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
1013 $table_editor->describe('category','catégorie',true
);
1014 $table_editor->describe('title','titre',true
);
1015 $table_editor->describe('answer','texte',false
);
1016 $table_editor->apply($page, $action, $id);
1019 function handler_skins(&$page, $action = 'list', $id = null
)
1021 $page->setTitle('Administration - Skins');
1022 $page->assign('title', 'Gestion des skins');
1023 $table_editor = new PLTableEditor('admin/skins','skins','id');
1024 $table_editor->describe('name','nom',true
);
1025 $table_editor->describe('skin_tpl','nom du template',true
);
1026 $table_editor->describe('auteur','auteur',false
);
1027 $table_editor->describe('comment','commentaire',true
);
1028 $table_editor->describe('date','date',false
);
1029 $table_editor->describe('ext','extension du screenshot',false
);
1030 $table_editor->apply($page, $action, $id);
1033 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
)
1035 $page->setTitle('Administration - Postfix : Blacklist');
1036 $page->assign('title', 'Blacklist de postfix');
1037 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
1038 $table_editor->describe('reject_text','Texte de rejet',true
);
1039 $table_editor->describe('email','email',true
);
1040 $table_editor->apply($page, $action, $id);
1043 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
)
1045 $page->setTitle('Administration - Postfix : Whitelist');
1046 $page->assign('title', 'Whitelist de postfix');
1047 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
1048 $table_editor->describe('email','email',true
);
1049 $table_editor->apply($page, $action, $id);
1052 function handler_mx_broken(&$page, $action = 'list', $id = null
)
1054 $page->setTitle('Administration - MX Défaillants');
1055 $page->assign('title', 'MX Défaillant');
1056 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
1057 $table_editor->describe('host', 'Masque', true
);
1058 $table_editor->describe('state', 'Niveau', true
);
1059 $table_editor->describe('text', 'Description du problème', false
);
1060 $table_editor->apply($page, $action, $id);
1063 function handler_logger_actions(&$page, $action = 'list', $id = null
)
1065 $page->setTitle('Administration - Actions');
1066 $page->assign('title', 'Gestion des actions de logger');
1067 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
1068 $table_editor->describe('text','intitulé',true
);
1069 $table_editor->describe('description','description',true
);
1070 $table_editor->apply($page, $action, $id);
1073 function handler_downtime(&$page, $action = 'list', $id = null
) {
1074 $page->setTitle('Administration - Coupures');
1075 $page->assign('title', 'Gestion des coupures');
1076 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
1077 $table_editor->describe('debut','date',true
);
1078 $table_editor->describe('duree','durée',false
);
1079 $table_editor->describe('resume','résumé',true
);
1080 $table_editor->describe('services','services affectés',true
);
1081 $table_editor->describe('description','description',false
);
1082 $table_editor->apply($page, $action, $id);
1085 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
1087 if (S
::hasAuthToken()) {
1088 $page->setRssLink('Changement Récents',
1089 '/Site/AllRecentChanges?action=rss&user=' . S
::v('hruid') . '&hash=' . S
::v('token'));
1092 // update wiki perms
1093 if ($action == 'update') {
1094 S
::assert_xsrf_token();
1096 $perms_read = Post
::v('read');
1097 $perms_edit = Post
::v('edit');
1098 if ($perms_read ||
$perms_edit) {
1099 foreach ($_POST as $wiki_page => $val) {
1101 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1102 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1103 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1104 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1106 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1111 } else if ($action != 'list' && !empty($wikipage)) {
1112 $wp = new PlWikiPage($wikipage);
1113 S
::assert_xsrf_token();
1115 if ($action == 'delete') {
1116 if ($wp->delete()) {
1117 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1119 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1121 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1122 if ($changedLinks = $wp->rename($wikipage2)) {
1123 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1124 if (is_numeric($changedLinks)) {
1125 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1127 $page->trigSuccess($s);
1129 $page->trigError("Impossible de déplacer la page ".$wikipage);
1134 $perms = PlWikiPage
::permOptions();
1136 // list wiki pages and their perms
1137 $wiki_pages = PlWikiPage
::listPages();
1139 $wiki_tree = array();
1140 foreach ($wiki_pages as $file => $desc) {
1141 list($cat, $name) = explode('.', $file);
1142 if (!isset($wiki_tree[$cat])) {
1143 $wiki_tree[$cat] = array();
1145 $wiki_tree[$cat][$name] = $desc;
1148 $page->changeTpl('admin/wiki.tpl');
1149 $page->addJsLink('jquery.js');
1150 $page->assign('wiki_pages', $wiki_tree);
1151 $page->assign('perms_opts', $perms);
1154 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1156 $page->changeTpl('admin/ipwatcher.tpl');
1158 $states = array('safe' => 'Ne pas surveiller',
1159 'unsafe' => 'Surveiller les inscriptions',
1160 'dangerous' => 'Surveiller tous les accès',
1161 'ban' => 'Bannir cette adresse');
1162 $page->assign('states', $states);
1164 switch (Post
::v('action')) {
1166 if (trim(Post
::v('ipN')) != '') {
1167 S
::assert_xsrf_token();
1168 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1169 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1170 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1171 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1176 S
::assert_xsrf_token();
1177 Xdb
::execute('UPDATE ip_watch
1178 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1179 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1180 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1184 if ($action == 'delete' && !is_null($ip)) {
1185 S
::assert_xsrf_token();
1186 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1189 if ($action != 'create' && $action != 'edit') {
1192 $page->assign('action', $action);
1194 if ($action == 'list') {
1195 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1196 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1197 IF(w.ip = s.ip, s.host, s.forward_host)),
1198 w.mask, w.detection, w.state, a.hruid
1200 LEFT JOIN logger.sessions AS s ON (s.ip = w.ip)
1201 LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip)
1202 LEFT JOIN accounts AS a ON (a.uid = s.uid)
1203 GROUP BY w.ip, a.hruid
1204 ORDER BY w.state, w.ip, a.hruid";
1205 $it = Xdb
::iterRow($sql);
1209 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1210 $ip = uint_to_ip($ip);
1211 $mask = uint_to_ip($mask);
1212 if (count($props) == 0 ||
$props['ip'] != $ip) {
1213 if (count($props) > 0) {
1216 $props = array('ip' => $ip,
1219 'detection' => $date,
1221 'users' => array($hruid));
1223 $props['users'][] = $hruid;
1226 if (count($props) > 0) {
1229 $page->assign('table', $table);
1230 } elseif ($action == 'edit') {
1231 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1232 a1.hruid AS edit, a2.hruid AS hruid, s.host
1234 LEFT JOIN accounts AS a1 ON (a1.uid = w.uid)
1235 LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
1236 LEFT JOIN accounts AS a2 ON (a2.uid = s.uid)
1240 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1243 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1244 if (count($props) == 0) {
1245 $props = array('ip' => $ip,
1246 'mask' => uint_to_ip($mask),
1248 'detection' => $detection,
1251 'description' => $description,
1253 'users' => array($hruid));
1255 $props['users'][] = $hruid;
1258 $page->assign('ip', $props);
1262 function handler_icons(&$page)
1264 $page->changeTpl('admin/icons.tpl');
1265 $dh = opendir('../htdocs/images/icons');
1267 $page->trigError('Dossier des icones introuvables.');
1270 while (($file = readdir($dh)) !== false
) {
1271 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1272 array_push($icons, substr($file, 0, -4));
1276 $page->assign('icons', $icons);
1279 function handler_accounts(&$page)
1281 $page->changeTpl('admin/accounts.tpl');
1282 $page->assign('disabled', XDB
::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
1283 a.state = \'disabled\' AS disabled, a.comment
1285 WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags)
1286 ORDER BY a.hruid'));
1287 $page->assign('admins', XDB
::iterator('SELECT a.hruid
1290 ORDER BY a.hruid'));
1294 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: