X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fxorg.misc.inc.php;h=b025e7a465e3ddaee6d5f2f3994bfad8ccd01af7;hb=61e0e8619a9e391d9536d1af3c8cd441491bbc99;hp=2ecaab80261ac87d0a5d595bef01c168a0bf13f6;hpb=8f11b29f7600dfcc825065ce9e89e3c7866de5c6;p=platal.git diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index 2ecaab8..b025e7a 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -1,6 +1,6 @@ >= 8; + } + return $v; +} + +/** Convert uint to ip (to build a human understandable ip) + */ +function uint_to_ip($uint) +{ + return long2ip($uint); +} + + +/****************************************************************************** + * Security functions + *****************************************************************************/ + function check_ip($level) { if (empty($_SERVER['REMOTE_ADDR'])) { @@ -240,14 +268,16 @@ function check_ip($level) } $ips[] = $_SERVER['REMOTE_ADDR']; foreach ($ips as &$ip) { - $ip = "ip LIKE " . XDB::escape($ip); + $ip = '(ip & mask) = (' . ip_to_uint($ip) . '& mask)'; } - $res = XDB::query('SELECT state + $res = XDB::query('SELECT state, description FROM ip_watch WHERE ' . implode(' OR ', $ips) . ' ORDER BY state DESC'); if ($res->numRows()) { - $_SESSION['check_ip'] = $res->fetchOneCell(); + $state = $res->fetchOneAssoc(); + $_SESSION['check_ip'] = $state['state']; + $_SESSION['check_ip_desc'] = $state['description']; } else { $_SESSION['check_ip'] = 'safe'; } @@ -285,22 +315,10 @@ function check_redirect($red = null) if (is_null($red)) { $red = new Redirect(S::v('uid')); } - $_SESSION['no_redirect'] = !$red->other_active(''); - $_SESSION['mx_failures'] = $red->get_broken_mx(); - $warning = 0; - foreach ($red->emails as &$mail) { - if ($mail->active) { - $warning++; - } + if ($red->get_uid() == S::v('uid')) { + $_SESSION['no_redirect'] = !$red->other_active(''); + $_SESSION['mx_failures'] = $red->get_broken_mx(); } - foreach ($_SESSION['mx_failures'] as &$fail) { - if ($fail['state'] == 'broken') { - $warning -= 99999; - } else if ($fail['state'] == 'warning') { - $warning--; - } - } - $_SESSION['email_is_warning'] = ($warning <= 0 ? true : false); } function send_warning_mail($title) @@ -315,5 +333,41 @@ function send_warning_mail($title) $mailer->send(); } +function kill_sessions() +{ + assert(S::has_perms()); + shell_exec('sudo -u root ' . dirname(dirname(__FILE__)) . '/bin/kill_sessions.sh'); +} + + +/****************************************************************************** + * Dynamic configuration update/edition stuff + *****************************************************************************/ + +function update_NbIns() +{ + global $globals; + $res = XDB::query("SELECT COUNT(*) + FROM auth_user_md5 + WHERE perms IN ('admin','user') AND deces=0"); + $cnt = $res->fetchOneCell(); + $globals->change_dynamic_config(array('NbIns' => $cnt)); +} + +function update_NbValid() +{ + global $globals; + $res = XDB::query("SELECT COUNT(*) + FROM requests"); + $globals->change_dynamic_config(array('NbValid' => $res->fetchOneCell())); +} + +function update_NbNotifs() +{ + require_once 'notifs.inc.php'; + $n = select_notifs(false, S::i('uid'), S::v('watch_last'), false); + $_SESSION['notifs'] = $n->numRows(); +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>