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