<?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)
+{
+ 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'])) {
}
$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
}
$_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)
$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:
?>