added telnet and reboot control, openrouterinit script

This commit is contained in:
wt committed 2024-06-26 15:59:10 +07:00
1 parent 0937112f04
commit 5279a9a6a6
23 files changed
+839 -26

No files matched your search

+28 -17
View File
@@ -3,12 +3,15 @@ const loginformbody = document.querySelector('.loginformbody')
const loginusername = document.querySelector("#loginusernameinput")
const loginpassword = document.querySelector("#loginpasswordinput")
const exitbutton = document.querySelector('.exitbutton')
console.log(localStorage.getItem("token"))
const adminpanelsection = document.querySelector('.adminpanel')
const headerusername = document.querySelector('.headerusername')
if (localStorage.getItem("token") === null) {
adminpanelsection.classList.remove('active')
loginform.classList.add('active')
// loginform.style.background = "initial"
} else {
adminpanelsection.classList.add('active')
headerusername.innerHTML = JSON.parse(localStorage.getItem('userdata')).username
}
loginformbody.addEventListener('submit', (e) => {
@@ -19,39 +22,47 @@ loginformbody.addEventListener('submit', (e) => {
const login = async (username, password) => {
const response = await fetch(routes.login(), {
method: 'POST',
headers: {
Accept: 'application/json',
// 'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
// mode: 'no-cors',
body: `{"username":"${username}","password":"${password}"}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
if (error.message === "Unexpected end of JSON input") {
console.log("error")
// notification(`Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, "error")
notification(`Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, "error")
} else {
console.log("error")
// notification(`Ошибка на сервере: ${error}`, "error")
notification(`Ошибка на сервере: ${error}`, "error")
}
})
if (response.status === "403") {
console.log("Неправильный логин или пароль")
// notification("Неправильный логин или пароль", "error")
notification("Неправильный логин или пароль", "error")
}
if (response.token) {
// notification("Успешно", "success")
notification("Успешно", "success")
loginform.classList.remove("active")
localStorage.setItem("token", response.token)
adminpanelsection.classList.add('active')
await get_user_data()
loginforminputusername.value = ""
loginforminputpassword.value = ""
loginusername.value = ""
loginpassword.value = ""
}
}
const get_user_data = async () => {
const response = await fetch(routes.user(), {
method: "POST",
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
if (response.id) {
headerusername.innerHTML = response.username
localStorage.setItem("userdata", JSON.stringify(response))
}
}
exitbutton.addEventListener('click', () => {
localStorage.clear()
loginform.classList.add('active')
loginusername.value = ""
loginpassword = ""
notification('Вы вышли', "success")
adminpanelsection.classList.remove('active')
})