Files
openrouter/src/web/js/settings/ssh.js
T
wt 4b2d425d13
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
added backup restore settings and updated config #3
2025-02-21 12:23:24 +07:00

108 lines
3.6 KiB
JavaScript

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 = () => {
sshenable.checked = settings.ssh.enabled
if (settings.ssh.enabled) {
sshsettingsbody.classList.add('active')
add_ssh_key_button.classList.add('active')
add_ssh_key_button.parentElement.classList.remove('onebutton')
} else {
sshsettingsbody.classList.remove('active')
add_ssh_key_button.classList.remove('active')
add_ssh_key_button.parentElement.classList.add('onebutton')
}
}
const set_ssh_settings_func = () => {
settings.ssh.enabled = sshenable.checked
settings.ssh.keys = sshkeys
settings.ssh.port = sshportinput.value
settings.ssh.server = sshserverinput.options[sshserverinput.selectedIndex].value
set_all_settings()
sshenable.checked = settings.ssh.enabled
get_ssh_keys()
sshportinput.value = settings.ssh.port
for (let i = 0; i < sshserverinput.options.length; i++) {
if (sshserverinput.options[i].value === settings.ssh.server) {
sshserverinput.selectedIndex = i;
break;
}
}
}
set_ssh_settings.addEventListener('click', () => {
if (confirm("Confirm SSH settings?")) {
set_ssh_settings_func()
}
})
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 = () => {
sshkeys = settings.ssh.keys
sshkeystablebody.innerHTML = ""
for (const key in sshkeys) {
sshkeystablebody.innerHTML += `<tr>
<td class="one" style="flex-direction:column;align-items:start;">
${sshkeys[key]}
<button class="delsshkeybutton" id="${key}">Del</button>
</td>
</tr>`
}
}
// ------------------- end SSH keys ------------------------------
sshkeystablebody.addEventListener('click', (e) => {
if (e.target.classList.contains('delsshkeybutton')) {
if (confirm(`Confirm SSH settings?: (delete SSH key)`)) {
sshkeys.splice(e.target.id)
set_ssh_settings_func()
}
}
})
add_ssh_key_button.addEventListener('click', () => {
const sshkey = prompt('Get your SSH key:')
if (sshkey === null) return
if (confirm('Confirm SSH settings? (add SSH key)')) {
sshkeys.push(sshkey)
set_ssh_settings_func()
}
})
// -------------------- SSH port ----------------------
const get_ssh_port = () => {
sshportinput.value = settings.ssh.port
}
// ------------------- end SSH port -------------------
const get_ssh_server = () => {
for (let i = 0; i < sshserverinput.options.length; i++) {
if (sshserverinput.options[i].value === settings.ssh.server) {
sshserverinput.selectedIndex = i;
break;
}
}
}