const sshenable = document.querySelector('#sshenable') const set_ssh_settings = document.querySelector('#set_ssh_settings') const sshsettingsbody = document.querySelector('#sshsettingsbody') const sshkeystablebody = document.querySelector('#sshkeystablebody') const sshportinput = document.querySelector('#sshportinput') const add_ssh_key_button = document.querySelector('#add_ssh_key') const sshserverinput = document.querySelector('#sshserverinput') let sshkeys = [] // -------------------- SSH status -------------------------------- const get_ssh_status = () => { fetch(routes.ssh_status_get(), { method: 'POST', body: `{"token":"${localStorage.getItem("token")}"}` }).then(data => data.json()).then(jsondata => { if (jsondata.status === '1') { sshenable.checked = true sshsettingsbody.classList.add('active') add_ssh_key_button.classList.add('active') add_ssh_key_button.parentElement.classList.remove('onebutton') } }).catch((error) => { notification(`Ошибка на сервере: ${error}`, "error") }) } const set_ssh_status = () => { fetch(routes.ssh_status_set(), { method: 'POST', body: `{"token":"${localStorage.getItem("token")}","status":"${sshenable.checked ? 1 : 0}"}` }).then(res => res.json()).then(jsondata => { if (jsondata.status === '1') { sshenable.checked = true // telnetsettingbody.classList.add('active') } notification("Настройки SSH сохранены", "success") }).catch((error) => { notification(`Ошибка на сервере: ${error}`, "error") }) } // -------------------------------- end SSH status --------------------------------------- set_ssh_settings.addEventListener('click', () => { if (confirm("Confirm SSH settings?")) { set_ssh_status() set_ssh_port() } }) sshenable.addEventListener('click', () => { if (sshenable.checked) { sshsettingsbody.classList.add('active') add_ssh_key_button.classList.add('active') add_ssh_key_button.parentElement.classList.remove('onebutton') return } sshsettingsbody.classList.remove('active') add_ssh_key_button.classList.remove('active') add_ssh_key_button.parentElement.classList.add('onebutton') }) // -------------------- SSH keys --------------------------------- const get_ssh_keys = () => { fetch(routes.ssh_keys_get(), { method: 'POST', body: `{"token":"${localStorage.getItem("token")}"}` }).then(data => data.json()).then(jsondata => { sshkeys = jsondata.keys sshkeystablebody.innerHTML = "" for (const key in sshkeys) { sshkeystablebody.innerHTML += `