Initial public release of Oscar Admin

Standalone Open OSCAR Server admin dashboard with login, user/session/room management, BART, buddy list, Gotify addon, audit log, and API console. Includes AI disclosure and open-source project docs.
This commit is contained in:
Oscar Admin Contributors 2026-12-03 18:26:44 -05:00
commit 77342f4629
18 changed files with 4611 additions and 0 deletions

13
.gitignore vendored Normal file
View file

@ -0,0 +1,13 @@
# Runtime / secrets - never commit
/config.php
/audit.log
/gotify-users.php
/gotify-users.json
# OS/editor noise
.DS_Store
Thumbs.db
.idea/
.vscode/
*.swp
*.swo

7
AI_DISCLOSURE.md Normal file
View file

@ -0,0 +1,7 @@
# AI Disclosure
Parts of this project were created and maintained with assistance from AI coding tools.
AI-assisted contributions may include code, refactors, documentation, and configuration. All AI-assisted output is intended to be reviewed, tested, and maintained by human contributors before release.
If you find an issue, security concern, or incorrect behavior, please open an issue or report it through the process described in [SECURITY.md](SECURITY.md).

48
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,48 @@
# Contributing
Thanks for your interest in improving Oscar Admin.
## Before you start
- Keep changes focused and easy to review.
- Do not commit secrets or runtime data (`config.php`, `audit.log`, `gotify-users.php`).
- Preserve the project's security model: private Management API, CSRF on writes, anti-enumeration login behavior, and optional Gotify.
## Development
### Requirements
- PHP 8.1+ (8.2+ recommended)
- PHP cURL extension
- Access to an Open OSCAR Server Management API (private/local)
### Local setup
```bash
cp config.example.php config.php
php -S 127.0.0.1:8081
```
Then open `http://127.0.0.1:8081/login.php`.
### Code style
- PHP: clear, small functions; strict types where already used; escape output with `h()` in templates.
- JS: vanilla JS, defensive DOM checks, no build step.
- CSS: keep admin styles in `admin.css`; `assets/style.css` is the bundled base stylesheet.
## Pull requests
- Describe the problem and the user-facing impact.
- Include manual test steps.
- For security-sensitive changes, note threat/abuse considerations.
- If AI tools were used, make sure the change is reviewed and understood before submitting.
## Reporting bugs
Please include:
- What you expected vs. what happened
- Steps to reproduce
- PHP version and deployment context (nginx/apache/php-fpm/built-in)
- Relevant logs/screenshots (redact secrets, tokens, and private IPs as needed)

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Oscar Admin contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

156
README.md Executable file
View file

@ -0,0 +1,156 @@
# Oscar Admin
A standalone, web-based admin dashboard for [Open OSCAR Server](https://github.com/oscar-server/oscar-server) (AIM/ICQ OSCAR protocol).
Oscar Admin provides a clean UI for day-to-day server administration: users, sessions, chat rooms, messaging, directory, BART assets, buddy lists (feedbag), audit logs, and a raw Management API console.
> **Status:** Active. The admin panel is intended to be deployed alongside Open OSCAR Server, but this repository is standalone and does not require changes to the server source.
## Features
- **Secure login** - OSCAR screen name + math anti-spam challenge + one-time code sent via OSCAR IM.
- **Anti-enumeration** - Allowed and non-allowed screen names get the same login flow/UI.
- **Optional Gotify delivery** - Per-user Gotify URL/token settings; login codes can be sent through Gotify when configured. 100% optional.
- **Overview** - Version, online sessions, users, and room counts.
- **User management** - List/search, create/delete, details, suspend/unsuspend, bot flag, password reset, buddy icon, active sessions.
- **Session management** - List active sessions, inspect details, kick sessions.
- **Chat rooms** - List public/private rooms, create/delete public rooms.
- **Messaging** - Send IM/popup through the system account (feature availability depends on server version).
- **Directory** - Category/keyword CRUD and AIM directory entries.
- **BART / Buddy Art** - Type catalog, browse assets, upload/hash/preview/delete, feedbag BART item set/remove, and a built-in info guide.
- **Buddy List / Feedbag** - User-friendly group/buddy management and linked accounts.
- **Audit log** - Local log of admin actions.
- **API Console** - Raw Management API requests for advanced/debug use.
## Requirements
- **PHP 8.1+** with `curl` and `session` extensions enabled.
- A web server capable of running PHP (nginx + PHP-FPM, Apache, Caddy+php-fpm, etc.).
- An **Open OSCAR Server** instance with the **Management API** enabled.
- A system OSCAR account on that server (used to send login codes/messages).
## Quick Start
1. **Clone the repo**
```bash
git clone https://github.com/<your-org>/oscar-admin.git
cd oscar-admin
```
2. **Create config**
```bash
cp config.example.php config.php
```
3. **Edit `config.php`**
- Add allowed admin screen names to `admin_users`.
- Set `system_screen_name` and `system_password` (an existing OSCAR account).
- Set `mgmt_api_host` / `mgmt_api_port` to your private Management API endpoint.
- Optionally enable Gotify (`gotify_enabled => true`).
4. **Serve with PHP**
For local testing:
```bash
php -S 127.0.0.1:8081
```
Open `http://127.0.0.1:8081/login.php`.
For production, use nginx/Apache + PHP-FPM behind HTTPS.
## Configuration
See [`config.example.php`](config.example.php) for all options. Key settings:
| Setting | Purpose |
|---|---|
| `admin_users` | OSCAR screen names allowed to sign in |
| `system_screen_name` / `system_password` | OSCAR account used to send login codes/messages |
| `mgmt_api_host` / `mgmt_api_port` | Private Open OSCAR Management API endpoint |
| `gotify_enabled` | Enables optional Gotify addon |
| `gotify_url` / `gotify_token` | Optional global Gotify fallback (per-user settings preferred) |
| `shared_style_path` | Base CSS path (defaults to bundled `assets/style.css`) |
## Gotify (Optional)
Gotify support is a 100% optional addon (`lib_gotify.php`). The panel works without it.
1. Set `gotify_enabled => true` in `config.php`.
2. Sign in to the admin dashboard.
3. Open the top-right user menu and save your Gotify URL/token.
4. Use **Test** to verify delivery.
If a Gotify URL/token is saved for a user, login codes are sent through Gotify for that user. Clear settings to disable Gotify delivery for that account.
Per-user Gotify settings are stored in `gotify-users.php` (gitignored). It is a PHP file to reduce accidental direct exposure.
## Deployment / Hardening
### Keep the Management API private
The OSCAR Management API is powerful. Bind it to `127.0.0.1` or a trusted private network and **do not expose it publicly**.
### Protect sensitive files
Do not serve or commit:
- `config.php` - secrets and config
- `audit.log` - admin action log
- `gotify-users.php` - per-user Gotify tokens/URLs
Example nginx rules (adjust paths to your install):
```nginx
location /admin/ {
# ... php handling ...
location ~* /admin/(config\.php|config\.example\.php|lib\.php|lib_gotify\.php|user-menu\.php|gotify-users\.php|gotify-users\.json|audit\.log|README\.md|\.gitignore)$ {
deny all;
return 404;
}
}
```
Also serve the admin panel over HTTPS and consider an IP allowlist/VPN/auth proxy.
## Project Structure
```text
.
├── action.php # Authenticated JSON action endpoint (dashboard -> Management API)
├── admin.css # Admin-specific styles
├── admin.js # Dashboard client behavior
├── assets/
│ └── style.css # Bundled base stylesheet
├── bart-info.php # BART/Buddy Art help page
├── config.example.php # Configuration template
├── index.php # Dashboard UI
├── lib.php # Shared helpers: config/session/auth/API/audit/page shell
├── lib_gotify.php # Optional Gotify addon
├── login.php # Login flow (math challenge + OSCAR/Gotify OTP)
├── logout.php # CSRF-protected logout
└── user-menu.php # User menu / per-user Gotify settings
```
Runtime files (gitignored): `config.php`, `audit.log`, `gotify-users.php`.
## Security
See [SECURITY.md](SECURITY.md) for vulnerability reporting and deployment guidance.
## AI Disclosure
Parts of this project were created and maintained with assistance from AI coding tools. See [AI_DISCLOSURE.md](AI_DISCLOSURE.md).
## Contributing
Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) before opening a PR.
## License
[MIT](LICENSE)

26
SECURITY.md Normal file
View file

@ -0,0 +1,26 @@
# Security Policy
## Supported versions
The latest version on the default branch is the supported version.
## Reporting a vulnerability
Please **do not** open a public issue for a suspected security vulnerability.
Instead, report it privately to the maintainers with:
- A description of the issue and impact
- Steps to reproduce or proof of concept
- Affected files/endpoints/configuration
- Any suggested mitigation
If you need a private contact channel, use the repository owner's preferred security contact method listed on their GitHub/Git profile.
## Security notes for deployers
- Keep `config.php`, `audit.log`, and `gotify-users.php` outside public access and out of git.
- **Never expose the OSCAR Management API publicly.** Bind it to localhost or a trusted private network.
- Serve the admin panel behind HTTPS.
- Restrict access at the web server where appropriate (VPN/IP allowlist/auth proxy).
- Review web server rules to deny direct access to sensitive files.

400
action.php Normal file
View file

@ -0,0 +1,400 @@
<?php
declare(strict_types=1);
/**
* Authenticated JSON action endpoint for the admin dashboard.
*
* All dashboard writes/reads go through this file via fetch() from admin.js.
* - Requires logged-in admin session.
* - CSRF required for non-GET requests.
* - Non-GET actions are written to audit.log (with sensitive fields scrubbed).
* - Most actions proxy to the OSCAR Management API via admin_api().
*/
require_once __DIR__ . '/lib.php';
$gotifyLib = __DIR__ . '/lib_gotify.php';
if (file_exists($gotifyLib)) {
require_once $gotifyLib;
}
admin_require_login();
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$input = array_merge($_GET, $_POST);
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
if (stripos($contentType, 'application/json') !== false) {
$raw = file_get_contents('php://input');
$decoded = json_decode($raw ?: '', true);
if (is_array($decoded)) {
$input = array_merge($input, $decoded);
}
}
$action = (string) ($input['action'] ?? '');
if ($method !== 'GET') {
if (!admin_csrf_valid($input['csrf'] ?? null)) {
admin_json(['ok' => false, 'error' => 'Invalid CSRF token.'], 403);
}
$scrubbed = $input;
foreach (['password', 'csrf', 'body'] as $k) { if (isset($scrubbed[$k])) $scrubbed[$k] = '[redacted]'; }
admin_audit($action ?: 'unknown', $scrubbed);
}
function admin_need(string $value, string $field): string
{
$value = trim($value);
if ($value === '') {
admin_json(['ok' => false, 'error' => "Missing field: {$field}"], 400);
}
return $value;
}
switch ($action) {
case 'overview':
$version = admin_api('GET', '/version');
$sessions = admin_api('GET', '/session');
$users = admin_api('GET', '/user');
$publicRooms = admin_api('GET', '/chat/room/public');
$privateRooms = admin_api('GET', '/chat/room/private');
admin_json([
'ok' => true,
'version' => $version,
'sessions' => $sessions,
'users' => $users,
'public_rooms' => $publicRooms,
'private_rooms' => $privateRooms,
]);
case 'users.list':
admin_json(admin_api('GET', '/user'));
case 'users.create':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$password = admin_need((string) ($input['password'] ?? ''), 'password');
admin_json(admin_api('POST', '/user', ['screen_name' => $screenName, 'password' => $password]));
case 'users.delete':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
admin_json(admin_api('DELETE', '/user', ['screen_name' => $screenName]));
case 'users.get':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
admin_json(admin_api('GET', '/user/' . rawurlencode($screenName) . '/account'));
case 'users.patch':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$body = [];
if (array_key_exists('suspended_status', $input)) {
$status = $input['suspended_status'];
if ($status === '' || $status === null) {
$body['suspended_status'] = null;
} else {
$body['suspended_status'] = (string) $status;
}
}
if (array_key_exists('is_bot', $input)) {
$val = $input['is_bot'];
if ($val === '' || $val === null) {
$body['is_bot'] = null;
} else {
$body['is_bot'] = filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($body['is_bot'] === null && $val !== 'false' && $val !== '0') {
$body['is_bot'] = (bool) $val;
}
}
}
if ($body === []) {
admin_json(['ok' => false, 'error' => 'No fields to update.'], 400);
}
admin_json(admin_api('PATCH', '/user/' . rawurlencode($screenName) . '/account', $body));
case 'users.set_password':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$password = admin_need((string) ($input['password'] ?? ''), 'password');
admin_json(admin_api('PUT', '/user/password', ['screen_name' => $screenName, 'password' => $password]));
case 'sessions.list':
admin_json(admin_api('GET', '/session'));
case 'sessions.get':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
admin_json(admin_api('GET', '/session/' . rawurlencode($screenName)));
case 'sessions.kick':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
admin_json(admin_api('DELETE', '/session/' . rawurlencode($screenName)));
case 'rooms.public.list':
admin_json(admin_api('GET', '/chat/room/public'));
case 'rooms.private.list':
admin_json(admin_api('GET', '/chat/room/private'));
case 'rooms.public.create':
$name = admin_need((string) ($input['name'] ?? ''), 'name');
admin_json(admin_api('POST', '/chat/room/public', ['name' => $name]));
case 'rooms.public.delete':
$names = $input['names'] ?? [];
if (is_string($names)) {
$names = array_filter(array_map('trim', preg_split('/[\r\n,]+/', $names)));
}
if (!is_array($names) || $names === []) {
admin_json(['ok' => false, 'error' => 'Missing field: names'], 400);
}
$names = array_values(array_filter(array_map(fn($n) => trim((string) $n), $names), fn($n) => $n !== ''));
admin_json(admin_api('DELETE', '/chat/room/public', ['names' => $names]));
case 'im.send':
$from = admin_need((string) ($input['from'] ?? ''), 'from');
$to = admin_need((string) ($input['to'] ?? ''), 'to');
$text = admin_need((string) ($input['text'] ?? ''), 'text');
$storeOffline = filter_var($input['store_offline'] ?? false, FILTER_VALIDATE_BOOLEAN);
admin_json(admin_api('POST', '/instant-message', [
'from' => $from,
'to' => $to,
'text' => $text,
'storeOffline' => $storeOffline,
]));
case 'popup.send':
$message = admin_need((string) ($input['message'] ?? ''), 'message');
$body = ['message' => $message];
$broadcast = filter_var($input['broadcast'] ?? false, FILTER_VALIDATE_BOOLEAN);
if ($broadcast) {
$body['broadcast'] = true;
} else {
$recipients = $input['recipients'] ?? [];
if (is_string($recipients)) {
$recipients = array_filter(array_map('trim', preg_split('/[\r\n,]+/', $recipients)));
}
$recipients = is_array($recipients) ? array_values(array_filter(array_map(fn($r) => trim((string) $r), $recipients), fn($r) => $r !== '')) : [];
if ($recipients === []) {
admin_json(['ok' => false, 'error' => 'Provide recipients or enable broadcast.'], 400);
}
$body['recipients'] = $recipients;
}
if (isset($input['url']) && trim((string) $input['url']) !== '') $body['url'] = trim((string) $input['url']);
if (isset($input['width']) && $input['width'] !== '') $body['width'] = max(0, min(65535, (int) $input['width']));
if (isset($input['height']) && $input['height'] !== '') $body['height'] = max(0, min(65535, (int) $input['height']));
admin_json(admin_api('POST', '/popup', $body));
case 'directory.categories.list':
admin_json(admin_api('GET', '/directory/category'));
case 'directory.categories.create':
$name = admin_need((string) ($input['name'] ?? ''), 'name');
admin_json(admin_api('POST', '/directory/category', ['name' => $name]));
case 'directory.categories.delete':
$id = (int) ($input['id'] ?? 0);
if ($id <= 0) admin_json(['ok' => false, 'error' => 'Missing field: id'], 400);
admin_json(admin_api('DELETE', '/directory/category/' . $id));
case 'directory.keywords.list':
$id = (int) ($input['category_id'] ?? $input['id'] ?? 0);
if ($id <= 0) admin_json(['ok' => false, 'error' => 'Missing field: category_id'], 400);
admin_json(admin_api('GET', '/directory/category/' . $id . '/keyword'));
case 'directory.keywords.create':
$categoryId = (int) ($input['category_id'] ?? 0);
$name = admin_need((string) ($input['name'] ?? ''), 'name');
if ($categoryId <= 0) admin_json(['ok' => false, 'error' => 'Missing field: category_id'], 400);
admin_json(admin_api('POST', '/directory/keyword', ['category_id' => $categoryId, 'name' => $name]));
case 'directory.keywords.delete':
$id = (int) ($input['id'] ?? 0);
if ($id <= 0) admin_json(['ok' => false, 'error' => 'Missing field: id'], 400);
admin_json(admin_api('DELETE', '/directory/keyword/' . $id));
case 'directory.aim.list':
admin_json(admin_api('GET', '/directory/aim'));
case 'users.icon.get':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$r = admin_api('GET', '/user/' . rawurlencode($screenName) . '/icon');
if ($r['ok']) {
admin_json(['ok' => true, 'status' => $r['status'], 'data' => ['base64' => base64_encode($r['raw']), 'content_type' => 'image/*']]);
}
admin_json($r);
case 'bart.list':
$type = $input['type'] ?? null;
if ($type === null || $type === '') admin_json(['ok' => false, 'error' => 'Missing field: type'], 400);
admin_json(admin_api('GET', '/bart', null, ['type' => (int) $type]));
case 'bart.get':
$hash = admin_need((string) ($input['hash'] ?? ''), 'hash');
$r = admin_api('GET', '/bart/' . rawurlencode($hash));
if ($r['ok']) {
admin_json(['ok' => true, 'status' => $r['status'], 'data' => ['base64' => base64_encode($r['raw'])]]);
}
admin_json($r);
case 'bart.upload':
// BART upload needs raw binary body; admin_api() JSON-encodes bodies, so use curl directly.
$hash = admin_need((string) ($input['hash'] ?? ''), 'hash');
$type = $input['type'] ?? null;
if ($type === null || $type === '') admin_json(['ok' => false, 'error' => 'Missing field: type'], 400);
$b64 = admin_need((string) ($input['data_base64'] ?? ''), 'data_base64');
$bin = base64_decode($b64, true);
if ($bin === false) admin_json(['ok' => false, 'error' => 'Invalid base64 data.'], 400);
$url = admin_mgmt_base() . '/bart/' . rawurlencode($hash) . '?type=' . urlencode((string) (int) $type);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Content-Type: application/octet-stream', 'Accept: application/json'],
CURLOPT_POSTFIELDS => $bin,
CURLOPT_TIMEOUT => 20,
CURLOPT_CONNECTTIMEOUT => 5,
]);
$raw = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$err = curl_error($ch);
curl_close($ch);
if ($raw === false) admin_json(['ok' => false, 'status' => 0, 'error' => $err ?: 'Request failed']);
$decoded = json_decode($raw, true);
$ok = $status >= 200 && $status < 300;
admin_json(['ok' => $ok, 'status' => $status, 'error' => $ok ? null : ($decoded['message'] ?? $raw), 'data' => $decoded, 'raw' => $raw]);
case 'bart.delete':
$hash = admin_need((string) ($input['hash'] ?? ''), 'hash');
admin_json(admin_api('DELETE', '/bart/' . rawurlencode($hash)));
case 'feedbag.bart.set':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$hash = admin_need((string) ($input['hash'] ?? ''), 'hash');
$type = $input['type'] ?? null;
if ($type === null || $type === '') admin_json(['ok' => false, 'error' => 'Missing field: type'], 400);
admin_json(admin_api('PUT', '/feedbag/' . rawurlencode($screenName) . '/bart', ['hash' => $hash, 'type' => (int) $type]));
case 'feedbag.bart.delete':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$type = $input['type'] ?? null;
if ($type === null || $type === '') admin_json(['ok' => false, 'error' => 'Missing field: type'], 400);
admin_json(admin_api('DELETE', '/feedbag/' . rawurlencode($screenName) . '/bart', null, ['type' => (int) $type]));
case 'feedbag.groups.list':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
admin_json(admin_api('GET', '/feedbag/' . rawurlencode($screenName) . '/group'));
case 'feedbag.groups.create':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$groupName = admin_need((string) ($input['group_name'] ?? ''), 'group_name');
admin_json(admin_api('PUT', '/feedbag/' . rawurlencode($screenName) . '/group/' . rawurlencode($groupName)));
case 'feedbag.buddy.add':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$groupId = (int) ($input['group_id'] ?? 0);
$buddy = admin_need((string) ($input['buddy_screen_name'] ?? ''), 'buddy_screen_name');
if ($groupId <= 0) admin_json(['ok' => false, 'error' => 'Missing field: group_id'], 400);
admin_json(admin_api('PUT', '/feedbag/' . rawurlencode($screenName) . '/group/' . $groupId . '/buddy/' . rawurlencode($buddy)));
case 'feedbag.buddy.delete':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$groupId = (int) ($input['group_id'] ?? 0);
$buddy = admin_need((string) ($input['buddy_screen_name'] ?? ''), 'buddy_screen_name');
if ($groupId <= 0) admin_json(['ok' => false, 'error' => 'Missing field: group_id'], 400);
admin_json(admin_api('DELETE', '/feedbag/' . rawurlencode($screenName) . '/group/' . $groupId . '/buddy/' . rawurlencode($buddy)));
case 'linked.list':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
admin_json(admin_api('GET', '/user/' . rawurlencode($screenName) . '/linked-account'));
case 'linked.add':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$linked = admin_need((string) ($input['linked_screen_name'] ?? ''), 'linked_screen_name');
admin_json(admin_api('POST', '/user/' . rawurlencode($screenName) . '/linked-account', ['linked_screen_name' => $linked]));
case 'linked.delete':
$screenName = admin_need((string) ($input['screen_name'] ?? ''), 'screen_name');
$linked = admin_need((string) ($input['linked_screen_name'] ?? ''), 'linked_screen_name');
admin_json(admin_api('DELETE', '/user/' . rawurlencode($screenName) . '/linked-account/' . rawurlencode($linked)));
case 'audit.list':
$limit = max(1, min(1000, (int) ($input['limit'] ?? 200)));
admin_json(['ok' => true, 'data' => admin_audit_read($limit)]);
case 'gotify.self.get':
if (!function_exists('admin_gotify_feature_enabled') || !admin_gotify_feature_enabled()) {
admin_json(['ok' => false, 'error' => 'Gotify is not enabled.'], 400);
}
$user = admin_current_user();
$sn = (string) ($user['screen_name'] ?? '');
$cfg = admin_gotify_user_get($sn);
admin_json(['ok' => true, 'data' => [
'enabled' => true,
'configured' => $cfg !== null,
'url' => $cfg['url'] ?? '',
'token_set' => $cfg !== null && ($cfg['token'] ?? '') !== '',
'priority' => $cfg['priority'] ?? (int) admin_cfg('gotify_priority', 5),
'updated_at' => $cfg['updated_at'] ?? '',
]]);
case 'gotify.self.save':
if (!function_exists('admin_gotify_feature_enabled') || !admin_gotify_feature_enabled()) {
admin_json(['ok' => false, 'error' => 'Gotify is not enabled.'], 400);
}
$user = admin_current_user();
$sn = (string) ($user['screen_name'] ?? '');
$url = trim((string) ($input['url'] ?? ''));
$token = trim((string) ($input['token'] ?? ''));
$priority = isset($input['priority']) ? (int) $input['priority'] : null;
if ($url !== '' && $token === '') {
$existing = admin_gotify_user_get($sn);
if ($existing && !empty($existing['token'])) {
$token = (string) $existing['token'];
}
}
$result = admin_gotify_user_save($sn, $url, $token, $priority);
if (!($result['ok'] ?? false)) {
admin_json(['ok' => false, 'error' => $result['error'] ?? 'Failed to save.'], 400);
}
$cfg = admin_gotify_user_get($sn);
admin_json(['ok' => true, 'data' => [
'configured' => $cfg !== null,
'url' => $cfg['url'] ?? '',
'token_set' => $cfg !== null && ($cfg['token'] ?? '') !== '',
'priority' => $cfg['priority'] ?? (int) admin_cfg('gotify_priority', 5),
'updated_at' => $cfg['updated_at'] ?? '',
'cleared' => $result['cleared'] ?? false,
]]);
case 'gotify.self.test':
if (!function_exists('admin_gotify_feature_enabled') || !admin_gotify_feature_enabled()) {
admin_json(['ok' => false, 'error' => 'Gotify is not enabled.'], 400);
}
$user = admin_current_user();
$sn = (string) ($user['screen_name'] ?? '');
$cfg = function_exists('admin_gotify_user_get') ? admin_gotify_user_get($sn) : null;
if (!$cfg) {
admin_json(['ok' => false, 'error' => 'No Gotify configuration saved for your account. Save URL and token first.'], 400);
}
$send = admin_gotify_send_for_user($sn, 'Oscar Admin test', "This is a test notification for {$sn} from Oscar Admin.", $cfg['priority'] ?? null);
if (!($send['ok'] ?? false)) {
admin_json(['ok' => false, 'error' => $send['error'] ?? 'Gotify test failed.'], 400);
}
admin_json(['ok' => true, 'data' => ['sent' => true]]);
case 'api.raw':
$reqMethod = strtoupper(admin_need((string) ($input['method'] ?? 'GET'), 'method'));
$path = admin_need((string) ($input['path'] ?? ''), 'path');
if (!str_starts_with($path, '/')) {
$path = '/' . $path;
}
if (!in_array($reqMethod, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], true)) {
admin_json(['ok' => false, 'error' => 'Unsupported method.'], 400);
}
$body = null;
if (isset($input['body']) && trim((string) $input['body']) !== '') {
$decoded = json_decode((string) $input['body'], true);
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
admin_json(['ok' => false, 'error' => 'Body must be valid JSON.'], 400);
}
$body = $decoded;
}
admin_json(admin_api($reqMethod, $path, is_array($body) ? $body : null));
default:
admin_json(['ok' => false, 'error' => 'Unknown action.'], 400);
}

