X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fxorg.misc.inc.php;h=eefbfb291e76dde37d32f0d9cad3a621196d0ebc;hb=06df222b7962dd5b71b34ec1dd078276d7327dbc;hp=2ecaab80261ac87d0a5d595bef01c168a0bf13f6;hpb=a011bedd38f49c5a220cc3332692c9bdff33d3b7;p=platal.git diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index 2ecaab8..eefbfb2 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 +271,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 +318,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++; - } - } - foreach ($_SESSION['mx_failures'] as &$fail) { - if ($fail['state'] == 'broken') { - $warning -= 99999; - } else if ($fail['state'] == 'warning') { - $warning--; - } + if ($red->get_uid() == S::v('uid')) { + $_SESSION['no_redirect'] = !$red->other_active(''); + $_SESSION['mx_failures'] = $red->get_broken_mx(); } - $_SESSION['email_is_warning'] = ($warning <= 0 ? true : false); } function send_warning_mail($title) @@ -315,5 +336,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: ?>