<?php
/***************************************************************************
- * Copyright (C) 2003-2006 Polytechnique.org *
+ * Copyright (C) 2003-2007 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'),
'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'),
'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'),
+ 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'),
'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'),
'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'),
'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'),
+ 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'),
'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'),
'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'),
'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'),
+ 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'),
);
}
function handler_postfix_delayed(&$page)
{
$page->changeTpl('admin/postfix_delayed.tpl');
- $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
+ $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés');
if (Env::has('del')) {
$crc = Env::v('crc');
XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc);
- $page->trig($crc." verra tous ses mails supprimés !");
+ $page->trig($crc." verra tous ses mails supprimés !");
} elseif (Env::has('ok')) {
$crc = Env::v('crc');
XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc);
$page->assign('session', $a = $res->fetchOneAssoc());
- $res = XDB::iterator('SELECT a.text, e.data, UNIX_TIMESTAMP(e.stamp) AS stamp
+ $res = XDB::iterator('SELECT a.text, e.data, e.stamp
FROM logger.events AS e
LEFT JOIN logger.actions AS a ON e.action=a.id
WHERE e.session={?}', $arg);
// get the requested sessions
$where = $this->_makeWhere($year, $month, $day, $loguid);
- $select = "SELECT s.id, UNIX_TIMESTAMP(s.start) as start, s.uid,
+ $select = "SELECT s.id, s.start, s.uid,
a.alias as username
FROM logger.sessions AS s
LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie')
}
$page->assign_by_ref('sessions', $sessions);
} else {
- $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
+ $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur");
}
}
- $page->changeTpl('logger-view.tpl');
+ $page->changeTpl('admin/logger-view.tpl');
$page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions');
}
require_once("user.func.inc.php");
if (S::has('suid')) {
- $page->kill("déjà en SUID !!!");
+ $page->kill("déjà en SUID !!!");
}
if (Env::has('user_id')) {
- $login = get_user_login(Env::i('user_id'));
+ $login = get_user_forlife(Env::i('user_id'));
if (empty($login)) {
$login = Env::i('user_id');
}
} elseif (Env::has('login')) {
- $login = get_user_login(Env::v('login'));
+ $login = get_user_forlife(Env::v('login'));
}
if(Env::has('logs_button') && $login) {
- pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m'));
+ pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m'));
}
if (Env::has('ax_button') && $login) {
if ($login) {
if (is_numeric($login)) {
- $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
+ $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe,
+ (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
FROM auth_user_md5 AS u
LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie')
WHERE u.user_id = {?}", $login);
} else {
- $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
+ $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe,
+ (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
FROM auth_user_md5 AS u
INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
}
$page->trig("invalid email $email");
} else {
$redirect->add_email($email);
- $page->trig("Ajout de $email effectué");
+ $page->trig("Ajout de $email effectué");
}
break;
WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')",
$mr['user_id'], $val);
fix_bestalias($mr['user_id']);
- $page->trig($val." a été supprimé");
+ $page->trig($val." a été supprimé");
}
break;
case "activate_fwd":
if (XDB::execute($query)) {
user_reindex($mr['user_id']);
- require_once("diogenes/diogenes.hermes.inc.php");
- $mailer = new HermesMailer();
- $mailer->setFrom("webmaster@polytechnique.org");
- $mailer->addTo("web@polytechnique.org");
- $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
- $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query));
+ $mailer = new PlMailer("admin/mail_intervention.tpl");
+ $mailer->assign("user", S::v('forlife'));
+ $mailer->assign("query", $query);
$mailer->send();
- $page->trig("updaté correctement.");
+ $page->trig("updaté correctement.");
}
if (Env::v('nomusageN') != $mr['nom_usage']) {
set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN')));
}
+ if (Env::v('decesN') != $mr['deces']) {
+ user_clear_all_subs($mr['user_id'], false);
+ }
$r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
FROM auth_user_md5 AS u
LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie')
// DELETE FROM auth_user_md5
case "u_kill":
user_clear_all_subs($mr['user_id']);
- $page->trig("'{$mr['user_id']}' a été désinscrit !");
- require_once("diogenes/diogenes.hermes.inc.php");
- $mailer = new HermesMailer();
- $mailer->setFrom("webmaster@polytechnique.org");
- $mailer->addTo("web@polytechnique.org");
- $mailer->setSubject("INTERVENTION de ".S::v('forlife'));
- $mailer->setTxtBody("\nUtilisateur $login effacé");
+ $page->trig("'{$mr['user_id']}' a été désinscrit !");
+ $mailer = new PlMailer("admin/mail_intervention.tpl");
+ $mailer->assign("user", S::v('forlife'));
+ $mailer->assign("query", "\nUtilisateur $login désinscrit");
$mailer->send();
break;
}
}
- $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host
- FROM logger.sessions
- WHERE uid={?} AND suid=0
- ORDER BY start DESC
- LIMIT 1", $mr['user_id']);
+ $res = XDB::query("SELECT start, host
+ FROM logger.sessions
+ WHERE uid={?} AND suid=0
+ ORDER BY start DESC
+ LIMIT 1", $mr['user_id']);
list($lastlogin,$host) = $res->fetchOneRow();
$page->assign('lastlogin', $lastlogin);
$page->assign('host', $host);
+ $res = XDB::query("SELECT alias
+ FROM virtual
+ INNER JOIN virtual_redirect USING(vid)
+ WHERE type = 'user' AND redirect LIKE '" . $login . "@%'");
+ if ($res->numRows()) {
+ $page->assign('virtual', $res->fetchOneCell());
+ }
+
$page->assign('aliases', XDB::iterator(
"SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire
FROM aliases
$page->assign('mr',$mr);
}
}
+
+ function getMatricule($line, $key)
+ {
+ $mat = $line['matricule'];
+ $year = intval(substr($mat, 0, 3));
+ $rang = intval(substr($mat, 3, 3));
+ if ($year > 200) { $year /= 10; };
+ if ($year < 96) {
+ return null;
+ } else {
+ return sprintf('%04u%04u', 1900+$year, $rang);
+ }
+ }
+
+ function handler_promo(&$page, $action = null, $promo = null)
+ {
+ if (Env::has('promo')) {
+ if(Env::i('promo') > 1900 && Env::i('promo') < 2050) {
+ $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax';
+ pl_redirect('admin/promo/' . $action . '/' . Env::i('promo'));
+ } else {
+ $page->trig('Promo non valide');
+ }
+ }
+
+ $page->changeTpl('admin/promo.tpl');
+ if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) {
+ $page->assign('promo', $promo);
+ } else {
+ return;
+ }
+
+ $importer = new CSVImporter('auth_user_md5', 'matricule');
+ $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule'));
+ switch ($action) {
+ case 'add':
+ $fields = array('nom', 'nom_ini', 'prenom',
+ 'prenom_ini', 'promo', 'promo_sortie', 'flags',
+ 'matricule', 'matricule_ax', 'perms');
+ $importer->forceValue('promo', $promo);
+ $importer->forceValue('promo_sortie', $promo + 3);
+ break;
+ case 'ax':
+ $fields = array('matricule', 'matricule_ax');
+ break;
+ }
+ $importer->apply($page, "admin/promo/$action/$promo", $fields);
+ }
+
function handler_homonyms(&$page, $op = 'list', $target = null) {
$page->changeTpl('admin/homonymes.tpl');
$page->assign('xorg_title','Polytechnique.org - Administration - Homonymes');
// on examine l'op a effectuer
switch ($op) {
case 'mail':
- send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
- switch_bestalias($target, $loginbis);
+ send_warning_homonyme($prenom, $nom, $forlife, $loginbis);
+ switch_bestalias($target, $loginbis);
$op = 'list';
break;
case 'correct':
- switch_bestalias($target, $loginbis);
+ switch_bestalias($target, $loginbis);
XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis);
XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target);
- send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
+ send_robot_homonyme($prenom, $nom, $forlife, $loginbis);
$op = 'list';
break;
}
$page->changeTpl('admin/ax-xorg.tpl');
$page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org');
- // liste des différences
+ // liste des différences
$res = XDB::query(
'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
FROM auth_user_md5 AS u
ORDER BY u.promo,u.nom,u.prenom');
$page->assign('diffs', $res->fetchAllAssoc());
- // gens à l'ax mais pas chez nous
+ // gens à l'ax mais pas chez nous
$res = XDB::query(
'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom
FROM identification_ax as ia
WHERE u.nom IS NULL');
$page->assign('mank', $res->fetchAllAssoc());
- // gens chez nous et pas à l'ax
+ // gens chez nous et pas à l'ax
$res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL');
$page->assign('plus', $res->fetchAllAssoc());
}
$res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo);
while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) {
$val = Env::v($mat);
- if($val == $deces || empty($val)) continue;
- XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
- $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
- if($deces=='0000-00-00' or empty($deces)) {
- require_once('notifs.inc.php');
- register_watch_op($uid, WATCH_DEATH, $val);
- require_once('user.func.inc.php');
- user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
- }
+ if($val == $deces || empty($val)) continue;
+ XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat);
+ $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val");
+ if($deces=='0000-00-00' or empty($deces)) {
+ require_once('notifs.inc.php');
+ register_watch_op($uid, WATCH_DEATH, $val);
+ require_once('user.func.inc.php');
+ user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email
+ }
}
$page->assign('new_deces',$new_deces);
}
function handler_validate(&$page, $action = 'list', $id = null) {
$page->changeTpl('admin/valider.tpl');
$page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande');
- require_once("validations.inc.php");
+ $page->addCssLink('nl.css');
+ require_once("validations.inc.php");
if ($action == 'edit' and !is_null($id)) {
$page->assign('preview_id', $id);
}
if(Env::has('uid') && Env::has('type') && Env::has('stamp')) {
- $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
+ $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp'));
if($req) { $req->handle_formu(); }
}
$page->assign('vit', new ValidateIterator());
}
function handler_validate_answers(&$page, $action = 'list', $id = null) {
- $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
- $page->assign('title', 'Gestion des réponses automatiques');
+ $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation');
+ $page->assign('title', 'Gestion des réponses automatiques');
$table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id');
- $table_editor->describe('category','catégorie',true);
+ $table_editor->describe('category','catégorie',true);
$table_editor->describe('title','titre',true);
$table_editor->describe('answer','texte',false);
$table_editor->apply($page, $action, $id);
$table_editor->describe('email','email',true);
$table_editor->apply($page, $action, $id);
}
+ function handler_mx_broken(&$page, $action = 'list', $id = null) {
+ $page->assign('xorg_title', 'Polytechnique.org - Administration - MX Défaillants');
+ $page->assign('title', 'MX Défaillant');
+ $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true);
+ $table_editor->describe('host', 'Masque', true);
+ $table_editor->describe('state', 'Niveau', true);
+ $table_editor->describe('text', 'Description du problème', false);
+ $table_editor->apply($page, $action, $id);
+ }
function handler_logger_actions(&$page, $action = 'list', $id = null) {
$page->assign('xorg_title','Polytechnique.org - Administration - Actions');
$page->assign('title', 'Gestion des actions de logger');
$table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id');
- $table_editor->describe('text','intitulé',true);
+ $table_editor->describe('text','intitulé',true);
$table_editor->describe('description','description',true);
$table_editor->apply($page, $action, $id);
}
$page->assign('title', 'Gestion des coupures');
$table_editor = new PLTableEditor('admin/downtime','coupures','id');
$table_editor->describe('debut','date',true);
- $table_editor->describe('duree','durée',false);
- $table_editor->describe('resume','résumé',true);
- $table_editor->describe('services','services affectés',true);
+ $table_editor->describe('duree','durée',false);
+ $table_editor->describe('resume','résumé',true);
+ $table_editor->describe('services','services affectés',true);
$table_editor->describe('description','description',false);
$table_editor->apply($page, $action, $id);
}
- function handler_wiki(&$page, $action='list') {
+
+ function handler_wiki(&$page, $action='list')
+ {
require_once 'wiki.inc.php';
// update wiki perms
while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
list($read,$edit) = wiki_get_perms($file);
$wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
+ if (is_file($dir . '/cache_' . wiki_filename($file) . '.tpl')) {
+ $wiki_pages[$file]['cached'] = true;
+ }
}
closedir($dh);
}
}
ksort($wiki_pages);
+ $wiki_tree = array();
+ foreach ($wiki_pages as $file => $desc) {
+ list($cat, $name) = explode('.', $file);
+ if (!isset($wiki_tree[$cat])) {
+ $wiki_tree[$cat] = array();
+ }
+ $wiki_tree[$cat][$name] = $desc;
+ }
+
+
$page->changeTpl('admin/wiki.tpl');
- $page->assign('wiki_pages', $wiki_pages);
+ $page->assign('wiki_pages', $wiki_tree);
$page->assign('perms_opts', $perms);
}
+
+ function handler_ipwatch(&$page, $action = 'list', $ip = null)
+ {
+ $page->changeTpl('admin/ipwatcher.tpl');
+
+ $states = array('safe' => 'Ne pas surveiller',
+ 'unsafe' => 'Surveiller les inscription',
+ 'dangerous' => 'Surveiller tous les accès',
+ 'ban' => 'Bannir cette adresse');
+ $page->assign('states', $states);
+
+ switch (Post::v('action')) {
+ case 'create':
+ if (trim(Post::v('ipN')) != '') {
+ Xdb::execute('INSERT IGNORE INTO ip_watch (ip, state, detection, last, uid, description)
+ VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
+ trim(Post::v('ipN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
+ };
+ break;
+
+ case 'edit':
+ Xdb::execute('UPDATE ip_watch
+ SET state = {?}, last = NOW(), uid = {?}, description = {?}
+ WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('ipN'));
+ break;
+
+ default:
+ if ($action == 'delete' && !is_null($ip)) {
+ Xdb::execute('DELETE FROM emails_watch WHERE ip = {?}', $ip);
+ }
+ }
+ if ($action != 'create' && $action != 'edit') {
+ $action = 'list';
+ }
+ $page->assign('action', $action);
+
+ if ($action == 'list') {
+ $sql = "SELECT w.ip, IF(w.ip = s.ip, s.host, s.forward_host), w.detection, w.state, a.alias AS forlife
+ FROM ip_watch AS w
+ LEFT JOIN logger.sessions AS s ON (s.ip = w.ip OR s.forward_ip = w.ip)
+ LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type = 'a_vie')
+ GROUP BY w.ip, a.alias
+ ORDER BY w.state, w.ip, a.alias";
+ $it = Xdb::iterRow($sql);
+
+ $table = array();
+ $props = array();
+ while (list($ip, $host, $date, $state, $forlife) = $it->next()) {
+ if (count($props) == 0 || $props['ip'] != $ip) {
+ if (count($props) > 0) {
+ $table[] = $props;
+ }
+ $props = array('ip' => $ip,
+ 'host' => $host,
+ 'detection' => $date,
+ 'state' => $state,
+ 'users' => array($forlife));
+ } else {
+ $props['users'][] = $forlife;
+ }
+ }
+ if (count($props) > 0) {
+ $table[] = $props;
+ }
+ $page->assign('table', $table);
+ } elseif ($action == 'edit') {
+ $sql = "SELECT w.detection, w.state, w.last, w.description,
+ a1.alias AS edit, a2.alias AS forlife, s.host
+ FROM ip_watch AS w
+ LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
+ LEFT JOIN logger.sessions AS s ON (w.ip = s.ip)
+ LEFT JOIN aliases AS a2 ON (a2.id = s.uid AND a2.type = 'a_vie')
+ WHERE w.ip = {?}
+ GROUP BY a2.alias
+ ORDER BY a2.alias";
+ $it = Xdb::iterRow($sql, $ip);
+
+ $props = array();
+ while (list($detection, $state, $last, $description, $edit, $forlife, $host) = $it->next()) {
+ if (count($props) == 0) {
+ $props = array('ip' => $ip,
+ 'host' => $host,
+ 'detection' => $detection,
+ 'state' => $state,
+ 'last' => $last,
+ 'description' => $description,
+ 'edit' => $edit,
+ 'users' => array($forlife));
+ } else {
+ $props['users'][] = $forlife;
+ }
+ }
+ $page->assign('ip', $props);
+ }
+ }
}
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>