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

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

View File

@ -3,48 +3,6 @@ function hash_password($password) {
$salt_str = bin2hex(openssl_random_pseudo_bytes(8));
return "{SSHA256}".base64_encode(hash('sha256', $password . $salt_str, true) . $salt_str);
}
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;
}
}
function last_login($user) {
global $pdo;
try {

View File

@ -3,7 +3,7 @@ function init_db_schema() {
try {
global $pdo;
$db_version = "31072018_2319";
$db_version = "05072018_2319";
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@ -147,7 +147,7 @@ function init_db_schema() {
"col" => "username",
"ref" => "admin.username",
"delete" => "CASCADE",
"update" => "NO ACTION"
"update" => "CASCADE"
)
)
),

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