+ function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
+ $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
+ $page->assign('title', 'Blacklist de postfix');
+ $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true);
+ $table_editor->describe('reject_text','Texte de rejet',true);
+ $table_editor->describe('email','email',true);
+ $table_editor->apply($page, $action, $id);
+ }
+ function handler_postfix_whitelist(&$page, $action = 'list', $id = null) {
+ $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist');
+ $page->assign('title', 'Whitelist de postfix');
+ $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true);
+ $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('description','description',true);
+ $table_editor->apply($page, $action, $id);
+ }
+ function handler_downtime(&$page, $action = 'list', $id = null) {
+ $page->assign('xorg_title','Polytechnique.org - Administration - Coupures');
+ $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('description','description',false);
+ $table_editor->apply($page, $action, $id);
+ }
+
+ function handler_wiki(&$page, $action='list', $wikipage='', $wikipage2='')
+ {
+ require_once 'wiki.inc.php';
+
+ if (S::v('core_rss_hash')) {
+ $page->setRssLink('Changement Récents',
+ '/Site/AllRecentChanges?action=rss&user=' . S::v('forlife') . '&hash=' . S::v('core_rss_hash'));
+ }
+ // update wiki perms
+ if ($action == 'update') {
+ $perms_read = Post::v('read');
+ $perms_edot = Post::v('edit');
+ if ($perms_read || $perms_edit) {
+ foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
+ $wiki_page = str_replace('_', '/', $wiki_page);
+ if (!$perms_read || !$perms_edit)
+ list($perms0, $perms1) = wiki_get_perms($wiki_page);
+ if ($perms_read)
+ $perms0 = $perms_read;
+ if ($perms_edit)
+ $perms1 = $perms_edit;
+ wiki_set_perms($wiki_page, $perms0, $perms1);
+ }
+ }
+ }
+
+ if ($action == 'delete' && $wikipage != '') {
+ if (wiki_delete_page($wikipage)) {
+ $page->trig("La page ".$wikipage." a été supprimée.");
+ } else {
+ $page->trig("Impossible de supprimer la page ".$wikipage.".");
+ }
+ }
+
+ if ($action == 'rename' && $wikipage != '' && $wikipage2 != '' && $wikipage != $wikipage2) {
+ if ($changedLinks = wiki_rename_page($wikipage, $wikipage2)) {
+ $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.';
+ if (is_numeric($changedLinks)) {
+ $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.');
+ }
+ $page->trig($s);
+ } else {
+ $page->trig("Impossible de déplacer la page ".$wikipage);
+ }
+ }
+
+ $perms = wiki_perms_options();
+
+ // list wiki pages and their perms
+ $wiki_pages = array();
+ $dir = wiki_work_dir();
+ if (is_dir($dir)) {
+ if ($dh = opendir($dir)) {
+ 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->addJsLink('jquery.js');
+ $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 inscriptions',
+ '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);
+ }
+ }
+
+ function handler_icons(&$page)
+ {
+ $page->changeTpl('admin/icons.tpl');
+ $dh = opendir('../htdocs/images/icons');
+ if (!$dh) {
+ $page->trig('Dossier des icones introuvables.');
+ }
+ $icons = array();
+ while (($file = readdir($dh)) !== false) {
+ if (strlen($file) > 4 && substr($file,-4) == '.gif') {
+ array_push($icons, substr($file, 0, -4));
+ }
+ }
+ sort($icons);
+ $page->assign('icons', $icons);