feat: implement mail-login directadmin plugin
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
final class KeyName
|
||||
{
|
||||
public const MAX_LENGTH = 96;
|
||||
|
||||
public static function build(string $serverName, string $username, int $timestamp): string
|
||||
{
|
||||
$server = self::clean($serverName);
|
||||
$user = self::clean($username);
|
||||
$raw = 'autologin-' . $server . '-' . $user . '-' . $timestamp;
|
||||
if (strlen($raw) <= self::MAX_LENGTH) {
|
||||
return $raw;
|
||||
}
|
||||
$hash = substr(hash('sha256', $raw), 0, 10);
|
||||
$suffix = '-' . $hash . '-' . $timestamp;
|
||||
$bodyMax = self::MAX_LENGTH - strlen($suffix);
|
||||
$body = rtrim(substr('autologin-' . $server . '-' . $user, 0, $bodyMax), '-');
|
||||
return $body . $suffix;
|
||||
}
|
||||
|
||||
private static function clean(string $value): string
|
||||
{
|
||||
$value = strtolower(trim($value));
|
||||
$value = preg_replace('/[^a-z0-9-]+/', '-', $value) ?? '';
|
||||
$value = trim($value, '-');
|
||||
return $value !== '' ? $value : 'unknown';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user