forked from test2/Amnezia-Web-Panel-main
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);
|
||||
|
||||
Reference in New Issue
Block a user