diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php index 3ca51b45..d99661cb 100644 --- a/data/web/inc/functions.inc.php +++ b/data/web/inc/functions.inc.php @@ -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 { diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php index a3b67283..b938a56b 100644 --- a/data/web/inc/init_db.inc.php +++ b/data/web/inc/init_db.inc.php @@ -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" ) ) ), diff --git a/data/web/inc/prerequisites.inc.php b/data/web/inc/prerequisites.inc.php index ad201a68..1370155e 100644 --- a/data/web/inc/prerequisites.inc.php +++ b/data/web/inc/prerequisites.inc.php @@ -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