From b35e3fd4b48b5a547c39ed979c94aed3bf489f4c Mon Sep 17 00:00:00 2001 From: crazymath072 <102372274+CR072@users.noreply.github.com> Date: Sat, 23 Dec 2023 17:23:17 +0530 Subject: [PATCH 1/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1042fe..568ac06 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ If you download from the [Releases](https://github.com/ManucrackYT/LapsusClient/ The best way to contact the developers is on Discord. -[![discord](https://discordapp.com/api/guilds/954138561509203978/embed.png?style=banner3)][discord] +[![discord](https://discordapp.com/api/guilds/954138561509203978/embed.png?style=banner3)](https://discord.gg/) --- From 9a7b4f3a0e5b746515f1ef430809bc9307ca686c Mon Sep 17 00:00:00 2001 From: crazymath072 <102372274+CR072@users.noreply.github.com> Date: Sat, 23 Dec 2023 17:45:33 +0530 Subject: [PATCH 2/6] Added server control feature --- api/power.js | 77 +++++++++++++++++++++++++++++++++++++++ settings.json | 3 +- themes/lapsus/servers.ejs | 41 ++++++++++++++++++++- 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 api/power.js diff --git a/api/power.js b/api/power.js new file mode 100644 index 0000000..dd9c72b --- /dev/null +++ b/api/power.js @@ -0,0 +1,77 @@ +const settings = require("../settings.json"); +const fetch = require('node-fetch'); + +module.exports.load = async function(app, db) { + app.get("/api/servers/start", async (req, res) => { + if (!req.session.pterodactyl) return res.redirect("/login"); + const id = req.query.id; + const user = req.query.user; + + if (!id || !user) { + return; + } + + if (user != req.session.userinfo.id) { + return res.json({ "success": false, "message": "Unauthorized request" }); + } + + try { + const response = await fetch(`${settings.pterodactyl.domain}/api/client/servers/${id}/power`, { + method: "POST", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Authorization": `Bearer ${settings.pterodactyl.account_key}` + }, + body: JSON.stringify({ signal: "start" }) + }); + + if (!response.ok) { + console.error(`Failed to start server. Status: ${response.status}`); + return res.json({ "success": false, "message": "Failed to start server" }); + } + + console.log("Server started successfully"); + return res.json({ "success": true, "message": "Operation success!" }); + } catch (error) { + console.error("Error during server start request:", error); + return res.json({ "success": false, "message": "Internal server error" }); + } + }); + app.get("/api/servers/stop", async (req, res) => { + if (!req.session.pterodactyl) return res.redirect("/login"); + const id = req.query.id; + const user = req.query.user; + + if (!id || !user) { + return; + } + + if (user != req.session.userinfo.id) { + return res.json({ "success": false, "message": "Unauthorized request" }); + } + + try { + const response = await fetch(`${settings.pterodactyl.domain}/api/client/servers/${id}/power`, { + method: "POST", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Authorization": `Bearer ${settings.pterodactyl.account_key}` + }, + body: JSON.stringify({ signal: "stop" }) + }); + + if (!response.ok) { + console.error(`Failed to start server. Status: ${response.status}`); + return res.json({ "success": false, "message": "Failed to start server" }); + } + + console.log("Server started successfully"); + return res.json({ "success": true, "message": "Operation success!" }); + } catch (error) { + console.error("Error during server start request:", error); + return res.json({ "success": false, "message": "Internal server error" }); + } + }); +} \ No newline at end of file diff --git a/settings.json b/settings.json index 9918fde..f476020 100644 --- a/settings.json +++ b/settings.json @@ -33,7 +33,8 @@ }, "pterodactyl": { "domain": "https://panel.yourdomain.com", - "key": "ptla_" + "key": "ptla_", + "account_key": "" }, "linkvertise": { "userid": "679241", diff --git a/themes/lapsus/servers.ejs b/themes/lapsus/servers.ejs index e17d3c1..8cdfba0 100644 --- a/themes/lapsus/servers.ejs +++ b/themes/lapsus/servers.ejs @@ -104,11 +104,50 @@ Edit + + + + Start + + + + + Stop + Delete - + From 873c1ec3eba8205b446cd01ab21524efb76b83f8 Mon Sep 17 00:00:00 2001 From: crazymath072 <102372274+CR072@users.noreply.github.com> Date: Sat, 23 Dec 2023 17:46:49 +0530 Subject: [PATCH 3/6] Fixed readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 568ac06..454392b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ If you download from the [Releases](https://github.com/ManucrackYT/LapsusClient/ The best way to contact the developers is on Discord. -[![discord](https://discordapp.com/api/guilds/954138561509203978/embed.png?style=banner3)](https://discord.gg/) +[![discord](https://discordapp.com/api/guilds/954138561509203978/embed.png?style=banner3)](https://discord.com/invite/Xa3sm5fZKg) --- From dfad20084a01e9ec3d307d5e50c465046b71e85b Mon Sep 17 00:00:00 2001 From: crazymath072 <102372274+CR072@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:43:13 +0530 Subject: [PATCH 4/6] Add restart endpoint --- api/power.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/api/power.js b/api/power.js index dd9c72b..d82ad23 100644 --- a/api/power.js +++ b/api/power.js @@ -38,6 +38,42 @@ module.exports.load = async function(app, db) { return res.json({ "success": false, "message": "Internal server error" }); } }); + app.get("/api/servers/restart", async (req, res) => { + if (!req.session.pterodactyl) return res.redirect("/login"); + const id = req.query.id; + const user = req.query.user; + + if (!id || !user) { + return; + } + + if (user != req.session.userinfo.id) { + return res.json({ "success": false, "message": "Unauthorized request" }); + } + + try { + const response = await fetch(`${settings.pterodactyl.domain}/api/client/servers/${id}/power`, { + method: "POST", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Authorization": `Bearer ${settings.pterodactyl.account_key}` + }, + body: JSON.stringify({ signal: "restart" }) + }); + + if (!response.ok) { + console.error(`Failed to start server. Status: ${response.status}`); + return res.json({ "success": false, "message": "Failed to start server" }); + } + + console.log("Server started successfully"); + return res.json({ "success": true, "message": "Operation success!" }); + } catch (error) { + console.error("Error during server start request:", error); + return res.json({ "success": false, "message": "Internal server error" }); + } + }); app.get("/api/servers/stop", async (req, res) => { if (!req.session.pterodactyl) return res.redirect("/login"); const id = req.query.id; @@ -74,4 +110,4 @@ module.exports.load = async function(app, db) { return res.json({ "success": false, "message": "Internal server error" }); } }); -} \ No newline at end of file +} From 8757cc54f7e2b9c190ad4e7b8c822de8986cc779 Mon Sep 17 00:00:00 2001 From: crazymath072 <102372274+CR072@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:45:37 +0530 Subject: [PATCH 5/6] Added restart button --- themes/lapsus/servers.ejs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/themes/lapsus/servers.ejs b/themes/lapsus/servers.ejs index 8cdfba0..23d9645 100644 --- a/themes/lapsus/servers.ejs +++ b/themes/lapsus/servers.ejs @@ -99,21 +99,26 @@
- + - Edit + Start - + - Start + Restart Stop + + + + Edit + @@ -134,6 +139,21 @@ } } + async function restart(id) { + try { + let response = await fetch(`/api/servers/restart?id=${id}&user=<%= userinfo.id %>`); + const data = await response.json(); + + if (data.success == true) { + document.getElementById(`restart${id}`).textContent = "Restarted!"; + } else { + console.error("Failed to start server:", data.message); + } + } catch (error) { + console.error("Error during server start request:", error); + } + } + async function stop(id) { try { let response = await fetch(`/api/servers/stop?id=${id}&user=<%= userinfo.id %>`) @@ -249,4 +269,4 @@
- \ No newline at end of file + From 7f546d605c7e5eca44c6b5889b35f9c9951dda4a Mon Sep 17 00:00:00 2001 From: crazymath072 <102372274+CR072@users.noreply.github.com> Date: Sat, 23 Dec 2023 19:28:55 +0530 Subject: [PATCH 6/6] Update colors & Icons --- themes/lapsus/servers.ejs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/themes/lapsus/servers.ejs b/themes/lapsus/servers.ejs index 23d9645..ef9a360 100644 --- a/themes/lapsus/servers.ejs +++ b/themes/lapsus/servers.ejs @@ -99,20 +99,23 @@
- - - - Start + + + + + Start - - - - Restart + + + + + Restart - - - - Stop + + + + + Stop