Version 0.3.0 - Add of Services
All checks were successful
Neutral/pipeline/head This commit looks good

This commit is contained in:
Raphix
2023-11-04 14:50:28 +01:00
parent 52a86f3871
commit 1685ec3712
14 changed files with 578 additions and 49 deletions

View File

@ -4,6 +4,7 @@ const path = require("path")
const { __glob } = require("./global-variables")
const auth = require("./auth")
const files = require("./files")
const service = require("./services")
const plog = new LogType("Web")
const cook = require("cookie")
const http = require("http")
@ -44,6 +45,8 @@ module.exports.serverIO = function(server) {
* POST REQUEST
*/
if(user.checkPermission("FILES_EXPLORER")) {
PostRequest("FX_GET", (root) => {
PostAnswer("FX_GET", files.getFiles(root))
@ -90,6 +93,30 @@ module.exports.serverIO = function(server) {
})
}
if(user.checkPermission("SERVICES")) {
PostRequest("SV_GET_SERVICE_STATUS", async (sv) => {
PostAnswer("SV_GET_SERVICE_STATUS", {answer: await service.getServiceStatus(sv), name: sv})
})
PostRequest("SV_START_SERVICE", async (sv) => {
PostAnswer("SV_START_SERVICE", {answer: await service.startService(sv), name: sv})
})
PostRequest("SV_STOP_SERVICE", async (sv) => {
PostAnswer("SV_STOP_SERVICE", {answer: await service.stopService(sv), name: sv})
})
PostRequest("SV_RESTART_SERVICE", async (sv) => {
PostAnswer("SV_RESTART_SERVICE", {answer: await service.restartService(sv), name: sv})
})
}
socket.on("disconnect", () => {
plog.log("Déconnexion au panel par '" + user.username + "' avec le socket : " + socket.id)

136
bin/services.js Normal file
View File

@ -0,0 +1,136 @@
const { LogType } = require("loguix")
const fs = require("fs")
const path = require("path")
const { __glob } = require("./global-variables")
const clog = new LogType("Services")
const http = require('http');
const https = require('https');
module.exports.getServiceStatus = function(service) {
const protocol = service.startsWith('https') ? https : http;
const url = new URL(service);
const options = {
method: 'HEAD',
host: url.hostname,
port: url.port,
path: url.pathname,
};
return new Promise((resolve, reject) => {
const req = protocol.request(options, (res) => {
if(res.statusCode !== 502) {
resolve("ONLINE");
} else {
resolve("OFFLINE");
}
});
req.on('error', (err) => {
resolve("OFFLINE");
});
req.end();
});
}
module.exports.stopService = function(service) {
return new Promise((resolve, reject) => {
const child_process = require('child_process');
if(service == "https://subsonics.raphix.fr") {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 stop 'Subsonics'")
resolve("OK")
} else if(service == "https://git.raphix.fr" ) {
let req = child_process.exec("ssh raphix@omega.raphix.fr sudo -S systemctl stop gitea")
resolve("OK")
} else if(service == "https://jenkins.raphix.fr") {
let req = child_process.exec("ssh raphix@omega.raphix.fr sudo -S systemctl stop jenkins ")
resolve("OK")
} else if(service == 'https://raphix.fr') {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 stop 'Website - Raphix'")
resolve("OK")
} else if(service == "https://cv.raphix.fr") {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 stop 'CV - Raphael'")
resolve("OK")
} else if(service == "http://omega.raphix.fr:2333") {
let req = child_process.exec(" ssh raphix@omega.raphix.fr sudo -S systemctl stop lavalink ")
resolve("OK")
} else {
resolve(false)
}
});
}
module.exports.startService = function(service) {
return new Promise((resolve, reject) => {
const child_process = require('child_process');
if(service == "https://subsonics.raphix.fr") {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 start /home/gitlab-ci/subsonic.config.js")
resolve("OK")
} else if(service == "https://git.raphix.fr" ) {
let req = child_process.exec("ssh raphix@omega.raphix.fr sudo -S systemctl start gitea")
resolve("OK")
} else if(service == "https://jenkins.raphix.fr") {
let req = child_process.exec("ssh raphix@omega.raphix.fr sudo -S systemctl start jenkins ")
resolve("OK")
} else if(service == 'https://raphix.fr') {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 start /home/gitlab-ci/website.config.js")
resolve("OK")
} else if(service == "https://cv.raphix.fr") {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 start /home/gitlab-ci/cv.config.js")
resolve("OK")
} else if(service == "http://omega.raphix.fr:2333") {
let req = child_process.exec(" ssh raphix@omega.raphix.fr sudo -S systemctl start lavalink ")
resolve("OK")
} else {
resolve(false)
}
});
}
module.exports.restartService = function(service) {
return new Promise((resolve, reject) => {
const child_process = require('child_process');
if(service == "https://subsonics.raphix.fr") {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 restart 'Subsonics'")
resolve("OK")
} else if(service == "https://git.raphix.fr" ) {
let req = child_process.exec("ssh raphix@omega.raphix.fr sudo -S systemctl restart gitea")
resolve("OK")
} else if(service == "https://jenkins.raphix.fr") {
let req = child_process.exec("ssh raphix@omega.raphix.fr sudo -S systemctl restart jenkins ")
resolve("OK")
} else if(service == 'https://raphix.fr') {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 restart 'Website - Raphix'")
resolve("OK")
} else if(service == "https://cv.raphix.fr") {
let req = child_process.exec("ssh raphix@alpha.raphix.fr sudo -S -u gitlab-ci pm2 restart 'CV - Raphael'")
resolve("OK")
} else if(service == "http://omega.raphix.fr:2333") {
let req = child_process.exec(" ssh raphix@omega.raphix.fr sudo -S systemctl restart lavalink ")
resolve("OK")
} else {
resolve(false)
}
});
}

View File

@ -204,7 +204,6 @@ module.exports.User = class {
this.#sync()
if(this.permission.includes(name)) {
return true
} else {
return false