Compare commits

...

4 commits

19 changed files with 40 additions and 111 deletions

6
composer.lock generated
View file

@ -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",

View file

@ -3,7 +3,7 @@ namespace Misuzu;
use RuntimeException;
use Index\Colour\Colour;
use Index\Colour\ColourRGB;
use Index\Colour\ColourRgb;
use Misuzu\Perm;
$authInfo = $msz->getAuthInfo();
@ -86,7 +86,7 @@ while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
$roleColour = $colourInherit
? Colour::none()
: new ColourRGB($colourRed, $colourGreen, $colourBlue);
: new ColourRgb($colourRed, $colourGreen, $colourBlue);
if(mb_strlen($roleDesc) > 1000) {
echo 'Description may not be longer than 1000 characters.';

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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(?), ?)');

View file

@ -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;
}

View file

@ -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;

View file

@ -22,7 +22,7 @@ class CommentsPostInfo {
) {}
public static function fromResult(
IDbResult $result,
DbResult $result,
bool $includeRepliesCount = false,
bool $includeVotesCount = false
): CommentsPostInfo {

View file

@ -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;
}

View file

@ -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;
}

View file

@ -2,16 +2,18 @@
namespace Misuzu;
use Index\Http\Routing\{HttpGet,RouteHandler,RouteHandlerTrait};
use Index\Urls\{UrlFormat,UrlRegistry,UrlSource,UrlSourceTrait};
use Index\Urls\{UrlFormat,UrlRegistry,UrlSource};
class LegacyRoutes implements RouteHandler, UrlSource {
use RouteHandlerTrait, UrlSourceTrait;
use RouteHandlerTrait;
public function __construct(
private UrlRegistry $urls
) {}
public function registerUrls(UrlRegistry $urls): void {
UrlFormat::register($urls, $this);
// eventually this should be handled by context classes
$urls->register('search-index', '/search.php');
$urls->register('search-query', '/search.php', ['q' => '<query>'], '<section>');

View file

@ -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;
}

View file

@ -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);

View file

@ -6,7 +6,7 @@ use Misuzu\SiteInfo;
use Misuzu\Users\Assets\UserAvatarAsset;
use Aiwass\Server\{RpcActionHandler,RpcQuery};
use Index\XArray;
use Index\Colour\{Colour,ColourRGB};
use Index\Colour\{Colour,ColourRgb};
use Index\Urls\UrlRegistry;
final class UsersRpcActions extends RpcActionHandler {
@ -35,7 +35,7 @@ final class UsersRpcActions extends RpcActionHandler {
} else {
// Index doesn't have a proper toRawRGB func???
$colourRaw = Colour::toMisuzu($colour) & 0xFFFFFF;
$colourCSS = (string)ColourRGB::convert($colour);
$colourCSS = (string)ColourRgb::convert($colour);
}
$baseUrl = $this->siteInfo->getURL();

View file

@ -28,13 +28,13 @@
<div class="manage__user-item__detail">
<i class="fas fa-user-plus fa-fw"></i>
<time datetime="{{ user.info.createdTime|date('c') }}" title="{{ user.info.createdTime|date('r') }}">{{ user.info.createdTime|time_format }}</time> /
<span>{{ user.info.registerRemoteAddressRaw }}</span>
<span>{{ user.info.registerRemoteAddress }}</span>
</div>
{% if user.info.hasLastActive %}
<div class="manage__user-item__detail">
<i class="fas fa-user-clock fa-fw"></i>
<time datetime="{{ user.info.lastActiveTime|date('c') }}" title="{{ user.info.lastActiveTime|date('r') }}">{{ user.info.lastActiveTime|time_format }}</time> /
<span>{{ user.info.lastRemoteAddressRaw }}</span>
<span>{{ user.info.lastRemoteAddress }}</span>
</div>
{% endif %}
{% if user.info.isDeleted %}

View file

@ -189,7 +189,7 @@
IP Address
</div>
<div class="settings__login-attempt__detail__value">
{{ attempt.remoteAddressRaw }}
{{ attempt.remoteAddress }}
</div>
</div>