Removed some refs to IPAddress class.

This commit is contained in:
flash 2018-09-27 09:15:33 +02:00
parent cbda92f72e
commit b0f6db2450
6 changed files with 16 additions and 12 deletions

View file

@ -169,7 +169,7 @@ switch ($authMode) {
break; break;
} }
$ipAddress = IPAddress::remote()->getString(); $ipAddress = remote_address();
$emailSent = Database::prepare(' $emailSent = Database::prepare('
SELECT COUNT(`verification_code`) > 0 SELECT COUNT(`verification_code`) > 0
FROM `msz_users_password_resets` FROM `msz_users_password_resets`
@ -235,7 +235,7 @@ MSG;
$authLoginError = ''; $authLoginError = '';
while ($isSubmission) { while ($isSubmission) {
$ipAddress = IPAddress::remote()->getString(); $ipAddress = remote_address();
if (!isset($authUsername, $authPassword)) { if (!isset($authUsername, $authPassword)) {
$authLoginError = "You didn't fill all the forms!"; $authLoginError = "You didn't fill all the forms!";
@ -343,7 +343,7 @@ MSG;
$authUsername, $authUsername,
$authPassword, $authPassword,
$authEmail, $authEmail,
IPAddress::remote()->getString() remote_address()
); );
if ($createUser < 1) { if ($createUser < 1) {

View file

@ -1,6 +1,5 @@
<?php <?php
use Misuzu\Database; use Misuzu\Database;
use Misuzu\Net\IPAddress;
require_once __DIR__ . '/../../misuzu.php'; require_once __DIR__ . '/../../misuzu.php';
@ -124,7 +123,7 @@ if ($postRequest) {
$topicId, $topicId,
$forum['forum_id'], $forum['forum_id'],
$app->getUserId(), $app->getUserId(),
IPAddress::remote()->getString(), remote_address(),
$postText, $postText,
MSZ_PARSER_BBCODE MSZ_PARSER_BBCODE
); );

View file

@ -141,7 +141,7 @@ final class IPAddress
public static function remote(string $fallbackAddress = self::FALLBACK_ADDRESS): IPAddress public static function remote(string $fallbackAddress = self::FALLBACK_ADDRESS): IPAddress
{ {
try { try {
return self::fromString($_SERVER['REMOTE_ADDR'] ?? $fallbackAddress); return self::fromString(remote_address($fallbackAddress));
} catch (InvalidArgumentException $ex) { } catch (InvalidArgumentException $ex) {
return self::fromString($fallbackAddress); return self::fromString($fallbackAddress);
} }

View file

@ -77,7 +77,7 @@ function user_bump_last_active(int $userId, string $ipAddress = null): void
`last_ip` = INET6_ATON(:last_ip) `last_ip` = INET6_ATON(:last_ip)
WHERE `user_id` = :user_id WHERE `user_id` = :user_id
'); ');
$bumpUserLast->bindValue('last_ip', $ipAddress ?? $_SERVER['REMOTE_ADDR'] ?? '::1'); $bumpUserLast->bindValue('last_ip', $ipAddress ?? remote_address());
$bumpUserLast->bindValue('user_id', $userId); $bumpUserLast->bindValue('user_id', $userId);
$bumpUserLast->execute(); $bumpUserLast->execute();
} }

View file

@ -6,9 +6,9 @@ function audit_log(
string $action, string $action,
int $userId = 0, int $userId = 0,
array $params = [], array $params = [],
IPAddress $ipAddress = null ?string $ipAddress = null
): void { ): void {
$ipAddress = $ipAddress ?? IPAddress::remote(); $ipAddress = $ipAddress ?? remote_address();
for ($i = 0; $i < count($params); $i++) { for ($i = 0; $i < count($params); $i++) {
if (preg_match('#^(-?[0-9]+)$#', $params[$i])) { if (preg_match('#^(-?[0-9]+)$#', $params[$i])) {
@ -20,13 +20,13 @@ function audit_log(
INSERT INTO `msz_audit_log` INSERT INTO `msz_audit_log`
(`log_action`, `user_id`, `log_params`, `log_ip`, `log_country`) (`log_action`, `user_id`, `log_params`, `log_ip`, `log_country`)
VALUES VALUES
(:action, :user, :params, :ip, :country) (:action, :user, :params, INET6_ATON(:ip), :country)
'); ');
$addLog->bindValue('action', $action); $addLog->bindValue('action', $action);
$addLog->bindValue('user', $userId < 1 ? null : $userId); $addLog->bindValue('user', $userId < 1 ? null : $userId);
$addLog->bindValue('params', json_encode($params)); $addLog->bindValue('params', json_encode($params));
$addLog->bindValue('ip', $ipAddress->getRaw()); $addLog->bindValue('ip', $ipAddress);
$addLog->bindValue('country', $ipAddress->getCountryCode()); $addLog->bindValue('country', get_country_code($ipAddress));
$addLog->execute(); $addLog->execute();
} }

View file

@ -29,6 +29,11 @@ function array_apply(array $array, callable $func): array
return $array; return $array;
} }
function remote_address(string $fallback = '::1'): string
{
return $_SERVER['REMOTE_ADDR'] ?? $fallback;
}
function set_cookie_m(string $name, string $value, int $expires): void function set_cookie_m(string $name, string $value, int $expires): void
{ {
setcookie( setcookie(