Browse Source
Fix various issues
fix router param
fix max age
unit is seconds not ms
fix regressions
fix missing expire date in client create dialog
fix wrong type rules
fix wrong api endpoint
properly catch error running cron job
fix type issues
pull/1389/head
Bernd Storath
10 months ago
No known key found for this signature in database
GPG Key ID: D6C85685A555540F
7 changed files with
32 additions and
16 deletions
src/components/Clients/CreateDialog.vue
src/server/api/cnf/[clientOneTimeLink].ts
src/server/utils/WireGuard.ts
src/server/utils/config.ts
src/server/utils/types.ts
src/stores/modal.ts
src/utils/api.ts
@ -71,6 +71,23 @@
/ >
< / p >
< / div >
< div v-show ="globalStore.enableExpireTime" class="mt-2" >
< p class = "text-sm text-gray-500" >
< label
class = "block text-gray-900 dark:text-neutral-200 text-sm font-bold mb-2"
for = "expireDate"
>
{ { $t ( 'ExpireDate' ) } }
< / label >
< input
v - model . trim = "modalStore.clientExpireDate"
class = "rounded p-2 border-2 dark:bg-neutral-700 dark:text-neutral-200 border-gray-100 dark:border-neutral-600 focus:border-gray-200 focus:dark:border-neutral-500 dark:placeholder:text-neutral-400 outline-none w-full"
type = "date"
: placeholder = "$t('ExpireDate')"
name = "expireDate"
/ >
< / p >
< / div >
< / div >
< / div >
< / div >
@ -110,4 +127,5 @@
< script setup lang = "ts" >
const modalStore = useModalStore ( ) ;
const globalStore = useGlobalStore ( ) ;
< / script >
@ -43,7 +43,6 @@ class WireGuard {
}
debug ( 'Loading configuration...' ) ;
// TODO: Better way to invalidate cache
this . # configCache = null ;
try {
const config = await fs . readFile ( path . join ( WG_PATH , 'wg0.json' ) , 'utf8' ) ;
@ -261,7 +260,7 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
expireDate ,
} : {
name : string ;
expireDate : string ;
expireDate : string | null ;
} ) {
if ( ! name ) {
throw new Error ( 'Missing: Name' ) ;
@ -418,7 +417,7 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
expireDate ,
} : {
clientId : string ;
expireDate : string ;
expireDate : string | null ;
} ) {
const client = await this . getClient ( { clientId } ) ;
@ -577,13 +576,13 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
}
const inst = new WireGuard ( ) ;
inst . getConfig ( ) . catch ( ( err ) = > {
console . error ( err ) ;
process . exit ( 1 ) ;
} ) ;
// This also has to also start the WireGuard Server
async function cronJobEveryMinute() {
await inst . cronJobEveryMinute ( ) ;
await inst . cronJobEveryMinute ( ) . catch ( ( err ) = > {
debug ( 'Running Cron Job failed.' ) ;
console . error ( err ) ;
} ) ;
setTimeout ( cronJobEveryMinute , 60 * 1000 ) ;
}
cronJobEveryMinute ( ) ;
@ -9,7 +9,7 @@ export const PORT = process.env.PORT || '51821';
export const WEBUI_HOST = process . env . WEBUI_HOST || '0.0.0.0' ;
export const PASSWORD_HASH = process . env . PASSWORD_HASH ;
export const MAX_AGE = process . env . MAX_AGE
? parseInt ( process . env . MAX_AGE , 10 ) * 1000 * 60
? parseInt ( process . env . MAX_AGE , 10 ) * 60
: 0 ;
export const WG_PATH = process . env . WG_PATH || '/etc/wireguard/' ;
export const WG_DEVICE = process . env . WG_DEVICE || 'eth0' ;
@ -30,14 +30,13 @@ const password = z
. string ( { message : 'Password must be a valid string' } )
. pipe ( safeStringRefine ) ;
const remember = z
. boolean ( { message : 'Remember must be a valid boolean' } )
. optional ( ) ;
const remember = z . boolean ( { message : 'Remember must be a valid boolean' } ) ;
const expireDate = z
. string ( { message : 'expiredDate must be a valid string' } )
. min ( 1 , 'expiredDate must be at least 1 Character' )
. pipe ( safeStringRefine ) ;
. pipe ( safeStringRefine )
. nullable ( ) ;
export const clientIdType = z . object (
{
@ -5,12 +5,12 @@ export const useModalStore = defineStore('Modal', () => {
const clientDelete = ref < null | WGClient > ( null ) ;
const clientCreate = ref < null | boolean > ( null ) ;
const clientCreateName = ref < string > ( '' ) ;
const clientExpireDate = ref < string | null > ( null ) ;
const clientExpireDate = ref < string > ( '' ) ;
const qrcode = ref < null | string > ( null ) ;
function createClient() {
const name = clientCreateName . value ;
const expireDate = clientExpireDate . value ;
const expireDate = clientExpireDate . value || null ;
if ( ! name ) return ;
api
@ -93,7 +93,7 @@ class API {
}
async showOneTimeLink ( { clientId } : { clientId : string } ) {
return $fetch ( ` /api/wireguard/ ${ clientId } /:clientId /generateOneTimeLink` , {
return $fetch ( ` /api/wireguard/client/ ${ clientId } /generateOneTimeLink ` , {
method : 'post' ,
} ) ;
}