martynka commited on
Commit
cda5d78
·
verified ·
1 Parent(s): 170a8ce

Create index-temp.html

Browse files
Files changed (1) hide show
  1. index-temp.html +103 -0
index-temp.html ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>LibreChat Admin</title>
5
+ <style>
6
+ body { font-family: Arial, sans-serif; margin: 0; padding: 20px; }
7
+ .container { max-width: 1000px; margin: 0 auto; }
8
+ table { width: 100%; border-collapse: collapse; margin-top: 20px; }
9
+ th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
10
+ button { padding: 6px 12px; cursor: pointer; }
11
+ .login-form { max-width: 400px; margin: 50px auto; }
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <div id="login" class="login-form" style="display: block;">
16
+ <h2>Admin Login</h2>
17
+ <input type="password" id="password" placeholder="Admin Password">
18
+ <button onclick="login()">Login</button>
19
+ </div>
20
+
21
+ <div id="admin-panel" class="container" style="display: none;">
22
+ <h1>User Management</h1>
23
+ <div>
24
+ <input type="text" id="new-username" placeholder="Username">
25
+ <input type="password" id="new-password" placeholder="Password">
26
+ <button onclick="addUser()">Add User</button>
27
+ </div>
28
+ <table id="users-table">
29
+ <thead>
30
+ <tr>
31
+ <th>Username</th>
32
+ <th>Actions</th>
33
+ </tr>
34
+ </thead>
35
+ <tbody></tbody>
36
+ </table>
37
+ </div>
38
+
39
+ <script>
40
+ let authToken = '';
41
+ async function login() {
42
+ const password = document.getElementById('password').value;
43
+ const response = await fetch('/sudo/login', {
44
+ method: 'POST',
45
+ headers: { 'Content-Type': 'application/json' },
46
+ body: JSON.stringify({ password })
47
+ });
48
+ if (response.ok) {
49
+ const data = await response.json();
50
+ authToken = data.token;
51
+ document.getElementById('login').style.display = 'none';
52
+ document.getElementById('admin-panel').style.display = 'block';
53
+ loadUsers();
54
+ } else {
55
+ alert('Login failed!');
56
+ }
57
+ }
58
+ async function loadUsers() {
59
+ const response = await fetch('/sudo/users', {
60
+ headers: { 'X-Auth-Token': authToken }
61
+ });
62
+ const users = await response.json();
63
+
64
+ const tbody = document.querySelector('#users-table tbody');
65
+ tbody.innerHTML = users.map(user => `
66
+ <tr>
67
+ <td>${user.username}</td>
68
+ <td>
69
+ <button onclick="deleteUser('${user.username}')">Delete</button>
70
+ </td>
71
+ </tr>
72
+ `).join('');
73
+ }
74
+ async function addUser() {
75
+ const username = document.getElementById('new-username').value;
76
+ const password = document.getElementById('new-password').value;
77
+
78
+ const response = await fetch('/sudo/users', {
79
+ method: 'POST',
80
+ headers: {
81
+ 'Content-Type': 'application/json',
82
+ 'X-Auth-Token': authToken
83
+ },
84
+ body: JSON.stringify({ username, password })
85
+ });
86
+ if (response.ok) {
87
+ loadUsers();
88
+ document.getElementById('new-username').value = '';
89
+ document.getElementById('new-password').value = '';
90
+ }
91
+ }
92
+ async function deleteUser(username) {
93
+ if (confirm(`Delete ${username}?`)) {
94
+ await fetch(`/sudo/users/${username}`, {
95
+ method: 'DELETE',
96
+ headers: { 'X-Auth-Token': authToken }
97
+ });
98
+ loadUsers();
99
+ }
100
+ }
101
+ </script>
102
+ </body>
103
+ </html>