From 42e117deb1a3f9b61cb09ee9435599020703ba2f Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Thu, 18 Aug 2022 13:02:05 +1000 Subject: [PATCH 1/7] added skeleton ACL class --- src/lib/common/classes.ts | 8 ++++++++ src/lib/common/stores.js | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/common/classes.ts b/src/lib/common/classes.ts index 22a7f00..5384a6e 100644 --- a/src/lib/common/classes.ts +++ b/src/lib/common/classes.ts @@ -14,6 +14,14 @@ export class Device { } } +export class ACL { + public groups: {[key: string]: string} = {} + + public constructor(init?: Partial) { + Object.assign(this, init); + } +} + export class Route { advertisedRoutes: string[] = []; enabledRoutes: string[] = []; diff --git a/src/lib/common/stores.js b/src/lib/common/stores.js index 0873d52..b3502a1 100644 --- a/src/lib/common/stores.js +++ b/src/lib/common/stores.js @@ -1,5 +1,5 @@ import { writable } from 'svelte/store'; -import { Device, User } from '$lib/common/classes'; +import { Device, User, ACL } from '$lib/common/classes'; // used to store the value of an alert across all components export const alertStore = writable(''); @@ -24,4 +24,6 @@ export const deviceSearchStore = writable(''); export const deviceSortStore = writable('id'); export const deviceSortDirectionStore = writable('ascending'); export const userSortStore = writable('id'); -export const sortDirectionStore = writable('ascending'); \ No newline at end of file +export const sortDirectionStore = writable('ascending'); +// stores ACL object +export const aclStore = writable(new ACL()); \ No newline at end of file From 60697dcc6a2dbccfbc26ffd4ebb83ed15ee5402d Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Thu, 18 Aug 2022 13:26:15 +1000 Subject: [PATCH 2/7] changed group keys to have string arrays --- src/lib/common/classes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/common/classes.ts b/src/lib/common/classes.ts index 5384a6e..baf7684 100644 --- a/src/lib/common/classes.ts +++ b/src/lib/common/classes.ts @@ -15,7 +15,7 @@ export class Device { } export class ACL { - public groups: {[key: string]: string} = {} + public groups: {[key: string]: [string]} = {} public constructor(init?: Partial) { Object.assign(this, init); From fa28d334e0af4c55ad0eae68e3808a0370baa1a9 Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Mon, 22 Aug 2022 10:55:39 +1000 Subject: [PATCH 3/7] minor cleanup, added flag switch in html --- src/lib/common/Stores.svelte | 1 + src/lib/common/stores.js | 19 ++++++++++++++----- src/lib/settings/DevSettings.svelte | 12 ++++++++++++ src/routes/settings.html/+page.svelte | 3 +++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/lib/settings/DevSettings.svelte diff --git a/src/lib/common/Stores.svelte b/src/lib/common/Stores.svelte index 628e89c..2c5713d 100644 --- a/src/lib/common/Stores.svelte +++ b/src/lib/common/Stores.svelte @@ -24,6 +24,7 @@ // stores URL and API key URLStore.set(localStorage.getItem('headscaleURL') || ''); + // remove trailing slashes when storing the URL URLStore.subscribe((val) => localStorage.setItem('headscaleURL', val.replace(/\/+$/, ''))); APIKeyStore.set(localStorage.getItem('headscaleAPIKey') || ''); APIKeyStore.subscribe((val) => localStorage.setItem('headscaleAPIKey', val)); diff --git a/src/lib/common/stores.js b/src/lib/common/stores.js index b3502a1..33a0883 100644 --- a/src/lib/common/stores.js +++ b/src/lib/common/stores.js @@ -1,6 +1,10 @@ import { writable } from 'svelte/store'; import { Device, User, ACL } from '$lib/common/classes'; +// +// localStorage Stores (global scope, saves to the browser) +// + // used to store the value of an alert across all components export const alertStore = writable(''); // used to determine if the API is functioning @@ -12,11 +16,6 @@ export const URLStore = writable(''); export const APIKeyStore = writable(''); // stores preauth key preference export const preAuthHideStore = writable(false); -// stores user and device data -export const userStore = writable([new User()]); -export const userFilterStore = writable([new User()]); -export const deviceStore = writable([new Device()]); -export const deviceFilterStore = writable([new Device()]); // stores search state export const userSearchStore = writable(''); export const deviceSearchStore = writable(''); @@ -25,5 +24,15 @@ export const deviceSortStore = writable('id'); export const deviceSortDirectionStore = writable('ascending'); export const userSortStore = writable('id'); export const sortDirectionStore = writable('ascending'); + +// +// Normal Stores (global scope, saves until refresh) +// + +// stores user and device data +export const userStore = writable([new User()]); +export const userFilterStore = writable([new User()]); +export const deviceStore = writable([new Device()]); +export const deviceFilterStore = writable([new Device()]); // stores ACL object export const aclStore = writable(new ACL()); \ No newline at end of file diff --git a/src/lib/settings/DevSettings.svelte b/src/lib/settings/DevSettings.svelte new file mode 100644 index 0000000..fa643ef --- /dev/null +++ b/src/lib/settings/DevSettings.svelte @@ -0,0 +1,12 @@ + + +

Developer Flags

+{#if showDevSettings} +
+

ACL Pages

+
+{/if} diff --git a/src/routes/settings.html/+page.svelte b/src/routes/settings.html/+page.svelte index d510bf3..c25d624 100644 --- a/src/routes/settings.html/+page.svelte +++ b/src/routes/settings.html/+page.svelte @@ -2,6 +2,7 @@ // // Imports // + import DevSettings from '$lib/settings/DevSettings.svelte'; import ServerSettings from '$lib/settings/ServerSettings.svelte'; import ThemeSettings from '$lib/settings/ThemeSettings.svelte'; import { onMount } from 'svelte'; @@ -26,5 +27,7 @@

Version

insert-version +
+
From b29c79fe90a9f421f87f8bc6f1bfc2ff8d2fb4be Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Mon, 22 Aug 2022 11:00:08 +1000 Subject: [PATCH 4/7] refactor stores.js to be more explicit --- src/lib/common/stores.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/common/stores.js b/src/lib/common/stores.js index 33a0883..1ad46a4 100644 --- a/src/lib/common/stores.js +++ b/src/lib/common/stores.js @@ -5,25 +5,18 @@ import { Device, User, ACL } from '$lib/common/classes'; // localStorage Stores (global scope, saves to the browser) // -// used to store the value of an alert across all components -export const alertStore = writable(''); -// used to determine if the API is functioning -export const apiTestStore = writable(''); // stores the theme export const themeStore = writable(''); // stores URL and API Key export const URLStore = writable(''); export const APIKeyStore = writable(''); -// stores preauth key preference -export const preAuthHideStore = writable(false); -// stores search state -export const userSearchStore = writable(''); -export const deviceSearchStore = writable(''); // stores sorting preferences export const deviceSortStore = writable('id'); export const deviceSortDirectionStore = writable('ascending'); export const userSortStore = writable('id'); export const sortDirectionStore = writable('ascending'); +// stores preauth key preference +export const preAuthHideStore = writable(false); // // Normal Stores (global scope, saves until refresh) @@ -35,4 +28,11 @@ export const userFilterStore = writable([new User()]); export const deviceStore = writable([new Device()]); export const deviceFilterStore = writable([new Device()]); // stores ACL object -export const aclStore = writable(new ACL()); \ No newline at end of file +export const aclStore = writable(new ACL()); +// used to store the value of an alert across all components +export const alertStore = writable(''); +// used to determine if the API is functioning +export const apiTestStore = writable(''); +// stores search state +export const userSearchStore = writable(''); +export const deviceSearchStore = writable(''); \ No newline at end of file From a5ed48bda0839092282166beb4093cdcc56aeb5c Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Sat, 10 Sep 2022 13:17:10 +1000 Subject: [PATCH 5/7] added toggle to show groups page under dev settings --- src/lib/common/Stores.svelte | 6 +++++- src/lib/common/nav.svelte | 13 +++++++++++++ src/lib/common/stores.js | 4 ++++ src/lib/settings/DevSettings.svelte | 3 ++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lib/common/Stores.svelte b/src/lib/common/Stores.svelte index 2c5713d..69f3130 100644 --- a/src/lib/common/Stores.svelte +++ b/src/lib/common/Stores.svelte @@ -1,6 +1,6 @@ diff --git a/src/lib/common/nav.svelte b/src/lib/common/nav.svelte index 45b1aab..4300ade 100644 --- a/src/lib/common/nav.svelte +++ b/src/lib/common/nav.svelte @@ -3,6 +3,7 @@ import { fade } from 'svelte/transition'; import { writable } from 'svelte/store'; import { base } from '$app/paths'; + import { showACLPagesStore } from './stores'; // navigation bar variables let navExpanded = writable(''); @@ -46,6 +47,18 @@ User View + {#if $showACLPagesStore} + + + + + Group View + + {/if} diff --git a/src/lib/common/stores.js b/src/lib/common/stores.js index 1ad46a4..865caca 100644 --- a/src/lib/common/stores.js +++ b/src/lib/common/stores.js @@ -18,6 +18,10 @@ export const sortDirectionStore = writable('ascending'); // stores preauth key preference export const preAuthHideStore = writable(false); +// Dev Setting Stores +// Shows or Hides ACL Settings +export const showACLPagesStore = writable(false); + // // Normal Stores (global scope, saves until refresh) // diff --git a/src/lib/settings/DevSettings.svelte b/src/lib/settings/DevSettings.svelte index fa643ef..ae1d721 100644 --- a/src/lib/settings/DevSettings.svelte +++ b/src/lib/settings/DevSettings.svelte @@ -1,4 +1,5 @@

Developer Flags

{#if showDevSettings}
-

ACL Pages

+

ACL Pages

{/if} From 438639804fdbfcd5cac7c91d52b174890523f7e3 Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Sat, 10 Sep 2022 13:25:02 +1000 Subject: [PATCH 6/7] added group view page --- src/routes/groups.html/+page.svelte | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/routes/groups.html/+page.svelte diff --git a/src/routes/groups.html/+page.svelte b/src/routes/groups.html/+page.svelte new file mode 100644 index 0000000..6eacf2e --- /dev/null +++ b/src/routes/groups.html/+page.svelte @@ -0,0 +1,25 @@ + + + + {#if showACLPagesStore} + + {/if} + From df2737e0ef8e71763df38bc45d18c715eda3bb31 Mon Sep 17 00:00:00 2001 From: Christopher Bisset Date: Sat, 10 Sep 2022 13:26:04 +1000 Subject: [PATCH 7/7] removed artificial delay in groups view --- src/routes/groups.html/+page.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/groups.html/+page.svelte b/src/routes/groups.html/+page.svelte index 6eacf2e..78bbc50 100644 --- a/src/routes/groups.html/+page.svelte +++ b/src/routes/groups.html/+page.svelte @@ -10,8 +10,6 @@ let componentLoaded = false; onMount(async () => { - // Display component frontend - await new Promise((r) => setTimeout(r, 200)); componentLoaded = true; });