2 /***************************************************************************
3 * Copyright (C) 2003-2009 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'),
53 'admin/jobs' => $this->make_hook('jobs', AUTH_MDP
, 'admin'),
57 function handler_phpinfo(&$page)
63 function handler_get_rights(&$page, $level)
66 $page->kill('Déjà en SUID');
69 Platal
::session()->startSUID($user, $level);
74 function handler_default(&$page)
76 $page->changeTpl('admin/index.tpl');
77 $page->setTitle('Administration');
80 function handler_postfix_delayed(&$page)
82 $page->changeTpl('admin/postfix_delayed.tpl');
83 $page->setTitle('Administration - Postfix : Retardés');
85 if (Env
::has('del')) {
87 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
88 $page->trigSuccess($crc . " verra tous ses emails supprimés !");
89 } elseif (Env
::has('ok')) {
91 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
92 $page->trigSuccess($crc . " a le droit de passer !");
96 "SELECT crc, nb, update_time, create_time,
97 FIND_IN_SET('del', p.release) AS del,
98 FIND_IN_SET('ok', p.release) AS ok
99 FROM postfix_mailseen AS p
101 ORDER BY p.release != ''");
103 $page->assign_by_ref('mails', $sql);
106 function handler_postfix_regexpsbounces(&$page, $new = null
) {
107 $page->changeTpl('admin/emails_bounces_re.tpl');
108 $page->setTitle('Administration - Postfix : Regexps Bounces');
109 $page->assign('new', $new);
111 if (Post
::has('submit')) {
112 foreach (Env
::v('lvl') as $id=>$val) {
114 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
115 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
120 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
125 /** Retrieves the available days for a given year and month.
126 * Obtain a list of days of the given month in the given year
127 * that are within the range of dates that we have log entries for.
129 * @param integer year
130 * @param integer month
131 * @return array days in that month we have log entries covering.
134 function _getDays($year, $month)
136 // give a 'no filter' option
139 if ($year && $month) {
140 $day_max = Array(-1, 31, checkdate(2, 29, $year) ?
29 : 28 , 31,
141 30, 31, 30, 31, 31, 30, 31, 30, 31);
142 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
143 MONTH(MAX(start)), MONTH(MIN(start)),
144 DAYOFMONTH(MAX(start)),
145 DAYOFMONTH(MIN(start))
147 list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow();
149 if (($year < $ymin) ||
($year == $ymin && $month < $mmin)) {
153 if (($year > $ymax) ||
($year == $ymax && $month > $mmax)) {
157 $min = ($year==$ymin && $month==$mmin) ?
intval($dmin) : 1;
158 $max = ($year==$ymax && $month==$mmax) ?
intval($dmax) : $day_max[$month];
160 for($i = $min; $i<=$max; $i++
) {
168 /** Retrieves the available months for a given year.
169 * Obtains a list of month numbers that are within the timeframe that
170 * we have log entries for.
172 * @param integer year
173 * @return array List of month numbers we have log info for.
176 function _getMonths($year)
178 // give a 'no filter' option
182 $res = XDB
::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)),
183 MONTH(MAX(start)), MONTH(MIN(start))
185 list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow();
187 if (($year < $ymin) ||
($year > $ymax)) {
191 $min = $year == $ymin ?
intval($mmin) : 1;
192 $max = $year == $ymax ?
intval($mmax) : 12;
194 for($i = $min; $i<=$max; $i++
) {
202 /** Retrieves the available years.
203 * Obtains a list of years that we have log entries covering.
205 * @return array years we have log entries for.
210 // give a 'no filter' option
213 // retrieve available years
214 $res = XDB
::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM log_sessions");
215 list($max, $min) = $res->fetchOneRow();
217 for($i = intval($min); $i<=$max; $i++
) {
224 /** Make a where clause to get a user's sessions.
225 * Prepare the where clause request that will retrieve the sessions.
227 * @param $year INTEGER Only get log entries made during the given year.
228 * @param $month INTEGER Only get log entries made during the given month.
229 * @param $day INTEGER Only get log entries made during the given day.
230 * @param $uid INTEGER Only get log entries referring to the given user ID.
232 * @return STRING the WHERE clause of a query, including the 'WHERE' keyword
235 function _makeWhere($year, $month, $day, $uid)
237 // start constructing the "where" clause
241 array_push($where, "uid='$uid'");
243 // we were given at least a year
246 $dmin = mktime(0, 0, 0, $month, $day, $year);
247 $dmax = mktime(0, 0, 0, $month, $day+
1, $year);
249 $dmin = mktime(0, 0, 0, $month, 1, $year);
250 $dmax = mktime(0, 0, 0, $month+
1, 1, $year);
252 $dmin = mktime(0, 0, 0, 1, 1, $year);
253 $dmax = mktime(0, 0, 0, 1, 1, $year+
1);
255 $where[] = "start >= " . date("Ymd000000", $dmin);
256 $where[] = "start < " . date("Ymd000000", $dmax);
259 if (!empty($where)) {
260 return ' WHERE ' . implode($where, " AND ");
264 // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC
269 function handler_logger(&$page, $action = null
, $arg = null
) {
270 if ($action == 'session') {
272 // we are viewing a session
273 $res = XDB
::query("SELECT ls.*, a.alias AS username, sa.alias AS suer
274 FROM log_sessions AS ls
275 LEFT JOIN #x4dat#.aliases AS a ON (a.id = ls.uid AND a.type='a_vie')
276 LEFT JOIN #x4dat#.aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie')
277 WHERE ls.id = {?}", $arg);
279 $page->assign('session', $a = $res->fetchOneAssoc());
281 $res = XDB
::iterator('SELECT a.text, e.data, e.stamp
283 LEFT JOIN log_actions AS a ON e.action=a.id
284 WHERE e.session={?}', $arg);
285 while ($myarr = $res->next()) {
286 $page->append('events', $myarr);
290 $loguser = $action == 'user' ?
$arg : Env
::v('loguser');
292 $res = XDB
::query('SELECT id FROM aliases WHERE alias={?}',
294 $loguid = $res->fetchOneCell();
297 $year = Env
::i('year');
298 $month = Env
::i('month');
299 $day = Env
::i('day');
301 $year = Env
::i('year', intval(date('Y')));
302 $month = Env
::i('month', intval(date('m')));
303 $day = Env
::i('day', intval(date('d')));
311 // smarty assignments
312 // retrieve available years
313 $page->assign('years', $this->_getYears());
314 $page->assign('year', $year);
316 // retrieve available months for the current year
317 $page->assign('months', $this->_getMonths($year));
318 $page->assign('month', $month);
320 // retrieve available days for the current year and month
321 $page->assign('days', $this->_getDays($year, $month));
322 $page->assign('day', $day);
324 $page->assign('loguser', $loguser);
325 // smarty assignments
327 if ($loguid ||
$year) {
329 // get the requested sessions
330 $where = $this->_makeWhere($year, $month, $day, $loguid);
331 $select = "SELECT s.id, s.start, s.uid,
333 FROM log_sessions AS s
334 LEFT JOIN #x4dat#.aliases AS a ON (a.id = s.uid AND a.type='a_vie')
336 ORDER BY start DESC";
337 $res = XDB
::iterator($select);
340 while ($mysess = $res->next()) {
341 $mysess['events'] = array();
342 $sessions[$mysess['id']] = $mysess;
344 array_reverse($sessions);
347 $sql = "SELECT s.id, a.text
348 FROM log_sessions AS s
349 LEFT JOIN log_events AS e ON(e.session=s.id)
350 INNER JOIN log_actions AS a ON(a.id=e.action)
353 $res = XDB
::iterator($sql);
354 while ($event = $res->next()) {
355 array_push($sessions[$event['id']]['events'], $event['text']);
357 $page->assign_by_ref('sessions', $sessions);
359 $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
363 $page->changeTpl('admin/logger-view.tpl');
365 $page->setTitle('Administration - Logs des sessions');
368 function handler_user(&$page, $login = false
)
371 $page->changeTpl('admin/user.tpl');
372 $page->setTitle('Administration - Compte');
375 $page->kill("Déjà en SUID !!!");
378 // Loads the user identity using the environment.
379 $user = User
::get($login);
384 $login = $user->login();
385 $registered = ($user->state
!= 'pending');
388 if (!empty($_POST)) {
389 S
::assert_xsrf_token();
390 if (Post
::has('uid') && Post
::i('uid') != $user->id()) {
391 $page->kill('Une erreur s\'est produite');
395 // Handles specific requests (AX sync, su, ...).
396 if(Post
::has('logs_account')) {
397 pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
400 if(Post
::has('su_button') && $registered) {
401 if (!Platal
::session()->startSUID($user)) {
402 $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login());
409 $to_update = array();
410 if (Post
::has('disable_weak_access')) {
411 $to_update['weak_password'] = null
;
412 } else if (Post
::has('update_account')) {
413 if (Post
::s('full_name') != $user->fullName()) {
414 // XXX: Update profile if a profile is associated
415 $to_update['full_name'] = Post
::s('full_name');
417 if (Post
::s('display_name') != $user->displayName()) {
418 // XXX: Update profile if a profile is associated
419 $to_update['display_name'] = Post
::s('display_name');
421 if (Post
::s('sex') != ($user->isFemale() ?
'female' : 'male')) {
422 $to_update['sex'] = Post
::s('sex');
424 if (!Post
::blank('hashpass')) {
425 $to_update['password'] = Post
::s('hashpass');
426 // TODO: Propagate the password update to GoogleApps, when required. Eg:
427 // $account = new GoogleAppsAccount($user);
428 // if ($account->active() && $account->sync_password) {
429 // $account->set_password($pass_encrypted);
432 if (!Post
::blank('weak_password')) {
433 $to_update['weak_password'] = Post
::s('weak_password');
435 if (Post
::i('token_access', 0) != ($user->token_access ?
1 : 0)) {
436 $to_update['token'] = Post
::i('token_access') ?
rand_url_id(16) : null
;
438 if (Post
::i('skin', 0) != $user->skin
) {
439 $to_update['skin'] = Post
::i('skin', 0);
440 if ($to_update['skin'] == 0) {
441 $to_update['skin'] = null
;
444 if (Post
::s('state') != $user->state
) {
445 $to_update['state'] = Post
::s('state');
447 if (Post
::i('is_admin', 0) != ($user->is_admin ?
1 : 0)) {
448 $to_update['is_admin'] = Post
::b('is_admin');
450 if (Post
::s('type') != $user->type
) {
451 $to_update['type'] = Post
::s('type');
453 if (Post
::i('watch', 0) != ($user->watch ?
1 : 0)) {
454 $to_update['flags'] = new PlFlagset();
455 $to_update['flags']->addFlag('watch', Post
::i('watch'));
457 if (Post
::t('comment') != $user->comment
) {
458 $to_update['comment'] = Post
::blank('comment') ? null
: Post
::t('comment');
461 if (!empty($to_update)) {
462 // TODO: fetch the initial values of the fields, and eventually send
463 // a summary of the changes to an admin.
465 foreach ($to_update as $k => $value) {
466 $set[] = XDB
::format($k . ' = {?}', $value);
468 XDB
::execute('UPDATE accounts
469 SET ' . implode(', ', $set) . '
470 WHERE uid = ' . XDB
::format('{?}', $user->id()));
471 $page->trigSuccess('Données du compte mise à jour avec succès');
472 $user = User
::getWithUID($user->id());
477 if (Post
::has('add_profile') || Post
::has('del_profile') || Post
::has('owner')) {
478 if (Post
::i('del_profile', 0) != 0) {
479 XDB
::execute('DELETE FROM account_profiles
480 WHERE uid = {?} AND pid = {?}',
481 $user->id(), Post
::i('del_profile'));
482 } else if (!Post
::blank('new_profile')) {
483 $profile = Profile
::get(Post
::t('new_profile'));
485 $page->trigError('Le profil ' . Post
::t('new_profile') . ' n\'existe pas');
487 XDB
::execute('INSERT IGNORE INTO account_profiles (uid, pid)
489 $user->id(), $profile->id());
492 XDB
::execute('UPDATE account_profiles
493 SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\'))
495 Post
::i('owner'), $user->id());
499 // Email forwards form {{{
500 require_once("emails.inc.php");
501 $redirect = ($registered ?
new Redirect($user) : null
);
502 if (Post
::has('add_fwd')) {
503 $email = Post
::t('email');
504 if (!isvalid_email_redirection($email)) {
505 $page->trigError("Email non valide: $email");
507 $redirect->add_email($email);
508 $page->trigSuccess("Ajout de $email effectué");
510 } else if (!Post
::blank('del_fwd')) {
511 $redirect->delete_email(Post
::t('del_fwd'));
512 } else if (!Post
::blank('activate_fwd')) {
513 $redirect->modify_one_email(Post
::t('activate_fwd', true
));
514 } else if (!Post
::blank('deactivate_fwd')) {
515 $redirect->modify_one_email(Post
::t('deactivate_fwd', false
));
516 } else if (Post
::has('disable_fwd')) {
517 $redirect->disable();
518 } else if (Post
::has('enable_fwd')) {
520 } else if (!Post
::blank('clean_fwd')) {
521 $redirect->clean_errors(Post
::t('clean_fwd'));
525 // Email alias form {{{
526 if (Post
::has('add_alias')) {
527 // Splits new alias in user and fqdn.
528 $alias = Env
::t('email');
529 if (strpos($alias, '@') !== false
) {
530 list($alias, $domain) = explode('@', $alias);
532 $domain = $globals->mail
->domain
;
535 // Checks for alias' user validity.
536 if (!preg_match('/[-a-z0-9\.]+/s', $alias)) {
537 $page->trigError("'$alias' n'est pas un alias valide");
540 // Eventually adds the alias to the right domain.
541 if ($domain == $globals->mail
->alias_dom ||
$domain == $globals->mail
->alias_dom2
) {
542 $req = new AliasReq($user, $alias, 'Admin request', false
);
543 if ($req->commit()) {
544 $page->trigSuccess("Nouvel alias '$alias@$domain' attribué");
546 $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué");
548 } elseif ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
549 $res = XDB
::execute("INSERT INTO aliases (id, alias, type)
550 VALUES ({?}, {?}, 'alias')",
551 $user->id(), $alias);
552 $page->trigSuccess("Nouvel alias '$alias' ajouté");
554 $page->trigError("Le domaine '$domain' n'est pas valide");
556 } else if (!Post
::blank('del_alias')) {
557 XDB
::execute("DELETE FROM aliases
558 WHERE id = {?} AND alias = {?} AND
559 type NOT IN ('a_vie', 'homonyme')",
561 XDB
::execute("UPDATE emails
563 WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
565 fix_bestalias($user);
566 $page->trigSuccess("L'alias '$val' a été supprimé");
567 } else if (!Post
::blank('best')) {
568 XDB
::execute("UPDATE aliases
569 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
570 WHERE id = {?}", $user->id());
571 XDB
::execute("UPDATE aliases
572 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
573 WHERE id = {?} AND alias = {?}", $user->id(), $val);
574 // As having a non-null bestalias value is critical in
575 // plat/al's code, we do an a posteriori check on the
576 // validity of the bestalias.
577 fix_bestalias($user);
582 if (Post
::has('del_openid')) {
583 XDB
::execute('DELETE FROM openid_trusted
584 WHERE id = {?}', Post
::i('del_openid'));
589 if (Post
::has('b_edit')) {
590 XDB
::execute("DELETE FROM forum_innd
591 WHERE uid = {?}", $user->id());
592 if (Env
::v('write_perm') != "" || Env
::v('read_perm') != "" || Env
::v('commentaire') != "" ) {
593 XDB
::execute("INSERT INTO forum_innd
594 SET ipmin = '0', ipmax = '4294967295',
595 write_perm = {?}, read_perm = {?},
596 comment = {?}, priority = '200', uid = {?}",
597 Env
::v('write_perm'), Env
::v('read_perm'), Env
::v('comment'), $user->id());
603 $page->addJsLink('ui.core.js');
604 $page->addJsLink('ui.tabs.js');
606 // Displays last login and last host information.
607 $res = XDB
::query("SELECT start, host
609 WHERE uid = {?} AND suid = 0
611 LIMIT 1", $user->id());
612 list($lastlogin,$host) = $res->fetchOneRow();
613 $page->assign('lastlogin', $lastlogin);
614 $page->assign('host', $host);
616 // Display active aliases.
617 $page->assign('virtuals', $user->emailAliases());
618 $page->assign('aliases', XDB
::iterator("SELECT alias, type='a_vie' AS for_life,
619 FIND_IN_SET('bestalias',flags) AS best, expire
621 WHERE id = {?} AND type != 'homonyme'
622 ORDER BY type != 'a_vie'", $user->id()));
623 $page->assign('account_types', XDB
::iterator('SELECT * FROM account_types ORDER BY type'));
624 $page->assign('skins', XDB
::iterator('SELECT id, name FROM skins ORDER BY name'));
625 $page->assign('profiles', XDB
::iterator('SELECT p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner
626 FROM account_profiles AS ap
627 INNER JOIN profiles AS p ON (ap.pid = p.pid)
628 WHERE ap.uid = {?}', $user->id()));
629 $page->assign('openid', XDB
::iterator('SELECT id, url
631 WHERE user_id = {?}', $user->id()));
633 // Displays email redirection and the general profile.
634 if ($registered && $redirect) {
635 $page->assign('emails', $redirect->emails
);
638 $page->assign('user', $user);
640 // Displays forum bans.
641 $res = XDB
::query("SELECT write_perm, read_perm, comment
643 WHERE uid = {?}", $user->id());
644 $bans = $res->fetchOneAssoc();
645 $page->assign('bans', $bans);
648 function getHruid($line, $key, $relation)
650 $prenom = CSVImporter
::getValue($line, 'prenom', $relation['prenom']);
651 $nom = CSVImporter
::getValue($line, 'nom', $relation['nom']);
652 $promo = CSVImporter
::getValue($line, 'promo', $relation['promo']);
654 if ($prenom != 'NULL' && $nom != 'NULL' && $promo != 'NULL') {
655 return make_forlife($prenom, $nom, $promo);
660 function getMatricule($line, $key, $relation)
662 $mat = $line['matricule'];
663 $year = intval(substr($mat, 0, 3));
664 $rang = intval(substr($mat, 3, 3));
665 if ($year > 200) { $year /= 10; };
669 return sprintf('%04u%04u', 1900+
$year, $rang);
673 function handler_promo(&$page, $action = null
, $promo = null
)
675 if (Env
::has('promo')) {
676 if(Env
::i('promo') > 1900 && Env
::i('promo') < 2050) {
677 $action = Env
::v('valid_promo') == 'Ajouter des membres' ?
'add' : 'ax';
678 pl_redirect('admin/promo/' . $action . '/' . Env
::i('promo'));
680 $page->trigError('Promotion non valide.');
684 $page->changeTpl('admin/promo.tpl');
685 if ($promo > 1900 && $promo < 2050 && ($action == 'add' ||
$action == 'ax')) {
686 $page->assign('promo', $promo);
691 $importer = new CSVImporter('auth_user_md5', 'matricule');
692 $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule'));
695 $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini',
696 'prenom_ini', 'promo', 'promo_sortie', 'flags',
697 'matricule', 'matricule_ax', 'perms');
698 $importer->forceValue('hruid', array($this, 'getHruid'));
699 $importer->forceValue('promo', $promo);
700 $importer->forceValue('promo_sortie', $promo +
3);
703 $fields = array('matricule', 'matricule_ax');
706 $importer->apply($page, "admin/promo/$action/$promo", $fields);
709 function handler_homonyms(&$page, $op = 'list', $target = null
)
711 $page->changeTpl('admin/homonymes.tpl');
712 $page->setTitle('Administration - Homonymes');
713 $this->load("homonyms.inc.php");
716 $user = User
::getSilent($target);
717 if (!$user ||
!($loginbis = select_if_homonyme($user))) {
720 $page->assign('user', $user);
721 $page->assign('loginbis',$loginbis);
725 $page->assign('op', $op);
726 $page->assign('target', $target);
728 // on a un $target valide, on prepare les mails
730 // on examine l'op a effectuer
733 S
::assert_xsrf_token();
735 send_warning_homonyme($user, $loginbis);
736 switch_bestalias($user, $loginbis);
738 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.');
742 S
::assert_xsrf_token();
744 switch_bestalias($user, $loginbis);
745 XDB
::execute("UPDATE aliases
746 SET type = 'homonyme', expire=NOW()
747 WHERE alias = {?}", $loginbis);
748 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id)
749 VALUES ({?}, {?})", $target, $target);
750 send_robot_homonyme($user, $loginbis);
752 $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.');
758 $res = XDB
::iterator(
759 "SELECT a.alias AS homonyme, s.alias AS forlife,
760 IF(h.homonyme_id = s.id, a.expire, NULL) AS expire,
761 IF(h.homonyme_id = s.id, a.type, NULL) AS type,
764 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
765 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
766 INNER JOIN accounts AS ac ON (ac.uid = a.id)
767 WHERE a.type = 'homonyme' OR a.expire != ''
768 ORDER BY a.alias, forlife");
770 while ($tab = $res->next()) {
771 $hnymes[$tab['homonyme']][] = $tab;
773 $page->assign_by_ref('hnymes',$hnymes);
777 function handler_deaths(&$page, $promo = 0, $validate = false
)
779 $page->changeTpl('admin/deces_promo.tpl');
780 $page->setTitle('Administration - Deces');
783 $promo = Env
::t('promo', 'X1923');
785 $page->assign('promo', $promo);
791 S
::assert_xsrf_token();
793 $res = XDB
::iterRow('SELECT p.hrpid, pd.directory_name, p.deathdate
795 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
796 WHERE pd.promo = {?}', $promo);
797 while (list($pid, $name, $death) = $res->next()) {
799 if($val == $deces ||
empty($val)) {
803 XDB
::execute('UPDATE profiles
804 SET deathdate = {?}, deathdate_rec = NOW()
805 WHERE hrpid = {?}', $val, $pid);
806 $page->trigSuccess('Ajout du décès de ' . $name . ' le ' . $val . '.');
807 if($death == '0000-00-00' ||
empty($death)) {
808 // TODO: FIX THIS DEPRECATED CALL
809 require_once('user.func.inc.php');
810 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
815 $res = XDB
::iterator('SELECT p.hrpid, pd.directory_name, p.deathdate
817 INNER JOIN profile_display AS pd ON (p.pid = pd.pid)
819 ORDER BY pd.sort_name', $promo);
820 $page->assign('decedes', $res);
823 function handler_dead_but_active(&$page)
825 $page->changeTpl('admin/dead_but_active.tpl');
826 $page->setTitle('Administration - Décédés');
828 $res = XDB
::iterator(
829 "SELECT a.hruid, pd.promo, p.ax_id, pd.directory_name, p.deathdate, DATE(MAX(s.start)) AS last
830 FROM #x4dat#.accounts AS a
831 INNER JOIN #x4dat#.account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))
832 INNER JOIN #x4dat#.profiles AS p ON (p.pid = ap.pid)
833 INNER JOIN #x4dat#.profile_display AS pd ON (pd.pid = p.pid)
834 LEFT JOIN log_sessions AS s ON (s.uid = a.uid AND suid = 0)
835 WHERE a.state = 'active' AND p.deathdate IS NOT NULL
837 ORDER BY pd.promo, pd.sort_name");
838 $page->assign('dead', $res);
841 function handler_validate(&$page, $action = 'list', $id = null
)
843 $page->changeTpl('admin/valider.tpl');
844 $page->setTitle('Administration - Valider une demande');
845 $page->addCssLink('nl.css');
846 $page->addJsLink('ajax.js');
847 require_once("validations.inc.php");
850 if ($action == 'edit' and !is_null($id)) {
851 $page->assign('preview_id', $id);
854 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
855 S
::assert_xsrf_token();
857 $req = Validate
::get_typed_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
859 $req->handle_formu();
861 $page->trigWarning('La validation a déjà été effectuée.');
865 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
866 while (($a = $r->next()) && $a['Field'] != 'category');
867 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
870 $res = XDB
::query('SELECT hidden_requests FROM requests_hidden WHERE user_id = {?}', S
::v('uid'));
871 $hide_requests = $res->fetchOneCell();
872 if (Post
::has('hide')) {
874 foreach ($categories as $cat)
875 if (!Post
::v($cat)) {
879 $hide_requests = join(',', $hide);
880 XDB
::query('REPLACE INTO requests_hidden (user_id, hidden_requests) VALUES({?}, {?})',
881 S
::v('uid'), $hide_requests);
882 } elseif ($hide_requests) {
883 foreach (explode(',', $hide_requests) as $hide_type)
884 $hidden[$hide_type] = true
;
886 $page->assign('hide_requests', $hidden);
888 // Update the count of item to validate here... useful in development configuration
889 // where several copies of the site use the same DB, but not the same "dynamic configuration"
891 $globals->updateNbValid();
892 $page->assign('vit', new ValidateIterator());
895 function handler_validate_answers(&$page, $action = 'list', $id = null
)
897 $page->setTitle('Administration - Réponses automatiques de validation');
898 $page->assign('title', 'Gestion des réponses automatiques');
899 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
900 $table_editor->describe('category','catégorie',true
);
901 $table_editor->describe('title','titre',true
);
902 $table_editor->describe('answer','texte',false
);
903 $table_editor->apply($page, $action, $id);
906 function handler_skins(&$page, $action = 'list', $id = null
)
908 $page->setTitle('Administration - Skins');
909 $page->assign('title', 'Gestion des skins');
910 $table_editor = new PLTableEditor('admin/skins','skins','id');
911 $table_editor->describe('name','nom',true
);
912 $table_editor->describe('skin_tpl','nom du template',true
);
913 $table_editor->describe('auteur','auteur',false
);
914 $table_editor->describe('comment','commentaire',true
);
915 $table_editor->describe('date','date',false
);
916 $table_editor->describe('ext','extension du screenshot',false
);
917 $table_editor->apply($page, $action, $id);
920 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
)
922 $page->setTitle('Administration - Postfix : Blacklist');
923 $page->assign('title', 'Blacklist de postfix');
924 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
925 $table_editor->describe('reject_text','Texte de rejet',true
);
926 $table_editor->describe('email','email',true
);
927 $table_editor->apply($page, $action, $id);
930 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
)
932 $page->setTitle('Administration - Postfix : Whitelist');
933 $page->assign('title', 'Whitelist de postfix');
934 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
935 $table_editor->describe('email','email',true
);
936 $table_editor->apply($page, $action, $id);
939 function handler_mx_broken(&$page, $action = 'list', $id = null
)
941 $page->setTitle('Administration - MX Défaillants');
942 $page->assign('title', 'MX Défaillant');
943 $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true
);
944 $table_editor->describe('host', 'Masque', true
);
945 $table_editor->describe('state', 'Niveau', true
);
946 $table_editor->describe('text', 'Description du problème', false
);
947 $table_editor->apply($page, $action, $id);
950 function handler_logger_actions(&$page, $action = 'list', $id = null
)
952 $page->setTitle('Administration - Actions');
953 $page->assign('title', 'Gestion des actions de logger');
954 $table_editor = new PLTableEditor('admin/logger/actions','log_actions','id');
955 $table_editor->describe('text','intitulé',true
);
956 $table_editor->describe('description','description',true
);
957 $table_editor->apply($page, $action, $id);
960 function handler_downtime(&$page, $action = 'list', $id = null
)
962 $page->setTitle('Administration - Coupures');
963 $page->assign('title', 'Gestion des coupures');
964 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
965 $table_editor->describe('debut','date',true
);
966 $table_editor->describe('duree','durée',false
);
967 $table_editor->describe('resume','résumé',true
);
968 $table_editor->describe('services','services affectés',true
);
969 $table_editor->describe('description','description',false
);
970 $table_editor->apply($page, $action, $id);
973 function handler_account_types(&$page, $action = 'list', $id = null
)
975 $page->setTitle('Administration - Types de comptes');
976 $page->assign('title', 'Gestion des types de comptes');
977 $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true
);
978 $table_editor->describe('type', 'Catégorie', true
);
979 $table_editor->describe('perms', 'Permissions associées', true
);
980 $table_editor->apply($page, $action, $id);
983 function handler_wiki(&$page, $action = 'list', $wikipage = null
, $wikipage2 = null
)
985 if (S
::hasAuthToken()) {
986 $page->setRssLink('Changement Récents',
987 '/Site/AllRecentChanges?action=rss&user=' . S
::v('hruid') . '&hash=' . S
::v('token'));
991 if ($action == 'update') {
992 S
::assert_xsrf_token();
994 $perms_read = Post
::v('read');
995 $perms_edit = Post
::v('edit');
996 if ($perms_read ||
$perms_edit) {
997 foreach ($_POST as $wiki_page => $val) {
999 $wp = new PlWikiPage(str_replace(array('_', '/'), '.', $wiki_page));
1000 if ($wp->setPerms($perms_read ?
$perms_read : $wp->readPerms(),
1001 $perms_edit ?
$perms_edit : $wp->writePerms())) {
1002 $page->trigSuccess("Permission de la page $wiki_page mises à jour");
1004 $page->trigError("Impossible de mettre les permissions de la page $wiki_page à jour");
1009 } else if ($action != 'list' && !empty($wikipage)) {
1010 $wp = new PlWikiPage($wikipage);
1011 S
::assert_xsrf_token();
1013 if ($action == 'delete') {
1014 if ($wp->delete()) {
1015 $page->trigSuccess("La page ".$wikipage." a été supprimée.");
1017 $page->trigError("Impossible de supprimer la page ".$wikipage.".");
1019 } else if ($action == 'rename' && !empty($wikipage2) && $wikipage != $wikipage2) {
1020 if ($changedLinks = $wp->rename($wikipage2)) {
1021 $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
1022 if (is_numeric($changedLinks)) {
1023 $s .= $changedLinks.' lien'.(($changedLinks>1)?
's ont été modifiés.':' a été modifié.');
1025 $page->trigSuccess($s);
1027 $page->trigError("Impossible de déplacer la page ".$wikipage);
1032 $perms = PlWikiPage
::permOptions();
1034 // list wiki pages and their perms
1035 $wiki_pages = PlWikiPage
::listPages();
1037 $wiki_tree = array();
1038 foreach ($wiki_pages as $file => $desc) {
1039 list($cat, $name) = explode('.', $file);
1040 if (!isset($wiki_tree[$cat])) {
1041 $wiki_tree[$cat] = array();
1043 $wiki_tree[$cat][$name] = $desc;
1046 $page->changeTpl('admin/wiki.tpl');
1047 $page->assign('wiki_pages', $wiki_tree);
1048 $page->assign('perms_opts', $perms);
1051 function handler_ipwatch(&$page, $action = 'list', $ip = null
)
1053 $page->changeTpl('admin/ipwatcher.tpl');
1055 $states = array('safe' => 'Ne pas surveiller',
1056 'unsafe' => 'Surveiller les inscriptions',
1057 'dangerous' => 'Surveiller tous les accès',
1058 'ban' => 'Bannir cette adresse');
1059 $page->assign('states', $states);
1061 switch (Post
::v('action')) {
1063 if (trim(Post
::v('ipN')) != '') {
1064 S
::assert_xsrf_token();
1065 Xdb
::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description)
1066 VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})',
1067 ip_to_uint(trim(Post
::v('ipN'))), ip_to_uint(trim(Post
::v('maskN'))),
1068 Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
1073 S
::assert_xsrf_token();
1074 Xdb
::execute('UPDATE ip_watch
1075 SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?}
1076 WHERE ip = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'),
1077 ip_to_uint(Post
::v('maskN')), ip_to_uint(Post
::v('ipN')));
1081 if ($action == 'delete' && !is_null($ip)) {
1082 S
::assert_xsrf_token();
1083 Xdb
::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip));
1086 if ($action != 'create' && $action != 'edit') {
1089 $page->assign('action', $action);
1091 if ($action == 'list') {
1092 $sql = "SELECT w.ip, IF(s.ip IS NULL,
1093 IF(w.ip = s2.ip, s2.host, s2.forward_host),
1094 IF(w.ip = s.ip, s.host, s.forward_host)),
1095 w.mask, w.detection, w.state, a.hruid
1096 FROM #x4dat#.ip_watch AS w
1097 LEFT JOIN log_sessions AS s ON (s.ip = w.ip)
1098 LEFT JOIN log_sessions AS s2 ON (s2.forward_ip = w.ip)
1099 LEFT JOIN #x4dat#.accounts AS a ON (a.uid = s.uid)
1100 GROUP BY w.ip, a.hruid
1101 ORDER BY w.state, w.ip, a.hruid";
1102 $it = Xdb
::iterRow($sql);
1106 while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) {
1107 $ip = uint_to_ip($ip);
1108 $mask = uint_to_ip($mask);
1109 if (count($props) == 0 ||
$props['ip'] != $ip) {
1110 if (count($props) > 0) {
1113 $props = array('ip' => $ip,
1116 'detection' => $date,
1118 'users' => array($hruid));
1120 $props['users'][] = $hruid;
1123 if (count($props) > 0) {
1126 $page->assign('table', $table);
1127 } elseif ($action == 'edit') {
1128 $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,
1129 a1.hruid AS edit, a2.hruid AS hruid, s.host
1130 FROM #x4dat#.ip_watch AS w
1131 LEFT JOIN #x4dat#.accounts AS a1 ON (a1.uid = w.uid)
1132 LEFT JOIN log_sessions AS s ON (w.ip = s.ip)
1133 LEFT JOIN #x4dat#.accounts AS a2 ON (a2.uid = s.uid)
1137 $it = Xdb
::iterRow($sql, ip_to_uint($ip));
1140 while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) {
1141 if (count($props) == 0) {
1142 $props = array('ip' => $ip,
1143 'mask' => uint_to_ip($mask),
1145 'detection' => $detection,
1148 'description' => $description,
1150 'users' => array($hruid));
1152 $props['users'][] = $hruid;
1155 $page->assign('ip', $props);
1159 function handler_icons(&$page)
1161 $page->changeTpl('admin/icons.tpl');
1162 $dh = opendir('../htdocs/images/icons');
1164 $page->trigError('Dossier des icones introuvables.');
1167 while (($file = readdir($dh)) !== false
) {
1168 if (strlen($file) > 4 && substr($file,-4) == '.gif') {
1169 array_push($icons, substr($file, 0, -4));
1173 $page->assign('icons', $icons);
1176 function handler_accounts(&$page)
1178 $page->changeTpl('admin/accounts.tpl');
1179 $page->assign('disabled', XDB
::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch,
1180 a.state = \'disabled\' AS disabled, a.comment
1182 WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags)
1183 ORDER BY a.hruid'));
1184 $page->assign('admins', XDB
::iterator('SELECT a.hruid
1187 ORDER BY a.hruid'));
1190 function handler_jobs(&$page, $id = -1)
1192 $page->changeTpl('admin/jobs.tpl');
1194 if (Env
::has('search')) {
1195 $res = XDB
::query("SELECT e.id, e.name, e.acronym
1196 FROM profile_job_enum AS e
1197 WHERE e.name LIKE CONCAT('% ', {?}, '%') OR e.acronym LIKE CONCAT('% ', {?}, '%')",
1198 Env
::t('job'), Env
::t('job'));
1200 if ($res->numRows() <= 20) {
1201 $page->assign('jobs', $res->fetchAllAssoc());
1203 $page->trigError("Il y a trop d'entreprises correspondant à ton choix. Affine-le !");
1206 $page->assign('askedJob', Env
::v('job'));
1210 if (Env
::has('edit')) {
1211 // TODO: use address and phone classes to update profile_job_enum and profile_phones once they are done.
1213 S
::assert_xsrf_token();
1214 $selectedJob = Env
::has('selectedJob');
1216 XDB
::execute("DELETE FROM profile_phones
1217 WHERE uid = {?} AND link_type = 'hq'",
1219 XDB
::execute("DELETE FROM profile_addresses
1220 WHERE jobid = {?} AND type = 'hq'",
1222 XDB
::execute('DELETE FROM profile_job_enum
1226 if (Env
::has('change')) {
1227 XDB
::execute('UPDATE profile_job
1230 Env
::i('newJobId'), $id);
1232 $page->trigSuccess("L'entreprise a bien été remplacée.");
1234 require_once 'profil.func.inc.php';
1235 require_once 'geocoding.inc.php';
1237 $display_tel = format_display_number(Env
::v('tel'), $error_tel);
1238 $display_fax = format_display_number(Env
::v('fax'), $error_fax);
1239 $gmapsGeocoder = new GMapsGeocoder();
1240 $address = array('text' => Env
::t('address'));
1241 $address = $gmapsGeocoder->getGeocodedAddress($address);
1242 Geocoder
::getAreaId($address, 'administrativeArea');
1243 Geocoder
::getAreaId($address, 'subAdministrativeArea');
1244 Geocoder
::getAreaId($address, 'locality');
1246 XDB
::execute('UPDATE profile_job_enum
1247 SET name = {?}, acronym = {?}, url = {?}, email = {?},
1248 NAF_code = {?}, AX_code = {?}, holdingid = {?}
1250 Env
::t('name'), Env
::t('acronym'), Env
::t('url'), Env
::t('email'),
1251 Env
::t('NAF_code'), Env
::i('AX_code'), Env
::i('holdingId'), $id);
1253 XDB
::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type,
1254 search_tel, display_tel, pub)
1255 VALUES ({?}, 'hq', 0, 0, 'fixed', {?}, {?}, 'public'),
1256 ({?}, 'hq', 0, 1, 'fax', {?}, {?}, 'public')",
1257 $id, format_phone_number(Env
::v('tel')), $display_tel,
1258 $id, format_phone_number(Env
::v('fax')), $display_fax);
1260 XDB
::execute("INSERT INTO profile_addresses (jobid, type, id, accuracy,
1261 text, postalText, postalCode, localityId,
1262 subAdministrativeAreaId, administrativeAreaId,
1263 countryId, latitude, longitude, updateTime,
1264 north, south, east, west)
1265 VALUES ({?}, 'hq', 0, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
1266 {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?})",
1267 $id, $address['accuracy'], $address['text'], $address['postalText'],
1268 $address['postalCode'], $address['localityId'],
1269 $address['subAdministrativeAreaId'], $address['administrativeAreaId'],
1270 $address['countryId'], $address['latitude'], $address['longitude'],
1271 $address['updateTime'], $address['north'], $address['south'],
1272 $address['east'], $address['west']);
1274 $page->trigSuccess("L'entreprise a bien été mise à jour.");
1278 if (!Env
::has('change') && $id != -1) {
1279 $res = XDB
::query("SELECT e.id, e.name, e.acronym, e.url, e.email, e.NAF_code, e.AX_code,
1280 h.id AS holdingId, h.name AS holdingName, h.acronym AS holdingAcronym,
1281 t.display_tel AS tel, f.display_tel AS fax, a.text AS address
1282 FROM profile_job_enum AS e
1283 LEFT JOIN profile_job_enum AS h ON (e.holdingid = h.id)
1284 LEFT JOIN profile_phones AS t ON (t.uid = e.id AND link_type = 'hq' AND tel_id = 0)
1285 LEFT JOIN profile_phones AS f ON (f.uid = e.id AND link_type = 'hq' AND tel_id = 1)
1286 LEFT JOIN profile_addresses AS a ON (a.jobid = e.id AND a.type = 'hq')
1290 if ($res->numRows() == 0) {
1291 $page->trigError('Auncune entreprise ne correspond à cet identifiant.');
1293 $page->assign('selectedJob', $res->fetchOneAssoc());
1299 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: