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 require_once dirname(__FILE__
).'/../classes/LoggerView.php';
99 if (!Env
::has('logauth')) {
100 $_REQUEST['logauth'] = 'native';
103 $logview = new LoggerView
;
104 $logview->run($page);
106 $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
109 function handler_user(&$page, $login = false
) {
110 $page->changeTpl('admin/utilisateurs.tpl');
111 $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log');
112 require_once("emails.inc.php");
113 require_once("user.func.inc.php");
115 if (S
::has('suid')) {
116 $page->kill("déjà en SUID !!!");
119 if (Env
::has('user_id')) {
120 $login = get_user_login(Env
::i('user_id'));
121 } elseif (Env
::has('login')) {
122 $login = get_user_login(Env
::v('login'));
125 if(Env
::has('logs_button') && $login) {
126 pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
129 if (Env
::has('ax_button') && $login) {
130 pl_redirect("admin/synchro_ax/$login");
133 if(Env
::has('suid_button') && $login) {
134 $_SESSION['log']->log("suid_start", "login by ".S
::v('forlife'));
135 $_SESSION['suid'] = $_SESSION;
136 $r = XDB
::query("SELECT id FROM aliases WHERE alias={?}", $login);
137 if($uid = $r->fetchOneCell()) {
138 start_connexion($uid,true
);
144 $r = XDB
::query("SELECT *, a.alias AS forlife, u.flags AS sexe
145 FROM auth_user_md5 AS u
146 INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
147 $mr = $r->fetchOneAssoc();
149 $redirect = new Redirect($mr['user_id']);
151 // Check if there was a submission
152 foreach($_POST as $key => $val) {
155 $email = trim(Env
::v('email'));
156 if (!isvalid_email_redirection($email)) {
157 $page->trig("invalid email $email");
159 $redirect->add_email($email);
160 $page->trig("Ajout de $email effectué");
166 $redirect->delete_email($val);
172 XDB
::execute("DELETE FROM aliases WHERE id={?} AND alias={?}
173 AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val);
174 fix_bestalias($mr['user_id']);
175 $page->trig($val." a été supprimé");
180 $redirect->modify_one_email($val, true
);
183 case "deactivate_fwd":
185 $redirect->modify_one_email($val, false
);
189 XDB
::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')",
190 $mr['user_id'], Env
::v('email'));
194 // 'bestalias' is the first bit of the set : 1
195 // 255 is the max for flags (8 sets max)
196 XDB
::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']);
197 XDB
::execute("UPDATE aliases
199 WHERE id={?} AND alias={?}", $mr['user_id'], $val);
205 require_once('secure_hash.inc.php');
206 $pass_encrypted = Env
::v('newpass_clair') != "********" ?
hash_encrypt(Env
::v('newpass_clair')) : Env
::v('passw');
207 $naiss = Env
::v('naissanceN');
208 $deces = Env
::v('decesN');
209 $perms = Env
::v('permsN');
210 $prenm = Env
::v('prenomN');
211 $nom = Env
::v('nomN');
212 $promo = Env
::i('promoN');
213 $sexe = Env
::v('sexeN');
214 $comm = Env
::v('commentN');
216 $query = "UPDATE auth_user_md5 SET
217 naissance = '$naiss',
219 password = '$pass_encrypted',
221 prenom = '".addslashes($prenm)."',
222 nom = '".addslashes($nom)."',
225 comment = '".addslashes($comm)."'
226 WHERE user_id = '{$mr['user_id']}'";
227 if (XDB
::execute($query)) {
228 user_reindex($mr['user_id']);
230 require_once("diogenes/diogenes.hermes.inc.php");
231 $mailer = new HermesMailer();
232 $mailer->setFrom("webmaster@polytechnique.org");
233 $mailer->addTo("web@polytechnique.org");
234 $mailer->setSubject("INTERVENTION de ".S
::v('forlife'));
235 $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
238 $page->trig("updaté correctement.");
240 if (Env
::v('nomusageN') != $mr['nom_usage']) {
241 require_once('nomusage.inc.php');
242 set_new_usage($mr['user_id'], Env
::v('nomusageN'), make_username(Env
::v('prenomN'), Env
::v('nomusageN')));
244 $r = XDB
::query("SELECT *, a.alias AS forlife, u.flags AS sexe
245 FROM auth_user_md5 AS u
246 INNER JOIN aliases AS a ON (u.user_id=a.id)
247 WHERE user_id = {?}", $mr['user_id']);
248 $mr = $r->fetchOneAssoc();
251 // DELETE FROM auth_user_md5
253 user_clear_all_subs($mr['user_id']);
254 $page->trig("'{$mr['user_id']}' a été désinscrit !");
255 require_once("diogenes/diogenes.hermes.inc.php");
256 $mailer = new HermesMailer();
257 $mailer->setFrom("webmaster@polytechnique.org");
258 $mailer->addTo("web@polytechnique.org");
259 $mailer->setSubject("INTERVENTION de ".S
::v('forlife'));
260 $mailer->setTxtBody("\nUtilisateur $login effacé");
266 $res = XDB
::query("SELECT UNIX_TIMESTAMP(start), host
268 WHERE uid={?} AND suid=0
270 LIMIT 1", $mr['user_id']);
271 list($lastlogin,$host) = $res->fetchOneRow();
272 $page->assign('lastlogin', $lastlogin);
273 $page->assign('host', $host);
275 $page->assign('aliases', XDB
::iterator(
276 "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
278 WHERE id = {?} AND type!='homonyme'
279 ORDER BY type!= 'a_vie'", $mr["user_id"]));
280 $page->assign('xorgmails', $xorgmails);
281 $page->assign('email_panne', $email_panne);
282 $page->assign('emails',$redirect->emails
);
284 $page->assign('mr',$mr);
287 function handler_homonyms(&$page, $op = 'list', $target = null
) {
288 $page->changeTpl('admin/homonymes.tpl');
289 $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
290 require_once("homonymes.inc.php");
293 if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) {
296 $page->assign('nom',$nom);
297 $page->assign('prenom',$prenom);
298 $page->assign('forlife',$forlife);
299 $page->assign('loginbis',$loginbis);
303 $page->assign('op',$op);
304 $page->assign('target',$target);
306 // on a un $target valide, on prepare les mails
309 // on examine l'op a effectuer
312 send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
313 switch_bestalias($target, $loginbis);
317 switch_bestalias($target, $loginbis);
318 XDB
::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
319 XDB
::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
320 send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
327 $res = XDB
::iterator(
328 "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife,
330 IF(h.homonyme_id=s.id, a.expire, NULL) AS expire,
331 IF(h.homonyme_id=s.id, a.type, NULL) AS type
333 LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id)
334 INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie')
335 INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id)
336 WHERE a.type='homonyme' OR a.expire!=''
337 ORDER BY a.alias,promo");
339 while ($tab = $res->next()) {
340 $hnymes[$tab['homonyme']][] = $tab;
342 $page->assign_by_ref('hnymes',$hnymes);
346 function handler_ax_xorg(&$page) {
347 $page->changeTpl('admin/ax-xorg.tpl');
348 $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
350 // liste des différences
352 '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
353 FROM auth_user_md5 AS u
354 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax
355 WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom)
356 AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro))
357 OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1)
358 ORDER BY u.promo,u.nom,u.prenom');
359 $page->assign('diffs', $res->fetchAllAssoc());
361 // gens à l'ax mais pas chez nous
363 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
364 FROM identification_ax as ia
365 LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax
366 WHERE u.nom IS NULL');
367 $page->assign('mank', $res->fetchAllAssoc());
369 // gens chez nous et pas à l'ax
370 $res = XDB
::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
371 $page->assign('plus', $res->fetchAllAssoc());
374 function handler_deaths(&$page, $promo = 0, $validate = false
) {
375 $page->changeTpl('admin/deces_promo.tpl');
376 $page->assign('xorg_title','Polytechnique.org - Administration - Deces');
379 $promo = Env
::i('promo');
380 if (Env
::has('sub10')) $promo -= 10;
381 if (Env
::has('sub01')) $promo -= 1;
382 if (Env
::has('add01')) $promo +
= 1;
383 if (Env
::has('add10')) $promo +
= 10;
385 $page->assign('promo',$promo);
388 $new_deces = array();
389 $res = XDB
::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
390 while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
392 if($val == $deces ||
empty($val)) continue;
393 XDB
::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
394 $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
395 if($deces=='0000-00-00' or empty($deces)) {
396 require_once('notifs.inc.php');
397 register_watch_op($uid, WATCH_DEATH
, $val);
398 require_once('user.func.inc.php');
399 user_clear_all_subs($uid, false
); // by default, dead ppl do not loose their email
402 $page->assign('new_deces',$new_deces);
405 $res = XDB
::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo);
406 $page->assign('decedes', $res);
409 function handler_synchro_ax(&$page, $user = null
, $action = null
) {
410 $page->changeTpl('admin/synchro_ax.tpl');
411 $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX');
413 require_once('synchro_ax.inc.php');
415 if (is_ax_key_missing()) {
416 $page->assign('no_private_key', true
);
420 require_once('user.func.inc.php');
423 $login = get_user_forlife($user);
425 if (Env
::has('user')) {
426 $login = get_user_forlife(Env
::v('user'));
427 if ($login === false
) {
432 if (Env
::has('mat')) {
436 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
437 WHERE matricule={?}", Env
::i('mat'));
438 $login = $res->fetchOneCell();
442 if ($action == 'import') {
443 ax_synchronize($login, S
::v('uid'));
445 // get details from user, but looking only info that can be seen by ax
446 $user = get_user_details($login, S
::v('uid'), 'ax');
447 $userax= get_user_ax($user['matricule_ax']);
448 require_once 'profil.func.inc.php';
449 $diff = diff_user_details($userax, $user, 'ax');
451 $page->assign('x', $user);
452 $page->assign('diff', $diff);
456 function handler_validate(&$page) {
457 $page->changeTpl('admin/valider.tpl');
458 $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
459 require_once("validations.inc.php");
461 if(Env
::has('uid') && Env
::has('type') && Env
::has('stamp')) {
462 $req = Validate
::get_request(Env
::v('uid'), Env
::v('type'), Env
::v('stamp'));
463 if($req) { $req->handle_formu(); }
466 $r = XDB
::iterator('SHOW COLUMNS FROM requests_answers');
467 while (($a = $r->next()) && $a['Field'] != 'category');
468 $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1))));
471 if (Post
::has('hide')) {
473 foreach ($categories as $cat)
474 if (!Post
::v($cat)) {
478 setcookie('hide_requests', join(',',$hide), time()+
(count($hide)?
25920000:(-3600)), '/', '', 0);
479 } elseif (Env
::has('hide_requests')) {
480 foreach (explode(',',Env
::v('hide_requests')) as $hide_type)
481 $hidden[$hide_type] = true
;
483 $page->assign('hide_requests', $hidden);
485 $page->assign('vit', new ValidateIterator());
487 function handler_validate_answers(&$page, $action = 'list', $id = null
) {
488 require_once('../classes/PLTableEditor.php');
489 $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
490 $page->assign('title', 'Gestion des réponses automatiques');
491 $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
492 $table_editor->describe('category','catégorie',true
);
493 $table_editor->describe('title','titre',true
);
494 $table_editor->describe('answer','texte',false
);
495 $table_editor->apply($page, $action, $id);
497 function handler_skins(&$page, $action = 'list', $id = null
) {
498 require_once('../classes/PLTableEditor.php');
499 $page->assign('xorg_title','Polytechnique.org - Administration - Skins');
500 $page->assign('title', 'Gestion des skins');
501 $table_editor = new PLTableEditor('admin/skins','skins','id');
502 $table_editor->describe('name','nom',true
);
503 $table_editor->describe('skin_tpl','nom du template',true
);
504 $table_editor->describe('auteur','auteur',false
);
505 $table_editor->describe('comment','commentaire',true
);
506 $table_editor->describe('date','date',false
);
507 $table_editor->describe('ext','extension du screenshot',false
);
508 $table_editor->apply($page, $action, $id);
510 function handler_postfix_blacklist(&$page, $action = 'list', $id = null
) {
511 require_once('../classes/PLTableEditor.php');
512 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
513 $page->assign('title', 'Blacklist de postfix');
514 $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true
);
515 $table_editor->describe('reject_text','Texte de rejet',true
);
516 $table_editor->describe('email','email',true
);
517 $table_editor->apply($page, $action, $id);
519 function handler_postfix_whitelist(&$page, $action = 'list', $id = null
) {
520 require_once('../classes/PLTableEditor.php');
521 $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
522 $page->assign('title', 'Whitelist de postfix');
523 $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true
);
524 $table_editor->describe('email','email',true
);
525 $table_editor->apply($page, $action, $id);
527 function handler_logger_actions(&$page, $action = 'list', $id = null
) {
528 require_once('../classes/PLTableEditor.php');
529 $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
530 $page->assign('title', 'Gestion des actions de logger');
531 $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
532 $table_editor->describe('text','intitulé',true
);
533 $table_editor->describe('description','description',true
);
534 $table_editor->apply($page, $action, $id);
536 function handler_downtime(&$page, $action = 'list', $id = null
) {
537 require_once('../classes/PLTableEditor.php');
538 $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
539 $page->assign('title', 'Gestion des coupures');
540 $table_editor = new PLTableEditor('admin/downtime','coupures','id');
541 $table_editor->describe('debut','date',true
);
542 $table_editor->describe('duree','durée',false
);
543 $table_editor->describe('resume','résumé',true
);
544 $table_editor->describe('services','services affectés',true
);
545 $table_editor->describe('description','description',false
);
546 $table_editor->apply($page, $action, $id);
548 function handler_wiki(&$page, $action='list') {
549 require_once 'wiki.inc.php';
552 if ($action == 'update') {
553 $perms_read = Post
::v('read');
554 $perms_edot = Post
::v('edit');
555 if ($perms_read ||
$perms_edit) {
556 foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
557 $wiki_page = str_replace('_', '/', $wiki_page);
558 if (!$perms_read ||
!$perms_edit)
559 list($perms0, $perms1) = wiki_get_perms($wiki_page);
561 $perms0 = $perms_read;
563 $perms1 = $perms_edit;
564 wiki_set_perms($wiki_page, $perms0, $perms1);
569 $perms = wiki_perms_options();
571 // list wiki pages and their perms
572 $wiki_pages = array();
573 $dir = wiki_work_dir();
575 if ($dh = opendir($dir)) {
576 while (($file = readdir($dh)) !== false
) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
577 list($read,$edit) = wiki_get_perms($file);
578 $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
585 $page->changeTpl('admin/wiki.tpl');
586 $page->assign('wiki_pages', $wiki_pages);
587 $page->assign('perms_opts', $perms);