Repository navigation
Expand file tree
/
Copy pathdashboard.php
More file actions
491 lines (457 loc) · 27.2 KB
/
Copy pathdashboard.php
File metadata and controls
491 lines (457 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<?php
require_once __DIR__ . '/lib/env.php';
require_once __DIR__ . '/lib/auth.php';
require_once __DIR__ . '/lib/RouterosAPI.php';
loadEnv();
requireAuth();
// Connect to router
$api = new RouterosAPI();
$connected = $api->connect(
env('ROUTER_HOST', '100.64.0.2'),
(int) env('ROUTER_PORT', '8728'),
env('ROUTER_USER', 'admin'),
env('ROUTER_PASS', '')
);
$routerError = $connected ? '' : $api->getError();
$users = [];
$active = [];
$resources = [];
$profiles = [];
if ($connected) {
$users = $api->query('/ppp/secret/print');
$active = $api->query('/ppp/active/print');
$resources = $api->query('/system/resource/print');
$profiles = $api->query('/ppp/profile/print');
$api->disconnect();
}
$activeMap = [];
foreach ($active as $sess) {
if (isset($sess['name'])) $activeMap[$sess['name']] = $sess;
}
$csrf = generateCsrfToken();
$res = $resources[0] ?? [];
$totalUsers = count($users);
$onlineCount = count($activeMap);
?>
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VPN Manager — Dashboard</title>
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/sstp/assets/style.css">
<script>
const savedTheme = localStorage.getItem('theme') || 'dark';
document.documentElement.setAttribute('data-theme', savedTheme);
</script>
</head>
<body class="dashboard-page">
<!-- Sidebar -->
<aside class="sidebar" id="sidebar">
<div class="sidebar-header">
<div class="logo">
<span class="logo-text nav-text">VPN Manager</span>
</div>
</div>
<nav class="sidebar-nav">
<a href="#" class="nav-item active" data-section="users">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span class="nav-text">VPN Users</span>
</a>
<a href="#" class="nav-item" data-section="settings">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
<span class="nav-text">Settings</span>
</a>
<a href="#" class="nav-item" data-section="help">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
<span class="nav-text">Help</span>
</a>
</nav>
<div class="sidebar-footer">
<button class="sidebar-collapse-btn" id="sidebarCollapseBtn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="11 17 6 12 11 7"/><polyline points="18 17 13 12 18 7"/></svg>
<span class="nav-text">Collapse</span>
</button>
<a href="/sstp/logout.php" class="logout-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
<span class="nav-text">Logout</span>
</a>
</div>
</aside>
<!-- Mobile backdrop -->
<div class="sidebar-backdrop" id="sidebarBackdrop"></div>
<!-- Main -->
<main class="main">
<!-- Top bar -->
<header class="topbar">
<button class="menu-toggle" id="menuToggle">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
</button>
<div class="topbar-title" id="topbarTitle">VPN Users</div>
<div class="topbar-actions">
<button class="theme-toggle" id="themeToggle" title="Toggle Theme">
<svg class="icon-sun" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>
<svg class="icon-moon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
</button>
</div>
</header>
<?php if ($routerError): ?>
<div class="alert alert-error" style="margin:1.5rem;">
Router connection failed: <?= htmlspecialchars($routerError, ENT_QUOTES, 'UTF-8') ?>
</div>
<?php endif; ?>
<!-- Stats row -->
<div class="stats-row">
<div class="stat-card">
<div class="stat-icon purple"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/></svg></div>
<div>
<div class="stat-value"><?= $totalUsers ?></div>
<div class="stat-label">Total Users</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon green"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg></div>
<div>
<div class="stat-value"><?= $onlineCount ?></div>
<div class="stat-label">Active Sessions</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon blue"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg></div>
<div>
<div class="stat-value"><?= isset($res['cpu-load']) ? $res['cpu-load'] . '%' : 'N/A' ?></div>
<div class="stat-label">CPU Load</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon orange"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="3" width="20" height="14" rx="2"/></svg></div>
<div>
<div class="stat-value"><?php
if (isset($res['free-memory'], $res['total-memory'])) {
$used = $res['total-memory'] - $res['free-memory'];
echo round($used / $res['total-memory'] * 100) . '%';
} else { echo 'N/A'; }
?></div>
<div class="stat-label">RAM Used</div>
</div>
</div>
</div>
<!-- ==================== USERS SECTION ==================== -->
<section class="section active" id="section-users">
<div class="section-header">
<div>
<h2>VPN Users</h2>
<p class="section-sub"><?= $totalUsers ?> users · <?= $onlineCount ?> online</p>
</div>
<div class="header-actions">
<button class="btn btn-secondary" onclick="location.reload()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
Refresh
</button>
<button class="btn btn-primary" id="addUserBtn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
Add User
</button>
</div>
</div>
<div class="search-bar">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<input type="text" id="userSearch" placeholder="Search users...">
</div>
<div class="table-wrapper">
<table class="data-table" id="usersTable">
<thead>
<tr>
<th>Username</th>
<th>Status</th>
<th>Assigned IP</th>
<th>Current IP</th>
<th>Caller IP</th>
<th>Uptime</th>
<th>Profile</th>
<th>Comment</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="usersBody">
<?php foreach ($users as $u):
$name = $u['name'] ?? '';
$profile = $u['profile'] ?? 'default';
$disabled = ($u['disabled'] ?? 'false') === 'true';
$comment = $u['comment'] ?? '';
$password = $u['password'] ?? '';
$remoteAddr = $u['remote-address'] ?? '';
$sess = $activeMap[$name] ?? null;
$isOnline = $sess !== null;
$vpnIp = $sess['address'] ?? '—';
$caller = $sess['caller-id'] ?? '—';
$uptime = $sess['uptime'] ?? '—';
$rxBytes = isset($sess['bytes-in']) ? formatBytes((int)$sess['bytes-in']) : '—';
$txBytes = isset($sess['bytes-out']) ? formatBytes((int)$sess['bytes-out']) : '—';
?>
<tr class="user-row <?= $disabled ? 'row-disabled' : '' ?>" data-name="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>">
<td><strong><?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?></strong></td>
<td>
<?php if ($disabled): ?>
<span class="badge badge-disabled">Disabled</span>
<?php elseif ($isOnline): ?>
<span class="badge badge-online">Online</span>
<?php else: ?>
<span class="badge badge-offline">Offline</span>
<?php endif; ?>
</td>
<td class="mono"><?= htmlspecialchars($remoteAddr ?: '—', ENT_QUOTES, 'UTF-8') ?></td>
<td class="mono"><?= htmlspecialchars($vpnIp, ENT_QUOTES, 'UTF-8') ?></td>
<td class="mono muted"><?= htmlspecialchars($caller, ENT_QUOTES, 'UTF-8') ?></td>
<td><?= htmlspecialchars($uptime, ENT_QUOTES, 'UTF-8') ?></td>
<td><span class="badge badge-profile"><?= htmlspecialchars($profile, ENT_QUOTES, 'UTF-8') ?></span></td>
<td class="muted"><?= htmlspecialchars(substr($comment, 0, 28), ENT_QUOTES, 'UTF-8') ?><?= strlen($comment) > 28 ? '…' : '' ?></td>
<td>
<div class="action-btns">
<button class="act-btn edit-btn" title="Edit User"
data-name="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>"
data-profile="<?= htmlspecialchars($profile, ENT_QUOTES, 'UTF-8') ?>"
data-comment="<?= htmlspecialchars($comment, ENT_QUOTES, 'UTF-8') ?>"
data-pass="<?= htmlspecialchars($password, ENT_QUOTES, 'UTF-8') ?>"
data-remote="<?= htmlspecialchars($remoteAddr, ENT_QUOTES, 'UTF-8') ?>"
data-disabled="<?= $disabled ? '1' : '0' ?>">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>
</button>
<button class="act-btn copy-btn" title="Copy Connect Command"
data-name="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>"
data-pass="<?= htmlspecialchars($password, ENT_QUOTES, 'UTF-8') ?>">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
</button>
<?php if ($isOnline): ?>
<button class="act-btn kick-btn" title="Disconnect User"
data-name="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>"
data-id="<?= htmlspecialchars($sess['.id'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
</button>
<?php endif; ?>
<button class="act-btn toggle-btn" title="<?= $disabled ? 'Enable' : 'Disable' ?>"
data-name="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>"
data-disabled="<?= $disabled ? '1' : '0' ?>">
<?php if ($disabled): ?>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#22c55e" stroke-width="2"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
<?php else: ?>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#f59e0b" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="9" y1="9" x2="15" y2="15"/><line x1="15" y1="9" x2="9" y2="15"/></svg>
<?php endif; ?>
</button>
<button class="act-btn delete-btn" title="Delete User"
data-name="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($users)): ?>
<tr><td colspan="9" class="empty-state">No users found</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="pagination" id="pagination"></div>
</section>
<!-- ==================== SETTINGS SECTION ==================== -->
<section class="section" id="section-settings">
<div class="section-header">
<div>
<h2>Settings</h2>
<p class="section-sub">System configuration and security</p>
</div>
</div>
<div style="display:flex; flex-direction:column; gap:1.5rem; max-width:600px;">
<div class="stat-card" style="flex-direction:column; align-items:flex-start; padding:1.5rem;">
<h3 style="margin-top:0; font-size:1.1rem;">Router Connection</h3>
<p class="muted" style="font-size:0.875rem; margin-bottom:1rem;">Manually verify API connectivity to the MikroTik CHR instance.</p>
<button class="btn btn-secondary" id="checkConnBtn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
Check Connection
</button>
<div id="checkConnResult" style="margin-top:1rem; font-size:0.875rem; display:none;"></div>
</div>
<div class="stat-card" style="flex-direction:column; align-items:flex-start; padding:1.5rem;">
<h3 style="margin-top:0; font-size:1.1rem;">Change Panel Password</h3>
<p class="muted" style="font-size:0.875rem; margin-bottom:1rem;">Update your web interface login password.</p>
<form id="changePassForm" style="width:100%; display:flex; flex-direction:column; gap:1rem;">
<input type="hidden" name="action" value="change_password">
<div class="form-group">
<label>Current Password</label>
<input type="password" name="current_password" required>
</div>
<div class="form-group">
<label>New Password</label>
<input type="password" name="new_password" required minlength="6">
</div>
<button type="submit" class="btn btn-primary" style="align-self:flex-start;">
Update Password
</button>
</form>
</div>
</div>
</section>
<!-- ==================== HELP SECTION ==================== -->
<section class="section" id="section-help">
<div class="section-header">
<div>
<h2>Help & Support</h2>
<p class="section-sub">Developer information and project support</p>
</div>
</div>
<div style="display:flex; flex-direction:column; gap:1.5rem; max-width:600px;">
<div class="stat-card" style="flex-direction:column; align-items:flex-start; padding:2rem;">
<p class="muted" style="font-size:0.9rem; line-height:1.5; margin-bottom:1.5rem;">
Developed by <strong>mahmud</strong>.<br>
A modern, lightweight web interface for managing SSTP VPN servers.
</p>
<div style="background:var(--bg); border:1px solid var(--border); padding:1rem; border-radius:var(--radius); width:100%;">
<h4 style="margin:0 0 0.5rem 0; font-size:0.95rem;">Support the Developer</h4>
<p class="muted" style="font-size:0.85rem; margin-bottom:1rem; line-height:1.4;">
If you found this helpful for your business or personal use, consider supporting the development.
</p>
<a href="https://wa.me/+8801540221898" target="_blank" class="btn btn-primary" style="text-decoration:none; display:inline-flex;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right:0.5rem;"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>
Buy me a Coffee
</a>
</div>
</div>
</div>
</section>
</main>
<!-- ==================== MODALS ==================== -->
<!-- Add/Edit User Modal -->
<div class="modal-overlay" id="editModal">
<div class="modal">
<div class="modal-header">
<h3 id="editModalTitle">Add User</h3>
<button class="modal-close" data-modal="editModal">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
</button>
</div>
<div class="modal-body">
<form id="userForm">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf, ENT_QUOTES, 'UTF-8') ?>">
<input type="hidden" name="action" id="formAction" value="add_user">
<input type="hidden" name="original_name" id="originalName" value="">
<div class="form-group">
<label for="fu_name">Username <span class="required">*</span></label>
<input type="text" id="fu_name" name="name" required maxlength="64"
pattern="[a-zA-Z0-9._\-]+" title="Letters, numbers, ., _, - only">
</div>
<div class="form-group">
<label for="fu_pass">Password <span class="required">*</span></label>
<div class="input-with-btn">
<input type="text" id="fu_pass" name="password" required maxlength="128">
<button type="button" class="btn btn-secondary" id="genPassBtn">Generate</button>
</div>
</div>
<div class="form-group">
<label for="fu_profile">Profile</label>
<select id="fu_profile" name="profile">
<?php foreach ($profiles as $p):
$pname = $p['name'] ?? '';
if (!$pname) continue;
?>
<option value="<?= htmlspecialchars($pname, ENT_QUOTES, 'UTF-8') ?>"><?= htmlspecialchars($pname, ENT_QUOTES, 'UTF-8') ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="fu_remote_address">Static IP (Client) <span class="muted" style="font-size:0.75rem; font-weight:400;">(auto-assigned on create)</span></label>
<input type="text" id="fu_remote_address" name="remote_address" placeholder="Override or leave blank">
</div>
<div class="form-group">
<label for="fu_comment">Comment / Note</label>
<input type="text" id="fu_comment" name="comment" maxlength="255">
</div>
<div class="form-group checkbox-group">
<label class="checkbox-label">
<input type="checkbox" id="fu_disabled" name="disabled" value="1">
<span>Disabled</span>
</label>
</div>
<!-- Connection Commands (shown only on edit) -->
<div id="cmdSection" style="display:none;">
<div class="cmd-block">
<div class="cmd-block-header">
<select id="cmdDeviceSelect" class="cmd-select">
<option value="windows">Windows</option>
<option value="linux">Linux</option>
<option value="routeros">RouterOS</option>
</select>
<button type="button" id="cmdCopyBtn">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
Copy
</button>
</div>
<pre id="cmdPre"></pre>
</div>
</div>
<div class="modal-actions">
<button type="button" class="btn btn-secondary" data-modal-close="editModal">Cancel</button>
<button type="submit" class="btn btn-primary">Save User</button>
</div>
</form>
</div>
</div>
</div>
<!-- Device Selection Modal -->
<div class="modal-overlay" id="deviceModal">
<div class="modal modal-sm">
<div class="modal-header">
<h3>Select Device OS</h3>
<button class="modal-close" data-modal="deviceModal">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
</button>
</div>
<div class="modal-body">
<p style="font-size:0.875rem; color:var(--text-muted); margin-bottom:1rem;">Select the OS to copy its connection command:</p>
<div style="display:flex; flex-direction:column; gap:0.5rem;">
<button class="btn btn-secondary btn-full dev-sel-btn" data-os="windows">Windows</button>
<button class="btn btn-secondary btn-full dev-sel-btn" data-os="linux">Linux</button>
<button class="btn btn-secondary btn-full dev-sel-btn" data-os="routeros">RouterOS</button>
</div>
</div>
</div>
</div>
<!-- Confirm Dialog -->
<div class="modal-overlay" id="confirmModal">
<div class="modal modal-sm">
<div class="modal-header">
<h3 id="confirmTitle">Confirm Action</h3>
</div>
<div class="modal-body">
<p id="confirmMsg"></p>
<div class="modal-actions">
<button class="btn btn-secondary" id="confirmCancel">Cancel</button>
<button class="btn btn-danger" id="confirmOk">Confirm</button>
</div>
</div>
</div>
</div>
<!-- Toast -->
<div class="toast-container" id="toastContainer"></div>
<script>
const CSRF = <?= json_encode($csrf) ?>;
const SERVER_HOST = <?= json_encode(env('VPN_PUBLIC_IP', $_SERVER['HTTP_HOST'] ?? 'systik.net')) ?>;
const SERVER_PORT = '4443';
const USERS_PER_PAGE = 5;
</script>
<script src="/sstp/assets/app.js"></script>
</body>
</html>
<?php
function formatBytes(int $bytes): string {
if ($bytes <= 0) return '0 B';
$units = ['B','KB','MB','GB','TB'];
$i = floor(log($bytes, 1024));
return round($bytes / pow(1024, $i), 2) . ' ' . $units[$i];
}
?>