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/1648/head
Bernd Storath 8 months ago
parent
commit
61bc62903f
  1. 18
      src/components/Clients/CreateDialog.vue
  2. 0
      src/server/api/cnf/[clientOneTimeLink].ts
  3. 15
      src/server/utils/WireGuard.ts
  4. 2
      src/server/utils/config.ts
  5. 7
      src/server/utils/types.ts
  6. 4
      src/stores/modal.ts
  7. 2
      src/utils/api.ts

18
src/components/Clients/CreateDialog.vue

@ -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>

0
src/server/api/cnf/:clientsOnteTimeLink.ts → src/server/api/cnf/[clientOneTimeLink].ts

15
src/server/utils/WireGuard.ts

@ -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();

2
src/server/utils/config.ts

@ -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';

7
src/server/utils/types.ts

@ -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(
{

4
src/stores/modal.ts

@ -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

2
src/utils/api.ts

@ -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',
});
}

Loading…
Cancel
Save