We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 70521d55 authored by Evan Prodromou's avatar Evan Prodromou

log IP for API auth errors

parent 7af94dc1
...@@ -67,7 +67,9 @@ class ApiAction extends Action ...@@ -67,7 +67,9 @@ class ApiAction extends Action
$this->process_command(); $this->process_command();
} else { } else {
# basic authentication failed # 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(); $this->show_basic_auth_error();
} }
} }
......
...@@ -1490,4 +1490,28 @@ function common_shorten_url($long_url) ...@@ -1490,4 +1490,28 @@ function common_shorten_url($long_url)
curl_close($curlh); curl_close($curlh);
return $short_url; 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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment