X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fadmin.php;h=b69a258039fbc27e90ac7358ae22c0496c4246bd;hb=1ebf2b93bef5ab13342293a34041b9a68ed31f03;hp=501b03000ce965a5a03c9fddc28df1a940c39e50;hpb=866bd5351ad9e3dd9e5603d078fd19825487d976;p=platal.git diff --git a/modules/admin.php b/modules/admin.php index 501b030..b69a258 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -49,6 +49,7 @@ class AdminModule extends PLModule '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'), + 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP, 'admin'), ); } @@ -367,7 +368,7 @@ class AdminModule extends PLModule { global $globals; $page->changeTpl('admin/utilisateurs.tpl'); - $page->setTitle('Administration - Edit/Su/Log'); + $page->setTitle('Administration - Compte'); require_once("emails.inc.php"); if (S::suid()) { @@ -385,36 +386,117 @@ class AdminModule extends PLModule if ($user) { $login = $user->login(); - $registered = ($user->forlifeEmail() != null); + $registered = $user->state != 'pending'; } else { return; } // Handles specific requests (AX sync, su, ...). - if(Env::has('logs_button') && $registered) { + if(Env::has('logs_account')) { pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); } - if (Env::has('ax_button') && $registered) { - pl_redirect("admin/synchro_ax/" . $user->login()); - } - - if(Env::has('suid_button') && $registered) { + if(Env::has('su_button') && $registered) { if (!Platal::session()->startSUID($user)) { - $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->id()); + $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login()); } else { pl_redirect(""); } } // Fetches user data. - $userinfo_query = "SELECT *, FIND_IN_SET('watch', flags) AS watch, FIND_IN_SET('femme', flags) AS sexe, - (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err - FROM auth_user_md5 - WHERE user_id = {?}"; - $mr = XDB::query($userinfo_query, $user->id())->fetchOneAssoc(); $redirect = ($registered ? new Redirect($user) : null); + // Account Form {{{ + $to_update = array(); + if (Env::has('disable_weak_access')) { + S::assert_xsrf_token(); + $to_update['weak_password'] = null; + } else if (Env::has('update_account')) { + S::assert_xsrf_token(); + if (Env::s('full_name') != $user->fullName()) { + $to_update['full_name'] = Env::s('full_name'); + } + if (Env::s('display_name') != $user->displayName()) { + $to_update['display_name'] = Env::s('display_name'); + } + if (Env::s('sex') != ($user->isFemale() ? 'female' : 'male')) { + $to_update['sex'] = Env::s('sex'); + } + if (!Env::blank('hashpass')) { + $to_update['password'] = Env::s('hashpass'); + } + if (!Env::blank('weak_password')) { + $to_update['weak_password'] = Env::s('weak_password'); + } + if (Env::i('token_access', 0) != ($user->token_access ? 1 : 0)) { + $to_update['token'] = Env::i('token_access') ? rand_url_id(16) : null; + } + if (Env::i('skin', 0) != $user->skin) { + $to_update['skin'] = Env::i('skin', 0); + if ($to_update['skin'] == 0) { + $to_update['skin'] = null; + } + } + if (Env::s('state') != $user->state) { + $to_update['state'] = Env::s('state'); + } + if (Env::i('is_admin', 0) != ($user->is_admin ? 1 : 0)) { + $to_update['is_admin'] = Env::b('is_admin'); + } + if (Env::s('type') != $user->type) { + $to_update['type'] = Env::s('type'); + } + if (Env::i('watch', 0) != ($user->watch ? 1 : 0)) { + $to_update['flags'] = new PlFlagset(); + $to_update['flags']->addFlag('watch', Env::i('watch')); + } + if (Env::t('comment') != $user->comment) { + $to_update['comment'] = Env::blank('comment') ? null : Env::t('comment'); + } + } + if (!empty($to_update)) { + $set = array(); + foreach ($to_update as $k => $value) { + $set[] = XDB::format($k . ' = {?}', $value); + } + XDB::execute('UPDATE accounts + SET ' . implode(', ', $set) . ' + WHERE uid = ' . XDB::format('{?}', $user->id())); + $page->trigSuccess('Données du compte mise à jour avec succès'); + $user = User::getWithUID($user->id()); + } + // }}} + // Profile form {{{ + if (Env::has('add_profile') || Env::has('del_profile') || Env::has('owner')) { + S::assert_xsrf_token(); + if (Env::i('del_profile', 0) != 0) { + XDB::execute('DELETE FROM account_profiles + WHERE uid = {?} AND pid = {?}', + $user->id(), Env::i('del_profile')); + } else if (!Env::blank('new_profile')) { + $profile = Profile::get(Env::t('new_profile')); + if (!$profile) { + $page->trigError('Le profil ' . Env::t('new_profile') . ' n\'existe pas'); + } else { + XDB::execute('INSERT IGNORE INTO account_profiles (uid, pid) + VALUES ({?}, {?})', + $user->id(), $profile->id()); + } + } + XDB::execute('UPDATE account_profiles + SET perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\')) + WHERE uid = {?}', + Env::i('owner'), $user->id()); + } + + + // }}} + + $page->addJsLink('ui.core.js'); + $page->addJsLink('ui.tabs.js'); + + // Processes admin requests, if any. foreach($_POST as $key => $val) { S::assert_xsrf_token(); @@ -632,6 +714,7 @@ class AdminModule extends PLModule // User re-registration. case "u_kill": + require_once('user.func.inc.php'); user_clear_all_subs($user->id()); $globals->updateNbIns(); $page->trigSuccess("'" . $user->id() . "' a été désinscrit !"); @@ -645,9 +728,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 = {?}", @@ -668,21 +751,18 @@ class AdminModule extends PLModule $page->assign('host', $host); // Display active aliases. - $page->assign('virtuals', XDB::iterator( - "SELECT alias - FROM virtual - INNER JOIN virtual_redirect USING (vid) - 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('virtuals', $user->emailAliases()); $page->assign('aliases', XDB::iterator( "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire FROM aliases WHERE id = {?} AND type != 'homonyme' ORDER BY type != 'a_vie'", $user->id())); + $page->assign('account_types', XDB::iterator('SELECT * FROM account_types ORDER BY type')); + $page->assign('skins', XDB::iterator('SELECT id, name FROM skins ORDER BY name')); + $page->assign('profiles', XDB::iterator('SELECT p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner + FROM account_profiles AS ap + INNER JOIN profiles AS p ON (ap.pid = p.pid) + WHERE ap.uid = {?}', $user->id())); // Displays email redirection and the general profile. if ($registered && $redirect) { @@ -694,7 +774,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); @@ -762,15 +842,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); } } @@ -785,37 +864,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; @@ -824,13 +906,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) @@ -852,7 +936,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'); @@ -890,7 +975,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'); @@ -904,7 +990,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'); @@ -921,7 +1008,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; @@ -995,7 +1085,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'); @@ -1004,7 +1095,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'); @@ -1017,7 +1110,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); @@ -1025,14 +1119,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); @@ -1041,7 +1139,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'); @@ -1049,7 +1149,9 @@ class AdminModule extends PLModule $table_editor->describe('description','description',true); $table_editor->apply($page, $action, $id); } - function handler_downtime(&$page, $action = 'list', $id = null) { + + function handler_downtime(&$page, $action = 'list', $id = null) + { $page->setTitle('Administration - Coupures'); $page->assign('title', 'Gestion des coupures'); $table_editor = new PLTableEditor('admin/downtime','coupures','id'); @@ -1061,11 +1163,21 @@ class AdminModule extends PLModule $table_editor->apply($page, $action, $id); } + function handler_account_types(&$page, $action = 'list', $id = null) + { + $page->setTitle('Administration - Types de comptes'); + $page->assign('title', 'Gestion des types de comptes'); + $table_editor = new PLTableEditor('admin/account/types', 'account_types', 'type', true); + $table_editor->describe('type', 'Catégorie', true); + $table_editor->describe('perms', 'Permissions associées', true); + $table_editor->apply($page, $action, $id); + } + 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 @@ -1174,13 +1286,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(); @@ -1208,14 +1320,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(); @@ -1258,14 +1370,15 @@ class AdminModule extends PLModule function handler_accounts(&$page) { $page->changeTpl('admin/accounts.tpl'); - $page->assign('disabled', XDB::iterator('SELECT u.nom, u.prenom, u.promo, u.comment, u.hruid - FROM auth_user_md5 AS u - WHERE perms = \'disabled\' - ORDER BY nom, prenom')); - $page->assign('admins', XDB::iterator('SELECT u.nom, u.prenom, u.promo, u.hruid - FROM auth_user_md5 AS u - WHERE perms = \'admin\' - ORDER BY nom, prenom')); + $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')); } }