86f0a6af |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | class AdminModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
27 | 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), |
86f0a6af |
28 | 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), |
29 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), |
e7ae7df9 |
30 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
e7ae7df9 |
31 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
e7ae7df9 |
32 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
33 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), |
e7ae7df9 |
34 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
35 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), |
36 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), |
37 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), |
38 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
39 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), |
e7ae7df9 |
40 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
41 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
e18888f4 |
42 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), |
3aec1c21 |
43 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
86f0a6af |
44 | ); |
45 | } |
46 | |
47 | function handler_default(&$page) |
48 | { |
49 | $page->changeTpl('admin/index.tpl'); |
50 | $page->assign('xorg_title','Polytechnique.org - Administration'); |
51 | } |
52 | |
53 | function handler_postfix_delayed(&$page) |
54 | { |
55 | $page->changeTpl('admin/postfix_delayed.tpl'); |
56 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés'); |
57 | |
58 | if (Env::has('del')) { |
59 | $crc = Env::v('crc'); |
60 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); |
61 | $page->trig($crc." verra tous ses mails supprimés !"); |
62 | } elseif (Env::has('ok')) { |
63 | $crc = Env::v('crc'); |
64 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); |
65 | $page->trig($crc." a le droit de passer !"); |
66 | } |
67 | |
68 | $sql = XDB::iterator( |
69 | "SELECT crc, nb, update_time, create_time, |
70 | FIND_IN_SET('del', release) AS del, |
71 | FIND_IN_SET('ok', release) AS ok |
72 | FROM postfix_mailseen |
73 | WHERE nb >= 30 |
74 | ORDER BY release != ''"); |
75 | |
76 | $page->assign_by_ref('mails', $sql); |
77 | } |
78 | |
79 | function handler_postfix_regexpsbounces(&$page, $new = null) { |
80 | $page->changeTpl('admin/emails_bounces_re.tpl'); |
81 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces'); |
82 | $page->assign('new', $new); |
83 | |
84 | if (Post::has('submit')) { |
85 | foreach (Env::v('lvl') as $id=>$val) { |
86 | XDB::query( |
87 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", |
88 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] |
89 | ); |
90 | } |
91 | } |
92 | |
93 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); |
94 | } |
95 | |
441e9e98 |
96 | // {{{ logger view |
86f0a6af |
97 | |
441e9e98 |
98 | /** Retrieves the available days for a given year and month. |
99 | * Obtain a list of days of the given month in the given year |
100 | * that are within the range of dates that we have log entries for. |
101 | * |
102 | * @param integer year |
103 | * @param integer month |
104 | * @return array days in that month we have log entries covering. |
105 | * @private |
106 | */ |
107 | function _getDays($year, $month) |
108 | { |
109 | // give a 'no filter' option |
110 | $months[0] = "----"; |
111 | |
112 | if ($year && $month) { |
113 | $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, |
114 | 30, 31, 30, 31, 31, 30, 31, 30, 31); |
115 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), |
116 | MONTH(MAX(start)), MONTH(MIN(start)), |
117 | DAYOFMONTH(MAX(start)), |
118 | DAYOFMONTH(MIN(start)) |
119 | FROM logger.sessions"); |
120 | list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow(); |
121 | |
122 | if (($year < $ymin) || ($year == $ymin && $month < $mmin)) { |
123 | return array(); |
124 | } |
125 | |
126 | if (($year > $ymax) || ($year == $ymax && $month > $mmax)) { |
127 | return array(); |
128 | } |
129 | |
130 | $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1; |
131 | $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month]; |
132 | |
133 | for($i = $min; $i<=$max; $i++) { |
134 | $days[$i] = $i; |
135 | } |
136 | } |
137 | return $days; |
138 | } |
139 | |
140 | |
141 | /** Retrieves the available months for a given year. |
142 | * Obtains a list of month numbers that are within the timeframe that |
143 | * we have log entries for. |
144 | * |
145 | * @param integer year |
146 | * @return array List of month numbers we have log info for. |
147 | * @private |
148 | */ |
149 | function _getMonths($year) |
150 | { |
151 | // give a 'no filter' option |
152 | $months[0] = "----"; |
153 | |
154 | if ($year) { |
155 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), |
156 | MONTH(MAX(start)), MONTH(MIN(start)) |
157 | FROM logger.sessions"); |
158 | list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow(); |
159 | |
160 | if (($year < $ymin) || ($year > $ymax)) { |
161 | return array(); |
162 | } |
163 | |
164 | $min = $year == $ymin ? intval($mmin) : 1; |
165 | $max = $year == $ymax ? intval($mmax) : 12; |
166 | |
167 | for($i = $min; $i<=$max; $i++) { |
168 | $months[$i] = $i; |
169 | } |
170 | } |
171 | return $months; |
172 | } |
173 | |
174 | |
175 | /** Retrieves the available years. |
176 | * Obtains a list of years that we have log entries covering. |
177 | * |
178 | * @return array years we have log entries for. |
179 | * @private |
180 | */ |
181 | function _getYears() |
182 | { |
183 | // give a 'no filter' option |
184 | $years[0] = "----"; |
185 | |
186 | // retrieve available years |
187 | $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions"); |
188 | list($max, $min) = $res->fetchOneRow(); |
189 | |
190 | for($i = intval($min); $i<=$max; $i++) { |
191 | $years[$i] = $i; |
192 | } |
193 | return $years; |
194 | } |
195 | |
196 | |
197 | /** Make a where clause to get a user's sessions. |
198 | * Prepare the where clause request that will retrieve the sessions. |
199 | * |
200 | * @param $year INTEGER Only get log entries made during the given year. |
201 | * @param $month INTEGER Only get log entries made during the given month. |
202 | * @param $day INTEGER Only get log entries made during the given day. |
203 | * @param $uid INTEGER Only get log entries referring to the given user ID. |
204 | * |
205 | * @return STRING the WHERE clause of a query, including the 'WHERE' keyword |
206 | * @private |
207 | */ |
208 | function _makeWhere($year, $month, $day, $uid) |
209 | { |
210 | // start constructing the "where" clause |
211 | $where = array(); |
212 | |
213 | if ($uid) |
214 | array_push($where, "uid='$uid'"); |
215 | |
216 | // we were given at least a year |
217 | if ($year) { |
218 | if ($day) { |
219 | $dmin = mktime(0, 0, 0, $month, $day, $year); |
220 | $dmax = mktime(0, 0, 0, $month, $day+1, $year); |
221 | } elseif ($month) { |
222 | $dmin = mktime(0, 0, 0, $month, 1, $year); |
223 | $dmax = mktime(0, 0, 0, $month+1, 1, $year); |
224 | } else { |
225 | $dmin = mktime(0, 0, 0, 1, 1, $year); |
226 | $dmax = mktime(0, 0, 0, 1, 1, $year+1); |
227 | } |
228 | $where[] = "start >= " . date("Ymd000000", $dmin); |
229 | $where[] = "start < " . date("Ymd000000", $dmax); |
230 | } |
231 | |
232 | if (!empty($where)) { |
233 | return ' WHERE ' . implode($where, " AND "); |
234 | } else { |
235 | return ''; |
236 | } |
237 | // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC |
238 | } |
239 | |
240 | // }}} |
241 | |
242 | function handler_logger(&$page, $action = null, $arg = null) { |
243 | if ($action == 'session') { |
244 | |
245 | // we are viewing a session |
246 | $res = XDB::query("SELECT ls.*, a.alias AS username, sa.alias AS suer |
247 | FROM logger.sessions AS ls |
248 | LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie') |
249 | LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie') |
250 | WHERE ls.id = {?}", $arg); |
251 | |
252 | $page->assign('session', $a = $res->fetchOneAssoc()); |
253 | |
254 | $res = XDB::iterator('SELECT a.text, e.data, UNIX_TIMESTAMP(e.stamp) AS stamp |
255 | FROM logger.events AS e |
256 | LEFT JOIN logger.actions AS a ON e.action=a.id |
257 | WHERE e.session={?}', $arg); |
258 | while ($myarr = $res->next()) { |
259 | $page->append('events', $myarr); |
260 | } |
261 | |
262 | } else { |
263 | $loguser = $action == 'user' ? $arg : Env::v('loguser'); |
264 | |
265 | $res = XDB::query('SELECT id FROM aliases WHERE alias={?}', |
266 | $loguser); |
267 | $loguid = $res->fetchOneCell(); |
268 | |
269 | if ($loguid) { |
270 | $year = Env::i('year'); |
271 | $month = Env::i('month'); |
272 | $day = Env::i('day'); |
273 | } else { |
274 | $year = Env::i('year', intval(date('Y'))); |
275 | $month = Env::i('month', intval(date('m'))); |
276 | $day = Env::i('day', intval(date('d'))); |
277 | } |
278 | |
279 | if (!$year) |
280 | $month = 0; |
281 | if (!$month) |
282 | $day = 0; |
283 | |
284 | // smarty assignments |
285 | // retrieve available years |
286 | $page->assign('years', $this->_getYears()); |
287 | $page->assign('year', $year); |
288 | |
289 | // retrieve available months for the current year |
290 | $page->assign('months', $this->_getMonths($year)); |
291 | $page->assign('month', $month); |
292 | |
293 | // retrieve available days for the current year and month |
294 | $page->assign('days', $this->_getDays($year, $month)); |
295 | $page->assign('day', $day); |
296 | |
297 | $page->assign('loguser', $loguser); |
298 | // smarty assignments |
299 | |
300 | if ($loguid || $year) { |
301 | |
302 | // get the requested sessions |
303 | $where = $this->_makeWhere($year, $month, $day, $loguid); |
304 | $select = "SELECT s.id, UNIX_TIMESTAMP(s.start) as start, s.uid, |
305 | a.alias as username |
306 | FROM logger.sessions AS s |
307 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie') |
308 | $where |
309 | ORDER BY start DESC"; |
310 | $res = XDB::iterator($select); |
311 | |
312 | $sessions = array(); |
313 | while ($mysess = $res->next()) { |
314 | $mysess['events'] = array(); |
315 | $sessions[$mysess['id']] = $mysess; |
316 | } |
317 | array_reverse($sessions); |
318 | |
319 | // attach events |
320 | $sql = "SELECT s.id, a.text |
321 | FROM logger.sessions AS s |
322 | LEFT JOIN logger.events AS e ON(e.session=s.id) |
323 | INNER JOIN logger.actions AS a ON(a.id=e.action) |
324 | $where"; |
325 | |
326 | $res = XDB::iterator($sql); |
327 | while ($event = $res->next()) { |
328 | array_push($sessions[$event['id']]['events'], $event['text']); |
329 | } |
330 | $page->assign_by_ref('sessions', $sessions); |
331 | } else { |
332 | $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur"); |
333 | } |
86f0a6af |
334 | } |
335 | |
441e9e98 |
336 | $page->changeTpl('logger-view.tpl'); |
86f0a6af |
337 | |
c4271d38 |
338 | $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions'); |
86f0a6af |
339 | } |
340 | |
341 | function handler_user(&$page, $login = false) { |
342 | $page->changeTpl('admin/utilisateurs.tpl'); |
343 | $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log'); |
344 | require_once("emails.inc.php"); |
345 | require_once("user.func.inc.php"); |
346 | |
347 | if (S::has('suid')) { |
348 | $page->kill("déjà en SUID !!!"); |
349 | } |
350 | |
351 | if (Env::has('user_id')) { |
352 | $login = get_user_login(Env::i('user_id')); |
353 | } elseif (Env::has('login')) { |
354 | $login = get_user_login(Env::v('login')); |
355 | } |
356 | |
357 | if(Env::has('logs_button') && $login) { |
358 | pl_redirect("admin/logger?login=$login&year=".date('Y')."&month=".date('m')); |
359 | } |
360 | |
361 | if (Env::has('ax_button') && $login) { |
362 | pl_redirect("admin/synchro_ax/$login"); |
363 | } |
364 | |
365 | if(Env::has('suid_button') && $login) { |
366 | $_SESSION['log']->log("suid_start", "login by ".S::v('forlife')); |
367 | $_SESSION['suid'] = $_SESSION; |
368 | $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login); |
369 | if($uid = $r->fetchOneCell()) { |
370 | start_connexion($uid,true); |
371 | pl_redirect(""); |
372 | } |
373 | } |
374 | |
375 | if ($login) { |
376 | $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe |
377 | FROM auth_user_md5 AS u |
378 | INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login); |
379 | $mr = $r->fetchOneAssoc(); |
380 | |
381 | $redirect = new Redirect($mr['user_id']); |
382 | |
383 | // Check if there was a submission |
384 | foreach($_POST as $key => $val) { |
385 | switch ($key) { |
386 | case "add_fwd": |
387 | $email = trim(Env::v('email')); |
388 | if (!isvalid_email_redirection($email)) { |
389 | $page->trig("invalid email $email"); |
390 | } else { |
391 | $redirect->add_email($email); |
392 | $page->trig("Ajout de $email effectué"); |
393 | } |
394 | break; |
395 | |
396 | case "del_fwd": |
397 | if (!empty($val)) { |
398 | $redirect->delete_email($val); |
399 | } |
400 | break; |
401 | |
402 | case "del_alias": |
403 | if (!empty($val)) { |
404 | XDB::execute("DELETE FROM aliases WHERE id={?} AND alias={?} |
405 | AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val); |
d91e720f |
406 | XDB::execute("UPDATE emails |
407 | SET rewrite = '' |
408 | WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", |
409 | $mr['user_id'], $val); |
86f0a6af |
410 | fix_bestalias($mr['user_id']); |
411 | $page->trig($val." a été supprimé"); |
412 | } |
413 | break; |
414 | case "activate_fwd": |
415 | if (!empty($val)) { |
416 | $redirect->modify_one_email($val, true); |
417 | } |
418 | break; |
419 | case "deactivate_fwd": |
420 | if (!empty($val)) { |
421 | $redirect->modify_one_email($val, false); |
422 | } |
423 | break; |
424 | case "add_alias": |
425 | XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", |
426 | $mr['user_id'], Env::v('email')); |
427 | break; |
428 | |
429 | case "best": |
430 | // 'bestalias' is the first bit of the set : 1 |
431 | // 255 is the max for flags (8 sets max) |
432 | XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']); |
433 | XDB::execute("UPDATE aliases |
434 | SET flags= flags | 1 |
435 | WHERE id={?} AND alias={?}", $mr['user_id'], $val); |
436 | break; |
437 | |
438 | |
439 | // Editer un profil |
440 | case "u_edit": |
441 | require_once('secure_hash.inc.php'); |
442 | $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); |
443 | $naiss = Env::v('naissanceN'); |
34ffe99a |
444 | $deces = Env::v('decesN'); |
86f0a6af |
445 | $perms = Env::v('permsN'); |
446 | $prenm = Env::v('prenomN'); |
447 | $nom = Env::v('nomN'); |
448 | $promo = Env::i('promoN'); |
449 | $sexe = Env::v('sexeN'); |
450 | $comm = Env::v('commentN'); |
451 | |
452 | $query = "UPDATE auth_user_md5 SET |
453 | naissance = '$naiss', |
34ffe99a |
454 | deces = '$deces', |
86f0a6af |
455 | password = '$pass_encrypted', |
456 | perms = '$perms', |
457 | prenom = '".addslashes($prenm)."', |
458 | nom = '".addslashes($nom)."', |
459 | flags = '$sexe', |
460 | promo = $promo, |
461 | comment = '".addslashes($comm)."' |
462 | WHERE user_id = '{$mr['user_id']}'"; |
463 | if (XDB::execute($query)) { |
464 | user_reindex($mr['user_id']); |
465 | |
466 | require_once("diogenes/diogenes.hermes.inc.php"); |
467 | $mailer = new HermesMailer(); |
468 | $mailer->setFrom("webmaster@polytechnique.org"); |
469 | $mailer->addTo("web@polytechnique.org"); |
470 | $mailer->setSubject("INTERVENTION de ".S::v('forlife')); |
471 | $mailer->setTxtBody(preg_replace("/[ \t]+/", ' ', $query)); |
472 | $mailer->send(); |
473 | |
474 | $page->trig("updaté correctement."); |
475 | } |
476 | if (Env::v('nomusageN') != $mr['nom_usage']) { |
86f0a6af |
477 | set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN'))); |
478 | } |
479 | $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe |
480 | FROM auth_user_md5 AS u |
481 | INNER JOIN aliases AS a ON (u.user_id=a.id) |
482 | WHERE user_id = {?}", $mr['user_id']); |
483 | $mr = $r->fetchOneAssoc(); |
484 | break; |
485 | |
486 | // DELETE FROM auth_user_md5 |
487 | case "u_kill": |
488 | user_clear_all_subs($mr['user_id']); |
489 | $page->trig("'{$mr['user_id']}' a été désinscrit !"); |
490 | require_once("diogenes/diogenes.hermes.inc.php"); |
491 | $mailer = new HermesMailer(); |
492 | $mailer->setFrom("webmaster@polytechnique.org"); |
493 | $mailer->addTo("web@polytechnique.org"); |
494 | $mailer->setSubject("INTERVENTION de ".S::v('forlife')); |
495 | $mailer->setTxtBody("\nUtilisateur $login effacé"); |
496 | $mailer->send(); |
497 | break; |
498 | } |
499 | } |
500 | |
501 | $res = XDB::query("SELECT UNIX_TIMESTAMP(start), host |
502 | FROM logger.sessions |
503 | WHERE uid={?} AND suid=0 |
504 | ORDER BY start DESC |
505 | LIMIT 1", $mr['user_id']); |
506 | list($lastlogin,$host) = $res->fetchOneRow(); |
507 | $page->assign('lastlogin', $lastlogin); |
508 | $page->assign('host', $host); |
509 | |
510 | $page->assign('aliases', XDB::iterator( |
511 | "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire |
512 | FROM aliases |
513 | WHERE id = {?} AND type!='homonyme' |
514 | ORDER BY type!= 'a_vie'", $mr["user_id"])); |
86f0a6af |
515 | $page->assign('emails',$redirect->emails); |
516 | |
517 | $page->assign('mr',$mr); |
518 | } |
519 | } |
520 | function handler_homonyms(&$page, $op = 'list', $target = null) { |
521 | $page->changeTpl('admin/homonymes.tpl'); |
522 | $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes'); |
523 | require_once("homonymes.inc.php"); |
74c55fd6 |
524 | |
86f0a6af |
525 | if ($target) { |
526 | if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { |
527 | $target=0; |
528 | } else { |
529 | $page->assign('nom',$nom); |
530 | $page->assign('prenom',$prenom); |
531 | $page->assign('forlife',$forlife); |
532 | $page->assign('loginbis',$loginbis); |
533 | } |
534 | } |
74c55fd6 |
535 | |
86f0a6af |
536 | $page->assign('op',$op); |
537 | $page->assign('target',$target); |
74c55fd6 |
538 | |
86f0a6af |
539 | // on a un $target valide, on prepare les mails |
540 | if ($target) { |
74c55fd6 |
541 | |
86f0a6af |
542 | // on examine l'op a effectuer |
543 | switch ($op) { |
544 | case 'mail': |
545 | send_warning_homonyme($prenom, $nom, $forlife, $loginbis); |
546 | switch_bestalias($target, $loginbis); |
547 | $op = 'list'; |
548 | break; |
549 | case 'correct': |
550 | switch_bestalias($target, $loginbis); |
551 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis); |
552 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target); |
553 | send_robot_homonyme($prenom, $nom, $forlife, $loginbis); |
554 | $op = 'list'; |
555 | break; |
556 | } |
557 | } |
74c55fd6 |
558 | |
86f0a6af |
559 | if ($op == 'list') { |
560 | $res = XDB::iterator( |
561 | "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, |
562 | promo,prenom,nom, |
563 | IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, |
564 | IF(h.homonyme_id=s.id, a.type, NULL) AS type |
565 | FROM aliases AS a |
566 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) |
567 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') |
568 | INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) |
569 | WHERE a.type='homonyme' OR a.expire!='' |
570 | ORDER BY a.alias,promo"); |
571 | $hnymes = Array(); |
572 | while ($tab = $res->next()) { |
573 | $hnymes[$tab['homonyme']][] = $tab; |
574 | } |
575 | $page->assign_by_ref('hnymes',$hnymes); |
576 | } |
577 | } |
74c55fd6 |
578 | |
86f0a6af |
579 | function handler_ax_xorg(&$page) { |
580 | $page->changeTpl('admin/ax-xorg.tpl'); |
581 | $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org'); |
74c55fd6 |
582 | |
86f0a6af |
583 | // liste des différences |
584 | $res = XDB::query( |
585 | '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 |
586 | FROM auth_user_md5 AS u |
587 | INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax |
588 | WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) |
589 | AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) |
590 | OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) |
591 | ORDER BY u.promo,u.nom,u.prenom'); |
592 | $page->assign('diffs', $res->fetchAllAssoc()); |
74c55fd6 |
593 | |
86f0a6af |
594 | // gens à l'ax mais pas chez nous |
595 | $res = XDB::query( |
596 | 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom |
597 | FROM identification_ax as ia |
598 | LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax |
599 | WHERE u.nom IS NULL'); |
600 | $page->assign('mank', $res->fetchAllAssoc()); |
74c55fd6 |
601 | |
86f0a6af |
602 | // gens chez nous et pas à l'ax |
603 | $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL'); |
604 | $page->assign('plus', $res->fetchAllAssoc()); |
605 | } |
74c55fd6 |
606 | |
86f0a6af |
607 | function handler_deaths(&$page, $promo = 0, $validate = false) { |
608 | $page->changeTpl('admin/deces_promo.tpl'); |
609 | $page->assign('xorg_title','Polytechnique.org - Administration - Deces'); |
74c55fd6 |
610 | |
86f0a6af |
611 | if (!$promo) |
612 | $promo = Env::i('promo'); |
613 | if (Env::has('sub10')) $promo -= 10; |
614 | if (Env::has('sub01')) $promo -= 1; |
615 | if (Env::has('add01')) $promo += 1; |
616 | if (Env::has('add10')) $promo += 10; |
74c55fd6 |
617 | |
86f0a6af |
618 | $page->assign('promo',$promo); |
74c55fd6 |
619 | |
86f0a6af |
620 | if ($validate) { |
621 | $new_deces = array(); |
622 | $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo); |
623 | while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) { |
624 | $val = Env::v($mat); |
625 | if($val == $deces || empty($val)) continue; |
626 | XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); |
627 | $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val"); |
628 | if($deces=='0000-00-00' or empty($deces)) { |
629 | require_once('notifs.inc.php'); |
630 | register_watch_op($uid, WATCH_DEATH, $val); |
631 | require_once('user.func.inc.php'); |
632 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email |
633 | } |
634 | } |
635 | $page->assign('new_deces',$new_deces); |
636 | } |
74c55fd6 |
637 | |
86f0a6af |
638 | $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); |
639 | $page->assign('decedes', $res); |
640 | } |
74c55fd6 |
641 | |
86f0a6af |
642 | function handler_synchro_ax(&$page, $user = null, $action = null) { |
643 | $page->changeTpl('admin/synchro_ax.tpl'); |
644 | $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX'); |
74c55fd6 |
645 | |
86f0a6af |
646 | require_once('synchro_ax.inc.php'); |
74c55fd6 |
647 | |
86f0a6af |
648 | if (is_ax_key_missing()) { |
649 | $page->assign('no_private_key', true); |
650 | $page->run(); |
651 | } |
74c55fd6 |
652 | |
86f0a6af |
653 | require_once('user.func.inc.php'); |
654 | |
655 | if ($user) |
656 | $login = get_user_forlife($user); |
657 | |
658 | if (Env::has('user')) { |
659 | $login = get_user_forlife(Env::v('user')); |
660 | if ($login === false) { |
661 | return; |
662 | } |
663 | } |
74c55fd6 |
664 | |
86f0a6af |
665 | if (Env::has('mat')) { |
666 | $res = XDB::query( |
74c55fd6 |
667 | "SELECT alias |
86f0a6af |
668 | FROM aliases AS a |
669 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
670 | WHERE matricule={?}", Env::i('mat')); |
671 | $login = $res->fetchOneCell(); |
672 | } |
74c55fd6 |
673 | |
86f0a6af |
674 | if ($login) { |
675 | if ($action == 'import') { |
676 | ax_synchronize($login, S::v('uid')); |
677 | } |
678 | // get details from user, but looking only info that can be seen by ax |
679 | $user = get_user_details($login, S::v('uid'), 'ax'); |
680 | $userax= get_user_ax($user['matricule_ax']); |
681 | require_once 'profil.func.inc.php'; |
682 | $diff = diff_user_details($userax, $user, 'ax'); |
74c55fd6 |
683 | |
86f0a6af |
684 | $page->assign('x', $user); |
685 | $page->assign('diff', $diff); |
686 | } |
687 | } |
74c55fd6 |
688 | |
ed5b9703 |
689 | function handler_validate(&$page, $action = 'list', $id = null) { |
86f0a6af |
690 | $page->changeTpl('admin/valider.tpl'); |
691 | $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande'); |
692 | require_once("validations.inc.php"); |
74c55fd6 |
693 | |
ed5b9703 |
694 | if ($action == 'edit' and !is_null($id)) { |
695 | $page->assign('preview_id', $id); |
696 | } |
697 | |
86f0a6af |
698 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
699 | $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
700 | if($req) { $req->handle_formu(); } |
701 | } |
74c55fd6 |
702 | |
cfb96867 |
703 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
704 | while (($a = $r->next()) && $a['Field'] != 'category'); |
705 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); |
74c55fd6 |
706 | |
cfb96867 |
707 | $hidden = array(); |
708 | if (Post::has('hide')) { |
74c55fd6 |
709 | $hide = array(); |
710 | foreach ($categories as $cat) |
cfb96867 |
711 | if (!Post::v($cat)) { |
712 | $hidden[$cat] = 1; |
713 | $hide[] = $cat; |
714 | } |
715 | setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0); |
716 | } elseif (Env::has('hide_requests')) { |
717 | foreach (explode(',',Env::v('hide_requests')) as $hide_type) |
718 | $hidden[$hide_type] = true; |
719 | } |
720 | $page->assign('hide_requests', $hidden); |
74c55fd6 |
721 | |
86f0a6af |
722 | $page->assign('vit', new ValidateIterator()); |
723 | } |
e18888f4 |
724 | function handler_validate_answers(&$page, $action = 'list', $id = null) { |
e18888f4 |
725 | $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation'); |
726 | $page->assign('title', 'Gestion des réponses automatiques'); |
727 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
728 | $table_editor->describe('category','catégorie',true); |
729 | $table_editor->describe('title','titre',true); |
730 | $table_editor->describe('answer','texte',false); |
731 | $table_editor->apply($page, $action, $id); |
732 | } |
e7ae7df9 |
733 | function handler_skins(&$page, $action = 'list', $id = null) { |
e7ae7df9 |
734 | $page->assign('xorg_title','Polytechnique.org - Administration - Skins'); |
735 | $page->assign('title', 'Gestion des skins'); |
736 | $table_editor = new PLTableEditor('admin/skins','skins','id'); |
737 | $table_editor->describe('name','nom',true); |
738 | $table_editor->describe('skin_tpl','nom du template',true); |
739 | $table_editor->describe('auteur','auteur',false); |
740 | $table_editor->describe('comment','commentaire',true); |
741 | $table_editor->describe('date','date',false); |
742 | $table_editor->describe('ext','extension du screenshot',false); |
743 | $table_editor->apply($page, $action, $id); |
74c55fd6 |
744 | } |
e7ae7df9 |
745 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { |
e7ae7df9 |
746 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist'); |
747 | $page->assign('title', 'Blacklist de postfix'); |
748 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); |
749 | $table_editor->describe('reject_text','Texte de rejet',true); |
750 | $table_editor->describe('email','email',true); |
751 | $table_editor->apply($page, $action, $id); |
74c55fd6 |
752 | } |
e7ae7df9 |
753 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { |
e7ae7df9 |
754 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist'); |
755 | $page->assign('title', 'Whitelist de postfix'); |
756 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); |
757 | $table_editor->describe('email','email',true); |
758 | $table_editor->apply($page, $action, $id); |
74c55fd6 |
759 | } |
e7ae7df9 |
760 | function handler_logger_actions(&$page, $action = 'list', $id = null) { |
e7ae7df9 |
761 | $page->assign('xorg_title','Polytechnique.org - Administration - Actions'); |
762 | $page->assign('title', 'Gestion des actions de logger'); |
763 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); |
764 | $table_editor->describe('text','intitulé',true); |
765 | $table_editor->describe('description','description',true); |
766 | $table_editor->apply($page, $action, $id); |
74c55fd6 |
767 | } |
e7ae7df9 |
768 | function handler_downtime(&$page, $action = 'list', $id = null) { |
e7ae7df9 |
769 | $page->assign('xorg_title','Polytechnique.org - Administration - Coupures'); |
770 | $page->assign('title', 'Gestion des coupures'); |
771 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); |
772 | $table_editor->describe('debut','date',true); |
773 | $table_editor->describe('duree','durée',false); |
774 | $table_editor->describe('resume','résumé',true); |
775 | $table_editor->describe('services','services affectés',true); |
776 | $table_editor->describe('description','description',false); |
777 | $table_editor->apply($page, $action, $id); |
74c55fd6 |
778 | } |
3aec1c21 |
779 | function handler_wiki(&$page, $action='list') { |
780 | require_once 'wiki.inc.php'; |
74c55fd6 |
781 | |
3aec1c21 |
782 | // update wiki perms |
783 | if ($action == 'update') { |
784 | $perms_read = Post::v('read'); |
785 | $perms_edot = Post::v('edit'); |
786 | if ($perms_read || $perms_edit) { |
787 | foreach ($_POST as $wiki_page => $val) if ($val == 'on') { |
788 | $wiki_page = str_replace('_', '/', $wiki_page); |
789 | if (!$perms_read || !$perms_edit) |
74c55fd6 |
790 | list($perms0, $perms1) = wiki_get_perms($wiki_page); |
3aec1c21 |
791 | if ($perms_read) |
792 | $perms0 = $perms_read; |
793 | if ($perms_edit) |
794 | $perms1 = $perms_edit; |
795 | wiki_set_perms($wiki_page, $perms0, $perms1); |
796 | } |
797 | } |
798 | } |
74c55fd6 |
799 | |
3aec1c21 |
800 | $perms = wiki_perms_options(); |
74c55fd6 |
801 | |
3aec1c21 |
802 | // list wiki pages and their perms |
803 | $wiki_pages = array(); |
804 | $dir = wiki_work_dir(); |
805 | if (is_dir($dir)) { |
806 | if ($dh = opendir($dir)) { |
807 | while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') { |
808 | list($read,$edit) = wiki_get_perms($file); |
809 | $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]); |
810 | } |
811 | closedir($dh); |
812 | } |
813 | } |
814 | ksort($wiki_pages); |
74c55fd6 |
815 | |
3aec1c21 |
816 | $page->changeTpl('admin/wiki.tpl'); |
74c55fd6 |
817 | $page->assign('wiki_pages', $wiki_pages); |
3aec1c21 |
818 | $page->assign('perms_opts', $perms); |
819 | } |
86f0a6af |
820 | } |
821 | |
822 | ?> |