Inital Commit
This commit is contained in:
690
public/admin.html
Normal file
690
public/admin.html
Normal file
@@ -0,0 +1,690 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin - Obi-WLANKenobi Portal</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Orbitron', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: #000000;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background:
|
||||
radial-gradient(ellipse at top, rgba(13, 110, 253, 0.15) 0%, transparent 50%),
|
||||
radial-gradient(ellipse at bottom, rgba(13, 110, 253, 0.1) 0%, transparent 50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: rgba(10, 25, 47, 0.95);
|
||||
border: 2px solid rgba(13, 110, 253, 0.5);
|
||||
border-radius: 20px;
|
||||
box-shadow:
|
||||
0 0 60px rgba(13, 110, 253, 0.4),
|
||||
inset 0 0 60px rgba(13, 110, 253, 0.1);
|
||||
padding: 40px;
|
||||
max-width: 700px;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #0d6efd;
|
||||
font-size: 28px;
|
||||
margin-bottom: 24px;
|
||||
font-weight: 900;
|
||||
text-shadow: 0 0 20px rgba(13, 110, 253, 0.8);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
color: #6ea8fe;
|
||||
font-size: 14px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
input, select {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
background: rgba(13, 110, 253, 0.1);
|
||||
border: 2px solid rgba(13, 110, 253, 0.5);
|
||||
border-radius: 8px;
|
||||
color: #fff;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: rgba(163, 207, 255, 0.5);
|
||||
}
|
||||
|
||||
input:focus, select:focus {
|
||||
outline: none;
|
||||
border-color: #0d6efd;
|
||||
box-shadow: 0 0 15px rgba(13, 110, 253, 0.5);
|
||||
}
|
||||
|
||||
select option {
|
||||
background: #0a192f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 14px 28px;
|
||||
border-radius: 8px;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
border: 2px solid;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
|
||||
color: white;
|
||||
border-color: #0d6efd;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 20px rgba(13, 110, 253, 0.6);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: transparent;
|
||||
color: #6ea8fe;
|
||||
border-color: rgba(13, 110, 253, 0.5);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: rgba(13, 110, 253, 0.2);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: transparent;
|
||||
color: #ea868f;
|
||||
border-color: rgba(220, 53, 69, 0.5);
|
||||
padding: 8px 14px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: rgba(220, 53, 69, 0.2);
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background: rgba(220, 53, 69, 0.2);
|
||||
color: #ea868f;
|
||||
border: 1px solid rgba(220, 53, 69, 0.5);
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background: rgba(13, 110, 253, 0.2);
|
||||
color: #6ea8fe;
|
||||
border: 1px solid rgba(13, 110, 253, 0.5);
|
||||
}
|
||||
|
||||
.code-display {
|
||||
background: rgba(13, 110, 253, 0.15);
|
||||
border: 2px solid rgba(13, 110, 253, 0.5);
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.code-display .code-value {
|
||||
font-size: 32px;
|
||||
font-weight: 900;
|
||||
color: #0d6efd;
|
||||
letter-spacing: 4px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.code-display .hint {
|
||||
font-size: 12px;
|
||||
color: #6ea8fe;
|
||||
}
|
||||
|
||||
.codes-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.codes-table th,
|
||||
.codes-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid rgba(13, 110, 253, 0.2);
|
||||
color: #a3cfff;
|
||||
}
|
||||
|
||||
.codes-table th {
|
||||
color: #0d6efd;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.codes-table .code-cell {
|
||||
font-family: monospace;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.codes-table .expired {
|
||||
color: #ea868f;
|
||||
}
|
||||
|
||||
.header-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.header-row h1 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
#loginView, #dashboardView {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#loginView.visible, #dashboardView.visible {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
color: #6ea8fe;
|
||||
font-size: 16px;
|
||||
margin: 24px 0 12px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid rgba(13, 110, 253, 0.3);
|
||||
}
|
||||
|
||||
.section-title:first-of-type {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
color: #6ea8fe;
|
||||
font-size: 14px;
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.form-row .form-group {
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
width: auto;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.packages-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.packages-table th,
|
||||
.packages-table td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid rgba(13, 110, 253, 0.2);
|
||||
color: #a3cfff;
|
||||
}
|
||||
|
||||
.packages-table th {
|
||||
color: #0d6efd;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.btn-small {
|
||||
padding: 6px 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="loginView" class="visible">
|
||||
<h1>Admin Login</h1>
|
||||
<div class="message" id="loginError"></div>
|
||||
<form id="loginForm" onsubmit="return handleLogin(event)">
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" placeholder="Enter admin password" required autocomplete="current-password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="dashboardView">
|
||||
<div class="header-row">
|
||||
<h1>Portal Admin</h1>
|
||||
<button type="button" class="btn btn-secondary" onclick="handleLogout()">Logout</button>
|
||||
</div>
|
||||
|
||||
<div class="section-title">Generate New Code</div>
|
||||
<div class="message" id="genMessage"></div>
|
||||
<form id="generateForm" onsubmit="return handleGenerate(event)">
|
||||
<div class="form-group">
|
||||
<label for="expiry">Expiration</label>
|
||||
<select id="expiry" name="expiry">
|
||||
<option value="60">1 hour</option>
|
||||
<option value="360">6 hours</option>
|
||||
<option value="720">12 hours</option>
|
||||
<option value="1440" selected>24 hours</option>
|
||||
<option value="2880">48 hours</option>
|
||||
<option value="10080">7 days</option>
|
||||
<option value="">No expiry</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Generate Code</button>
|
||||
</form>
|
||||
|
||||
<div id="newCodeDisplay" class="code-display" style="display: none;">
|
||||
<div class="code-value" id="newCodeValue"></div>
|
||||
<button type="button" class="btn btn-secondary" onclick="copyNewCode()">Copy to clipboard</button>
|
||||
<div class="hint" style="margin-top: 8px;">Share this code with WiFi guests. They enter it on the portal to connect.</div>
|
||||
</div>
|
||||
|
||||
<div class="section-title">Pakete & Preise</div>
|
||||
<div class="message" id="pkgMessage"></div>
|
||||
<form id="packageForm" onsubmit="return handlePackageSubmit(event)">
|
||||
<input type="hidden" id="packageId" name="packageId" value="">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="pkgName">Name</label>
|
||||
<input type="text" id="pkgName" name="pkgName" placeholder="z.B. 24 Stunden" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pkgDuration">Dauer</label>
|
||||
<select id="pkgDuration" name="pkgDuration">
|
||||
<option value="60">1 Stunde</option>
|
||||
<option value="360">6 Stunden</option>
|
||||
<option value="720">12 Stunden</option>
|
||||
<option value="1440" selected>24 Stunden</option>
|
||||
<option value="2880">48 Stunden</option>
|
||||
<option value="10080">7 Tage</option>
|
||||
<option value="43200">30 Tage</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pkgPrice">Preis</label>
|
||||
<input type="number" id="pkgPrice" name="pkgPrice" placeholder="2.99" step="0.01" min="0" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pkgCurrency">Währung</label>
|
||||
<select id="pkgCurrency" name="pkgCurrency">
|
||||
<option value="EUR" selected>EUR</option>
|
||||
<option value="CHF">CHF</option>
|
||||
<option value="USD">USD</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label><input type="checkbox" id="pkgActive" name="pkgActive" checked> Aktiv (im Portal sichtbar)</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" id="packageSubmitBtn">Paket hinzufügen</button>
|
||||
<button type="button" class="btn btn-secondary" id="packageCancelBtn" style="display: none; margin-left: 8px;" onclick="cancelPackageEdit()">Abbrechen</button>
|
||||
</form>
|
||||
<table class="packages-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Dauer</th>
|
||||
<th>Preis</th>
|
||||
<th>Aktiv</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="packagesTableBody">
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="emptyPackages" class="empty-state">Keine Pakete. Erstelle eines oben.</div>
|
||||
|
||||
<div class="section-title">Active Codes</div>
|
||||
<div id="codesList">
|
||||
<table class="codes-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Code</th>
|
||||
<th>Uses</th>
|
||||
<th>Expires</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="codesTableBody">
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="emptyCodes" class="empty-state">No codes yet. Generate one above.</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let lastGeneratedCode = '';
|
||||
|
||||
async function checkAuth() {
|
||||
try {
|
||||
const r = await fetch('/admin/check');
|
||||
const data = await r.json();
|
||||
if (data.authenticated) {
|
||||
document.getElementById('loginView').classList.remove('visible');
|
||||
document.getElementById('dashboardView').classList.add('visible');
|
||||
loadCodes();
|
||||
loadPackages();
|
||||
} else {
|
||||
document.getElementById('loginView').classList.add('visible');
|
||||
document.getElementById('dashboardView').classList.remove('visible');
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById('loginView').classList.add('visible');
|
||||
document.getElementById('dashboardView').classList.remove('visible');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogin(e) {
|
||||
e.preventDefault();
|
||||
const password = document.getElementById('password').value;
|
||||
const errEl = document.getElementById('loginError');
|
||||
errEl.style.display = 'none';
|
||||
try {
|
||||
const r = await fetch('/admin/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password })
|
||||
});
|
||||
const data = await r.json();
|
||||
if (data.success) {
|
||||
document.getElementById('password').value = '';
|
||||
checkAuth();
|
||||
} else {
|
||||
errEl.textContent = 'Invalid password.';
|
||||
errEl.className = 'message error';
|
||||
errEl.style.display = 'block';
|
||||
}
|
||||
} catch (e) {
|
||||
errEl.textContent = 'Login failed. Try again.';
|
||||
errEl.className = 'message error';
|
||||
errEl.style.display = 'block';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
await fetch('/admin/logout', { method: 'POST' });
|
||||
checkAuth();
|
||||
}
|
||||
|
||||
async function handleGenerate(e) {
|
||||
e.preventDefault();
|
||||
const expiry = document.getElementById('expiry').value;
|
||||
const msgEl = document.getElementById('genMessage');
|
||||
msgEl.style.display = 'none';
|
||||
try {
|
||||
const r = await fetch('/admin/codes', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
expiresInMinutes: expiry ? parseInt(expiry, 10) : null
|
||||
})
|
||||
});
|
||||
const data = await r.json();
|
||||
if (data.success) {
|
||||
lastGeneratedCode = data.code;
|
||||
document.getElementById('newCodeValue').textContent = data.code;
|
||||
document.getElementById('newCodeDisplay').style.display = 'block';
|
||||
loadCodes();
|
||||
msgEl.textContent = 'Code generated successfully.';
|
||||
msgEl.className = 'message success';
|
||||
msgEl.style.display = 'block';
|
||||
}
|
||||
} catch (e) {
|
||||
msgEl.textContent = 'Failed to generate code.';
|
||||
msgEl.className = 'message error';
|
||||
msgEl.style.display = 'block';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function copyNewCode() {
|
||||
if (!lastGeneratedCode) return;
|
||||
navigator.clipboard.writeText(lastGeneratedCode).then(() => {
|
||||
const btn = document.querySelector('#newCodeDisplay .btn-secondary');
|
||||
const orig = btn.textContent;
|
||||
btn.textContent = 'Copied!';
|
||||
setTimeout(() => { btn.textContent = orig; }, 1500);
|
||||
});
|
||||
}
|
||||
|
||||
async function loadCodes() {
|
||||
try {
|
||||
const r = await fetch('/admin/codes');
|
||||
const data = await r.json();
|
||||
const tbody = document.getElementById('codesTableBody');
|
||||
const emptyEl = document.getElementById('emptyCodes');
|
||||
tbody.innerHTML = '';
|
||||
if (!data.codes || data.codes.length === 0) {
|
||||
emptyEl.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
emptyEl.style.display = 'none';
|
||||
const now = new Date();
|
||||
data.codes.forEach((c) => {
|
||||
const tr = document.createElement('tr');
|
||||
const expiresAt = c.expiresAt ? new Date(c.expiresAt) : null;
|
||||
const expired = c.expired || (expiresAt && expiresAt < now);
|
||||
const expiresText = expiresAt
|
||||
? (expired ? 'Expired' : formatDate(expiresAt))
|
||||
: 'Never';
|
||||
tr.innerHTML = `
|
||||
<td class="code-cell ${expired ? 'expired' : ''}">${c.code}</td>
|
||||
<td>${c.useCount || 0}</td>
|
||||
<td class="${expired ? 'expired' : ''}">${expiresText}</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-danger" onclick="revokeCode('${c.code}')">Revoke</button>
|
||||
</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to load codes', e);
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(d) {
|
||||
return new Date(d).toLocaleString();
|
||||
}
|
||||
|
||||
async function revokeCode(code) {
|
||||
if (!confirm('Revoke this code? It will no longer work for new connections.')) return;
|
||||
try {
|
||||
const r = await fetch('/admin/codes/' + encodeURIComponent(code), {
|
||||
method: 'DELETE'
|
||||
});
|
||||
const data = await r.json();
|
||||
if (data.success) {
|
||||
loadCodes();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to revoke', e);
|
||||
}
|
||||
}
|
||||
|
||||
function formatDuration(min) {
|
||||
if (min >= 43200) return (min / 1440) + ' Tage';
|
||||
if (min >= 1440) return (min / 1440) + ' Tage';
|
||||
if (min >= 60) return (min / 60) + ' Stunden';
|
||||
return min + ' Min';
|
||||
}
|
||||
|
||||
async function loadPackages() {
|
||||
try {
|
||||
const r = await fetch('/admin/packages');
|
||||
const data = await r.json();
|
||||
const tbody = document.getElementById('packagesTableBody');
|
||||
const emptyEl = document.getElementById('emptyPackages');
|
||||
tbody.innerHTML = '';
|
||||
if (!data.packages || data.packages.length === 0) {
|
||||
emptyEl.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
emptyEl.style.display = 'none';
|
||||
data.packages.forEach((p) => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<td>${p.name}</td>
|
||||
<td>${formatDuration(p.durationMinutes)}</td>
|
||||
<td>${p.price} ${p.currency}</td>
|
||||
<td>${p.active ? 'Ja' : 'Nein'}</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-secondary btn-small" onclick="editPackage('${p.id}')">Bearbeiten</button>
|
||||
<button type="button" class="btn btn-danger btn-small" onclick="deletePackage('${p.id}')">Löschen</button>
|
||||
</td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to load packages', e);
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePackageSubmit(e) {
|
||||
e.preventDefault();
|
||||
const id = document.getElementById('packageId').value;
|
||||
const msgEl = document.getElementById('pkgMessage');
|
||||
msgEl.style.display = 'none';
|
||||
const body = {
|
||||
name: document.getElementById('pkgName').value.trim(),
|
||||
durationMinutes: parseInt(document.getElementById('pkgDuration').value, 10),
|
||||
price: parseFloat(document.getElementById('pkgPrice').value),
|
||||
currency: document.getElementById('pkgCurrency').value,
|
||||
active: document.getElementById('pkgActive').checked
|
||||
};
|
||||
try {
|
||||
const url = id ? '/admin/packages/' + encodeURIComponent(id) : '/admin/packages';
|
||||
const method = id ? 'PUT' : 'POST';
|
||||
const r = await fetch(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
const data = await r.json();
|
||||
if (data.success) {
|
||||
document.getElementById('packageForm').reset();
|
||||
document.getElementById('packageId').value = '';
|
||||
document.getElementById('pkgActive').checked = true;
|
||||
document.getElementById('packageSubmitBtn').textContent = 'Paket hinzufügen';
|
||||
document.getElementById('packageCancelBtn').style.display = 'none';
|
||||
loadPackages();
|
||||
msgEl.textContent = id ? 'Paket aktualisiert.' : 'Paket hinzugefügt.';
|
||||
msgEl.className = 'message success';
|
||||
msgEl.style.display = 'block';
|
||||
} else {
|
||||
msgEl.textContent = data.error || 'Fehler.';
|
||||
msgEl.className = 'message error';
|
||||
msgEl.style.display = 'block';
|
||||
}
|
||||
} catch (e) {
|
||||
msgEl.textContent = 'Fehler beim Speichern.';
|
||||
msgEl.className = 'message error';
|
||||
msgEl.style.display = 'block';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function editPackage(id) {
|
||||
fetch('/admin/packages')
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const p = data.packages.find(x => x.id === id);
|
||||
if (!p) return;
|
||||
document.getElementById('packageId').value = p.id;
|
||||
document.getElementById('pkgName').value = p.name;
|
||||
document.getElementById('pkgDuration').value = String(p.durationMinutes);
|
||||
document.getElementById('pkgPrice').value = p.price;
|
||||
document.getElementById('pkgCurrency').value = p.currency;
|
||||
document.getElementById('pkgActive').checked = p.active;
|
||||
document.getElementById('packageSubmitBtn').textContent = 'Paket speichern';
|
||||
document.getElementById('packageCancelBtn').style.display = 'inline-block';
|
||||
})
|
||||
.catch(e => console.error(e));
|
||||
}
|
||||
|
||||
function cancelPackageEdit() {
|
||||
document.getElementById('packageForm').reset();
|
||||
document.getElementById('packageId').value = '';
|
||||
document.getElementById('pkgActive').checked = true;
|
||||
document.getElementById('packageSubmitBtn').textContent = 'Paket hinzufügen';
|
||||
document.getElementById('packageCancelBtn').style.display = 'none';
|
||||
}
|
||||
|
||||
async function deletePackage(id) {
|
||||
if (!confirm('Paket wirklich löschen?')) return;
|
||||
try {
|
||||
const r = await fetch('/admin/packages/' + encodeURIComponent(id), {
|
||||
method: 'DELETE'
|
||||
});
|
||||
const data = await r.json();
|
||||
if (data.success) {
|
||||
loadPackages();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to delete package', e);
|
||||
}
|
||||
}
|
||||
|
||||
checkAuth();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
721
public/index.html
Normal file
721
public/index.html
Normal file
@@ -0,0 +1,721 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Obi-WLANKenobi - Guest Portal</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Orbitron', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: #000000;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
position: relative;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background:
|
||||
radial-gradient(ellipse at top, rgba(13, 110, 253, 0.15) 0%, transparent 50%),
|
||||
radial-gradient(ellipse at bottom, rgba(13, 110, 253, 0.1) 0%, transparent 50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.stars {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.star {
|
||||
position: absolute;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
animation: twinkle 3s infinite;
|
||||
}
|
||||
|
||||
@keyframes twinkle {
|
||||
0%, 100% { opacity: 0.3; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
.container {
|
||||
background: rgba(10, 25, 47, 0.95);
|
||||
border: 2px solid rgba(13, 110, 253, 0.5);
|
||||
border-radius: 20px;
|
||||
box-shadow:
|
||||
0 0 60px rgba(13, 110, 253, 0.4),
|
||||
inset 0 0 60px rgba(13, 110, 253, 0.1);
|
||||
padding: 50px;
|
||||
max-width: 550px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
animation: slideUp 0.5s ease-out;
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(30px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
margin: 0 auto 20px;
|
||||
background: radial-gradient(circle, rgba(13, 110, 253, 0.8) 0%, rgba(13, 110, 253, 0.3) 70%);
|
||||
border: 3px solid #0d6efd;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 60px;
|
||||
box-shadow: 0 0 40px rgba(13, 110, 253, 0.8);
|
||||
animation: pulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
box-shadow: 0 0 40px rgba(13, 110, 253, 0.8);
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 60px rgba(13, 110, 253, 1);
|
||||
transform: scale(1.02);
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #0d6efd;
|
||||
font-size: 36px;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 900;
|
||||
text-shadow: 0 0 20px rgba(13, 110, 253, 0.8);
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
color: #6ea8fe;
|
||||
font-size: 16px;
|
||||
margin-bottom: 15px;
|
||||
line-height: 1.6;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.quote {
|
||||
color: #a3cfff;
|
||||
font-size: 14px;
|
||||
margin-bottom: 40px;
|
||||
font-style: italic;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background: rgba(13, 110, 253, 0.1);
|
||||
border: 1px solid rgba(13, 110, 253, 0.3);
|
||||
border-radius: 12px;
|
||||
padding: 25px;
|
||||
margin-bottom: 30px;
|
||||
text-align: left;
|
||||
box-shadow: inset 0 0 20px rgba(13, 110, 253, 0.1);
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
font-size: 14px;
|
||||
color: #a3cfff;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.info-item:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
margin-right: 15px;
|
||||
flex-shrink: 0;
|
||||
color: #0d6efd;
|
||||
filter: drop-shadow(0 0 5px rgba(13, 110, 253, 0.8));
|
||||
}
|
||||
|
||||
.code-input {
|
||||
width: 100%;
|
||||
padding: 16px 20px;
|
||||
margin-bottom: 20px;
|
||||
background: rgba(13, 110, 253, 0.1);
|
||||
border: 2px solid rgba(13, 110, 253, 0.5);
|
||||
border-radius: 12px;
|
||||
color: #fff;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 3px;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.code-input::placeholder {
|
||||
color: rgba(163, 207, 255, 0.5);
|
||||
}
|
||||
|
||||
.code-input:focus {
|
||||
outline: none;
|
||||
border-color: #0d6efd;
|
||||
box-shadow: 0 0 20px rgba(13, 110, 253, 0.4);
|
||||
}
|
||||
|
||||
.code-label {
|
||||
color: #6ea8fe;
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.connect-btn {
|
||||
background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
|
||||
color: white;
|
||||
border: 2px solid #0d6efd;
|
||||
padding: 20px 40px;
|
||||
font-size: 20px;
|
||||
font-weight: 900;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow:
|
||||
0 4px 15px rgba(13, 110, 253, 0.6),
|
||||
0 0 30px rgba(13, 110, 253, 0.4);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2px;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
}
|
||||
|
||||
.connect-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow:
|
||||
0 6px 25px rgba(13, 110, 253, 0.8),
|
||||
0 0 50px rgba(13, 110, 253, 0.6);
|
||||
background: linear-gradient(135deg, #0a58ca 0%, #084298 100%);
|
||||
}
|
||||
|
||||
.connect-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.connect-btn:disabled {
|
||||
background: rgba(13, 110, 253, 0.3);
|
||||
border-color: rgba(13, 110, 253, 0.3);
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
display: none;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border: 3px solid rgba(13, 110, 253, 0.3);
|
||||
border-top-color: #0d6efd;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
margin: 0 auto;
|
||||
box-shadow: 0 0 10px rgba(13, 110, 253, 0.5);
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.message {
|
||||
margin-top: 20px;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
display: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background: rgba(13, 110, 253, 0.2);
|
||||
color: #6ea8fe;
|
||||
border: 1px solid rgba(13, 110, 253, 0.5);
|
||||
box-shadow: 0 0 20px rgba(13, 110, 253, 0.3);
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background: rgba(220, 53, 69, 0.2);
|
||||
color: #ea868f;
|
||||
border: 1px solid rgba(220, 53, 69, 0.5);
|
||||
box-shadow: 0 0 20px rgba(220, 53, 69, 0.3);
|
||||
}
|
||||
|
||||
.terms {
|
||||
margin-top: 30px;
|
||||
font-size: 11px;
|
||||
color: rgba(163, 207, 255, 0.6);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.terms a {
|
||||
color: #0d6efd;
|
||||
text-decoration: none;
|
||||
text-shadow: 0 0 5px rgba(13, 110, 253, 0.5);
|
||||
}
|
||||
|
||||
.terms a:hover {
|
||||
text-decoration: underline;
|
||||
text-shadow: 0 0 10px rgba(13, 110, 253, 0.8);
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
margin-bottom: 24px;
|
||||
border-bottom: 2px solid rgba(13, 110, 253, 0.3);
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
padding: 12px 16px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #6ea8fe;
|
||||
font-family: 'Orbitron', sans-serif;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
border-bottom: 3px solid transparent;
|
||||
margin-bottom: -2px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tab:hover {
|
||||
color: #a3cfff;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
color: #0d6efd;
|
||||
border-bottom-color: #0d6efd;
|
||||
}
|
||||
|
||||
.tab-panel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-panel.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.package-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
max-height: 50vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.package-row {
|
||||
background: rgba(13, 110, 253, 0.1);
|
||||
border: 2px solid rgba(13, 110, 253, 0.4);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.package-row:hover {
|
||||
border-color: rgba(13, 110, 253, 0.6);
|
||||
}
|
||||
|
||||
.package-row.expanded {
|
||||
border-color: #0d6efd;
|
||||
box-shadow: 0 0 15px rgba(13, 110, 253, 0.3);
|
||||
}
|
||||
|
||||
.package-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 14px 18px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.package-header:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.package-name {
|
||||
color: #0d6efd;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.package-price {
|
||||
color: #6ea8fe;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.package-chevron {
|
||||
margin-left: 10px;
|
||||
color: #6ea8fe;
|
||||
font-size: 14px;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.package-row.expanded .package-chevron {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.package-paypal {
|
||||
display: none;
|
||||
padding: 0 18px 18px;
|
||||
border-top: 1px solid rgba(13, 110, 253, 0.3);
|
||||
}
|
||||
|
||||
.package-row.expanded .package-paypal {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.package-paypal > div {
|
||||
min-width: 150px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.container {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
font-size: 50px;
|
||||
}
|
||||
|
||||
.connect-btn {
|
||||
padding: 18px 30px;
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="stars" id="stars"></div>
|
||||
|
||||
<div class="container">
|
||||
<div class="logo">⚔️</div>
|
||||
<h1>OBI-WLANKENOBI</h1>
|
||||
<p class="subtitle">A Guest Portal From A More Civilized Age</p>
|
||||
<p class="quote">"Hello there! The Force is strong with this connection."</p>
|
||||
|
||||
<div class="info-box">
|
||||
<div class="info-item">
|
||||
<svg class="info-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path>
|
||||
</svg>
|
||||
<span>Faster than the Millennium Falcon</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<svg class="info-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path>
|
||||
</svg>
|
||||
<span>Protected by Jedi encryption</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<svg class="info-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
<span>24 parsecs of connectivity</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button type="button" class="tab active" data-tab="paypal">Mit PayPal kaufen</button>
|
||||
<button type="button" class="tab" data-tab="code">Ich habe einen Code</button>
|
||||
</div>
|
||||
|
||||
<div id="paypalPanel" class="tab-panel active">
|
||||
<div id="packagesContainer"></div>
|
||||
</div>
|
||||
|
||||
<div id="codePanel" class="tab-panel">
|
||||
<label class="code-label" for="wifiCode">Zugangscode eingeben</label>
|
||||
<input type="text" id="wifiCode" class="code-input" placeholder="XXXXXXXX" maxlength="8" autocomplete="off">
|
||||
|
||||
<button class="connect-btn" id="connectBtn" onclick="connectToWiFi()">
|
||||
<span id="btnText">Use The Force</span>
|
||||
<div class="spinner" id="spinner"></div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="message" id="message"></div>
|
||||
|
||||
<div class="terms">
|
||||
By connecting, you agree this is the way. May the WiFi be with you.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Create starfield
|
||||
function createStars() {
|
||||
const starsContainer = document.getElementById('stars');
|
||||
const starCount = 200;
|
||||
|
||||
for (let i = 0; i < starCount; i++) {
|
||||
const star = document.createElement('div');
|
||||
star.className = 'star';
|
||||
|
||||
const size = Math.random() * 2 + 1;
|
||||
star.style.width = size + 'px';
|
||||
star.style.height = size + 'px';
|
||||
star.style.left = Math.random() * 100 + '%';
|
||||
star.style.top = Math.random() * 100 + '%';
|
||||
star.style.animationDelay = Math.random() * 3 + 's';
|
||||
star.style.animationDuration = (Math.random() * 3 + 2) + 's';
|
||||
|
||||
starsContainer.appendChild(star);
|
||||
}
|
||||
}
|
||||
|
||||
createStars();
|
||||
|
||||
// PayPal ist jetzt Standard-Tab – Pakete beim Start laden
|
||||
loadPackagesAndPayPal();
|
||||
|
||||
// Tabs
|
||||
document.querySelectorAll('.tab').forEach((t) => {
|
||||
t.addEventListener('click', () => {
|
||||
document.querySelectorAll('.tab').forEach((x) => x.classList.remove('active'));
|
||||
document.querySelectorAll('.tab-panel').forEach((x) => x.classList.remove('active'));
|
||||
t.classList.add('active');
|
||||
const panel = t.dataset.tab === 'code' ? 'codePanel' : 'paypalPanel';
|
||||
document.getElementById(panel).classList.add('active');
|
||||
if (t.dataset.tab === 'paypal') loadPackagesAndPayPal();
|
||||
});
|
||||
});
|
||||
|
||||
let paypalLoaded = false;
|
||||
|
||||
function togglePackage(row) {
|
||||
const wasExpanded = row.classList.contains('expanded');
|
||||
document.querySelectorAll('.package-row').forEach((r) => r.classList.remove('expanded'));
|
||||
document.querySelectorAll('.package-header[aria-expanded]').forEach((h) => h.setAttribute('aria-expanded', 'false'));
|
||||
if (!wasExpanded) {
|
||||
row.classList.add('expanded');
|
||||
row.querySelector('.package-header').setAttribute('aria-expanded', 'true');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPackagesAndPayPal() {
|
||||
const container = document.getElementById('packagesContainer');
|
||||
container.innerHTML = '<p style="color:#6ea8fe">Lade Pakete...</p>';
|
||||
try {
|
||||
const [pkgsRes, configRes] = await Promise.all([
|
||||
fetch('/api/packages'),
|
||||
fetch('/api/paypal/config')
|
||||
]);
|
||||
const { packages } = await pkgsRes.json();
|
||||
const { clientId } = await configRes.json();
|
||||
if (!packages || packages.length === 0) {
|
||||
container.innerHTML = '<p style="color:#6ea8fe">Derzeit keine Pakete verfügbar.</p>';
|
||||
return;
|
||||
}
|
||||
if (!clientId) {
|
||||
container.innerHTML = '<p style="color:#ea868f">PayPal ist nicht konfiguriert.</p>';
|
||||
return;
|
||||
}
|
||||
container.innerHTML = '';
|
||||
container.className = 'package-list';
|
||||
packages.forEach((pkg) => {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'package-row';
|
||||
row.dataset.packageId = pkg.id;
|
||||
row.innerHTML = `
|
||||
<div class="package-header" role="button" tabindex="0" aria-expanded="false">
|
||||
<span class="package-name">${pkg.name}</span>
|
||||
<span>
|
||||
<span class="package-price">${pkg.price.toFixed(2)} ${pkg.currency}</span>
|
||||
<span class="package-chevron">▼</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="package-paypal" id="paypal-btn-${pkg.id}"></div>
|
||||
`;
|
||||
const header = row.querySelector('.package-header');
|
||||
header.addEventListener('click', () => togglePackage(row));
|
||||
header.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); togglePackage(row); } });
|
||||
container.appendChild(row);
|
||||
});
|
||||
if (!paypalLoaded) {
|
||||
const script = document.createElement('script');
|
||||
script.src = `https://www.paypal.com/sdk/js?client-id=${clientId}¤cy=EUR`;
|
||||
script.async = true;
|
||||
script.onload = () => renderPayPalButtons(packages);
|
||||
document.head.appendChild(script);
|
||||
paypalLoaded = true;
|
||||
} else {
|
||||
renderPayPalButtons(packages);
|
||||
}
|
||||
} catch (e) {
|
||||
container.innerHTML = '<p style="color:#ea868f">Fehler beim Laden.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function renderPayPalButtons(packages) {
|
||||
if (typeof paypal === 'undefined') return;
|
||||
packages.forEach((pkg) => {
|
||||
const el = document.getElementById('paypal-btn-' + pkg.id);
|
||||
if (!el || el.hasChildNodes()) return;
|
||||
paypal.Buttons({
|
||||
createOrder: async () => {
|
||||
const r = await fetch('/api/paypal/create-order', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ packageId: pkg.id })
|
||||
});
|
||||
const data = await r.json();
|
||||
if (!data.success) throw new Error(data.error || 'Order failed');
|
||||
return data.orderId;
|
||||
},
|
||||
onApprove: async (data) => {
|
||||
const message = document.getElementById('message');
|
||||
try {
|
||||
const r = await fetch('/api/paypal/capture-order', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ orderId: data.orderID })
|
||||
});
|
||||
const result = await r.json();
|
||||
if (result.success) {
|
||||
message.className = 'message success';
|
||||
message.textContent = 'Bezahlung erfolgreich! Du wirst verbunden...';
|
||||
message.style.display = 'block';
|
||||
setTimeout(() => {
|
||||
window.location.href = 'http://captive.apple.com/hotspot-detect.html';
|
||||
}, 1500);
|
||||
setTimeout(() => {
|
||||
window.location.href = result.redirectUrl || 'https://google.com';
|
||||
}, 3500);
|
||||
} else {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
} catch (err) {
|
||||
message.className = 'message error';
|
||||
message.textContent = 'Fehler: ' + (err.message || 'Bezahlung fehlgeschlagen.');
|
||||
message.style.display = 'block';
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
const message = document.getElementById('message');
|
||||
message.className = 'message error';
|
||||
message.textContent = 'PayPal Fehler: ' + (err.message || 'Unbekannt');
|
||||
message.style.display = 'block';
|
||||
}
|
||||
}).render('#paypal-btn-' + pkg.id);
|
||||
});
|
||||
}
|
||||
|
||||
async function connectToWiFi() {
|
||||
const btn = document.getElementById('connectBtn');
|
||||
const btnText = document.getElementById('btnText');
|
||||
const spinner = document.getElementById('spinner');
|
||||
const message = document.getElementById('message');
|
||||
const codeInput = document.getElementById('wifiCode');
|
||||
|
||||
const code = (codeInput && codeInput.value || '').trim();
|
||||
if (!code) {
|
||||
message.className = 'message error';
|
||||
message.textContent = 'Please enter your access code.';
|
||||
message.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable button and show loading
|
||||
btn.disabled = true;
|
||||
btnText.style.display = 'none';
|
||||
spinner.style.display = 'block';
|
||||
message.style.display = 'none';
|
||||
|
||||
try {
|
||||
const response = await fetch('/authorize', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ code })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
// Show success message
|
||||
message.className = 'message success';
|
||||
message.textContent = '✨ You are now connected to the Force! Redirecting...';
|
||||
message.style.display = 'block';
|
||||
|
||||
// For iOS/macOS: redirect to Apple's captive portal detection URL
|
||||
// This triggers the CNA (Captive Network Assistant) to close
|
||||
setTimeout(() => {
|
||||
// Try Apple's captive portal URL first (closes iOS popup)
|
||||
window.location.href = 'http://captive.apple.com/hotspot-detect.html';
|
||||
}, 1500);
|
||||
|
||||
// Fallback: if still here after 3s, try the redirect URL
|
||||
setTimeout(() => {
|
||||
window.location.href = data.redirectUrl || 'https://www.google.com';
|
||||
}, 3500);
|
||||
} else {
|
||||
throw new Error(data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
// Show error message
|
||||
message.className = 'message error';
|
||||
message.textContent = '⚠️ ' + (error.message || 'The Force is not strong with this one. Please try again.');
|
||||
message.style.display = 'block';
|
||||
|
||||
// Re-enable button
|
||||
btn.disabled = false;
|
||||
btnText.style.display = 'block';
|
||||
spinner.style.display = 'none';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user