Template
Issue invite configs as subscription URLs with redeem-based lifetime.
Admin picks inbound once, sets duration in days from Get config, and configures the 3x-ui /sub base URL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+50
-33
@@ -3,16 +3,15 @@
|
||||
{% block title_extra %} — {{ _('invite_public_title') }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card" style="max-width: 560px; margin: 2rem auto;">
|
||||
<div class="card-header"
|
||||
style="justify-content: center; text-align: center; flex-direction: column; gap: var(--space-xs);">
|
||||
<h2 class="card-title">{{ invite.name }}</h2>
|
||||
<p style="color: var(--text-muted); font-size: 0.9rem;">{{ _('invite_public_subtitle') }}</p>
|
||||
<div class="card" style="max-width: 520px; margin: 2.5rem auto; overflow:hidden;">
|
||||
<div style="padding: var(--space-xl) var(--space-lg) var(--space-md); text-align:center; background: linear-gradient(180deg, rgba(59,130,246,0.12), transparent);">
|
||||
<div style="width:56px;height:56px;border-radius:16px;margin:0 auto var(--space-md);display:flex;align-items:center;justify-content:center;background:var(--bg-primary);font-size:1.6rem;">🔗</div>
|
||||
<h2 class="card-title" style="margin-bottom:6px;">{{ invite.name }}</h2>
|
||||
<p style="color: var(--text-muted); font-size: 0.92rem; margin:0;">{{ _('invite_public_subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
{% if need_password %}
|
||||
<div style="padding: var(--space-lg); text-align: center;">
|
||||
<div class="logo-icon" style="font-size: 3rem; margin-bottom: var(--space-md);">🔐</div>
|
||||
<p style="margin-bottom: var(--space-md);">{{ _('invite_protected_desc') }}</p>
|
||||
<form id="authForm" onsubmit="authInvite(event)"
|
||||
style="display: flex; flex-direction: column; gap: var(--space-md); max-width: 300px; margin: 0 auto;">
|
||||
@@ -26,27 +25,39 @@
|
||||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
<div style="padding: var(--space-lg); text-align: center;">
|
||||
<div id="statusBox" style="margin-bottom: var(--space-md); color: var(--text-muted); font-size: 0.95rem;">
|
||||
{% if invite.unlimited %}
|
||||
{{ _('invite_uses_left_unlimited').replace('{}', invite.used_count|string) }}
|
||||
{% elif invite.remaining is not none %}
|
||||
{{ _('invite_uses_left').replace('{}', invite.remaining|string) }}
|
||||
{% endif %}
|
||||
<div style="padding: var(--space-lg);">
|
||||
<div style="display:grid; grid-template-columns:1fr 1fr; gap:var(--space-sm); margin-bottom:var(--space-lg);">
|
||||
<div style="background:var(--bg-primary); border-radius:var(--radius-md); padding:var(--space-md); text-align:center;">
|
||||
<div style="font-size:0.72rem; color:var(--text-muted); text-transform:uppercase;">{{ _('invite_uses') }}</div>
|
||||
<div id="usesValue" style="font-weight:700; font-size:1.15rem; margin-top:4px;">
|
||||
{% if invite.unlimited %}∞{% else %}{{ invite.remaining }}{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div style="background:var(--bg-primary); border-radius:var(--radius-md); padding:var(--space-md); text-align:center;">
|
||||
<div style="font-size:0.72rem; color:var(--text-muted); text-transform:uppercase;">{{ _('invite_duration_short') }}</div>
|
||||
<div style="font-weight:700; font-size:1.15rem; margin-top:4px;">
|
||||
{% if invite.duration_days %}{{ invite.duration_days }} {{ _('days_short') }}{% else %}∞{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="statusHint" style="text-align:center; color:var(--text-muted); font-size:0.88rem; margin:0 0 var(--space-md);">
|
||||
{% if invite.duration_days %}
|
||||
{{ _('invite_duration_starts_hint').replace('{}', invite.duration_days|string) }}
|
||||
{% else %}
|
||||
{{ _('invite_get_config_hint') }}
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
{% if invite.available %}
|
||||
<button class="btn btn-primary" style="width:100%; max-width:320px;" onclick="createInviteConfig()" id="createBtn">
|
||||
<button class="btn btn-primary" style="width:100%;" onclick="createInviteConfig()" id="createBtn">
|
||||
<span id="createBtnText">{{ _('guest_get_config') }}</span>
|
||||
<div class="spinner hidden" id="createSpinner" style="width:14px;height:14px;"></div>
|
||||
</button>
|
||||
<div class="form-hint" style="margin-top: var(--space-sm);">{{ _('invite_get_config_hint') }}</div>
|
||||
{% elif invite.expired %}
|
||||
<p style="color:#ef4444;">{{ _('invite_expired') }}</p>
|
||||
{% elif invite.exhausted %}
|
||||
<p style="color:#ef4444;">{{ _('invite_exhausted') }}</p>
|
||||
<p style="text-align:center; color:#ef4444; margin:0;">{{ _('invite_exhausted') }}</p>
|
||||
{% else %}
|
||||
<p style="color:#ef4444;">{{ _('disabled') }}</p>
|
||||
<p style="text-align:center; color:#ef4444; margin:0;">{{ _('disabled') }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -58,14 +69,15 @@
|
||||
<h2 class="modal-title" id="configModalTitle">{{ _('config') }}</h2>
|
||||
<button class="modal-close" onclick="closeModal('configModal')">×</button>
|
||||
</div>
|
||||
<div id="expiresBanner" class="hidden" style="margin:0 var(--space-md) var(--space-sm); padding:var(--space-sm) var(--space-md); border-radius:var(--radius-md); background:rgba(59,130,246,0.1); color:var(--text-muted); font-size:0.85rem;"></div>
|
||||
<div class="config-tabs">
|
||||
<button class="config-tab active" onclick="switchConfigTab('conf')">{{ _('config_tab') }}</button>
|
||||
<button class="config-tab active" onclick="switchConfigTab('conf')">{{ _('invite_sub_tab') }}</button>
|
||||
<button class="config-tab" onclick="switchConfigTab('vpn')">{{ _('vpn_key_tab') }}</button>
|
||||
<button class="config-tab" onclick="switchConfigTab('qr')">{{ _('qr_code_tab') }}</button>
|
||||
</div>
|
||||
<div class="config-panel active" id="panel-conf">
|
||||
<div class="config-display">
|
||||
<textarea class="config-text" id="configText" readonly rows="12"
|
||||
<textarea class="config-text" id="configText" readonly rows="8"
|
||||
style="width:100%; border:none; background:transparent; color:inherit; font-family:monospace; resize:none; outline:none;"></textarea>
|
||||
<div class="config-actions">
|
||||
<button class="btn btn-secondary btn-sm" onclick="copyConfig()" style="flex:1">{{ _('copy_config') }}</button>
|
||||
@@ -130,17 +142,24 @@
|
||||
document.getElementById(panels[tab]).classList.add('active');
|
||||
}
|
||||
|
||||
function openConfigModal(name, config, vpnLink) {
|
||||
function openConfigModal(name, config, vpnLink, expiresAt) {
|
||||
currentConfig = config;
|
||||
currentVpnLink = vpnLink || '';
|
||||
currentVpnLink = vpnLink || config || '';
|
||||
document.getElementById('configText').value = config;
|
||||
document.getElementById('vpnLinkText').textContent = currentVpnLink;
|
||||
document.getElementById('configModalTitle').textContent = name;
|
||||
document.getElementById('downloadBtn').onclick = () => downloadFile(config, `${name}.conf`);
|
||||
const banner = document.getElementById('expiresBanner');
|
||||
if (expiresAt) {
|
||||
banner.textContent = _('invite_config_expires_at').replace('{}', new Date(expiresAt).toLocaleString());
|
||||
banner.classList.remove('hidden');
|
||||
} else {
|
||||
banner.classList.add('hidden');
|
||||
}
|
||||
document.getElementById('downloadBtn').onclick = () => downloadFile(config, `${name}.txt`);
|
||||
const qrContainer = document.getElementById('qrcode');
|
||||
qrContainer.innerHTML = '';
|
||||
new QRCode(qrContainer, {
|
||||
text: config, width: 256, height: 256,
|
||||
text: currentVpnLink || config, width: 256, height: 256,
|
||||
colorDark: '#000000', colorLight: '#ffffff',
|
||||
correctLevel: QRCode.CorrectLevel.L
|
||||
});
|
||||
@@ -152,14 +171,11 @@
|
||||
function copyVpnLink() { copyToClipboard(currentVpnLink); }
|
||||
|
||||
function updateStatus(invite) {
|
||||
const box = document.getElementById('statusBox');
|
||||
if (!box || !invite) return;
|
||||
if (invite.unlimited) {
|
||||
box.textContent = _('invite_uses_left_unlimited').replace('{}', String(invite.used_count || 0));
|
||||
} else if (invite.remaining != null) {
|
||||
box.textContent = _('invite_uses_left').replace('{}', String(invite.remaining));
|
||||
const uses = document.getElementById('usesValue');
|
||||
if (uses && invite) {
|
||||
uses.textContent = invite.unlimited ? '∞' : String(invite.remaining ?? 0);
|
||||
}
|
||||
if (!invite.available) {
|
||||
if (invite && !invite.available) {
|
||||
const btn = document.getElementById('createBtn');
|
||||
if (btn) btn.style.display = 'none';
|
||||
}
|
||||
@@ -180,7 +196,8 @@
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok || data.error) throw new Error(data.error || _('error'));
|
||||
if (data.config) openConfigModal(data.connection?.name || 'VPN', data.config, data.vpn_link || '');
|
||||
const share = data.subscription_url || data.config || '';
|
||||
if (share) openConfigModal(data.connection?.name || 'VPN', share, data.vpn_link || share, data.expires_at);
|
||||
updateStatus(data.invite);
|
||||
} catch (err) {
|
||||
alert(`${_('error')}: ` + err.message);
|
||||
|
||||
+95
-81
@@ -4,18 +4,30 @@
|
||||
|
||||
{% block content %}
|
||||
<section>
|
||||
<div class="flex items-center justify-between"
|
||||
style="margin-bottom: var(--space-lg); gap: var(--space-md); flex-wrap: wrap;">
|
||||
<h1 class="section-title" style="margin-bottom:0;">
|
||||
<span class="icon">🔗</span>
|
||||
{{ _('invites_title') }}
|
||||
</h1>
|
||||
<div style="display:flex; align-items:flex-end; justify-content:space-between; gap:var(--space-md); flex-wrap:wrap; margin-bottom:var(--space-lg);">
|
||||
<div>
|
||||
<h1 class="section-title" style="margin-bottom:var(--space-xs);">
|
||||
<span class="icon">🔗</span>
|
||||
{{ _('invites_title') }}
|
||||
</h1>
|
||||
<p style="color:var(--text-muted); margin:0; max-width:42rem; line-height:1.45;">{{ _('invites_hint') }}</p>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick="openCreateInvite()">
|
||||
<span>+</span> {{ _('invite_create') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p class="form-hint" style="margin-bottom: var(--space-lg);">{{ _('invites_hint') }}</p>
|
||||
{% if not xui_sub_url and xui_configured %}
|
||||
<div class="card" style="margin-bottom:var(--space-lg); border-color: rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.06);">
|
||||
<div style="display:flex; gap:var(--space-md); align-items:flex-start;">
|
||||
<div style="font-size:1.4rem;">⚠️</div>
|
||||
<div>
|
||||
<div style="font-weight:600; margin-bottom:4px;">{{ _('invite_sub_url_missing_title') }}</div>
|
||||
<div class="form-hint" style="margin:0;">{{ _('invite_sub_url_missing_hint') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div id="invitesEmpty" class="empty-state {% if invites %}hidden{% endif %}">
|
||||
<div class="empty-icon">🔗</div>
|
||||
@@ -23,36 +35,43 @@
|
||||
<div class="empty-desc">{{ _('invites_empty_desc') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="clients-list" id="invitesGrid"
|
||||
style="display: grid; gap: var(--space-md); {% if not invites %}display:none;{% endif %}">
|
||||
<div id="invitesGrid" style="display:{% if invites %}grid{% else %}none{% endif %}; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-md);">
|
||||
{% for inv in invites %}
|
||||
<div class="client-item" id="invite-{{ inv.id }}" style="{% if not inv.enabled %}opacity:0.55;{% endif %}">
|
||||
<div class="client-info">
|
||||
<div class="client-avatar">🔗</div>
|
||||
<div class="card invite-card" id="invite-{{ inv.id }}" style="padding:var(--space-md); {% if not inv.enabled %}opacity:0.55;{% endif %}">
|
||||
<div style="display:flex; justify-content:space-between; gap:var(--space-sm); align-items:flex-start; margin-bottom:var(--space-sm);">
|
||||
<div>
|
||||
<div class="client-name">
|
||||
{{ inv.name }}
|
||||
{% if inv.available %}
|
||||
<span class="badge badge-success">{{ _('invite_active') }}</span>
|
||||
{% elif inv.expired %}
|
||||
<span class="badge badge-warn">{{ _('invite_expired') }}</span>
|
||||
{% elif inv.exhausted %}
|
||||
<span class="badge badge-warn">{{ _('invite_exhausted') }}</span>
|
||||
{% else %}
|
||||
<span class="badge badge-secondary">{{ _('disabled') }}</span>
|
||||
{% endif %}
|
||||
<div style="font-weight:700; font-size:1.05rem;">{{ inv.name }}</div>
|
||||
<div style="font-size:0.8rem; color:var(--text-muted); margin-top:2px;">
|
||||
{% if inv.protocol == 'xui' %}3x-ui VLESS{% else %}{{ inv.protocol }}{% endif %}
|
||||
· inbound #{{ inv.xui_inbound_id or '—' }}
|
||||
</div>
|
||||
<div class="client-meta">
|
||||
<span>{{ _('invite_uses') }}:
|
||||
{% if inv.unlimited %}{{ inv.used_count }} / ∞{% else %}{{ inv.used_count }} / {{ inv.max_uses }}{% endif %}
|
||||
</span>
|
||||
<span>{{ inv.protocol if inv.protocol != 'xui' else '3x-ui VLESS' }}</span>
|
||||
{% if inv.has_password %}<span>🔐</span>{% endif %}
|
||||
</div>
|
||||
{% if inv.available %}
|
||||
<span class="badge badge-success">{{ _('invite_active') }}</span>
|
||||
{% elif inv.exhausted %}
|
||||
<span class="badge badge-warn">{{ _('invite_exhausted') }}</span>
|
||||
{% else %}
|
||||
<span class="badge badge-secondary">{{ _('disabled') }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div style="display:grid; grid-template-columns:1fr 1fr; gap:var(--space-sm); margin-bottom:var(--space-md);">
|
||||
<div style="background:var(--bg-primary); border-radius:var(--radius-md); padding:var(--space-sm);">
|
||||
<div style="font-size:0.7rem; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.04em;">{{ _('invite_uses') }}</div>
|
||||
<div style="font-weight:700; margin-top:2px;">
|
||||
{% if inv.unlimited %}{{ inv.used_count }} / ∞{% else %}{{ inv.used_count }} / {{ inv.max_uses }}{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div style="background:var(--bg-primary); border-radius:var(--radius-md); padding:var(--space-sm);">
|
||||
<div style="font-size:0.7rem; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.04em;">{{ _('invite_duration_short') }}</div>
|
||||
<div style="font-weight:700; margin-top:2px;">
|
||||
{% if inv.duration_days %}{{ inv.duration_days }} {{ _('days_short') }}{% else %}∞{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="client-actions" style="display:flex; gap:var(--space-xs); flex-wrap:wrap;">
|
||||
<button class="btn btn-secondary btn-sm" onclick="copyInviteUrl('{{ inv.token }}')" title="{{ _('copy') }}">📋</button>
|
||||
|
||||
<div style="display:flex; gap:var(--space-xs); flex-wrap:wrap;">
|
||||
<button class="btn btn-primary btn-sm" onclick="copyInviteUrl('{{ inv.token }}')">📋 {{ _('copy') }}</button>
|
||||
<button class="btn btn-secondary btn-sm" onclick="editInvite('{{ inv.id }}')">✏️</button>
|
||||
<button class="btn btn-secondary btn-sm" onclick="toggleInvite('{{ inv.id }}', {{ 'false' if inv.enabled else 'true' }})">
|
||||
{% if inv.enabled %}⏸{% else %}▶️{% endif %}
|
||||
@@ -64,9 +83,8 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Create / Edit Modal -->
|
||||
<div class="modal-backdrop" id="inviteModal">
|
||||
<div class="modal" style="max-width: 520px;">
|
||||
<div class="modal" style="max-width: 560px;">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title" id="inviteModalTitle">{{ _('invite_create') }}</h2>
|
||||
<button class="modal-close" onclick="closeModal('inviteModal')">×</button>
|
||||
@@ -79,10 +97,17 @@
|
||||
<input class="form-input" type="text" id="inviteName" placeholder="Promo / Friends">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('invite_max_uses_label') }}</label>
|
||||
<input class="form-input" type="number" id="inviteMaxUses" min="0" value="1">
|
||||
<div class="form-hint">{{ _('invite_max_uses_hint') }}</div>
|
||||
<div style="display:grid; grid-template-columns:1fr 1fr; gap:var(--space-md);">
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('invite_max_uses_label') }}</label>
|
||||
<input class="form-input" type="number" id="inviteMaxUses" min="0" value="1">
|
||||
<div class="form-hint">{{ _('invite_max_uses_hint') }}</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('invite_duration_label') }}</label>
|
||||
<input class="form-input" type="number" id="inviteDurationDays" min="0" value="0">
|
||||
<div class="form-hint">{{ _('invite_duration_hint') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -114,8 +139,9 @@
|
||||
<div class="form-group" id="inviteInboundGroup">
|
||||
<label class="form-label">{{ _('xui_inbound_label') }}</label>
|
||||
<select class="form-select" id="inviteInboundId">
|
||||
<option value="0">{{ _('xui_inbound_auto') }}</option>
|
||||
<option value="">{{ _('invite_inbound_loading') }}</option>
|
||||
</select>
|
||||
<div class="form-hint">{{ _('invite_inbound_hint') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -126,14 +152,6 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('invite_expires_label') }}</label>
|
||||
<input class="form-input" type="datetime-local" id="inviteExpires">
|
||||
<label style="display:none; align-items:center; gap:var(--space-sm); margin-top:var(--space-xs); cursor:pointer;" id="inviteClearExpWrap">
|
||||
<input type="checkbox" id="inviteClearExpires"> {{ _('invite_clear_expires') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('invite_note_label') }}</label>
|
||||
<input class="form-input" type="text" id="inviteNote" placeholder="{{ _('invite_note_placeholder') }}">
|
||||
@@ -158,6 +176,7 @@
|
||||
<script>
|
||||
const invitesData = {{ invites | tojson }};
|
||||
const xuiConfigured = {{ 'true' if xui_configured else 'false' }};
|
||||
const xuiDefaultInbound = {{ xui_default_inbound | int }};
|
||||
|
||||
function inviteUrl(token) {
|
||||
return `${window.location.origin}/invite/${token}`;
|
||||
@@ -171,22 +190,36 @@
|
||||
function updateInviteProtoFields() {
|
||||
const v = document.getElementById('inviteProtocol').value;
|
||||
document.getElementById('inviteInboundGroup').style.display = (v === 'xui') ? '' : 'none';
|
||||
if (v === 'xui') loadInviteInbounds(document.getElementById('inviteInboundId').value || xuiDefaultInbound);
|
||||
}
|
||||
|
||||
async function loadInviteInbounds(selected) {
|
||||
const select = document.getElementById('inviteInboundId');
|
||||
select.innerHTML = `<option value="0">${_('xui_inbound_auto')}</option>`;
|
||||
if (!xuiConfigured) return;
|
||||
select.innerHTML = `<option value="">${_('invite_inbound_loading')}</option>`;
|
||||
if (!xuiConfigured) {
|
||||
select.innerHTML = `<option value="">${_('invite_inbound_need_xui')}</option>`;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = await apiCall('/api/settings/xui/inbounds');
|
||||
(data.inbounds || []).forEach(ib => {
|
||||
const list = data.inbounds || [];
|
||||
if (!list.length) {
|
||||
select.innerHTML = `<option value="">${_('invite_inbound_empty')}</option>`;
|
||||
return;
|
||||
}
|
||||
select.innerHTML = '';
|
||||
list.forEach((ib, idx) => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = ib.id;
|
||||
opt.textContent = `${ib.remark || 'VLESS'} (:${ib.port})`;
|
||||
if (selected && String(ib.id) === String(selected)) opt.selected = true;
|
||||
const prefer = selected || xuiDefaultInbound;
|
||||
if (prefer && String(ib.id) === String(prefer)) opt.selected = true;
|
||||
else if (!prefer && idx === 0) opt.selected = true;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
} catch (e) { /* ignore */ }
|
||||
} catch (e) {
|
||||
select.innerHTML = `<option value="">${_('error')}: ${e.message}</option>`;
|
||||
}
|
||||
}
|
||||
|
||||
function parseProtocolValue() {
|
||||
@@ -201,9 +234,8 @@
|
||||
|
||||
function setProtocolSelect(protocol, serverId) {
|
||||
const sel = document.getElementById('inviteProtocol');
|
||||
if (protocol === 'xui') {
|
||||
sel.value = 'xui';
|
||||
} else {
|
||||
if (protocol === 'xui') sel.value = 'xui';
|
||||
else {
|
||||
const want = `${protocol}|${serverId || 0}`;
|
||||
if ([...sel.options].some(o => o.value === want)) sel.value = want;
|
||||
else sel.value = 'xui';
|
||||
@@ -216,15 +248,14 @@
|
||||
document.getElementById('inviteModalTitle').textContent = _('invite_create');
|
||||
document.getElementById('inviteName').value = '';
|
||||
document.getElementById('inviteMaxUses').value = '1';
|
||||
document.getElementById('inviteDurationDays').value = '0';
|
||||
document.getElementById('inviteUserId').value = '';
|
||||
document.getElementById('invitePassword').value = '';
|
||||
document.getElementById('inviteExpires').value = '';
|
||||
document.getElementById('inviteNote').value = '';
|
||||
document.getElementById('inviteClearPwdWrap').style.display = 'none';
|
||||
document.getElementById('inviteClearExpWrap').style.display = 'none';
|
||||
document.getElementById('inviteResetUsedWrap').style.display = 'none';
|
||||
setProtocolSelect('xui', 0);
|
||||
loadInviteInbounds(0);
|
||||
loadInviteInbounds(xuiDefaultInbound);
|
||||
openModal('inviteModal');
|
||||
}
|
||||
|
||||
@@ -235,64 +266,47 @@
|
||||
document.getElementById('inviteModalTitle').textContent = _('invite_edit');
|
||||
document.getElementById('inviteName').value = inv.name || '';
|
||||
document.getElementById('inviteMaxUses').value = String(inv.max_uses ?? 1);
|
||||
document.getElementById('inviteDurationDays').value = String(inv.duration_days ?? 0);
|
||||
document.getElementById('inviteUserId').value = inv.user_id || '';
|
||||
document.getElementById('invitePassword').value = '';
|
||||
document.getElementById('inviteNote').value = inv.note || '';
|
||||
document.getElementById('inviteClearPwdWrap').style.display = inv.has_password ? 'flex' : 'none';
|
||||
document.getElementById('inviteClearPassword').checked = false;
|
||||
document.getElementById('inviteClearExpWrap').style.display = inv.expires_at ? 'flex' : 'none';
|
||||
document.getElementById('inviteClearExpires').checked = false;
|
||||
document.getElementById('inviteResetUsedWrap').style.display = 'block';
|
||||
document.getElementById('inviteResetUsed').checked = false;
|
||||
if (inv.expires_at) {
|
||||
try {
|
||||
const d = new Date(inv.expires_at);
|
||||
const local = new Date(d.getTime() - d.getTimezoneOffset() * 60000);
|
||||
document.getElementById('inviteExpires').value = local.toISOString().slice(0, 16);
|
||||
} catch (e) {
|
||||
document.getElementById('inviteExpires').value = '';
|
||||
}
|
||||
} else {
|
||||
document.getElementById('inviteExpires').value = '';
|
||||
}
|
||||
setProtocolSelect(inv.protocol || 'xui', inv.server_id || 0);
|
||||
loadInviteInbounds(inv.xui_inbound_id || 0);
|
||||
loadInviteInbounds(inv.xui_inbound_id || xuiDefaultInbound);
|
||||
openModal('inviteModal');
|
||||
}
|
||||
|
||||
async function saveInvite() {
|
||||
const btn = document.getElementById('inviteSaveBtn');
|
||||
const text = document.getElementById('inviteSaveText');
|
||||
const spinner = document.getElementById('inviteSaveSpinner');
|
||||
btn.disabled = true;
|
||||
spinner.classList.remove('hidden');
|
||||
try {
|
||||
const editId = document.getElementById('inviteEditId').value;
|
||||
const proto = parseProtocolValue();
|
||||
const expiresVal = document.getElementById('inviteExpires').value;
|
||||
const inbound = parseInt(document.getElementById('inviteInboundId').value || '0');
|
||||
if (proto.protocol === 'xui' && !inbound) throw new Error(_('invite_inbound_required'));
|
||||
|
||||
const body = {
|
||||
name: document.getElementById('inviteName').value || 'Invite',
|
||||
max_uses: parseInt(document.getElementById('inviteMaxUses').value || '1'),
|
||||
duration_days: parseInt(document.getElementById('inviteDurationDays').value || '0'),
|
||||
user_id: document.getElementById('inviteUserId').value || '',
|
||||
protocol: proto.protocol,
|
||||
server_id: proto.server_id,
|
||||
xui_inbound_id: parseInt(document.getElementById('inviteInboundId').value || '0'),
|
||||
xui_inbound_id: inbound,
|
||||
note: document.getElementById('inviteNote').value || '',
|
||||
};
|
||||
const pwd = document.getElementById('invitePassword').value;
|
||||
if (pwd) body.password = pwd;
|
||||
if (expiresVal) body.expires_at = new Date(expiresVal).toISOString();
|
||||
|
||||
if (!body.user_id) throw new Error(_('invite_user_required'));
|
||||
|
||||
if (editId) {
|
||||
body.clear_password = document.getElementById('inviteClearPassword').checked;
|
||||
body.clear_expires = document.getElementById('inviteClearExpires').checked;
|
||||
body.reset_used = document.getElementById('inviteResetUsed').checked;
|
||||
if (!expiresVal && !body.clear_expires) {
|
||||
// keep existing — don't send expires_at
|
||||
delete body.expires_at;
|
||||
}
|
||||
await apiCall(`/api/invites/${editId}`, 'PUT', body);
|
||||
showToast(_('invite_updated'), 'success');
|
||||
} else {
|
||||
|
||||
+10
-2
@@ -436,6 +436,12 @@
|
||||
value="{{ settings.sync.xui_url }}" placeholder="https://panel.example.com:2053/path">
|
||||
<div class="form-hint">{{ _('xui_url_hint') }}</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('xui_sub_url_label') }}</label>
|
||||
<input type="url" class="form-input" name="xui_sub_url"
|
||||
value="{{ settings.sync.xui_sub_url or '' }}" placeholder="https://sub.example.com:2096/sub">
|
||||
<div class="form-hint">{{ _('xui_sub_url_hint') }}</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ _('xui_api_token_label') }}</label>
|
||||
<input type="password" class="form-input" name="xui_api_token"
|
||||
@@ -1028,7 +1034,8 @@
|
||||
xui_create_conns: syncForm.xui_create_conns.checked,
|
||||
xui_server_id: parseInt(syncForm.xui_server_id.value || '0'),
|
||||
xui_protocol: syncForm.xui_protocol.value,
|
||||
xui_inbound_id: parseInt(syncForm.xui_inbound_id.value || '0')
|
||||
xui_inbound_id: parseInt(syncForm.xui_inbound_id.value || '0'),
|
||||
xui_sub_url: (syncForm.xui_sub_url && syncForm.xui_sub_url.value || '').trim()
|
||||
};
|
||||
const res = await fetch('/api/settings/xui_sync_now', {
|
||||
method: 'POST',
|
||||
@@ -1110,7 +1117,8 @@
|
||||
xui_create_conns: syncForm.xui_create_conns.checked,
|
||||
xui_server_id: parseInt(syncForm.xui_server_id.value || '0'),
|
||||
xui_protocol: syncForm.xui_protocol.value,
|
||||
xui_inbound_id: parseInt(syncForm.xui_inbound_id.value || '0')
|
||||
xui_inbound_id: parseInt(syncForm.xui_inbound_id.value || '0'),
|
||||
xui_sub_url: (syncForm.xui_sub_url && syncForm.xui_sub_url.value || '').trim()
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user