[xiph-commits] r14899 - branches/dir.xiph.org/inc

balbinus at svn.xiph.org balbinus at svn.xiph.org
Sat May 17 02:46:38 PDT 2008


Author: balbinus
Date: 2008-05-17 02:46:37 -0700 (Sat, 17 May 2008)
New Revision: 14899

Modified:
   branches/dir.xiph.org/inc/lib.apilog.php
   branches/dir.xiph.org/inc/lib.utils.php
Log:
New function for obtaining the IP address.

Modified: branches/dir.xiph.org/inc/lib.apilog.php
===================================================================
--- branches/dir.xiph.org/inc/lib.apilog.php	2008-05-16 06:48:58 UTC (rev 14898)
+++ branches/dir.xiph.org/inc/lib.apilog.php	2008-05-17 09:46:37 UTC (rev 14899)
@@ -13,15 +13,18 @@
             $db->noReturnQuery('UPDATE api_log_cpt SET `id_log` = ((`id_log` MOD 10000) + 1) WHERE @prev_id := `id_log`;');
             $res = $db->singleQuery('SELECT @prev_id AS id;');
             $id = $res->current('id');*/
+            $ip = utils::getRealIp();
+            $ip = $ip !== false ? $ip : '127.0.0.1';
             
             $sql = 'INSERT INTO `api_log_%s` (`message`, `remote_ip`, `listen_url_hash`, `server_id`, `mountpoint_id`) '
                   .'VALUES ("%s", INET_ATON("%s"), "%s", %d, %d);';
             $sql = sprintf($sql, date('Ymd'),
                                  mysql_real_escape_string($result),
-                                 array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)
+/*                                 array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)
 								   ? $_SERVER['HTTP_X_FORWARDED_FOR']
 								           : array_key_exists('REMOTE_ADDR', $_SERVER)
-									  ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',
+									  ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',*/
+				 $ip,
                                  $listen_url !== null ? md5($listen_url) : 0,
                                  $server_id, $mountpoint_id);
             $db->noReturnQuery($sql);
@@ -89,15 +92,19 @@
             $db->noReturnQuery('UPDATE refused_log_cpt SET `id_log` = ((`id_log` MOD 5000) + 1) WHERE @prev_id := `id_log`;');
             $res = $db->singleQuery('SELECT @prev_id AS id;');
             $id = $res->current('id');*/
+            $ip = utils::getRealIp();
+            $ip = $ip !== false ? $ip : '127.0.0.1';
             
+            
             $sql = 'INSERT INTO `refused_log_%s` (`reason`, `remote_ip`, `listen_url`, `listen_url_hash`) '
               .'VALUES (%d, INET_ATON("%s"), "%s", %u);';
             $sql = sprintf($sql, date('Ymd'),
                                  intval($reason),
-                                 array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)
+/*                                 array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)
 								   ? $_SERVER['HTTP_X_FORWARDED_FOR']
 								           : array_key_exists('REMOTE_ADDR', $_SERVER)
-									  ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',
+									  ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',*/
+				 $ip,
                                  $listen_url != false ? mysql_real_escape_string($listen_url) : '',
                                  $listen_url != false ? sprintf('%u', crc32($listen_url)) : 0);
             $db->noReturnQuery($sql);

Modified: branches/dir.xiph.org/inc/lib.utils.php
===================================================================
--- branches/dir.xiph.org/inc/lib.utils.php	2008-05-16 06:48:58 UTC (rev 14898)
+++ branches/dir.xiph.org/inc/lib.utils.php	2008-05-17 09:46:37 UTC (rev 14899)
@@ -25,6 +25,21 @@
             return false;
         }
     }
+    
+    public static function getRealIp()
+    {
+        $ip = false;
+        if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER))
+        {
+                $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+        }
+        elseif (array_key_exists('REMOTE_ADDR', $_SERVER))
+        {
+                $ip = $_SERVER['REMOTE_ADDR'];
+        }
+
+        return $ip;
+    }
 }
 
 ?>



More information about the commits mailing list