X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fadmin.php;h=1dcde365f55581fbf531ddbafabafa73744425a4;hb=a0b453227e9433d2bd4dea1e07a7463800702839;hp=e48e167573b03cd1691dc9ed6c4002ae37ffbfc6;hpb=8f201b6990b0799230f093920c68e651d040e03b;p=platal.git diff --git a/modules/admin.php b/modules/admin.php index e48e167..1dcde36 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -1,6 +1,6 @@ $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,8 @@ 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'), + 'admin/account/types' => $this->make_hook('account_types', AUTH_MDP, 'admin'), ); } @@ -56,16 +59,27 @@ 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'); - $page->setTitle('Polytechnique.org - Administration'); + $page->setTitle('Administration'); } function handler_postfix_delayed(&$page) { $page->changeTpl('admin/postfix_delayed.tpl'); - $page->setTitle('Polytechnique.org - Administration - Postfix : Retardés'); + $page->setTitle('Administration - Postfix : Retardés'); if (Env::has('del')) { $crc = Env::v('crc'); @@ -90,7 +104,7 @@ class AdminModule extends PLModule function handler_postfix_regexpsbounces(&$page, $new = null) { $page->changeTpl('admin/emails_bounces_re.tpl'); - $page->setTitle('Polytechnique.org - Administration - Postfix : Regexps Bounces'); + $page->setTitle('Administration - Postfix : Regexps Bounces'); $page->assign('new', $new); if (Post::has('submit')) { @@ -347,339 +361,277 @@ class AdminModule extends PLModule $page->changeTpl('admin/logger-view.tpl'); - $page->setTitle('Polytechnique.org - Administration - Logs des sessions'); + $page->setTitle('Administration - Logs des sessions'); } function handler_user(&$page, $login = false) { global $globals; $page->changeTpl('admin/utilisateurs.tpl'); - $page->setTitle('Polytechnique.org - Administration - Edit/Su/Log'); - require_once("emails.inc.php"); - require_once("user.func.inc.php"); + $page->setTitle('Administration - Compte'); - if (S::has('suid')) { + if (S::suid()) { $page->kill("Déjà en SUID !!!"); } - if (Env::has('user_id')) { - $login = get_user_forlife(Env::i('user_id')); - if (empty($login)) { - $login = Env::i('user_id'); + // Loads the user identity using the environment. + $user = User::get($login); + $login = $user->login(); + $registered = ($user->state != 'pending'); + + // Form processing + if (!empty($_POST)) { + S::assert_xsrf_token(); + if (Post::has('uid') && Post::i('uid') != $user->id()) { + $page->kill('Une erreur s\'est produite'); } - } elseif (Env::has('login')) { - $login = get_user_forlife(Env::v('login')); } - if(Env::has('logs_button') && $login) { + // Handles specific requests (AX sync, su, ...). + if(Post::has('logs_account')) { pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); } - if (Env::has('ax_button') && $login) { - pl_redirect("admin/synchro_ax/$login"); + if(Post::has('su_button') && $registered) { + if (!Platal::session()->startSUID($user)) { + $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login()); + } else { + pl_redirect(""); + } } - if(Env::has('suid_button') && $login) { - S::logger()->log("suid_start", "login by ".S::v('forlife')); - $r = XDB::query("SELECT id - FROM aliases - WHERE alias={?}", $login); - if($uid = $r->fetchOneCell()) { - if (!Platal::session()->startSUID($uid)) { - $page->trigError('Impossible d\'effectuer un SUID sur ' . $uid); + // Account Form {{{ + $to_update = array(); + if (Post::has('disable_weak_access')) { + $to_update['weak_password'] = null; + } else if (Post::has('update_account')) { + if (Post::s('full_name') != $user->fullName()) { + // XXX: Update profile if a profile is associated + $to_update['full_name'] = Post::s('full_name'); + } + if (Post::s('display_name') != $user->displayName()) { + // XXX: Update profile if a profile is associated + $to_update['display_name'] = Post::s('display_name'); + } + if (Post::s('sex') != ($user->isFemale() ? 'female' : 'male')) { + $to_update['sex'] = Post::s('sex'); + } + if (!Post::blank('hashpass')) { + $to_update['password'] = Post::s('hashpass'); + } + if (!Post::blank('weak_password')) { + $to_update['weak_password'] = Post::s('weak_password'); + } + if (Post::i('token_access', 0) != ($user->token_access ? 1 : 0)) { + $to_update['token'] = Post::i('token_access') ? rand_url_id(16) : null; + } + if (Post::i('skin', 0) != $user->skin) { + $to_update['skin'] = Post::i('skin', 0); + if ($to_update['skin'] == 0) { + $to_update['skin'] = null; + } + } + if (Post::s('state') != $user->state) { + $to_update['state'] = Post::s('state'); + } + if (Post::i('is_admin', 0) != ($user->is_admin ? 1 : 0)) { + $to_update['is_admin'] = Post::b('is_admin'); + } + if (Post::s('type') != $user->type) { + $to_update['type'] = Post::s('type'); + } + if (Post::i('watch', 0) != ($user->watch ? 1 : 0)) { + $to_update['flags'] = new PlFlagset(); + $to_update['flags']->addFlag('watch', Post::i('watch')); + } + if (Post::t('comment') != $user->comment) { + $to_update['comment'] = Post::blank('comment') ? null : Post::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 (Post::has('add_profile') || Post::has('del_profile') || Post::has('owner')) { + if (Post::i('del_profile', 0) != 0) { + XDB::execute('DELETE FROM account_profiles + WHERE uid = {?} AND pid = {?}', + $user->id(), Post::i('del_profile')); + } else if (!Post::blank('new_profile')) { + $profile = Profile::get(Post::t('new_profile')); + if (!$profile) { + $page->trigError('Le profil ' . Post::t('new_profile') . ' n\'existe pas'); } else { - $page->kill("coucou"); - pl_redirect(""); + 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 = {?}', + Post::i('owner'), $user->id()); } + // }}} - if ($login) { - if (is_numeric($login)) { - $r = XDB::query("SELECT *, a.alias AS forlife, - FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', 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); + // Email forwards form {{{ + require_once("emails.inc.php"); + $redirect = ($registered ? new Redirect($user) : null); + if (Post::has('add_fwd')) { + $email = Post::t('email'); + if (!isvalid_email_redirection($email)) { + $page->trigError("Email non valide: $email"); } else { - $r = XDB::query("SELECT *, a.alias AS forlife, - FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', 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); + $redirect->add_email($email); + $page->trigSuccess("Ajout de $email effectué"); } - $mr = $r->fetchOneAssoc(); - - // Checks the user has a forlife, as non-registered user can't have redirections. - if ($mr['forlife']) { - $redirect = new Redirect($mr['user_id']); + } else if (!Post::blank('del_fwd')) { + $redirect->delete_email(Post::t('del_fwd')); + } else if (!Post::blank('activate_fwd')) { + $redirect->modify_one_email(Post::t('activate_fwd', true)); + } else if (!Post::blank('deactivate_fwd')) { + $redirect->modify_one_email(Post::t('deactivate_fwd', false)); + } else if (Post::has('disable_fwd')) { + $redirect->disable(); + } else if (Post::has('enable_fwd')) { + $redirect->enable(); + } else if (!Post::blank('clean_fwd')) { + $redirect->clean_errors(Post::t('clean_fwd')); + } + // }}} + + // Email alias form {{{ + if (Post::has('add_alias')) { + // Splits new alias in user and fqdn. + $alias = Env::t('email'); + if (strpos($alias, '@') !== false) { + list($alias, $domain) = explode('@', $alias); + } else { + $domain = $globals->mail->domain; } - // Check if there was a submission - foreach($_POST as $key => $val) { - S::assert_xsrf_token(); - - switch ($key) { - case "add_fwd": - $email = trim(Env::v('email')); - if (!isvalid_email_redirection($email)) { - $page->trigError("Email non valide: $email"); - } else { - $redirect->add_email($email); - $page->trigSuccess("Ajout de $email effectué"); - } - break; - - case "del_fwd": - if (!empty($val)) { - $redirect->delete_email($val); - } - break; - - case "del_alias": - if (!empty($val)) { - XDB::execute("DELETE FROM aliases - WHERE id={?} AND alias={?} - AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val); - XDB::execute("UPDATE emails - SET rewrite = '' - WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", - $mr['user_id'], $val); - fix_bestalias($mr['user_id']); - $page->trigSuccess($val." a été supprimé"); - } - break; - case "activate_fwd": - if (!empty($val)) { - $redirect->modify_one_email($val, true); - } - break; - case "deactivate_fwd": - if (!empty($val)) { - $redirect->modify_one_email($val, false); - } - break; - case "disable_fwd": - $redirect->disable(); - break; - case "enable_fwd": - $redirect->enable(); - break; - case "clean_fwd": - if (!empty($val)) { - $redirect->clean_errors($val); - } - break; - case "add_alias": - global $globals; - $alias = trim(Env::v('email')); - if (strpos($alias, '@') !== false) { - list($alias, $domain) = explode('@', $alias); - } else { - $domain = $globals->mail->domain; - } - if (!preg_match('/[-a-z0-9\.]+/s', $alias)) { - $page->trigError("'$alias' n'est pas un alias valide"); - } - if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { - $req = new AliasReq($mr['user_id'], $alias, 'Admin request', false); - if ($req->commit()) { - $page->trigSuccess("Nouvel alias '$alias@$domain' attribué"); - } else { - $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué"); - } - } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { - if (XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", - $mr['user_id'], $alias)) { - $page->trigSuccess("Nouvel alias '$alias' ajouté"); - } else { - $page->trigError("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué"); - } - } else { - $page->trigError("Le domaine '$domain' n'est pas valide"); - } - break; - - case "best": - // 'bestalias' is the first bit of the set : 1 - // 255 is the max for flags (8 sets max) - XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']); - XDB::execute("UPDATE aliases - SET flags= flags | 1 - WHERE id={?} AND alias={?}", $mr['user_id'], $val); - break; - - - // Editer un profil - case "u_edit": - require_once('secure_hash.inc.php'); - $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); - $naiss = Env::v('naissanceN'); - $deces = Env::v('decesN'); - $perms = Env::v('permsN'); - $prenm = Env::v('prenomN'); - $nom = Env::v('nomN'); - $nomusage = Env::v('nomusageN'); - $promo = Env::i('promoN'); - $sexe = Env::v('sexeN'); - $comm = trim(Env::v('commentN')); - $watch = Env::v('watchN'); - $flags = ''; - if ($sexe) { - $flags = 'femme'; - } - if ($watch) { - if ($flags) { - $flags .= ','; - } - $flags .= 'watch'; - } - - if ($watch && !$comm) { - $page->trigError("Il est nécessaire de mettre un commentaire pour surveiller un compte"); - break; - } - - $watch = 'SELECT naissance, deces, password, perms, nom_usage, - prenom, nom, flags, promo, comment - FROM auth_user_md5 - WHERE user_id = ' . $mr['user_id']; - $res = XDB::query($watch); - $old_fields = $res->fetchOneAssoc(); - $query = "UPDATE auth_user_md5 SET - naissance = '$naiss', - deces = '$deces', - password = '$pass_encrypted', - perms = '$perms', - prenom = '".addslashes($prenm)."', - nom = '".addslashes($nom)."', - nom_usage = '".addslashes($nomusage)."', - flags = '$flags', - promo = $promo, - comment = '".addslashes($comm)."' - WHERE user_id = '{$mr['user_id']}'"; - if ($perms == 'disabled' && $old_fields['perms'] != 'disabled') { - // A user has been banned ==> ensure his php session has been killed - // This solution is ugly and overkill, but, it should be efficient. - kill_sessions(); - } - if (XDB::execute($query)) { - user_reindex($mr['user_id']); - - $res = XDB::query($watch); - $new_fields = $res->fetchOneAssoc(); - - $mailer = new PlMailer("admin/useredit.mail.tpl"); - $mailer->assign("admin", S::v('forlife')); - $mailer->assign("user", $mr['forlife']); - $mailer->assign('old', $old_fields); - $mailer->assign('new', $new_fields); - $mailer->send(); - - // update number of subscribers (perms or deceased may have changed) - $globals->updateNbIns(); - - $page->trigSuccess("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']) { - require_once 'notifs.inc.php'; - register_watch_op($mr['user_id'], WATCH_DEATH, $mr['deces']); - user_clear_all_subs($mr['user_id'], false); - } - $r = XDB::query("SELECT *, a.alias AS forlife, - FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', 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') - WHERE u.user_id = {?}", $mr['user_id']); - $mr = $r->fetchOneAssoc(); - - // If GoogleApps is enabled, the user did choose to use synchronized passwords, - // and the password was changed, updates the Google Apps password as well. - if ($globals->mailstorage->googleapps_domain && Env::v('newpass_clair') != "********") { - require_once 'googleapps.inc.php'; - $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']); - if ($account->active() && $account->sync_password) { - $account->set_password($pass_encrypted); - } - } + // Checks for alias' user validity. + if (!preg_match('/[-a-z0-9\.]+/s', $alias)) { + $page->trigError("'$alias' n'est pas un alias valide"); + } - // If GoogleApps is enabled, and the user is now disabled, disables the Google Apps account as well. - if ($globals->mailstorage->googleapps_domain && - $new_fields['perms'] == 'disabled' && - $new_fields['perms'] != $old_fields['perms']) { - require_once 'googleapps.inc.php'; - $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']); - $account->suspend(); - } - break; - - // DELETE FROM auth_user_md5 - case "u_kill": - user_clear_all_subs($mr['user_id']); - // update number of subscribers (perms or deceased may have changed) - $globals->updateNbIns(); - $page->trigSuccess("'{$mr['user_id']}' a été désinscrit !"); - $mailer = new PlMailer("admin/useredit.mail.tpl"); - $mailer->assign("admin", S::v('forlife')); - $mailer->assign("user", $mr['forlife']); - $mailer->assign("deletion", true); - $mailer->send(); - break; - - case "b_edit": - XDB::execute("DELETE FROM forums.innd WHERE uid = {?}", $mr['user_id']); - if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "" ) { - XDB::execute("INSERT INTO forums.innd - SET ipmin = '0', - ipmax = '4294967295', - write_perm = {?}, - read_perm = {?}, - comment = {?}, - priority = '200', - uid = {?}", - Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $mr['user_id']); - } - break; + // Eventually adds the alias to the right domain. + if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { + $req = new AliasReq($user, $alias, 'Admin request', false); + if ($req->commit()) { + $page->trigSuccess("Nouvel alias '$alias@$domain' attribué"); + } else { + $page->trigError("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué"); } + } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { + $res = XDB::execute("INSERT INTO aliases (id, alias, type) + VALUES ({?}, {?}, 'alias')", + $user->id(), $alias); + $page->trigSuccess("Nouvel alias '$alias' ajouté"); + } else { + $page->trigError("Le domaine '$domain' n'est pas valide"); } - - $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::iterator("SELECT alias - FROM virtual - INNER JOIN virtual_redirect USING(vid) - WHERE type = 'user' AND redirect LIKE '" . $mr['forlife'] . "@%'"); - $page->assign('virtuals', $res); - - $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'", $mr["user_id"])); - if ($mr['perms'] != 'pending' && isset($redirect)) { - $page->assign('emails', $redirect->emails); + } else if (!Post::blank('del_alias')) { + XDB::execute("DELETE FROM aliases + WHERE id = {?} AND alias = {?} AND + type NOT IN ('a_vie', 'homonyme')", + $user->id(), $val); + XDB::execute("UPDATE emails + SET rewrite = '' + WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", + $user->id(), $val); + fix_bestalias($user); + $page->trigSuccess("L'alias '$val' a été supprimé"); + } else if (!Post::blank('best')) { + XDB::execute("UPDATE aliases + SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) + WHERE id = {?}", $user->id()); + XDB::execute("UPDATE aliases + SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') + WHERE id = {?} AND alias = {?}", $user->id(), $val); + // As having a non-null bestalias value is critical in + // plat/al's code, we do an a posteriori check on the + // validity of the bestalias. + fix_bestalias($user); + } + // }}} + + // Forum form {{{ + if (Post::has('b_edit')) { + 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 forum_innd + SET ipmin = '0', ipmax = '4294967295', + write_perm = {?}, read_perm = {?}, + comment = {?}, priority = '200', uid = {?}", + Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $user->id()); } + } + // }}} + + + $page->addJsLink('ui.core.js'); + $page->addJsLink('ui.tabs.js'); + + + // Displays last login and last host information. + $res = XDB::query("SELECT start, host + FROM logger.sessions + WHERE uid = {?} AND suid = 0 + ORDER BY start DESC + LIMIT 1", $user->id()); + list($lastlogin,$host) = $res->fetchOneRow(); + $page->assign('lastlogin', $lastlogin); + $page->assign('host', $host); + + // Display active aliases. + $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) { + $page->assign('emails', $redirect->emails); + } - $page->assign('mr',$mr); + $page->assign('mr', $mr); + $page->assign('user', $user); + + // Displays forum bans. + $res = XDB::query("SELECT write_perm, read_perm, comment + FROM forum_innd + WHERE uid = {?}", $user->id()); + $bans = $res->fetchOneAssoc(); + $page->assign('bans', $bans); + } - // Bans forums - $res = XDB::query("SELECT write_perm, read_perm, comment - FROM forums.innd - WHERE uid = {?}", $mr['user_id']); - $bans = $res->fetchOneAssoc(); - $page->assign('bans', $bans); + function getHruid($line, $key) + { + var_dump($line); + if (!isset($line['nom']) || !isset($line['prenom']) || !isset($line['promo'])) { + return null; } + return make_forlife($line['prenom'], $line['nom'], $line['promo']); } function getMatricule($line, $key) @@ -702,7 +654,7 @@ class AdminModule extends PLModule $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax'; pl_redirect('admin/promo/' . $action . '/' . Env::i('promo')); } else { - $page->trigError('Promo non valide'); + $page->trigError('Promotion non valide.'); } } @@ -714,12 +666,13 @@ class AdminModule extends PLModule } $importer = new CSVImporter('auth_user_md5', 'matricule'); - $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule')); + $importer->registerFunction('matricule', 'matricule Ecole vers X.org', array($this, 'getMatricule')); switch ($action) { case 'add': - $fields = array('nom', 'nom_ini', 'prenom', 'naissance_ini', + $fields = array('hruid', 'nom', 'nom_ini', 'prenom', 'naissance_ini', 'prenom_ini', 'promo', 'promo_sortie', 'flags', 'matricule', 'matricule_ax', 'perms'); + $importer->forceValue('hruid', array($this, 'getHruid')); $importer->forceValue('promo', $promo); $importer->forceValue('promo_sortie', $promo + 3); break; @@ -730,18 +683,18 @@ class AdminModule extends PLModule $importer->apply($page, "admin/promo/$action/$promo", $fields); } - function handler_homonyms(&$page, $op = 'list', $target = null) { + function handler_homonyms(&$page, $op = 'list', $target = null) + { $page->changeTpl('admin/homonymes.tpl'); - $page->setTitle('Polytechnique.org - Administration - Homonymes'); - require_once("homonymes.inc.php"); + $page->setTitle('Administration - Homonymes'); + $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); } } @@ -756,35 +709,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é à ' . $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é à ' . $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; @@ -793,37 +751,10 @@ class AdminModule extends PLModule } } - function handler_ax_xorg(&$page) { - $page->changeTpl('admin/ax-xorg.tpl'); - $page->setTitle('Polytechnique.org - 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 - 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) - AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) - OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) - ORDER BY u.promo,u.nom,u.prenom'); - $page->assign('diffs', $res->fetchAllAssoc()); - - // 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 - LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax - WHERE u.nom IS NULL'); - $page->assign('mank', $res->fetchAllAssoc()); - - // 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()); - } - - function handler_deaths(&$page, $promo = 0, $validate = false) { + function handler_deaths(&$page, $promo = 0, $validate = false) + { $page->changeTpl('admin/deces_promo.tpl'); - $page->setTitle('Polytechnique.org - Administration - Deces'); + $page->setTitle('Administration - Deces'); if (!$promo) $promo = Env::i('promo'); @@ -837,7 +768,6 @@ class AdminModule extends PLModule if ($validate) { S::assert_xsrf_token(); - $new_deces = array(); $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); @@ -846,7 +776,7 @@ class AdminModule extends PLModule } XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); - $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val"); + $page->trigSuccess('Ajout du décès de ' . $prenom . " " . $nom . ' le ' . $val . '.'); if($deces == '0000-00-00' || empty($deces)) { require_once('notifs.inc.php'); register_watch_op($uid, WATCH_DEATH, $val); @@ -854,21 +784,20 @@ class AdminModule extends PLModule user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email } } - $page->assign('new_deces',$new_deces); } $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); $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('Polytechnique.org - Administration - Décédés'); + $page->setTitle('Administration - Décédés'); $res = XDB::iterator( - "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, a.alias, DATE(MAX(s.start)) AS last + "SELECT u.promo, u.nom, u.prenom, u.deces, u.matricule_ax, u.hruid, DATE(MAX(s.start)) AS last FROM auth_user_md5 AS u - LEFT JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie') LEFT JOIN logger.sessions AS s ON (s.uid = u.user_id AND suid = 0) WHERE perms IN ('admin', 'user') AND deces <> 0 GROUP BY u.user_id @@ -876,57 +805,10 @@ class AdminModule extends PLModule $page->assign('dead', $res); } - function handler_synchro_ax(&$page, $user = null, $action = null) { - $page->changeTpl('admin/synchro_ax.tpl'); - $page->setTitle('Polytechnique.org - Administration - Synchro AX'); - - require_once('synchro_ax.inc.php'); - - if (is_ax_key_missing()) { - $page->assign('no_private_key', true); - $page->run(); - } - - require_once('user.func.inc.php'); - - if ($user) - $login = get_user_forlife($user); - - if (Env::has('user')) { - $login = get_user_forlife(Env::v('user')); - if ($login === false) { - return; - } - } - - if (Env::has('mat')) { - $res = XDB::query( - "SELECT alias - FROM aliases AS a - INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') - WHERE matricule={?}", Env::i('mat')); - $login = $res->fetchOneCell(); - } - - if ($login) { - if ($action == 'import') { - ax_synchronize($login, S::v('uid')); - } - // get details from user, but looking only info that can be seen by ax - $user = get_user_details($login, S::v('uid'), 'ax'); - $userax= get_user_ax($user['matricule_ax']); - require_once 'profil.func.inc.php'; - $diff = diff_user_details($userax, $user, 'ax'); - - $page->assign('x', $user); - $page->assign('diff', $diff); - } - } - function handler_validate(&$page, $action = 'list', $id = null) { $page->changeTpl('admin/valider.tpl'); - $page->setTitle('Polytechnique.org - Administration - Valider une demande'); + $page->setTitle('Administration - Valider une demande'); $page->addCssLink('nl.css'); $page->addJsLink('ajax.js'); require_once("validations.inc.php"); @@ -940,7 +822,11 @@ class AdminModule extends PLModule S::assert_xsrf_token(); $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); - $req->handle_formu(); + if ($req) { + $req->handle_formu(); + } else { + $page->trigWarning('La validation a déjà été effectuée.'); + } } $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); @@ -973,8 +859,9 @@ class AdminModule extends PLModule $page->assign('vit', new ValidateIterator()); } - function handler_validate_answers(&$page, $action = 'list', $id = null) { - $page->setTitle('Polytechnique.org - Administration - Réponses automatiques de validation'); + 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'); $table_editor->describe('category','catégorie',true); @@ -982,8 +869,10 @@ class AdminModule extends PLModule $table_editor->describe('answer','texte',false); $table_editor->apply($page, $action, $id); } - function handler_skins(&$page, $action = 'list', $id = null) { - $page->setTitle('Polytechnique.org - Administration - Skins'); + + 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'); $table_editor->describe('name','nom',true); @@ -995,23 +884,28 @@ class AdminModule extends PLModule $table_editor->apply($page, $action, $id); } - function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { - $page->setTitle('Polytechnique.org - Administration - Postfix : Blacklist'); + 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); $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->setTitle('Polytechnique.org - Administration - Postfix : Whitelist'); + + 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) { - $page->setTitle('Polytechnique.org - Administration - MX Défaillants'); + + 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); $table_editor->describe('host', 'Masque', true); @@ -1019,16 +913,20 @@ 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) { - $page->setTitle('Polytechnique.org - Administration - Actions'); + + 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'); $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->setTitle('Polytechnique.org - Administration - Coupures'); + + 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'); $table_editor->describe('debut','date',true); @@ -1039,11 +937,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('forlife') . '&hash=' . S::v('core_rss_hash')); + '/Site/AllRecentChanges?action=rss&user=' . S::v('hruid') . '&hash=' . S::v('token')); } // update wiki perms @@ -1103,7 +1011,6 @@ class AdminModule extends PLModule } $page->changeTpl('admin/wiki.tpl'); - $page->addJsLink('jquery.js'); $page->assign('wiki_pages', $wiki_tree); $page->assign('perms_opts', $perms); } @@ -1152,18 +1059,18 @@ 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, a.alias AS forlife + 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 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"; + 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(); $props = array(); - while (list($ip, $host, $mask, $date, $state, $forlife) = $it->next()) { + while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) { $ip = uint_to_ip($ip); $mask = uint_to_ip($mask); if (count($props) == 0 || $props['ip'] != $ip) { @@ -1175,9 +1082,9 @@ class AdminModule extends PLModule 'host' => $host, 'detection' => $date, 'state' => $state, - 'users' => array($forlife)); + 'users' => array($hruid)); } else { - $props['users'][] = $forlife; + $props['users'][] = $hruid; } } if (count($props) > 0) { @@ -1186,18 +1093,18 @@ class AdminModule extends PLModule $page->assign('table', $table); } elseif ($action == 'edit') { $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask, - a1.alias AS edit, a2.alias AS forlife, s.host + a1.hruid AS edit, a2.hruid AS hruid, s.host FROM ip_watch AS w - LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') + LEFT JOIN accounts AS a1 ON (a1.uid = w.uid) 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') + LEFT JOIN accounts AS a2 ON (a2.uid = s.uid) WHERE w.ip = {?} - GROUP BY a2.alias - ORDER BY a2.alias"; + GROUP BY a2.hruid + ORDER BY a2.hruid"; $it = Xdb::iterRow($sql, ip_to_uint($ip)); $props = array(); - while (list($detection, $state, $last, $description, $mask, $edit, $forlife, $host) = $it->next()) { + while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) { if (count($props) == 0) { $props = array('ip' => $ip, 'mask' => uint_to_ip($mask), @@ -1207,9 +1114,9 @@ class AdminModule extends PLModule 'last' => $last, 'description' => $description, 'edit' => $edit, - 'users' => array($forlife)); + 'users' => array($hruid)); } else { - $props['users'][] = $forlife; + $props['users'][] = $hruid; } } $page->assign('ip', $props); @@ -1232,6 +1139,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: