WebOrbiton
v1.3.1

AtheraStudio SyncDrop

458 lines · 23.2 KB
  1. <?php
  2. declare(strict_types=1);
  3. ​
  4. defined('SD_BOOT') || exit;
  5. ​
  6. const SD_BAN_THRESHOLD = 100;
  7. const SD_BAN_WINDOW = 86400;
  8. const SD_BAN_STEPS = [86400, 604800, 2592000];
  9. const SD_BAN_MEMORY = 7776000;
  10. const SD_BAN_MAX = 5000;
  11. const SD_ALLOW_MAX = 200;
  12. const SD_TRUST_TTL = 2592000;
  13. const SD_BAN_MAIL_LIMIT = 5;
  14. const SD_BAN_DURATIONS = [3600, 86400, 604800, 2592000, 0];
  15. const SD_THREATS = [
  16. 'scanner' => 100,
  17. 'signature' => 50,
  18. 'honeypot' => 50,
  19. 'pow_forged' => 30,
  20. 'pow_invalid' => 20,
  21. 'probe' => 20,
  22. 'method' => 30,
  23. 'host' => 20,
  24. 'api_anon' => 25,
  25. 'lockout' => 30,
  26. 'fail_setup_code' => 15,
  27. 'fail_password' => 10,
  28. 'fail_totp' => 10,
  29. 'fail_antibot' => 10,
  30. 'fail_captcha' => 10,
  31. 'fail_bot' => 0,
  32. 'bot_confessed' => 50,
  33. 'captcha_decoy' => 50,
  34. ];
  35. const SD_SCANNER_UA = '/(sqlmap|nikto|nmap|masscan|zgrab|wpscan|nuclei|dirbuster|gobuster|feroxbuster|ffuf|wfuzz|acunetix|netsparker|jaeles|whatweb|openvas|nessus|hydra|havij|commix|xsstrike|arachni|skipfish|w3af|zmeu|morfeus|fimap|dirsearch|nmap scripting engine)/i';
  36. const SD_ATTACK_PATTERNS = [
  37. '#\.\.(/|\\\\)#',
  38. '#(/etc/(passwd|shadow|hosts|group)|win\.ini|boot\.ini|/proc/self/)#',
  39. '#<\s*/?\s*(script|iframe|object|embed|svg|img|body)\b#',
  40. '#(javascript|vbscript|livescript)\s*:#',
  41. '#\bon(error|load|mouseover|focus|toggle|animationstart)\s*=#',
  42. '#\bunion\b[\s/*+()]{1,40}(all\s+)?select\b#',
  43. '#\b(sleep|benchmark|pg_sleep|extractvalue|updatexml)\s*\(#',
  44. '#\bwaitfor\s+delay\b#',
  45. '#[\'"]\s*(or|and|\|\||&&)\s*[\'"]?\s*\d+\s*[\'"]?\s*(=|<|>|like)#',
  46. '#\binformation_schema\b#',
  47. '#\$\{\s*(jndi|env|sys|java|lower|upper|::-)#',
  48. '#\b(base64_decode|shell_exec|passthru|proc_open|popen|assert|eval|system|exec|phpinfo|file_put_contents)\s*\(#',
  49. '#\b(php|phar|expect|zip|glob|data):/{1,2}#',
  50. '#/(usr/)?bin/(ba|z|da|k)?sh\b#',
  51. '#\b(wget|curl)\s+(-\S+\s+)*https?://#',
  52. '#(wp-(login|admin|content|includes|config|json)|xmlrpc\.php|phpmyadmin|/pma/|adminer|/\.env|\.git/|/\.aws|/\.ssh|cgi-bin|vendor/phpunit|eval-stdin|server-status|/actuator|hnap1|boaform|/owa/|\.ds_store|web\.config|\.htpasswd|/shell\.php|/(backup|dump|db|database|site)\.(zip|sql|tar|gz|rar|7z))#',
  53. ];
  54. ​
  55. function sd_ban_key(string $ip): string
  56. {
  57. if (!str_contains($ip, ':')) return $ip;
  58. return sd_cidr_parse($ip . '/64')['text'] ?? $ip;
  59. }
  60. ​
  61. function sd_shield_match(array $list, string $ip): ?array
  62. {
  63. $now = time();
  64. foreach ([$ip, sd_ban_key($ip)] as $key) {
  65. $entry = $list[$key] ?? null;
  66. if (is_array($entry) && sd_shield_active($entry, $now)) return [$key, $entry];
  67. }
  68. foreach ($list as $key => $entry) {
  69. $key = (string)$key;
  70. if (!str_contains($key, '/') || !is_array($entry) || !sd_shield_active($entry, $now)) continue;
  71. if (sd_cidr_contains($key, $ip)) return [$key, $entry];
  72. }
  73. return null;
  74. }
  75. ​
  76. function sd_shield_active(array $entry, int $now): bool
  77. {
  78. $until = (int)($entry['until'] ?? 0);
  79. return $until === 0 || $until > $now;
  80. }
  81. ​
  82. function sd_shield_allowed(?array $state = null): bool
  83. {
  84. $state ??= sd_read_state('bans');
  85. return sd_shield_match($state['allow'] ?? [], sd_ip()) !== null;
  86. }
  87. ​
  88. function sd_shield_trusted(?array $state = null): bool
  89. {
  90. $state ??= sd_read_state('bans');
  91. return (int)($state['trust'][sd_ban_key(sd_ip())] ?? 0) > time();
  92. }
  93. ​
  94. function sd_shield_exempt(): bool
  95. {
  96. if (session_status() === PHP_SESSION_ACTIVE && ($_SESSION['stage'] ?? '') === 'full') return true;
  97. $state = sd_read_state('bans');
  98. return sd_shield_allowed($state) || sd_shield_trusted($state);
  99. }
  100. ​
  101. function sd_shield_deny(int $code, string $message = ''): never
  102. {
  103. http_response_code($code);
  104. header('Content-Type: text/plain; charset=utf-8');
  105. $texts = [400 => 'Bad Request', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed'];
  106. echo $message !== '' ? $message : $code . ' ' . ($texts[$code] ?? 'Error');
  107. exit;
  108. }
  109. ​
  110. function sd_shield_text(string $raw): string
  111. {
  112. $once = rawurldecode($raw);
  113. $twice = rawurldecode($once);
  114. return strtolower($raw . "\n" . $once . "\n" . $twice . "\n" . html_entity_decode($twice, ENT_QUOTES | ENT_HTML5, 'UTF-8'));
  115. }
  116. ​
  117. function sd_shield_signature(string $text): bool
  118. {
  119. foreach (SD_ATTACK_PATTERNS as $re) {
  120. if (preg_match($re, $text)) return true;
  121. }
  122. return false;
  123. }
  124. ​
  125. function sd_shield_prune(array &$s, int $now): void
  126. {
  127. foreach (['bans', 'allow', 'trust', 'score', 'level'] as $k) {
  128. if (!isset($s[$k]) || !is_array($s[$k])) $s[$k] = [];
  129. }
  130. foreach ($s['bans'] as $k => $b) {
  131. if (!is_array($b) || !sd_shield_active($b, $now)) unset($s['bans'][$k]);
  132. }
  133. foreach ($s['trust'] as $k => $until) {
  134. if ((int)$until <= $now) unset($s['trust'][$k]);
  135. }
  136. foreach ($s['score'] as $k => $events) {
  137. $events = array_values(array_filter((array)$events, static fn($e) => is_array($e) && $now - (int)($e[0] ?? 0) < SD_BAN_WINDOW));
  138. if ($events) $s['score'][$k] = $events;
  139. else unset($s['score'][$k]);
  140. }
  141. foreach ($s['level'] as $k => $l) {
  142. if (!is_array($l) || $now - (int)($l[1] ?? 0) > SD_BAN_MEMORY) unset($s['level'][$k]);
  143. }
  144. foreach (['bans' => 'at', 'level' => 1, 'trust' => null, 'score' => null] as $k => $field) {
  145. if (count($s[$k]) <= SD_BAN_MAX) continue;
  146. uasort($s[$k], static function ($a, $b) use ($field): int {
  147. $ta = is_array($a) ? (int)($field === null ? (end($a)[0] ?? 0) : ($a[$field] ?? 0)) : (int)$a;
  148. $tb = is_array($b) ? (int)($field === null ? (end($b)[0] ?? 0) : ($b[$field] ?? 0)) : (int)$b;
  149. return $tb <=> $ta;
  150. });
  151. $s[$k] = array_slice($s[$k], 0, SD_BAN_MAX, true);
  152. }
  153. }
  154. ​
  155. function sd_threat(string $reason): bool
  156. {
  157. if (sd_shield_exempt()) return false;
  158. $points = SD_THREATS[$reason] ?? 10;
  159. $key = sd_ban_key(sd_ip());
  160. $result = sd_state('bans', static function (array &$s) use ($key, $reason, $points): ?array {
  161. $now = time();
  162. sd_shield_prune($s, $now);
  163. if (isset($s['bans'][$key])) return null;
  164. $events = $s['score'][$key] ?? [];
  165. $events[] = [$now, $points, $reason];
  166. $events = array_slice($events, -40);
  167. $total = array_sum(array_map(static fn($e) => (int)$e[1], $events));
  168. if ($total < SD_BAN_THRESHOLD) {
  169. $s['score'][$key] = $events;
  170. return null;
  171. }
  172. unset($s['score'][$key]);
  173. $level = (int)($s['level'][$key][0] ?? 0) + 1;
  174. $s['level'][$key] = [$level, $now];
  175. $until = $now + SD_BAN_STEPS[min($level, count(SD_BAN_STEPS)) - 1];
  176. $s['bans'][$key] = ['at' => $now, 'until' => $until, 'reason' => $reason, 'auto' => 1, 'note' => '', 'last' => $now, 'level' => $level];
  177. $mail = array_values(array_filter((array)($s['mail'] ?? []), static fn($t) => $now - (int)$t < 3600));
  178. $send = count($mail) < SD_BAN_MAIL_LIMIT;
  179. if ($send) $mail[] = $now;
  180. $s['mail'] = $mail;
  181. return ['until' => $until, 'level' => $level, 'mail' => $send];
  182. });
  183. if (!str_starts_with($reason, 'fail_')) sd_audit('threat', ['reason' => $reason, 'points' => $points]);
  184. if ($result === null) return false;
  185. sd_audit('ip_banned', ['ban' => $key, 'reason' => $reason, 'until' => gmdate('c', $result['until']), 'level' => $result['level']]);
  186. if ($result['mail']) {
  187. sd_alert('alert_ban_subject', 'alert_ban_body', ['ban' => $key, 'reason' => t('shield_r_' . $reason), 'until' => gmdate('Y-m-d H:i', $result['until']) . ' UTC']);
  188. }
  189. return true;
  190. }
  191. ​
  192. function sd_shield_trust(): void
  193. {
  194. $key = sd_ban_key(sd_ip());
  195. sd_state('bans', static function (array &$s) use ($key): void {
  196. $now = time();
  197. sd_shield_prune($s, $now);
  198. $s['trust'][$key] = $now + SD_TRUST_TTL;
  199. unset($s['score'][$key]);
  200. });
  201. }
  202. ​
  203. function sd_shield_gate(): void
  204. {
  205. $method = strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? 'GET'));
  206. $state = sd_read_state('bans');
  207. if (!sd_shield_allowed($state)) {
  208. $ban = sd_shield_match($state['bans'] ?? [], sd_ip());
  209. if ($ban !== null) {
  210. $now = time();
  211. if ($now - (int)($ban[1]['last'] ?? 0) >= 60) {
  212. sd_state('bans', static function (array &$s) use ($ban, $now): void {
  213. if (isset($s['bans'][$ban[0]])) $s['bans'][$ban[0]]['last'] = $now;
  214. });
  215. }
  216. sd_shield_deny(403, t('shield_blocked'));
  217. }
  218. if (preg_match(SD_SCANNER_UA, sd_ua())) {
  219. sd_threat('scanner');
  220. sd_shield_deny(403);
  221. }
  222. if (!in_array($method, ['GET', 'POST', 'HEAD'], true)) {
  223. sd_threat('method');
  224. sd_shield_deny(405);
  225. }
  226. if (sd_host() === '') {
  227. sd_threat('host');
  228. sd_shield_deny(400);
  229. }
  230. } elseif (sd_host() === '') {
  231. sd_shield_deny(400);
  232. }
  233. $probe = isset($_SERVER['SD_PROBE']) || isset($_SERVER['REDIRECT_SD_PROBE']);
  234. if (!$probe && sd_request_path_ok()) return;
  235. $uri = sd_shield_text((string)($_SERVER['REQUEST_URI'] ?? ''));
  236. $attack = sd_shield_signature($uri);
  237. if ($probe || $attack) {
  238. sd_threat($attack ? 'signature' : 'probe');
  239. sd_shield_deny(404);
  240. }
  241. if ($method !== 'GET') sd_shield_deny(404);
  242. header('Location: ' . sd_url_base(), true, 303);
  243. exit;
  244. }
  245. ​
  246. function sd_shield_inspect(): void
  247. {
  248. if (($_SESSION['stage'] ?? '') === 'full') return;
  249. $text = (string)($_SERVER['QUERY_STRING'] ?? '');
  250. foreach ($_POST as $name => $value) {
  251. if (in_array($name, ['password', 'password2', 'current', '_pow', '_nonce', '_csrf'], true)) continue;
  252. $text .= "\n" . (is_string($value) ? $value : (string)json_encode($value));
  253. }
  254. if (sd_shield_signature(sd_shield_text($text))) {
  255. sd_threat('signature');
  256. sd_shield_deny(403);
  257. }
  258. }
  259. ​
  260. function sd_shield_ban(string $address, int $duration, string $note): ?string
  261. {
  262. $range = sd_cidr_parse($address);
  263. if ($range === null) return 'err_ban_invalid';
  264. if ($range['bits'] < ($range['max'] === 32 ? 16 : 32)) return 'err_ban_range';
  265. if (sd_cidr_contains($range['text'], sd_ip())) return 'err_ban_self';
  266. if (!in_array($duration, SD_BAN_DURATIONS, true)) $duration = 86400;
  267. $note = mb_substr(trim((string)preg_replace('/[\x00-\x1F\x7F]/u', ' ', $note)), 0, 120);
  268. $key = $range['text'];
  269. sd_state('bans', static function (array &$s) use ($key, $duration, $note): void {
  270. $now = time();
  271. sd_shield_prune($s, $now);
  272. $s['bans'][$key] = ['at' => $now, 'until' => $duration === 0 ? 0 : $now + $duration, 'reason' => 'manual', 'auto' => 0, 'note' => $note, 'last' => 0, 'level' => 0];
  273. unset($s['score'][$key]);
  274. });
  275. sd_audit('ip_banned', ['ban' => $key, 'reason' => 'manual', 'until' => $duration === 0 ? 'permanent' : gmdate('c', time() + $duration)]);
  276. return null;
  277. }
  278. ​
  279. function sd_shield_unban(string $key): bool
  280. {
  281. $done = sd_state('bans', static function (array &$s) use ($key): bool {
  282. sd_shield_prune($s, time());
  283. $found = isset($s['bans'][$key]);
  284. unset($s['bans'][$key], $s['score'][$key], $s['level'][$key]);
  285. return $found;
  286. });
  287. if ($done) sd_audit('ip_unbanned', ['ban' => $key]);
  288. return $done;
  289. }
  290. ​
  291. function sd_shield_allow(string $address, string $note): ?string
  292. {
  293. $range = sd_cidr_parse($address);
  294. if ($range === null) return 'err_ban_invalid';
  295. if ($range['bits'] < ($range['max'] === 32 ? 16 : 32)) return 'err_ban_range';
  296. $key = $range['text'];
  297. $note = mb_substr(trim((string)preg_replace('/[\x00-\x1F\x7F]/u', ' ', $note)), 0, 120);
  298. $ok = sd_state('bans', static function (array &$s) use ($key, $note): bool {
  299. sd_shield_prune($s, time());
  300. if (!isset($s['allow'][$key]) && count($s['allow']) >= SD_ALLOW_MAX) return false;
  301. $s['allow'][$key] = ['at' => time(), 'note' => $note];
  302. return true;
  303. });
  304. if (!$ok) return 'err_allow_full';
  305. sd_audit('allow_added', ['ip' => $key]);
  306. return null;
  307. }
  308. ​
  309. function sd_shield_disallow(string $key): void
  310. {
  311. sd_state('bans', static function (array &$s) use ($key): void {
  312. unset($s['allow'][$key]);
  313. });
  314. sd_audit('allow_removed', ['ip' => $key]);
  315. }
  316. ​
  317. function sd_route_shield(): never
  318. {
  319. if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
  320. if (!sd_csrf_ok()) sd_redirect('shield');
  321. $error = null;
  322. $message = '';
  323. switch ((string)($_POST['action'] ?? '')) {
  324. case 'ban':
  325. $error = sd_shield_ban((string)($_POST['address'] ?? ''), (int)($_POST['duration'] ?? 86400), (string)($_POST['note'] ?? ''));
  326. $message = 'msg_banned';
  327. break;
  328. case 'unban':
  329. sd_shield_unban((string)($_POST['key'] ?? ''));
  330. $message = 'msg_unbanned';
  331. break;
  332. case 'allow':
  333. $error = sd_shield_allow((string)($_POST['address'] ?? ''), (string)($_POST['note'] ?? ''));
  334. $message = 'msg_allowed';
  335. break;
  336. case 'allow_me':
  337. $error = sd_shield_allow(sd_ip(), t('shield_me_note'));
  338. $message = 'msg_allowed';
  339. break;
  340. case 'disallow':
  341. sd_shield_disallow((string)($_POST['key'] ?? ''));
  342. $message = 'msg_allow_removed';
  343. break;
  344. }
  345. if ($message !== '') sd_flash($error === null ? 'ok' : 'error', t($error ?? $message));
  346. sd_redirect('shield');
  347. }
  348. sd_view_shield();
  349. exit;
  350. }
  351. ​
  352. function sd_shield_time(int $ts): string
  353. {
  354. return '<time class="sd-time" datetime="' . h(gmdate('c', $ts)) . '">' . h(gmdate('Y-m-d H:i', $ts)) . ' UTC</time>';
  355. }
  356. ​
  357. function sd_shield_form(string $action, string $key, string $label, string $tone, string $icon, string $confirm = ''): string
  358. {
  359. return '<form method="post" action="' . h(sd_url('shield')) . '"' . ($confirm !== '' ? ' data-confirm="' . h($confirm) . '"' : '') . '>' . sd_csrf_field()
  360. . '<input type="hidden" name="action" value="' . h($action) . '"><input type="hidden" name="key" value="' . h($key) . '">'
  361. . '<button type="submit" class="orb-btn orb-btn-outline orb-btn-sm orb-tone-' . h($tone) . '">' . sd_icon($icon, 14) . h($label) . '</button></form>';
  362. }
  363. ​
  364. function sd_view_shield(): void
  365. {
  366. sd_open(t('shield_title'), 'app', 'shield');
  367. $state = sd_read_state('bans');
  368. $now = time();
  369. $bans = array_filter((array)($state['bans'] ?? []), static fn($b) => is_array($b) && sd_shield_active($b, $now));
  370. uasort($bans, static fn($a, $b) => (int)($b['at'] ?? 0) <=> (int)($a['at'] ?? 0));
  371. $allow = (array)($state['allow'] ?? []);
  372. $watch = [];
  373. foreach ((array)($state['score'] ?? []) as $key => $events) {
  374. $events = array_values(array_filter((array)$events, static fn($e) => is_array($e) && $now - (int)($e[0] ?? 0) < SD_BAN_WINDOW));
  375. if (!$events || isset($bans[$key])) continue;
  376. $last = end($events);
  377. $watch[$key] = ['points' => array_sum(array_map(static fn($e) => (int)$e[1], $events)), 'reason' => (string)$last[2], 't' => (int)$last[0]];
  378. }
  379. uasort($watch, static fn($a, $b) => $b['points'] <=> $a['points']);
  380. $watch = array_slice($watch, 0, 50, true);
  381. $ip = sd_ip();
  382. $status = sd_shield_allowed($state) ? ['success', t('shield_allowed')] : (sd_shield_trusted($state) ? ['success', t('shield_trusted')] : ['neutral', t('shield_untrusted')]);
  383. $auto = count(array_filter($bans, static fn($b) => !empty($b['auto'])));
  384. ​
  385. echo '<p class="orb-lead orb-mb-4 sd-shield-lead">' . h(t('shield_lead')) . '</p>';
  386. echo '<div class="sd-stats sd-shield-stats orb-mb-4">'
  387. . '<div class="sd-stat"><span class="sd-stat-n orb-mono sd-shield-ip">' . h($ip) . '</span><span class="sd-stat-l">' . h(t('shield_your_ip')) . ' <span class="orb-pill orb-pill-' . $status[0] . '">' . h($status[1]) . '</span></span></div>'
  388. . '<div class="sd-stat"><span class="sd-stat-n">' . count($bans) . '</span><span class="sd-stat-l">' . h(t('shield_active')) . '</span><span class="orb-text-xs orb-text-muted">' . h(t('shield_active_split', ['a' => (string)$auto, 'm' => (string)(count($bans) - $auto)])) . '</span></div>'
  389. . '<div class="sd-stat"><span class="sd-stat-n">' . count($watch) . '</span><span class="sd-stat-l">' . h(t('shield_watched')) . '</span></div>'
  390. . '<div class="sd-stat"><span class="sd-stat-n">' . count($allow) . '</span><span class="sd-stat-l">' . h(t('shield_allow_title')) . '</span></div></div>';
  391. ​
  392. echo '<section class="orb-card"><div class="orb-card-header"><span class="orb-card-title">' . sd_icon('lock', 16) . ' ' . h(t('shield_bans')) . '</span><span class="orb-badge">' . count($bans) . '</span></div>';
  393. if (!$bans) {
  394. echo '<div class="orb-card-body orb-text-muted">' . h(t('shield_no_bans')) . '</div>';
  395. } else {
  396. echo '<div class="orb-table-wrap"><table class="orb-table orb-table-responsive"><thead><tr><th>' . h(t('col_address')) . '</th><th>' . h(t('col_reason')) . '</th><th>' . h(t('col_since')) . '</th><th>' . h(t('col_until')) . '</th><th>' . h(t('col_last')) . '</th><th></th></tr></thead><tbody>';
  397. foreach ($bans as $key => $b) {
  398. $reason = t('shield_r_' . (string)($b['reason'] ?? 'manual'));
  399. $note = trim((string)($b['note'] ?? ''));
  400. $until = (int)($b['until'] ?? 0);
  401. echo '<tr><td data-label="' . h(t('col_address')) . '" class="orb-mono">' . h((string)$key) . '</td>'
  402. . '<td data-label="' . h(t('col_reason')) . '"><div class="sd-reason"><span class="orb-pill orb-pill-' . (!empty($b['auto']) ? 'danger' : 'warning') . '">' . h(!empty($b['auto']) ? t('shield_auto') : t('shield_manual')) . '</span><span>' . h($reason) . '</span>' . ($note !== '' ? '<span class="orb-text-xs orb-text-muted">' . h($note) . '</span>' : '') . '</div></td>'
  403. . '<td data-label="' . h(t('col_since')) . '">' . sd_shield_time((int)($b['at'] ?? 0)) . '</td>'
  404. . '<td data-label="' . h(t('col_until')) . '">' . ($until === 0 ? h(t('shield_forever')) : sd_shield_time($until)) . '</td>'
  405. . '<td data-label="' . h(t('col_last')) . '">' . ((int)($b['last'] ?? 0) > 0 ? sd_shield_time((int)$b['last']) : '—') . '</td>'
  406. . '<td>' . sd_shield_form('unban', (string)$key, t('shield_unban'), 'success', 'undo', t('shield_unban_confirm')) . '</td></tr>';
  407. }
  408. echo '</tbody></table></div>';
  409. }
  410. echo '</section>';
  411. ​
  412. $durations = '';
  413. foreach (SD_BAN_DURATIONS as $d) $durations .= '<option value="' . $d . '"' . ($d === 86400 ? ' selected' : '') . '>' . h(t('shield_d_' . $d)) . '</option>';
  414. echo '<div class="orb-grid orb-grid-2 orb-gap-4 orb-mt-4 sd-settings">';
  415. echo '<section class="orb-card"><div class="orb-card-header"><span class="orb-card-title">' . sd_icon('plus', 16) . ' ' . h(t('shield_ban_title')) . '</span></div><div class="orb-card-body"><form method="post" action="' . h(sd_url('shield')) . '">' . sd_csrf_field() . '<input type="hidden" name="action" value="ban">'
  416. . sd_field('address', t('shield_address'), 'text', ['id' => 'f-ban-address', 'required' => true, 'maxlength' => 64, 'class' => 'orb-mono', 'spellcheck' => 'false', 'autocomplete' => 'off', 'placeholder' => '203.0.113.7'], t('shield_address_hint'))
  417. . '<div class="orb-form-group"><label class="orb-label" for="f-duration">' . h(t('shield_duration')) . '</label><select class="orb-select" id="f-duration" name="duration">' . $durations . '</select></div>'
  418. . sd_field('note', t('shield_note'), 'text', ['id' => 'f-ban-note', 'maxlength' => 120, 'autocomplete' => 'off'])
  419. . '<button class="orb-btn orb-btn-primary" type="submit">' . sd_icon('lock') . h(t('shield_ban_btn')) . '</button></form></div></section>';
  420. ​
  421. echo '<section class="orb-card"><div class="orb-card-header"><span class="orb-card-title">' . sd_icon('check', 16) . ' ' . h(t('shield_allow_title')) . '</span></div><div class="orb-card-body">'
  422. . '<p class="orb-text-sm orb-text-muted orb-mb-4">' . h(t('shield_allow_hint')) . '</p>';
  423. if ($allow) {
  424. echo '<ul class="sd-allow">';
  425. foreach ($allow as $key => $a) {
  426. $note = trim((string)($a['note'] ?? ''));
  427. echo '<li><div><span class="orb-mono">' . h((string)$key) . '</span>' . ($note !== '' ? '<div class="orb-text-xs orb-text-muted">' . h($note) . '</div>' : '') . '</div>' . sd_shield_form('disallow', (string)$key, t('shield_remove'), 'danger', 'trash') . '</li>';
  428. }
  429. echo '</ul>';
  430. } else {
  431. echo '<p class="orb-text-sm orb-text-muted orb-mb-4">' . h(t('shield_allow_empty')) . '</p>';
  432. }
  433. echo '<form method="post" action="' . h(sd_url('shield')) . '" class="orb-mt-4">' . sd_csrf_field() . '<input type="hidden" name="action" value="allow">'
  434. . sd_field('address', t('shield_address'), 'text', ['required' => true, 'maxlength' => 64, 'class' => 'orb-mono', 'spellcheck' => 'false', 'autocomplete' => 'off', 'id' => 'f-allow-address', 'placeholder' => $ip])
  435. . sd_field('note', t('shield_note'), 'text', ['id' => 'f-allow-note', 'maxlength' => 120, 'autocomplete' => 'off'])
  436. . '<div class="orb-flex orb-gap-2 orb-flex-wrap"><button class="orb-btn orb-btn-primary" type="submit">' . sd_icon('plus') . h(t('shield_allow_btn')) . '</button>'
  437. . '<button class="orb-btn orb-btn-secondary" type="submit" name="action" value="allow_me" formnovalidate>' . sd_icon('shield') . h(t('shield_allow_me')) . '</button></div></form>'
  438. . '</div></section></div>';
  439. ​
  440. echo '<section class="orb-card orb-mt-4"><div class="orb-card-header"><span class="orb-card-title">' . sd_icon('alert', 16) . ' ' . h(t('shield_watch_title')) . '</span><span class="orb-badge">' . count($watch) . '</span></div>';
  441. if (!$watch) {
  442. echo '<div class="orb-card-body orb-text-muted">' . h(t('shield_watch_empty')) . '</div>';
  443. } else {
  444. echo '<div class="orb-table-wrap"><table class="orb-table orb-table-responsive"><thead><tr><th>' . h(t('col_address')) . '</th><th>' . h(t('col_points')) . '</th><th>' . h(t('col_reason')) . '</th><th>' . h(t('col_last')) . '</th><th></th></tr></thead><tbody>';
  445. foreach ($watch as $key => $w) {
  446. $pct = min(100, (int)round($w['points'] * 100 / SD_BAN_THRESHOLD));
  447. echo '<tr><td data-label="' . h(t('col_address')) . '" class="orb-mono">' . h((string)$key) . '</td>'
  448. . '<td data-label="' . h(t('col_points')) . '"><progress class="sd-meter" max="100" value="' . $pct . '"></progress><span class="orb-text-xs orb-text-muted">' . h(t('shield_points', ['n' => (string)$w['points']])) . '</span></td>'
  449. . '<td data-label="' . h(t('col_reason')) . '">' . h(t('shield_r_' . $w['reason'])) . '</td>'
  450. . '<td data-label="' . h(t('col_last')) . '">' . sd_shield_time($w['t']) . '</td>'
  451. . '<td><form method="post" action="' . h(sd_url('shield')) . '" data-confirm="' . h(t('shield_ban_confirm')) . '">' . sd_csrf_field() . '<input type="hidden" name="action" value="ban"><input type="hidden" name="address" value="' . h((string)$key) . '"><input type="hidden" name="duration" value="2592000"><button type="submit" class="orb-btn orb-btn-outline orb-btn-sm orb-tone-danger">' . sd_icon('lock', 14) . h(t('shield_ban_btn')) . '</button></form></td></tr>';
  452. }
  453. echo '</tbody></table></div>';
  454. }
  455. echo '</section>';
  456. sd_close('app');
  457. }
  458. ​