Track site-created 3x-ui clients and per-panel inbound whitelist for users
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,9 +4,12 @@
|
||||
<div class="admin-top">
|
||||
<h1>Клиенты</h1>
|
||||
<div class="actions">
|
||||
<a class="btn btn-sm btn-ghost" href="/admin/clients">Все</a>
|
||||
<a class="btn btn-sm {% if tab == 'wg' %}btn-accent{% else %}btn-ghost{% endif %}" href="/admin/clients">WireGuard / AWG</a>
|
||||
<a class="btn btn-sm {% if tab == 'xui' %}btn-accent{% else %}btn-ghost{% endif %}" href="/admin/clients?source=xui">3x-ui</a>
|
||||
{% if tab == 'wg' %}
|
||||
<a class="btn btn-sm btn-ghost" href="/admin/clients?protocol=wireguard">WireGuard</a>
|
||||
<a class="btn btn-sm btn-ghost" href="/admin/clients?protocol=awg2">AWG 2.0</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -20,8 +23,9 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if tab == 'wg' %}
|
||||
<div class="panel" style="margin-bottom:1rem">
|
||||
<div class="panel-head"><strong>Новый доступ</strong></div>
|
||||
<div class="panel-head"><strong>Новый доступ (WireGuard / AWG)</strong></div>
|
||||
<div class="panel-body">
|
||||
<form method="post" action="/admin/clients" class="form-grid">
|
||||
<label>Имя
|
||||
@@ -31,10 +35,12 @@
|
||||
<select name="server_id" required>
|
||||
{% for s in servers %}
|
||||
<option value="{{ s.id }}">{{ s.name }} ({{ s.protocol }})</option>
|
||||
{% else %}
|
||||
<option value="" disabled selected>Нет серверов</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<button class="btn btn-accent" type="submit">Создать</button>
|
||||
<button class="btn btn-accent" type="submit" {% if not servers %}disabled{% endif %}>Создать</button>
|
||||
<label style="grid-column: 1 / -1">Заметка
|
||||
<input name="notes" placeholder="опционально" />
|
||||
</label>
|
||||
@@ -84,4 +90,160 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
{# ——— 3x-ui ——— #}
|
||||
<div class="panel" style="margin-bottom:1rem">
|
||||
<div class="panel-head">
|
||||
<strong>Новый клиент 3x-ui</strong>
|
||||
<span class="muted">только inbound’ы, отмеченные на сервере как доступные пользователям</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{% if not xui_panels %}
|
||||
<p class="muted" style="margin:0">Сначала добавьте панель на странице <a href="/admin/xui">3x-ui</a>.</p>
|
||||
{% else %}
|
||||
<form method="post" action="/admin/clients/xui" class="stack" id="xui-client-form">
|
||||
<div class="form-grid">
|
||||
<label>Сервер 3x-ui
|
||||
<select name="panel_id" id="xui-panel" required>
|
||||
{% for p in xui_panels %}
|
||||
<option value="{{ p.id }}">{{ p.name }}{% if not p.is_reachable %} (offline){% endif %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>Протокол
|
||||
<select name="protocol" id="xui-protocol" required>
|
||||
<option value="vless">VLESS</option>
|
||||
<option value="wireguard">WireGuard</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>Inbound
|
||||
<select name="inbound_id" id="xui-inbound" required>
|
||||
<option value="" disabled selected>Выберите сервер</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<label>Email / имя
|
||||
<input name="email" placeholder="user@example.com" required />
|
||||
</label>
|
||||
<label>Срок (дни, 0 = безлимит)
|
||||
<input type="number" name="expiry_days" value="30" min="0" />
|
||||
</label>
|
||||
<label>Лимит GB
|
||||
<input type="number" name="total_gb" value="0" min="0" />
|
||||
</label>
|
||||
<label>Limit IP
|
||||
<input type="number" name="limit_ip" value="0" min="0" />
|
||||
</label>
|
||||
</div>
|
||||
<label class="check">
|
||||
<input type="checkbox" name="start_after_first_use" value="1" checked />
|
||||
Старт после первого использования
|
||||
</label>
|
||||
<label id="xui-flow-wrap">Flow (VLESS)
|
||||
<input name="flow" placeholder="xtls-rprx-vision" />
|
||||
</label>
|
||||
<label>Комментарий
|
||||
<input name="comment" />
|
||||
</label>
|
||||
<button class="btn btn-accent" type="submit" id="xui-submit" disabled>Создать в 3x-ui</button>
|
||||
<p class="muted" id="xui-inbound-hint" style="margin:0">Нет доступных inbound’ов — откройте сервер в <a href="/admin/xui">3x-ui</a> и отметьте нужные.</p>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-head"><strong>Клиенты, созданные через сайт (3x-ui)</strong></div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Сервер</th>
|
||||
<th>Протокол</th>
|
||||
<th>Inbound</th>
|
||||
<th>Срок</th>
|
||||
<th>Создан</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for c in xui_clients %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ c.email }}</strong>
|
||||
{% if c.link %}<div class="muted" style="font-size:.78rem;max-width:240px;word-break:break-all">{{ c.link[:64] }}{% if c.link|length > 64 %}…{% endif %}</div>{% endif %}
|
||||
</td>
|
||||
<td>{{ c.panel.name if c.panel else '—' }}</td>
|
||||
<td><span class="badge badge-proto">{{ c.protocol }}</span></td>
|
||||
<td class="muted">#{{ c.inbound_id }} {% if c.inbound_remark %}{{ c.inbound_remark }}{% endif %}</td>
|
||||
<td class="muted">
|
||||
{% if c.expiry_days and c.expiry_days > 0 %}
|
||||
{{ c.expiry_days }} дн.{% if c.start_after_first_use %} · после 1-го входа{% endif %}
|
||||
{% else %}без срока{% endif %}
|
||||
</td>
|
||||
<td class="muted">{{ c.created_at.strftime('%Y-%m-%d %H:%M') if c.created_at else '—' }}</td>
|
||||
<td>
|
||||
{% if c.panel %}
|
||||
<a class="btn btn-sm btn-ghost" href="/admin/xui/{{ c.panel_id }}">Панель</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="7" class="muted">Клиентов 3x-ui пока нет</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
const panelSelect = document.getElementById('xui-panel');
|
||||
const protocolSelect = document.getElementById('xui-protocol');
|
||||
const inboundSelect = document.getElementById('xui-inbound');
|
||||
const submitBtn = document.getElementById('xui-submit');
|
||||
const hint = document.getElementById('xui-inbound-hint');
|
||||
const flowWrap = document.getElementById('xui-flow-wrap');
|
||||
if (!panelSelect || !inboundSelect) return;
|
||||
|
||||
const cached = {{ user_inbounds_by_panel | tojson }};
|
||||
|
||||
function fillInbounds() {
|
||||
const panelId = panelSelect.value;
|
||||
const protocol = protocolSelect.value;
|
||||
const rows = (cached[panelId] || []).filter((r) => r.protocol === protocol);
|
||||
inboundSelect.innerHTML = '';
|
||||
if (!rows.length) {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = '';
|
||||
opt.disabled = true;
|
||||
opt.selected = true;
|
||||
opt.textContent = 'Нет доступных inbound’ов';
|
||||
inboundSelect.appendChild(opt);
|
||||
submitBtn.disabled = true;
|
||||
if (hint) hint.style.display = '';
|
||||
return;
|
||||
}
|
||||
rows.forEach((r) => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = r.inbound_id;
|
||||
opt.textContent = `#${r.inbound_id} ${r.remark || r.protocol} :${r.port || '?'}`;
|
||||
inboundSelect.appendChild(opt);
|
||||
});
|
||||
submitBtn.disabled = false;
|
||||
if (hint) hint.style.display = 'none';
|
||||
}
|
||||
|
||||
function toggleFlow() {
|
||||
if (flowWrap) flowWrap.style.display = protocolSelect.value === 'vless' ? '' : 'none';
|
||||
}
|
||||
|
||||
panelSelect.addEventListener('change', fillInbounds);
|
||||
protocolSelect.addEventListener('change', () => { toggleFlow(); fillInbounds(); });
|
||||
toggleFlow();
|
||||
fillInbounds();
|
||||
})();
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
<div class="flash flash-error">{{ flash[6:] }}</div>
|
||||
{% elif flash == 'client_created' %}
|
||||
<div class="flash">Клиент создан в 3x-ui</div>
|
||||
{% elif flash == 'inbounds_synced' %}
|
||||
<div class="flash">Inbound’ы синхронизированы с 3x-ui</div>
|
||||
{% elif flash == 'inbounds_saved' %}
|
||||
<div class="flash">Доступные пользователям inbound’ы сохранены</div>
|
||||
{% elif flash == 'ok' %}
|
||||
<div class="flash">Данные обновлены</div>
|
||||
{% endif %}
|
||||
@@ -65,6 +69,60 @@ PublicKey = {{ created.publicKey }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<strong>Создано через сайт</strong>
|
||||
<span class="muted">только клиенты, которых вы создали в этой панели</span>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Протокол</th>
|
||||
<th>Inbound</th>
|
||||
<th>Срок</th>
|
||||
<th>Лимиты</th>
|
||||
<th>Ссылка / ключи</th>
|
||||
<th>Когда</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for c in site_clients %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ c.email }}</strong>
|
||||
{% if c.comment %}<div class="muted">{{ c.comment }}</div>{% endif %}
|
||||
</td>
|
||||
<td><span class="badge badge-proto">{{ c.protocol }}</span></td>
|
||||
<td class="muted">#{{ c.inbound_id }} {% if c.inbound_remark %}{{ c.inbound_remark }}{% endif %}</td>
|
||||
<td class="muted">
|
||||
{% if c.expiry_days and c.expiry_days > 0 %}
|
||||
{{ c.expiry_days }} дн.
|
||||
{% if c.start_after_first_use %}<br><span class="badge badge-ok">после 1-го входа</span>{% endif %}
|
||||
{% else %}
|
||||
без срока
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="muted">
|
||||
{{ c.total_gb or 0 }} GB
|
||||
{% if c.limit_ip %}<br>IP ≤ {{ c.limit_ip }}{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if c.link %}
|
||||
<div class="link-box" style="margin:0;max-width:280px;font-size:.78rem;word-break:break-all;">{{ c.link }}</div>
|
||||
{% elif c.private_key %}
|
||||
<div class="muted" style="font-size:.78rem;word-break:break-all;">priv: {{ c.private_key[:24] }}…</div>
|
||||
{% else %}—{% endif %}
|
||||
</td>
|
||||
<td class="muted">{{ c.created_at }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="7" class="muted">Пока никого не создавали через сайт</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if data %}
|
||||
<div class="stats">
|
||||
<div class="stat">
|
||||
@@ -165,10 +223,55 @@ PublicKey = {{ created.publicKey }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="panel" style="margin-bottom:1rem">
|
||||
<div class="panel-head">
|
||||
<strong>Доступные inbound’ы (VLESS / WireGuard)</strong>
|
||||
<strong>Inbound’ы для пользователей</strong>
|
||||
<span class="muted">отметьте, какие будут доступны при создании клиентов</span>
|
||||
</div>
|
||||
<form method="post" action="/admin/xui/{{ panel.id }}/inbounds/users">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Для пользователей</th>
|
||||
<th>ID</th>
|
||||
<th>Remark</th>
|
||||
<th>Protocol</th>
|
||||
<th>Port</th>
|
||||
<th>В 3x-ui</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ib in panel_inbounds %}
|
||||
<tr>
|
||||
<td>
|
||||
<label class="check" style="margin:0">
|
||||
<input type="checkbox" name="inbound_ids" value="{{ ib.inbound_id }}" {% if ib.is_available_for_users %}checked{% endif %} />
|
||||
</label>
|
||||
</td>
|
||||
<td>{{ ib.inbound_id }}</td>
|
||||
<td>{{ ib.remark or '—' }}</td>
|
||||
<td><span class="badge badge-proto">{{ ib.protocol }}</span></td>
|
||||
<td>{{ ib.port or '—' }}</td>
|
||||
<td>{% if ib.enable %}<span class="badge badge-ok">on</span>{% else %}<span class="badge badge-off">off</span>{% endif %}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="6" class="muted">Список пуст — нажмите «Синхронизировать inbound’ы»</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="actions" style="padding:1rem;gap:.5rem;display:flex;flex-wrap:wrap">
|
||||
<button class="btn btn-accent" type="submit" {% if not panel_inbounds %}disabled{% endif %}>Сохранить для пользователей</button>
|
||||
<button class="btn btn-ghost" type="submit" formaction="/admin/xui/{{ panel.id }}/inbounds/sync" formmethod="post">Синхронизировать с 3x-ui</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% if data %}
|
||||
<div class="panel" style="margin-bottom:1rem">
|
||||
<div class="panel-head">
|
||||
<strong>Все inbound’ы из API (VLESS / WireGuard)</strong>
|
||||
<span class="muted" id="inbounds-status"></span>
|
||||
</div>
|
||||
<table>
|
||||
@@ -198,7 +301,10 @@ PublicKey = {{ created.publicKey }}
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-head"><strong>Clients</strong></div>
|
||||
<div class="panel-head">
|
||||
<strong>Все клиенты 3x-ui</strong>
|
||||
<span class="muted">из API панели (включая созданных не через сайт)</span>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user