diff --git a/composer.lock b/composer.lock index 7cb8ba6..8b6d7f7 100644 --- a/composer.lock +++ b/composer.lock @@ -457,11 +457,11 @@ }, { "name": "flashwave/index", - "version": "v0.2410.42339", + "version": "v0.2410.51409", "source": { "type": "git", "url": "https://patchii.net/flash/index.git", - "reference": "d3e4d0985a1189d15fb8ed9eb105830c9dc38c4d" + "reference": "c43c6eb334f85edf8fa7b5e4058b3ba35a27d960" }, "require": { "ext-mbstring": "*", @@ -500,7 +500,7 @@ ], "description": "Composer package for the common library for my projects.", "homepage": "https://railgun.sh/index", - "time": "2024-10-04T23:39:32+00:00" + "time": "2024-10-05T14:10:08+00:00" }, { "name": "guzzlehttp/psr7", diff --git a/src/AuditLog/AuditLog.php b/src/AuditLog/AuditLog.php index 0b82baf..180a12d 100644 --- a/src/AuditLog/AuditLog.php +++ b/src/AuditLog/AuditLog.php @@ -3,7 +3,6 @@ namespace Misuzu\AuditLog; use InvalidArgumentException; use Index\Db\{DbConnection,DbStatementCache}; -use Index\Net\IPAddress; use Misuzu\Pagination; use Misuzu\Users\UserInfo; @@ -16,12 +15,10 @@ class AuditLog { public function countLogs( UserInfo|string|null $userInfo = null, - IPAddress|string|null $remoteAddr = null + ?string $remoteAddr = null ): int { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $hasUserInfo = $userInfo !== null; $hasRemoteAddr = $remoteAddr !== null; @@ -57,13 +54,11 @@ class AuditLog { public function getLogs( UserInfo|string|null $userInfo = null, - IPAddress|string|null $remoteAddr = null, + ?string $remoteAddr = null, ?Pagination $pagination = null ): iterable { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $hasUserInfo = $userInfo !== null; $hasRemoteAddr = $remoteAddr !== null; @@ -104,13 +99,11 @@ class AuditLog { UserInfo|string|null $userInfo, string $action, array $params = [], - IPAddress|string $remoteAddr = '::1', + string $remoteAddr = '::1', string $countryCode = 'XX' ): void { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; // action names should have stricter validation, // i do want to switch to a lowercase colon separated format later but i'll save that for the unified log in Hanyuu diff --git a/src/AuditLog/AuditLogInfo.php b/src/AuditLog/AuditLogInfo.php index 1689d72..77c9195 100644 --- a/src/AuditLog/AuditLogInfo.php +++ b/src/AuditLog/AuditLogInfo.php @@ -4,7 +4,6 @@ namespace Misuzu\AuditLog; use ValueError; use Carbon\CarbonImmutable; use Index\Db\DbResult; -use Index\Net\IPAddress; class AuditLogInfo { public function __construct( @@ -51,14 +50,10 @@ class AuditLogInfo { return CarbonImmutable::createFromTimestampUTC($this->created); } - public function getRemoteAddressRaw(): string { + public function getRemoteAddress(): string { return $this->address; } - public function getRemoteAddress(): IPAddress { - return IPAddress::parse($this->address); - } - public function getCountryCode(): string { return $this->country; } diff --git a/src/Auth/LoginAttemptInfo.php b/src/Auth/LoginAttemptInfo.php index 302ab31..bd24da7 100644 --- a/src/Auth/LoginAttemptInfo.php +++ b/src/Auth/LoginAttemptInfo.php @@ -4,7 +4,6 @@ namespace Misuzu\Auth; use Misuzu\ClientInfo; use Carbon\CarbonImmutable; use Index\Db\DbResult; -use Index\Net\IPAddress; class LoginAttemptInfo { public function __construct( @@ -41,14 +40,10 @@ class LoginAttemptInfo { return $this->success; } - public function getRemoteAddressRaw(): string { + public function getRemoteAddress(): string { return $this->remoteAddr; } - public function getRemoteAddress(): IPAddress { - return IPAddress::parse($this->remoteAddr); - } - public function getCountryCode(): string { return $this->countryCode; } diff --git a/src/Auth/LoginAttempts.php b/src/Auth/LoginAttempts.php index 2eb7d9b..b8027a7 100644 --- a/src/Auth/LoginAttempts.php +++ b/src/Auth/LoginAttempts.php @@ -2,7 +2,6 @@ namespace Misuzu\Auth; use Index\Db\{DbConnection,DbStatementCache}; -use Index\Net\IPAddress; use Misuzu\ClientInfo; use Misuzu\Pagination; use Misuzu\Users\UserInfo; @@ -20,13 +19,11 @@ class LoginAttempts { public function countAttempts( ?bool $success = null, UserInfo|string|null $userInfo = null, - IPAddress|string|null $remoteAddr = null, + ?string $remoteAddr = null, int|null $timeRange = null ): int { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $hasSuccess = $success !== null; $hasUserInfo = $userInfo !== null; @@ -65,7 +62,7 @@ class LoginAttempts { return $count; } - public function countRemainingAttempts(IPAddress|string $remoteAddr): int { + public function countRemainingAttempts(string $remoteAddr): int { return self::REMAINING_MAX - $this->countAttempts( success: false, timeRange: self::REMAINING_WINDOW, @@ -76,14 +73,12 @@ class LoginAttempts { public function getAttempts( ?bool $success = null, UserInfo|string|null $userInfo = null, - IPAddress|string|null $remoteAddr = null, - int|null $timeRange = null, + ?string $remoteAddr = null, + ?int $timeRange = null, ?Pagination $pagination = null ): iterable { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $hasSuccess = $success !== null; $hasUserInfo = $userInfo !== null; @@ -126,14 +121,12 @@ class LoginAttempts { public function recordAttempt( bool $success, - IPAddress|string $remoteAddr, + string $remoteAddr, string $countryCode, string $userAgentString, ?ClientInfo $clientInfo = null, UserInfo|string|null $userInfo = null ): void { - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); diff --git a/src/Auth/RecoveryTokenInfo.php b/src/Auth/RecoveryTokenInfo.php index ce48a47..fccacf1 100644 --- a/src/Auth/RecoveryTokenInfo.php +++ b/src/Auth/RecoveryTokenInfo.php @@ -3,7 +3,6 @@ namespace Misuzu\Auth; use Carbon\CarbonImmutable; use Index\Db\DbResult; -use Index\Net\IPAddress; class RecoveryTokenInfo { public const LIFETIME = 60 * 60; @@ -24,14 +23,10 @@ class RecoveryTokenInfo { return $this->userId; } - public function getRemoteAddressRaw(): string { + public function getRemoteAddress(): string { return $this->remoteAddr; } - public function getRemoteAddress(): IPAddress { - return IPAddress::parse($this->remoteAddr); - } - public function getCreatedTime(): int { return $this->created; } diff --git a/src/Auth/RecoveryTokens.php b/src/Auth/RecoveryTokens.php index c2970b5..798891c 100644 --- a/src/Auth/RecoveryTokens.php +++ b/src/Auth/RecoveryTokens.php @@ -5,7 +5,6 @@ use InvalidArgumentException; use RuntimeException; use Index\Base32; use Index\Db\{DbConnection,DbStatementCache}; -use Index\Net\IPAddress; use Misuzu\ClientInfo; use Misuzu\Pagination; use Misuzu\Users\UserInfo; @@ -24,14 +23,12 @@ class RecoveryTokens { public function getToken( UserInfo|string|null $userInfo = null, - IPAddress|string|null $remoteAddr = null, + ?string $remoteAddr = null, ?string $verifyCode = null, ?bool $isUnused = null ): RecoveryTokenInfo { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $hasUserInfo = $userInfo !== null; $hasRemoteAddr = $remoteAddr !== null; @@ -75,12 +72,11 @@ class RecoveryTokens { public function createToken( UserInfo|string $userInfo, - IPAddress|string $remoteAddr + string $remoteAddr ): RecoveryTokenInfo { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; + $verifyCode = self::generateCode(); $stmt = $this->cache->get('INSERT INTO msz_users_password_resets (user_id, reset_ip, verification_code) VALUES (?, INET6_ATON(?), ?)'); diff --git a/src/Auth/SessionInfo.php b/src/Auth/SessionInfo.php index e049977..03ae2d5 100644 --- a/src/Auth/SessionInfo.php +++ b/src/Auth/SessionInfo.php @@ -4,7 +4,6 @@ namespace Misuzu\Auth; use Misuzu\ClientInfo; use Carbon\CarbonImmutable; use Index\Db\DbResult; -use Index\Net\IPAddress; class SessionInfo { public function __construct( @@ -51,26 +50,18 @@ class SessionInfo { return $this->token; } - public function getFirstRemoteAddressRaw(): string { + public function getFirstRemoteAddress(): string { return $this->firstRemoteAddr; } - public function getFirstRemoteAddress(): IPAddress { - return IPAddress::parse($this->firstRemoteAddr); - } - public function hasLastRemoteAddress(): bool { return $this->lastRemoteAddr !== null; } - public function getLastRemoteAddressRaw(): string { + public function getLastRemoteAddress(): ?string { return $this->lastRemoteAddr; } - public function getLastRemoteAddress(): ?IPAddress { - return $this->lastRemoteAddr === null ? null : IPAddress::parse($this->lastRemoteAddr); - } - public function getUserAgentString(): string { return $this->userAgent; } diff --git a/src/Auth/Sessions.php b/src/Auth/Sessions.php index a65d434..d1623d9 100644 --- a/src/Auth/Sessions.php +++ b/src/Auth/Sessions.php @@ -5,7 +5,6 @@ use InvalidArgumentException; use RuntimeException; use Index\XString; use Index\Db\{DbConnection,DbStatementCache,DbTools}; -use Index\Net\IPAddress; use Misuzu\ClientInfo; use Misuzu\Pagination; use Misuzu\Users\UserInfo; @@ -121,15 +120,13 @@ class Sessions { public function createSession( UserInfo|string $userInfo, - IPAddress|string $remoteAddr, + string $remoteAddr, string $countryCode, string $userAgentString, ?ClientInfo $clientInfo = null ): SessionInfo { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $sessionToken = self::generateToken(); $clientInfo = json_encode($clientInfo ?? ClientInfo::parse($userAgentString)); @@ -241,7 +238,7 @@ class Sessions { public function recordSessionActivity( SessionInfo|string|null $sessionInfo = null, ?string $sessionToken = null, - IPAddress|string|null $remoteAddr = null + ?string $remoteAddr = null ): void { if($sessionInfo === null && $sessionToken === null) throw new InvalidArgumentException('Either $sessionInfo or $sessionToken needs to be set.'); @@ -249,8 +246,6 @@ class Sessions { throw new InvalidArgumentException('Only one of $sessionInfo and $sessionToken may be set at once.'); if($sessionInfo instanceof SessionInfo) $sessionInfo = $sessionInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $hasSessionInfo = $sessionInfo !== null; $hasSessionToken = $sessionToken !== null; diff --git a/src/Forum/ForumPostInfo.php b/src/Forum/ForumPostInfo.php index a41fff6..1f1cca8 100644 --- a/src/Forum/ForumPostInfo.php +++ b/src/Forum/ForumPostInfo.php @@ -5,7 +5,6 @@ use Misuzu\Parsers\Parser; use Carbon\CarbonImmutable; use Index\XDateTime; use Index\Db\DbResult; -use Index\Net\IPAddress; class ForumPostInfo { public function __construct( @@ -58,14 +57,10 @@ class ForumPostInfo { return $this->userId; } - public function getRemoteAddressRaw(): string { + public function getRemoteAddress(): string { return $this->remoteAddr; } - public function getRemoteAddress(): IPAddress { - return IPAddress::parse($this->remoteAddr); - } - public function getBody(): string { return $this->body; } diff --git a/src/Forum/ForumPosts.php b/src/Forum/ForumPosts.php index e9c0527..9797075 100644 --- a/src/Forum/ForumPosts.php +++ b/src/Forum/ForumPosts.php @@ -6,7 +6,6 @@ use RuntimeException; use stdClass; use Carbon\CarbonImmutable; use Index\Db\{DbConnection,DbStatementCache,DbTools}; -use Index\Net\IPAddress; use Misuzu\Pagination; use Misuzu\Users\UserInfo; @@ -265,7 +264,7 @@ class ForumPosts { public function createPost( ForumTopicInfo|string $topicInfo, UserInfo|string|null $userInfo, - IPAddress|string $remoteAddr, + string $remoteAddr, string $body, int $bodyParser, bool $displaySignature, @@ -283,9 +282,6 @@ class ForumPosts { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; - $stmt = $this->cache->get('INSERT INTO msz_forum_posts (topic_id, forum_id, user_id, post_ip, post_text, post_parse, post_display_signature) VALUES (?, ?, ?, INET6_ATON(?), ?, ?, ?)'); $stmt->addParameter(1, $topicInfo); $stmt->addParameter(2, $categoryInfo); @@ -301,7 +297,7 @@ class ForumPosts { public function updatePost( ForumPostInfo|string $postInfo, - IPAddress|string|null $remoteAddr = null, + ?string $remoteAddr = null, ?string $body = null, ?int $bodyParser = null, ?bool $displaySignature = null, @@ -314,9 +310,6 @@ class ForumPosts { $values = []; if($remoteAddr !== null) { - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; - $fields[] = 'post_ip = INET6_ATON(?)'; $values[] = $remoteAddr; } diff --git a/src/Users/UserInfo.php b/src/Users/UserInfo.php index ead325c..1644b6d 100644 --- a/src/Users/UserInfo.php +++ b/src/Users/UserInfo.php @@ -5,7 +5,6 @@ use Misuzu\Parsers\Parser; use Carbon\CarbonImmutable; use Index\Colour\Colour; use Index\Db\DbResult; -use Index\Net\IPAddress; class UserInfo { public function __construct( @@ -86,22 +85,14 @@ class UserInfo { return $this->emailAddr; } - public function getRegisterRemoteAddressRaw(): string { + public function getRegisterRemoteAddress(): string { return $this->registerRemoteAddr; } - public function getRegisterRemoteAddress(): IPAddress { - return IPAddress::parse($this->registerRemoteAddr); - } - - public function getLastRemoteAddressRaw(): string { + public function getLastRemoteAddress(): string { return $this->lastRemoteAddr; } - public function getLastRemoteAddress(): IPAddress { - return IPAddress::parse($this->lastRemoteAddr); - } - public function isSuperUser(): bool { return $this->super; } diff --git a/src/Users/Users.php b/src/Users/Users.php index 8808b81..45787ab 100644 --- a/src/Users/Users.php +++ b/src/Users/Users.php @@ -7,7 +7,6 @@ use DateTimeInterface; use Index\XString; use Index\Colour\Colour; use Index\Db\{DbConnection,DbStatementCache,DbTools}; -use Index\Net\IPAddress; use Misuzu\Pagination; use Misuzu\Tools; use Misuzu\Parsers\Parser; @@ -282,12 +281,10 @@ class Users { string $name, string $password, string $email, - IPAddress|string $remoteAddr, + string $remoteAddr, string $countryCode, RoleInfo|string|null $displayRoleInfo = null ): UserInfo { - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; if($displayRoleInfo instanceof RoleInfo) $displayRoleInfo = $displayRoleInfo->getId(); elseif($displayRoleInfo === null) @@ -436,12 +433,10 @@ class Users { public function recordUserActivity( UserInfo|string $userInfo, - IPAddress|string $remoteAddr + string $remoteAddr ): void { if($userInfo instanceof UserInfo) $userInfo = $userInfo->getId(); - if($remoteAddr instanceof IPAddress) - $remoteAddr = (string)$remoteAddr; $stmt = $this->cache->get('UPDATE msz_users SET user_active = NOW(), last_ip = INET6_ATON(?) WHERE user_id = ?'); $stmt->addParameter(1, $remoteAddr); diff --git a/templates/manage/users/users.twig b/templates/manage/users/users.twig index aef435b..8e196cb 100644 --- a/templates/manage/users/users.twig +++ b/templates/manage/users/users.twig @@ -28,13 +28,13 @@
/ - {{ user.info.registerRemoteAddressRaw }} + {{ user.info.registerRemoteAddress }}
{% if user.info.hasLastActive %}
/ - {{ user.info.lastRemoteAddressRaw }} + {{ user.info.lastRemoteAddress }}
{% endif %} {% if user.info.isDeleted %} diff --git a/templates/user/macros.twig b/templates/user/macros.twig index 5f4e729..e238dc2 100644 --- a/templates/user/macros.twig +++ b/templates/user/macros.twig @@ -189,7 +189,7 @@ IP Address
- {{ attempt.remoteAddressRaw }} + {{ attempt.remoteAddress }}