-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
332 lines (307 loc) · 11.4 KB
/
admin.html
File metadata and controls
332 lines (307 loc) · 11.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rustress Admin</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
h2 {
color: #555;
border-bottom: 2px solid #007bff;
padding-bottom: 10px;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
input[type="text"], textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
textarea {
height: 80px;
resize: vertical;
}
button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-right: 10px;
}
button:hover {
background-color: #0056b3;
}
.delete-btn {
background-color: #dc3545;
}
.delete-btn:hover {
background-color: #c82333;
}
.users-list {
margin-top: 30px;
}
.user-row {
display: flex;
align-items: center;
padding: 12px 16px;
margin-bottom: 8px;
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 6px;
font-size: 14px;
}
.user-row:hover {
background: #e9ecef;
}
.user-info {
flex: 1;
display: flex;
gap: 20px;
align-items: center;
}
.user-field {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.user-field strong {
color: #495057;
margin-right: 5px;
}
.username {
min-width: 120px;
font-weight: bold;
color: #007bff;
}
.domain {
min-width: 140px;
}
.nostr-key {
min-width: 150px;
max-width: 200px;
font-family: monospace;
font-size: 12px;
}
.delete-icon-btn {
background: #dc3545;
border: none;
color: white;
width: 32px;
height: 32px;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
margin: 0;
padding: 0;
}
.delete-icon-btn:hover {
background: #c82333;
}
.success {
color: #155724;
background-color: #d4edda;
border: 1px solid #c3e6cb;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
}
.error {
color: #721c24;
background-color: #f8d7da;
border: 1px solid #f5c6cb;
padding: 10px;
border-radius: 4px;
margin-bottom: 15px;
}
.loading {
opacity: 0.6;
pointer-events: none;
}
</style>
</head>
<body>
<div class="container">
<h1>⚡ Rustress Admin Panel</h1>
<div id="message"></div>
<h2>Add New User</h2>
<form id="addUserForm">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="domain">Domain:</label>
<input type="text" id="domain" name="domain" required
placeholder="example.com">
</div>
<div class="form-group">
<label for="nostr_pubkey">Nostr Public Key (npub or hex) - Optional:</label>
<input type="text" id="nostr_pubkey" name="nostr_pubkey"
placeholder="npub1... or hex format (for NIP-05 only)">
</div>
<div class="form-group">
<label for="connection_secret">NWC Connection String - Optional:</label>
<textarea id="connection_secret" name="connection_secret"
placeholder="nostr+walletconnect://... (for LNURL payments only)"></textarea>
<small style="color: #666; font-size: 12px; margin-top: 5px; display: block;">
⚠️ <strong>Security:</strong> Use read-only NWC connections with <strong>make_invoice</strong> permission only.
Never use connections with <strong>pay_invoice</strong> permission as they are stored unencrypted.
</small>
</div>
<button type="submit">Add User</button>
</form>
<div class="users-list">
<h2>Current Users</h2>
<button onclick="loadUsers()">Refresh Users</button>
<div id="usersList"></div>
</div>
</div>
<script>
// Show message to user
function showMessage(message, type = 'success') {
const messageDiv = document.getElementById('message');
messageDiv.innerHTML = `<div class="${type}">${message}</div>`;
setTimeout(() => {
messageDiv.innerHTML = '';
}, 5000);
}
// Add user form submission
document.getElementById('addUserForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const userData = {
username: formData.get('username'),
nostr_pubkey: formData.get('nostr_pubkey'),
connection_secret: formData.get('connection_secret'),
domain: formData.get('domain')
};
// Client-side validation: at least one of nostr_pubkey or connection_secret must be provided
const hasNostrPubkey = userData.nostr_pubkey && userData.nostr_pubkey.trim() !== '';
const hasConnectionSecret = userData.connection_secret && userData.connection_secret.trim() !== '';
if (!hasNostrPubkey && !hasConnectionSecret) {
showMessage('At least one of "Nostr Public Key" (for NIP-05) or "NWC Connection String" (for LNURL) must be provided', 'error');
return;
}
try {
document.body.classList.add('loading');
const response = await fetch('/admin/add', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData)
});
if (response.status === 401) {
showMessage('Session expired. Please refresh the page to login again.', 'error');
setTimeout(() => window.location.reload(), 2000);
return;
}
const result = await response.json();
if (response.ok) {
showMessage(`User "${userData.username || 'auto-generated'}" added successfully! Lightning Address: ${result.lightning_address}`);
e.target.reset();
loadUsers();
} else {
showMessage(`Error: ${result.reason || 'Failed to add user'}`, 'error');
}
} catch (error) {
showMessage(`Error: ${error.message}`, 'error');
} finally {
document.body.classList.remove('loading');
}
});
// Load and display users
async function loadUsers() {
try {
document.body.classList.add('loading');
const response = await fetch('/admin/users');
const users = await response.json();
const usersList = document.getElementById('usersList');
if (users.length === 0) {
usersList.innerHTML = '<p>No users found.</p>';
return;
}
usersList.innerHTML = users.map(user => `
<div class="user-row">
<div class="user-info">
<div class="user-field username">${user.username}</div>
<div class="user-field domain">${user.username}@${user.domain}</div>
<div class="user-field nostr-key" title="${user.nostr_pubkey || 'None'}">${user.nostr_pubkey ? (user.nostr_pubkey.length > 20 ? user.nostr_pubkey.substring(0, 20) + '...' : user.nostr_pubkey) : 'None'}</div>
</div>
<button class="delete-icon-btn" onclick="deleteUser('${user.username}', '${user.domain}')" title="Delete user">
🗑️
</button>
</div>
`).join('');
} catch (error) {
showMessage(`Error loading users: ${error.message}`, 'error');
} finally {
document.body.classList.remove('loading');
}
}
// Delete user
async function deleteUser(username, domain) {
if (!confirm(`Are you sure you want to delete user "${username}@${domain}"?`)) {
return;
}
try {
document.body.classList.add('loading');
const response = await fetch(`/admin/${username}/${domain}`, {
method: 'DELETE'
});
if (response.status === 401) {
showMessage('Session expired. Please refresh the page to login again.', 'error');
setTimeout(() => window.location.reload(), 2000);
return;
}
const result = await response.json();
if (response.ok) {
showMessage(`User "${username}@${domain}" deleted successfully!`);
loadUsers();
} else {
showMessage(`Error: ${result.reason || 'Failed to delete user'}`, 'error');
}
} catch (error) {
showMessage(`Error: ${error.message}`, 'error');
} finally {
document.body.classList.remove('loading');
}
}
// Load users on page load
window.addEventListener('load', loadUsers);
</script>
</body>
</html>