Use only IP to logout

This commit is contained in:
Douglas Barone 2023-10-26 08:00:44 -04:00
parent ae101042e8
commit 27345c8840
3 changed files with 9 additions and 11 deletions

View File

@ -1,13 +1,13 @@
import { db } from '../prisma'
import { PaFirewallService } from '../services/PaFirewallService'
export async function logout(username: string, domain: string, ip: string) {
export async function logout(ip: string) {
try {
const paHosts = await db.paHost.findMany()
const pa = new PaFirewallService(paHosts[0].ip, paHosts[0].key)
await pa.logout(username, ip, domain)
await pa.logout(ip)
return true
} catch (error) {

View File

@ -39,8 +39,8 @@ export class PaFirewallService {
return true
}
async logout(username: string, ip: string, domain: string) {
const command = this.createLogoutCommand(username, ip, domain)
async logout(ip: string) {
const command = this.createLogoutCommand(ip)
const url = `https://${this.ip}/api/?type=user-id&key=${this.key}&cmd=${command}`
const response = await fetch(url, { method: 'POST' })
@ -54,7 +54,7 @@ export class PaFirewallService {
throw new Error('Failed to logout user')
}
console.log(`Logged out user ${username} from IP ${ip}`)
console.log(`Logged out user from IP ${ip}`)
return true
}
@ -72,14 +72,14 @@ export class PaFirewallService {
</uid-message>`
}
private createLogoutCommand(username: string, ip: string, domain: string) {
private createLogoutCommand(ip: string) {
return `
<uid-message>
<version>1.0</version>
<type>update</type>
<payload>
<logout>
<entry name="${domain}\\${username}" ip="${ip}" timeout="${MAP_TIMEOUT_IN_MINUTES}"/>
<entry ip="${ip}" timeout="${MAP_TIMEOUT_IN_MINUTES}"/>
</logout>
</payload>
</uid-message>`

View File

@ -36,10 +36,8 @@ export const appRouter = t.router({
).mutation(async ({ input, ctx }) => {
return await login(input.username, input.password, ctx.ip)
}),
logout: input(
z.object({ username: z.string(), domain: z.string() })
).mutation(async ({ input, ctx }) => {
return await logout(input.username, input.domain, ctx.ip)
logout: mutation(async ({ input, ctx }) => {
return await logout(ctx.ip)
}),
autoLogin: mutation(async ({ ctx }) => {