421
admin.css Normal file
View file

@ -0,0 +1,421 @@
/*
* Oscar Admin - standalone styles.
*
* Loaded alongside the bundled shared base stylesheet (assets/style.css,
* configurable via shared_style_path) by admin_page(). Keep this file
* self-contained for admin-specific layout/components.
*
* Sections: tokens/base, layout/nav, components, forms/buttons, tables,
* detail/BART/feedbag helpers, auth, toasts, animations, responsive.
*/
:root {
--bg: #0b1020;
--bg-soft: #121a2f;
--panel: rgba(18, 26, 47, 0.72);
--panel-solid: #141d35;
--panel-2: #1b2742;
--text: #e8eefc;
--muted: #93a4c4;
--accent: #6ea8ff;
--accent-2: #8b7bff;
--ok: #4fd18b;
--warn: #ffcc66;
--danger: #ff6b6b;
--line: rgba(148, 163, 184, 0.16);
--line-strong: rgba(148, 163, 184, 0.28);
--shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
--radius: 16px;
--radius-sm: 10px;
--font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body.admin-body {
font-family: var(--font);
color: var(--text);
background:
radial-gradient(1200px 600px at 10% -10%, rgba(110,168,255,.18), transparent 60%),
radial-gradient(900px 500px at 100% 0%, rgba(139,123,255,.14), transparent 55%),
linear-gradient(180deg, #090e1a 0%, #0b1020 100%);
overflow-x: hidden;
}
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .92em; background: rgba(255,255,255,.06); padding: .15em .4em; border-radius: 4px; }
.bg-orb { position: fixed; border-radius: 50%; filter: blur(60px); pointer-events: none; z-index: 0; opacity: .55; }
.orb-a { width: 420px; height: 420px; top: -120px; left: -80px; background: rgba(110,168,255,.22); animation: float 14s ease-in-out infinite, hueDrift 20s ease-in-out infinite; }
.orb-b { width: 360px; height: 360px; top: 20%; right: -100px; background: rgba(139,123,255,.18); animation: float 18s ease-in-out infinite reverse, hueDrift 24s ease-in-out infinite reverse; }
.bg-grid {
position: fixed; inset: 0; pointer-events: none; z-index: 0;
background-image: linear-gradient(rgba(255,255,255,.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.02) 1px, transparent 1px);
background-size: 32px 32px;
mask-image: radial-gradient(ellipse 70% 60% at 50% 20%, black, transparent);
animation: gridPan 30s linear infinite;
}
.bg-grid::after {
content: ''; position: absolute; inset: 0;
background: linear-gradient(120deg, transparent 30%, rgba(110,168,255,.04) 50%, transparent 70%);
background-size: 200% 200%;
animation: shimmerBg 12s ease-in-out infinite;
}
.admin-topbar {
position: sticky; top: 0; z-index: 50;
display: flex; align-items: center; justify-content: space-between; gap: 1rem;
padding: .65rem 1.25rem;
background: rgba(11, 16, 32, 0.72);
backdrop-filter: blur(16px);
border-bottom: 1px solid var(--line);
}
.admin-brand { display: flex; align-items: center; gap: .85rem; }
.brand-mark {
width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px;
background: linear-gradient(135deg, rgba(110,168,255,.25), rgba(139,123,255,.2));
border: 1px solid rgba(110,168,255,.3);
color: var(--accent);
box-shadow: 0 0 0 4px rgba(110,168,255,.06);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-title { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-sub { font-size: .78rem; color: var(--muted); }
.admin-nav { display: flex; align-items: center; gap: .75rem; }
.admin-nav a { color: var(--muted); text-decoration: none; padding: .5rem .75rem; border-radius: 8px; font-size: .9rem; }
.admin-nav a:hover, .admin-nav a.active { color: var(--text); background: rgba(255,255,255,.05); }
.nav-user { color: var(--muted); font-size: .85rem; padding: .35rem .65rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.03); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { position: relative; }
.user-menu-trigger { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; font: inherit; color: var(--muted); font-size: .85rem; padding: .35rem .65rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.03); max-width: 220px; }
.user-menu-trigger:hover { color: var(--text); border-color: var(--line-strong); background: rgba(255,255,255,.05); }
.user-menu-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-dropdown { position: absolute; top: calc(100% + .5rem); right: 0; width: min(340px, calc(100vw - 2rem)); background: linear-gradient(180deg, rgba(24,35,61,.98), rgba(16,24,43,.98)); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.45); padding: .75rem; z-index: 200; }
.user-menu-dropdown[hidden] { display: none !important; }
.user-menu-head { padding: .25rem .25rem .6rem; border-bottom: 1px solid var(--line); margin-bottom: .6rem; }
.user-menu-name { font-weight: 650; font-size: .95rem; }
.user-menu-section { padding: .25rem 0; }
.user-menu-section + .user-menu-section { border-top: 1px solid var(--line); margin-top: .6rem; padding-top: .75rem; }
.user-menu-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: .5rem; display: flex; align-items: center; gap: .25rem; }
.user-menu-actions .btn-block { width: 100%; }
.inline-form { margin: 0; }
.admin-main { position: relative; z-index: 1; width: min(1400px, calc(100% - 2rem)); margin: 0 auto; padding: 1rem 0 2rem; }
/* Buttons */
.btn {
appearance: none; border: 1px solid var(--line-strong); background: rgba(255,255,255,.04); color: var(--text);
padding: .65rem 1rem; border-radius: 10px; font: inherit; font-size: .9rem; font-weight: 550; cursor: pointer;
display: inline-flex; align-items: center; justify-content: center; gap: .5rem; text-decoration: none;
transition: transform .15s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.btn:hover { background: rgba(255,255,255,.08); border-color: rgba(148,163,184,.4); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
position: relative; overflow: hidden;
background: linear-gradient(135deg, rgba(110,168,255,.95), rgba(139,123,255,.95));
border-color: transparent; color: #08101f; font-weight: 650;
box-shadow: 0 8px 24px rgba(110,168,255,.25);
}
.btn-primary::after {
content: ''; position: absolute; top: 0; left: 0; width: 40%; height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
transform: translateX(-120%) skewX(-15deg);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 10px 30px rgba(110,168,255,.32); }
.btn-primary:hover::after { animation: sheen .7s ease; }
.btn-danger { background: rgba(255,107,107,.12); border-color: rgba(255,107,107,.35); color: #ffb3b3; }
.btn-danger:hover { background: rgba(255,107,107,.18); }
.btn-ghost { background: transparent; }
.btn-small { padding: .4rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn-block { width: 100%; }
/* Hero */
.hero {
display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin: .5rem 0 1rem;
}
.eyebrow { font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: .2rem; }
.hero h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.1; letter-spacing: -.03em; }
.hero p { margin: .35rem 0 0; max-width: 60ch; font-size: .92rem; }
.hero-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.status-chip {
display: inline-flex; align-items: center; gap: .5rem; padding: .5rem .8rem; border-radius: 999px;
background: rgba(255,255,255,.04); border: 1px solid var(--line); font-size: .82rem; color: var(--muted);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 4px rgba(255,204,102,.12); }
.status-chip.ok .status-dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(79,209,139,.12); }
.status-chip.bad .status-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,107,107,.12); }
/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat-card {
display: flex; gap: .75rem; align-items: flex-start; padding: .85rem 1rem;
background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
backdrop-filter: blur(10px); box-shadow: var(--shadow);
transition: transform .2s ease, border-color .2s ease;
}
.stat-card:hover { transform: translateY(-3px); border-color: rgba(110,168,255,.25); box-shadow: 0 20px 60px rgba(0,0,0,.35), 0 0 24px rgba(110,168,255,.08); }
.stat-icon {
width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
background: linear-gradient(135deg, rgba(110,168,255,.16), rgba(139,123,255,.12)); color: var(--accent);
flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.2; margin: .1rem 0; letter-spacing: -.02em; }
.stat-sub { font-size: .75rem; }
/* Panels / tabs */
.panel {
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
backdrop-filter: blur(10px); box-shadow: var(--shadow); overflow: hidden;
}
.tab-bar { display: flex; gap: .2rem; padding: .5rem .75rem; border-bottom: 1px solid var(--line); overflow-x: auto; background: rgba(0,0,0,.08); }
.tab {
appearance: none; background: transparent; border: 0; color: var(--muted); font: inherit; font-size: .85rem; font-weight: 550;
padding: .5rem .75rem; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: all .2s ease; position: relative;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,.04); }
.tab.active { color: var(--text); background: rgba(110,168,255,.12); }
.tab.active::after {
content: ''; position: absolute; left: 1rem; right: 1rem; bottom: .35rem; height: 2px; border-radius: 2px;
background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.tab-panels { padding: .85rem 1rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .25s ease; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 1.05rem; letter-spacing: -.01em; }
.panel-head p { margin: .15rem 0 0; font-size: .84rem; }
.subhead { font-size: .88rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }
/* Cards/forms */
.card.subcard {
background: rgba(255,255,255,.02); border: 1px solid var(--line); border-radius: 10px; padding: .75rem;
}
.subcard h3 { margin: 0 0 .6rem; font-size: .92rem; }
.split-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: .75rem; }
.room-columns { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.stack-form { display: flex; flex-direction: column; gap: .65rem; }
.stack-form.compact { gap: .5rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field span, .field label { font-size: .82rem; color: var(--muted); font-weight: 550; }
.field input, .field textarea, .field select, .input {
width: 100%; padding: .5rem .65rem; border-radius: 8px; border: 1px solid var(--line-strong);
background: rgba(0,0,0,.18); color: var(--text); font: inherit; font-size: .88rem;
transition: border-color .2s ease, box-shadow .2s ease;
}
.field input:focus, .field textarea:focus, .field select:focus, .input:focus {
outline: none; border-color: rgba(110,168,255,.55); box-shadow: 0 0 0 4px rgba(110,168,255,.12);
}
.field textarea { resize: vertical; min-height: 70px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.check { display: flex; gap: .55rem; align-items: flex-start; font-size: .88rem; color: var(--muted); }
.check input { margin-top: .2rem; accent-color: var(--accent); }
.table-tools { margin-bottom: .5rem; }
.table-tools .input { max-width: 320px; }
.users-toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.users-toolbar .input { max-width: 240px; }
.bulk-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-left: auto; }
.bulk-actions .input { width: auto; max-width: 160px; }
.auto-refresh-toggle { font-size: .82rem; color: var(--muted); margin: 0; white-space: nowrap; }
.inline-controls { display: flex; gap: .5rem; align-items: center; }
.inline-controls .input { width: 140px; }
/* Code block */
.code-block {
margin: 0; padding: 1rem; border-radius: 10px; border: 1px solid var(--line);
background: rgba(0,0,0,.25); color: #cfe0ff; font-family: var(--mono); font-size: .82rem;
line-height: 1.6; overflow: auto; max-height: 420px; white-space: pre-wrap; word-break: break-word;
}
/* Tooltips */
.tip {
display: inline-flex; align-items: center; justify-content: center;
width: 16px; height: 16px; margin-left: .35rem; border-radius: 50%;
background: rgba(110,168,255,.14); border: 1px solid rgba(110,168,255,.28);
color: var(--accent); font-size: .65rem; font-weight: 700; line-height: 1;
cursor: help; vertical-align: middle; position: relative; flex-shrink: 0;
}
.tip:hover, .tip:focus { background: rgba(110,168,255,.22); outline: none; }
.tip::after {
content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px);
transform: translateX(calc(-50% + var(--tip-shift, 0px))) translateY(4px); width: max-content; max-width: 260px;
padding: .5rem .65rem; border-radius: 8px; background: #18233d; color: var(--text);
border: 1px solid var(--line-strong); box-shadow: 0 10px 30px rgba(0,0,0,.35);
font-size: .74rem; font-weight: 500; line-height: 1.45; text-transform: none; letter-spacing: normal;
white-space: normal; opacity: 0; pointer-events: none; transition: opacity .15s ease, transform .15s ease; z-index: 500;
}
.tip::before {
content: ''; position: absolute; left: 50%; bottom: calc(100% + 3px);
transform: translateX(calc(-50% + var(--tip-shift, 0px))) translateY(4px); border: 5px solid transparent; border-top-color: #18233d;
opacity: 0; pointer-events: none; transition: opacity .15s ease, transform .15s ease; z-index: 501;
}
.tip:hover::after, .tip:focus::after, .tip:hover::before, .tip:focus::before { opacity: 1; transform: translateX(calc(-50% + var(--tip-shift, 0px))) translateY(0); }
.label-row { display: inline-flex; align-items: center; gap: .25rem; }
/* BART layout */
.bart-layout { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: .75rem; align-items: start; }
.bart-rail { position: sticky; top: .75rem; max-height: calc(100vh - 1.5rem); overflow: hidden; display: flex; flex-direction: column; }
.bart-rail .bart-type-catalog { flex: 1; min-height: 0; max-height: none; overflow: auto; }
.bart-main { display: grid; gap: .75rem; min-width: 0; }
@media (max-width: 1100px) {
.bart-layout { grid-template-columns: 1fr; }
.bart-rail { position: static; max-height: none; }
}
/* BART catalog */
.bart-type-catalog { display: grid; gap: .75rem; max-height: 60vh; overflow: auto; padding-right: .15rem; }
.bart-group-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin-bottom: .35rem; }
.bart-group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .45rem; }
.bart-type-card { text-align: left; padding: .6rem .7rem; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.02); color: var(--text); cursor: pointer; transition: all .18s ease; }
.bart-type-card:hover { border-color: rgba(110,168,255,.3); background: rgba(110,168,255,.05); transform: translateY(-1px); }
.bart-type-card.selected { border-color: rgba(110,168,255,.55); background: rgba(110,168,255,.1); box-shadow: inset 0 0 0 1px rgba(110,168,255,.2); }
.bart-type-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .2rem; }
.bart-type-icon { font-size: 1rem; line-height: 1; }
.bart-type-id { font-size: .68rem; color: var(--accent); font-weight: 700; font-family: var(--mono); }
.bart-type-name { font-size: .83rem; font-weight: 650; margin: .05rem 0; }
.bart-type-desc { font-size: .71rem; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bart-type-info { padding: .55rem .7rem; border-radius: 9px; background: rgba(110,168,255,.06); border: 1px solid rgba(110,168,255,.12); font-size: .8rem; }
.bart-type-info:empty { display: none; }
.bart-selected-type { display: flex; gap: .6rem; align-items: flex-start; }
.bart-selected-icon { font-size: 1.3rem; line-height: 1; margin-top: .05rem; }
.bart-browse-status { font-size: .78rem; color: var(--muted); min-height: 1.2em; margin-top: .35rem; }
.bart-browse-status:empty { display: none; }
.bart-upload-purpose { margin-bottom: .65rem; }
.bart-purpose { padding: .7rem .85rem; border-radius: 10px; background: linear-gradient(135deg, rgba(110,168,255,.12), rgba(92,214,166,.06)); border: 1px solid rgba(110,168,255,.2); }
.bart-purpose-label { font-size: .67rem; text-transform: uppercase; letter-spacing: .07em; color: var(--accent); font-weight: 700; margin-bottom: .15rem; }
.bart-purpose-name { font-size: .95rem; font-weight: 650; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.bart-purpose-icon { font-size: 1.1rem; }
/* Detail view */
.detail-view {
padding: 0; border-radius: 0; border: 0;
background: transparent; color: var(--text); font-size: .84rem; line-height: 1.5;
overflow: visible; max-height: none;
}
.kv-grid { display: grid; gap: .35rem; }
.kv-row { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: .5rem; padding: .35rem .5rem; border-radius: 8px; background: rgba(255,255,255,.02); border: 1px solid rgba(148,163,184,.08); }
.kv-k { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 650; align-self: start; padding-top: .1rem; word-break: break-word; }
.kv-v { min-width: 0; word-break: break-word; }
.kv-v .mono { font-size: .82rem; }
.detail-section { margin-top: .6rem; }
.detail-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: .35rem; }
.detail-list { display: grid; gap: .4rem; }
.detail-card { padding: .55rem .65rem; border-radius: 8px; border: 1px solid rgba(148,163,184,.1); background: rgba(255,255,255,.02); }
.detail-empty { color: var(--muted); font-style: italic; }
.bool-yes { color: #8fe0b5; }
.bool-no { color: var(--muted); }
.audit-details .kv-grid { gap: .2rem; }
.audit-details .kv-row { grid-template-columns: 120px 1fr; padding: .2rem .35rem; font-size: .78rem; }
.audit-details .detail-list { gap: .25rem; }
.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: .75rem; }
.detail-stat { padding: .7rem .8rem; border-radius: 10px; background: rgba(255,255,255,.03); border: 1px solid var(--line); }
.detail-stat-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.detail-stat-value { font-size: 1.1rem; font-weight: 700; margin-top: .15rem; letter-spacing: -.01em; }
.detail-stat-sub { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.detail-info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .5rem; margin-bottom: .75rem; }
.detail-info-item { padding: .55rem .7rem; border-radius: 9px; background: rgba(255,255,255,.02); border: 1px solid rgba(148,163,184,.08); }
.detail-info-label { font-size: .67rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: .15rem; }
.detail-info-value { font-size: .88rem; word-break: break-word; }
.instance-list { display: grid; gap: .6rem; }
.instance-card { padding: .75rem; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.02); }
.instance-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.instance-title { font-weight: 650; font-size: .88rem; }
.tag-row { display: flex; gap: .35rem; flex-wrap: wrap; }
/* Tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,.12); }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th, .data-table td { padding: .45rem .65rem; text-align: left; border-bottom: 1px solid rgba(148,163,184,.1); vertical-align: middle; }
.data-table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; background: rgba(255,255,255,.02); position: sticky; top: 0; }
.data-table tbody tr { transition: background .15s ease; }
.data-table tbody tr:hover { background: rgba(110,168,255,.04); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.empty-cell { text-align: center; color: var(--muted); padding: 2rem 1rem !important; }
.actions-cell { white-space: nowrap; display: flex; gap: .4rem; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 650; border: 1px solid transparent; }
.pill-ok { color: #8fe0b5; background: rgba(79,209,139,.12); border-color: rgba(79,209,139,.2); }
.pill-warn { color: #ffe0a3; background: rgba(255,204,102,.12); border-color: rgba(255,204,102,.2); }
.pill-bad { color: #ffb3b3; background: rgba(255,107,107,.12); border-color: rgba(255,107,107,.2); }
.pill-muted { color: var(--muted); background: rgba(148,163,184,.1); border-color: rgba(148,163,184,.15); }
.mono { font-family: var(--mono); font-size: .85em; }
/* Auth */
.auth-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: stretch; min-height: calc(100vh - 180px); padding: 1.5rem 0; }
.auth-card, .side-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 2rem; backdrop-filter: blur(12px); box-shadow: var(--shadow); }
.auth-card { animation: borderGlow 6s ease-in-out infinite; }
.auth-head h1 { margin: 0; font-size: 2rem; letter-spacing: -.02em; }
.auth-head p { margin: .5rem 0 1.5rem; }
.auth-foot { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: .85rem; display: flex; align-items: center; gap: .5rem; }
.auth-foot .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.pulse-dot { animation: pulseRing 2s ease-out infinite; }
.pending-box { padding: 1rem; border-radius: 12px; background: rgba(110,168,255,.08); border: 1px solid rgba(110,168,255,.18); margin-bottom: 1rem; }
.pending-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pending-name { font-size: 1.25rem; font-weight: 700; margin: .2rem 0; }
.pending-expiry { font-size: .82rem; }
.reset-row { margin-top: .75rem; }
.side-card { display: flex; flex-direction: column; justify-content: center; background: linear-gradient(160deg, rgba(110,168,255,.08), rgba(20,29,53,.6)); }
.side-card h2 { margin: 0 0 1.25rem; font-size: 1.3rem; }
.step-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1.25rem; }
.step-list li { display: flex; gap: 1rem; align-items: flex-start; }
.step-num { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: rgba(110,168,255,.15); color: var(--accent); font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.step-list strong { display: block; margin-bottom: .15rem; }
.step-list p { margin: 0; font-size: .9rem; }
/* Flashes/toasts */
.flash { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem; border: 1px solid transparent; }
.flash-error { background: rgba(255,107,107,.1); border-color: rgba(255,107,107,.25); color: #ffbdbd; }
.flash-success { background: rgba(79,209,139,.1); border-color: rgba(79,209,139,.25); color: #b7efd0; }
.flash-info { background: rgba(110,168,255,.1); border-color: rgba(110,168,255,.25); color: #c7dcff; }
#toast-container { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .6rem; z-index: 200; width: min(360px, calc(100vw - 2rem)); }
.toast {
padding: .85rem 1rem; border-radius: 12px; background: #18233d; border: 1px solid var(--line-strong); color: var(--text);
box-shadow: 0 10px 30px rgba(0,0,0,.35); font-size: .88rem; animation: toastIn .3s ease;
}
.toast.success { border-color: rgba(79,209,139,.35); }
.toast.error { border-color: rgba(255,107,107,.35); }
.toast.out { animation: toastOut .25s ease forwards; }
/* Animations */
.reveal { animation: riseIn .5s ease both; }
.delay-1 { animation-delay: .08s; }
.delay-2 { animation-delay: .16s; }
@keyframes riseIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-16px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(10px); } }
@keyframes hueDrift { 0%,100% { filter: blur(60px) hue-rotate(0deg); } 50% { filter: blur(60px) hue-rotate(25deg); } }
@keyframes gridPan { from { background-position: 0 0, 0 0; } to { background-position: 32px 32px, 32px 32px; } }
@keyframes shimmerBg { 0%,100% { background-position: 0% 50%; opacity: .4; } 50% { background-position: 100% 50%; opacity: 1; } }
@keyframes pulseRing { 0% { box-shadow: 0 0 0 0 rgba(110,168,255,.45); } 70% { box-shadow: 0 0 0 8px rgba(110,168,255,0); } 100% { box-shadow: 0 0 0 0 rgba(110,168,255,0); } }
@keyframes borderGlow { 0%,100% { border-color: rgba(110,168,255,.18); box-shadow: 0 20px 60px rgba(0,0,0,.35), 0 0 0 1px rgba(110,168,255,.05); } 50% { border-color: rgba(139,123,255,.3); box-shadow: 0 20px 60px rgba(0,0,0,.35), 0 0 30px rgba(110,168,255,.08); } }
@keyframes sheen { from { transform: translateX(-120%) skewX(-15deg); } to { transform: translateX(220%) skewX(-15deg); } }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
/* Responsive */
@media (max-width: 1100px) {
.stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
.auth-wrap, .split-grid, .room-columns { grid-template-columns: 1fr; }
.hero { flex-direction: column; align-items: stretch; }
}
@media (max-width: 700px) {
.admin-topbar { flex-direction: column; align-items: stretch; }
.admin-nav { justify-content: space-between; flex-wrap: wrap; }
.stats-grid { grid-template-columns: 1fr; }
.admin-main { width: min(100% - 1rem, 1400px); }
.tab-panels { padding: 1rem; }
.data-table th, .data-table td { padding: .6rem; }
}

1024
admin.js Normal file

File diff suppressed because it is too large Load diff

689
assets/style.css Normal file
View file

@ -0,0 +1,689 @@
/* Bundled base stylesheet for Oscar Admin. Self-contained: no external fonts, scripts, or CDNs. */
:root {
--bg: #161821;
--bg-soft: #1d2030;
--panel: #20243a;
--panel-2: #262b44;
--text: #e8eaf3;
--muted: #98a0b8;
--accent: #5aa9ff;
--accent-2: #8f7dff;
--ok: #6fd69b;
--warn: #f2c66d;
--danger: #f06f6f;
--line: #353b57;
--shadow: 0 10px 30px rgba(0, 0, 0, .25);
--radius: 12px;
--radius-sm: 8px;
--max: 1040px;
--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color-scheme: dark;
}
html[data-theme="light"] {
--bg: #f4f6fb;
--bg-soft: #ffffff;
--panel: #ffffff;
--panel-2: #eef2fb;
--text: #1b1f33;
--muted: #5d6680;
--accent: #1f6fd1;
--accent-2: #6a54e8;
--ok: #1e8f58;
--warn: #9a6a00;
--danger: #c23b3b;
--line: #d6dbea;
--shadow: 0 10px 30px rgba(20, 30, 60, .08);
color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
margin: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
background:
radial-gradient(1200px 500px at 85% -10%, rgba(90, 169, 255, .10), transparent 60%),
radial-gradient(900px 400px at -10% 10%, rgba(143, 125, 255, .09), transparent 60%),
var(--bg);
background-attachment: fixed;
color: var(--text);
font: 16px/1.6 var(--font);
-webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
code, pre {
font-family: var(--mono);
background: var(--panel-2);
border: 1px solid var(--line);
border-radius: 6px;
}
code { padding: 1px 6px; font-size: .9em; overflow-wrap: anywhere; }
.skip-link {
position: absolute;
left: 12px;
top: -60px;
padding: 8px 12px;
background: var(--accent);
color: #fff;
border-radius: var(--radius-sm);
z-index: 200;
}
.skip-link:focus { top: 12px; }
/* ---------- Header and navigation ---------- */
.site-header {
position: sticky;
top: 0;
z-index: 100;
display: flex;
align-items: center;
gap: 14px;
width: 100%;
padding: 14px max(16px, calc((100% - var(--max)) / 2));
background: color-mix(in srgb, var(--bg) 85%, transparent);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--line);
}
.brand {
display: inline-flex;
align-items: center;
gap: 10px;
font-weight: 700;
font-size: 1.05rem;
color: var(--text);
white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-logo {
display: block;
width: 32px;
height: 32px;
flex: none;
border-radius: 9px;
}
.site-nav {
display: flex;
flex: 1;
flex-wrap: wrap;
gap: 2px;
justify-content: flex-end;
}
.site-nav a {
position: relative;
padding: 7px 11px;
border-radius: var(--radius-sm);
color: var(--muted);
font-size: .92rem;
transition: color .2s ease, background .2s ease;
}
.site-nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--panel-2); }
.site-nav a[aria-current="page"]::after {
content: "";
position: absolute;
left: 11px;
right: 11px;
bottom: 2px;
height: 2px;
border-radius: 2px;
background: var(--accent);
}
.nav-toggle { display: none; }
.logout-form { margin: 0; }
.logout-form .button { min-height: 34px; padding: 6px 10px; font-size: .92rem; }
/* ---------- Layout ---------- */
main {
flex: 1;
width: min(100% - 32px, var(--max));
margin: 0 auto;
padding: 28px 0 48px;
animation: rise .4s ease-out both;
outline: none;
}
h1 { font-size: clamp(1.6rem, 2.5vw, 2.1rem); line-height: 1.2; margin: .2em 0 .45em; }
h2 { font-size: 1.2rem; margin: 0 0 .5em; }
p { margin: 0 0 .8em; }
ul, ol { margin: 0 0 .8em; padding-left: 1.3em; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.card {
background: var(--panel);
border: 1px solid var(--line);
border-radius: var(--radius);
padding: 20px 22px;
margin: 0 0 18px;
box-shadow: var(--shadow);
transition: border-color .2s ease, transform .2s ease;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card > :last-child { margin-bottom: 0; }
.grid-2 {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
.account-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
align-items: start;
}
.account-grid > .card { margin: 0; }
.account-grid .form { max-width: none; }
.account-grid .actions + .form {
margin-top: 18px;
padding-top: 18px;
border-top: 1px solid var(--line);
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 16px;
}
.actions form { margin: 0; }
.hero {
padding: 26px 0 10px;
animation: rise .5s ease-out both;
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: .8rem;
font-weight: 700;
letter-spacing: .12em;
text-transform: uppercase;
}
.hero h1 { font-size: clamp(2rem, 4vw, 2.8rem); margin-bottom: .35em; }
/* ---------- Buttons ---------- */
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
min-height: 40px;
padding: 9px 16px;
border: 1px solid var(--accent);
border-radius: var(--radius-sm);
background: transparent;
color: var(--accent);
font: inherit;
font-size: .92rem;
font-weight: 600;
text-decoration: none;
cursor: pointer;
transition: background .2s ease, color .2s ease, transform .15s ease, box-shadow .2s ease;
}
.button:hover { text-decoration: none; background: color-mix(in srgb, var(--accent) 14%, transparent); }
.button:active { transform: translateY(1px); }
.button-primary {
background: linear-gradient(135deg, var(--accent), var(--accent-2));
border-color: transparent;
color: #fff;
box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.button-primary:hover { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; filter: brightness(1.08); }
.button-ghost { border-color: var(--line); color: var(--text); }
.button-small { min-height: 28px; padding: 4px 10px; font-size: .78rem; }
.button[aria-expanded="true"] { border-color: var(--accent); }
/* ---------- Stats ---------- */
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 12px;
margin: 18px 0;
}
.stat-tile {
display: flex;
flex-direction: column;
gap: 4px;
padding: 16px 18px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: var(--radius);
box-shadow: var(--shadow);
animation: rise .5s ease-out both;
}
.stat-tile:nth-child(2) { animation-delay: .04s; }
.stat-tile:nth-child(3) { animation-delay: .08s; }
.stat-tile:nth-child(4) { animation-delay: .12s; }
.stat-tile:nth-child(5) { animation-delay: .16s; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-note { font-size: .8rem; }
/* ---------- Home ---------- */
.home-lower {
display: grid;
grid-template-columns: minmax(0, 1.65fr) minmax(250px, 1fr);
gap: 18px;
align-items: start;
}
.home-lower > .card { margin: 0; }
.card-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 10px;
}
.card-head h2 { margin: 0; }
.card-head > a { font-size: .88rem; white-space: nowrap; }
.howto-list {
list-style: none;
padding: 0;
margin: 0;
display: grid;
counter-reset: howto;
}
.howto-list li {
counter-increment: howto;
display: grid;
grid-template-columns: 26px minmax(0, 1fr);
gap: 12px;
padding: 11px 0;
border-bottom: 1px dashed var(--line);
}
.howto-list li:first-child { padding-top: 0; }
.howto-list li:last-child { padding-bottom: 0; border-bottom: 0; }
.howto-num {
width: 26px;
height: 26px;
display: grid;
place-items: center;
border-radius: 50%;
background: var(--panel-2);
border: 1px solid var(--line);
color: var(--accent);
font-size: .78rem;
font-weight: 700;
}
.howto-num::before { content: counter(howto); }
.howto-list strong { display: block; font-size: .95rem; margin: 1px 0 2px; }
.howto-list p { margin: 0; font-size: .9rem; color: var(--muted); }
.copy-inline {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 58px;
min-height: 22px;
margin-left: 6px;
padding: 0 8px;
border: 1px solid var(--line);
border-radius: 999px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: .72rem;
font-weight: 600;
line-height: 1;
vertical-align: baseline;
cursor: pointer;
transition: color .15s ease, border-color .15s ease;
}
.copy-inline:hover { color: var(--text); border-color: var(--accent); }
/* ---------- Pills and status ---------- */
.pill {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 2px 10px;
border: 1px solid var(--line);
border-radius: 999px;
font-size: .8rem;
color: var(--muted);
white-space: nowrap;
}
.pill.is-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 60%, transparent); }
.pill.is-down { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.pill.is-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 60%, transparent); }
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
}
.pill.is-ok .dot { animation: pulse 2.4s ease-out infinite; }
/* ---------- Lists, key-value and steps ---------- */
.kv {
display: grid;
grid-template-columns: max-content 1fr;
gap: 10px 18px;
align-items: center;
margin: 0 0 12px;
}
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.link-list li:last-child { border-bottom: 0; }
.steps { list-style: none; padding: 0; counter-reset: step; }
.steps li {
counter-increment: step;
position: relative;
padding: 12px 12px 12px 52px;
border-bottom: 1px solid var(--line);
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
content: counter(step);
position: absolute;
left: 12px;
top: 12px;
width: 28px;
height: 28px;
display: grid;
place-items: center;
border-radius: 50%;
background: var(--panel-2);
border: 1px solid var(--line);
font-weight: 700;
font-size: .85rem;
}
.steps li > * { display: block; }
details {
border-top: 1px solid var(--line);
padding: 10px 0;
}
details:first-of-type { border-top: 0; }
summary {
cursor: pointer;
font-weight: 600;
list-style: none;
display: flex;
justify-content: space-between;
align-items: center;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--muted); font-size: 1.1rem; transition: transform .2s ease; }
details[open] > summary::after { content: "−"; }
details > :not(summary) { margin-top: 8px; }
/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; padding: 0; }
.table-wrap table { margin: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; background: var(--bg-soft); }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: 0; }
.pager {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
margin: 16px 0;
}
/* ---------- Filters ---------- */
.filters {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) auto;
gap: 12px;
align-items: end;
}
.filter-actions { display: flex; gap: 8px; }
/* ---------- Forms ---------- */
.form { display: grid; gap: 16px; max-width: 520px; }
label { display: grid; gap: 6px; font-weight: 500; font-size: .95rem; }
input[type="text"],
input[type="email"],
input[type="password"],
select {
width: 100%;
min-height: 42px;
padding: 9px 12px;
background: var(--bg);
color: var(--text);
border: 1px solid var(--line);
border-radius: var(--radius-sm);
font: inherit;
transition: border-color .2s ease, box-shadow .2s ease;
}
input:focus, select:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
input[aria-invalid="true"] { border-color: var(--danger); }
.input-with-button { display: flex; gap: 8px; }
.input-with-button input { flex: 1; }
.hint { color: var(--muted); font-size: .82rem; font-weight: 400; }
.field-error { color: var(--danger); font-size: .85rem; font-weight: 500; }
.field-error[hidden] { display: none; }
.strength { font-size: .82rem; color: var(--muted); min-height: 1.2em; }
.strength.is-weak { color: var(--danger); }
.strength.is-fair { color: var(--warn); }
.strength.is-strong { color: var(--ok); }
/* ---------- Account pages ---------- */
.auth-grid {
display: grid;
grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr);
gap: 20px;
align-items: start;
}
.auth-main,
.auth-side { margin: 0; }
.auth-main > h1 { margin-top: 0; }
.auth-form { max-width: none; }
.form-section { display: grid; gap: 14px; }
.form-section + .form-section {
padding-top: 18px;
border-top: 1px solid var(--line);
}
.form-section-title {
margin: 0;
font-size: .74rem;
font-weight: 700;
letter-spacing: .1em;
text-transform: uppercase;
color: var(--muted);
}
.auth-submit { width: 100%; min-height: 46px; }
.auth-consent { margin: 0; text-align: center; }
.auth-side h2 { font-size: .95rem; }
.auth-side h2:not(:first-child) { margin-top: 18px; }
.auth-side .check-list { margin-bottom: 14px; }
.check-list {
list-style: none;
padding: 0;
margin: 0 0 12px;
display: grid;
gap: 9px;
}
.check-list li {
position: relative;
padding-left: 22px;
font-size: .9rem;
line-height: 1.45;
}
.check-list li::before {
content: "✓";
position: absolute;
left: 0;
top: 0;
color: var(--accent);
font-weight: 700;
}
/* ---------- Notices, empty states ---------- */
.notice {
padding: 12px 14px;
border-radius: var(--radius-sm);
border: 1px solid var(--line);
background: var(--panel);
margin: 0 0 16px;
animation: rise .3s ease-out both;
}
.notice.is-ok { border-color: color-mix(in srgb, var(--ok) 60%, transparent); color: var(--ok); }
.notice.is-error { border-color: color-mix(in srgb, var(--danger) 60%, transparent); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 28px 18px; }
/* ---------- Long-form pages (privacy, terms) ---------- */
.prose { max-width: 78ch; }
.prose h2 { margin: 22px 0 8px; font-size: 1.15rem; }
.prose h2:first-child { margin-top: 0; }
.prose p { margin: 0 0 12px; line-height: 1.65; }
.prose ul { margin: 0 0 14px; padding-left: 22px; }
.prose li { margin: 5px 0; line-height: 1.6; }
.prose p:last-child, .prose ul:last-child { margin-bottom: 0; }
.prose h2[id] { scroll-margin-top: 84px; }
/* ---------- Room and client grids ---------- */
.room-grid,
.client-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
gap: 16px;
}
.room-card,
.client-card { display: flex; flex-direction: column; gap: 4px; }
.room-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 4px;
}
.room-head h2 { margin: 0; font-size: 1.05rem; word-break: break-word; }
/* ---------- Other servers ---------- */
.server-list { display: grid; gap: 14px; }
.server-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
grid-template-areas:
"head action"
"desc action";
align-items: center;
gap: 4px 24px;
margin: 0;
padding: 20px 22px;
}
.server-row-head {
grid-area: head;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.server-row-head h2 { margin: 0; font-size: 1.15rem; }
.server-row-desc {
grid-area: desc;
margin: 0;
color: var(--muted);
max-width: 74ch;
}
.server-row > .button { grid-area: action; white-space: nowrap; }
/* ---------- Footer ---------- */
.site-footer {
width: min(100% - 32px, var(--max));
margin: 0 auto;
padding: 22px 0 30px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: .88rem;
display: grid;
gap: 6px;
}
.footer-links { display: flex; gap: 14px; flex-wrap: wrap; }
/* ---------- Motion ---------- */
@keyframes rise {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: none; }
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
70% { box-shadow: 0 0 0 7px transparent; }
100% { box-shadow: 0 0 0 0 transparent; }
}
/* ---------- Responsive ---------- */
@media (max-width: 820px) {
.grid-2 { grid-template-columns: 1fr; }
.account-grid { grid-template-columns: 1fr; }
.auth-grid { grid-template-columns: 1fr; }
.home-lower { grid-template-columns: 1fr; }
.filters { grid-template-columns: 1fr 1fr; }
.filter-actions { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
.site-header { flex-wrap: wrap; }
.nav-toggle { display: inline-flex; margin-left: auto; }
.site-nav {
display: none;
width: 100%;
flex-direction: column;
gap: 4px;
padding: 8px 0 4px;
}
.site-nav.is-open { display: flex; }
.site-nav a { padding: 10px 12px; }
.theme-toggle { order: 3; }
.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
.server-row {
grid-template-columns: 1fr;
grid-template-areas:
"head"
"desc"
"action";
gap: 10px;
justify-items: start;
}
}
@media (max-width: 520px) {
.filters { grid-template-columns: 1fr; }
.kv { grid-template-columns: 1fr; gap: 4px; }
.kv dd { margin-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}

199
bart-info.php Normal file
View file

@ -0,0 +1,199 @@
<?php
declare(strict_types=1);
/**
* BART/Buddy ART info page.
*
* Static help page linked from the dashboard BART tab. Keep content practical
* and include sources/caveats when protocol details weren't verified live.
*/
require_once __DIR__ . '/lib.php';
$admin = admin_require_login();
admin_page('BART Info', 'dashboard', function (): void {
?>
<style>
.bip { display: grid; gap: 1rem; }
.bip-hero { padding: 1.25rem 1.4rem; }
.bip-hero h1 { margin: .2rem 0 .35rem; font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -.02em; }
.bip-hero p { margin: 0; max-width: 70ch; }
.bip-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.bip-section { padding: 1.25rem 1.4rem; }
.bip-section h2 { margin: 0 0 .35rem; font-size: 1.2rem; letter-spacing: -.01em; }
.bip-section > p { margin: 0 0 1rem; color: var(--muted); max-width: 75ch; }
.bip-caveat { padding: 1rem 1.1rem; border-radius: 12px; border: 1px solid rgba(255,211,106,.28); background: rgba(255,211,106,.08); }
.bip-caveat strong { color: #ffe3a0; }
.bip-cards { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .75rem; }
.bip-card { padding: 1rem; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.02); min-width: 0; }
.bip-card h3 { margin: 0 0 .4rem; font-size: .95rem; }
.bip-card p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.55; overflow-wrap: anywhere; }
.bip-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .75rem; }
.bip-step-list { display: grid; gap: .65rem; }
.bip-step { padding: 1rem; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.02); min-width: 0; }
.bip-step h3 { margin: 0 0 .35rem; font-size: .92rem; display: flex; gap: .5rem; align-items: center; }
.bip-step-num { width: 24px; height: 24px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; background: rgba(110,168,255,.16); color: var(--accent); font-size: .75rem; font-weight: 700; flex-shrink: 0; }
.bip-step p, .bip-step li { color: var(--muted); font-size: .88rem; line-height: 1.55; overflow-wrap: anywhere; }
.bip-step ul { margin: .4rem 0 0; padding-left: 1.1rem; display: grid; gap: .25rem; }
.bip-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.bip-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.bip-table th, .bip-table td { padding: .75rem .85rem; text-align: left; vertical-align: top; border-bottom: 1px solid rgba(148,163,184,.1); font-size: .86rem; }
.bip-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; background: rgba(255,255,255,.02); }
.bip-table tr:last-child td { border-bottom: 0; }
.bip-table td code, .bip code { font-family: var(--mono); font-size: .92em; background: rgba(110,168,255,.1); padding: .08rem .3rem; border-radius: 4px; }
.bip-source-list { display: grid; gap: .65rem; }
.bip-source { display: block; padding: 1rem; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.02); color: inherit; text-decoration: none; min-width: 0; }
.bip-source:hover { border-color: rgba(110,168,255,.3); background: rgba(110,168,255,.04); }
.bip-source h3 { margin: 0 0 .3rem; font-size: .92rem; }
.bip-source p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.5; overflow-wrap: anywhere; }
@media (max-width: 980px) { .bip-cards { grid-template-columns: 1fr; } .bip-grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .bip-section, .bip-hero { padding: 1rem; } }
</style>
<div class="bip">
<section class="panel bip-hero reveal">
<div style="display:flex;justify-content:space-between;gap:1rem;align-items:flex-start;flex-wrap:wrap">
<div>
<div class="eyebrow">Open OSCAR Server</div>
<h1>BART / Buddy ART Guide</h1>
<p class="muted">What BART assets are, how type IDs and hashes work, and how to manage them on the server and in OSCAR clients.</p>
</div>
<div class="bip-actions">
<a class="btn btn-ghost" href="index.php" style="text-decoration:none">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 18l-6-6 6-6"/></svg>
Back to Dashboard
</a>
</div>
</div>
</section>
<section class="panel bip-section reveal delay-1">
<div class="bip-caveat">
<strong>Accuracy note:</strong> This is a practical guide. Type IDs/names/descriptions reflect common OSCAR BART documentation and the catalog used by this admin UI. Management API endpoint details are based on Open OSCAR Server <code>api.yml</code>. NINA wiki was offline during this update, so protocol details were not re-verified live. Verify implementation-specific behavior against the sources below.
</div>
</section>
<section class="panel bip-section reveal delay-1">
<h2>What is BART?</h2>
<p>BART stands for <strong>Buddy ART</strong>. It's the OSCAR asset system used for buddy icons, sounds, emoticon sets, IM chrome, status strings, and other client art.</p>
<div class="bip-cards">
<div class="bip-card">
<h3>Identified by type + hash</h3>
<p>Each asset has a <strong>type ID</strong> (what it is) and a <strong>hash</strong> (usually MD5 hex of the file content). Together they identify the asset.</p>
</div>
<div class="bip-card">
<h3>Stored on the server</h3>
<p>The OSCAR server stores BART assets. Clients upload/download through the BART foodgroup (<code>0x0010</code>), and admins can manage them through the Management API.</p>
</div>
<div class="bip-card">
<h3>Used by clients</h3>
<p>Clients reference BART assets for buddy icons, arrival/depart sounds, IM chrome, emoticons, and other features. Support varies by client version.</p>
</div>
</div>
</section>
<section class="panel bip-section reveal delay-1">
<h2>Common BART type IDs</h2>
<p>Type IDs tell the server and client what the asset is for. These are the known types shown in the admin catalog.</p>
<div class="bip-table-wrap">
<table class="bip-table">
<thead><tr><th>ID</th><th>Name</th><th>Group</th><th>What it's for / notes</th></tr></thead>
<tbody>
<tr><td><code>0</code></td><td>Buddy icon (small)</td><td><span class="pill pill-muted">Icons</span></td><td>Small buddy icon. GIF/JPEG/BMP/PNG, &lt;= 32x32, &lt;= 2KB.</td></tr>
<tr><td><code>1</code></td><td>Buddy icon</td><td><span class="pill pill-muted">Icons</span></td><td>Standard buddy icon. GIF/JPEG/BMP/PNG, &lt;= 64x64, &lt;= 7KB.</td></tr>
<tr><td><code>12</code></td><td>Buddy icon (big)</td><td><span class="pill pill-muted">Icons</span></td><td>Large buddy icon. GIF/JPEG/BMP/PNG, &lt;= 1024x1024, &lt;= 64KB.</td></tr>
<tr><td><code>2</code></td><td>Status string</td><td><span class="pill pill-muted">Status</span></td><td>Status text in StringTLV format (DATA flag always set).</td></tr>
<tr><td><code>13</code></td><td>Status string time</td><td><span class="pill pill-muted">Status</span></td><td>Time when the status string was set.</td></tr>
<tr><td><code>3</code></td><td>Arrive sound</td><td><span class="pill pill-muted">Sounds</span></td><td>Sound played when a buddy comes online. WAV/MP3/MID, &lt;= 10KB.</td></tr>
<tr><td><code>96</code></td><td>Depart sound</td><td><span class="pill pill-muted">Sounds</span></td><td>Sound played when a buddy goes offline. WAV/MP3/MID, &lt;= 10KB.</td></tr>
<tr><td><code>131</code></td><td>IM sound</td><td><span class="pill pill-muted">Sounds</span></td><td>Instant message sound. WAV/MP3, &lt;= 10KB.</td></tr>
<tr><td><code>4</code></td><td>Rich text</td><td><span class="pill pill-muted">Text &amp; UI</span></td><td>Rich text formatting codes (DATA flag always set).</td></tr>
<tr><td><code>129</code></td><td>IM chrome</td><td><span class="pill pill-muted">Text &amp; UI</span></td><td>IM window wallpaper/background. GIF/JPG/BMP.</td></tr>
<tr><td><code>136</code></td><td>IM chrome XML</td><td><span class="pill pill-muted">Text &amp; UI</span></td><td>IM chrome XML definition.</td></tr>
<tr><td><code>137</code></td><td>IM chrome immersive</td><td><span class="pill pill-muted">Text &amp; UI</span></td><td>Immersive Expressions for IM chrome.</td></tr>
<tr><td><code>5</code></td><td>SuperBuddy icon</td><td><span class="pill pill-muted">Other</span></td><td>SuperBuddy icon XML.</td></tr>
<tr><td><code>6</code></td><td>Radio station</td><td><span class="pill pill-muted">Other</span></td><td>Radio station opaque struct (DATA flag always set).</td></tr>
<tr><td><code>15</code></td><td>Current AV track</td><td><span class="pill pill-muted">Other</span></td><td>Current audio/video track XML.</td></tr>
<tr><td><code>1024</code></td><td>Emoticon set</td><td><span class="pill pill-muted">Other</span></td><td>Set of default emoticons.</td></tr>
<tr><td><code>1026</code></td><td>Encryption cert chain</td><td><span class="pill pill-muted">Security</span></td><td>Certificate chain for encryption certs.</td></tr>
<tr><td><code>1027</code></td><td>Signing cert chain</td><td><span class="pill pill-muted">Security</span></td><td>Certificate chain for signing certs.</td></tr>
<tr><td><code>1028</code></td><td>Gateway cert</td><td><span class="pill pill-muted">Security</span></td><td>Certificate for enterprise gateway.</td></tr>
</tbody>
</table>
</div>
</section>
<section class="panel bip-section reveal delay-2">
<h2>How to use BART in the admin panel</h2>
<p>The BART tab talks to the Open OSCAR Management API. Pick a type, browse existing assets, or upload a new one.</p>
<div class="bip-grid-2">
<div class="bip-step-list">
<div class="bip-step">
<h3><span class="bip-step-num">1</span>Pick a type</h3>
<p>Select a type card in the left catalog. The selected type is used for browsing and uploading, and the upload banner explains what that type is for.</p>
</div>
<div class="bip-step">
<h3><span class="bip-step-num">2</span>Browse assets</h3>
<ul>
<li><strong>List this type</strong> - fetch assets for the selected type ID.</li>
<li><strong>Load all assets</strong> - scan known types and merge results so you can search by hash, type ID, or type name.</li>
<li><strong>Preview/Use</strong> - preview an asset or copy its hash/type into forms.</li>
</ul>
</div>
<div class="bip-step">
<h3><span class="bip-step-num">3</span>Upload or delete</h3>
<ul>
<li><strong>Upload</strong> - choose a file, auto-generate MD5 hash, then upload to <code>POST /bart/{hash}?type=...</code>.</li>
<li><strong>Delete</strong> - remove an asset by hash via <code>DELETE /bart/{hash}</code>.</li>
</ul>
</div>
</div>
<div class="bip-step-list">
<div class="bip-step">
<h3>On the server</h3>
<ul>
<li>Assets are stored by hash/type in the server's BART store.</li>
<li>Management API endpoints: <code>GET /bart?type=</code>, <code>GET /bart/{hash}</code>, <code>POST /bart/{hash}?type=</code>, <code>DELETE /bart/{hash}</code>.</li>
<li>Feedbag entries can reference BART items (e.g. buddy icons). The admin Feedbag tab can set/remove a user's feedbag BART item.</li>
</ul>
</div>
<div class="bip-step">
<h3>In OSCAR clients</h3>
<ul>
<li>Clients use the BART foodgroup (<code>0x0010</code>) to upload/download art assets.</li>
<li>Buddy icons are typically uploaded, hashed, and referenced in presence/feedbag data so other clients can fetch them.</li>
<li>Feature support varies by client and server version. A 404/unsupported response may mean the running server build doesn't expose that endpoint.</li>
</ul>
</div>
</div>
</div>
</section>
<section class="panel bip-section reveal delay-3">
<h2>Sources &amp; references</h2>
<p>Use these for authoritative or implementation-specific details.</p>
<div class="bip-source-list">
<a class="bip-source" href="https://github.com/mk6i/open-oscar-server/blob/main/api.yml" target="_blank" rel="noopener noreferrer">
<h3>Open OSCAR Management API spec (api.yml)</h3>
<p>Used for Management API endpoint behavior (<code>/bart</code> list/get/upload/delete, feedbag BART item endpoints). Primary source for admin-panel API behavior.</p>
</a>
<a class="bip-source" href="https://github.com/mk6i/open-oscar-server" target="_blank" rel="noopener noreferrer">
<h3>Open OSCAR Server (GitHub)</h3>
<p>Server project, releases, and implementation details.</p>
</a>
<a class="bip-source" href="https://wiki.nina.chat/wiki/Protocols/OSCAR/BART" target="_blank" rel="noopener noreferrer">
<h3>NINA Wiki - OSCAR BART</h3>
<p>Protocol-level BART reference. <strong>Not re-verified live during this update because the wiki was offline.</strong></p>
</a>
<a class="bip-source" href="https://wiki.nina.chat/wiki/Protocols/OSCAR" target="_blank" rel="noopener noreferrer">
<h3>NINA Wiki - OSCAR Protocol</h3>
<p>General OSCAR protocol/foodgroup reference. Also not re-verified live during this update.</p>
</a>
<div class="bip-source">
<h3>Admin panel implementation</h3>
<p>Type labels/descriptions in this guide mirror the BART type catalog used by this admin UI; verify against protocol/server docs before relying on size/format constraints for a specific client.</p>
</div>
</div>
</section>
</div>
<?php
});

58
config.example.php Normal file
View file

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/**
* Oscar Admin - standalone configuration template.
*
* Copy to config.php and fill in values. config.php is gitignored.
* Keep the Management API private (localhost/trusted network only).
*/
return [
// --- Admin access ---
// OSCAR screen names allowed to sign into this admin panel.
// Use the normalized/canonical screen name as it appears on the server.
'admin_users' => [
// 'admin',
// 'clay',
],
// --- System OSCAR account used to send login codes / messages ---
// Create this account on the OSCAR server first.
'system_screen_name' => 'SystemAdmin',
'system_password' => 'CHANGE_ME',
// --- OSCAR Management API ("dev API") ---
// The management API listens on API_LISTENER in the OSCAR server settings.
// Keep this on localhost/private network; do not expose it publicly.
'mgmt_api_host' => '127.0.0.1',
'mgmt_api_port' => 8080,
// Optional: separate dev API endpoint if your setup uses one.
// Leave empty to use mgmt_api_host/mgmt_api_port.
'dev_api_host' => '',
'dev_api_port' => 0,
// --- Admin UI ---
'site_name' => 'Oscar Server Admin',
'session_name' => 'oscar_admin',
'login_code_ttl_seconds' => 600,
'login_code_length' => 8,
'max_login_attempts' => 8,
'login_attempt_window_seconds' => 900,
// --- Optional Gotify addon (lib_gotify.php) ---
// 100% optional. The admin panel works without this addon.
// Enable the feature here; each admin user sets their own Gotify URL/token
// from the dashboard user menu (stored in gotify-users.php, gitignored).
'gotify_enabled' => false,
'gotify_priority' => 5, // default priority for notifications (0-10)
// Optional global fallback (used only if a user has no personal Gotify config).
// Prefer per-user settings in the dashboard.
'gotify_url' => '',
'gotify_token' => '',
// Base path to shared web CSS. Defaults to bundled assets/style.css.
// Relative to this admin directory, or absolute.
'shared_style_path' => 'assets/style.css',
];

