Updates ChangeLog.
[platal.git] / include / xorg.misc.inc.php
index 2ecaab8..2c8c88a 100644 (file)
@@ -1,6 +1,6 @@
 <?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   *
@@ -228,6 +228,25 @@ function make_forlife($prenom, $nom, $promo)
     return $forlife;
 }
 
+/** Convert ip to uint (to store it in a database)
+ */
+function ip_to_uint($ip)
+{
+    return ip2long($ip);
+}
+
+/** 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,7 +259,7 @@ function check_ip($level)
         }
         $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
@@ -287,20 +306,6 @@ function check_redirect($red = null)
     }
     $_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--;
-        }
-    }
-    $_SESSION['email_is_warning'] = ($warning <= 0 ? true : false);
 }
 
 function send_warning_mail($title)
@@ -315,5 +320,35 @@ function send_warning_mail($title)
     $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:
 ?>