2023-05-17 21:40:37 +00:00
|
|
|
import { API, organization } from "/vars.js";
|
2023-01-19 19:58:44 +00:00
|
|
|
|
2023-05-15 20:36:28 +00:00
|
|
|
export const resources_config = {
|
2023-01-19 20:33:05 +00:00
|
|
|
disk: {
|
2023-02-10 21:36:47 +00:00
|
|
|
actionBarOrder: ["move", "resize", "detach_attach", "delete"],
|
2023-01-19 20:33:05 +00:00
|
|
|
lxc: {
|
|
|
|
prefixOrder: ["rootfs", "mp", "unused"],
|
2023-05-17 21:40:37 +00:00
|
|
|
rootfs: { name: "ROOTFS", icon: "images/resources/drive.svg", actions: ["move", "resize"] },
|
|
|
|
mp: { name: "MP", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"] },
|
|
|
|
unused: { name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"] }
|
2023-01-19 20:33:05 +00:00
|
|
|
},
|
|
|
|
qemu: {
|
|
|
|
prefixOrder: ["ide", "sata", "unused"],
|
2023-05-17 21:40:37 +00:00
|
|
|
ide: { name: "IDE", icon: "images/resources/disk.svg", actions: ["delete"] },
|
|
|
|
sata: { name: "SATA", icon: "images/resources/drive.svg", actions: ["detach", "move", "reassign", "resize"] },
|
|
|
|
unused: { name: "UNUSED", icon: "images/resources/drive.svg", actions: ["attach", "delete", "reassign"] }
|
2023-01-19 20:33:05 +00:00
|
|
|
}
|
2023-05-15 21:22:12 +00:00
|
|
|
},
|
|
|
|
network: {
|
|
|
|
prefix: "net"
|
2023-01-19 20:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 20:36:28 +00:00
|
|
|
export const instances_config = {
|
2023-01-26 20:50:15 +00:00
|
|
|
running: {
|
2023-04-06 21:21:11 +00:00
|
|
|
statusSrc: "images/status/active.svg",
|
|
|
|
statusAlt: "Instance is running",
|
2023-02-21 21:50:54 +00:00
|
|
|
powerButtonSrc: "images/actions/instance/stop.svg",
|
2023-02-01 00:02:10 +00:00
|
|
|
powerButtonAlt: "Shutdown Instance",
|
2023-02-21 21:50:54 +00:00
|
|
|
configButtonSrc: "images/actions/instance/config-inactive.svg",
|
2023-02-21 19:57:47 +00:00
|
|
|
configButtonAlt: "Change Configuration (Inactive)",
|
2023-02-21 21:50:54 +00:00
|
|
|
consoleButtonSrc: "images/actions/instance/console-active.svg",
|
2023-02-21 19:57:47 +00:00
|
|
|
consoleButtonAlt: "Open Console",
|
|
|
|
deleteButtonSrc: "images/actions/delete-inactive.svg",
|
|
|
|
deleteButtonAlt: "Delete Instance (Inactive)"
|
2023-01-26 20:50:15 +00:00
|
|
|
},
|
|
|
|
stopped: {
|
2023-04-06 21:21:11 +00:00
|
|
|
statusSrc: "images/status/inactive.svg",
|
|
|
|
statusAlt: "Instance is stopped",
|
2023-02-21 21:50:54 +00:00
|
|
|
powerButtonSrc: "images/actions/instance/start.svg",
|
2023-02-01 00:02:10 +00:00
|
|
|
powerButtonAlt: "Start Instance",
|
2023-02-21 21:50:54 +00:00
|
|
|
configButtonSrc: "images/actions/instance/config-active.svg",
|
2023-02-21 19:57:47 +00:00
|
|
|
configButtonAlt: "Change Configuration",
|
2023-02-21 21:50:54 +00:00
|
|
|
consoleButtonSrc: "images/actions/instance/console-inactive.svg",
|
2023-02-21 19:57:47 +00:00
|
|
|
consoleButtonAlt: "Open Console (Inactive)",
|
|
|
|
deleteButtonSrc: "images/actions/delete-active.svg",
|
|
|
|
deleteButtonAlt: "Delete Instance"
|
2023-01-26 20:50:15 +00:00
|
|
|
},
|
|
|
|
loading: {
|
2023-04-06 21:21:11 +00:00
|
|
|
statusSrc: "images/status/loading.svg",
|
|
|
|
statusAlt: "Instance is loading",
|
|
|
|
powerButtonSrc: "images/status/loading.svg",
|
2023-02-01 00:02:10 +00:00
|
|
|
powerButtonAlt: "Loading Instance",
|
2023-02-21 21:50:54 +00:00
|
|
|
configButtonSrc: "images/actions/instance/config-inactive.svg",
|
2023-02-21 19:57:47 +00:00
|
|
|
configButtonAlt: "Change Configuration (Inactive)",
|
2023-02-21 21:50:54 +00:00
|
|
|
consoleButtonSrc: "images/actions/instance/console-inactive.svg",
|
2023-02-21 19:57:47 +00:00
|
|
|
consoleButtonAlt: "Open Console (Inactive)",
|
|
|
|
deleteButtonSrc: "images/actions/delete-inactive.svg",
|
|
|
|
deleteButtonAlt: "Delete Instance (Inactive)"
|
2023-01-26 20:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 20:36:28 +00:00
|
|
|
export const nodes_config = {
|
2023-04-06 21:21:11 +00:00
|
|
|
online: {
|
|
|
|
statusSrc: "images/status/active.svg",
|
|
|
|
statusAlt: "Node is online",
|
|
|
|
},
|
|
|
|
offline: {
|
|
|
|
statusSrc: "images/status/inactive.svg",
|
|
|
|
statusAlt: "Node is offline",
|
|
|
|
},
|
|
|
|
uknown: {
|
|
|
|
statusSrc: "images/status/inactive.svg",
|
|
|
|
statusAlt: "Node status is unknown",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:21:45 +00:00
|
|
|
export function getCookie(cname) {
|
2022-12-16 07:40:04 +00:00
|
|
|
let name = cname + "=";
|
|
|
|
let decodedCookie = decodeURIComponent(document.cookie);
|
2022-12-18 00:07:18 +00:00
|
|
|
let ca = decodedCookie.split(";");
|
2023-05-17 21:40:37 +00:00
|
|
|
for (let i = 0; i < ca.length; i++) {
|
2022-12-16 07:40:04 +00:00
|
|
|
let c = ca[i];
|
2022-12-18 00:07:18 +00:00
|
|
|
while (c.charAt(0) === " ") {
|
2022-12-16 07:40:04 +00:00
|
|
|
c = c.substring(1);
|
|
|
|
}
|
2022-12-18 00:07:18 +00:00
|
|
|
if (c.indexOf(name) === 0) {
|
2022-12-16 07:40:04 +00:00
|
|
|
return c.substring(name.length, c.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export async function requestTicket(username, password, realm) {
|
|
|
|
let response = await requestAPI("/ticket", "POST", { username: `${username}@${realm}`, password: password }, false);
|
2022-12-13 00:21:33 +00:00
|
|
|
return response;
|
2022-12-11 06:49:10 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export async function requestPVE(path, method, body = null) {
|
2022-12-11 06:49:10 +00:00
|
|
|
let prms = new URLSearchParams(body);
|
2023-01-25 02:06:31 +00:00
|
|
|
let content = {
|
|
|
|
method: method,
|
|
|
|
mode: "cors",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 21:40:37 +00:00
|
|
|
if (method === "POST") {
|
2023-01-25 02:06:31 +00:00
|
|
|
content.body = prms.toString();
|
|
|
|
content.headers.CSRFPreventionToken = getCookie("CSRFPreventionToken");
|
|
|
|
}
|
|
|
|
|
2023-02-24 22:25:36 +00:00
|
|
|
let response = await request(`${API}/proxmox${path}`, content);
|
2023-01-25 02:06:31 +00:00
|
|
|
return response;
|
|
|
|
}
|
2022-12-13 00:00:11 +00:00
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export async function requestAPI(path, method, body = null) {
|
2023-01-25 02:06:31 +00:00
|
|
|
let prms = new URLSearchParams(body);
|
2022-12-13 00:00:11 +00:00
|
|
|
let content = {
|
2022-12-11 06:49:10 +00:00
|
|
|
method: method,
|
|
|
|
mode: "cors",
|
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
2022-12-13 00:18:40 +00:00
|
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
2022-12-11 06:49:10 +00:00
|
|
|
}
|
2022-12-13 00:00:11 +00:00
|
|
|
}
|
2023-02-21 22:50:01 +00:00
|
|
|
if (method === "POST" || method === "DELETE") {
|
2022-12-16 07:44:48 +00:00
|
|
|
content.headers.CSRFPreventionToken = getCookie("CSRFPreventionToken");
|
2022-12-11 06:49:10 +00:00
|
|
|
}
|
2023-02-01 23:42:30 +00:00
|
|
|
if (body) {
|
|
|
|
content.body = prms.toString();
|
|
|
|
}
|
2022-12-13 00:00:11 +00:00
|
|
|
|
2023-01-27 21:49:50 +00:00
|
|
|
let response = await request(`${API}${path}`, content);
|
2023-01-25 02:06:31 +00:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
async function request(url, content) {
|
2022-12-13 00:00:11 +00:00
|
|
|
|
2023-05-15 22:41:54 +00:00
|
|
|
let response = await fetch(url, content);
|
|
|
|
let data = null;
|
|
|
|
try {
|
|
|
|
data = await response.json();
|
|
|
|
data.status = response.status;
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
data = null;
|
2023-04-19 21:11:35 +00:00
|
|
|
}
|
2023-05-15 22:41:54 +00:00
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
if (!response.ok) {
|
|
|
|
return { status: response.status, error: data ? data.error : response.status };
|
2023-04-19 21:11:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.status = response.status;
|
2023-05-15 22:41:54 +00:00
|
|
|
return data ? data : response;
|
2023-03-24 21:13:33 +00:00
|
|
|
}
|
2022-12-19 05:52:39 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export function goToPage(page, data = {}, newwindow = false) {
|
2023-02-17 05:12:28 +00:00
|
|
|
let url = new URL(`https://${window.location.host}/${page}`);
|
2023-05-17 21:40:37 +00:00
|
|
|
for (let k in data) {
|
2023-02-17 05:12:28 +00:00
|
|
|
url.searchParams.append(k, data[k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newwindow) {
|
2023-05-16 15:18:36 +00:00
|
|
|
window.open(url, `${organization} - client`, "height=480,width=848");
|
2023-02-17 05:12:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.location.assign(url.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export function goToURL(href, data = {}, newwindow = false) {
|
2023-02-17 05:12:28 +00:00
|
|
|
let url = new URL(href);
|
2023-05-17 21:40:37 +00:00
|
|
|
for (let k in data) {
|
2022-12-19 05:52:39 +00:00
|
|
|
url.searchParams.append(k, data[k]);
|
|
|
|
}
|
2023-02-14 05:36:21 +00:00
|
|
|
|
|
|
|
if (newwindow) {
|
2023-05-16 15:18:36 +00:00
|
|
|
window.open(url, `${organization} - client`, "height=480,width=848");
|
2023-02-14 05:36:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.location.assign(url.toString());
|
|
|
|
}
|
2022-12-19 06:14:57 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export function getURIData() {
|
2022-12-19 06:14:57 +00:00
|
|
|
let url = new URL(window.location.href);
|
|
|
|
return Object.fromEntries(url.searchParams);
|
2023-01-09 23:08:45 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export async function deleteAllCookies() {
|
2023-05-13 07:28:09 +00:00
|
|
|
await requestAPI("/ticket", "DELETE");
|
2023-05-16 15:18:36 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:40:37 +00:00
|
|
|
export function setTitleAndHeader() {
|
2023-05-16 15:18:36 +00:00
|
|
|
document.title = `${organization} - client`;
|
|
|
|
document.querySelector("h1").innerText = organization;
|
2022-12-11 06:49:10 +00:00
|
|
|
}
|