Version 0.2.0 - PREVERSION - Ajout de certaines fonctionnalités
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
This commit is contained in:
24
bin/auth.js
24
bin/auth.js
@ -23,7 +23,6 @@ module.exports.check = function(token) {
|
||||
})
|
||||
|
||||
if(isApproved) {
|
||||
alog.log("Connexion par Token de l'utilisateur : " + username)
|
||||
return true
|
||||
} else {
|
||||
if(token) {
|
||||
@ -88,4 +87,27 @@ module.exports.signout = function(token) {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.getUserByToken = function(token) {
|
||||
var isApproved = false;
|
||||
var userGetted = null
|
||||
users.getUsers().forEach((fetchUser) => {
|
||||
if(fetchUser.tokens.includes(token)) {
|
||||
userGetted = fetchUser
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
if(userGetted) {
|
||||
return userGetted
|
||||
|
||||
} else {
|
||||
if(token) {
|
||||
|
||||
alog.warn("Erreur d'authentification - Token n'existe pas : " + token)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ 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"
|
||||
|
78
bin/server.js
Normal file
78
bin/server.js
Normal file
@ -0,0 +1,78 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const auth = require("./auth")
|
||||
const plog = new LogType("Web")
|
||||
const cook = require("cookie")
|
||||
const http = require("http")
|
||||
|
||||
/**
|
||||
* NOTE INTERNE
|
||||
*
|
||||
* Changer les pictures de users autre part
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {http.Server} server
|
||||
*/
|
||||
|
||||
module.exports.serverIO = function(server) {
|
||||
|
||||
const io = require('socket.io')(server)
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
let token = cook.parse(socket.handshake.headers.cookie).token
|
||||
const 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", () => {
|
||||
|
||||
GetAnswer("USERINFO", {username: user.username, display_name: user.display_name ,picture: user.picture, permission: user.permission})
|
||||
})
|
||||
|
||||
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
|
||||
plog.log("Déconnexion au panel par '" + user.username + "' avec le socket : " + socket.id)
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
socket.disconnect()
|
||||
plog.warn("Connexion directe vers le panel avec un token inexistant : " + this.token)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
58
bin/users.js
58
bin/users.js
@ -45,11 +45,40 @@ module.exports.fetchUsers = function () {
|
||||
permission: userFetched.permission,
|
||||
tokens: userFetched.tokens,
|
||||
lastLogin: userFetched.lastLogin,
|
||||
picture: userFetched.picture
|
||||
|
||||
})
|
||||
|
||||
usersList.set(user.username, user)
|
||||
}
|
||||
|
||||
if(usersList.size == 0) {
|
||||
const adminUser = new this.User({
|
||||
"username": "admin",
|
||||
"password": "neutral",
|
||||
"display_name": "Administrateur",
|
||||
"permission": [
|
||||
"FILES_EXPLORER",
|
||||
"SERVICES",
|
||||
"SERVERS",
|
||||
"PIPELINES",
|
||||
"METRICS",
|
||||
"USERS",
|
||||
"LINKS",
|
||||
"SETTINGS"
|
||||
],
|
||||
"tokens": [],
|
||||
"lastLogin": "DEFAULT ACCOUNT",
|
||||
"picture": "/images/users/default.jpg"
|
||||
})
|
||||
|
||||
|
||||
adminUser.register()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
ulog.step.end("fetch_user")
|
||||
}
|
||||
|
||||
@ -64,7 +93,7 @@ module.exports.User = class {
|
||||
permission = []
|
||||
tokens = []
|
||||
lastLogin = new Date()
|
||||
|
||||
picture = "/images/users/default.jpg"
|
||||
|
||||
constructor(properties) {
|
||||
|
||||
@ -76,6 +105,7 @@ module.exports.User = class {
|
||||
this.permission = properties.permission
|
||||
this.tokens = properties.tokens
|
||||
this.lastLogin = properties.lastLogin
|
||||
this.picture = properties.picture
|
||||
|
||||
const userFile = getFile()
|
||||
|
||||
@ -123,7 +153,9 @@ module.exports.User = class {
|
||||
if(this.lastLogin == null) {
|
||||
this.lastLogin = new Date()
|
||||
}
|
||||
|
||||
if(this.picture == null) {
|
||||
this.picture = "/images/users/default.jpg"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -251,6 +283,28 @@ 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
|
||||
this.register()
|
||||
ulog.log("Le nom d'affichage de l'utilisateur a été modifié : " + this.username)
|
||||
|
||||
}
|
||||
|
||||
setLastLogin(text) {
|
||||
this.#sync()
|
||||
this.lastLogin = text
|
||||
this.register()
|
||||
}
|
||||
|
||||
#sync() {
|
||||
|
||||
for(var userGet of usersList.keys()) {
|
||||
|
11
bin/www
11
bin/www
@ -8,15 +8,19 @@ var {LogType} = require("loguix")
|
||||
var { __glob } = require("./global-variables")
|
||||
log.setup(__glob.LOGS)
|
||||
|
||||
const wlog = new LogType("Web")
|
||||
const wlog = new LogType("Serveur")
|
||||
|
||||
if(process.env.DEV ) {
|
||||
|
||||
wlog.log("MODE DEVELOPEMENT ACTIF")
|
||||
}
|
||||
|
||||
wlog.step.init("start_server", "Démarrage du serveur Express JS")
|
||||
|
||||
var app = require('../main');
|
||||
var debug = require('debug')('neutral:server');
|
||||
var http = require('http');
|
||||
var config = require("./config")
|
||||
|
||||
var serverIO = require("./server")
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
@ -30,6 +34,7 @@ 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