X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fxorg.misc.inc.php;h=eefbfb291e76dde37d32f0d9cad3a621196d0ebc;hb=06df222b7962dd5b71b34ec1dd078276d7327dbc;hp=6447ddb3d06ec981f6604a997565b3eed4def898;hpb=33a55e8d5a9ad9d6d92fe66b6e52c9ea1149639a;p=platal.git diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index 6447ddb..eefbfb2 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -234,7 +234,17 @@ function make_forlife($prenom, $nom, $promo) */ function ip_to_uint($ip) { - return ip2long($ip); + $part = explode('.', $ip); + if (count($part) != 4) { + return null; + } + $v = 0; + $fact = 0x1000000; + for ($i = 0 ; $i < 4 ; ++$i) { + $v += $fact * $part[$i]; + $fact >>= 8; + } + return $v; } /** Convert uint to ip (to build a human understandable ip) @@ -261,14 +271,16 @@ function check_ip($level) } $ips[] = $_SERVER['REMOTE_ADDR']; foreach ($ips as &$ip) { - $ip = "ip = " . ip_to_uint($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'; } @@ -306,8 +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(); + if ($red->get_uid() == S::v('uid')) { + $_SESSION['no_redirect'] = !$red->other_active(''); + $_SESSION['mx_failures'] = $red->get_broken_mx(); + } } function send_warning_mail($title)