]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
log IP for API auth errors
authorEvan Prodromou <evan@controlyourself.ca>
Sat, 27 Jun 2009 14:37:58 +0000 (07:37 -0700)
committerEvan Prodromou <evan@controlyourself.ca>
Sat, 27 Jun 2009 14:37:58 +0000 (07:37 -0700)
actions/api.php
lib/util.php

index 1fe5875ad6b586d6ec2fe7f2938ceab0110797dd..08f5fadad99d70c657fa07a97e6cd972c7a1fc0d 100644 (file)
@@ -67,7 +67,9 @@ class ApiAction extends Action
                     $this->process_command();
                 } else {
                     # basic authentication failed
-                    common_log(LOG_WARNING, "Failed API auth attempt, nickname: $nickname.");
+                    list($proxy, $ip) = common_client_ip();
+
+                    common_log(LOG_WARNING, "Failed API auth attempt, nickname = $nickname, proxy = $proxy, ip = $ip.");
                     $this->show_basic_auth_error();
                 }
             }
index c8da8c7dd1228e919804c0d4b65cda4183c496ab..9c1af7a0dc6df113329b13435a47bdc439b130e0 100644 (file)
@@ -1490,4 +1490,28 @@ function common_shorten_url($long_url)
     curl_close($curlh);
 
     return $short_url;
-}
\ No newline at end of file
+}
+
+function common_client_ip()
+{
+    if (!isset($_SERVER) || !array_key_exists('REQUEST_METHOD', $_SERVER)) {
+        return null;
+    }
+
+    if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
+        if ($_SERVER['HTTP_CLIENT_IP']) {
+            $proxy = $_SERVER['HTTP_CLIENT_IP'];
+        } else {
+            $proxy = $_SERVER['REMOTE_ADDR'];
+        }
+        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+    } else {
+        if ($_SERVER['HTTP_CLIENT_IP']) {
+            $ip = $_SERVER['HTTP_CLIENT_IP'];
+        } else {
+            $ip = $_SERVER['REMOTE_ADDR'];
+        }
+    }
+
+    return array($ip, $proxy);
+}