Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>TURN Server Admin Panel</title> | |
<style> | |
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; } | |
h1 { color: #333; } | |
form { margin-bottom: 20px; } | |
input { margin: 5px 0; padding: 5px; } | |
button { padding: 5px 10px; background-color: #4CAF50; color: white; border: none; cursor: pointer; } | |
ul { list-style-type: none; padding: 0; } | |
li { margin-bottom: 10px; } | |
</style> | |
</head> | |
<body> | |
<h1>TURN Server Admin Panel</h1> | |
<form id="addUserForm"> | |
<input type="text" id="username" placeholder="Username" required> | |
<input type="password" id="password" placeholder="Password" required> | |
<button type="submit">Add User</button> | |
</form> | |
<h2>Current Users</h2> | |
<ul id="userList"></ul> | |
<script> | |
function fetchUsers() { | |
fetch('/users') | |
.then(response => response.json()) | |
.then(users => { | |
const userList = document.getElementById('userList'); | |
userList.innerHTML = ''; | |
users.forEach(user => { | |
const li = document.createElement('li'); | |
li.textContent = user.username; | |
const removeButton = document.createElement('button'); | |
removeButton.textContent = 'Remove'; | |
removeButton.onclick = () => removeUser(user.username); | |
li.appendChild(removeButton); | |
userList.appendChild(li); | |
}); | |
}); | |
} | |
function addUser(username, password) { | |
fetch('/addUser', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify({ username, password }) | |
}).then(() => fetchUsers()); | |
} | |
function removeUser(username) { | |
fetch('/removeUser', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify({ username }) | |
}).then(() => fetchUsers()); | |
} | |
document.getElementById('addUserForm').onsubmit = (e) => { | |
e.preventDefault(); | |
const username = document.getElementById('username').value; | |
const password = document.getElementById('password').value; | |
addUser(username, password); | |
e.target.reset(); | |
}; | |
fetchUsers(); | |
</script> | |
</body> | |
</html> |