Commit | Line | Data |
---|---|---|
86f0a6af | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
86f0a6af | 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( | |
5f9a40b4 | 27 | 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'), |
28 | 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), | |
86f0a6af | 29 | 'admin/ax-xorg' => $this->make_hook('ax_xorg', AUTH_MDP, 'admin'), |
30 | 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), | |
e7ae7df9 | 31 | 'admin/downtime' => $this->make_hook('downtime', AUTH_MDP, 'admin'), |
e7ae7df9 | 32 | 'admin/homonyms' => $this->make_hook('homonyms', AUTH_MDP, 'admin'), |
e7ae7df9 | 33 | 'admin/logger' => $this->make_hook('logger', AUTH_MDP, 'admin'), |
34 | 'admin/logger/actions' => $this->make_hook('logger_actions', AUTH_MDP, 'admin'), | |
e7ae7df9 | 35 | 'admin/postfix/blacklist' => $this->make_hook('postfix_blacklist', AUTH_MDP, 'admin'), |
36 | 'admin/postfix/delayed' => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'), | |
37 | 'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'), | |
38 | 'admin/postfix/whitelist' => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'), | |
ccdbc270 | 39 | 'admin/mx/broken' => $this->make_hook('mx_broken', AUTH_MDP, 'admin'), |
e7ae7df9 | 40 | 'admin/skins' => $this->make_hook('skins', AUTH_MDP, 'admin'), |
41 | 'admin/synchro_ax' => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'), | |
e7ae7df9 | 42 | 'admin/user' => $this->make_hook('user', AUTH_MDP, 'admin'), |
1f53925a | 43 | 'admin/promo' => $this->make_hook('promo', AUTH_MDP, 'admin'), |
e7ae7df9 | 44 | 'admin/validate' => $this->make_hook('validate', AUTH_MDP, 'admin'), |
e18888f4 | 45 | 'admin/validate/answers' => $this->make_hook('validate_answers', AUTH_MDP, 'admin'), |
3aec1c21 | 46 | 'admin/wiki' => $this->make_hook('wiki', AUTH_MDP, 'admin'), |
5480a216 | 47 | 'admin/ipwatch' => $this->make_hook('ipwatch', AUTH_MDP, 'admin'), |
f141945d | 48 | 'admin/icons' => $this->make_hook('icons', AUTH_MDP, 'admin'), |
86f0a6af | 49 | ); |
50 | } | |
51 | ||
5f9a40b4 | 52 | function handler_phpinfo(&$page) |
53 | { | |
54 | phpinfo(); | |
55 | exit; | |
56 | } | |
57 | ||
86f0a6af | 58 | function handler_default(&$page) |
59 | { | |
60 | $page->changeTpl('admin/index.tpl'); | |
61 | $page->assign('xorg_title','Polytechnique.org - Administration'); | |
62 | } | |
63 | ||
64 | function handler_postfix_delayed(&$page) | |
65 | { | |
66 | $page->changeTpl('admin/postfix_delayed.tpl'); | |
a7de4ef7 | 67 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Retardés'); |
86f0a6af | 68 | |
69 | if (Env::has('del')) { | |
70 | $crc = Env::v('crc'); | |
71 | XDB::execute("UPDATE postfix_mailseen SET release = 'del' WHERE crc = {?}", $crc); | |
a7de4ef7 | 72 | $page->trig($crc." verra tous ses mails supprimés !"); |
86f0a6af | 73 | } elseif (Env::has('ok')) { |
74 | $crc = Env::v('crc'); | |
75 | XDB::execute("UPDATE postfix_mailseen SET release = 'ok' WHERE crc = {?}", $crc); | |
76 | $page->trig($crc." a le droit de passer !"); | |
77 | } | |
78 | ||
79 | $sql = XDB::iterator( | |
80 | "SELECT crc, nb, update_time, create_time, | |
81 | FIND_IN_SET('del', release) AS del, | |
82 | FIND_IN_SET('ok', release) AS ok | |
83 | FROM postfix_mailseen | |
84 | WHERE nb >= 30 | |
85 | ORDER BY release != ''"); | |
86 | ||
87 | $page->assign_by_ref('mails', $sql); | |
88 | } | |
89 | ||
90 | function handler_postfix_regexpsbounces(&$page, $new = null) { | |
91 | $page->changeTpl('admin/emails_bounces_re.tpl'); | |
92 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Regexps Bounces'); | |
93 | $page->assign('new', $new); | |
94 | ||
95 | if (Post::has('submit')) { | |
96 | foreach (Env::v('lvl') as $id=>$val) { | |
97 | XDB::query( | |
98 | "REPLACE INTO emails_bounces_re (id,pos,lvl,re,text) VALUES ({?}, {?}, {?}, {?}, {?})", | |
99 | $id, $_POST['pos'][$id], $_POST['lvl'][$id], $_POST['re'][$id], $_POST['text'][$id] | |
100 | ); | |
101 | } | |
102 | } | |
103 | ||
104 | $page->assign('bre', XDB::iterator("SELECT * FROM emails_bounces_re ORDER BY pos")); | |
105 | } | |
106 | ||
441e9e98 | 107 | // {{{ logger view |
86f0a6af | 108 | |
441e9e98 | 109 | /** Retrieves the available days for a given year and month. |
110 | * Obtain a list of days of the given month in the given year | |
111 | * that are within the range of dates that we have log entries for. | |
112 | * | |
113 | * @param integer year | |
114 | * @param integer month | |
115 | * @return array days in that month we have log entries covering. | |
116 | * @private | |
117 | */ | |
118 | function _getDays($year, $month) | |
119 | { | |
120 | // give a 'no filter' option | |
121 | $months[0] = "----"; | |
122 | ||
123 | if ($year && $month) { | |
124 | $day_max = Array(-1, 31, checkdate(2, 29, $year) ? 29 : 28 , 31, | |
125 | 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
126 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), | |
127 | MONTH(MAX(start)), MONTH(MIN(start)), | |
128 | DAYOFMONTH(MAX(start)), | |
129 | DAYOFMONTH(MIN(start)) | |
130 | FROM logger.sessions"); | |
131 | list($ymax, $ymin, $mmax, $mmin, $dmax, $dmin) = $res->fetchOneRow(); | |
132 | ||
133 | if (($year < $ymin) || ($year == $ymin && $month < $mmin)) { | |
134 | return array(); | |
135 | } | |
136 | ||
137 | if (($year > $ymax) || ($year == $ymax && $month > $mmax)) { | |
138 | return array(); | |
139 | } | |
140 | ||
141 | $min = ($year==$ymin && $month==$mmin) ? intval($dmin) : 1; | |
142 | $max = ($year==$ymax && $month==$mmax) ? intval($dmax) : $day_max[$month]; | |
143 | ||
144 | for($i = $min; $i<=$max; $i++) { | |
145 | $days[$i] = $i; | |
146 | } | |
147 | } | |
148 | return $days; | |
149 | } | |
150 | ||
151 | ||
152 | /** Retrieves the available months for a given year. | |
153 | * Obtains a list of month numbers that are within the timeframe that | |
154 | * we have log entries for. | |
155 | * | |
156 | * @param integer year | |
157 | * @return array List of month numbers we have log info for. | |
158 | * @private | |
159 | */ | |
160 | function _getMonths($year) | |
161 | { | |
162 | // give a 'no filter' option | |
163 | $months[0] = "----"; | |
164 | ||
165 | if ($year) { | |
166 | $res = XDB::query("SELECT YEAR (MAX(start)), YEAR (MIN(start)), | |
167 | MONTH(MAX(start)), MONTH(MIN(start)) | |
168 | FROM logger.sessions"); | |
169 | list($ymax, $ymin, $mmax, $mmin) = $res->fetchOneRow(); | |
170 | ||
171 | if (($year < $ymin) || ($year > $ymax)) { | |
172 | return array(); | |
173 | } | |
174 | ||
175 | $min = $year == $ymin ? intval($mmin) : 1; | |
176 | $max = $year == $ymax ? intval($mmax) : 12; | |
177 | ||
178 | for($i = $min; $i<=$max; $i++) { | |
179 | $months[$i] = $i; | |
180 | } | |
181 | } | |
182 | return $months; | |
183 | } | |
184 | ||
185 | ||
186 | /** Retrieves the available years. | |
187 | * Obtains a list of years that we have log entries covering. | |
188 | * | |
189 | * @return array years we have log entries for. | |
190 | * @private | |
191 | */ | |
192 | function _getYears() | |
193 | { | |
194 | // give a 'no filter' option | |
195 | $years[0] = "----"; | |
196 | ||
197 | // retrieve available years | |
198 | $res = XDB::query("select YEAR(MAX(start)), YEAR(MIN(start)) FROM logger.sessions"); | |
199 | list($max, $min) = $res->fetchOneRow(); | |
200 | ||
201 | for($i = intval($min); $i<=$max; $i++) { | |
202 | $years[$i] = $i; | |
203 | } | |
204 | return $years; | |
205 | } | |
206 | ||
207 | ||
208 | /** Make a where clause to get a user's sessions. | |
209 | * Prepare the where clause request that will retrieve the sessions. | |
210 | * | |
211 | * @param $year INTEGER Only get log entries made during the given year. | |
212 | * @param $month INTEGER Only get log entries made during the given month. | |
213 | * @param $day INTEGER Only get log entries made during the given day. | |
214 | * @param $uid INTEGER Only get log entries referring to the given user ID. | |
215 | * | |
216 | * @return STRING the WHERE clause of a query, including the 'WHERE' keyword | |
217 | * @private | |
218 | */ | |
219 | function _makeWhere($year, $month, $day, $uid) | |
220 | { | |
221 | // start constructing the "where" clause | |
222 | $where = array(); | |
223 | ||
224 | if ($uid) | |
225 | array_push($where, "uid='$uid'"); | |
226 | ||
227 | // we were given at least a year | |
228 | if ($year) { | |
229 | if ($day) { | |
230 | $dmin = mktime(0, 0, 0, $month, $day, $year); | |
231 | $dmax = mktime(0, 0, 0, $month, $day+1, $year); | |
232 | } elseif ($month) { | |
233 | $dmin = mktime(0, 0, 0, $month, 1, $year); | |
234 | $dmax = mktime(0, 0, 0, $month+1, 1, $year); | |
235 | } else { | |
236 | $dmin = mktime(0, 0, 0, 1, 1, $year); | |
237 | $dmax = mktime(0, 0, 0, 1, 1, $year+1); | |
238 | } | |
239 | $where[] = "start >= " . date("Ymd000000", $dmin); | |
240 | $where[] = "start < " . date("Ymd000000", $dmax); | |
241 | } | |
242 | ||
243 | if (!empty($where)) { | |
244 | return ' WHERE ' . implode($where, " AND "); | |
245 | } else { | |
246 | return ''; | |
247 | } | |
248 | // WE know it's totally reversed, so better use array_reverse than a SORT BY start DESC | |
249 | } | |
250 | ||
251 | // }}} | |
252 | ||
253 | function handler_logger(&$page, $action = null, $arg = null) { | |
254 | if ($action == 'session') { | |
255 | ||
256 | // we are viewing a session | |
257 | $res = XDB::query("SELECT ls.*, a.alias AS username, sa.alias AS suer | |
258 | FROM logger.sessions AS ls | |
259 | LEFT JOIN aliases AS a ON (a.id = ls.uid AND a.type='a_vie') | |
260 | LEFT JOIN aliases AS sa ON (sa.id = ls.suid AND sa.type='a_vie') | |
261 | WHERE ls.id = {?}", $arg); | |
262 | ||
263 | $page->assign('session', $a = $res->fetchOneAssoc()); | |
264 | ||
504ccd57 | 265 | $res = XDB::iterator('SELECT a.text, e.data, e.stamp |
441e9e98 | 266 | FROM logger.events AS e |
267 | LEFT JOIN logger.actions AS a ON e.action=a.id | |
268 | WHERE e.session={?}', $arg); | |
269 | while ($myarr = $res->next()) { | |
270 | $page->append('events', $myarr); | |
271 | } | |
272 | ||
273 | } else { | |
274 | $loguser = $action == 'user' ? $arg : Env::v('loguser'); | |
275 | ||
276 | $res = XDB::query('SELECT id FROM aliases WHERE alias={?}', | |
277 | $loguser); | |
278 | $loguid = $res->fetchOneCell(); | |
279 | ||
280 | if ($loguid) { | |
281 | $year = Env::i('year'); | |
282 | $month = Env::i('month'); | |
283 | $day = Env::i('day'); | |
284 | } else { | |
285 | $year = Env::i('year', intval(date('Y'))); | |
286 | $month = Env::i('month', intval(date('m'))); | |
287 | $day = Env::i('day', intval(date('d'))); | |
288 | } | |
289 | ||
290 | if (!$year) | |
291 | $month = 0; | |
292 | if (!$month) | |
293 | $day = 0; | |
294 | ||
295 | // smarty assignments | |
296 | // retrieve available years | |
297 | $page->assign('years', $this->_getYears()); | |
298 | $page->assign('year', $year); | |
299 | ||
300 | // retrieve available months for the current year | |
301 | $page->assign('months', $this->_getMonths($year)); | |
302 | $page->assign('month', $month); | |
303 | ||
304 | // retrieve available days for the current year and month | |
305 | $page->assign('days', $this->_getDays($year, $month)); | |
306 | $page->assign('day', $day); | |
307 | ||
308 | $page->assign('loguser', $loguser); | |
309 | // smarty assignments | |
310 | ||
311 | if ($loguid || $year) { | |
312 | ||
313 | // get the requested sessions | |
314 | $where = $this->_makeWhere($year, $month, $day, $loguid); | |
504ccd57 | 315 | $select = "SELECT s.id, s.start, s.uid, |
441e9e98 | 316 | a.alias as username |
317 | FROM logger.sessions AS s | |
318 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type='a_vie') | |
319 | $where | |
320 | ORDER BY start DESC"; | |
321 | $res = XDB::iterator($select); | |
322 | ||
323 | $sessions = array(); | |
324 | while ($mysess = $res->next()) { | |
325 | $mysess['events'] = array(); | |
326 | $sessions[$mysess['id']] = $mysess; | |
327 | } | |
328 | array_reverse($sessions); | |
329 | ||
330 | // attach events | |
331 | $sql = "SELECT s.id, a.text | |
332 | FROM logger.sessions AS s | |
333 | LEFT JOIN logger.events AS e ON(e.session=s.id) | |
334 | INNER JOIN logger.actions AS a ON(a.id=e.action) | |
335 | $where"; | |
336 | ||
337 | $res = XDB::iterator($sql); | |
338 | while ($event = $res->next()) { | |
339 | array_push($sessions[$event['id']]['events'], $event['text']); | |
340 | } | |
341 | $page->assign_by_ref('sessions', $sessions); | |
342 | } else { | |
a7de4ef7 | 343 | $page->assign('msg_nofilters', "Sélectionner une annuée et/ou un utilisateur"); |
441e9e98 | 344 | } |
86f0a6af | 345 | } |
346 | ||
8b1f8e12 | 347 | $page->changeTpl('admin/logger-view.tpl'); |
86f0a6af | 348 | |
c4271d38 | 349 | $page->assign('xorg_title','Polytechnique.org - Administration - Logs des sessions'); |
86f0a6af | 350 | } |
351 | ||
f97f90f0 | 352 | function handler_user(&$page, $login = false) |
353 | { | |
84270653 | 354 | global $globals; |
86f0a6af | 355 | $page->changeTpl('admin/utilisateurs.tpl'); |
356 | $page->assign('xorg_title','Polytechnique.org - Administration - Edit/Su/Log'); | |
357 | require_once("emails.inc.php"); | |
358 | require_once("user.func.inc.php"); | |
359 | ||
360 | if (S::has('suid')) { | |
7cbf5d4b | 361 | $page->kill("Déjà en SUID !!!"); |
86f0a6af | 362 | } |
363 | ||
364 | if (Env::has('user_id')) { | |
5c5554b7 | 365 | $login = get_user_forlife(Env::i('user_id')); |
f97f90f0 | 366 | if (empty($login)) { |
367 | $login = Env::i('user_id'); | |
368 | } | |
86f0a6af | 369 | } elseif (Env::has('login')) { |
5c5554b7 | 370 | $login = get_user_forlife(Env::v('login')); |
86f0a6af | 371 | } |
372 | ||
373 | if(Env::has('logs_button') && $login) { | |
24b5c84d | 374 | pl_redirect("admin/logger?loguser=$login&year=".date('Y')."&month=".date('m')); |
86f0a6af | 375 | } |
376 | ||
377 | if (Env::has('ax_button') && $login) { | |
378 | pl_redirect("admin/synchro_ax/$login"); | |
379 | } | |
380 | ||
381 | if(Env::has('suid_button') && $login) { | |
382 | $_SESSION['log']->log("suid_start", "login by ".S::v('forlife')); | |
383 | $_SESSION['suid'] = $_SESSION; | |
384 | $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login); | |
385 | if($uid = $r->fetchOneCell()) { | |
b0964579 | 386 | start_connexion($uid, true); |
86f0a6af | 387 | pl_redirect(""); |
388 | } | |
389 | } | |
390 | ||
391 | if ($login) { | |
f97f90f0 | 392 | if (is_numeric($login)) { |
0be07aa6 | 393 | $r = XDB::query("SELECT *, a.alias AS forlife, |
394 | FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe, | |
1517a52d | 395 | (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err |
f97f90f0 | 396 | FROM auth_user_md5 AS u |
397 | LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie') | |
398 | WHERE u.user_id = {?}", $login); | |
399 | } else { | |
eaf30d86 | 400 | $r = XDB::query("SELECT *, a.alias AS forlife, |
0be07aa6 | 401 | FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe, |
1517a52d | 402 | (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err |
f97f90f0 | 403 | FROM auth_user_md5 AS u |
404 | INNER JOIN aliases AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login); | |
eaf30d86 | 405 | } |
86f0a6af | 406 | $mr = $r->fetchOneAssoc(); |
407 | ||
f97f90f0 | 408 | if (!is_numeric($login)) { //user has a forlife |
409 | $redirect = new Redirect($mr['user_id']); | |
410 | } | |
86f0a6af | 411 | |
412 | // Check if there was a submission | |
413 | foreach($_POST as $key => $val) { | |
414 | switch ($key) { | |
415 | case "add_fwd": | |
416 | $email = trim(Env::v('email')); | |
417 | if (!isvalid_email_redirection($email)) { | |
418 | $page->trig("invalid email $email"); | |
419 | } else { | |
420 | $redirect->add_email($email); | |
a7de4ef7 | 421 | $page->trig("Ajout de $email effectué"); |
86f0a6af | 422 | } |
423 | break; | |
424 | ||
425 | case "del_fwd": | |
426 | if (!empty($val)) { | |
427 | $redirect->delete_email($val); | |
428 | } | |
429 | break; | |
430 | ||
431 | case "del_alias": | |
432 | if (!empty($val)) { | |
f97f90f0 | 433 | XDB::execute("DELETE FROM aliases |
434 | WHERE id={?} AND alias={?} | |
435 | AND type!='a_vie' AND type!='homonyme'", $mr['user_id'], $val); | |
d91e720f | 436 | XDB::execute("UPDATE emails |
437 | SET rewrite = '' | |
438 | WHERE uid = {?} AND rewrite LIKE CONCAT({?}, '@%')", | |
eaf30d86 | 439 | $mr['user_id'], $val); |
86f0a6af | 440 | fix_bestalias($mr['user_id']); |
a7de4ef7 | 441 | $page->trig($val." a été supprimé"); |
86f0a6af | 442 | } |
443 | break; | |
441c2451 | 444 | case "activate_fwd": |
445 | if (!empty($val)) { | |
446 | $redirect->modify_one_email($val, true); | |
447 | } | |
448 | break; | |
449 | case "deactivate_fwd": | |
450 | if (!empty($val)) { | |
451 | $redirect->modify_one_email($val, false); | |
452 | } | |
453 | break; | |
454 | case "disable_fwd": | |
455 | $redirect->disable(); | |
456 | break; | |
457 | case "enable_fwd": | |
458 | $redirect->enable(); | |
459 | break; | |
460 | case "clean_fwd": | |
461 | if (!empty($val)) { | |
462 | $redirect->cleanErrors($val); | |
463 | } | |
464 | break; | |
86f0a6af | 465 | case "add_alias": |
bd5e1f3d | 466 | global $globals; |
467 | $alias = trim(Env::v('email')); | |
468 | if (strpos($alias, '@') !== false) { | |
469 | list($alias, $domain) = explode('@', $alias); | |
470 | } else { | |
471 | $domain = $globals->mail->domain; | |
472 | } | |
473 | if (!preg_match('/[-a-z0-9\.]+/s', $alias)) { | |
474 | $page->trig("'$alias' n'est pas un alias valide"); | |
475 | } | |
476 | if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { | |
477 | $req = new AliasReq($mr['user_id'], $alias, 'Admin request', false); | |
478 | if ($req->commit()) { | |
479 | $page->trig("Nouvel alias '$alias@$domain' attribué"); | |
480 | } else { | |
481 | $page->trig("Impossible d'ajouter l'alias '$alias@$domain', il est probablement déjà attribué"); | |
482 | } | |
483 | } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { | |
484 | if (XDB::execute("INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, 'alias')", | |
485 | $mr['user_id'], $alias)) { | |
486 | $page->trig("Nouvel alias '$alias' ajouté"); | |
487 | } else { | |
488 | $page->trig("Impossible d'ajouter l'alias '$alias', il est probablement déjà attribué"); | |
489 | } | |
490 | } else { | |
491 | $page->trig("Le domaine '$domain' n'est pas valide"); | |
492 | } | |
86f0a6af | 493 | break; |
494 | ||
495 | case "best": | |
496 | // 'bestalias' is the first bit of the set : 1 | |
497 | // 255 is the max for flags (8 sets max) | |
498 | XDB::execute("UPDATE aliases SET flags= flags & (255 - 1) WHERE id={?}", $mr['user_id']); | |
499 | XDB::execute("UPDATE aliases | |
500 | SET flags= flags | 1 | |
501 | WHERE id={?} AND alias={?}", $mr['user_id'], $val); | |
502 | break; | |
503 | ||
504 | ||
505 | // Editer un profil | |
506 | case "u_edit": | |
441c2451 | 507 | require_once('secure_hash.inc.php'); |
508 | $pass_encrypted = Env::v('newpass_clair') != "********" ? hash_encrypt(Env::v('newpass_clair')) : Env::v('passw'); | |
509 | $naiss = Env::v('naissanceN'); | |
510 | $deces = Env::v('decesN'); | |
511 | $perms = Env::v('permsN'); | |
512 | $prenm = Env::v('prenomN'); | |
513 | $nom = Env::v('nomN'); | |
514 | $promo = Env::i('promoN'); | |
515 | $sexe = Env::v('sexeN'); | |
516 | $comm = trim(Env::v('commentN')); | |
517 | $watch = Env::v('watchN'); | |
518 | $flags = ''; | |
519 | if ($sexe) { | |
520 | $flags = 'femme'; | |
521 | } | |
522 | if ($watch) { | |
523 | if ($flags) { | |
524 | $flags .= ','; | |
525 | } | |
526 | $flags .= 'watch'; | |
0be07aa6 | 527 | } |
0be07aa6 | 528 | |
441c2451 | 529 | if ($watch && !$comm) { |
530 | $page->trig("Il est nécessaire de mettre un commentaire pour surveiller un compte"); | |
531 | break; | |
532 | } | |
86f0a6af | 533 | |
7cbf5d4b | 534 | $watch = 'SELECT naissance, deces, password, perms, |
535 | prenom, nom, flags, promo, comment | |
536 | FROM auth_user_md5 | |
537 | WHERE user_id = ' . $mr['user_id']; | |
538 | $res = XDB::query($watch); | |
539 | $old_fields = $res->fetchOneAssoc(); | |
441c2451 | 540 | $query = "UPDATE auth_user_md5 SET |
541 | naissance = '$naiss', | |
542 | deces = '$deces', | |
543 | password = '$pass_encrypted', | |
544 | perms = '$perms', | |
545 | prenom = '".addslashes($prenm)."', | |
546 | nom = '".addslashes($nom)."', | |
547 | flags = '$flags', | |
548 | promo = $promo, | |
549 | comment = '".addslashes($comm)."' | |
550 | WHERE user_id = '{$mr['user_id']}'"; | |
551 | if (XDB::execute($query)) { | |
86f0a6af | 552 | user_reindex($mr['user_id']); |
553 | ||
7cbf5d4b | 554 | $res = XDB::query($watch); |
555 | $new_fields = $res->fetchOneAssoc(); | |
eaf30d86 | 556 | |
b71f7275 | 557 | $mailer = new PlMailer("admin/useredit.mail.tpl"); |
d588654c | 558 | $mailer->assign("user", S::v('forlife')); |
7cbf5d4b | 559 | $mailer->assign('old', $old_fields); |
560 | $mailer->assign('new', $new_fields); | |
86f0a6af | 561 | $mailer->send(); |
328d2791 PC |
562 | |
563 | // update number of subscribers (perms or deceased may have changed) | |
564 | update_NbIns(); | |
86f0a6af | 565 | |
a7de4ef7 | 566 | $page->trig("updaté correctement."); |
86f0a6af | 567 | } |
568 | if (Env::v('nomusageN') != $mr['nom_usage']) { | |
a11b5424 | 569 | require_once "xorg.misc.inc.php"; |
86f0a6af | 570 | set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN'))); |
571 | } | |
c53b5964 | 572 | if (Env::v('decesN') != $mr['deces']) { |
3ebe4a0a FB |
573 | require_once 'notifs.inc.php'; |
574 | register_watch_op($mr['user_id'], WATCH_DEATH, $mr['deces']); | |
c53b5964 | 575 | user_clear_all_subs($mr['user_id'], false); |
576 | } | |
0be07aa6 | 577 | $r = XDB::query("SELECT *, a.alias AS forlife, |
578 | FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe | |
f97f90f0 | 579 | FROM auth_user_md5 AS u |
580 | LEFT JOIN aliases AS a ON (a.id = u.user_id AND type= 'a_vie') | |
581 | WHERE u.user_id = {?}", $mr['user_id']); | |
86f0a6af | 582 | $mr = $r->fetchOneAssoc(); |
84270653 VZ |
583 | |
584 | // If GoogleApps is enabled, the user did choose to use synchronized passwords, | |
585 | // and the password was changed, updates the Google Apps password as well. | |
586 | if ($globals->mailstorage->googleapps_domain && Env::v('newpass_clair') != "********") { | |
587 | require_once 'googleapps.inc.php'; | |
588 | $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']); | |
589 | if ($account->g_status == 'active' && $account->sync_password) { | |
590 | $account->set_password($pass_encrypted); | |
591 | } | |
592 | } | |
593 | ||
594 | // If GoogleApps is enabled, and the user is now disabled, disables the Google Apps account as well. | |
595 | if ($globals->mailstorage->googleapps_domain && | |
596 | $new_fields['perms'] == 'disabled' && | |
597 | $new_fields['perms'] != $old_fields['perms']) { | |
598 | require_once 'googleapps.inc.php'; | |
599 | $account = new GoogleAppsAccount($mr['user_id'], $mr['forlife']); | |
600 | $account->suspend(); | |
601 | } | |
86f0a6af | 602 | break; |
603 | ||
604 | // DELETE FROM auth_user_md5 | |
605 | case "u_kill": | |
606 | user_clear_all_subs($mr['user_id']); | |
328d2791 PC |
607 | // update number of subscribers (perms or deceased may have changed) |
608 | update_NbIns(); | |
a7de4ef7 | 609 | $page->trig("'{$mr['user_id']}' a été désinscrit !"); |
b71f7275 | 610 | $mailer = new PlMailer("admin/useredit.mail.tpl"); |
d588654c | 611 | $mailer->assign("user", S::v('forlife')); |
9565d77a | 612 | $mailer->assign("deletion", true); |
86f0a6af | 613 | $mailer->send(); |
614 | break; | |
615 | } | |
616 | } | |
617 | ||
b7d19878 | 618 | $res = XDB::query("SELECT start, host |
619 | FROM logger.sessions | |
620 | WHERE uid={?} AND suid=0 | |
621 | ORDER BY start DESC | |
622 | LIMIT 1", $mr['user_id']); | |
86f0a6af | 623 | list($lastlogin,$host) = $res->fetchOneRow(); |
624 | $page->assign('lastlogin', $lastlogin); | |
625 | $page->assign('host', $host); | |
626 | ||
441c2451 | 627 | $res = XDB::iterator("SELECT alias |
628 | FROM virtual | |
629 | INNER JOIN virtual_redirect USING(vid) | |
bd5e1f3d | 630 | WHERE type = 'user' AND redirect LIKE '" . $mr['forlife'] . "@%'"); |
441c2451 | 631 | $page->assign('virtuals', $res); |
5c5554b7 | 632 | |
86f0a6af | 633 | $page->assign('aliases', XDB::iterator( |
634 | "SELECT alias, type='a_vie' AS for_life,FIND_IN_SET('bestalias',flags) AS best,expire | |
635 | FROM aliases | |
636 | WHERE id = {?} AND type!='homonyme' | |
637 | ORDER BY type!= 'a_vie'", $mr["user_id"])); | |
bd5e1f3d | 638 | if ($mr['perms'] != 'pending' && isset($redirect)) { |
639 | $page->assign('emails', $redirect->emails); | |
f97f90f0 | 640 | } |
86f0a6af | 641 | |
642 | $page->assign('mr',$mr); | |
643 | } | |
644 | } | |
1f53925a | 645 | |
646 | function getMatricule($line, $key) | |
647 | { | |
648 | $mat = $line['matricule']; | |
649 | $year = intval(substr($mat, 0, 3)); | |
650 | $rang = intval(substr($mat, 3, 3)); | |
651 | if ($year > 200) { $year /= 10; }; | |
652 | if ($year < 96) { | |
653 | return null; | |
654 | } else { | |
655 | return sprintf('%04u%04u', 1900+$year, $rang); | |
656 | } | |
657 | } | |
658 | ||
659 | function handler_promo(&$page, $action = null, $promo = null) | |
660 | { | |
661 | if (Env::has('promo')) { | |
662 | if(Env::i('promo') > 1900 && Env::i('promo') < 2050) { | |
eaf30d86 | 663 | $action = Env::v('valid_promo') == 'Ajouter des membres' ? 'add' : 'ax'; |
1f53925a | 664 | pl_redirect('admin/promo/' . $action . '/' . Env::i('promo')); |
665 | } else { | |
666 | $page->trig('Promo non valide'); | |
667 | } | |
668 | } | |
669 | ||
670 | $page->changeTpl('admin/promo.tpl'); | |
671 | if ($promo > 1900 && $promo < 2050 && ($action == 'add' || $action == 'ax')) { | |
672 | $page->assign('promo', $promo); | |
673 | } else { | |
674 | return; | |
675 | } | |
676 | ||
677 | $importer = new CSVImporter('auth_user_md5', 'matricule'); | |
678 | $importer->registerFunction('matricule', 'matricle Ecole vers X.org', array($this, 'getMatricule')); | |
679 | switch ($action) { | |
680 | case 'add': | |
440b63df | 681 | $fields = array('nom', 'nom_ini', 'prenom', 'naissance_ini', |
1f53925a | 682 | 'prenom_ini', 'promo', 'promo_sortie', 'flags', |
683 | 'matricule', 'matricule_ax', 'perms'); | |
684 | $importer->forceValue('promo', $promo); | |
685 | $importer->forceValue('promo_sortie', $promo + 3); | |
686 | break; | |
687 | case 'ax': | |
688 | $fields = array('matricule', 'matricule_ax'); | |
689 | break; | |
690 | } | |
691 | $importer->apply($page, "admin/promo/$action/$promo", $fields); | |
692 | } | |
693 | ||
86f0a6af | 694 | function handler_homonyms(&$page, $op = 'list', $target = null) { |
695 | $page->changeTpl('admin/homonymes.tpl'); | |
696 | $page->assign('xorg_title','Polytechnique.org - Administration - Homonymes'); | |
697 | require_once("homonymes.inc.php"); | |
74c55fd6 | 698 | |
86f0a6af | 699 | if ($target) { |
700 | if (! list($prenom,$nom,$forlife,$loginbis) = select_if_homonyme($target)) { | |
701 | $target=0; | |
702 | } else { | |
703 | $page->assign('nom',$nom); | |
704 | $page->assign('prenom',$prenom); | |
705 | $page->assign('forlife',$forlife); | |
706 | $page->assign('loginbis',$loginbis); | |
707 | } | |
708 | } | |
74c55fd6 | 709 | |
86f0a6af | 710 | $page->assign('op',$op); |
711 | $page->assign('target',$target); | |
74c55fd6 | 712 | |
86f0a6af | 713 | // on a un $target valide, on prepare les mails |
714 | if ($target) { | |
74c55fd6 | 715 | |
86f0a6af | 716 | // on examine l'op a effectuer |
717 | switch ($op) { | |
718 | case 'mail': | |
b7d19878 | 719 | send_warning_homonyme($prenom, $nom, $forlife, $loginbis); |
720 | switch_bestalias($target, $loginbis); | |
86f0a6af | 721 | $op = 'list'; |
722 | break; | |
723 | case 'correct': | |
b7d19878 | 724 | switch_bestalias($target, $loginbis); |
86f0a6af | 725 | XDB::execute("UPDATE aliases SET type='homonyme',expire=NOW() WHERE alias={?}", $loginbis); |
726 | XDB::execute("REPLACE INTO homonymes (homonyme_id,user_id) VALUES({?},{?})", $target, $target); | |
b7d19878 | 727 | send_robot_homonyme($prenom, $nom, $forlife, $loginbis); |
86f0a6af | 728 | $op = 'list'; |
729 | break; | |
730 | } | |
731 | } | |
74c55fd6 | 732 | |
86f0a6af | 733 | if ($op == 'list') { |
734 | $res = XDB::iterator( | |
735 | "SELECT a.alias AS homonyme,s.id AS user_id,s.alias AS forlife, | |
736 | promo,prenom,nom, | |
737 | IF(h.homonyme_id=s.id, a.expire, NULL) AS expire, | |
738 | IF(h.homonyme_id=s.id, a.type, NULL) AS type | |
739 | FROM aliases AS a | |
740 | LEFT JOIN homonymes AS h ON (h.homonyme_id = a.id) | |
741 | INNER JOIN aliases AS s ON (s.id = h.user_id AND s.type='a_vie') | |
742 | INNER JOIN auth_user_md5 AS u ON (s.id=u.user_id) | |
743 | WHERE a.type='homonyme' OR a.expire!='' | |
744 | ORDER BY a.alias,promo"); | |
745 | $hnymes = Array(); | |
746 | while ($tab = $res->next()) { | |
747 | $hnymes[$tab['homonyme']][] = $tab; | |
748 | } | |
749 | $page->assign_by_ref('hnymes',$hnymes); | |
750 | } | |
751 | } | |
74c55fd6 | 752 | |
86f0a6af | 753 | function handler_ax_xorg(&$page) { |
754 | $page->changeTpl('admin/ax-xorg.tpl'); | |
755 | $page->assign('xorg_title','Polytechnique.org - Administration - AX/X.org'); | |
74c55fd6 | 756 | |
a7de4ef7 | 757 | // liste des différences |
86f0a6af | 758 | $res = XDB::query( |
759 | '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 | |
760 | FROM auth_user_md5 AS u | |
761 | INNER JOIN identification_ax AS ia ON u.matricule_ax = ia.matricule_ax | |
762 | WHERE (SOUNDEX(u.nom) != SOUNDEX(ia.nom) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom) | |
763 | AND SOUNDEX(u.nom) != SOUNDEX(ia.nom_patro) AND SOUNDEX(CONCAT(ia.particule,u.nom)) != SOUNDEX(ia.nom_patro)) | |
764 | OR u.prenom != ia.prenom OR (u.promo != ia.promo AND u.promo != ia.promo+1 AND u.promo != ia.promo-1) | |
765 | ORDER BY u.promo,u.nom,u.prenom'); | |
766 | $page->assign('diffs', $res->fetchAllAssoc()); | |
74c55fd6 | 767 | |
7cbf5d4b | 768 | // gens à l'ax mais pas chez nous |
86f0a6af | 769 | $res = XDB::query( |
770 | 'SELECT ia.promo,ia.nom,ia.nom_patro,ia.prenom | |
771 | FROM identification_ax as ia | |
772 | LEFT JOIN auth_user_md5 AS u ON u.matricule_ax = ia.matricule_ax | |
773 | WHERE u.nom IS NULL'); | |
774 | $page->assign('mank', $res->fetchAllAssoc()); | |
74c55fd6 | 775 | |
7cbf5d4b | 776 | // gens chez nous et pas à l'ax |
86f0a6af | 777 | $res = XDB::query('SELECT promo,nom,prenom FROM auth_user_md5 WHERE matricule_ax IS NULL'); |
778 | $page->assign('plus', $res->fetchAllAssoc()); | |
779 | } | |
74c55fd6 | 780 | |
86f0a6af | 781 | function handler_deaths(&$page, $promo = 0, $validate = false) { |
782 | $page->changeTpl('admin/deces_promo.tpl'); | |
783 | $page->assign('xorg_title','Polytechnique.org - Administration - Deces'); | |
74c55fd6 | 784 | |
86f0a6af | 785 | if (!$promo) |
786 | $promo = Env::i('promo'); | |
787 | if (Env::has('sub10')) $promo -= 10; | |
788 | if (Env::has('sub01')) $promo -= 1; | |
789 | if (Env::has('add01')) $promo += 1; | |
790 | if (Env::has('add10')) $promo += 10; | |
74c55fd6 | 791 | |
86f0a6af | 792 | $page->assign('promo',$promo); |
74c55fd6 | 793 | |
86f0a6af | 794 | if ($validate) { |
795 | $new_deces = array(); | |
796 | $res = XDB::iterRow("SELECT user_id,matricule,nom,prenom,deces FROM auth_user_md5 WHERE promo = {?}", $promo); | |
797 | while (list($uid,$mat,$nom,$prenom,$deces) = $res->next()) { | |
798 | $val = Env::v($mat); | |
b7d19878 | 799 | if($val == $deces || empty($val)) continue; |
800 | XDB::execute('UPDATE auth_user_md5 SET deces={?} WHERE matricule = {?}', $val, $mat); | |
801 | $new_deces[] = array('name' => "$prenom $nom", 'date' => "$val"); | |
802 | if($deces=='0000-00-00' or empty($deces)) { | |
803 | require_once('notifs.inc.php'); | |
804 | register_watch_op($uid, WATCH_DEATH, $val); | |
805 | require_once('user.func.inc.php'); | |
806 | user_clear_all_subs($uid, false); // by default, dead ppl do not loose their email | |
807 | } | |
86f0a6af | 808 | } |
809 | $page->assign('new_deces',$new_deces); | |
810 | } | |
74c55fd6 | 811 | |
86f0a6af | 812 | $res = XDB::iterator('SELECT matricule, nom, prenom, deces FROM auth_user_md5 WHERE promo = {?} ORDER BY nom,prenom', $promo); |
813 | $page->assign('decedes', $res); | |
814 | } | |
74c55fd6 | 815 | |
86f0a6af | 816 | function handler_synchro_ax(&$page, $user = null, $action = null) { |
817 | $page->changeTpl('admin/synchro_ax.tpl'); | |
818 | $page->assign('xorg_title','Polytechnique.org - Administration - Synchro AX'); | |
74c55fd6 | 819 | |
86f0a6af | 820 | require_once('synchro_ax.inc.php'); |
74c55fd6 | 821 | |
86f0a6af | 822 | if (is_ax_key_missing()) { |
823 | $page->assign('no_private_key', true); | |
824 | $page->run(); | |
825 | } | |
74c55fd6 | 826 | |
86f0a6af | 827 | require_once('user.func.inc.php'); |
828 | ||
829 | if ($user) | |
830 | $login = get_user_forlife($user); | |
831 | ||
832 | if (Env::has('user')) { | |
833 | $login = get_user_forlife(Env::v('user')); | |
834 | if ($login === false) { | |
835 | return; | |
836 | } | |
837 | } | |
74c55fd6 | 838 | |
86f0a6af | 839 | if (Env::has('mat')) { |
840 | $res = XDB::query( | |
74c55fd6 | 841 | "SELECT alias |
86f0a6af | 842 | FROM aliases AS a |
843 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') | |
844 | WHERE matricule={?}", Env::i('mat')); | |
845 | $login = $res->fetchOneCell(); | |
846 | } | |
74c55fd6 | 847 | |
86f0a6af | 848 | if ($login) { |
849 | if ($action == 'import') { | |
850 | ax_synchronize($login, S::v('uid')); | |
851 | } | |
852 | // get details from user, but looking only info that can be seen by ax | |
853 | $user = get_user_details($login, S::v('uid'), 'ax'); | |
854 | $userax= get_user_ax($user['matricule_ax']); | |
855 | require_once 'profil.func.inc.php'; | |
856 | $diff = diff_user_details($userax, $user, 'ax'); | |
74c55fd6 | 857 | |
86f0a6af | 858 | $page->assign('x', $user); |
859 | $page->assign('diff', $diff); | |
860 | } | |
861 | } | |
74c55fd6 | 862 | |
e654517d | 863 | function handler_validate(&$page, $action = 'list', $id = null) |
864 | { | |
86f0a6af | 865 | $page->changeTpl('admin/valider.tpl'); |
866 | $page->assign('xorg_title','Polytechnique.org - Administration - Valider une demande'); | |
441c2451 | 867 | $page->addCssLink('nl.css'); |
3ad44e08 | 868 | $page->addJsLink('ajax.js'); |
e654517d | 869 | require_once("validations.inc.php"); |
870 | ||
74c55fd6 | 871 | |
ed5b9703 | 872 | if ($action == 'edit' and !is_null($id)) { |
873 | $page->assign('preview_id', $id); | |
874 | } | |
875 | ||
86f0a6af | 876 | if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { |
20d7932b | 877 | $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); |
86f0a6af | 878 | if($req) { $req->handle_formu(); } |
879 | } | |
74c55fd6 | 880 | |
cfb96867 | 881 | $r = XDB::iterator('SHOW COLUMNS FROM requests_answers'); |
882 | while (($a = $r->next()) && $a['Field'] != 'category'); | |
883 | $page->assign('categories', $categories = explode(',', str_replace("'", '', substr($a['Type'], 5, -1)))); | |
74c55fd6 | 884 | |
cfb96867 | 885 | $hidden = array(); |
886 | if (Post::has('hide')) { | |
74c55fd6 | 887 | $hide = array(); |
888 | foreach ($categories as $cat) | |
cfb96867 | 889 | if (!Post::v($cat)) { |
890 | $hidden[$cat] = 1; | |
891 | $hide[] = $cat; | |
892 | } | |
893 | setcookie('hide_requests', join(',',$hide), time()+(count($hide)?25920000:(-3600)), '/', '', 0); | |
894 | } elseif (Env::has('hide_requests')) { | |
895 | foreach (explode(',',Env::v('hide_requests')) as $hide_type) | |
896 | $hidden[$hide_type] = true; | |
897 | } | |
898 | $page->assign('hide_requests', $hidden); | |
74c55fd6 | 899 | |
86f0a6af | 900 | $page->assign('vit', new ValidateIterator()); |
901 | } | |
e654517d | 902 | |
e18888f4 | 903 | function handler_validate_answers(&$page, $action = 'list', $id = null) { |
a7de4ef7 | 904 | $page->assign('xorg_title','Polytechnique.org - Administration - Réponses automatiques de validation'); |
905 | $page->assign('title', 'Gestion des réponses automatiques'); | |
e18888f4 | 906 | $table_editor = new PLTableEditor('admin/validate/answers','requests_answers','id'); |
a7de4ef7 | 907 | $table_editor->describe('category','catégorie',true); |
e18888f4 | 908 | $table_editor->describe('title','titre',true); |
909 | $table_editor->describe('answer','texte',false); | |
910 | $table_editor->apply($page, $action, $id); | |
911 | } | |
e7ae7df9 | 912 | function handler_skins(&$page, $action = 'list', $id = null) { |
e7ae7df9 | 913 | $page->assign('xorg_title','Polytechnique.org - Administration - Skins'); |
914 | $page->assign('title', 'Gestion des skins'); | |
915 | $table_editor = new PLTableEditor('admin/skins','skins','id'); | |
916 | $table_editor->describe('name','nom',true); | |
917 | $table_editor->describe('skin_tpl','nom du template',true); | |
918 | $table_editor->describe('auteur','auteur',false); | |
919 | $table_editor->describe('comment','commentaire',true); | |
920 | $table_editor->describe('date','date',false); | |
921 | $table_editor->describe('ext','extension du screenshot',false); | |
922 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 923 | } |
e7ae7df9 | 924 | function handler_postfix_blacklist(&$page, $action = 'list', $id = null) { |
e7ae7df9 | 925 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist'); |
926 | $page->assign('title', 'Blacklist de postfix'); | |
927 | $table_editor = new PLTableEditor('admin/postfix/blacklist','postfix_blacklist','email', true); | |
928 | $table_editor->describe('reject_text','Texte de rejet',true); | |
929 | $table_editor->describe('email','email',true); | |
930 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 931 | } |
e7ae7df9 | 932 | function handler_postfix_whitelist(&$page, $action = 'list', $id = null) { |
e7ae7df9 | 933 | $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Whitelist'); |
934 | $page->assign('title', 'Whitelist de postfix'); | |
935 | $table_editor = new PLTableEditor('admin/postfix/whitelist','postfix_whitelist','email', true); | |
936 | $table_editor->describe('email','email',true); | |
937 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 938 | } |
ccdbc270 | 939 | function handler_mx_broken(&$page, $action = 'list', $id = null) { |
a7de4ef7 | 940 | $page->assign('xorg_title', 'Polytechnique.org - Administration - MX Défaillants'); |
941 | $page->assign('title', 'MX Défaillant'); | |
ccdbc270 | 942 | $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true); |
943 | $table_editor->describe('host', 'Masque', true); | |
944 | $table_editor->describe('state', 'Niveau', true); | |
a7de4ef7 | 945 | $table_editor->describe('text', 'Description du problème', false); |
ccdbc270 | 946 | $table_editor->apply($page, $action, $id); |
947 | } | |
e7ae7df9 | 948 | function handler_logger_actions(&$page, $action = 'list', $id = null) { |
e7ae7df9 | 949 | $page->assign('xorg_title','Polytechnique.org - Administration - Actions'); |
950 | $page->assign('title', 'Gestion des actions de logger'); | |
951 | $table_editor = new PLTableEditor('admin/logger/actions','logger.actions','id'); | |
a7de4ef7 | 952 | $table_editor->describe('text','intitulé',true); |
e7ae7df9 | 953 | $table_editor->describe('description','description',true); |
954 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 955 | } |
e7ae7df9 | 956 | function handler_downtime(&$page, $action = 'list', $id = null) { |
e7ae7df9 | 957 | $page->assign('xorg_title','Polytechnique.org - Administration - Coupures'); |
958 | $page->assign('title', 'Gestion des coupures'); | |
959 | $table_editor = new PLTableEditor('admin/downtime','coupures','id'); | |
960 | $table_editor->describe('debut','date',true); | |
a7de4ef7 | 961 | $table_editor->describe('duree','durée',false); |
962 | $table_editor->describe('resume','résumé',true); | |
963 | $table_editor->describe('services','services affectés',true); | |
e7ae7df9 | 964 | $table_editor->describe('description','description',false); |
965 | $table_editor->apply($page, $action, $id); | |
74c55fd6 | 966 | } |
bc0903c7 | 967 | |
9162f4ed | 968 | function handler_wiki(&$page, $action='list', $wikipage='', $wikipage2='') |
bc0903c7 | 969 | { |
3aec1c21 | 970 | require_once 'wiki.inc.php'; |
74c55fd6 | 971 | |
a2b461ce | 972 | if (S::v('core_rss_hash')) { |
973 | $page->setRssLink('Changement Récents', | |
974 | '/Site/AllRecentChanges?action=rss&user=' . S::v('forlife') . '&hash=' . S::v('core_rss_hash')); | |
975 | } | |
3aec1c21 | 976 | // update wiki perms |
977 | if ($action == 'update') { | |
978 | $perms_read = Post::v('read'); | |
979 | $perms_edot = Post::v('edit'); | |
980 | if ($perms_read || $perms_edit) { | |
981 | foreach ($_POST as $wiki_page => $val) if ($val == 'on') { | |
982 | $wiki_page = str_replace('_', '/', $wiki_page); | |
983 | if (!$perms_read || !$perms_edit) | |
74c55fd6 | 984 | list($perms0, $perms1) = wiki_get_perms($wiki_page); |
3aec1c21 | 985 | if ($perms_read) |
986 | $perms0 = $perms_read; | |
987 | if ($perms_edit) | |
988 | $perms1 = $perms_edit; | |
989 | wiki_set_perms($wiki_page, $perms0, $perms1); | |
990 | } | |
991 | } | |
992 | } | |
eaf30d86 | 993 | |
9162f4ed | 994 | if ($action == 'delete' && $wikipage != '') { |
995 | if (wiki_delete_page($wikipage)) { | |
996 | $page->trig("La page ".$wikipage." a été supprimée."); | |
997 | } else { | |
998 | $page->trig("Impossible de supprimer la page ".$wikipage."."); | |
999 | } | |
1000 | } | |
eaf30d86 | 1001 | |
9162f4ed | 1002 | if ($action == 'rename' && $wikipage != '' && $wikipage2 != '' && $wikipage != $wikipage2) { |
1003 | if ($changedLinks = wiki_rename_page($wikipage, $wikipage2)) { | |
1004 | $s = 'La page <em>'.$wikipage.'</em> a été déplacée en <em>'.$wikipage2.'</em>.'; | |
1005 | if (is_numeric($changedLinks)) { | |
1006 | $s .= $changedLinks.' lien'.(($changedLinks>1)?'s ont été modifiés.':' a été modifié.'); | |
1007 | } | |
1008 | $page->trig($s); | |
1009 | } else { | |
1010 | $page->trig("Impossible de déplacer la page ".$wikipage); | |
1011 | } | |
1012 | } | |
74c55fd6 | 1013 | |
3aec1c21 | 1014 | $perms = wiki_perms_options(); |
74c55fd6 | 1015 | |
3aec1c21 | 1016 | // list wiki pages and their perms |
1017 | $wiki_pages = array(); | |
1018 | $dir = wiki_work_dir(); | |
1019 | if (is_dir($dir)) { | |
1020 | if ($dh = opendir($dir)) { | |
1021 | while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') { | |
1022 | list($read,$edit) = wiki_get_perms($file); | |
1023 | $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]); | |
4694ce89 | 1024 | if (is_file($dir . '/cache_' . wiki_filename($file) . '.tpl')) { |
1025 | $wiki_pages[$file]['cached'] = true; | |
1026 | } | |
3aec1c21 | 1027 | } |
1028 | closedir($dh); | |
1029 | } | |
1030 | } | |
1031 | ksort($wiki_pages); | |
bc0903c7 | 1032 | $wiki_tree = array(); |
1033 | foreach ($wiki_pages as $file => $desc) { | |
1034 | list($cat, $name) = explode('.', $file); | |
1035 | if (!isset($wiki_tree[$cat])) { | |
1036 | $wiki_tree[$cat] = array(); | |
1037 | } | |
1038 | $wiki_tree[$cat][$name] = $desc; | |
1039 | } | |
1040 | ||
3aec1c21 | 1041 | $page->changeTpl('admin/wiki.tpl'); |
e923a0ce | 1042 | $page->addJsLink('jquery.js'); |
bc0903c7 | 1043 | $page->assign('wiki_pages', $wiki_tree); |
3aec1c21 | 1044 | $page->assign('perms_opts', $perms); |
1045 | } | |
5480a216 | 1046 | |
1047 | function handler_ipwatch(&$page, $action = 'list', $ip = null) | |
eaf30d86 | 1048 | { |
5480a216 | 1049 | $page->changeTpl('admin/ipwatcher.tpl'); |
eaf30d86 | 1050 | |
5480a216 | 1051 | $states = array('safe' => 'Ne pas surveiller', |
c339246f | 1052 | 'unsafe' => 'Surveiller les inscriptions', |
a7de4ef7 | 1053 | 'dangerous' => 'Surveiller tous les accès', |
5480a216 | 1054 | 'ban' => 'Bannir cette adresse'); |
1055 | $page->assign('states', $states); | |
1056 | ||
1057 | switch (Post::v('action')) { | |
1058 | case 'create': | |
1059 | if (trim(Post::v('ipN')) != '') { | |
1060 | Xdb::execute('INSERT IGNORE INTO ip_watch (ip, state, detection, last, uid, description) | |
1061 | VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', | |
9797734d | 1062 | ip_to_uint(trim(Post::v('ipN'))), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); |
eaf30d86 PH |
1063 | }; |
1064 | break; | |
1065 | ||
1066 | case 'edit': | |
1067 | Xdb::execute('UPDATE ip_watch | |
5480a216 | 1068 | SET state = {?}, last = NOW(), uid = {?}, description = {?} |
9797734d FB |
1069 | WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), |
1070 | ip_to_uint(Post::v('ipN'))); | |
5480a216 | 1071 | break; |
eaf30d86 | 1072 | |
5480a216 | 1073 | default: |
1074 | if ($action == 'delete' && !is_null($ip)) { | |
9797734d | 1075 | Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip)); |
5480a216 | 1076 | } |
1077 | } | |
1078 | if ($action != 'create' && $action != 'edit') { | |
1079 | $action = 'list'; | |
1080 | } | |
1081 | $page->assign('action', $action); | |
1082 | ||
1083 | if ($action == 'list') { | |
9797734d FB |
1084 | $sql = "SELECT w.ip, IF(s.ip IS NULL, |
1085 | IF(w.ip = s2.ip, s2.host, s2.forward_host), | |
1086 | IF(w.ip = s.ip, s.host, s.forward_host)), | |
1087 | w.detection, w.state, a.alias AS forlife | |
5480a216 | 1088 | FROM ip_watch AS w |
9797734d FB |
1089 | LEFT JOIN logger.sessions AS s ON (s.ip = w.ip) |
1090 | LEFT JOIN logger.sessions AS s2 ON (s2.forward_ip = w.ip) | |
1091 | LEFT JOIN aliases AS a ON (a.id = s.uid AND a.type = 'a_vie') | |
5480a216 | 1092 | GROUP BY w.ip, a.alias |
1093 | ORDER BY w.state, w.ip, a.alias"; | |
1094 | $it = Xdb::iterRow($sql); | |
1095 | ||
1096 | $table = array(); | |
1097 | $props = array(); | |
1098 | while (list($ip, $host, $date, $state, $forlife) = $it->next()) { | |
9797734d | 1099 | $ip = uint_to_ip($ip); |
5480a216 | 1100 | if (count($props) == 0 || $props['ip'] != $ip) { |
1101 | if (count($props) > 0) { | |
1102 | $table[] = $props; | |
1103 | } | |
1104 | $props = array('ip' => $ip, | |
1105 | 'host' => $host, | |
1106 | 'detection' => $date, | |
1107 | 'state' => $state, | |
1108 | 'users' => array($forlife)); | |
1109 | } else { | |
1110 | $props['users'][] = $forlife; | |
1111 | } | |
1112 | } | |
1113 | if (count($props) > 0) { | |
1114 | $table[] = $props; | |
1115 | } | |
1116 | $page->assign('table', $table); | |
1117 | } elseif ($action == 'edit') { | |
1118 | $sql = "SELECT w.detection, w.state, w.last, w.description, | |
1119 | a1.alias AS edit, a2.alias AS forlife, s.host | |
1120 | FROM ip_watch AS w | |
eaf30d86 | 1121 | LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') |
5480a216 | 1122 | LEFT JOIN logger.sessions AS s ON (w.ip = s.ip) |
1123 | LEFT JOIN aliases AS a2 ON (a2.id = s.uid AND a2.type = 'a_vie') | |
1124 | WHERE w.ip = {?} | |
1125 | GROUP BY a2.alias | |
1126 | ORDER BY a2.alias"; | |
9797734d | 1127 | $it = Xdb::iterRow($sql, ip_to_uint($ip)); |
5480a216 | 1128 | |
1129 | $props = array(); | |
1130 | while (list($detection, $state, $last, $description, $edit, $forlife, $host) = $it->next()) { | |
1131 | if (count($props) == 0) { | |
1132 | $props = array('ip' => $ip, | |
1133 | 'host' => $host, | |
1134 | 'detection' => $detection, | |
1135 | 'state' => $state, | |
1136 | 'last' => $last, | |
1137 | 'description' => $description, | |
1138 | 'edit' => $edit, | |
1139 | 'users' => array($forlife)); | |
1140 | } else { | |
1141 | $props['users'][] = $forlife; | |
1142 | } | |
1143 | } | |
1144 | $page->assign('ip', $props); | |
1145 | } | |
1146 | } | |
eaf30d86 | 1147 | |
04148a2c | 1148 | function handler_icons(&$page) |
f141945d | 1149 | { |
1150 | $page->changeTpl('admin/icons.tpl'); | |
1151 | $dh = opendir('../htdocs/images/icons'); | |
1152 | if (!$dh) { | |
1153 | $page->trig('Dossier des icones introuvables.'); | |
1154 | } | |
1155 | $icons = array(); | |
1156 | while (($file = readdir($dh)) !== false) { | |
1157 | if (strlen($file) > 4 && substr($file,-4) == '.gif') { | |
1158 | array_push($icons, substr($file, 0, -4)); | |
1159 | } | |
1160 | } | |
1161 | sort($icons); | |
1162 | $page->assign('icons', $icons); | |
04148a2c | 1163 | } |
86f0a6af | 1164 | } |
1165 | ||
a7de4ef7 | 1166 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
86f0a6af | 1167 | ?> |