mirror of https://github.com/wg-easy/wg-easy
8 changed files with 203 additions and 48 deletions
@ -1,4 +1,10 @@ |
|||||
export default defineEventHandler((event) => { |
export default defineEventHandler(async (event) => { |
||||
setHeader(event, 'Content-Type', 'application/json'); |
setHeader(event, 'Content-Type', 'application/json'); |
||||
return LANG; |
|
||||
|
const system = await InMemory.getSystem(); |
||||
|
if (system) { |
||||
|
const { lang } = system; |
||||
|
return lang; |
||||
|
} |
||||
|
return 'en'; |
||||
}); |
}); |
||||
|
@ -1,10 +1,74 @@ |
|||||
|
import type { SessionConfig } from 'h3'; |
||||
|
import type { Undefined } from '../database'; |
||||
|
|
||||
|
export type Lang = 'en' | 'ua' | 'ru' | 'tr' | 'no' | 'pl' | 'fr'; |
||||
|
export type Version = string; |
||||
|
export type SessionTimeOut = number; |
||||
|
export type Port = number; |
||||
|
export type Address = string; |
||||
|
export type PassordHash = string; |
||||
|
export type Command = string; |
||||
|
export type Key = string; |
||||
|
export type IpTables = { |
||||
|
wgPreUp: Command; |
||||
|
wgPostUp: Command; |
||||
|
wgPreDown: Command; |
||||
|
wgPostDown: Command; |
||||
|
}; |
||||
|
export type WGInterface = { |
||||
|
privateKey: Key; |
||||
|
publicKey: Key; |
||||
|
address: Address; |
||||
|
}; |
||||
|
export type WGConfig = { |
||||
|
mtu: number; |
||||
|
persistentKeepalive: number; |
||||
|
rangeAddress: Address; |
||||
|
defaultDns: Array<Address>; |
||||
|
allowedIps: Array<Address>; |
||||
|
}; |
||||
|
export enum ChartType { |
||||
|
None = 0, |
||||
|
Line = 1, |
||||
|
Area = 2, |
||||
|
Bar = 3, |
||||
|
} |
||||
|
export type TrafficStats = { |
||||
|
enabled: boolean; |
||||
|
type: ChartType; |
||||
|
}; |
||||
|
export type Prometheus = { |
||||
|
enabled: boolean; |
||||
|
password?: PassordHash | Undefined; |
||||
|
}; |
||||
|
|
||||
/** |
/** |
||||
* Representing the WireGuard network configuration data structure of a computer interface system. |
* Representing the WireGuard network configuration data structure of a computer interface system. |
||||
*/ |
*/ |
||||
type System = { |
type System = { |
||||
privateKey: string; |
interface: WGInterface; |
||||
publicKey: string; |
|
||||
address: string; |
release: Version; |
||||
|
port: number; |
||||
|
webuiHost: string; |
||||
|
// maxAge
|
||||
|
sessionTimeout: SessionTimeOut; |
||||
|
lang: Lang; |
||||
|
|
||||
|
userConfig: WGConfig; |
||||
|
|
||||
|
wgPath: string; |
||||
|
wgDevice: string; |
||||
|
wgHost: Address; |
||||
|
wgPort: Port; |
||||
|
wgConfigPort: Port; |
||||
|
|
||||
|
iptables: IpTables; |
||||
|
trafficStats: TrafficStats; |
||||
|
|
||||
|
wgEnableExpiresTime: boolean; |
||||
|
prometheus: Prometheus; |
||||
|
sessionConfig: SessionConfig; |
||||
}; |
}; |
||||
|
|
||||
export default System; |
export default System; |
||||
|
@ -0,0 +1,14 @@ |
|||||
|
import type { Undefined } from '../database'; |
||||
|
import type System from '../entities/system'; |
||||
|
|
||||
|
/** |
||||
|
* Abstract class for system-related database operations. |
||||
|
* This class provides a method for retrieving system configuration data from the database. |
||||
|
*/ |
||||
|
export default abstract class SystemRepository { |
||||
|
/** |
||||
|
* Retrieves system data from the database. |
||||
|
* @returns {Promise<System | Undefined>} The system data or null if not found. |
||||
|
*/ |
||||
|
abstract getSystem(): Promise<System | Undefined>; |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
import type User from '../entities/user'; |
||||
|
import type { Identity, Undefined } from '../database'; |
||||
|
|
||||
|
/** |
||||
|
* Abstract class for user-related database operations. |
||||
|
* This class provides methods for retrieving and saving user data. |
||||
|
*/ |
||||
|
export default abstract class UserRepository { |
||||
|
/** |
||||
|
* Retrieves a user by their ID or by User structure from the database. |
||||
|
* @param {Identity<User>} id - The ID of the user or a user. |
||||
|
* @returns {Promise<User | Undefined>} The user data or null if not found. |
||||
|
*/ |
||||
|
abstract getUser(id: Identity<User>): Promise<User | Undefined>; |
||||
|
|
||||
|
/** |
||||
|
* Creates or Updates a user in the database. |
||||
|
* @param {User} user - The user to be saved. |
||||
|
* |
||||
|
* **Note:** If the user already exists, this method will update their details. |
||||
|
* If the user does not exist, it will create a new user entry. |
||||
|
*/ |
||||
|
abstract saveUser(user: User): Promise<void>; |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
import InMemoryDP from '@/server/databases/providers/inmemory'; |
||||
|
|
||||
|
const provider = new InMemoryDP(); // TODO manage multiple providers
|
||||
|
|
||||
|
provider.connect().catch((err) => { |
||||
|
console.error(err); |
||||
|
provider |
||||
|
.disconnect() |
||||
|
.catch((err) => { |
||||
|
console.error(err); |
||||
|
}) |
||||
|
.finally(() => { |
||||
|
process.exit(1); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
export default provider; |
Loading…
Reference in new issue