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'),
52 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP
, 'admin'),
56 function handler_phpinfo(&$page)
62 function handler_get_rights(&$page, $level)
65 $page->kill('Déjà en SUID');
68 Platal
::session()->startSUID($user, $level);
73 function handler_default(&$page)
75 $page->changeTpl('admin/index.tpl');
76 $page->setTitle('Administration');
79 function handler_postfix_delayed(&$page)
81 $page->changeTpl('admin/postfix_delayed.tpl');
82 $page->setTitle('Administration - Postfix : Retardés');
84 if (Env
::has('del')) {
86 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
87 $page->trigSuccess($crc." verra tous ses emails supprimés !");
88 } elseif (Env
::has('ok')) {
90 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
91 $page->trigSuccess($crc." a le droit de passer !");
95 "SELECT crc, nb, update_time, create_time,
96 FIND_IN_SET('del', release) AS del,
97 FIND_IN_SET('ok', release) AS ok
100 ORDER BY release != ''");
102 $page->assign_by_ref('mails', $sql);
105 function handler_postfix_regexpsbounces(&$page, $new = null
) {
106 $page->changeTpl('admin/emails_bounces_re.tpl');
107 $page->setTitle('Administration - Postfix : Regexps Bounces');
108 $page->assign('new', $new);
110 if (Post
::has('submit')) {
111 foreach (Env
::v('lvl') as $id=>$val) {
113 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
114 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
119 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
124 /** Retrieves the available days for a given year and month.
125 * Obtain a list of days of the given month in the given year
126 * that are within the range of dates that we have log entries for.
128 * @param integer year
129 * @param integer month
130 * @return array days in that month we have log entries covering.
133 function _getDays($year, $month)
135 // give a 'no filter' option
138 if ($year && $month) {
139 $day_max = Array(-1, 31, checkdate(2, 29, $year) ?
29 : 28 , 31,
140 30, 31, 30, 31, 31, 30, 31, 30, 31);
141 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
142 MONTH(MAX(start)), MONTH(MIN(start)),
143 DAYOFMONTH(MAX(start)),
144 DAYOFMONTH(MIN(start))
145 FROM logger.sessions");
146 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
148 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
152 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
156 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
157 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
159 for($i = $min; $i<=$max; $i++
) {
167 /** Retrieves the available months for a given year.
168 * Obtains a list of month numbers that are within the timeframe that
169 * we have log entries for.
171 * @param integer year
172 * @return array List of month numbers we have log info for.
175 function _getMonths($year)
177 // give a 'no filter' option
181 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
182 MONTH(MAX(start)), MONTH(MIN(start))
183 FROM logger.sessions");
184 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
186 if (($year < $ymin) ||
($year > $ymax)) {
190 $min = $year == $ymin ?
intval($mmin) : 1;
191 $max = $year == $ymax ?
intval($mmax) : 12;
193 for($i = $min; $i<=$max; $i++
) {
201 /** Retrieves the available years.
202 * Obtains a list of years that we have log entries covering.
204 * @return array years we have log entries for.
209 // give a 'no filter' option
212 // retrieve available years
213 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions");
214 list($max, $min) = $res->fetchOneRow();
216 for($i = intval($min); $i<=$max; $i++
) {
223 /** Make a where clause to get a user's sessions.
224 * Prepare the where clause request that will retrieve the sessions.
226 * @param $year INTEGER Only get log entries made during the given year.
227 * @param $month INTEGER Only get log entries made during the given month.
228 * @param $day INTEGER Only get log entries made during the given day.
229 * @param $uid INTEGER Only get log entries referring to the given user ID.
231 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
234 function _makeWhere($year, $month, $day, $uid)
236 // start constructing the "where" clause
240 array_push($where, "uid='$uid'");
242 // we were given at least a year
245 $dmin = mktime(0, 0, 0, $month, $day, $year);
246 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
248 $dmin = mktime(0, 0, 0, $month, 1, $year);
249 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
251 $dmin = mktime(0, 0, 0, 1, 1, $year);
252 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
254 $where[] = "start >= " . date("Ymd000000", $dmin);
255 $where[] = "start < " . date("Ymd000000", $dmax);
258 if (!empty($where)) {
259 return ' WHERE ' . implode($where, " AND ");
263 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
268 function handler_logger(&$page, $action = null
, $arg = null
) {
269 if ($action == 'session') {
271 // we are viewing a session
272 $res = XDB
::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
273 FROM logger.sessions AS ls
274 LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie')
275 LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie')
276 WHERE ls.id = {?}", $arg);
278 $page->assign('session', $a = $res->fetchOneAssoc());
280 $res = XDB
::iterator('SELECT a.text, e.data, e.stamp
281 FROM logger.events AS e
282 LEFT JOIN logger.actions AS a ON e.action=a.id
283 WHERE e.session={?}', $arg);
284 while ($myarr = $res->next()) {
285 $page->append('events', $myarr);
289 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
291 $res = XDB
::query('SELECT id FROM aliases WHERE alias={?}',
293 $loguid = $res->fetchOneCell();
296 $year = Env
::i('year');
297 $month = Env
::i('month');
298 $day = Env
::i('day');
300 $year = Env
::i('year', intval(date('Y')));
301 $month = Env
::i('month', intval(date('m')));
302 $day = Env
::i('day', intval(date('d')));
310 // smarty assignments
311 // retrieve available years
312 $page->assign('years', $this->_getYears());
313 $page->assign('year', $year);
315 // retrieve available months for the current year
316 $page->assign('months', $this->_getMonths($year));
317 $page->assign('month', $month);
319 // retrieve available days for the current year and month
320 $page->assign('days', $this->_getDays($year, $month));
321 $page->assign('day', $day);
323 $page->assign('loguser', $loguser);
324 // smarty assignments
326 if ($loguid ||
$year) {
328 // get the requested sessions
329 $where = $this->_makeWhere($year, $month, $day, $loguid);
330 $select = "SELECT s.id, s.start, s.uid,
332 FROM logger.sessions AS s
333 LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie')
335 ORDER BY start DESC";
336 $res = XDB
::iterator($select);
339 while ($mysess = $res->next()) {
340 $mysess['events'] = array();
341 $sessions[$mysess['id']] = $mysess;
343 array_reverse($sessions);
346 $sql = "SELECT s.id, a.text
347 FROM logger.sessions AS s
348 LEFT JOIN logger.events AS e ON(e.session=s.id)
349 INNER JOIN logger.actions AS a ON(a.id=e.action)
352 $res = XDB
::iterator($sql);
353 while ($event = $res->next()) {
354 array_push($sessions[$event['id']]['events'], $event['text']);
356 $page->assign_by_ref('sessions', $sessions);
358 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
362 $page->changeTpl('admin/logger-view.tpl');
364 $page->setTitle('Administration - Logs des sessions');
367 function handler_user(&$page, $login = false
)
370 $page->changeTpl('admin/utilisateurs.tpl');
371 $page->setTitle('Administration - Edit/Su/Log');
372 require_once("emails.inc.php");
375 $page->kill("Déjà en SUID !!!");
378 // Loads the user identity using the environment.
380 $user = User
::get($login);
381 } else if (Env
::has('user_id')) {
382 $user = User
::get(Env
::i('user_id'));
383 } else if (Env
::has('login')) {
384 $user = User
::get(Env
::v('login'));
388 $login = $user->login();
389 $registered = ($user->forlifeEmail() != null
);
394 // Handles specific requests (AX sync, su, ...).
395 if(Env
::has('logs_button') && $registered) {
396 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
399 if (Env
::has('ax_button') && $registered) {
400 pl_redirect("admin/synchro_ax/" . $user->login());
403 if(Env
::has('suid_button') && $registered) {
404 if (!Platal
::session()->startSUID($user)) {
405 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->id());
411 // Fetches user data.
412 $userinfo_query = "SELECT *, FIND_IN_SET('watch', flags) AS watch, FIND_IN_SET('femme', flags) AS sexe,
413 (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
415 WHERE user_id = {?}";
416 $mr = XDB
::query($userinfo_query, $user->id())->fetchOneAssoc();
417 $redirect = ($registered ?
new Redirect($user) : null
);
419 // Processes admin requests, if any.
420 foreach($_POST as $key => $val) {
421 S
::assert_xsrf_token();
424 // Email redirection actions.
426 $email = trim(Env
::v('email'));
427 if (!isvalid_email_redirection($email)) {
428 $page->trigError("Email non valide: $email");
430 $redirect->add_email($email);
431 $page->trigSuccess("Ajout de $email effectué");
437 $redirect->delete_email($val);
443 $redirect->modify_one_email($val, true
);
446 case "deactivate_fwd":
448 $redirect->modify_one_email($val, false
);
452 $redirect->disable();
459 $redirect->clean_errors($val);
467 // Splits new alias in user and fqdn.
468 $alias = trim(Env
::v('email'));
469 if (strpos($alias, '@') !== false
) {
470 list($alias, $domain) = explode('@', $alias);
472 $domain = $globals->mail
->domain
;
475 // Checks for alias' user validity.
476 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
477 $page->trigError("'$alias' n'est pas un alias valide");
480 // Eventually adds the alias to the right domain.
481 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
482 $req = new AliasReq($user, $alias, 'Admin request', false
);
483 if ($req->commit()) {
484 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
486 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
488 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
489 $res = XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
490 $user->id(), $alias);
492 $page->trigSuccess("Nouvel alias '$alias' ajouté");
494 $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué");
497 $page->trigError("Le domaine '$domain' n'est pas valide");
503 XDB
::execute("DELETE FROM aliases
504 WHERE id = {?} AND alias = {?} AND
505 type NOT IN ('a_vie', 'homonyme')",
507 XDB
::execute("UPDATE emails
509 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
511 fix_bestalias($user);
512 $page->trigSuccess("L'alias '$val' a été supprimé");
517 XDB
::execute("UPDATE aliases
518 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
519 WHERE id = {?}", $user->id());
520 XDB
::execute("UPDATE aliases
521 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
522 WHERE id = {?} AND alias = {?}", $user->id(), $val);
524 // As having a non-null bestalias value is critical in
525 // plat/al's code, we do an a posteriori check on the
526 // validity of the bestalias.
527 fix_bestalias($user);
532 // Loads new values from environment.
533 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
sha1(Env
::v('newpass_clair')) : Env
::v('passw');
534 $naiss = Env
::v('naissanceN');
535 $deces = Env
::v('decesN');
536 $perms = Env
::v('permsN');
537 $prenom = Env
::v('prenomN');
538 $nom = Env
::v('nomN');
539 $nomusage = Env
::v('nomusageN');
540 $promo = Env
::i('promoN');
541 $sexe = Env
::v('sexeN');
542 $comm = trim(Env
::v('commentN'));
543 $watch = Env
::v('watchN');
545 $flags = ($sexe ?
'femme' : '');
547 $flags .= ($flags ?
',watch' : 'watch');
549 if ($watch && !$comm) {
550 $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte");
554 // Fetches fields to watch for changes.
555 $watch_query = "SELECT naissance, deces, password, perms, nom_usage,
556 prenom, nom, flags, promo, comment
558 WHERE user_id = {?}";
559 $old_fields = XDB
::query($watch_query, $user->id())->fetchOneAssoc();
561 // If user was newly banned, we need to ensure her php session
562 // is killed. This hack is ugly (and largely overkill); it should
563 // however suits our needs.
564 if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') {
568 // Updates the user profile with the new values.
569 $res = XDB
::execute("UPDATE auth_user_md5
570 SET naissance = {?}, deces = {?}, password = {?},
571 perms = {?}, prenom = {?}, nom = {?}, nom_usage = {?},
572 flags = {?}, promo = {?}, comment = {?}
573 WHERE user_id = {?}",
574 $naiss, $deces, $pass_encrypted,
575 $perms, $prenom, $nom, $nomusage,
576 $flags, $promo, $comm, $user->id());
578 require_once("user.func.inc.php");
579 user_reindex($user->id());
580 $new_fields = XDB
::query($watch_query, $user->id())->fetchOneAssoc();
582 $mailer = new PlMailer("admin/useredit.mail.tpl");
583 $mailer->assign("admin", S
::user()->login());
584 $mailer->assign("user", $user->login());
585 $mailer->assign('old', $old_fields);
586 $mailer->assign('new', $new_fields);
589 $globals->updateNbIns();
590 $page->trigSuccess("Update was successful.");
592 $page->trigError("Update failed, please double check your values.");
595 // Checks for changes, and updates other tables of plat/al.
596 if (Env
::v('nomusageN') != $mr['nom_usage']) {
597 set_new_usage($user->id(), Env
::v('nomusageN'), make_username(Env
::v('prenomN'), Env
::v('nomusageN')));
599 if (Env
::v('decesN') != $mr['deces']) {
600 require_once 'notifs.inc.php';
601 register_watch_op($user->id(), WATCH_DEATH
, $mr['deces']);
602 user_clear_all_subs($user->id(), false
);
605 // Eventually updates the Google Apps account.
606 if ($globals->mailstorage
->googleapps_domain
) {
607 // If the user did choose to use synchronized passwords,
608 // and the password was changed, updates the Google Apps
610 if (Env
::v('newpass_clair') != "********") {
611 require_once 'googleapps.inc.php';
612 $account = new GoogleAppsAccount($user);
613 if ($account->active() && $account->sync_password
) {
614 $account->set_password($pass_encrypted);
618 // If the update did disable the user account, disables
619 // the Google Apps account as well.
620 if ($new_fields['perms'] == 'disabled' && $new_fields['perms'] != $old_fields['perms']) {
621 require_once 'googleapps.inc.php';
622 $account = new GoogleAppsAccount($user);
628 // Reloads the user profile, to ensure the latest version will
629 // be served to the administrator.
630 $mr = XDB
::query($userinfo_query, $user->id())->fetchOneAssoc();
634 // User re-registration.
636 user_clear_all_subs($user->id());
637 $globals->updateNbIns();
638 $page->trigSuccess("'" . $user->id() . "' a été désinscrit !");
640 $mailer = new PlMailer("admin/useredit.mail.tpl");
641 $mailer->assign("admin", S
::user()->login());
642 $mailer->assign("user", $user->login());
643 $mailer->assign("deletion", true
);
649 XDB
::execute("DELETE FROM forum_innd WHERE uid = {?}", $user->id());
650 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
651 XDB
::execute("INSERT INTO forum_innd
652 SET ipmin = '0', ipmax = '4294967295',
653 write_perm = {?}, read_perm = {?},
654 comment = {?}, priority = '200', uid = {?}",
655 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $user->id());
661 // Displays last login and last host information.
662 $res = XDB
::query("SELECT start, host
664 WHERE uid = {?} AND suid = 0
666 LIMIT 1", $user->id());
667 list($lastlogin,$host) = $res->fetchOneRow();
668 $page->assign('lastlogin', $lastlogin);
669 $page->assign('host', $host);
671 // Display active aliases.
672 $page->assign('virtuals', $user->emailAliases());
673 $page->assign('aliases', XDB
::iterator(
674 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
676 WHERE id = {?} AND type != 'homonyme'
677 ORDER BY type != 'a_vie'", $user->id()));
678 $page->assign('account_types', XDB
::iterator('SELECT * FROM account_types ORDER BY type'));
679 $page->assign('skins', XDB
::iterator('SELECT id, name FROM skins ORDER BY name'));
681 // Displays email redirection and the general profile.
682 if ($registered && $redirect) {
683 $page->assign('emails', $redirect->emails
);
686 $page->assign('mr', $mr);
687 $page->assign('user', $user);
689 // Displays forum bans.
690 $res = XDB
::query("SELECT write_perm, read_perm, comment
692 WHERE uid = {?}", $user->id());
693 $bans = $res->fetchOneAssoc();
694 $page->assign('bans', $bans);
697 function getHruid($line, $key)
700 if (!isset($line['nom']) ||
!isset($line['prenom']) ||
!isset($line['promo'])) {
703 return make_forlife($line['prenom'], $line['nom'], $line['promo']);
706 function getMatricule($line, $key)
708 $mat = $line['matricule'];
709 $year = intval(substr($mat, 0, 3));
710 $rang = intval(substr($mat, 3, 3));
711 if ($year > 200) { $year /= 10; };
715 return sprintf('%04u%04u', 1900+
$year, $rang);
719 function handler_promo(&$page, $action = null
, $promo = null
)
721 if (Env
::has('promo')) {
722 if(Env
::i('promo') > 1900 && Env
::i('promo') < 2050) {
723 $action = Env
::v('valid_promo') == 'Ajouter des membres' ?
'add' : 'ax';
724 pl_redirect('admin/promo/' . $action . '/' . Env
::i('promo'));
726 $page->trigError('Promotion non valide.');
730 $page->changeTpl('admin/promo.tpl');
731 if ($promo > 1900 && $promo < 2050 && ($action == 'add' ||
$action == 'ax')) {
732 $page->assign('promo', $promo);
737 $importer = new CSVImporter('auth_user_md5', 'matricule');
738 $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule'));
741 $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini',
742 'prenom_ini', 'promo', 'promo_sortie', 'flags',
743 'matricule', 'matricule_ax', 'perms');
744 $importer->forceValue('hruid', array($this, 'getHruid'));
745 $importer->forceValue('promo', $promo);
746 $importer->forceValue('promo_sortie', $promo +
3);
749 $fields = array('matricule', 'matricule_ax');
752 $importer->apply($page, "admin/promo/$action/$promo", $fields);
755 function handler_homonyms(&$page, $op = 'list', $target = null
)
757 $page->changeTpl('admin/homonymes.tpl');
758 $page->setTitle('Administration - Homonymes');
759 $this->load("homonyms.inc.php");
762 $user = User
::getSilent($target);
763 if (!$user ||
!($loginbis = select_if_homonyme($user))) {
766 $page->assign('user', $user);
767 $page->assign('loginbis',$loginbis);
771 $page->assign('op', $op);
772 $page->assign('target', $target);
774 // on a un $target valide, on prepare les mails
776 // on examine l'op a effectuer
779 S
::assert_xsrf_token();
781 send_warning_homonyme($user, $loginbis);
782 switch_bestalias($user, $loginbis);
784 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.');
788 S
::assert_xsrf_token();
790 switch_bestalias($user, $loginbis);
791 XDB
::execute("UPDATE aliases
792 SET type = 'homonyme', expire=NOW()
793 WHERE alias = {?}", $loginbis);
794 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id)
795 VALUES ({?}, {?})", $target, $target);
796 send_robot_homonyme($user, $loginbis);
798 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.');
804 $res = XDB
::iterator(
805 "SELECT a.alias AS homonyme, s.alias AS forlife,
806 IF(h.homonyme_id = s.id, a.expire, NULL) AS expire,
807 IF(h.homonyme_id = s.id, a.type, NULL) AS type,
810 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
811 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
812 INNER JOIN accounts AS ac ON (ac.uid = a.id)
813 WHERE a.type = 'homonyme' OR a.expire != ''
814 ORDER BY a.alias, forlife");
816 while ($tab = $res->next()) {
817 $hnymes[$tab['homonyme']][] = $tab;
819 $page->assign_by_ref('hnymes',$hnymes);
823 function handler_ax_xorg(&$page)
825 $page->changeTpl('admin/ax-xorg.tpl');
826 $page->setTitle('Administration - AX/X.org');
828 // liste des différences
830 'SELECT u.promo,u.nom AS nom, u.prenom AS prenom, ia.nom AS nomax,
831 ia.prenom AS prenomax, u.matricule AS mat, ia.matricule_ax AS matax
832 FROM auth_user_md5 AS u
833 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
834 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
835 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
836 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
837 ORDER BY u.promo,u.nom,u.prenom');
838 $page->assign('diffs', $res->fetchAllAssoc());
840 // gens à l'ax mais pas chez nous
842 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
843 FROM identification_ax as ia
844 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
845 WHERE u.nom IS NULL');
846 $page->assign('mank', $res->fetchAllAssoc());
848 // gens chez nous et pas à l'ax
849 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
850 $page->assign('plus', $res->fetchAllAssoc());
853 function handler_deaths(&$page, $promo = 0, $validate = false
)
855 $page->changeTpl('admin/deces_promo.tpl');
856 $page->setTitle('Administration - Deces');
859 $promo = Env
::i('promo');
860 if (Env
::has('sub10')) $promo -= 10;
861 if (Env
::has('sub01')) $promo -= 1;
862 if (Env
::has('add01')) $promo +
= 1;
863 if (Env
::has('add10')) $promo +
= 10;
865 $page->assign('promo',$promo);
868 S
::assert_xsrf_token();
870 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
871 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
873 if($val == $deces ||
empty($val)) {
877 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
878 $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.');
879 if($deces == '0000-00-00' ||
empty($deces)) {
880 require_once('notifs.inc.php');
881 register_watch_op($uid, WATCH_DEATH
, $val);
882 require_once('user.func.inc.php');
883 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
888 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
889 $page->assign('decedes', $res);
892 function handler_dead_but_active(&$page)
894 $page->changeTpl('admin/dead_but_active.tpl');
895 $page->setTitle('Administration - Décédés');
897 $res = XDB
::iterator(
898 "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, u.hruid, DATE(MAX(s.start)) AS last
899 FROM auth_user_md5 AS u
900 LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0)
901 WHERE perms IN ('admin', 'user') AND deces <> 0
903 ORDER BY u.promo, u.nom");
904 $page->assign('dead', $res);
907 function handler_synchro_ax(&$page, $login = null
, $action = null
)
909 $page->changeTpl('admin/synchro_ax.tpl');
910 $page->setTitle('Administration - Synchro AX');
912 // Checks for synchronization requirements.
913 require_once('synchro_ax.inc.php');
914 if (is_ax_key_missing()) {
915 $page->assign('no_private_key', true
);
919 // Determines user identity using environment.
921 $user = User
::get($login);
922 } else if (Env
::has('user')) {
923 $user = User
::get(Env
::v('user'));
924 } else if (Env
::has('mat')) {
925 $res = XDB
::query("SELECT user_id
927 WHERE matricule = {?}",
929 $user = User
::get($res->fetchOneCell());
934 // Finally synchronizes the AX and plat/al information.
935 if ($action == 'import') {
936 ax_synchronize($user->login(), S
::v('uid'));
939 require_once 'profil.func.inc.php';
940 $userxorg = get_user_details($user->login(), S
::v('uid'), 'ax');
941 $userax = get_user_ax($userxorg['matricule_ax']);
942 $diff = diff_user_details($userax, $userxorg, 'ax');
944 $page->assign('x', $userxorg);
945 $page->assign('diff', $diff);
948 function handler_validate(&$page, $action = 'list', $id = null
)
950 $page->changeTpl('admin/valider.tpl');
951 $page->setTitle('Administration - Valider une demande');
952 $page->addCssLink('nl.css');
953 $page->addJsLink('ajax.js');
954 require_once("validations.inc.php");
957 if ($action == 'edit' and !is_null($id)) {
958 $page->assign('preview_id', $id);
961 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
962 S
::assert_xsrf_token();
964 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
966 $req->handle_formu();
968 $page->trigWarning('La validation a déjà été effectuée.');
972 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
973 while (($a = $r->next()) && $a['Field'] != 'category');
974 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
977 $res = XDB
::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S
::v('uid'));
978 $hide_requests = $res->fetchOneCell();
979 if (Post
::has('hide')) {
981 foreach ($categories as $cat)
982 if (!Post
::v($cat)) {
986 $hide_requests = join(',', $hide);
987 XDB
::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
988 S
::v('uid'), $hide_requests);
989 } elseif ($hide_requests) {
990 foreach (explode(',', $hide_requests) as $hide_type)
991 $hidden[$hide_type] = true
;
993 $page->assign('hide_requests', $hidden);
995 // Update the count of item to validate here... useful in development configuration
996 // where several copies of the site use the same DB, but not the same "dynamic configuration"
998 $globals->updateNbValid();
999 $page->assign('vit', new ValidateIterator());
1002 function handler_validate_answers(&$page, $action = 'list', $id = null
)
1004 $page->setTitle('Administration - Réponses automatiques de validation');
1005 $page->assign('title', 'Gestion des réponses automatiques');
1006 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
1007 $table_editor->describe('category','catégorie',true
);
1008 $table_editor->describe('title','titre',true
);
1009 $table_editor->describe('answer','texte',false
);
1010 $table_editor->apply($page, $action, $id);
1013 function handler_skins(&$page, $action = 'list', $id = null
)
1015 $page->setTitle('Administration - Skins');
1016 $page->assign('title', 'Gestion des skins');
1017 $table_editor = new PLTableEditor('admin/skins','skins','id');
1018 $table_editor->describe('name','nom',true
);
1019 $table_editor->describe('skin_tpl','nom du template',true
);
1020 $table_editor->describe('auteur','auteur',false
);
1021 $table_editor->describe('comment','commentaire',true
);
1022 $table_editor->describe('date','date',false
);
1023 $table_editor->describe('ext','extension du screenshot',false
);
1024 $table_editor->apply($page, $action, $id);
1027 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
)
1029 $page->setTitle('Administration - Postfix : Blacklist');
1030 $page->assign('title', 'Blacklist de postfix');
1031 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
1032 $table_editor->describe('reject_text','Texte de rejet',true
);
1033 $table_editor->describe('email','email',true
);
1034 $table_editor->apply($page, $action, $id);
1037 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
)
1039 $page->setTitle('Administration - Postfix : Whitelist');
1040 $page->assign('title', 'Whitelist de postfix');
1041 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
1042 $table_editor->describe('email','email',true
);
1043 $table_editor->apply($page, $action, $id);
1046 function handler_mx_broken(&$page, $action = 'list', $id = null
)
1048 $page->setTitle('Administration - MX Défaillants');
1049 $page->assign('title', 'MX Défaillant');
1050 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
1051 $table_editor->describe('host', 'Masque', true
);
1052 $table_editor->describe('state', 'Niveau', true
);
1053 $table_editor->describe('text', 'Description du problème', false
);
1054 $table_editor->apply($page, $action, $id);
1057 function handler_logger_actions(&$page, $action = 'list', $id = null
)
1059 $page->setTitle('Administration - Actions');
1060 $page->assign('title', 'Gestion des actions de logger');
1061 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
1062 $table_editor->describe('text','intitulé',true
);
1063 $table_editor->describe('description','description',true
);
1064 $table_editor->apply($page, $action, $id);
1067 function handler_downtime(&$page, $action = 'list', $id = null
)
1069 $page->setTitle('Administration - Coupures');
1070 $page->assign('title', 'Gestion des coupures');
1071 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
1072 $table_editor->describe('debut','date',true
);
1073 $table_editor->describe('duree','durée',false
);
1074 $table_editor->describe('resume','résumé',true
);
1075 $table_editor->describe('services','services affectés',true
);
1076 $table_editor->describe('description','description',false
);
1077 $table_editor->apply($page, $action, $id);
1080 function handler_account_types(&$page, $action = 'list', $id = null
)
1082 $page->setTitle('Administration - Types de comptes');
1083 $page->assign('title', 'Gestion des types de comptes');
1084 $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true
);
1085 $table_editor->describe('type', 'Catégorie', true
);
1086 $table_editor->describe('perms', 'Permissions associées', true
);
1087 $table_editor->apply($page, $action, $id);
1090 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
1092 if (S
::hasAuthToken()) {
1093 $page->setRssLink('Changement Récents',
1094 '/Site/AllRecentChanges?action=rss&user=' . S
::v('hruid') . '&hash=' . S
::v('token'));
1097 // update wiki perms
1098 if ($action == 'update') {
1099 S
::assert_xsrf_token();
1101 $perms_read = Post
::v('read');
1102 $perms_edit = Post
::v('edit');
1103 if ($perms_read ||
$perms_edit) {
1104 foreach ($_POST as $wiki_page => $val) {
1106 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1107 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1108 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1109 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1111 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1116 } else if ($action != 'list' && !empty($wikipage)) {
1117 $wp = new PlWikiPage($wikipage);
1118 S
::assert_xsrf_token();
1120 if ($action == 'delete') {
1121 if ($wp->delete()) {
1122 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1124 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1126 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1127 if ($changedLinks = $wp->rename($wikipage2)) {
1128 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1129 if (is_numeric($changedLinks)) {
1130 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1132 $page->trigSuccess($s);
1134 $page->trigError("Impossible de déplacer la page ".$wikipage);
1139 $perms = PlWikiPage
::permOptions();
1141 // list wiki pages and their perms
1142 $wiki_pages = PlWikiPage
::listPages();
1144 $wiki_tree = array();
1145 foreach ($wiki_pages as $file => $desc) {
1146 list($cat, $name) = explode('.', $file);
1147 if (!isset($wiki_tree[$cat])) {
1148 $wiki_tree[$cat] = array();
1150 $wiki_tree[$cat][$name] = $desc;
1153 $page->changeTpl('admin/wiki.tpl');
1154 $page->addJsLink('jquery.js');
1155 $page->assign('wiki_pages', $wiki_tree);
1156 $page->assign('perms_opts', $perms);
1159 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1161 $page->changeTpl('admin/ipwatcher.tpl');
1163 $states = array('safe' => 'Ne pas surveiller',
1164 'unsafe' => 'Surveiller les inscriptions',
1165 'dangerous' => 'Surveiller tous les accès',
1166 'ban' => 'Bannir cette adresse');
1167 $page->assign('states', $states);
1169 switch (Post
::v('action')) {
1171 if (trim(Post
::v('ipN')) != '') {
1172 S
::assert_xsrf_token();
1173 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1174 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1175 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1176 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1181 S
::assert_xsrf_token();
1182 Xdb
::execute('UPDATE ip_watch
1183 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1184 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1185 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1189 if ($action == 'delete' && !is_null($ip)) {
1190 S
::assert_xsrf_token();
1191 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1194 if ($action != 'create' && $action != 'edit') {
1197 $page->assign('action', $action);
1199 if ($action == 'list') {
1200 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1201 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1202 IF(w.ip = s.ip, s.host, s.forward_host)),
1203 w.mask, w.detection, w.state, a.hruid
1205 LEFT JOIN logger.sessions AS s ON (s.ip = w.ip)
1206 LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip)
1207 LEFT JOIN accounts AS a ON (a.uid = s.uid)
1208 GROUP BY w.ip, a.hruid
1209 ORDER BY w.state, w.ip, a.hruid";
1210 $it = Xdb
::iterRow($sql);
1214 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1215 $ip = uint_to_ip($ip);
1216 $mask = uint_to_ip($mask);
1217 if (count($props) == 0 ||
$props['ip'] != $ip) {
1218 if (count($props) > 0) {
1221 $props = array('ip' => $ip,
1224 'detection' => $date,
1226 'users' => array($hruid));
1228 $props['users'][] = $hruid;
1231 if (count($props) > 0) {
1234 $page->assign('table', $table);
1235 } elseif ($action == 'edit') {
1236 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1237 a1.hruid AS edit, a2.hruid AS hruid, s.host
1239 LEFT JOIN accounts AS a1 ON (a1.uid = w.uid)
1240 LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
1241 LEFT JOIN accounts AS a2 ON (a2.uid = s.uid)
1245 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1248 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1249 if (count($props) == 0) {
1250 $props = array('ip' => $ip,
1251 'mask' => uint_to_ip($mask),
1253 'detection' => $detection,
1256 'description' => $description,
1258 'users' => array($hruid));
1260 $props['users'][] = $hruid;
1263 $page->assign('ip', $props);
1267 function handler_icons(&$page)
1269 $page->changeTpl('admin/icons.tpl');
1270 $dh = opendir('../htdocs/images/icons');
1272 $page->trigError('Dossier des icones introuvables.');
1275 while (($file = readdir($dh)) !== false
) {
1276 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1277 array_push($icons, substr($file, 0, -4));
1281 $page->assign('icons', $icons);
1284 function handler_accounts(&$page)
1286 $page->changeTpl('admin/accounts.tpl');
1287 $page->assign('disabled', XDB
::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
1288 a.state = \'disabled\' AS disabled, a.comment
1290 WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags)
1291 ORDER BY a.hruid'));
1292 $page->assign('admins', XDB
::iterator('SELECT a.hruid
1295 ORDER BY a.hruid'));
1299 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: