Menu="OtherSettings" Icon="icon.svg" Title="Fluxer" --- = 2 && $value[0] === "'" && substr($value, -1) === "'") { return str_replace("'\\''", "'", substr($value, 1, -1)); } return $value; } function fluxer_defaults(): array { return [ 'DOMAIN' => '', 'MODE' => 'proxy', 'APPDATA' => '/mnt/user/appdata/fluxer', 'STACK' => '/mnt/user/appdata/fluxer/stack', ]; } function fluxer_read_cfg(string $file): array { $cfg = fluxer_defaults(); if (!is_file($file)) { return $cfg; } foreach (file($file, FILE_IGNORE_NEW_LINES) as $line) { if (!str_contains($line, '=')) { continue; } [$key, $value] = explode('=', $line, 2); if (array_key_exists($key, $cfg)) { $cfg[$key] = fluxer_unquote($value); } } return $cfg; } function fluxer_valid_domain(string $domain): bool { return (bool) preg_match('/^[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$/', $domain); } function fluxer_valid_path(string $path): bool { return str_starts_with($path, '/mnt/') && !str_contains($path, '..') && !str_starts_with($path, '/boot'); } function fluxer_write_cfg(string $file, array $cfg): void { $dir = dirname($file); if (!is_dir($dir)) { mkdir($dir, 0700, true); } $body = ''; foreach (['DOMAIN', 'MODE', 'APPDATA', 'STACK'] as $key) { $body .= $key . '=' . fluxer_quote($cfg[$key]) . "\n"; } $tmp = $file . '.tmp'; file_put_contents($tmp, $body); rename($tmp, $file); } function fluxer_post_ok(): bool { if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') { return false; } $expected = $_SESSION['csrf_token'] ?? ''; if ($expected === '') { return true; } $got = $_POST['csrf_token'] ?? ''; return is_string($got) && hash_equals($expected, $got); } function fluxer_setup_token(string $env_file): string { if (!is_file($env_file)) { return ''; } foreach (file($env_file, FILE_IGNORE_NEW_LINES) as $line) { if (str_starts_with($line, 'FLUXER_SETUP_TOKEN=')) { return substr($line, strlen('FLUXER_SETUP_TOKEN=')); } } return ''; } $cfg = fluxer_read_cfg($cfg_file); $notice = ''; $error = ''; $token = ''; $action = $_POST['action'] ?? ''; if ($action !== '' && !fluxer_post_ok()) { $error = 'The form expired. Reload the page and try again.'; $action = ''; } if ($action === 'Save' || $action === 'Start' || $action === 'Show token') { $cfg['DOMAIN'] = trim($_POST['domain'] ?? ''); $cfg['MODE'] = trim($_POST['mode'] ?? 'proxy'); $cfg['APPDATA'] = trim($_POST['appdata'] ?? $cfg['APPDATA']); $cfg['STACK'] = trim($_POST['stack'] ?? $cfg['STACK']); if (($action === 'Start' || $cfg['DOMAIN'] !== '') && !fluxer_valid_domain($cfg['DOMAIN'])) { $error = 'Domain must be a hostname such as chat.example.com, with no https:// and no path.'; } elseif ($cfg['MODE'] !== 'proxy' && $cfg['MODE'] !== 'direct') { $error = 'Mode must be proxy or direct.'; } elseif (!fluxer_valid_path($cfg['APPDATA']) || !fluxer_valid_path($cfg['STACK'])) { $error = 'Data and stack paths must stay under /mnt and off the USB flash drive.'; } else { fluxer_write_cfg($cfg_file, $cfg); $notice = 'Saved.'; } } if ($error === '' && $action === 'Start') { $cmd = 'nohup /bin/bash ' . escapeshellarg($plugin_scripts . '/start.sh') . ' >/dev/null 2>&1 &'; exec($cmd); $notice = 'Start is running. The first image download takes several minutes. Refresh this page for the log.'; } if ($error === '' && $action === 'Stop') { $cmd = 'nohup /bin/bash ' . escapeshellarg($plugin_scripts . '/stop.sh') . ' >/dev/null 2>&1 &'; exec($cmd); $notice = 'Stop is running. Refresh this page for the log. Data is kept.'; } if ($error === '' && $action === 'Show token') { $token = fluxer_setup_token($cfg['STACK'] . '/.env'); if ($token === '') { $error = 'No setup token yet. Start Fluxer once, then show the token again.'; } } $csrf = $_SESSION['csrf_token'] ?? ''; $ps = ''; if (is_file($cfg['STACK'] . '/docker-compose.yml')) { $lines = []; exec('docker compose --project-directory ' . escapeshellarg($cfg['STACK']) . ' ps 2>&1', $lines); $ps = implode("\n", $lines); } $log = ''; if (is_file($log_file)) { $all = file($log_file, FILE_IGNORE_NEW_LINES); $log = implode("\n", array_slice($all, -40)); } ?>
Setup token. It is also FLUXER_SETUP_TOKEN in the stack .env. Copy the .env file somewhere safe before you rely on this server.
=htmlspecialchars($token, ENT_QUOTES)?>
Public address: https://=htmlspecialchars($cfg['DOMAIN'], ENT_QUOTES)?>
=htmlspecialchars($ps !== '' ? $ps : 'Not started yet.', ENT_QUOTES)?>
=htmlspecialchars($log !== '' ? $log : 'No log yet.', ENT_QUOTES)?>