[Web] Workaround for missing function when using API (fixes #1640)

[Web] Fixes SQL error on admin username change
This commit is contained in:
André
2018-08-05 22:31:53 +02:00
parent 9dd17d4609
commit 73f880ffba
3 changed files with 46 additions and 44 deletions

View File

@@ -52,6 +52,50 @@ catch (PDOException $e) {
exit;
}
// TODO: Move function
function get_remote_ip($anonymize = null) {
global $ANONYMIZE_IPS;
if ($anonymize === null) {
$anonymize = $ANONYMIZE_IPS;
}
elseif ($anonymize !== true && $anonymize !== false) {
$anonymize = true;
}
$remote = '';
if ($_SERVER['HTTP_CLIENT_IP']) {
$remote = $_SERVER['HTTP_CLIENT_IP'];
}
elseif ($_SERVER['HTTP_X_FORWARDED_FOR']) {
$remote = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
elseif ($_SERVER['HTTP_X_FORWARDED']) {
$remote = $_SERVER['HTTP_X_FORWARDED'];
}
elseif ($_SERVER['HTTP_FORWARDED_FOR']) {
$remote = $_SERVER['HTTP_FORWARDED_FOR'];
}
elseif ($_SERVER['HTTP_FORWARDED']) {
$remote = $_SERVER['HTTP_FORWARDED'];
}
elseif ($_SERVER['REMOTE_ADDR']) {
$remote = $_SERVER['REMOTE_ADDR'];
}
if (filter_var($remote, FILTER_VALIDATE_IP) === false) {
return '0.0.0.0';
}
if ($anonymize) {
if (strlen(inet_pton($remote)) == 4) {
return inet_ntop(inet_pton($remote) & inet_pton("255.255.255.0"));
}
elseif (strlen(inet_pton($remote)) == 16) {
return inet_ntop(inet_pton($remote) & inet_pton('ffff:ffff:ffff:ffff:0000:0000:0000:0000'));
}
}
else {
return $remote;
}
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/sessions.inc.php';
// Set language