This commit is contained in:
riglen
2026-04-20 14:16:09 +08:00
parent ee9cc6f429
commit 564042a8cc
14 changed files with 1401 additions and 86 deletions

136
templates/base.html Normal file
View File

@@ -0,0 +1,136 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>sub-provider admin</title>
<style>
:root {
--bg: #f3efe6;
--panel: #fffdf8;
--ink: #1f2a2e;
--muted: #66757f;
--line: #d7ccbb;
--accent: #b8542a;
--accent-soft: #f0d7c5;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: "Segoe UI", "PingFang SC", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at top left, #f7d9c5, transparent 28%),
radial-gradient(circle at bottom right, #dce8da, transparent 22%),
var(--bg);
}
a { color: inherit; }
.shell {
max-width: 1320px;
margin: 0 auto;
padding: 24px;
display: grid;
grid-template-columns: 240px minmax(0, 1fr);
gap: 24px;
}
.nav, .panel {
background: rgba(255, 253, 248, 0.92);
backdrop-filter: blur(10px);
border: 1px solid var(--line);
border-radius: 24px;
box-shadow: 0 20px 40px rgba(31, 42, 46, 0.08);
}
.nav { padding: 18px; align-self: start; position: sticky; top: 18px; }
.brand { font-size: 24px; font-weight: 700; margin-bottom: 20px; }
.nav a {
display: block;
text-decoration: none;
padding: 10px 12px;
border-radius: 12px;
margin-bottom: 8px;
}
.nav a.active {
background: var(--accent);
color: #fff;
}
.nav form { margin-top: 18px; }
.panel { padding: 24px; }
h1, h2 { margin-top: 0; }
.muted { color: var(--muted); }
.stack { display: grid; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card {
border: 1px solid var(--line);
border-radius: 18px;
padding: 18px;
background: var(--panel);
}
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
width: 100%;
padding: 10px 12px;
border-radius: 12px;
border: 1px solid var(--line);
background: #fff;
color: var(--ink);
}
textarea { min-height: 140px; resize: vertical; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
button, .button {
border: 0;
border-radius: 999px;
padding: 10px 16px;
font-weight: 600;
cursor: pointer;
background: var(--accent);
color: #fff;
text-decoration: none;
display: inline-block;
}
.button.secondary, button.secondary {
background: var(--accent-soft);
color: var(--ink);
}
.flash {
padding: 12px 14px;
border-radius: 14px;
border: 1px solid var(--line);
margin-bottom: 18px;
}
.flash.success { background: #e8f3e6; border-color: #b7d3b1; }
.flash.error { background: #f7dfdb; border-color: #ddb0a7; }
.inline { display: inline-flex; align-items: center; gap: 8px; }
.wide { width: 100%; min-height: 65vh; font-family: Consolas, monospace; }
@media (max-width: 920px) {
.shell { grid-template-columns: 1fr; }
.nav { position: static; }
.grid-2 { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="shell">
<nav class="nav">
<div class="brand">sub-provider</div>
{% if authenticated %}
<a href="/admin/sources" class="{% if active == 'sources' %}active{% endif %}">Sources</a>
<a href="/admin/profiles" class="{% if active == 'profiles' %}active{% endif %}">Profiles</a>
{% if auth_enabled %}
<form method="post" action="/admin/logout">
<button type="submit" class="secondary" style="width:100%;">Logout</button>
</form>
{% endif %}
{% endif %}
</nav>
<main class="panel">
{% if flash %}
<div class="flash {{ flash.level }}">{{ flash.message }}</div>
{% endif %}
{% block content %}{% endblock %}
</main>
</div>
</body>
</html>

126
templates/groups.html Normal file
View File

@@ -0,0 +1,126 @@
{% extends "base.html" %}
{% block content %}
<div class="stack">
<div class="actions" style="justify-content:space-between; align-items:center;">
<div>
<h1>Groups: {{ profile_key }}</h1>
<p class="muted">管理 region / selector / policy groups。当前版本以整表提交为主。</p>
</div>
<div class="actions">
<a class="button secondary" href="/admin/profiles">Back</a>
<a class="button" href="/admin/profiles/{{ profile_key }}/preview">Preview</a>
</div>
</div>
<form method="post" action="/admin/profiles/{{ profile_key }}/groups" class="stack">
{% for group in groups %}
<div class="card">
<input type="hidden" name="group_id" value="{{ group.id }}">
<div class="grid-2">
<div>
<label>Name</label>
<input name="group_name_{{ loop.index0 }}" value="{{ group.name }}">
</div>
<div>
<label>Kind</label>
<select name="group_kind_{{ loop.index0 }}">
<option value="region" {% if group.group_kind == 'region' %}selected{% endif %}>region</option>
<option value="selector" {% if group.group_kind == 'selector' %}selected{% endif %}>selector</option>
<option value="policy" {% if group.group_kind == 'policy' %}selected{% endif %}>policy</option>
</select>
</div>
<div>
<label>Type</label>
<select name="type_{{ loop.index0 }}">
<option value="select" {% if group.type == 'select' %}selected{% endif %}>select</option>
<option value="url-test" {% if group.type == 'url-test' %}selected{% endif %}>url-test</option>
</select>
</div>
<div>
<label>Order</label>
<input name="order_index_{{ loop.index0 }}" value="{{ group.order_index }}">
</div>
<div>
<label>Filter Regex</label>
<input name="filter_regex_{{ loop.index0 }}" value="{{ group.filter_regex }}">
</div>
<div>
<label>Tolerance</label>
<input name="tolerance_{{ loop.index0 }}" value="{{ group.tolerance or '' }}">
</div>
<div>
<label>URL</label>
<input name="url_{{ loop.index0 }}" value="{{ group.url }}">
</div>
<div>
<label>Interval</label>
<input name="interval_{{ loop.index0 }}" value="{{ group.interval or '' }}">
</div>
</div>
<div style="margin-top:12px;">
<label>Proxies / Tokens</label>
<textarea name="proxies_{{ loop.index0 }}">{% for item in group.proxies %}{{ item }}{% if not loop.last %}
{% endif %}{% endfor %}</textarea>
</div>
<div class="actions" style="margin-top:12px;">
<label class="inline"><input type="checkbox" name="enabled_{{ loop.index0 }}" {% if group.enabled %}checked{% endif %} style="width:auto"> Enabled</label>
<label class="inline"><input type="checkbox" name="delete_{{ loop.index0 }}" style="width:auto"> Delete</label>
</div>
</div>
{% endfor %}
<div class="card">
<h2>New Group</h2>
<div class="grid-2">
<div>
<label>Name</label>
<input name="new_group_name" placeholder="🤖 AI">
</div>
<div>
<label>Kind</label>
<select name="new_group_kind">
<option value="policy">policy</option>
<option value="selector">selector</option>
<option value="region">region</option>
</select>
</div>
<div>
<label>Type</label>
<select name="new_group_type">
<option value="select">select</option>
<option value="url-test">url-test</option>
</select>
</div>
<div>
<label>Order</label>
<input name="new_group_order_index" placeholder="{{ groups|length }}">
</div>
<div>
<label>Filter Regex</label>
<input name="new_group_filter_regex">
</div>
<div>
<label>Tolerance</label>
<input name="new_group_tolerance">
</div>
<div>
<label>URL</label>
<input name="new_group_url">
</div>
<div>
<label>Interval</label>
<input name="new_group_interval">
</div>
</div>
<div style="margin-top:12px;">
<label>Proxies / Tokens</label>
<textarea name="new_group_proxies"></textarea>
</div>
<label class="inline" style="margin-top:12px;"><input type="checkbox" name="new_group_enabled" checked style="width:auto"> Enabled</label>
</div>
<div class="actions">
<button type="submit">Save Groups</button>
</div>
</form>
</div>
{% endblock %}

73
templates/login.html Normal file
View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>sub-provider login</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: "Segoe UI", "PingFang SC", sans-serif;
background:
radial-gradient(circle at top left, #f7d9c5, transparent 28%),
radial-gradient(circle at bottom right, #dce8da, transparent 22%),
#f3efe6;
color: #1f2a2e;
}
.card {
width: min(420px, calc(100vw - 32px));
background: rgba(255,253,248,0.95);
border: 1px solid #d7ccbb;
border-radius: 24px;
padding: 28px;
box-shadow: 0 20px 40px rgba(31,42,46,0.08);
}
h1 { margin-top: 0; }
label { display:block; margin-bottom: 6px; color:#66757f; font-size: 13px; }
input {
width:100%;
padding: 12px;
border-radius: 12px;
border: 1px solid #d7ccbb;
box-sizing: border-box;
}
button {
margin-top: 16px;
width: 100%;
border: 0;
border-radius: 999px;
padding: 12px 16px;
background: #b8542a;
color: #fff;
font-weight: 600;
cursor: pointer;
}
.muted { color:#66757f; }
.flash {
padding: 12px 14px;
border-radius: 14px;
border: 1px solid #ddb0a7;
background: #f7dfdb;
margin-bottom: 18px;
}
</style>
</head>
<body>
<div class="card">
<h1>Admin Login</h1>
<p class="muted">输入 `.env` 中配置的 `ADMIN_TOKEN`。</p>
{% if flash %}
<div class="flash">{{ flash.message }}</div>
{% endif %}
<form method="post" action="/admin/login">
<input type="hidden" name="next" value="{{ next }}">
<label>Token</label>
<input type="password" name="token" autofocus>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>

31
templates/preview.html Normal file
View File

@@ -0,0 +1,31 @@
{% extends "base.html" %}
{% block content %}
<div class="stack">
<div class="actions" style="justify-content:space-between; align-items:center;">
<div>
<h1>Preview: {{ profile_key }}</h1>
<p class="muted">预览 profile 当前生成的完整 bundle YAML。</p>
</div>
<div class="actions">
<a class="button secondary" href="/admin/profiles/{{ profile_key }}/rules">Rules</a>
<a class="button" href="/admin/profiles">Profiles</a>
</div>
</div>
<div class="card">
<form method="get" action="/admin/profiles/{{ profile_key }}/preview" class="stack">
<div>
<label>Sources (comma separated)</label>
<input name="sources" value="{{ selected_sources|join(',') }}" placeholder="{{ available_sources|join(',') }}">
</div>
<div class="actions">
<button type="submit">Refresh Preview</button>
</div>
</form>
</div>
<div class="card">
<textarea class="wide" readonly>{{ yaml_text }}</textarea>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,40 @@
{% extends "base.html" %}
{% block content %}
<div class="stack">
<div class="actions" style="justify-content:space-between; align-items:center;">
<div>
<h1>Profile Sources: {{ profile_key }}</h1>
<p class="muted">配置 profile 默认会使用哪些源,以及它们的顺序。</p>
</div>
<div class="actions">
<a class="button secondary" href="/admin/profiles">Back</a>
<a class="button" href="/admin/profiles/{{ profile_key }}/preview">Preview</a>
</div>
</div>
<form method="post" action="/admin/profiles/{{ profile_key }}/sources" class="card">
<table>
<thead>
<tr><th>Enabled</th><th>Key</th><th>Order</th><th>Type</th><th>URL</th></tr>
</thead>
<tbody>
{% for binding in bindings %}
<tr>
<td>
<input type="hidden" name="source_key" value="{{ binding.key }}">
<input type="checkbox" name="enabled_{{ binding.key }}" {% if binding.enabled %}checked{% endif %} style="width:auto">
</td>
<td><strong>{{ binding.key }}</strong><div class="muted">{{ binding.display_name }}</div></td>
<td><input name="order_index_{{ binding.key }}" value="{{ binding.order_index }}"></td>
<td>{{ binding.kind }}</td>
<td class="muted">{{ binding.url }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="actions" style="margin-top:18px;">
<button type="submit">Save Source Bindings</button>
</div>
</form>
</div>
{% endblock %}

60
templates/profiles.html Normal file
View File

@@ -0,0 +1,60 @@
{% extends "base.html" %}
{% block content %}
<div class="stack">
<div>
<h1>Profiles</h1>
<p class="muted">管理客户端模板,并跳转到规则和预览页。</p>
</div>
<div class="card">
<h2>New / Edit Profile</h2>
<form method="post" action="/admin/profiles" class="stack">
<div class="grid-2">
<div><label>Key</label><input name="key" required placeholder="mihomo"></div>
<div><label>Title</label><input name="title" required></div>
<div><label>Provider Interval</label><input name="provider_interval" value="21600"></div>
<div><label>Rule Interval</label><input name="rule_interval" value="86400"></div>
<div><label>Test URL</label><input name="test_url" value="https://www.gstatic.com/generate_204"></div>
<div><label>Test Interval</label><input name="test_interval" value="300"></div>
<div><label>Main Policy</label><input name="main_policy" value="🚀 节点选择"></div>
<div><label>Source Policy</label><input name="source_policy" value="☁️ 机场选择"></div>
<div><label>Mixed Auto Policy</label><input name="mixed_auto_policy" value="♻️ 自动选择"></div>
<div><label>Manual Policy</label><input name="manual_policy" value="🚀 手动切换"></div>
<div><label>Direct Policy</label><input name="direct_policy" value="DIRECT"></div>
<div><label>Mode</label><input name="mode" value="rule"></div>
<div><label>Mixed Port</label><input name="mixed_port" value="7890"></div>
<div><label>Socks Port</label><input name="socks_port" value="7891"></div>
<div><label>Log Level</label><input name="log_level" value="info"></div>
</div>
<label class="inline"><input type="checkbox" name="allow_lan" checked style="width:auto"> Allow LAN</label>
<label class="inline"><input type="checkbox" name="ipv6" checked style="width:auto"> IPv6</label>
<div class="actions"><button type="submit">Save Profile</button></div>
</form>
</div>
<div class="stack">
{% for profile in profiles %}
<div class="card">
<div class="actions" style="justify-content:space-between; align-items:center;">
<div>
<h2 style="margin-bottom:4px;">{{ profile.key }}</h2>
<div class="muted">{{ profile.title }}</div>
</div>
<div class="actions">
<a class="button secondary" href="/admin/profiles/{{ profile.key }}/sources">Sources</a>
<a class="button secondary" href="/admin/profiles/{{ profile.key }}/groups">Groups</a>
<a class="button secondary" href="/admin/profiles/{{ profile.key }}/rules">Rules</a>
<a class="button" href="/admin/profiles/{{ profile.key }}/preview">Preview</a>
</div>
</div>
<div class="grid-2" style="margin-top:14px;">
<div><strong>Main:</strong> {{ profile.main_policy }}</div>
<div><strong>Source:</strong> {{ profile.source_policy }}</div>
<div><strong>Test URL:</strong> <span class="muted">{{ profile.test_url }}</span></div>
<div><strong>Mode:</strong> {{ profile.mode }}</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}

40
templates/rules.html Normal file
View File

@@ -0,0 +1,40 @@
{% extends "base.html" %}
{% block content %}
<div class="stack">
<div class="actions" style="justify-content:space-between; align-items:center;">
<div>
<h1>Rules: {{ profile_key }}</h1>
<p class="muted">控制规则模块启用状态、顺序和目标策略组。</p>
</div>
<div class="actions">
<a class="button secondary" href="/admin/profiles">Back</a>
<a class="button" href="/admin/profiles/{{ profile_key }}/preview">Preview</a>
</div>
</div>
<form method="post" action="/admin/profiles/{{ profile_key }}/rules" class="card">
<table>
<thead>
<tr><th>Enabled</th><th>Key</th><th>Order</th><th>Policy</th><th>Rule File</th></tr>
</thead>
<tbody>
{% for binding in bindings %}
<tr>
<td>
<input type="hidden" name="rule_key" value="{{ binding.key }}">
<input type="checkbox" name="enabled_{{ binding.key }}" {% if binding.enabled %}checked{% endif %} style="width:auto">
</td>
<td><strong>{{ binding.key }}</strong><div class="muted">{{ binding.behavior }} / {{ binding.format }}</div></td>
<td><input name="order_index_{{ binding.key }}" value="{{ binding.order_index }}"></td>
<td><input name="policy_{{ binding.key }}" value="{{ binding.policy }}"></td>
<td class="muted">{{ binding.file_path or "inline payload" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="actions" style="margin-top:18px;">
<button type="submit">Save Rules</button>
</div>
</form>
</div>
{% endblock %}

55
templates/sources.html Normal file
View File

@@ -0,0 +1,55 @@
{% extends "base.html" %}
{% block content %}
<div class="stack">
<div>
<h1>Sources</h1>
<p class="muted">管理订阅源。先做最小可用版本:增改删和启停。</p>
</div>
<div class="card">
<h2>New / Edit Source</h2>
<form method="post" action="/admin/sources" class="stack">
<div class="grid-2">
<div><label>Key</label><input name="key" required placeholder="airport-d"></div>
<div><label>Display Name</label><input name="display_name" placeholder="D"></div>
<div><label>Kind</label><select name="kind"><option value="auto">auto</option><option value="clash_yaml">clash_yaml</option><option value="base64_uri">base64_uri</option><option value="uri">uri</option></select></div>
<div><label>Cache TTL Seconds</label><input name="cache_ttl_seconds" placeholder="900"></div>
</div>
<div><label>URL</label><input name="url" required></div>
<div class="grid-2">
<div><label>Prefix</label><input name="prefix"></div>
<div><label>Suffix</label><input name="suffix"></div>
<div><label>Include Regex</label><input name="include_regex"></div>
<div><label>Exclude Regex</label><input name="exclude_regex"></div>
</div>
<label class="inline"><input type="checkbox" name="enabled" checked style="width:auto"> Enabled</label>
<div class="actions"><button type="submit">Save Source</button></div>
</form>
</div>
<div class="card">
<h2>Existing Sources</h2>
<table>
<thead>
<tr><th>Key</th><th>Type</th><th>URL</th><th>Prefix</th><th>Status</th><th></th></tr>
</thead>
<tbody>
{% for source in sources %}
<tr>
<td>{{ source.key }}</td>
<td>{{ source.kind }}</td>
<td class="muted">{{ source.url }}</td>
<td>{{ source.prefix }}</td>
<td>{{ "enabled" if source.enabled else "disabled" }}</td>
<td>
<form method="post" action="/admin/sources/{{ source.key }}/delete" onsubmit="return confirm('Delete source {{ source.key }}?')">
<button type="submit" class="secondary">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}