helmet, external_ip, emergency_shutdown added

This commit is contained in:
C
2022-12-16 15:29:33 +05:00
parent 76130224ac
commit 61b35128f4
10 changed files with 76 additions and 51 deletions
+12 -2
View File
@@ -33,6 +33,7 @@ module.exports.create_session = async (req, res, next) => {
throw new Error('session limit reached')
var session_id = crypto.randomBytes(16).toString('hex')
// create session on session server
http_client.get({
@@ -59,7 +60,8 @@ module.exports.create_session = async (req, res, next) => {
connection_link:answer.link,
connection_code:code
})
res.json({msg:'SESSION_CREATED', link:answer.link})
// SHALL REMOVE CONNECTION CODE BECAUSE IN WEB WE DO NOT NEED IT
res.json({msg:'SESSION_CREATED', link:answer.link, connection_code:code})
}, function(err) {
next(Error('session server not working'))
})
@@ -69,7 +71,15 @@ module.exports.create_session = async (req, res, next) => {
}
module.exports.connect_session = async (req, res, next) => {
try {
const db = await db_connection.get_db()
var session = await db.collection('session_active').findOne({connection_code:parseInt(req.query.connection_code)})
if (!session)
throw new Error('sessions not found')
res.json({connection_link:session.connection_link})
} catch (e) {
next (e)
}
}
module.exports.close_session = async (req, res, next) => {
@@ -0,0 +1,10 @@
const db_connection = require('../database/connection.js')
const crypto = require('crypto')
module.exports.emergency_shutdown = async (req, res, next) => {
const db = await db_connection.get_db()
var id = crypto.createHash('md5').update(req.query.ip+req.query.port).digest('hex')
var query = {server_id:{$in:[id]}}
await db.collection('session_active').deleteMany(query)
res.json({msg:'SESSIONS_CLOSED'})
}