|
|
|
import * as radius from 'radius';
|
|
|
|
import * as gblConfig from '../config';
|
|
|
|
import { IPacket } from './types/PacketHandler';
|
|
|
|
|
|
|
|
export type PacketDecoder = (msg: Buffer) =>
|
|
|
|
| {
|
|
|
|
packet?: radius.RadiusPacket & IPacket;
|
|
|
|
secret: string;
|
|
|
|
}
|
|
|
|
| Promise<{
|
|
|
|
packet?: radius.RadiusPacket & IPacket;
|
|
|
|
secret: string;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
export default class PackageInterface {
|
|
|
|
private static _instance?: PackageInterface;
|
|
|
|
|
|
|
|
public static get(): PackageInterface {
|
|
|
|
if (!this._instance) {
|
|
|
|
this._instance = new PackageInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public packetDecoder?: PacketDecoder;
|
|
|
|
|
|
|
|
public start = true;
|
|
|
|
|
|
|
|
public cacheTTL = 60000;
|
|
|
|
|
|
|
|
public cacheSuccessTTL = 86400;
|
|
|
|
|
|
|
|
public cacheFailTTL = 60;
|
|
|
|
|
|
|
|
public logger: (...any: unknown[]) => unknown = console.log; // eslint-disable-line no-console
|
|
|
|
|
|
|
|
private config: any = gblConfig;
|
|
|
|
|
|
|
|
public log(...any: unknown[]): void {
|
|
|
|
this.logger(...any);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getConfig(): any {
|
|
|
|
return this.config;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
public setConfig(inConfig: any) {
|
|
|
|
this.config = inConfig;
|
|
|
|
}
|
|
|
|
}
|