<?php
/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
+ * Copyright (C) 2003-2008 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
return $forlife;
}
+/** Convert ip to uint (to store it in a database)
+ */
+function ip_to_uint($ip)
+{
+ $part = explode('.', $ip);
+ $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)
+ */
+function uint_to_ip($uint)
+{
+ return sprintf('%d.%d.%d.%d', ($uint / 16777216) % 0xff,
+ ($uint / 65536) & 0xff,
+ ($uint / 256) & 0xff,
+ ($uint / 1.0) & 0xff);
+}
+
+
+/******************************************************************************
+ * Security functions
+ *****************************************************************************/
+
function check_ip($level)
{
if (empty($_SERVER['REMOTE_ADDR'])) {
}
$ips[] = $_SERVER['REMOTE_ADDR'];
foreach ($ips as &$ip) {
- $ip = "ip LIKE " . XDB::escape($ip);
+ $ip = "ip = " . ip_to_uint($ip);
}
$res = XDB::query('SELECT state
FROM ip_watch
$mailer->send();
}
+
+/******************************************************************************
+ * 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:
?>