508
index.php Normal file
View file

@ -0,0 +1,508 @@
<?php
declare(strict_types=1);
/**
* Admin dashboard page.
*
* UI shell for users/sessions/rooms/messaging/directory/BART/buddy list/audit/API console.
* Behavior lives in admin.js; data/actions go through action.php.
*/
require_once __DIR__ . '/lib.php';
$admin = admin_require_login();
admin_page('Dashboard', 'dashboard', function () use ($admin): void {
?>
<section class="hero reveal">
<div>
<div class="eyebrow">Open OSCAR Server</div>
<h1>Control Room</h1>
<p class="muted">Signed in as <strong><?= h((string) $admin['screen_name']) ?></strong>. Manage users, sessions, rooms, and messages from one place.</p>
</div>
<div class="hero-actions">
<button class="btn btn-primary" id="refresh-all" type="button" title="Reload overview, directory, and audit data">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 12a8 8 0 1 1-2.34-5.66"/><path d="M20 4v6h-6"/></svg>
Refresh
</button>
<label class="check auto-refresh-toggle"><input type="checkbox" id="auto-refresh-toggle"> <span>Auto-refresh 15s</span></label>
<div class="status-chip" id="api-status-chip"><span class="status-dot"></span><span class="status-text">Checking...</span></div>
</div>
</section>
<section class="stats-grid reveal delay-1" aria-label="Overview stats">
<article class="stat-card">
<div class="stat-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg></div>
<div class="stat-body"><div class="stat-label">Server</div><div class="stat-value" id="stat-version">—</div><div class="stat-sub muted" id="stat-version-sub">Version</div></div>
</article>
<article class="stat-card">
<div class="stat-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="8.5" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg></div>
<div class="stat-body"><div class="stat-label">Online sessions</div><div class="stat-value" id="stat-sessions">—</div><div class="stat-sub muted" id="stat-sessions-sub">Active now</div></div>
</article>
<article class="stat-card">
<div class="stat-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg></div>
<div class="stat-body"><div class="stat-label">Users</div><div class="stat-value" id="stat-users">—</div><div class="stat-sub muted" id="stat-users-sub">Registered accounts</div></div>
</article>
<article class="stat-card">
<div class="stat-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg></div>
<div class="stat-body"><div class="stat-label">Chat rooms</div><div class="stat-value" id="stat-rooms">—</div><div class="stat-sub muted" id="stat-rooms-sub">Public / private</div></div>
</article>
</section>
<section class="panel reveal delay-2">
<div class="tab-bar" role="tablist" aria-label="Admin sections">
<button class="tab active" role="tab" data-tab="sessions">Sessions</button>
<button class="tab" role="tab" data-tab="users">Users</button>
<button class="tab" role="tab" data-tab="rooms">Chat Rooms</button>
<button class="tab" role="tab" data-tab="messaging">Messaging</button>
<button class="tab" role="tab" data-tab="directory">Directory</button>
<button class="tab" role="tab" data-tab="bart">BART</button>
<button class="tab" role="tab" data-tab="feedbag">Feedbag</button>
<button class="tab" role="tab" data-tab="audit">Audit</button>
<button class="tab" role="tab" data-tab="api">API Console</button>
</div>
<div class="tab-panels">
<div class="tab-panel active" data-panel="sessions">
<div class="panel-head">
<div>
<h2>Active Sessions <span class="tip" tabindex="0" data-tip="Live sessions from the OSCAR Management API. Kick disconnects all active instances for that screen name.">?</span></h2>
<p class="muted">Who's online right now. Kick a session if needed.</p>
</div>
<button class="btn btn-ghost btn-small" data-refresh="sessions">Refresh</button>
</div>
<div class="table-wrap">
<table class="data-table">
<thead><tr><th>Screen name</th><th>Online</th><th>Idle</th><th>Away</th><th>Instance</th><th>Client</th><th></th></tr></thead>
<tbody id="sessions-tbody"><tr><td colspan="7" class="empty-cell">Loading...</td></tr></tbody>
</table>
</div>
<div class="card subcard" id="session-detail-card" style="margin-top:.75rem;display:none">
<div class="panel-head"><h3>Session detail: <span id="session-detail-name" class="mono"></span></h3><button class="btn btn-ghost btn-small" id="close-session-detail" type="button">Close</button></div>
<div id="session-detail-json" class="detail-view">Select a session.</div>
</div>
</div>
<div class="tab-panel" data-panel="users">
<div class="panel-head">
<div>
<h2>Users <span class="tip" tabindex="0" data-tip="Manage OSCAR accounts: create, view details, suspend/unsuspend, set bot flag, reset password, or delete.">?</span></h2>
<p class="muted">Create, inspect, suspend, or delete accounts.</p>
</div>
<button class="btn btn-ghost btn-small" data-refresh="users">Refresh</button>
</div>
<div class="split-grid">
<div class="card subcard">
<h3>Create user</h3>
<form id="create-user-form" class="stack-form compact">
<label class="field"><span>Screen name / UIN <span class="tip" tabindex="0" data-tip="AIM screen name or ICQ UIN to create.">?</span></span><input name="screen_name" required maxlength="64"></label>
<label class="field"><span>Password <span class="tip" tabindex="0" data-tip="Password for the new account.">?</span></span><input name="password" type="password" required maxlength="64"></label>
<button class="btn btn-primary" type="submit">Create user</button>
</form>
</div>
<div class="card subcard">
<h3>Set password</h3>
<form id="set-password-form" class="stack-form compact">
<label class="field"><span>Screen name / UIN <span class="tip" tabindex="0" data-tip="AIM screen name or ICQ UIN to create.">?</span></span><input name="screen_name" required maxlength="64"></label>
<label class="field"><span>New password <span class="tip" tabindex="0" data-tip="Sets a new password via the Management API.">?</span></span><input name="password" type="password" required maxlength="64"></label>
<button class="btn btn-primary" type="submit">Update password</button>
</form>
</div>
</div>
<div class="table-tools users-toolbar">
<input type="search" id="users-filter" class="input" placeholder="Filter users...">
<div class="bulk-actions">
<select id="bulk-suspend-status" class="input">
<option value="">Bulk status...</option>
<option value="">active (clear)</option>
<option value="suspended">suspended</option>
<option value="suspended_age">suspended_age</option>
<option value="expired">expired</option>
<option value="deleted">deleted</option>
</select>
<button class="btn btn-ghost btn-small" id="bulk-apply-status" type="button">Apply</button>
<button class="btn btn-danger btn-small" id="bulk-delete-users" type="button">Delete selected</button>
</div>
</div>
<div class="table-wrap">
<table class="data-table">
<thead><tr><th><input type="checkbox" id="users-select-all"></th><th>Screen name</th><th>Type</th><th>Status</th><th>Bot</th><th>Actions</th></tr></thead>
<tbody id="users-tbody"><tr><td colspan="6" class="empty-cell">Loading...</td></tr></tbody>
</table>
</div>
<div class="card subcard" id="user-detail-card" style="margin-top:.75rem;display:none">
<div class="panel-head"><h3>User details: <span id="user-detail-name" class="mono"></span></h3><button class="btn btn-ghost btn-small" id="close-user-detail" type="button">Close</button></div>
<div class="split-grid">
<div>
<div id="user-detail-json" class="detail-view">Select a user.</div>
</div>
<div class="stack-form compact">
<label class="field"><span>Suspend status <span class="tip" tabindex="0" data-tip="Account status: active (clear), suspended, suspended_age, expired, or deleted.">?</span></span>
<select id="user-detail-status" class="input">
<option value="">active (clear)</option>
<option value="suspended">suspended</option>
<option value="suspended_age">suspended_age</option>
<option value="expired">expired</option>
<option value="deleted">deleted</option>
</select>
</label>
<label class="check"><input type="checkbox" id="user-detail-bot"> <span>Bot account (exempt from rate limiting) <span class="tip" tabindex="0" data-tip="Marks account as bot; bots are exempt from rate limiting. Only enable for trusted bots.">?</span></span></label>
<button class="btn btn-primary btn-small" id="user-detail-save" type="button">Save account</button>
<div class="field-row">
<button class="btn btn-ghost btn-small" id="user-detail-icon" type="button">Load icon</button>
<button class="btn btn-ghost btn-small" id="user-detail-sessions" type="button">Load sessions</button>
</div>
<div id="user-detail-icon-wrap"></div>
<div id="user-detail-sessions-json" class="detail-view" style="display:none"></div>
</div>
</div>
</div>
</div>
<div class="tab-panel" data-panel="rooms">
<div class="panel-head">
<div>
<h2>Chat Rooms <span class="tip" tabindex="0" data-tip="Public rooms can be created/deleted here. Private rooms are listed read-only from the server.">?</span></h2>
<p class="muted">Public and private chat rooms on the server.</p>
</div>
<button class="btn btn-ghost btn-small" data-refresh="rooms">Refresh</button>
</div>
<div class="split-grid">
<div class="card subcard">
<h3>Create public room</h3>
<form id="create-room-form" class="stack-form compact">
<label class="field"><span>Room name</span><input name="name" required maxlength="128"></label>
<button class="btn btn-primary" type="submit">Create room</button>
</form>
</div>
<div class="card subcard">
<h3>Delete public rooms</h3>
<form id="delete-room-form" class="stack-form compact">
<label class="field"><span>Room names (one per line or comma-separated)</span><textarea name="names" rows="3" required></textarea></label>
<button class="btn btn-danger" type="submit">Delete rooms</button>
</form>
</div>
</div>
<div class="room-columns">
<div>
<h3 class="subhead">Public rooms</h3>
<div class="table-wrap"><table class="data-table"><thead><tr><th>Name</th><th>Created</th><th>Participants</th></tr></thead><tbody id="public-rooms-tbody"><tr><td colspan="3" class="empty-cell">Loading...</td></tr></tbody></table></div>
</div>
<div>
<h3 class="subhead">Private rooms</h3>
<div class="table-wrap"><table class="data-table"><thead><tr><th>Name</th><th>Created</th><th>Creator</th><th>Participants</th></tr></thead><tbody id="private-rooms-tbody"><tr><td colspan="4" class="empty-cell">Loading...</td></tr></tbody></table></div>
</div>
</div>
</div>
<div class="tab-panel" data-panel="messaging">
<div class="panel-head">
<div>
<h2>Messaging <span class="tip" tabindex="0" data-tip="Send IMs or popups via the Management API. Popups require a server version that supports /popup.">?</span></h2>
<p class="muted">Send instant messages or popup broadcasts through the management API.</p>
</div>
</div>
<div class="split-grid">
<div class="card subcard">
<h3>Send instant message</h3>
<form id="send-im-form" class="stack-form compact">
<label class="field"><span>From <span class="tip" tabindex="0" data-tip="Sender screen name. Must exist on the OSCAR server.">?</span></span><input name="from" required maxlength="64" value="<?= h((string) admin_cfg('system_screen_name', '')) ?>"></label>
<label class="field"><span>To</span><input name="to" required maxlength="64"></label>
<label class="field"><span>Message</span><textarea name="text" rows="4" required></textarea></label>
<label class="check"><input type="checkbox" name="store_offline"> <span>Store offline if recipient is offline <span class="tip" tabindex="0" data-tip="If enabled, the server stores the message for delivery when the recipient comes online.">?</span></span></label>
<button class="btn btn-primary" type="submit">Send IM</button>
</form>
</div>
<div class="card subcard">
<h3>Send popup</h3>
<p class="muted small" style="margin:-.25rem 0 .5rem;font-size:.78rem">Not supported on OSCAR Server 0.25.0; expected in the next release after v0.25.0 (added in main, PR #222).</p>
<form id="send-popup-form" class="stack-form compact">
<label class="field"><span>Recipients (one per line/comma, ignored if broadcast)</span><textarea name="recipients" rows="2"></textarea></label>
<label class="check"><input type="checkbox" name="broadcast"> <span>Broadcast to all connected users <span class="tip" tabindex="0" data-tip="Sends popup to every connected user. Recipients are ignored when broadcast is on.">?</span></span></label>
<label class="field"><span>Message</span><textarea name="message" rows="4" required maxlength="8000"></textarea></label>
<label class="field"><span>URL (optional)</span><input name="url" maxlength="2048" placeholder="https://..."></label>
<div class="field-row">
<label class="field"><span>Width</span><input name="width" type="number" min="0" max="65535" value="320"></label>
<label class="field"><span>Height</span><input name="height" type="number" min="0" max="65535" value="200"></label>
</div>
<button class="btn btn-primary" type="submit">Send popup</button>
</form>
</div>
</div>
</div>
<div class="tab-panel" data-panel="directory">
<div class="panel-head">
<div>
<h2>Directory <span class="tip" tabindex="0" data-tip="Manage AIM directory categories/keywords and view AIM directory entries.">?</span></h2>
<p class="muted">Manage AIM directory keyword categories and keywords.</p>
</div>
<button class="btn btn-ghost btn-small" data-refresh="directory">Refresh</button>
</div>
<div class="split-grid">
<div class="card subcard">
<h3>Create category</h3>
<form id="create-category-form" class="stack-form compact">
<label class="field"><span>Category name</span><input name="name" required maxlength="128"></label>
<button class="btn btn-primary" type="submit">Create category</button>
</form>
<h3 style="margin-top:1rem">Add keyword</h3>
<form id="create-keyword-form" class="stack-form compact">
<label class="field"><span>Category ID</span><input name="category_id" type="number" min="1" required></label>
<label class="field"><span>Keyword</span><input name="name" required maxlength="128"></label>
<button class="btn btn-primary" type="submit">Add keyword</button>
</form>
</div>
<div class="card subcard">
<h3>Categories</h3>
<div class="table-wrap">
<table class="data-table">
<thead><tr><th>ID</th><th>Name</th><th></th></tr></thead>
<tbody id="categories-tbody"><tr><td colspan="3" class="empty-cell">Loading...</td></tr></tbody>
</table>
</div>
</div>
</div>
<div class="card subcard" style="margin-top:1rem">
<div class="panel-head"><h3>Keywords</h3><div class="inline-controls"><input id="keyword-category-id" class="input" type="number" min="1" placeholder="Category ID"><button class="btn btn-ghost btn-small" id="load-keywords-btn" type="button">Load</button></div></div>
<div class="table-wrap">
<table class="data-table">
<thead><tr><th>ID</th><th>Name</th><th></th></tr></thead>
<tbody id="keywords-tbody"><tr><td colspan="3" class="empty-cell">Select a category.</td></tr></tbody>
</table>
</div>
</div>
<div class="card subcard" style="margin-top:1rem">
<div class="panel-head"><h3>AIM Directory Entries</h3><button class="btn btn-ghost btn-small" id="load-aim-directory" type="button">Load</button></div>
<div class="table-wrap"><table class="data-table"><thead><tr><th>Screen name</th><th>Name</th><th>Location</th><th>Keywords</th></tr></thead><tbody id="aim-directory-tbody"><tr><td colspan="4" class="empty-cell">Not loaded.</td></tr></tbody></table></div>
</div>
</div>
<div class="tab-panel" data-panel="bart">
<div class="panel-head">
<div>
<h2>BART Assets <span class="tip" tabindex="0" data-tip="BART (Buddy ART) is how AIM/OSCAR stores buddy icons, sounds, emoticons, IM chrome, and other art assets. Each asset has a type (what it is) and a hash (its ID).">?</span></h2>
<p class="muted">Pick an asset type on the left, then browse or upload on the right.</p>
</div>
<div class="inline-controls">
<a class="btn btn-ghost btn-small" href="bart-info.php" style="text-decoration:none">BART info</a>
<button class="btn btn-primary btn-small" id="bart-browse-all" type="button">Load all assets</button>
</div>
</div>
<div class="bart-layout">
<div class="card subcard bart-rail">
<div class="panel-head">
<div>
<h3>Asset types <span class="tip" tabindex="0" data-tip="Click a type to select it. The selected type is used for browsing and uploading.">?</span></h3>
<p class="muted small" style="margin:0;font-size:.78rem">Select what kind of asset you're working with.</p>
</div>
</div>
<input type="search" id="bart-type-filter" class="input" placeholder="Filter types..." style="margin-bottom:.6rem">
<div id="bart-type-catalog" class="bart-type-catalog"></div>
</div>
<div class="bart-main">
<div class="card subcard">
<div class="panel-head">
<div>
<h3>Browse assets</h3>
<p class="muted small" style="margin:0;font-size:.78rem">List assets for the selected type, or load everything.</p>
</div>
</div>
<form id="bart-list-form" class="stack-form compact">
<div class="field-row" style="align-items:flex-end">
<label class="field" style="flex:0 0 140px"><span>Type ID <span class="tip" tabindex="0" data-tip="Selected type ID. Click a type card on the left or enter an ID.">?</span></span><input name="type" id="bart-list-type" type="number" min="0" value="1" required></label>
<button class="btn btn-primary btn-small" type="submit">List this type</button>
<button class="btn btn-ghost btn-small" type="button" id="bart-browse-all-secondary">Load all types</button>
</div>
<div id="bart-selected-type-info" class="bart-type-info"></div>
</form>
<div class="field-row" style="margin-top:.5rem">
<input type="search" id="bart-asset-filter" class="input" placeholder="Search by hash or type name..." style="flex:1">
<span id="bart-asset-count" class="muted small" style="font-size:.78rem;white-space:nowrap"></span>
</div>
<div id="bart-browse-status" class="bart-browse-status"></div>
<div class="table-wrap" style="margin-top:.5rem"><table class="data-table"><thead><tr><th>Asset hash</th><th>Type</th><th></th></tr></thead><tbody id="bart-list-tbody"><tr><td colspan="3" class="empty-cell">Select a type and click "List this type", or click "Load all types".</td></tr></tbody></table></div>
</div>
<div class="card subcard">
<div class="panel-head">
<div>
<h3>Upload asset</h3>
<p class="muted small" style="margin:0;font-size:.78rem">Upload a file for the selected asset type.</p>
</div>
</div>
<div id="bart-upload-purpose" class="bart-upload-purpose"></div>
<form id="bart-upload-form" class="stack-form compact">
<label class="field"><span>Asset type <span class="tip" tabindex="0" data-tip="What this file will be used for. Pick from the catalog on the left or enter an ID.">?</span></span><input name="type" id="bart-upload-type" type="number" min="0" value="1" required></label>
<div id="bart-upload-type-info" class="bart-type-info"></div>
<label class="field"><span>File <span class="tip" tabindex="0" data-tip="The asset file to upload. Format depends on type (images, sounds, XML, etc.).">?</span></span><input name="file" id="bart-upload-file" type="file" required></label>
<label class="field"><span>Asset hash (MD5 hex) <span class="tip" tabindex="0" data-tip="BART assets are identified by MD5 hash. Auto-generates when you pick a file.">?</span></span>
<div class="inline-controls"><input name="hash" id="bart-upload-hash" required placeholder="auto-generate or paste hash" style="flex:1"><button class="btn btn-ghost btn-small" id="bart-hash-file" type="button">Hash file</button></div>
</label>
<button class="btn btn-primary" type="submit">Upload asset</button>
</form>
<hr style="border:0;border-top:1px solid var(--line);margin:.85rem 0">
<h3>Preview / delete by hash</h3>
<form id="bart-get-form" class="stack-form compact">
<label class="field"><span>Asset hash <span class="tip" tabindex="0" data-tip="Paste or pick a hash from the browse table to preview or delete it.">?</span></span><input name="hash" id="bart-get-hash" required placeholder="md5 hex"></label>
<div class="field-row">
<button class="btn btn-ghost btn-small" type="submit">Preview</button>
<button class="btn btn-danger btn-small" id="bart-delete-btn" type="button">Delete</button>
</div>
</form>
<div id="bart-preview" style="margin-top:.5rem"></div>
</div>
</div>
</div>
</div>
<div class="tab-panel" data-panel="feedbag">
<div class="panel-head">
<div>
<h2>Buddy List <span class="tip" tabindex="0" data-tip="The buddy list (called 'feedbag' in OSCAR) stores a user's groups and buddies on the server.">?</span></h2>
<p class="muted">Manage a user's buddy groups, buddies, linked accounts, and advanced icon settings.</p>
</div>
</div>
<div class="card subcard" style="margin-bottom:.75rem">
<div class="panel-head">
<div>
<h3>1. Choose a user</h3>
<p class="muted small" style="margin:0;font-size:.78rem">Load a user's buddy list to view and manage it.</p>
</div>
<div id="feedbag-current-user" class="muted small" style="font-size:.8rem"></div>
</div>
<form id="feedbag-load-form" class="stack-form compact">
<div class="field-row" style="align-items:flex-end">
<label class="field" style="flex:1"><span>Screen name <span class="tip" tabindex="0" data-tip="The AIM/ICQ screen name whose buddy list you want to manage.">?</span></span><input name="screen_name" id="feedbag-screen-name" required placeholder="e.g. clarth"></label>
<button class="btn btn-primary" type="submit">Load buddy list</button>
</div>
</form>
</div>
<div class="split-grid">
<div class="card subcard">
<div class="panel-head">
<div>
<h3>2. Buddy groups &amp; buddies</h3>
<p class="muted small" style="margin:0;font-size:.78rem">Groups organize a user's buddies. Add a group, then add buddies to it.</p>
</div>
</div>
<div id="feedbag-groups-view" class="detail-list" style="margin-bottom:.75rem">
<div class="detail-empty">Load a user to see their buddy list.</div>
</div>
<hr style="border:0;border-top:1px solid var(--line);margin:.75rem 0">
<h3>Add a group</h3>
<form id="feedbag-add-group-form" class="stack-form compact">
<label class="field"><span>Group name <span class="tip" tabindex="0" data-tip="A folder name in the buddy list, like 'Friends' or 'Co-workers'.">?</span></span><input name="group_name" id="feedbag-new-group-name" required placeholder="e.g. Friends"></label>
<button class="btn btn-primary btn-small" type="submit">Add group</button>
</form>
<details style="margin-top:.75rem">
<summary class="muted small" style="cursor:pointer;font-size:.78rem">Show raw data</summary>
<div id="feedbag-json" class="detail-view" style="margin-top:.5rem;max-height:260px;overflow:auto">—</div>
</details>
</div>
<div class="card subcard">
<div class="panel-head">
<div>
<h3>3. Manage buddies</h3>
<p class="muted small" style="margin:0;font-size:.78rem">Add or remove buddies in the selected user's groups.</p>
</div>
</div>
<form id="feedbag-buddy-form" class="stack-form compact">
<label class="field"><span>Group <span class="tip" tabindex="0" data-tip="Pick the group to add the buddy to. Load the buddy list first to populate this list.">?</span></span>
<select name="group_id" id="feedbag-group-select" class="input" required>
<option value="">Load a buddy list first...</option>
</select>
</label>
<label class="field"><span>Buddy screen name <span class="tip" tabindex="0" data-tip="The screen name of the buddy to add or remove.">?</span></span><input name="buddy_screen_name" id="feedbag-buddy-name" required placeholder="e.g. buddy123"></label>
<div class="field-row">
<button class="btn btn-primary btn-small" type="submit">Add buddy</button>
<button class="btn btn-danger btn-small" id="feedbag-remove-buddy-btn" type="button">Remove buddy</button>
</div>
</form>
<hr style="border:0;border-top:1px solid var(--line);margin:.85rem 0">
<h3>Linked accounts <span class="tip" tabindex="0" data-tip="Linked accounts are alternate screen names connected to the same user on the server.">?</span></h3>
<p class="muted small" style="margin:0 0 .5rem;font-size:.78rem">Connect alternate screen names to the loaded user.</p>
<form id="linked-load-form" class="stack-form compact">
<div class="field-row">
<button class="btn btn-ghost btn-small" type="submit">Load linked accounts</button>
</div>
</form>
<div id="linked-json" class="detail-view" style="margin:.5rem 0;max-height:160px;overflow:auto">—</div>
<form id="linked-add-form" class="stack-form compact">
<label class="field"><span>Linked screen name</span><input name="linked_screen_name" id="linked-screen-name" required placeholder="e.g. altname"></label>
<div class="field-row">
<button class="btn btn-primary btn-small" type="submit">Link account</button>
<button class="btn btn-danger btn-small" id="linked-remove-btn" type="button">Unlink</button>
</div>
</form>
<details style="margin-top:.85rem">
<summary class="muted small" style="cursor:pointer;font-size:.78rem">Advanced: Buddy icon / BART item</summary>
<p class="muted small" style="margin:.5rem 0;font-size:.78rem">Advanced OSCAR setting: assign a BART asset (like a buddy icon) to the user's feedbag. Most admins won't need this.</p>
<form id="feedbag-bart-set-form" class="stack-form compact">
<label class="field"><span>Asset hash</span><input name="hash" placeholder="md5 hex"></label>
<label class="field"><span>Type ID <span class="tip" tabindex="0" data-tip="BART type ID, e.g. 1 for buddy icon. See BART tab for type catalog.">?</span></span><input name="type" type="number" min="0" placeholder="e.g. 1"></label>
<div class="field-row">
<button class="btn btn-primary btn-small" type="submit">Set item</button>
<button class="btn btn-danger btn-small" id="feedbag-bart-delete-btn" type="button">Remove item</button>
</div>
</form>
</details>
</div>
</div>
</div>
<div class="tab-panel" data-panel="audit">
<div class="panel-head">
<div><h2>Audit Log <span class="tip" tabindex="0" data-tip="Local log of admin panel actions stored in audit.log on this server (gitignored).">?</span></h2><p class="muted">Recent admin actions from this panel.</p></div>
<button class="btn btn-ghost btn-small" id="refresh-audit" type="button">Refresh</button>
</div>
<div class="table-wrap">
<table class="data-table">
<thead><tr><th>Time</th><th>User</th><th>Action</th><th>Details</th></tr></thead>
<tbody id="audit-tbody"><tr><td colspan="4" class="empty-cell">Loading...</td></tr></tbody>
</table>
</div>
</div>
<div class="tab-panel" data-panel="api">
<div class="panel-head">
<div>
<h2>API Console</h2>
<p class="muted">Send raw requests to the configured Management API. Full power, full responsibility.</p>
</div>
</div>
<div class="card subcard">
<form id="api-console-form" class="stack-form">
<div class="field-row">
<label class="field" style="max-width:180px"><span>Method</span>
<select name="method">
<option>GET</option><option>POST</option><option>PUT</option><option>PATCH</option><option>DELETE</option>
</select>
</label>
<label class="field"><span>Path <span class="tip" tabindex="0" data-tip="Management API path, e.g. /session or /user/screenname/account.">?</span></span><input name="path" placeholder="/session" required></label>
</div>
<label class="field"><span>JSON body (optional) <span class="tip" tabindex="0" data-tip="Raw JSON request body. Leave empty for GET/DELETE requests that don't need a body.">?</span></span><textarea name="body" rows="8" placeholder='{"screen_name":"example","password":"secret"}' class="mono"></textarea></label>
<button class="btn btn-primary" type="submit">Send request</button>
</form>
</div>
<div class="card subcard" style="margin-top:1rem">
<div class="panel-head"><h3>Response</h3><button class="btn btn-ghost btn-small" id="clear-api-response" type="button">Clear</button></div>
<pre id="api-console-output" class="code-block">No request sent yet.</pre>
</div>
</div>
</div>
</section>
<div id="toast-container" aria-live="polite" aria-atomic="true"></div>
<?php
});

433
lib.php Normal file
View file

@ -0,0 +1,433 @@
<?php
declare(strict_types=1);
/**
* Oscar Admin shared helpers.
*
* This is the core include for the standalone admin panel.
* Responsibilities:
* - config loading (config.php, fallback config.example.php)
* - session/CSRF/auth helpers
* - OSCAR Management API client (admin_api/admin_send_im)
* - login throttle + pending-login state
* - page shell rendering (admin_page)
* - audit log helpers
*
* Keep this file dependency-light; optional integrations (Gotify) live in
* separate lib_gotify.php and are loaded conditionally.
*/
function admin_config(): array
{
static $config = null;
if ($config === null) {
$configPath = __DIR__ . '/config.php';
$examplePath = __DIR__ . '/config.example.php';
if (file_exists($configPath)) {
$config = require $configPath;
} elseif (file_exists($examplePath)) {
$config = require $examplePath;
} else {
throw new RuntimeException('Missing admin config.php (or config.example.php).');
}
}
return $config;
}
function admin_cfg(string $key, mixed $default = null): mixed
{
$config = admin_config();
return array_key_exists($key, $config) ? $config[$key] : $default;
}
function admin_start_session(): void
{
if (session_status() === PHP_SESSION_ACTIVE) {
return;
}
$secure = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
session_name((string) admin_cfg('session_name', 'oscar_admin'));
session_set_cookie_params([
'lifetime' => 0,
'path' => '/',
'secure' => $secure,
'httponly' => true,
'samesite' => 'Strict',
]);
session_start();
}
function h(string $value): string
{
return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
function admin_csrf_token(): string
{
admin_start_session();
if (empty($_SESSION['csrf'])) {
$_SESSION['csrf'] = bin2hex(random_bytes(32));
}
return $_SESSION['csrf'];
}
function admin_csrf_valid(?string $token): bool
{
admin_start_session();
return is_string($token)
&& isset($_SESSION['csrf'])
&& hash_equals($_SESSION['csrf'], $token);
}
function admin_normalize_screen_name(string $name): string
{
$name = trim($name);
$name = preg_replace('/\s+/', ' ', $name) ?? $name;
return strtolower($name);
}
function admin_is_allowed(string $screenName): bool
{
$normalized = admin_normalize_screen_name($screenName);
$allowed = admin_cfg('admin_users', []);
foreach ($allowed as $entry) {
if (admin_normalize_screen_name((string) $entry) === $normalized) {
return true;
}
}
return false;
}
function admin_mgmt_base(): string
{
$host = (string) admin_cfg('mgmt_api_host', '127.0.0.1');
$port = (int) admin_cfg('mgmt_api_port', 8080);
$host = trim($host);
if ($host === '') {
$host = '127.0.0.1';
}
if ($port < 1 || $port > 65535) {
$port = 8080;
}
return 'http://' . $host . ':' . $port;
}
function admin_api(string $method, string $path, ?array $body = null, array $query = []): array
{
$base = admin_mgmt_base();
$url = $base . $path;
if ($query !== []) {
$url .= '?' . http_build_query($query);
}
$ch = curl_init($url);
$headers = ['Accept: application/json'];
$payload = null;
if ($body !== null) {
$payload = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$headers[] = 'Content-Type: application/json';
}
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => strtoupper($method),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 15,
CURLOPT_CONNECTTIMEOUT => 5,
]);
if ($payload !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
}
$raw = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$err = curl_error($ch);
curl_close($ch);
if ($raw === false) {
return ['ok' => false, 'status' => 0, 'error' => $err ?: 'Request failed', 'data' => null, 'raw' => ''];
}
$decoded = json_decode($raw, true);
$ok = $status >= 200 && $status < 300;
return [
'ok' => $ok,
'status' => $status,
'error' => $ok ? null : (is_array($decoded) && isset($decoded['message']) ? (string) $decoded['message'] : ($raw !== '' ? $raw : 'HTTP ' . $status)),
'data' => $decoded,
'raw' => $raw,
];
}
function admin_send_im(string $to, string $text, bool $storeOffline = true): array
{
$from = trim((string) admin_cfg('system_screen_name', ''));
if ($from === '') {
return ['ok' => false, 'status' => 0, 'error' => 'System screen name is not configured', 'data' => null, 'raw' => ''];
}
return admin_api('POST', '/instant-message', [
'from' => $from,
'to' => $to,
'text' => $text,
'storeOffline' => $storeOffline,
]);
}
function admin_random_code(int $length = 8): string
{
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
$max = strlen($alphabet) - 1;
$out = '';
for ($i = 0; $i < $length; $i++) {
$out .= $alphabet[random_int(0, $max)];
}
return $out;
}
function admin_login_attempts_key(): string
{
return 'login_attempts';
}
function admin_login_throttled(): bool
{
admin_start_session();
$window = (int) admin_cfg('login_attempt_window_seconds', 900);
$max = (int) admin_cfg('max_login_attempts', 8);
$now = time();
$attempts = $_SESSION[admin_login_attempts_key()] ?? [];
if (!is_array($attempts)) {
$attempts = [];
}
$attempts = array_values(array_filter($attempts, fn($ts) => is_int($ts) && $ts >= ($now - $window)));
$_SESSION[admin_login_attempts_key()] = $attempts;
return count($attempts) >= $max;
}
function admin_record_login_failure(): void
{
admin_start_session();
$now = time();
$attempts = $_SESSION[admin_login_attempts_key()] ?? [];
if (!is_array($attempts)) {
$attempts = [];
}
$attempts[] = $now;
$_SESSION[admin_login_attempts_key()] = $attempts;
}
function admin_clear_login_failures(): void
{
admin_start_session();
unset($_SESSION[admin_login_attempts_key()]);
}
function admin_set_pending_login(string $screenName, string $code, string $delivery = 'oscar'): void
{
admin_start_session();
$ttl = (int) admin_cfg('login_code_ttl_seconds', 600);
$_SESSION['pending_login'] = [
'screen_name' => $screenName,
'normalized' => admin_normalize_screen_name($screenName),
'code_hash' => password_hash($code, PASSWORD_DEFAULT),
'expires_at' => time() + max(60, $ttl),
'delivery' => $delivery === 'gotify' ? 'gotify' : 'oscar',
];
}
function admin_pending_login(): ?array
{
admin_start_session();
$pending = $_SESSION['pending_login'] ?? null;
if (!is_array($pending)) {
return null;
}
if (($pending['expires_at'] ?? 0) < time()) {
unset($_SESSION['pending_login']);
return null;
}
return $pending;
}
function admin_clear_pending_login(): void
{
admin_start_session();
unset($_SESSION['pending_login']);
}
function admin_login_user(string $screenName): void
{
admin_start_session();
session_regenerate_id(true);
$_SESSION['admin_user'] = [
'screen_name' => $screenName,
'normalized' => admin_normalize_screen_name($screenName),
'logged_in_at' => time(),
];
admin_clear_pending_login();
admin_clear_login_failures();
}
function admin_current_user(): ?array
{
admin_start_session();
$user = $_SESSION['admin_user'] ?? null;
if (!is_array($user) || empty($user['screen_name'])) {
return null;
}
return $user;
}
function admin_require_login(): array
{
$user = admin_current_user();
if ($user === null) {
header('Location: login.php');
exit;
}
return $user;
}
function admin_logout(): void
{
admin_start_session();
$_SESSION = [];
if (ini_get('session.use_cookies')) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
session_destroy();
}
function admin_flash(string $type, string $message): void
{
admin_start_session();
$_SESSION['flash'][] = ['type' => $type, 'message' => $message];
}
function admin_flashes(): array
{
admin_start_session();
$flashes = $_SESSION['flash'] ?? [];
unset($_SESSION['flash']);
return is_array($flashes) ? $flashes : [];
}
function admin_json(array $payload, int $status = 200): never
{
http_response_code($status);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
function admin_redirect(string $url): never
{
header('Location: ' . $url);
exit;
}
function admin_page(string $title, string $active, callable $body): void
{
$user = admin_current_user();
$flashes = admin_flashes();
$site = (string) admin_cfg('site_name', 'Oscar Admin');
$shared = (string) admin_cfg('shared_style_path', 'assets/style.css');
$sharedHref = file_exists(__DIR__ . '/' . ltrim($shared, '/')) ? $shared : $shared;
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title><?= h($title) ?> - <?= h($site) ?></title>
<link rel="stylesheet" href="<?= h($sharedHref) ?>">
<link rel="stylesheet" href="admin.css">
</head>
<body class="admin-body">
<div class="bg-orb orb-a"></div>
<div class="bg-orb orb-b"></div>
<div class="bg-grid"></div>
<header class="admin-topbar">
<div class="admin-brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l7 3v5c0 5-3 7.5-7 10-4-2.5-7-5-7-10V6l7-3z"/><path d="M9 12l2 2 4-4"/></svg>
</div>
<div>
<div class="brand-title"><?= h($site) ?></div>
<div class="brand-sub">Open OSCAR control room</div>
</div>
</div>
<?php if ($user): ?>
<nav class="admin-nav" aria-label="Admin">
<a class="<?= $active === 'dashboard' ? 'active' : '' ?>" href="index.php">Dashboard</a>
<?php
$gotifyLib = __DIR__ . '/lib_gotify.php';
if (file_exists($gotifyLib) && !function_exists('admin_gotify_feature_enabled')) {
require_once $gotifyLib;
}
$menuFile = __DIR__ . '/user-menu.php';
if (file_exists($menuFile)) {
include $menuFile;
} else {
?>
<span class="nav-user" title="Signed in"><?= h((string) $user['screen_name']) ?></span>
<form method="post" action="logout.php" class="inline-form">
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
<button type="submit" class="btn btn-ghost btn-small">Logout</button>
</form>
<?php
}
?>
</nav>
<?php endif; ?>
</header>
<main class="admin-main">
<?php foreach ($flashes as $flash): ?>
<div class="flash flash-<?= h((string) ($flash['type'] ?? 'info')) ?>" role="status">
<?= h((string) ($flash['message'] ?? '')) ?>
</div>
<?php endforeach; ?>
<?php $body(); ?>
</main>
<script>
window.ADMIN_CSRF = <?= json_encode(admin_csrf_token(), JSON_UNESCAPED_SLASHES) ?>;
</script>
<script src="admin.js"></script>
</body>
</html>
<?php
}
/**
* Append a local audit entry (gitignored audit.log).
* Sensitive keys are scrubbed by callers where needed.
*/
function admin_audit(string $action, array $details = []): void
{
$file = __DIR__ . '/audit.log';
$user = admin_current_user();
$entry = [
'ts' => date('c'),
'user' => $user['screen_name'] ?? 'unknown',
'ip' => $_SERVER['REMOTE_ADDR'] ?? '',
'action' => $action,
'details' => $details,
];
@file_put_contents($file, json_encode($entry, JSON_UNESCAPED_SLASHES) . "\n", FILE_APPEND | LOCK_EX);
}
function admin_audit_read(int $limit = 200): array
{
$file = __DIR__ . '/audit.log';
if (!file_exists($file)) return [];
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (!$lines) return [];
$lines = array_slice($lines, -$limit);
$out = [];
foreach ($lines as $line) {
$decoded = json_decode($line, true);
if (is_array($decoded)) $out[] = $decoded;
}
return array_reverse($out);
}

195
lib_gotify.php Normal file
View file

@ -0,0 +1,195 @@
<?php
declare(strict_types=1);
/**
* Optional Gotify addon for Oscar Admin.
* 100% optional - the admin panel works without this file.
*
* Per-user settings are stored in gotify-users.php (gitignored).
* Global gotify_url/gotify_token in config are optional fallbacks.
*/
function admin_gotify_feature_enabled(): bool
{
if (!function_exists('admin_cfg')) return false;
return (bool) admin_cfg('gotify_enabled', false);
}
function admin_gotify_users_path(): string
{
return __DIR__ . '/gotify-users.php';
}
function admin_gotify_users_legacy_json_path(): string
{
return __DIR__ . '/gotify-users.json';
}
function admin_gotify_users_load(): array
{
$path = admin_gotify_users_path();
if (file_exists($path)) {
$data = @include $path;
return is_array($data) ? $data : [];
}
// One-time migration from legacy JSON if present.
$legacy = admin_gotify_users_legacy_json_path();
if (file_exists($legacy)) {
$raw = @file_get_contents($legacy);
$data = json_decode(is_string($raw) ? $raw : '', true);
if (is_array($data)) {
admin_gotify_users_save_all($data);
@unlink($legacy);
return $data;
}
}
return [];
}
function admin_gotify_users_save_all(array $data): bool
{
$path = admin_gotify_users_path();
$export = var_export($data, true);
$php = "<?php\ndeclare(strict_types=1);\n\n// Gotify per-user settings. Kept as PHP to avoid direct browser access.\nreturn " . $export . ";\n";
return @file_put_contents($path, $php, LOCK_EX) !== false;
}
function admin_gotify_user_get(string $screenName): ?array
{
if (!function_exists('admin_normalize_screen_name')) return null;
$key = admin_normalize_screen_name($screenName);
if ($key === '') return null;
$all = admin_gotify_users_load();
$row = $all[$key] ?? null;
if (!is_array($row)) return null;
$url = trim((string) ($row['url'] ?? ''));
$token = trim((string) ($row['token'] ?? ''));
if ($url === '' || $token === '') return null;
return [
'url' => $url,
'token' => $token,
'priority' => max(0, min(10, (int) ($row['priority'] ?? admin_cfg('gotify_priority', 5)))),
'updated_at' => (string) ($row['updated_at'] ?? ''),
];
}
function admin_gotify_user_save(string $screenName, string $url, string $token, ?int $priority = null): array
{
if (!function_exists('admin_normalize_screen_name')) {
return ['ok' => false, 'error' => 'Missing admin helpers.'];
}
$key = admin_normalize_screen_name($screenName);
if ($key === '') return ['ok' => false, 'error' => 'Invalid screen name.'];
$url = rtrim(trim($url), '/');
$token = trim($token);
$priority = $priority ?? (int) admin_cfg('gotify_priority', 5);
$priority = max(0, min(10, $priority));
$all = admin_gotify_users_load();
if ($url === '' || $token === '') {
unset($all[$key]);
$saved = admin_gotify_users_save_all($all);
return $saved ? ['ok' => true, 'cleared' => true] : ['ok' => false, 'error' => 'Failed to save Gotify settings.'];
}
// Basic validation
if (!preg_match('#^https?://#i', $url)) {
return ['ok' => false, 'error' => 'Gotify URL must start with http:// or https://'];
}
$all[$key] = [
'screen_name' => $screenName,
'url' => $url,
'token' => $token,
'priority' => $priority,
'updated_at' => date('c'),
];
$saved = admin_gotify_users_save_all($all);
return $saved ? ['ok' => true, 'cleared' => false] : ['ok' => false, 'error' => 'Failed to save Gotify settings.'];
}
function admin_gotify_resolve(string $screenName): ?array
{
$user = admin_gotify_user_get($screenName);
if ($user) return $user;
// Optional global fallback
$url = rtrim(trim((string) admin_cfg('gotify_url', '')), '/');
$token = trim((string) admin_cfg('gotify_token', ''));
if ($url !== '' && $token !== '') {
return [
'url' => $url,
'token' => $token,
'priority' => max(0, min(10, (int) admin_cfg('gotify_priority', 5))),
'updated_at' => '',
'fallback' => true,
];
}
return null;
}
function admin_gotify_enabled(): bool
{
// Back-compat alias: feature toggle (not "is configured for a specific user").
return admin_gotify_feature_enabled();
}
function admin_gotify_send(string $title, string $message, ?int $priority = null, ?string $url = null, ?string $token = null): array
{
if (!admin_gotify_feature_enabled()) {
return ['ok' => false, 'status' => 0, 'error' => 'Gotify is not enabled', 'data' => null, 'raw' => ''];
}
$url = rtrim(trim((string) ($url ?? admin_cfg('gotify_url', ''))), '/');
$token = trim((string) ($token ?? admin_cfg('gotify_token', '')));
if ($url === '' || $token === '') {
return ['ok' => false, 'status' => 0, 'error' => 'Gotify is not configured', 'data' => null, 'raw' => ''];
}
$priority = $priority ?? (int) admin_cfg('gotify_priority', 5);
$priority = max(0, min(10, $priority));
$endpoint = $url . '/message?token=' . rawurlencode($token);
$payload = json_encode([
'title' => $title,
'message' => $message,
'priority' => $priority,
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json; charset=utf-8', 'Accept: application/json'],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
]);
$raw = curl_exec($ch);
$status = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$err = curl_error($ch);
curl_close($ch);
if ($raw === false) {
return ['ok' => false, 'status' => 0, 'error' => $err ?: 'Gotify request failed', 'data' => null, 'raw' => ''];
}
$decoded = json_decode($raw, true);
$ok = $status >= 200 && $status < 300;
return [
'ok' => $ok,
'status' => $status,
'error' => $ok ? null : (is_array($decoded) && isset($decoded['errorDescription']) ? (string) $decoded['errorDescription'] : ($raw !== '' ? $raw : 'HTTP ' . $status)),
'data' => $decoded,
'raw' => $raw,
];
}
function admin_gotify_send_for_user(string $screenName, string $title, string $message, ?int $priority = null): array
{
$cfg = admin_gotify_resolve($screenName);
if (!$cfg) {
return ['ok' => false, 'status' => 0, 'error' => 'No Gotify configuration for this user', 'data' => null, 'raw' => ''];
}
return admin_gotify_send($title, $message, $priority ?? $cfg['priority'], $cfg['url'], $cfg['token']);
}

292
login.php Normal file
View file

@ -0,0 +1,292 @@
<?php
declare(strict_types=1);
/**
* Admin login page.
*
* Flow:
* 1) User enters OSCAR screen name + solves math anti-spam challenge.
* 2) Server sends one-time code via OSCAR IM, or via Gotify if that screen
* name has a personal Gotify config (Gotify addon is optional).
* 3) User verifies code and gets an admin session.
*
* Security/anti-enumeration:
* - Same UI flow for allowed and non-allowed screen names.
* - Non-allowed names get a random funny denial IM/notification, but the page
* still shows the normal "code sent" / verify flow with a fake pending code.
* - Session-based throttling limits brute force/spam.
*/
require_once __DIR__ . '/lib.php';
$gotifyLib = __DIR__ . '/lib_gotify.php';
if (file_exists($gotifyLib)) {
require_once $gotifyLib;
}
admin_start_session();
if (admin_current_user() !== null) {
admin_redirect('index.php');
}
function admin_login_math_new(): array
{
$a = random_int(2, 15);
$b = random_int(1, 12);
$ops = ['+', '-', '×'];
$op = $ops[array_rand($ops)];
if ($op === '-') {
if ($b > $a) { [$a, $b] = [$b, $a]; }
$answer = $a - $b;
} elseif ($op === '×') {
$a = random_int(2, 9);
$b = random_int(2, 9);
$answer = $a * $b;
} else {
$answer = $a + $b;
}
$_SESSION['login_math'] = [
'q' => "What is {$a} {$op} {$b}?",
'a' => (string) $answer,
't' => time(),
];
return $_SESSION['login_math'];
}
function admin_login_math_get(): array
{
$m = $_SESSION['login_math'] ?? null;
if (!is_array($m) || empty($m['q']) || !isset($m['a'])) {
return admin_login_math_new();
}
// Refresh stale challenges.
if (time() - (int) ($m['t'] ?? 0) > 900) {
return admin_login_math_new();
}
return $m;
}
function admin_login_math_check(?string $answer): bool
{
$m = admin_login_math_get();
$ok = is_string($answer) && trim($answer) !== '' && hash_equals((string) $m['a'], trim($answer));
// One attempt per challenge.
admin_login_math_new();
return $ok;
}
$error = '';
$notice = '';
$pending = admin_pending_login();
$stage = $pending ? 'verify' : 'request';
$math = admin_login_math_get();
$gotifyEnabled = function_exists('admin_gotify_enabled') && admin_gotify_enabled();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!admin_csrf_valid($_POST['csrf'] ?? null)) {
$error = 'Security check failed. Please try again.';
} elseif (admin_login_throttled()) {
$error = 'Too many login attempts. Take a breather and try again later.';
} else {
$action = (string) ($_POST['action'] ?? '');
if ($action === 'request_code') {
$screenName = trim((string) ($_POST['screen_name'] ?? ''));
$mathAnswer = (string) ($_POST['math_answer'] ?? '');
$delivery = 'oscar';
if ($gotifyEnabled && function_exists('admin_gotify_resolve')) {
$gcfg = admin_gotify_resolve($screenName);
if ($gcfg) {
$delivery = 'gotify';
}
}
if (!admin_login_math_check($mathAnswer)) {
admin_record_login_failure();
$error = 'Math check failed. Try again (robots are notoriously bad at this).';
$math = admin_login_math_get();
} elseif ($screenName === '' || strlen($screenName) > 64) {
$error = 'Enter your OSCAR screen name.';
$math = admin_login_math_get();
} elseif (!admin_is_allowed($screenName)) {
admin_record_login_failure();
$funny = [
"Nice try, {$screenName}. This admin panel is members-only, and the velvet rope just laughed at you.",
"Access denied. The admin hamsters held an emergency meeting and voted you 'not it'.",
"Whoa there, keyboard cowboy. You're not on the admin list. The server has filed your request under 'bold, but no'.",
"Nope. You're not an admin. Please return your imaginary badge at the nearest imaginary desk.",
"The OSCAR server checked the VIP list twice. You are on neither list. It also asked me to tell you to get lost, politely-ish.",
"Error 403: You lack the ancient admin runes. The control room door remains unimpressed.",
"Sorry {$screenName}, this dashboard runs on admin juice, and your cup is empty.",
"The admin council consulted the sacred spreadsheet. Your name was not there. It was a short meeting.",
"You have reached the admin panel. Unfortunately, the admin panel has not reached you back.",
"Bold move. Wrong permissions. The server admires the confidence, but not enough to let you in.",
"Access denied. I asked the mainframe, and it said 'lol no' with surprising professionalism.",
"This area is for admins only. You are currently in the 'very enthusiastic spectator' category.",
"The bouncer checked your name, checked it again, then checked the vibes. All three said no.",
"You must be this admin to ride this dashboard. You are currently several admins short.",
"The keys to the control room are guarded by a dragon. The dragon says you may not pass.",
];
$msg = $funny[array_rand($funny)];
// Best effort: notify via selected channel. Failure is intentionally silent to avoid leaking details.
if ($delivery === 'gotify' && function_exists('admin_gotify_send_for_user')) {
$gcfg = admin_gotify_resolve($screenName);
if ($gcfg) {
admin_gotify_send_for_user($screenName, 'Oscar Admin login denied', $msg);
}
// If no gotify config, silently skip send but keep same UI.
} else {
admin_send_im($screenName, $msg, true);
}
// Behave identically to a successful send to avoid account enumeration.
$fakeCode = admin_random_code((int) admin_cfg('login_code_length', 8));
admin_set_pending_login($screenName, $fakeCode, $delivery);
$pending = admin_pending_login();
$stage = 'verify';
$notice = $delivery === 'gotify'
? 'Login code sent via Gotify. Check your Gotify notifications.'
: 'Login code sent to ' . $screenName . ' on OSCAR. Check your IMs.';
} else {
$code = admin_random_code((int) admin_cfg('login_code_length', 8));
$text = "Oscar Admin login code for {$screenName}: {$code}\nThis code expires in " . (int) admin_cfg('login_code_ttl_seconds', 600) . " seconds. If you didn't request it, ignore this message.";
$send = ['ok' => false, 'error' => 'Delivery failed'];
if ($delivery === 'gotify' && function_exists('admin_gotify_send_for_user')) {
$gcfg = function_exists('admin_gotify_resolve') ? admin_gotify_resolve($screenName) : null;
if ($gcfg) {
$send = admin_gotify_send_for_user($screenName, 'Oscar Admin login code', $text);
} else {
// No personal/global gotify config - fake success UI to avoid enumeration, but no code is sent.
// Legit admins must configure Gotify in dashboard first.
$send = ['ok' => true, 'status' => 0, 'error' => null, 'data' => null, 'raw' => ''];
}
} else {
$send = admin_send_im($screenName, $text, true);
}
if (!$send['ok']) {
admin_record_login_failure();
$error = $delivery === 'gotify'
? 'Could not send a login code via Gotify right now. Check Gotify settings.'
: 'Could not send a login code via OSCAR right now. Check the system account and management API config.';
$math = admin_login_math_get();
} else {
admin_set_pending_login($screenName, $code, $delivery);
$pending = admin_pending_login();
$stage = 'verify';
$notice = $delivery === 'gotify'
? 'Login code sent via Gotify. Check your Gotify notifications.'
: 'Login code sent to ' . $screenName . ' on OSCAR. Check your IMs.';
}
}
} elseif ($action === 'verify_code') {
$pending = admin_pending_login();
$code = trim((string) ($_POST['code'] ?? ''));
if (!$pending) {
$error = 'Your login code expired. Request a new one.';
$stage = 'request';
} elseif ($code === '') {
$error = 'Enter the login code you received on OSCAR.';
$stage = 'verify';
} elseif (!password_verify($code, (string) $pending['code_hash'])) {
admin_record_login_failure();
$error = 'That code is not right. The OSCAR gods remain unimpressed.';
$stage = 'verify';
// After several failures, clear pending.
$attempts = $_SESSION['login_attempts'] ?? [];
if (is_array($attempts) && count($attempts) >= (int) admin_cfg('max_login_attempts', 8)) {
admin_clear_pending_login();
$stage = 'request';
}
} else {
$name = (string) $pending['screen_name'];
if (!admin_is_allowed($name)) {
// Treat as invalid to avoid account/enumeration leaks.
admin_record_login_failure();
$error = 'That code is not right. The OSCAR gods remain unimpressed.';
$stage = 'verify';
$attempts = $_SESSION['login_attempts'] ?? [];
if (is_array($attempts) && count($attempts) >= (int) admin_cfg('max_login_attempts', 8)) {
admin_clear_pending_login();
$stage = 'request';
}
} else {
admin_login_user($name);
admin_flash('success', 'Welcome back, ' . $name . '. The control room is yours.');
admin_redirect('index.php');
}
}
} elseif ($action === 'reset') {
admin_clear_pending_login();
$pending = null;
$stage = 'request';
$notice = 'Login reset. Start fresh.';
} else {
$error = 'Unknown action.';
}
}
}
admin_page('Login', 'login', function () use ($error, $notice, $pending, $stage, $math, $gotifyEnabled): void {
?>
<section class="auth-wrap">
<div class="auth-card card reveal">
<div class="auth-head">
<div class="eyebrow">Secure sign-in</div>
<h1>Admin access</h1>
<p class="muted">Sign in with your OSCAR screen name. We'll send a one-time code through <?= !empty($gotifyEnabled) ? 'OSCAR or Gotify' : 'the OSCAR server' ?>.</p>
</div>
<?php if ($error): ?>
<div class="flash flash-error" role="alert"><?= h($error) ?></div>
<?php endif; ?>
<?php if ($notice): ?>
<div class="flash flash-success" role="status"><?= h($notice) ?></div>
<?php endif; ?>
<?php if ($stage === 'verify' && $pending): ?>
<div class="pending-box">
<div class="pending-label">Code sent via <?= h(((string)($pending['delivery'] ?? 'oscar')) === 'gotify' ? 'Gotify' : 'OSCAR IM') ?></div>
<div class="pending-name"><?= h((string) $pending['screen_name']) ?></div>
<div class="pending-expiry muted">Expires in <?= h((string) max(0, (int) $pending['expires_at'] - time())) ?>s</div>
</div>
<form method="post" class="stack-form">
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
<input type="hidden" name="action" value="verify_code">
<label class="field">
<span>Login code</span>
<input type="text" name="code" autocomplete="one-time-code" inputmode="text" maxlength="32" required placeholder="Enter login code">
</label>
<button type="submit" class="btn btn-primary btn-block">Verify &amp; enter</button>
</form>
<form method="post" class="reset-row">
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
<input type="hidden" name="action" value="reset">
<button type="submit" class="btn btn-ghost btn-small">Use a different screen name</button>
</form>
<?php else: ?>
<form method="post" class="stack-form">
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
<input type="hidden" name="action" value="request_code">
<label class="field">
<span>OSCAR screen name</span>
<input type="text" name="screen_name" autocomplete="username" maxlength="64" required placeholder="your screen name">
</label>
<label class="field">
<span>Anti-spam check: <?= h((string) ($math['q'] ?? 'What is 1 + 1?')) ?></span>
<input type="text" name="math_answer" inputmode="numeric" autocomplete="off" required placeholder="Answer">
</label>
<button type="submit" class="btn btn-primary btn-block">Send login code</button>
</form>
<?php endif; ?>
</div>
<div class="auth-side reveal delay-1">
<div class="side-card">
<h2>How it works</h2>
<ol class="step-list">
<li><span class="step-num">1</span><div><strong>Enter your screen name</strong><p class="muted">The one configured as an admin.</p></div></li>
<li><span class="step-num">2</span><div><strong>Get your code</strong><p class="muted"><?= !empty($gotifyEnabled) ? 'Receive it via OSCAR IM or Gotify.' : 'The system account sends your one-time code via OSCAR IM.' ?></p></div></li>
<li><span class="step-num">3</span><div><strong>Verify and manage</strong><p class="muted">Access the full admin dashboard.</p></div></li>
</ol>
</div>
</div>
</section>
<?php
});

