Version 1.0.0 - Basic Web Application
This commit is contained in:
@ -34,7 +34,7 @@ module.exports.check = function(token) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de se connecter à Neutral
|
||||
* Permet de se connecter à Inventory
|
||||
* @param {object} data
|
||||
* @returns Token or AUTH_FAILED
|
||||
*/
|
||||
|
@ -35,11 +35,6 @@ module.exports.updateFile = function (file) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getSettings = function () {
|
||||
const file = this.getFile()
|
||||
return {"jenkins_token": file.JENKINS_TOKEN, "omega_token": file.OMEGA_KEY}
|
||||
}
|
||||
|
||||
module.exports.saveSettings = function (settings) {
|
||||
const file = this.getFile()
|
||||
file.JENKINS_TOKEN = settings.jenkins_token
|
||||
|
268
bin/files.js
268
bin/files.js
@ -1,268 +0,0 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const clog = new LogType("Fichier")
|
||||
const os = require("os");
|
||||
const uuid = require('uuid');
|
||||
var mime = require('mime-types');
|
||||
|
||||
|
||||
// check if shared folder exist, if not create it
|
||||
if(!fs.existsSync(__glob.SHARED)) {
|
||||
fs.mkdirSync(__glob.SHARED)
|
||||
}
|
||||
|
||||
module.exports.getFiles = function(root) {
|
||||
|
||||
var response = new Object()
|
||||
response.content = new Array()
|
||||
|
||||
|
||||
try{
|
||||
|
||||
if(root == "homepath") {
|
||||
|
||||
root = os.homedir()
|
||||
|
||||
}
|
||||
|
||||
if(root == "sharepath") {
|
||||
|
||||
root = __glob.SHARED
|
||||
|
||||
}
|
||||
|
||||
if(root == "logpath") {
|
||||
|
||||
root = __glob.LOGS
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(!fs.existsSync(root)) {
|
||||
response.content = "NOT_EXIST"
|
||||
|
||||
} else {
|
||||
|
||||
for(var file of fs.readdirSync(root)) {
|
||||
|
||||
const stat = fs.statSync(root + path.sep + file)
|
||||
|
||||
response.content.push({"name":file, id: uuid.v4().toString() ,"fileDirectory" : root + path.sep + file , "type":mime.lookup(file), "size":stat.size, "lastedition":stat.mtimeMs, "directory":stat.isDirectory()})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}catch(err) {
|
||||
|
||||
response.content = "NOT_PERMITTED"
|
||||
}
|
||||
|
||||
response.root = root
|
||||
response.parent = path.dirname(root)
|
||||
|
||||
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
module.exports.createFolder = function(root) {
|
||||
|
||||
// Check if folder already exist
|
||||
|
||||
if(!fs.existsSync(root)) {
|
||||
|
||||
try {
|
||||
fs.mkdirSync(root)
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return 'EXIST'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.deleteFile = function(root) {
|
||||
|
||||
if(fs.existsSync(root)) {
|
||||
|
||||
try {
|
||||
|
||||
fs.rmSync(root, { recursive: true, force: true })
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else {
|
||||
|
||||
return "NOT_EXIST"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.renameFile = function(settings) {
|
||||
|
||||
if(fs.existsSync(settings.root)) {
|
||||
|
||||
try {
|
||||
|
||||
fs.renameSync(settings.root + path.sep + settings.oldName, settings.root + path.sep + settings.newName)
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else {
|
||||
|
||||
return "NOT_EXIST"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.shareFile = function(settings) {
|
||||
|
||||
|
||||
if(fs.existsSync(settings.root)) {
|
||||
|
||||
try {
|
||||
//Create a sybolic link to shared folder
|
||||
|
||||
fs.symlinkSync(settings.root + path.sep + settings.name, __glob.SHARED + path.sep + settings.name)
|
||||
|
||||
// return the link of the file shared
|
||||
if(process.env.DEV) {
|
||||
return "http://localhost:3001/shared/" + settings.name
|
||||
|
||||
} else {
|
||||
return "https://neutral.raphix.fr/shared/" + settings.name
|
||||
|
||||
}
|
||||
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else {
|
||||
|
||||
return "NOT_EXIST"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports.getFile = function(root) {
|
||||
|
||||
if(fs.existsSync(root)) {
|
||||
|
||||
try {
|
||||
|
||||
// Check if the file is an image and if it is return the base64
|
||||
if(mime.lookup(root).includes("image")) {
|
||||
return "data:" + mime.lookup(root) + ";base64," + fs.readFileSync(root, "base64")
|
||||
} else {
|
||||
return fs.readFileSync(root, "utf-8")
|
||||
}
|
||||
|
||||
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else {
|
||||
|
||||
return "NOT_EXIST"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.saveFile = function(settings) {
|
||||
|
||||
try {
|
||||
|
||||
fs.writeFileSync(settings.root + path.sep + settings.name, settings.content)
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.downloadFile = function(root) {
|
||||
|
||||
if(fs.existsSync(root)) {
|
||||
|
||||
try {
|
||||
|
||||
return fs.readFileSync(root)
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else {
|
||||
|
||||
return "NOT_EXIST"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports.uploadFile = function(settings) {
|
||||
|
||||
try {
|
||||
|
||||
fs.writeFileSync(settings.root + path.sep + settings.name, settings.file)
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.newFile = function(settings) {
|
||||
|
||||
if(!fs.existsSync(settings)) {
|
||||
|
||||
try {
|
||||
|
||||
fs.writeFileSync(settings, "")
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else {
|
||||
|
||||
return "EXIST"
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.pasteFile = function(settings) {
|
||||
if(settings.action == "cut") {
|
||||
|
||||
try {
|
||||
|
||||
fs.renameSync(settings.file.fileDirectory, settings.newPath + path.sep + settings.name)
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
} else if(settings.action == "copy") {
|
||||
|
||||
try {
|
||||
fs.copyFileSync(settings.file.fileDirectory, settings.newPath + path.sep + settings.name)
|
||||
return "OK"
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
return "NOT_PERMITTED"
|
||||
}
|
||||
}
|
||||
}
|
@ -5,12 +5,9 @@ const __glob = {
|
||||
ROUTES: root + path.sep + "routes" + path.sep,
|
||||
ROOT: root,
|
||||
LOGS: root + path.sep + "logs",
|
||||
ICON: root + path.sep + "public" + path.sep + 'images' + path.sep + "FormatLogo_WHITE.ico",
|
||||
DATA: root + path.sep + "data",
|
||||
USERS: root + path.sep + "data" + path.sep + "users.json",
|
||||
CONFIG: root + path.sep + "data" + path.sep + "config.json",
|
||||
SHARED: root + path.sep + "data" + path.sep + "shared",
|
||||
USERS_IMAGES: root + path.sep + "data" + path.sep + "user_images",
|
||||
PACKAGE_JSON: root + path.sep + "package.json",
|
||||
};
|
||||
|
||||
|
106
bin/links.js
106
bin/links.js
@ -1,106 +0,0 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const ulog = new LogType("Links")
|
||||
const uuid = require("uuid")
|
||||
const config = require("./config")
|
||||
const {ApplyLinks} = require("../routes/link")
|
||||
|
||||
|
||||
|
||||
if(!fs.existsSync(__glob.DATA + path.sep + "links.json")) {
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "links.json", JSON.stringify([], null, 2))
|
||||
}
|
||||
|
||||
module.exports.getLinks = function() {
|
||||
return JSON.parse(fs.readFileSync(__glob.DATA + path.sep + "links.json"))
|
||||
}
|
||||
|
||||
const FirstLinkManager = new ApplyLinks(this.getLinks())
|
||||
|
||||
|
||||
module.exports.addLink = function(settings) {
|
||||
|
||||
var canDo = true
|
||||
const links = this.getLinks()
|
||||
var id = makeid(8)
|
||||
|
||||
if(settings.abstractLink) {
|
||||
settings.dest = id.toString()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Check if a destination already exists between links and if it's the case, we return an error "ALREADY_EXiST"
|
||||
links.forEach((link) => {
|
||||
if(link.dest == settings.dest) {
|
||||
|
||||
canDo = false
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
const link = {
|
||||
id: id,
|
||||
title: settings.title,
|
||||
url: settings.url,
|
||||
dest: settings.dest,
|
||||
}
|
||||
|
||||
if(canDo) {
|
||||
|
||||
links.push(link)
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "links.json", JSON.stringify(links, null, 2))
|
||||
const LinkManager = new ApplyLinks(this.getLinks())
|
||||
return "OK"
|
||||
|
||||
} else {
|
||||
|
||||
return "ALREADY_EXIST"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports.removeLink = function(id) {
|
||||
const links = this.getLinks()
|
||||
const newLinks = []
|
||||
links.forEach((link) => {
|
||||
if(link.id != id) {
|
||||
newLinks.push(link)
|
||||
}
|
||||
})
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "links.json", JSON.stringify(newLinks, null, 2))
|
||||
const LinkManager = new ApplyLinks(this.getLinks())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
module.exports.updateLink = function(id, settings) {
|
||||
const links = this.getLinks()
|
||||
const newLinks = []
|
||||
links.forEach((link) => {
|
||||
if(link.id == id) {
|
||||
link.title = settings.title
|
||||
link.url = settings.url
|
||||
}
|
||||
newLinks.push(link)
|
||||
})
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "links.json", JSON.stringify(newLinks, null, 2))
|
||||
const LinkManager = new ApplyLinks(this.getLinks())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function makeid(length) {
|
||||
let result = '';
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
const charactersLength = characters.length;
|
||||
let counter = 0;
|
||||
while (counter < length) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
counter += 1;
|
||||
}
|
||||
return result;
|
||||
}
|
128
bin/metrics.js
128
bin/metrics.js
@ -1,128 +0,0 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
var CryptoJS = require("crypto-js")
|
||||
const { __glob } = require("./global-variables")
|
||||
const { captureRejectionSymbol } = require("events")
|
||||
const clog = new LogType("Metrics")
|
||||
|
||||
|
||||
if(!fs.existsSync(__glob.DATA + path.sep + "metrics.json")) {
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "metrics.json", JSON.stringify([], null, 2))
|
||||
}
|
||||
|
||||
module.exports.getDataMetrics = function() {
|
||||
return JSON.parse(fs.readFileSync(__glob.DATA + path.sep + "metrics.json"))
|
||||
}
|
||||
|
||||
module.exports.getMetrics = function() {
|
||||
|
||||
|
||||
|
||||
const metrics = this.getDataMetrics()
|
||||
var metricsToReturn = new Array()
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
// Count the number processed
|
||||
|
||||
var processed = 0
|
||||
|
||||
if(metrics.length == 0) {
|
||||
resolve(metricsToReturn)
|
||||
}
|
||||
|
||||
await metrics.forEach(async (metric) => {
|
||||
|
||||
// Try to connect to the metric server with the key in query params named "privatekey"
|
||||
// If the connection is successful, we add the metric to the list of metrics to return
|
||||
|
||||
const url = `http://${metric.address}:${metric.port}/metrics?privatekey=${metric.key}`
|
||||
const fet = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
},
|
||||
credentials: "include"
|
||||
}).then(res => res.json())
|
||||
.then(res => {
|
||||
|
||||
if(res) {
|
||||
metric.data = res
|
||||
metricsToReturn.push(metric)
|
||||
processed++
|
||||
} else {
|
||||
metric.data = "ERROR"
|
||||
metricsToReturn.push(metric)
|
||||
}
|
||||
|
||||
if(processed == metrics.length) {
|
||||
resolve(metricsToReturn)
|
||||
}
|
||||
|
||||
}).catch((err) => {
|
||||
metric.data = "ERROR"
|
||||
metricsToReturn.push(metric)
|
||||
processed++
|
||||
if(processed == metrics.length) {
|
||||
resolve(metricsToReturn)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
module.exports.addMetric = function(settings) {
|
||||
|
||||
const metrics = this.getDataMetrics()
|
||||
|
||||
const metric = {
|
||||
id: makeid(8),
|
||||
name: settings.name,
|
||||
address: settings.address,
|
||||
port: settings.port,
|
||||
key: settings.key,
|
||||
}
|
||||
|
||||
metrics.push(metric)
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "metrics.json", JSON.stringify(metrics, null, 2))
|
||||
return "OK"
|
||||
}
|
||||
|
||||
module.exports.deleteMetric = function(id) {
|
||||
|
||||
const metrics = this.getDataMetrics()
|
||||
|
||||
metrics.forEach((metric) => {
|
||||
if(metric.id == id) {
|
||||
metrics.splice(metrics.indexOf(metric), 1)
|
||||
}
|
||||
})
|
||||
|
||||
fs.writeFileSync(__glob.DATA + path.sep + "metrics.json", JSON.stringify(metrics, null, 2))
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function makeid(length) {
|
||||
var result = [];
|
||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
||||
var charactersLength = characters.length;
|
||||
for ( var i = 0; i < length; i++ ) {
|
||||
result.push(characters.charAt(Math.floor(Math.random() *
|
||||
charactersLength)));
|
||||
}
|
||||
return result.join('');
|
||||
}
|
138
bin/pipelines.js
138
bin/pipelines.js
@ -1,138 +0,0 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const clog = new LogType("Pïpeline")
|
||||
const config = require("./config")
|
||||
|
||||
const tokenkey = config.getFile().JENKINS_TOKEN
|
||||
|
||||
module.exports.getAllPipelines = function() {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
||||
fetch(`https://jenkins.raphix.fr/api/json`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Authorization": `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(async list => {
|
||||
|
||||
const pipelinesJobs = new Array()
|
||||
|
||||
for(const job of list.jobs) {
|
||||
await fetch(`${job.url}/api/json`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Authorization": `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(async res => {
|
||||
|
||||
if(res._class == "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject") {
|
||||
await getJobMain(res).then(resJ => {
|
||||
res.jobs[0] = resJ
|
||||
pipelinesJobs.push(res)
|
||||
})
|
||||
} else {
|
||||
pipelinesJobs.push(res)
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
list.jobs = pipelinesJobs
|
||||
|
||||
resolve(list)
|
||||
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
resolve("UNAVAILABLE")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports.startPipeline = function(pipeline) {
|
||||
|
||||
|
||||
// If it's a freestyle job, build with params
|
||||
|
||||
if(pipeline.type == "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject") {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(`${pipeline.url}/job/${pipeline.jobname}/build?delay=0sec`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: "include"
|
||||
})
|
||||
.then(res => {
|
||||
resolve("OK")
|
||||
})
|
||||
})
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const parameters = pipeline.fields
|
||||
|
||||
const formatedParams = new URLSearchParams()
|
||||
|
||||
for(const param of parameters) {
|
||||
formatedParams.append(param.name, param.value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fetch(`${pipeline.url}/buildWithParameters?delay=0sec`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Basic ${tokenkey}`,
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
credentials: "include",
|
||||
body: formatedParams
|
||||
})
|
||||
.then(res => {
|
||||
resolve("OK")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getJobMain(res) {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
await fetch(`${res.jobs[0].url}/api/json`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `Basic ${tokenkey}`
|
||||
},
|
||||
credentials: 'include'
|
||||
}).then(res => res.json())
|
||||
.then(res => {
|
||||
resolve(res)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const clog = new LogType("Serveur Metrics")
|
||||
const osutils = require("os-utils")
|
||||
const os = require("os")
|
||||
const { statfs } = require("fs")
|
||||
const config = require("./config")
|
||||
|
||||
|
||||
|
||||
module.exports.getMetrics = async function(server) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(server == "Alpha") {
|
||||
var resp = "NULL"
|
||||
const space = statfs("/", (err, stats) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
|
||||
|
||||
|
||||
osutils.cpuUsage(function(cpuUsage) {
|
||||
resp = {
|
||||
cpu: Math.round(cpuUsage * 1000),
|
||||
usedram: osutils.totalmem() - osutils.freemem(),
|
||||
totalram: osutils.totalmem(),
|
||||
usedisk: stats.blocks - stats.bfree,
|
||||
totaldisk: stats.blocks,
|
||||
name: server
|
||||
}
|
||||
|
||||
resolve(resp)
|
||||
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
} else if(server == "Omega") {
|
||||
|
||||
const key = config.getFile().OMEGA_KEY;
|
||||
|
||||
fetch("http://omega.raphix.fr:4000/metrics?key="+key, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
"Accept-Encoding": "gzip, deflate",
|
||||
"Accept-Language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive"
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(raw => {
|
||||
raw.name = server;
|
||||
resolve(raw);
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
296
bin/servers.js
296
bin/servers.js
@ -1,296 +0,0 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables.js")
|
||||
const auth = require("./auth.js")
|
||||
const users = require("./users.js")
|
||||
const files = require("./files.js")
|
||||
const config = require("./config.js")
|
||||
const links = require("./links.js")
|
||||
const service = require("./services.js")
|
||||
const pipeline = require("./pipelines.js")
|
||||
const plog = new LogType("Web")
|
||||
const cook = require("cookie")
|
||||
const http = require("http")
|
||||
const servermetrics = require("./server-metrics.js")
|
||||
const metrics = require("./metrics.js")
|
||||
const pm2 = require('pm2');
|
||||
|
||||
/**
|
||||
* NOTE INTERNE
|
||||
*
|
||||
* Changer les pictures de users autre part
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {http.Server} server
|
||||
*/
|
||||
|
||||
module.exports.serverIO = function(server) {
|
||||
|
||||
const io = require('socket.io')(server, {
|
||||
maxHttpBufferSize: 1e8,
|
||||
pingTimeout: 60000
|
||||
})
|
||||
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
|
||||
let token = cook.parse(socket.handshake.headers.cookie).token
|
||||
var user = auth.getUserByToken(token)
|
||||
|
||||
if(user) {
|
||||
plog.log("Connexion au panel par '" + user.username + "' avec le socket : " + socket.id)
|
||||
user.setLastLogin(new Date())
|
||||
/**
|
||||
* GET REQUEST
|
||||
*/
|
||||
|
||||
// Get Users
|
||||
GetRequest("USERINFO", () => {
|
||||
user = auth.getUserByToken(token)
|
||||
GetAnswer("USERINFO", {username: user.username, display_name: user.display_name ,picture: user.picture, permission: user.permission})
|
||||
})
|
||||
|
||||
/**
|
||||
* POST REQUEST
|
||||
*/
|
||||
|
||||
PostRequest("US_EDIT_PERSONNAL", async (settings) => {
|
||||
user = auth.getUserByToken(token)
|
||||
PostAnswer("US_EDIT_PERSONNAL", await users.editMySelf(settings, user))
|
||||
})
|
||||
|
||||
if(user.checkPermission("FILES_EXPLORER")) {
|
||||
|
||||
PostRequest("FX_GET", (root) => {
|
||||
|
||||
PostAnswer("FX_GET", files.getFiles(root))
|
||||
})
|
||||
|
||||
PostRequest("FX_NEW_FOLDER", (root) => {
|
||||
|
||||
PostAnswer("FX_NEW_FOLDER", files.createFolder(root))
|
||||
})
|
||||
|
||||
PostRequest("FX_DELETE", (root) => {
|
||||
|
||||
PostAnswer("FX_DELETE", files.deleteFile(root))
|
||||
} )
|
||||
|
||||
PostRequest("FX_RENAME", (settings) => {
|
||||
|
||||
PostAnswer("FX_RENAME", files.renameFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_SHARE", (settings) => {
|
||||
|
||||
PostAnswer("FX_SHARE", files.shareFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_GETFILE", (root) => {
|
||||
|
||||
PostAnswer("FX_GETFILE", files.getFile(root))
|
||||
})
|
||||
|
||||
PostRequest("FX_SAVEFILE", (settings) => {
|
||||
|
||||
PostAnswer("FX_SAVEFILE", files.saveFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_NEW_FILE", (settings) => {
|
||||
|
||||
PostAnswer("FX_NEW_FILE", files.newFile(settings))
|
||||
})
|
||||
|
||||
PostRequest("FX_UPLOAD", (settings) => {
|
||||
|
||||
PostAnswer("FX_UPLOAD", files.uploadFile(settings))
|
||||
|
||||
})
|
||||
|
||||
PostRequest("FX_PASTE", (settings) => {
|
||||
|
||||
PostAnswer("FX_PASTE", files.pasteFile(settings))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
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})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if(user.checkPermission("LINKS")) {
|
||||
PostRequest("LINKS_GET_ALL", () => {
|
||||
PostAnswer("LINKS_GET_ALL", {answer: "OK", links: links.getLinks()})
|
||||
})
|
||||
|
||||
PostRequest("LINKS_ADD", (settings) => {
|
||||
PostAnswer("LINKS_ADD", {answer: links.addLink(settings)})
|
||||
})
|
||||
|
||||
PostRequest("LINKS_DELETE", (id) => {
|
||||
PostAnswer("LINKS_DELETE", links.removeLink(id))
|
||||
})
|
||||
|
||||
PostRequest("LINKS_EDIT", (settings) => {
|
||||
PostAnswer("LINKS_EDIT", links.updateLink(settings.id, settings))
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(user.checkPermission("SERVERS")) {
|
||||
PostRequest("SERVER_GET_METRICS_Alpha", async (settings) => {
|
||||
PostAnswer("SERVER_GET_METRICS_Alpha", {answer: "OK", metrics: await servermetrics.getMetrics(settings), name: settings});
|
||||
});
|
||||
PostRequest("SERVER_GET_METRICS_Omega", async (settings) => {
|
||||
PostAnswer("SERVER_GET_METRICS_Omega", {answer: "OK", metrics: await servermetrics.getMetrics(settings), name: settings});
|
||||
});
|
||||
}
|
||||
|
||||
if(user.checkPermission("PIPELINES")) {
|
||||
GetRequest("PL_GET_ALL", async () => {
|
||||
GetAnswer("PL_GET_ALL", await pipeline.getAllPipelines())
|
||||
})
|
||||
|
||||
PostRequest("PL_START", async (settings) => {
|
||||
PostAnswer("PL_START", await pipeline.startPipeline(settings))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if(user.checkPermission("USERS")) {
|
||||
GetRequest("US_ALL", async () => {
|
||||
GetAnswer("US_ALL", await users.getAllUsers())
|
||||
})
|
||||
|
||||
PostRequest("US_ADD", async (settings) => {
|
||||
PostAnswer("US_ADD", await users.addUser(settings))
|
||||
})
|
||||
|
||||
PostRequest("US_DELETE", async (settings) => {
|
||||
PostAnswer("US_DELETE", await users.deleteUser(settings))
|
||||
})
|
||||
|
||||
PostRequest("US_EDIT", async (settings) => {
|
||||
PostAnswer("US_EDIT", await users.editUser(settings))
|
||||
})
|
||||
|
||||
PostRequest("US_CLEAR_TOKENS", async (settings) => {
|
||||
|
||||
PostAnswer("US_CLEAR_TOKENS", await users.clearTokens(settings))
|
||||
})
|
||||
}
|
||||
|
||||
if(user.checkPermission("SETTINGS")) {
|
||||
PostRequest("SETTINGS_SAVE", async (settings) => {
|
||||
PostAnswer("SETTINGS_SAVE", await config.saveSettings(settings))
|
||||
})
|
||||
PostRequest("SERVER_RESTART", async () => {
|
||||
pm2.restart('Neutral')
|
||||
})
|
||||
PostRequest("SERVER_STOP", async () => {
|
||||
pm2.stop('Neutral')
|
||||
})
|
||||
GetRequest("SERVER_GET_LOGS", async () => {
|
||||
GetAnswer("SERVER_GET_LOGS", await fs.readdirSync(__glob.LOGS))
|
||||
})
|
||||
|
||||
PostRequest("SERVER_READ_LOG", async (logs) => {
|
||||
PostAnswer("SERVER_READ_LOG", await fs.readFileSync(__glob.LOGS + path.sep + logs).toString())
|
||||
})
|
||||
|
||||
GetRequest("SETTINGS_GET", async () => {
|
||||
GetAnswer("SETTINGS_GET", await config.getSettings())
|
||||
})
|
||||
}
|
||||
|
||||
if(user.checkPermission("METRICS")) {
|
||||
GetRequest("MT_ALL", async () => {
|
||||
GetAnswer("MT_ALL", await metrics.getMetrics())
|
||||
})
|
||||
|
||||
PostRequest("MT_ADD", async (settings) => {
|
||||
PostAnswer("MT_ADD", await metrics.addMetric(settings))
|
||||
})
|
||||
|
||||
PostRequest("MT_DELETE", async (settings) => {
|
||||
PostAnswer("MT_DELETE", await metrics.deleteMetric(settings))
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
socket.on("disconnect", (reason) => {
|
||||
plog.log("Déconnexion du panel par '" + user.username + "' avec le socket : " + socket.id)
|
||||
})
|
||||
|
||||
socket.on("connect_error", (err) => {
|
||||
console.log(err)
|
||||
console.log(err.message); // prints the message associated with the error
|
||||
});
|
||||
|
||||
function GetRequest(GQname, GQcallback) {
|
||||
socket.on("GET/" + GQname, () => {
|
||||
|
||||
plog.log(user.username + " - Socket : " + socket.id + " - GET/" + GQname + " - [RECIEVED]")
|
||||
GQcallback()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function GetAnswer(GRname, GRvalue) {
|
||||
|
||||
plog.log(user.username + " - Socket : " + socket.id + " - GET/" + GRname + " - [ANSWERED]")
|
||||
socket.emit("ANSWER/GET/" + GRname, GRvalue)
|
||||
|
||||
}
|
||||
|
||||
function PostRequest(GQname, GQcallback) {
|
||||
socket.on("POST/" + GQname, (value) => {
|
||||
plog.log(user.username + " - Socket : " + socket.id + " - POST/" + GQname + " - [RECIEVED]")
|
||||
GQcallback(value)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function PostAnswer(GRname, GRvalue) {
|
||||
|
||||
plog.log(user.username + " - Socket : " + socket.id + " - POST/" + GRname + " - [ANSWERED]")
|
||||
socket.emit("ANSWER/POST/" + GRname, GRvalue)
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
socket.disconnect()
|
||||
plog.warn("Connexion directe vers le panel avec un token inexistant : " + this.token)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
137
bin/services.js
137
bin/services.js
@ -1,137 +0,0 @@
|
||||
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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl stop gitea`)
|
||||
resolve("OK")
|
||||
} else if(service == `https://jenkins.raphix.fr`) {
|
||||
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl stop jenkins `)
|
||||
resolve("OK")
|
||||
|
||||
} else if(service == `https://raphix.fr`) {
|
||||
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl start gitea`)
|
||||
resolve("OK")
|
||||
} else if(service == `https://jenkins.raphix.fr`) {
|
||||
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl start jenkins `)
|
||||
resolve("OK")
|
||||
|
||||
} else if(service == `https://raphix.fr`) {
|
||||
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl restart gitea`)
|
||||
resolve("OK")
|
||||
} else if(service == `https://jenkins.raphix.fr`) {
|
||||
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl restart jenkins `)
|
||||
resolve("OK")
|
||||
|
||||
} else if(service == `https://raphix.fr`) {
|
||||
let req = child_process.exec(`ssh -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no 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 -o StrictHostKeyChecking=no raphix@omega.raphix.fr sudo -S systemctl restart lavalink `)
|
||||
resolve("OK")
|
||||
} else {
|
||||
resolve(false)
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
128
bin/users.js
128
bin/users.js
@ -50,10 +50,8 @@ module.exports.fetchUsers = function () {
|
||||
username: userFetched.username,
|
||||
password: userFetched.password,
|
||||
display_name: userFetched.display_name,
|
||||
permission: userFetched.permission,
|
||||
tokens: userFetched.tokens,
|
||||
lastLogin: userFetched.lastLogin,
|
||||
picture: userFetched.picture
|
||||
|
||||
})
|
||||
|
||||
@ -63,21 +61,10 @@ module.exports.fetchUsers = function () {
|
||||
if(usersList.size == 0) {
|
||||
const adminUser = new this.User({
|
||||
"username": "admin",
|
||||
"password": "neutral",
|
||||
"password": "inventory",
|
||||
"display_name": "Administrateur",
|
||||
"permission": [
|
||||
"FILES_EXPLORER",
|
||||
"SERVICES",
|
||||
"SERVERS",
|
||||
"PIPELINES",
|
||||
"METRICS",
|
||||
"USERS",
|
||||
"LINKS",
|
||||
"SETTINGS"
|
||||
],
|
||||
"tokens": [],
|
||||
"lastLogin": "DEFAULT ACCOUNT",
|
||||
"picture": "/images/default.jpg"
|
||||
})
|
||||
|
||||
|
||||
@ -94,16 +81,14 @@ module.exports.fetchUsers = function () {
|
||||
|
||||
/**
|
||||
* User Class is used to access to default user's properties and methods
|
||||
* @param {object} properties User properties with : username, password, display_name, permission...
|
||||
* @param {object} properties User properties with : username, password, display_name
|
||||
*/
|
||||
module.exports.User = class {
|
||||
username = null
|
||||
password = null;
|
||||
display_name = null
|
||||
permission = []
|
||||
tokens = []
|
||||
lastLogin = new Date()
|
||||
picture = "/images/default.jpg"
|
||||
|
||||
constructor(properties) {
|
||||
|
||||
@ -112,10 +97,8 @@ module.exports.User = class {
|
||||
this.username = properties.username
|
||||
this.password = keygen.encrypt(properties.password)
|
||||
this.display_name = properties.display_name
|
||||
this.permission = properties.permission
|
||||
this.tokens = properties.tokens
|
||||
this.lastLogin = properties.lastLogin
|
||||
this.picture = properties.picture
|
||||
|
||||
const userFile = getFile()
|
||||
|
||||
@ -125,7 +108,6 @@ module.exports.User = class {
|
||||
this.username = userFetched.username
|
||||
this.password = userFetched.password
|
||||
this.display_name = userFetched.display_name
|
||||
this.permission = userFetched.permission
|
||||
this.tokens = userFetched.tokens
|
||||
this.lastLogin = userFetched.lastLogin
|
||||
}
|
||||
@ -150,22 +132,14 @@ module.exports.User = class {
|
||||
ulog.warn("'" + this.username + "' is without display name !")
|
||||
this.display_name = this.username
|
||||
}
|
||||
if(this.permission == null) {
|
||||
ulog.warn("'" + this.username + "' has no longer permission !")
|
||||
|
||||
}
|
||||
if(this.tokens == null) {
|
||||
this.tokens = []
|
||||
}
|
||||
if(this.permission == null) {
|
||||
this.permission = []
|
||||
}
|
||||
if(this.lastLogin == null) {
|
||||
this.lastLogin = new Date()
|
||||
}
|
||||
if(this.picture == null) {
|
||||
this.picture = "/images/default.jpg"
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -211,47 +185,7 @@ module.exports.User = class {
|
||||
usersList.delete(this.username)
|
||||
}
|
||||
|
||||
checkPermission(name) {
|
||||
this.#sync()
|
||||
if(this.permission.includes(name)) {
|
||||
return true
|
||||
} else {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
addPermission(name) {
|
||||
this.#sync()
|
||||
for(var perms of this.permission) {
|
||||
if(name == perms) {
|
||||
ulog.warn("'" + this.username + "' a déjà la permission : " + name)
|
||||
return false
|
||||
}
|
||||
}
|
||||
this.permission.push(name)
|
||||
this.register()
|
||||
}
|
||||
|
||||
removePermission(name) {
|
||||
this.#sync()
|
||||
var havePermission = false
|
||||
for(var perms of this.permission) {
|
||||
if(name == perms) {
|
||||
havePermission = true
|
||||
}
|
||||
}
|
||||
if(havePermission) {
|
||||
this.permission.splice(this.permission.indexOf(name), 1)
|
||||
this.register()
|
||||
} else {
|
||||
|
||||
ulog.warn("'" + this.username + "' n'a pas la permission : " + name)
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setPassword(newPassword) {
|
||||
this.#sync()
|
||||
@ -293,14 +227,6 @@ module.exports.User = class {
|
||||
|
||||
}
|
||||
|
||||
setPicture(text) {
|
||||
this.#sync()
|
||||
this.picture = text
|
||||
this.register()
|
||||
ulog.log("La photo de l'utilisateur a été modifié : " + this.username)
|
||||
|
||||
}
|
||||
|
||||
setDisplayName(text) {
|
||||
this.#sync()
|
||||
this.display_name = text
|
||||
@ -325,24 +251,6 @@ module.exports.User = class {
|
||||
this.register()
|
||||
}
|
||||
|
||||
setPicture(file) {
|
||||
this.#sync()
|
||||
var pictureDir = __glob.USERS_IMAGES + path.sep + uuid.v4().toString() + ".png"
|
||||
if(!fs.existsSync(__glob.USERS_IMAGES)) {
|
||||
fs.mkdirSync(__glob.USERS_IMAGES)
|
||||
}
|
||||
fs.writeFileSync(pictureDir, file)
|
||||
|
||||
this.picture = pictureDir.replace(__glob.USERS_IMAGES + path.sep, "/users/")
|
||||
this.register()
|
||||
}
|
||||
|
||||
setPermissions(permissions) {
|
||||
this.#sync()
|
||||
this.permission = permissions
|
||||
this.register()
|
||||
}
|
||||
|
||||
clearTokens() {
|
||||
this.#sync()
|
||||
this.tokens = []
|
||||
@ -357,7 +265,6 @@ module.exports.User = class {
|
||||
this.username = userFetched.username
|
||||
this.password = userFetched.password
|
||||
this.display_name = userFetched.display_name
|
||||
this.permission = userFetched.permission
|
||||
this.tokens = userFetched.tokens
|
||||
this.lastLogin = userFetched.lastLogin
|
||||
}
|
||||
@ -382,23 +289,10 @@ module.exports.addUser = function(settings) {
|
||||
return "ALREADY_EXIST"
|
||||
} else {
|
||||
ulog.step.init("add_user", "Ajout d'un utilisateur dans la base de donnée : " + settings.username)
|
||||
var pictureDir = null
|
||||
|
||||
|
||||
if(settings.picture == null) {
|
||||
pictureDir = "/images/default.jpg"
|
||||
} else {
|
||||
pictureDir = __glob.USERS_IMAGES + path.sep + uuid.v4().toString() + ".png"
|
||||
fs.writeFileSync(pictureDir, settings.picture)
|
||||
|
||||
|
||||
}
|
||||
|
||||
const user = new this.User({
|
||||
username: settings.username,
|
||||
display_name: settings.display_name,
|
||||
permission: settings.permissions,
|
||||
picture: pictureDir.replace(__glob.USERS_IMAGES + path.sep, "/images/users/")
|
||||
display_name: settings.display_name
|
||||
|
||||
})
|
||||
|
||||
@ -451,13 +345,8 @@ module.exports.editUser = function(settings) {
|
||||
user.setPassword(settings.password)
|
||||
}
|
||||
|
||||
if(settings.picture) {
|
||||
user.setPicture(settings.picture)
|
||||
}
|
||||
if(settings.permissions) {
|
||||
|
||||
user.setPermissions(settings.permissions)
|
||||
}
|
||||
|
||||
|
||||
ulog.step.end("edit_user")
|
||||
return "OK"
|
||||
} else {
|
||||
@ -497,10 +386,7 @@ module.exports.editMySelf = function (settings, user) {
|
||||
if(settings.password) {
|
||||
user.setPassword(settings.password)
|
||||
}
|
||||
|
||||
if(settings.picture) {
|
||||
user.setPicture(settings.picture)
|
||||
}
|
||||
|
||||
ulog.step.end("edit_user")
|
||||
return "OK"
|
||||
} else {
|
||||
|
4
bin/www
4
bin/www
@ -20,13 +20,12 @@ wlog.step.init("start_server", "Démarrage du serveur Express JS")
|
||||
var app = require('../main');
|
||||
var http = require('http');
|
||||
var config = require("./config")
|
||||
var serverIO = require("./servers")
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
var port = normalizePort(process.env.PORT || '3001');
|
||||
var port = normalizePort(process.env.PORT || '5005');
|
||||
app.set('port', port);
|
||||
|
||||
/**
|
||||
@ -34,7 +33,6 @@ app.set('port', port);
|
||||
*/
|
||||
|
||||
var server = http.createServer(app);
|
||||
serverIO.serverIO(server)
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
|
Reference in New Issue
Block a user