Properly find PA host
This commit is contained in:
parent
ff01ff714a
commit
e80daa85e2
|
@ -5,6 +5,8 @@ import { PaFirewallService } from '../services/PaFirewallService'
|
|||
import { db } from '../prisma'
|
||||
import { LoginResult } from '../schemas/LoginResult'
|
||||
import { jwtService } from './jwt'
|
||||
import { getNetworkForIP } from './netInfo'
|
||||
import { PaHost } from '@prisma/client'
|
||||
|
||||
export async function login(
|
||||
username: string,
|
||||
|
@ -22,10 +24,22 @@ export async function login(
|
|||
|
||||
const paHosts = await db.paHost.findMany()
|
||||
|
||||
const pa = new PaFirewallService(paHosts[0].ip, paHosts[0].key)
|
||||
const network = await getNetworkForIP(ip)
|
||||
|
||||
const paHost: PaHost | undefined = paHosts.find(paHost => {
|
||||
return network?.contains(paHost.ip)
|
||||
})
|
||||
|
||||
if (!paHost) throw new Error('Rede não suportada')
|
||||
|
||||
const pa = new PaFirewallService(paHost.ip, paHost.key)
|
||||
|
||||
await pa.login({ username, ip, domain: user.domain })
|
||||
|
||||
console.log(
|
||||
`Mapped user ${user.domain}\\${username} to IP ${ip} on ${paHost.ip}`
|
||||
)
|
||||
|
||||
const jwt = jwtService.generateToken({
|
||||
displayName: user.displayName,
|
||||
username: user.username,
|
||||
|
|
|
@ -82,16 +82,15 @@ const networks = networksInfo.map(network => {
|
|||
export async function getNetworkForIP(ip: string) {
|
||||
z.string().ip().parse(ip)
|
||||
|
||||
console.log(ip)
|
||||
|
||||
const blackList = ['10.7.0.10']
|
||||
|
||||
if (blackList.includes(ip))
|
||||
return {
|
||||
name: 'Endereço IP inválido',
|
||||
shortName: 'XX',
|
||||
network: '?',
|
||||
isSupported: false
|
||||
network: undefined,
|
||||
isSupported: false,
|
||||
contains: () => false
|
||||
}
|
||||
|
||||
const network = networks.find(network => network.contains(ip))
|
||||
|
@ -100,8 +99,9 @@ export async function getNetworkForIP(ip: string) {
|
|||
return {
|
||||
name: 'Rede desconhecida',
|
||||
shortName: '--',
|
||||
network: '?',
|
||||
isSupported: false
|
||||
network: undefined,
|
||||
isSupported: false,
|
||||
contains: () => false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,8 @@ export async function getNetworkForIP(ip: string) {
|
|||
)
|
||||
|
||||
return {
|
||||
isSupported: !!paHost,
|
||||
...network,
|
||||
isSupported: !!paHost
|
||||
contains: network.contains
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,6 @@ export class PaFirewallService {
|
|||
throw new Error('Failed to map user ID to IP')
|
||||
}
|
||||
|
||||
console.log(`Mapped user ${domain}\\${username} to IP ${ip}`)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user