summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-09-22 22:14:36 +0300
committerMaxim Devaev <[email protected]>2024-09-23 02:32:23 +0300
commit5ed368769c889628ebae896556e5c6401cbafdaf (patch)
treeecaa45df14240683a14308a158761b5ac3cc3139 /web
parent1217144ecd476e28cfe43d7454a5224aa7fe7b7a (diff)
refactoring
Diffstat (limited to 'web')
-rw-r--r--web/share/js/index/main.js4
-rw-r--r--web/share/js/ipmi/main.js2
-rw-r--r--web/share/js/kvm/atx.js2
-rw-r--r--web/share/js/kvm/gpio.js4
-rw-r--r--web/share/js/kvm/hid.js10
-rw-r--r--web/share/js/kvm/msd.js10
-rw-r--r--web/share/js/kvm/ocr.js16
-rw-r--r--web/share/js/kvm/recorder.js12
-rw-r--r--web/share/js/kvm/session.js2
-rw-r--r--web/share/js/kvm/stream.js4
-rw-r--r--web/share/js/login/main.js2
-rw-r--r--web/share/js/tools.js16
-rw-r--r--web/share/js/vnc/main.js2
13 files changed, 48 insertions, 38 deletions
diff --git a/web/share/js/index/main.js b/web/share/js/index/main.js
index 3a0afb45..38c848c7 100644
--- a/web/share/js/index/main.js
+++ b/web/share/js/index/main.js
@@ -51,7 +51,7 @@ function __setAppText() {
}
function __loadKvmdInfo() {
- tools.httpGet("/api/info?fields=auth,meta,extras", function(http) {
+ tools.httpGet("/api/info", {"fields": "auth,meta,extras"}, function(http) {
if (http.status === 200) {
let info = JSON.parse(http.responseText).result;
@@ -121,7 +121,7 @@ function __makeApp(id, path, icon, name) {
}
function __logout() {
- tools.httpPost("/api/auth/logout", function(http) {
+ tools.httpPost("/api/auth/logout", null, function(http) {
if (http.status === 200 || http.status === 401 || http.status === 403) {
document.location.href = "/login";
} else {
diff --git a/web/share/js/ipmi/main.js b/web/share/js/ipmi/main.js
index 237b4005..26bd1f38 100644
--- a/web/share/js/ipmi/main.js
+++ b/web/share/js/ipmi/main.js
@@ -31,7 +31,7 @@ export function main() {
}
function __loadKvmdInfo() {
- tools.httpGet("/api/info", function(http) {
+ tools.httpGet("/api/info", null, function(http) {
if (http.status === 200) {
let ipmi_port = JSON.parse(http.responseText).result.extras.ipmi.port;
let make_item = (comment, ipmi, api) => `
diff --git a/web/share/js/kvm/atx.js b/web/share/js/kvm/atx.js
index 53c290cf..2a0e38f9 100644
--- a/web/share/js/kvm/atx.js
+++ b/web/share/js/kvm/atx.js
@@ -73,7 +73,7 @@ export function Atx(__recorder) {
var __clickButton = function(button, confirm_msg) {
let click_button = function() {
- tools.httpPost(`/api/atx/click?button=${button}`, function(http) {
+ tools.httpPost("/api/atx/click", {"button": button}, function(http) {
if (http.status === 409) {
wm.error("Performing another ATX operation for other client.<br>Please try again later");
} else if (http.status !== 200) {
diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js
index 4bee901a..fe326205 100644
--- a/web/share/js/kvm/gpio.js
+++ b/web/share/js/kvm/gpio.js
@@ -181,7 +181,7 @@ export function Gpio(__recorder) {
confirm = el.getAttribute("data-confirm-off");
}
let act = () => {
- __sendPost(`/api/gpio/switch?channel=${channel}&state=${to}`);
+ __sendPost("/api/gpio/switch", {"channel": channel, "state": to});
__recorder.recordGpioSwitchEvent(channel, to);
};
if (confirm) {
@@ -201,7 +201,7 @@ export function Gpio(__recorder) {
let channel = el.getAttribute("data-channel");
let confirm = el.getAttribute("data-confirm");
let act = () => {
- __sendPost(`/api/gpio/pulse?channel=${channel}`);
+ __sendPost("/api/gpio/pulse", {"channel": channel});
__recorder.recordGpioPulseEvent(channel);
};
if (confirm) {
diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js
index 6ca87748..ef16bcaf 100644
--- a/web/share/js/kvm/hid.js
+++ b/web/share/js/kvm/hid.js
@@ -253,7 +253,7 @@ export function Hid(__getGeometry, __recorder) {
tools.debug(`HID: paste-as-keys ${keymap}: ${text}`);
- tools.httpPost(`/api/hid/print?limit=0&keymap=${keymap}`, function(http) {
+ tools.httpPost("/api/hid/print", {"limit": 0, "keymap": keymap}, function(http) {
tools.el.setEnabled($("hid-pak-text"), true);
tools.el.setEnabled($("hid-pak-button"), true);
tools.el.setEnabled($("hid-pak-keymap-selector"), true);
@@ -286,7 +286,7 @@ export function Hid(__getGeometry, __recorder) {
var __clickOutputsRadio = function(hid) {
let output = tools.radio.getValue(`hid-outputs-${hid}-radio`);
- tools.httpPost(`/api/hid/set_params?${hid}_output=${output}`, function(http) {
+ tools.httpPost("/api/hid/set_params", {[`${hid}_output`]: output}, function(http) {
if (http.status !== 200) {
wm.error("Can't configure HID:<br>", http.responseText);
}
@@ -295,7 +295,7 @@ export function Hid(__getGeometry, __recorder) {
var __clickJigglerSwitch = function() {
let enabled = $("hid-jiggler-switch").checked;
- tools.httpPost(`/api/hid/set_params?jiggler=${enabled}`, function(http) {
+ tools.httpPost("/api/hid/set_params", {"jiggler": enabled}, function(http) {
if (http.status !== 200) {
wm.error(`Can't ${enabled ? "enabled" : "disable"} mouse juggler:<br>`, http.responseText);
}
@@ -304,7 +304,7 @@ export function Hid(__getGeometry, __recorder) {
var __clickConnectSwitch = function() {
let connected = $("hid-connect-switch").checked;
- tools.httpPost(`/api/hid/set_connected?connected=${connected}`, function(http) {
+ tools.httpPost("/api/hid/set_connected", {"connected": connected}, function(http) {
if (http.status !== 200) {
wm.error(`Can't ${connected ? "connect" : "disconnect"} HID:<br>`, http.responseText);
}
@@ -314,7 +314,7 @@ export function Hid(__getGeometry, __recorder) {
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset HID (keyboard & mouse)?").then(function(ok) {
if (ok) {
- tools.httpPost("/api/hid/reset", function(http) {
+ tools.httpPost("/api/hid/reset", null, function(http) {
if (http.status !== 200) {
wm.error("HID reset error:<br>", http.responseText);
}
diff --git a/web/share/js/kvm/msd.js b/web/share/js/kvm/msd.js
index 662c04e4..88491a23 100644
--- a/web/share/js/kvm/msd.js
+++ b/web/share/js/kvm/msd.js
@@ -86,9 +86,9 @@ export function Msd() {
var __clickRemoveButton = function() {
let name = $("msd-image-selector").value;
- wm.confirm(`Are you sure you want to remove the image<br><b>${name}</b> from PiKVM?`).then(function(ok) {
+ wm.confirm(`Are you sure you want to remove the image<br><b>${tools.escape(name)}</b> from PiKVM?`).then(function(ok) {
if (ok) {
- tools.httpPost(`/api/msd/remove?image=${name}`, function(http) {
+ tools.httpPost("/api/msd/remove", {"image": name}, function(http) {
if (http.status !== 200) {
wm.error("Can't remove image:<br>", http.responseText);
}
@@ -98,7 +98,7 @@ export function Msd() {
};
var __sendParam = function(name, value) {
- tools.httpPost(`/api/msd/set_params?${name}=${encodeURIComponent(value)}`, function(http) {
+ tools.httpPost("/api/msd/set_params", {[name]: value}, function(http) {
if (http.status !== 200) {
wm.error("Can't configure MSD:<br>", http.responseText);
}
@@ -164,7 +164,7 @@ export function Msd() {
};
var __clickConnectButton = function(connected) {
- tools.httpPost(`/api/msd/set_connected?connected=${connected}`, function(http) {
+ tools.httpPost("/api/msd/set_connected", {"connected": connected}, function(http) {
if (http.status !== 200) {
wm.error("Switch error:<br>", http.responseText);
}
@@ -177,7 +177,7 @@ export function Msd() {
var __clickResetButton = function() {
wm.confirm("Are you sure you want to reset Mass Storage Drive?").then(function(ok) {
if (ok) {
- tools.httpPost("/api/msd/reset", function(http) {
+ tools.httpPost("/api/msd/reset", null, function(http) {
if (http.status !== 200) {
wm.error("MSD reset error:<br>", http.responseText);
}
diff --git a/web/share/js/kvm/ocr.js b/web/share/js/kvm/ocr.js
index 94c9d563..13e1b887 100644
--- a/web/share/js/kvm/ocr.js
+++ b/web/share/js/kvm/ocr.js
@@ -161,13 +161,15 @@ export function Ocr(__getGeometry) {
tools.el.setEnabled($("stream-ocr-button"), false);
tools.el.setEnabled($("stream-ocr-lang-selector"), false);
$("stream-ocr-led").className = "led-yellow-rotating-fast";
-
- let lang = $("stream-ocr-lang-selector").value;
- let url = `/api/streamer/snapshot?ocr=1&ocr_langs=${lang}`;
- url += `&ocr_left=${__selection.left}&ocr_top=${__selection.top}`;
- url += `&ocr_right=${__selection.right}&ocr_bottom=${__selection.bottom}`;
-
- tools.httpGet(url, function(http) {
+ let params = {
+ "ocr": 1,
+ "ocr_langs": $("stream-ocr-lang-selector").value,
+ "ocr_left": __selection.left,
+ "ocr_top": __selection.top,
+ "ocr_right": __selection.right,
+ "orc_bottom": __selection.bottom,
+ };
+ tools.httpGet("/api/streamer/snapshot", params, function(http) {
if (http.status === 200) {
wm.copyTextToClipboard(http.responseText);
} else {
diff --git a/web/share/js/kvm/recorder.js b/web/share/js/kvm/recorder.js
index 03ec39b5..7ba0b3cb 100644
--- a/web/share/js/kvm/recorder.js
+++ b/web/share/js/kvm/recorder.js
@@ -280,7 +280,7 @@ export function Recorder() {
return;
} else if (event.event_type === "print") {
- tools.httpPost("/api/hid/print?limit=0", function(http) {
+ tools.httpPost("/api/hid/print", {"limit": 0}, function(http) {
if (http.status === 413) {
wm.error("Too many text for paste!");
__stopProcess();
@@ -294,7 +294,7 @@ export function Recorder() {
return;
} else if (event.event_type === "atx_button") {
- tools.httpPost(`/api/atx/click?button=${event.event.button}`, function(http) {
+ tools.httpPost("/api/atx/click", {"button": event.event.button}, function(http) {
if (http.status !== 200) {
wm.error("ATX error:<br>", http.responseText);
__stopProcess();
@@ -306,12 +306,14 @@ export function Recorder() {
} else if (["gpio_switch", "gpio_pulse"].includes(event.event_type)) {
let path = "/api/gpio";
+ let params = {"channel": event.event.channel};
if (event.event_type === "gpio_switch") {
- path += `/switch?channel=${event.event.channel}&state=${event.event.to}`;
+ path += "/switch";
+ params["state"] = event.event.to;
} else { // gpio_pulse
- path += `/pulse?channel=${event.event.channel}`;
+ path += "/pulse";
}
- tools.httpPost(path, function(http) {
+ tools.httpPost(path, params, function(http) {
if (http.status !== 200) {
wm.error("GPIO error:<br>", http.responseText);
__stopProcess();
diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js
index 98070927..8100f50c 100644
--- a/web/share/js/kvm/session.js
+++ b/web/share/js/kvm/session.js
@@ -280,7 +280,7 @@ export function Session() {
$("link-led").className = "led-yellow";
$("link-led").title = "Connecting...";
- tools.httpGet("/api/auth/check", function(http) {
+ tools.httpGet("/api/auth/check", null, function(http) {
if (http.status === 200) {
__ws = new WebSocket(`${tools.is_https ? "wss" : "ws"}://${location.host}/api/ws`);
__ws.sendHidEvent = (event) => __sendHidEvent(__ws, event.event_type, event.event);
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js
index b811a657..1b93e7c4 100644
--- a/web/share/js/kvm/stream.js
+++ b/web/share/js/kvm/stream.js
@@ -295,7 +295,7 @@ export function Streamer() {
wm.confirm("Are you sure you want to reset stream?").then(function (ok) {
if (ok) {
__resetStream();
- tools.httpPost("/api/streamer/reset", function(http) {
+ tools.httpPost("/api/streamer/reset", null, function(http) {
if (http.status !== 200) {
wm.error("Can't reset stream:<br>", http.responseText);
}
@@ -305,7 +305,7 @@ export function Streamer() {
};
var __sendParam = function(name, value) {
- tools.httpPost(`/api/streamer/set_params?${name}=${value}`, function(http) {
+ tools.httpPost("/api/streamer/set_params", {[name]: value}, function(http) {
if (http.status !== 200) {
wm.error("Can't configure stream:<br>", http.responseText);
}
diff --git a/web/share/js/login/main.js b/web/share/js/login/main.js
index 4ffa276a..58e7c80d 100644
--- a/web/share/js/login/main.js
+++ b/web/share/js/login/main.js
@@ -51,7 +51,7 @@ function __login() {
} else {
let passwd = $("passwd-input").value + $("code-input").value;
let body = `user=${encodeURIComponent(user)}&passwd=${encodeURIComponent(passwd)}`;
- tools.httpPost("/api/auth/login", function(http) {
+ tools.httpPost("/api/auth/login", null, function(http) {
if (http.status === 200) {
document.location.href = "/";
} else if (http.status === 403) {
diff --git a/web/share/js/tools.js b/web/share/js/tools.js
index 48f5b420..ee3bc187 100644
--- a/web/share/js/tools.js
+++ b/web/share/js/tools.js
@@ -39,7 +39,13 @@ export var tools = new function() {
/************************************************************************/
- self.httpRequest = function(method, url, callback, body=null, content_type=null, timeout=15000) {
+ self.httpRequest = function(method, url, params, callback, body=null, content_type=null, timeout=15000) {
+ if (params) {
+ params = new URLSearchParams(params);
+ if (params) {
+ url += "?" + params;
+ }
+ }
let http = new XMLHttpRequest();
http.open(method, url, true);
if (content_type) {
@@ -54,12 +60,12 @@ export var tools = new function() {
http.send(body);
};
- self.httpGet = function(url, callback, body=null, content_type=null, timeout=15000) {
- self.httpRequest("GET", url, callback, body, content_type, timeout);
+ self.httpGet = function(url, params, callback, body=null, content_type=null, timeout=15000) {
+ self.httpRequest("GET", url, params, callback, body, content_type, timeout);
};
- self.httpPost = function(url, callback, body=null, content_type=null, timeout=15000) {
- self.httpRequest("POST", url, callback, body, content_type, timeout);
+ self.httpPost = function(url, params, callback, body=null, content_type=null, timeout=15000) {
+ self.httpRequest("POST", url, params, callback, body, content_type, timeout);
};
/************************************************************************/
diff --git a/web/share/js/vnc/main.js b/web/share/js/vnc/main.js
index 965c7e9e..64294e3b 100644
--- a/web/share/js/vnc/main.js
+++ b/web/share/js/vnc/main.js
@@ -31,7 +31,7 @@ export function main() {
}
function __loadKvmdInfo() {
- tools.httpGet("/api/info", function(http) {
+ tools.httpGet("/api/info", null, function(http) {
if (http.status === 200) {
let vnc_port = JSON.parse(http.responseText).result.extras.vnc.port;
$("vnc-text").innerHTML = `