X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fadmin.php;h=4a9350e218c34b81a8d5e29fb7d41e983cee87ab;hb=191711d5aa707ee93b1f6ad386774e912637244d;hp=275253234cdf4e0e793a18abdde52128181b2e74;hpb=f0cd349e916b22734c1f64edb63a248ca9988d93;p=platal.git diff --git a/modules/admin.php b/modules/admin.php index 2752532..4a9350e 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -25,6 +25,7 @@ class AdminModule extends PLModule { return array( 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'), + 'get_rights' => $this->make_hook('get_rights', AUTH_MDP, 'admin'), 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP, 'admin'), @@ -47,6 +48,7 @@ class AdminModule extends PLModule 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), + 'admin/accounts' => $this->make_hook('accounts', AUTH_MDP, 'admin'), ); } @@ -56,6 +58,17 @@ class AdminModule extends PLModule exit; } + function handler_get_rights(&$page, $level) + { + if (S::suid()) { + $page->kill('Déjà en SUID'); + } + $user =& S::user(); + Platal::session()->startSUID($user, $level); + + pl_redirect('/'); + } + function handler_default(&$page) { $page->changeTpl('admin/index.tpl'); @@ -357,7 +370,7 @@ class AdminModule extends PLModule $page->setTitle('Administration - Edit/Su/Log'); require_once("emails.inc.php"); - if (S::has('suid')) { + if (S::suid()) { $page->kill("Déjà en SUID !!!"); } @@ -387,8 +400,7 @@ class AdminModule extends PLModule } if(Env::has('suid_button') && $registered) { - S::logger()->log("suid_start", "login on " . $user->login()); - if (!Platal::session()->startSUID($user->id())) { + if (!Platal::session()->startSUID($user)) { $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->id()); } else { pl_redirect(""); @@ -633,9 +645,9 @@ class AdminModule extends PLModule // Forum ban update. case "b_edit": - XDB::execute("DELETE FROM forums.innd WHERE uid = {?}", $user->id()); + XDB::execute("DELETE FROM forum_innd WHERE uid = {?}", $user->id()); if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) { - XDB::execute("INSERT INTO forums.innd + XDB::execute("INSERT INTO forum_innd SET ipmin = '0', ipmax = '4294967295', write_perm = {?}, read_perm = {?}, comment = {?}, priority = '200', uid = {?}", @@ -660,7 +672,11 @@ class AdminModule extends PLModule "SELECT alias FROM virtual INNER JOIN virtual_redirect USING (vid) - WHERE type = 'user' AND redirect LIKE CONCAT({?}, '@%')", $user->id())); + WHERE type = 'user' AND (redirect = {?} OR redirect = {?})", + $user->forlifeEmail(), + // TODO: remove this über-ugly hack. The issue is that you need + // to remove all @m4x.org addresses in virtual_redirect first. + $user->login() . '@' . $globals->mail->domain2)); $page->assign('aliases', XDB::iterator( "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire @@ -678,7 +694,7 @@ class AdminModule extends PLModule // Displays forum bans. $res = XDB::query("SELECT write_perm, read_perm, comment - FROM forums.innd + FROM forum_innd WHERE uid = {?}", $user->id()); $bans = $res->fetchOneAssoc(); $page->assign('bans', $bans); @@ -746,15 +762,14 @@ class AdminModule extends PLModule { $page->changeTpl('admin/homonymes.tpl'); $page->setTitle('Administration - Homonymes'); - require_once("homonymes.inc.php"); + $this->load("homonyms.inc.php"); if ($target) { - if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { - $target=0; + $user = User::getSilent($target); + if (!$user || !($loginbis = select_if_homonyme($user))) { + $target = 0; } else { - $page->assign('nom',$nom); - $page->assign('prenom',$prenom); - $page->assign('forlife',$forlife); + $page->assign('user', $user); $page->assign('loginbis',$loginbis); } } @@ -769,37 +784,40 @@ class AdminModule extends PLModule case 'mail': S::assert_xsrf_token(); - send_warning_homonyme($prenom, $nom, $forlife, $loginbis); - switch_bestalias($target, $loginbis); + send_warning_homonyme($user, $loginbis); + switch_bestalias($user, $loginbis); $op = 'list'; - $page->trigSuccess('Email envoyé à ' . $forlife . '.'); + $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . '.'); break; case 'correct': S::assert_xsrf_token(); - 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); + switch_bestalias($user, $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($user, $loginbis); $op = 'list'; - $page->trigSuccess('Email envoyé à ' . $forlife . ', alias supprimé.'); + $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.'); break; } } if ($op == 'list') { $res = XDB::iterator( - "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, - promo,prenom,nom, - IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, - IF(h.homonyme_id=s.id, a.type, NULL) AS type + "SELECT a.alias AS homonyme, s.alias AS forlife, + IF(h.homonyme_id = s.id, a.expire, NULL) AS expire, + IF(h.homonyme_id = s.id, a.type, NULL) AS type, + ac.uid AS user_id FROM aliases AS a LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') - INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) - WHERE a.type='homonyme' OR a.expire!='' - ORDER BY a.alias,promo"); + INNER JOIN accounts AS ac ON (ac.uid = a.id) + WHERE a.type = 'homonyme' OR a.expire != '' + ORDER BY a.alias, forlife"); $hnymes = Array(); while ($tab = $res->next()) { $hnymes[$tab['homonyme']][] = $tab; @@ -808,13 +826,15 @@ class AdminModule extends PLModule } } - function handler_ax_xorg(&$page) { + function handler_ax_xorg(&$page) + { $page->changeTpl('admin/ax-xorg.tpl'); $page->setTitle('Administration - AX/X.org'); // 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 + '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 INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) @@ -836,7 +856,8 @@ class AdminModule extends PLModule $page->assign('plus', $res->fetchAllAssoc()); } - function handler_deaths(&$page, $promo = 0, $validate = false) { + function handler_deaths(&$page, $promo = 0, $validate = false) + { $page->changeTpl('admin/deces_promo.tpl'); $page->setTitle('Administration - Deces'); @@ -874,7 +895,8 @@ class AdminModule extends PLModule $page->assign('decedes', $res); } - function handler_dead_but_active(&$page) { + function handler_dead_but_active(&$page) + { $page->changeTpl('admin/dead_but_active.tpl'); $page->setTitle('Administration - Décédés'); @@ -888,7 +910,8 @@ class AdminModule extends PLModule $page->assign('dead', $res); } - function handler_synchro_ax(&$page, $login = null, $action = null) { + function handler_synchro_ax(&$page, $login = null, $action = null) + { $page->changeTpl('admin/synchro_ax.tpl'); $page->setTitle('Administration - Synchro AX'); @@ -905,7 +928,10 @@ class AdminModule extends PLModule } else if (Env::has('user')) { $user = User::get(Env::v('user')); } else if (Env::has('mat')) { - $res = XDB::query("SELECT user_id FROM auth_user_md5 WHERE matricule = {?}", Env::i('mat')); + $res = XDB::query("SELECT user_id + FROM auth_user_md5 + WHERE matricule = {?}", + Env::i('mat')); $user = User::get($res->fetchOneCell()); } else { return; @@ -979,7 +1005,8 @@ class AdminModule extends PLModule $page->assign('vit', new ValidateIterator()); } - function handler_validate_answers(&$page, $action = 'list', $id = null) { + function handler_validate_answers(&$page, $action = 'list', $id = null) + { $page->setTitle('Administration - Réponses automatiques de validation'); $page->assign('title', 'Gestion des réponses automatiques'); $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); @@ -988,7 +1015,9 @@ class AdminModule extends PLModule $table_editor->describe('answer','texte',false); $table_editor->apply($page, $action, $id); } - function handler_skins(&$page, $action = 'list', $id = null) { + + function handler_skins(&$page, $action = 'list', $id = null) + { $page->setTitle('Administration - Skins'); $page->assign('title', 'Gestion des skins'); $table_editor = new PLTableEditor('admin/skins','skins','id'); @@ -1001,7 +1030,8 @@ class AdminModule extends PLModule $table_editor->apply($page, $action, $id); } - function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { + function handler_postfix_blacklist(&$page, $action = 'list', $id = null) + { $page->setTitle('Administration - Postfix : Blacklist'); $page->assign('title', 'Blacklist de postfix'); $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); @@ -1009,14 +1039,18 @@ class AdminModule extends PLModule $table_editor->describe('email','email',true); $table_editor->apply($page, $action, $id); } - function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { + + function handler_postfix_whitelist(&$page, $action = 'list', $id = null) + { $page->setTitle('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) { + + function handler_mx_broken(&$page, $action = 'list', $id = null) + { $page->setTitle('Administration - MX Défaillants'); $page->assign('title', 'MX Défaillant'); $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); @@ -1025,7 +1059,9 @@ class AdminModule extends PLModule $table_editor->describe('text', 'Description du problème', false); $table_editor->apply($page, $action, $id); } - function handler_logger_actions(&$page, $action = 'list', $id = null) { + + function handler_logger_actions(&$page, $action = 'list', $id = null) + { $page->setTitle('Administration - Actions'); $page->assign('title', 'Gestion des actions de logger'); $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); @@ -1033,6 +1069,7 @@ class AdminModule extends PLModule $table_editor->describe('description','description',true); $table_editor->apply($page, $action, $id); } + function handler_downtime(&$page, $action = 'list', $id = null) { $page->setTitle('Administration - Coupures'); $page->assign('title', 'Gestion des coupures'); @@ -1047,9 +1084,9 @@ class AdminModule extends PLModule function handler_wiki(&$page, $action = 'list', $wikipage = null, $wikipage2 = null) { - if (S::v('core_rss_hash')) { + if (S::hasAuthToken()) { $page->setRssLink('Changement Récents', - '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('core_rss_hash')); + '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('token')); } // update wiki perms @@ -1158,13 +1195,13 @@ class AdminModule extends PLModule $sql = "SELECT w.ip, IF(s.ip IS NULL, IF(w.ip = s2.ip, s2.host, s2.forward_host), IF(w.ip = s.ip, s.host, s.forward_host)), - w.mask, w.detection, w.state, u.hruid + w.mask, w.detection, w.state, a.hruid FROM ip_watch AS w LEFT JOIN logger.sessions AS s ON (s.ip = w.ip) LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip) - LEFT JOIN auth_user_md5 AS u ON (u.user_id = s.uid) - GROUP BY w.ip, u.hruid - ORDER BY w.state, w.ip, u.hruid"; + LEFT JOIN accounts AS a ON (a.uid = s.uid) + GROUP BY w.ip, a.hruid + ORDER BY w.state, w.ip, a.hruid"; $it = Xdb::iterRow($sql); $table = array(); @@ -1192,14 +1229,14 @@ class AdminModule extends PLModule $page->assign('table', $table); } elseif ($action == 'edit') { $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask, - u1.hruid AS edit, u2.hruid AS hruid, s.host + a1.hruid AS edit, a2.hruid AS hruid, s.host FROM ip_watch AS w - LEFT JOIN auth_user_md5 AS u1 ON (u1.user_id = w.uid) + LEFT JOIN accounts AS a1 ON (a1.uid = w.uid) LEFT JOIN logger.sessions AS s ON (w.ip = s.ip) - LEFT JOIN auth_user_md5 AS u2 ON (u2.user_id = s.uid) + LEFT JOIN accounts AS a2 ON (a2.uid = s.uid) WHERE w.ip = {?} - GROUP BY u2.hruid - ORDER BY u2.hruid"; + GROUP BY a2.hruid + ORDER BY a2.hruid"; $it = Xdb::iterRow($sql, ip_to_uint($ip)); $props = array(); @@ -1238,6 +1275,20 @@ class AdminModule extends PLModule sort($icons); $page->assign('icons', $icons); } + + function handler_accounts(&$page) + { + $page->changeTpl('admin/accounts.tpl'); + $page->assign('disabled', XDB::iterator('SELECT a.hruid, FIND_IN_SET(\'watch\', a.flags) AS watch, + a.state = \'disabled\' AS disabled, a.comment + FROM accounts AS a + WHERE a.state = \'disabled\' OR FIND_IN_SET(\'watch\', a.flags) + ORDER BY a.hruid')); + $page->assign('admins', XDB::iterator('SELECT a.hruid + FROM accounts AS a + WHERE a.is_admin + ORDER BY a.hruid')); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: