mirror of https://github.com/wg-easy/wg-easy
36 changed files with 6874 additions and 3266 deletions
@ -0,0 +1,6 @@ |
|||
{ |
|||
"trailingComma": "es5", |
|||
"tabWidth": 2, |
|||
"semi": true, |
|||
"singleQuote": true |
|||
} |
File diff suppressed because it is too large
@ -1,3 +1,3 @@ |
|||
import { createConfigForNuxt } from '@nuxt/eslint-config/flat' |
|||
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'; |
|||
|
|||
export default createConfigForNuxt({}) |
|||
export default createConfigForNuxt({}); |
|||
|
File diff suppressed because it is too large
@ -1,7 +1,7 @@ |
|||
import { LANG } from "~/utils/config"; |
|||
import { LANG } from '~/utils/config'; |
|||
|
|||
export default defineEventHandler((event) => { |
|||
assertMethod(event, "GET"); |
|||
assertMethod(event, 'GET'); |
|||
setHeader(event, 'Content-Type', 'application/json'); |
|||
return `"${LANG}"`; |
|||
}) |
|||
}); |
|||
|
@ -1,7 +1,7 @@ |
|||
import { RELEASE } from "~/utils/config"; |
|||
import { RELEASE } from '~/utils/config'; |
|||
|
|||
export default defineEventHandler((event) => { |
|||
assertMethod(event, "GET"); |
|||
assertMethod(event, 'GET'); |
|||
setHeader(event, 'Content-Type', 'application/json'); |
|||
return RELEASE; |
|||
}) |
|||
}); |
|||
|
@ -1,7 +1,7 @@ |
|||
import { UI_CHART_TYPE } from "~/utils/config"; |
|||
import { UI_CHART_TYPE } from '~/utils/config'; |
|||
|
|||
export default defineEventHandler((event) => { |
|||
assertMethod(event, "GET"); |
|||
assertMethod(event, 'GET'); |
|||
setHeader(event, 'Content-Type', 'application/json'); |
|||
return `"${UI_CHART_TYPE}"`; |
|||
}) |
|||
}); |
|||
|
@ -1,7 +1,7 @@ |
|||
import { UI_TRAFFIC_STATS } from "~/utils/config"; |
|||
import { UI_TRAFFIC_STATS } from '~/utils/config'; |
|||
|
|||
export default defineEventHandler((event) => { |
|||
assertMethod(event, "GET"); |
|||
assertMethod(event, 'GET'); |
|||
setHeader(event, 'Content-Type', 'application/json'); |
|||
return `"${UI_TRAFFIC_STATS}"`; |
|||
}) |
|||
}); |
|||
|
@ -1,9 +1,9 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "GET"); |
|||
assertMethod(event, 'GET'); |
|||
const config = await WireGuard.backupConfiguration(); |
|||
setHeader(event, 'Content-Disposition', 'attachment; filename="wg0.json"'); |
|||
setHeader(event, 'Content-Type', 'text/json'); |
|||
return config; |
|||
}) |
|||
}); |
|||
|
@ -1,12 +1,16 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "PUT"); |
|||
assertMethod(event, 'PUT'); |
|||
const clientId = getRouterParam(event, 'clientId'); |
|||
if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') { |
|||
if ( |
|||
clientId === '__proto__' || |
|||
clientId === 'constructor' || |
|||
clientId === 'prototype' |
|||
) { |
|||
throw createError({ status: 403 }); |
|||
} |
|||
const { address } = await readBody(event); |
|||
await WireGuard.updateClientAddress({ clientId, address }); |
|||
return { success: true }; |
|||
}) |
|||
}); |
|||
|
@ -1,11 +1,15 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "POST"); |
|||
assertMethod(event, 'POST'); |
|||
const clientId = getRouterParam(event, 'clientId'); |
|||
if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') { |
|||
if ( |
|||
clientId === '__proto__' || |
|||
clientId === 'constructor' || |
|||
clientId === 'prototype' |
|||
) { |
|||
throw createError({ status: 403 }); |
|||
} |
|||
await WireGuard.disableClient({ clientId }); |
|||
return { success: true }; |
|||
}) |
|||
}); |
|||
|
@ -1,11 +1,15 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "POST"); |
|||
assertMethod(event, 'POST'); |
|||
const clientId = getRouterParam(event, 'clientId'); |
|||
if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') { |
|||
if ( |
|||
clientId === '__proto__' || |
|||
clientId === 'constructor' || |
|||
clientId === 'prototype' |
|||
) { |
|||
throw createError({ status: 403 }); |
|||
} |
|||
await WireGuard.enableClient({ clientId }); |
|||
return { success: true }; |
|||
}) |
|||
}); |
|||
|
@ -1,12 +1,16 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "PUT"); |
|||
assertMethod(event, 'PUT'); |
|||
const clientId = getRouterParam(event, 'clientId'); |
|||
if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') { |
|||
if ( |
|||
clientId === '__proto__' || |
|||
clientId === 'constructor' || |
|||
clientId === 'prototype' |
|||
) { |
|||
throw createError({ status: 403 }); |
|||
} |
|||
const { name } = await readBody(event); |
|||
await WireGuard.updateClientName({ clientId, name }); |
|||
return { success: true }; |
|||
}) |
|||
}); |
|||
|
@ -1,9 +1,9 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "GET"); |
|||
assertMethod(event, 'GET'); |
|||
const clientId = getRouterParam(event, 'clientId'); |
|||
const svg = await WireGuard.getClientQRCodeSVG({ clientId }); |
|||
setHeader(event, 'Content-Type', 'image/svg+xml'); |
|||
return svg; |
|||
}) |
|||
}); |
|||
|
@ -1,11 +1,11 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
if (isMethod(event, "GET")) { |
|||
if (isMethod(event, 'GET')) { |
|||
return WireGuard.getClients(); |
|||
} else if (isMethod(event, "POST")) { |
|||
} else if (isMethod(event, 'POST')) { |
|||
const { name } = await readBody(event); |
|||
await WireGuard.createClient({ name }); |
|||
return { success: true }; |
|||
} |
|||
}) |
|||
}); |
|||
|
@ -1,8 +1,8 @@ |
|||
import WireGuard from "~/utils/WireGuard"; |
|||
import WireGuard from '~/utils/WireGuard'; |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
assertMethod(event, "PUT"); |
|||
assertMethod(event, 'PUT'); |
|||
const { file } = await readBody(event); |
|||
await WireGuard.restoreConfiguration(file); |
|||
return { success: true }; |
|||
}) |
|||
}); |
|||
|
@ -1,24 +1,29 @@ |
|||
import childProcess from 'child_process'; |
|||
|
|||
export function exec(cmd: string, {log}: {log: boolean|string} = {log: true}) { |
|||
export function exec( |
|||
cmd: string, |
|||
{ log }: { log: boolean | string } = { log: true } |
|||
) { |
|||
if (typeof log === 'string') { |
|||
|
|||
console.log(`$ ${log}`); |
|||
} else if (log === true) { |
|||
|
|||
console.log(`$ ${cmd}`); |
|||
} |
|||
|
|||
if (process.platform !== 'linux') { |
|||
return Promise.resolve(""); |
|||
return Promise.resolve(''); |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => { |
|||
childProcess.exec(cmd, { |
|||
childProcess.exec( |
|||
cmd, |
|||
{ |
|||
shell: 'bash', |
|||
}, (err, stdout) => { |
|||
}, |
|||
(err, stdout) => { |
|||
if (err) return reject(err); |
|||
return resolve(String(stdout).trim()); |
|||
}); |
|||
} |
|||
); |
|||
}); |
|||
} |
@ -1,5 +1,7 @@ |
|||
export function getRandomHex(size: number) { |
|||
const array = new Uint8Array(size); |
|||
crypto.getRandomValues(array); |
|||
return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join(''); |
|||
return Array.from(array, (byte) => byte.toString(16).padStart(2, '0')).join( |
|||
'' |
|||
); |
|||
} |
@ -1,25 +1,30 @@ |
|||
export type Theme = 'light' | 'dark' | 'auto' |
|||
export type Theme = 'light' | 'dark' | 'auto'; |
|||
|
|||
export type LocalStorage = { |
|||
theme: Theme, |
|||
uiShowCharts: '1' | '0', |
|||
lang: string |
|||
} |
|||
theme: Theme; |
|||
uiShowCharts: '1' | '0'; |
|||
lang: string; |
|||
}; |
|||
|
|||
export function getItem<K extends keyof LocalStorage>(item: K): LocalStorage[K]|null { |
|||
export function getItem<K extends keyof LocalStorage>( |
|||
item: K |
|||
): LocalStorage[K] | null { |
|||
if (import.meta.client) { |
|||
return localStorage.getItem(item) as LocalStorage[K]|null |
|||
return localStorage.getItem(item) as LocalStorage[K] | null; |
|||
} else { |
|||
return null |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
export function setItem<K extends keyof LocalStorage>(item: K, value: LocalStorage[K]) { |
|||
export function setItem<K extends keyof LocalStorage>( |
|||
item: K, |
|||
value: LocalStorage[K] |
|||
) { |
|||
if (import.meta.client) { |
|||
localStorage.setItem(item, value) |
|||
localStorage.setItem(item, value); |
|||
|
|||
return true |
|||
return true; |
|||
} else { |
|||
return false |
|||
return false; |
|||
} |
|||
} |
Loading…
Reference in new issue