2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 'admin' => $this->make_hook('default', AUTH_MDP
, 'admin'),
28 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP
, 'admin'),
29 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP
, 'admin'),
30 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP
, 'admin'),
31 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP
, 'admin'),
32 'admin/logger' => $this->make_hook('logger', AUTH_MDP
, 'admin'),
33 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP
, 'admin'),
34 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP
, 'admin'),
35 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP
, 'admin'),
36 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP
, 'admin'),
37 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP
, 'admin'),
38 'admin/skins' => $this->make_hook('skins', AUTH_MDP
, 'admin'),
39 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP
, 'admin'),
40 'admin/user' => $this->make_hook('user', AUTH_MDP
, 'admin'),
41 'admin/validate' => $this->make_hook('validate', AUTH_MDP
, 'admin'),
42 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP
, 'admin'),
43 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP
, 'admin'),
47 function handler_default(&$page)
49 $page->changeTpl('admin/index.tpl');
50 $page->assign('xorg_title','Polytechnique.org - Administration');
53 function handler_postfix_delayed(&$page)
55 $page->changeTpl('admin/postfix_delayed.tpl');
56 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
58 if (Env
::has('del')) {
60 XDB
::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
61 $page->trig($crc." verra tous ses mails supprimés !");
62 } elseif (Env
::has('ok')) {
64 XDB
::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
65 $page->trig($crc." a le droit de passer !");
69 "SELECT crc, nb, update_time, create_time,
70 FIND_IN_SET('del', release) AS del,
71 FIND_IN_SET('ok', release) AS ok
74 ORDER BY release != ''");
76 $page->assign_by_ref('mails', $sql);
79 function handler_postfix_regexpsbounces(&$page, $new = null
) {
80 $page->changeTpl('admin/emails_bounces_re.tpl');
81 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces');
82 $page->assign('new', $new);
84 if (Post
::has('submit')) {
85 foreach (Env
::v('lvl') as $id=>$val) {
87 "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})",
88 $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id]
93 $page->assign('bre', XDB
::iterator("SELECT * FROM emails_bounces_re ORDER BY pos"));
96 function handler_logger(&$page) {
97 $page->changeTpl('logger-view.tpl');
98 $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
99 require_once('diogenes/diogenes.logger-view.inc.php');
101 if (!Env
::has('logauth')) {
102 $_REQUEST['logauth'] = 'native';
105 $logview = new DiogenesLoggerView
;
106 $logview->run($page);
108 $page->fakeDiogenes();
111 function handler_user(&$page, $login = false
) {
112 $page->changeTpl('admin/utilisateurs.tpl');
113 $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log');
114 require_once("emails.inc.php");
115 require_once("user.func.inc.php");
117 if (S
::has('suid')) {
118 $page->kill("déjà en SUID !!!");
121 if (Env
::has('user_id')) {
122 $login = get_user_login(Env
::i('user_id'));
123 } elseif (Env
::has('login')) {
124 $login = get_user_login(Env
::v('login'));
127 if(Env
::has('logs_button') && $login) {
128 pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
131 if (Env
::has('ax_button') && $login) {
132 pl_redirect("admin/synchro_ax/$login");
135 if(Env
::has('suid_button') && $login) {
136 $_SESSION['log']->log("suid_start", "login by ".S
::v('forlife'));
137 $_SESSION['suid'] = $_SESSION;
138 $r = XDB
::query("SELECT id FROM aliases WHERE alias={?}", $login);
139 if($uid = $r->fetchOneCell()) {
140 start_connexion($uid,true
);
146 $r = XDB
::query("SELECT *, a.alias AS forlife, u.flags AS sexe
147 FROM auth_user_md5 AS u
148 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
149 $mr = $r->fetchOneAssoc();
151 $redirect = new Redirect($mr['user_id']);
153 // Check if there was a submission
154 foreach($_POST as $key => $val) {
157 $email = trim(Env
::v('email'));
158 if (!isvalid_email_redirection($email)) {
159 $page->trig("invalid email $email");
161 $redirect->add_email($email);
162 $page->trig("Ajout de $email effectué");
168 $redirect->delete_email($val);
174 XDB
::execute("DELETE FROM aliases WHERE id={?} AND alias={?}
175 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
176 fix_bestalias($mr['user_id']);
177 $page->trig($val." a été supprimé");
182 $redirect->modify_one_email($val, true
);
185 case "deactivate_fwd":
187 $redirect->modify_one_email($val, false
);
191 XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
192 $mr['user_id'], Env
::v('email'));
196 // 'bestalias' is the first bit of the set : 1
197 // 255 is the max for flags (8 sets max)
198 XDB
::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
199 XDB
::execute("UPDATE aliases
201 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
207 require_once('secure_hash.inc.php');
208 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
hash_encrypt(Env
::v('newpass_clair')) : Env
::v('passw');
209 $naiss = Env
::v('naissanceN');
210 $deces = Env
::v('decesN');
211 $perms = Env
::v('permsN');
212 $prenm = Env
::v('prenomN');
213 $nom = Env
::v('nomN');
214 $promo = Env
::i('promoN');
215 $sexe = Env
::v('sexeN');
216 $comm = Env
::v('commentN');
218 $query = "UPDATE auth_user_md5 SET
219 naissance = '$naiss',
221 password = '$pass_encrypted',
223 prenom = '".addslashes($prenm)."',
224 nom = '".addslashes($nom)."',
227 comment = '".addslashes($comm)."'
228 WHERE user_id = '{$mr['user_id']}'";
229 if (XDB
::execute($query)) {
230 user_reindex($mr['user_id']);
232 require_once("diogenes/diogenes.hermes.inc.php");
233 $mailer = new HermesMailer();
234 $mailer->setFrom("webmaster@polytechnique.org");
235 $mailer->addTo("web@polytechnique.org");
236 $mailer->setSubject("INTERVENTION de ".S
::v('forlife'));
237 $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
240 $page->trig("updaté correctement.");
242 if (Env
::v('nomusageN') != $mr['nom_usage']) {
243 require_once('nomusage.inc.php');
244 set_new_usage($mr['user_id'], Env
::v('nomusageN'), make_username(Env
::v('prenomN'), Env
::v('nomusageN')));
246 $r = XDB
::query("SELECT *, a.alias AS forlife, u.flags AS sexe
247 FROM auth_user_md5 AS u
248 INNER JOIN aliases AS a ON (u.user_id=a.id)
249 WHERE user_id = {?}", $mr['user_id']);
250 $mr = $r->fetchOneAssoc();
253 // DELETE FROM auth_user_md5
255 user_clear_all_subs($mr['user_id']);
256 $page->trig("'{$mr['user_id']}' a été désinscrit !");
257 require_once("diogenes/diogenes.hermes.inc.php");
258 $mailer = new HermesMailer();
259 $mailer->setFrom("webmaster@polytechnique.org");
260 $mailer->addTo("web@polytechnique.org");
261 $mailer->setSubject("INTERVENTION de ".S
::v('forlife'));
262 $mailer->setTxtBody("\nUtilisateur $login effacé");
268 $res = XDB
::query("SELECT UNIX_TIMESTAMP(start), host
270 WHERE uid={?} AND suid=0
272 LIMIT 1", $mr['user_id']);
273 list($lastlogin,$host) = $res->fetchOneRow();
274 $page->assign('lastlogin', $lastlogin);
275 $page->assign('host', $host);
277 $page->assign('aliases', XDB
::iterator(
278 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
280 WHERE id = {?} AND type!='homonyme'
281 ORDER BY type!= 'a_vie'", $mr["user_id"]));
282 $page->assign('xorgmails', $xorgmails);
283 $page->assign('email_panne', $email_panne);
284 $page->assign('emails',$redirect->emails
);
286 $page->assign('mr',$mr);
289 function handler_homonyms(&$page, $op = 'list', $target = null
) {
290 $page->changeTpl('admin/homonymes.tpl');
291 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
292 require_once("homonymes.inc.php");
295 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
298 $page->assign('nom',$nom);
299 $page->assign('prenom',$prenom);
300 $page->assign('forlife',$forlife);
301 $page->assign('loginbis',$loginbis);
305 $page->assign('op',$op);
306 $page->assign('target',$target);
308 // on a un $target valide, on prepare les mails
311 // on examine l'op a effectuer
314 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
315 switch_bestalias($target, $loginbis);
319 switch_bestalias($target, $loginbis);
320 XDB
::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
321 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
322 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
329 $res = XDB
::iterator(
330 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
332 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
333 IF(h.homonyme_id=s.id, a.type, NULL) AS type
335 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
336 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
337 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
338 WHERE a.type='homonyme' OR a.expire!=''
339 ORDER BY a.alias,promo");
341 while ($tab = $res->next()) {
342 $hnymes[$tab['homonyme']][] = $tab;
344 $page->assign_by_ref('hnymes',$hnymes);
348 function handler_ax_xorg(&$page) {
349 $page->changeTpl('admin/ax-xorg.tpl');
350 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
352 // liste des différences
354 'SELECT u.promo,u.nom AS nom,u.prenom AS prenom,ia.nom AS nomax,ia.prenom AS prenomax,u.matricule AS mat,ia.matricule_ax AS matax
355 FROM auth_user_md5 AS u
356 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
357 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
358 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
359 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
360 ORDER BY u.promo,u.nom,u.prenom');
361 $page->assign('diffs', $res->fetchAllAssoc());
363 // gens à l'ax mais pas chez nous
365 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
366 FROM identification_ax as ia
367 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
368 WHERE u.nom IS NULL');
369 $page->assign('mank', $res->fetchAllAssoc());
371 // gens chez nous et pas à l'ax
372 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
373 $page->assign('plus', $res->fetchAllAssoc());
376 function handler_deaths(&$page, $promo = 0, $validate = false
) {
377 $page->changeTpl('admin/deces_promo.tpl');
378 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
381 $promo = Env
::i('promo');
382 if (Env
::has('sub10')) $promo -= 10;
383 if (Env
::has('sub01')) $promo -= 1;
384 if (Env
::has('add01')) $promo +
= 1;
385 if (Env
::has('add10')) $promo +
= 10;
387 $page->assign('promo',$promo);
390 $new_deces = array();
391 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
392 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
394 if($val == $deces ||
empty($val)) continue;
395 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
396 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
397 if($deces=='0000-00-00' or empty($deces)) {
398 require_once('notifs.inc.php');
399 register_watch_op($uid, WATCH_DEATH
, $val);
400 require_once('user.func.inc.php');
401 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
404 $page->assign('new_deces',$new_deces);
407 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
408 $page->assign('decedes', $res);
411 function handler_synchro_ax(&$page, $user = null
, $action = null
) {
412 $page->changeTpl('admin/synchro_ax.tpl');
413 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
415 require_once('synchro_ax.inc.php');
417 if (is_ax_key_missing()) {
418 $page->assign('no_private_key', true
);
422 require_once('user.func.inc.php');
425 $login = get_user_forlife($user);
427 if (Env
::has('user')) {
428 $login = get_user_forlife(Env
::v('user'));
429 if ($login === false
) {
434 if (Env
::has('mat')) {
438 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
439 WHERE matricule={?}", Env
::i('mat'));
440 $login = $res->fetchOneCell();
444 if ($action == 'import') {
445 ax_synchronize($login, S
::v('uid'));
447 // get details from user, but looking only info that can be seen by ax
448 $user = get_user_details($login, S
::v('uid'), 'ax');
449 $userax= get_user_ax($user['matricule_ax']);
450 require_once 'profil.func.inc.php';
451 $diff = diff_user_details($userax, $user, 'ax');
453 $page->assign('x', $user);
454 $page->assign('diff', $diff);
458 function handler_validate(&$page) {
459 $page->changeTpl('admin/valider.tpl');
460 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
461 require_once("validations.inc.php");
463 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
464 $req = Validate
::get_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
465 if($req) { $req->handle_formu(); }
468 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
469 while (($a = $r->next()) && $a['Field'] != 'category');
470 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
473 if (Post
::has('hide')) {
475 foreach ($categories as $cat)
476 if (!Post
::v($cat)) {
480 setcookie('hide_requests', join(',',$hide), time()+
(count($hide)?
25920000:(-3600)), '/', '', 0);
481 } elseif (Env
::has('hide_requests')) {
482 foreach (explode(',',Env
::v('hide_requests')) as $hide_type)
483 $hidden[$hide_type] = true
;
485 $page->assign('hide_requests', $hidden);
487 $page->assign('vit', new ValidateIterator());
489 function handler_validate_answers(&$page, $action = 'list', $id = null
) {
490 require_once('../classes/PLTableEditor.php');
491 $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
492 $page->assign('title', 'Gestion des réponses automatiques');
493 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
494 $table_editor->describe('category','catégorie',true
);
495 $table_editor->describe('title','titre',true
);
496 $table_editor->describe('answer','texte',false
);
497 $table_editor->apply($page, $action, $id);
499 function handler_skins(&$page, $action = 'list', $id = null
) {
500 require_once('../classes/PLTableEditor.php');
501 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
502 $page->assign('title', 'Gestion des skins');
503 $table_editor = new PLTableEditor('admin/skins','skins','id');
504 $table_editor->describe('name','nom',true
);
505 $table_editor->describe('skin_tpl','nom du template',true
);
506 $table_editor->describe('auteur','auteur',false
);
507 $table_editor->describe('comment','commentaire',true
);
508 $table_editor->describe('date','date',false
);
509 $table_editor->describe('ext','extension du screenshot',false
);
510 $table_editor->apply($page, $action, $id);
512 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
) {
513 require_once('../classes/PLTableEditor.php');
514 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
515 $page->assign('title', 'Blacklist de postfix');
516 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
517 $table_editor->describe('reject_text','Texte de rejet',true
);
518 $table_editor->describe('email','email',true
);
519 $table_editor->apply($page, $action, $id);
521 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
) {
522 require_once('../classes/PLTableEditor.php');
523 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
524 $page->assign('title', 'Whitelist de postfix');
525 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
526 $table_editor->describe('email','email',true
);
527 $table_editor->apply($page, $action, $id);
529 function handler_logger_actions(&$page, $action = 'list', $id = null
) {
530 require_once('../classes/PLTableEditor.php');
531 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
532 $page->assign('title', 'Gestion des actions de logger');
533 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
534 $table_editor->describe('text','intitulé',true
);
535 $table_editor->describe('description','description',true
);
536 $table_editor->apply($page, $action, $id);
538 function handler_downtime(&$page, $action = 'list', $id = null
) {
539 require_once('../classes/PLTableEditor.php');
540 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
541 $page->assign('title', 'Gestion des coupures');
542 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
543 $table_editor->describe('debut','date',true
);
544 $table_editor->describe('duree','durée',false
);
545 $table_editor->describe('resume','résumé',true
);
546 $table_editor->describe('services','services affectés',true
);
547 $table_editor->describe('description','description',false
);
548 $table_editor->apply($page, $action, $id);
550 function handler_wiki(&$page, $action='list') {
551 require_once 'wiki.inc.php';
554 if ($action == 'update') {
555 $perms_read = Post
::v('read');
556 $perms_edot = Post
::v('edit');
557 if ($perms_read ||
$perms_edit) {
558 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
559 $wiki_page = str_replace('_', '/', $wiki_page);
560 if (!$perms_read ||
!$perms_edit)
561 list($perms0, $perms1) = wiki_get_perms($wiki_page);
563 $perms0 = $perms_read;
565 $perms1 = $perms_edit;
566 wiki_set_perms($wiki_page, $perms0, $perms1);
571 $perms = wiki_perms_options();
573 // list wiki pages and their perms
574 $wiki_pages = array();
575 $dir = wiki_work_dir();
577 if ($dh = opendir($dir)) {
578 while (($file = readdir($dh)) !== false
) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
579 list($read,$edit) = wiki_get_perms($file);
580 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
587 $page->changeTpl('admin/wiki.tpl');
588 $page->assign('wiki_pages', $wiki_pages);
589 $page->assign('perms_opts', $perms);