13
logout.php Normal file
View file

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
/**
* Admin logout endpoint (POST + CSRF).
*/
require_once __DIR__ . '/lib.php';
admin_start_session();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && admin_csrf_valid($_POST['csrf'] ?? null)) {
admin_logout();
}
admin_redirect('login.php');

108
user-menu.php Normal file
View file

@ -0,0 +1,108 @@
<?php
// User menu dropdown - own file. Included by admin_page() when user is logged in.
if (!isset($user) || !is_array($user)) return;
$sn = (string) ($user['screen_name'] ?? '');
$gotifyAvailable = function_exists('admin_gotify_feature_enabled') && admin_gotify_feature_enabled();
if (!$gotifyAvailable) {
?>
<span class="nav-user" title="Signed in"><?= h((string) $user['screen_name']) ?></span>
<form method="post" action="logout.php" class="inline-form">
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
<button type="submit" class="btn btn-ghost btn-small">Logout</button>
</form>
<?php
return;
}
?>
<div class="user-menu" id="user-menu">
<button type="button" class="nav-user user-menu-trigger" id="user-menu-trigger" aria-haspopup="menu" aria-expanded="false">
<span><?= h($sn) ?></span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>
</button>
<div class="user-menu-dropdown" id="user-menu-dropdown" role="menu" hidden>
<div class="user-menu-head">
<div class="user-menu-name"><?= h($sn) ?></div>
<div class="muted small">Signed in</div>
</div>
<div class="user-menu-section">
<div class="user-menu-section-title">Gotify notifications <span class="tip" tabindex="0" data-tip="Optional: receive login codes via your personal Gotify server. Useful if you can't access AIM/ICQ. If a Gotify URL and token are saved, login codes will be sent to Gotify. To turn it off, clear the settings.">?</span></div>
<form id="gotify-self-form" class="stack-form compact">
<label class="field"><span>Gotify URL</span><input name="url" id="gotify-self-url" type="url" placeholder="https://gotify.example.com" autocomplete="off"></label>
<label class="field"><span>App token <span class="tip" tabindex="0" data-tip="Gotify application token. Saved token is not shown again; re-enter to replace it.">?</span></span><input name="token" id="gotify-self-token" type="password" placeholder="Token" autocomplete="off"></label>
<label class="field"><span>Priority</span><input name="priority" id="gotify-self-priority" type="number" min="0" max="10" value="5"></label>
<div class="field-row" style="flex-wrap:nowrap">
<button type="submit" class="btn btn-primary btn-small">Save</button>
<button type="button" class="btn btn-ghost btn-small" id="gotify-self-test">Test</button>
<button type="button" class="btn btn-ghost btn-small" id="gotify-self-clear">Clear</button>
</div>
<div id="gotify-self-status" class="muted small"></div>
</form>
</div>
<div class="user-menu-section user-menu-actions">
<form method="post" action="logout.php" class="inline-form">
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
<button type="submit" class="btn btn-ghost btn-small btn-block">Logout</button>
</form>
</div>
</div>
</div>
<script>
(function(){
const trigger = document.getElementById('user-menu-trigger');
const menu = document.getElementById('user-menu-dropdown');
if (!trigger || !menu) return;
function close(){ menu.hidden = true; trigger.setAttribute('aria-expanded','false'); }
function open(){ menu.hidden = false; trigger.setAttribute('aria-expanded','true'); }
trigger.addEventListener('click', function(e){ e.stopPropagation(); menu.hidden ? open() : close(); });
document.addEventListener('click', function(e){ if (!menu.hidden && !e.target.closest('#user-menu')) close(); });
document.addEventListener('keydown', function(e){ if (e.key === 'Escape') close(); });
const form = document.getElementById('gotify-self-form');
if (!form) return;
const status = document.getElementById('gotify-self-status');
const urlIn = document.getElementById('gotify-self-url');
const tokenIn = document.getElementById('gotify-self-token');
const prioIn = document.getElementById('gotify-self-priority');
async function api(action, payload) {
const r = await fetch('action.php', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(Object.assign({action, csrf: window.ADMIN_CSRF}, payload||{}))});
return r.json().catch(() => ({ok:false,error:'Bad response'}));
}
async function load() {
status.textContent = 'Loading...';
const r = await api('gotify.self.get');
if (r.ok && r.data) {
urlIn.value = r.data.url || '';
tokenIn.value = '';
tokenIn.placeholder = r.data.token_set ? 'Token set (re-enter to change)' : 'Token';
prioIn.value = r.data.priority ?? 5;
status.textContent = r.data.configured ? 'Gotify configured for your account.' : 'No personal Gotify configured yet.';
form.dataset.tokenSet = r.data.token_set ? '1' : '';
} else {
status.textContent = r.error || 'Failed to load.';
}
}
form.addEventListener('submit', async function(e){
e.preventDefault();
status.textContent = 'Saving...';
const payload = {url: urlIn.value.trim(), token: tokenIn.value, priority: parseInt(prioIn.value||'5',10)};
const r = await api('gotify.self.save', payload);
status.textContent = r.ok ? (r.data?.cleared ? 'Gotify settings cleared.' : 'Saved.') : (r.error || 'Save failed');
if (r.ok) { tokenIn.value = ''; await load(); }
});
document.getElementById('gotify-self-test')?.addEventListener('click', async function(){
status.textContent = 'Sending test notification...';
const r = await api('gotify.self.test');
status.textContent = r.ok ? 'Test notification sent.' : (r.error || 'Test failed');
});
document.getElementById('gotify-self-clear')?.addEventListener('click', async function(){
if (!confirm('Clear your Gotify settings?')) return;
const r = await api('gotify.self.save', {url:'', token:'', priority:5});
status.textContent = r.ok ? 'Cleared.' : (r.error || 'Failed');
if (r.ok) await load();
});
trigger.addEventListener('click', function(){ if (!menu.hidden) load(); });
})();
</script>