mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Deleting old sessions fix
This commit is contained in:
parent
c8161e4dce
commit
771959ec2b
1 changed files with 17 additions and 11 deletions
|
@ -186,7 +186,6 @@ function GetApp(): ModuleType {
|
||||||
temp = temp[temp.length - 1]
|
temp = temp[temp.length - 1]
|
||||||
|
|
||||||
version = temp
|
version = temp
|
||||||
console.log(version)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function LoadMOTD() {
|
function LoadMOTD() {
|
||||||
|
@ -680,7 +679,6 @@ function GetApp(): ModuleType {
|
||||||
.replace(/"/g, '')
|
.replace(/"/g, '')
|
||||||
.replace(/;/g, '')
|
.replace(/;/g, '')
|
||||||
: false
|
: false
|
||||||
const cid = req.body.cid
|
|
||||||
const isScript = req.body.script
|
const isScript = req.body.script
|
||||||
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||||
const user: User = dbtools.Select(userDB, 'users', {
|
const user: User = dbtools.Select(userDB, 'users', {
|
||||||
|
@ -690,24 +688,32 @@ function GetApp(): ModuleType {
|
||||||
if (user) {
|
if (user) {
|
||||||
const sessionID = uuidv4()
|
const sessionID = uuidv4()
|
||||||
|
|
||||||
const existingSessions = dbtools.Select(userDB, 'sessions', {
|
const existingSessions = dbtools
|
||||||
|
.Select(userDB, 'sessions', {
|
||||||
userID: user.id,
|
userID: user.id,
|
||||||
isScript: isScript ? 1 : 0,
|
isScript: isScript ? 1 : 0,
|
||||||
})
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
return new Date(a).getTime() - new Date(b).getTime()
|
||||||
|
})
|
||||||
|
|
||||||
if (existingSessions.length >= minimumAlowwedSessions) {
|
// TODO: check if sort works, and only the first few gets deleted.
|
||||||
|
|
||||||
|
const diff = existingSessions.length - minimumAlowwedSessions
|
||||||
|
if (diff > 0) {
|
||||||
logger.Log(
|
logger.Log(
|
||||||
`Multiple ${isScript ? 'script' : 'website'} sessions ( ${
|
`Multiple ${isScript ? 'script' : 'website'} sessions ( ${
|
||||||
existingSessions.length
|
existingSessions.length
|
||||||
} ) for #${user.id}, deleting olds`,
|
} ) for #${user.id}, deleting olds`,
|
||||||
logger.GetColor('cyan')
|
logger.GetColor('cyan')
|
||||||
)
|
)
|
||||||
existingSessions.forEach((sess) => {
|
for (let i = 0; i < diff; i++) {
|
||||||
|
const id = existingSessions[i].id
|
||||||
dbtools.Delete(userDB, 'sessions', {
|
dbtools.Delete(userDB, 'sessions', {
|
||||||
id: sess.id,
|
id: id,
|
||||||
isScript: isScript ? 1 : 0,
|
isScript: isScript ? 1 : 0,
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbtools.Update(
|
dbtools.Update(
|
||||||
|
@ -763,7 +769,7 @@ function GetApp(): ModuleType {
|
||||||
logger.Log(
|
logger.Log(
|
||||||
`Login attempt with invalid pw: ${pw} to ${
|
`Login attempt with invalid pw: ${pw} to ${
|
||||||
isScript ? 'script' : 'website'
|
isScript ? 'script' : 'website'
|
||||||
}${cid ? ', CID:' + cid : ''}`,
|
}`,
|
||||||
logger.GetColor('cyan')
|
logger.GetColor('cyan')
|
||||||
)
|
)
|
||||||
res.json({
|
res.json({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue