From de64f1ed000b05990acb78e55081b7cf082dd43b Mon Sep 17 00:00:00 2001 From: core Date: Tue, 26 Sep 2023 11:34:31 -0400 Subject: [PATCH] [web] role deletion confirm, host index page --- tfweb/src/lib/i18n/locales/en.json | 20 ++- tfweb/src/routes/+layout.svelte | 6 +- tfweb/src/routes/hosts/+page.svelte | 25 +++- tfweb/src/routes/roles/+page.svelte | 20 +-- .../roles/[role_id]/delete/+page.svelte | 137 ++++++++++++++++++ 5 files changed, 182 insertions(+), 26 deletions(-) create mode 100644 tfweb/src/routes/roles/[role_id]/delete/+page.svelte diff --git a/tfweb/src/lib/i18n/locales/en.json b/tfweb/src/lib/i18n/locales/en.json index 949fabb..2d75fbb 100644 --- a/tfweb/src/lib/i18n/locales/en.json +++ b/tfweb/src/lib/i18n/locales/en.json @@ -88,9 +88,22 @@ "role": "Role", "lastseen": "Last Seen", "actions": "Actions", - "ipaddr": "IP Address" + "ipaddr": "IP Address", + "edit": "Edit", + "enroll": "Enroll", + "delete": "Delete", + "config": "Configuration" }, "roles": { + "delete": { + "title": "Are you sure you want to delete the role {rule}?", + "explainer": "This action cannot be undone. This role must be removed from all hosts, lighthouses, and relays prior to deleting it.", + "confirm": "I'm sure", + "cancel": "Nevermind", + "error": { + "ERR_DB_ERROR": "Removal failed (role was probably still attached to a host)" + } + }, "create": "Add", "explain": "Roles control how hosts, lighthouses, and relays communicate through firewall rules.", "noroles": "You don't have any roles. You'll need to add at least one before you can add any hosts.", @@ -129,7 +142,7 @@ } }, "edit": { - "title": "Editing rule {rule}", + "title": "Editing role {rule}", "any": "Any", "name": "Role name", "desc": "Role description", @@ -141,7 +154,8 @@ "description": "Description", "protocol": "Protocol", "portrange": "Port range", - "allowedrole": "Allowed role" + "allowedrole": "Allowed role", + "actions": "Actions" }, "ruleremove": "Remove rule", "ruleedit": "Edit rule", diff --git a/tfweb/src/routes/+layout.svelte b/tfweb/src/routes/+layout.svelte index c28cee0..410aed6 100644 --- a/tfweb/src/routes/+layout.svelte +++ b/tfweb/src/routes/+layout.svelte @@ -8,8 +8,10 @@ onMount(async () => { const bootstrap = await import("bootstrap/dist/js/bootstrap.js"); - const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]') - const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl)) + document.onload(() => { + const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]') + const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl)) + }); }) diff --git a/tfweb/src/routes/hosts/+page.svelte b/tfweb/src/routes/hosts/+page.svelte index 5192584..0224b22 100644 --- a/tfweb/src/routes/hosts/+page.svelte +++ b/tfweb/src/routes/hosts/+page.svelte @@ -8,6 +8,7 @@ import {PUBLIC_BASE_URL} from "$env/static/public"; import {Configuration, HostsApi, NetworksApi, RolesApi} from "$lib/api"; import type {Host} from "$lib/api/models/Host.ts"; + import type {Role} from "$lib/api/models/Role.ts"; import AdminLayout from "$components/AdminLayout.svelte"; let loading = true; @@ -16,6 +17,7 @@ $: currentlyLoading = $isLoading || loading; let hosts: Host[] = []; + let roles: Role[] = []; logSetup(); let logger = new Logger("hosts/+page.svelte"); @@ -74,8 +76,20 @@ console.log(hosts); + const rolesApi = new RolesApi(configuration); + roles = (await rolesApi.rolesList()).data!; + loading = false; - }) + }); + + function getRoleName(byId: string): string { + for (let i = 0; i < roles.length; i++) { + if (roles[i].id == byId) { + return roles[i].name!; + } + } + return "Unknown"; + } @@ -103,9 +117,14 @@ {host.name} {host.metadata?.lastSeenAt} {host.ipAddress} - {host.roleID} + {getRoleName(host.roleID)} - +
+ + + + +
{/if} diff --git a/tfweb/src/routes/roles/+page.svelte b/tfweb/src/routes/roles/+page.svelte index 5a18fdd..70697a9 100644 --- a/tfweb/src/routes/roles/+page.svelte +++ b/tfweb/src/routes/roles/+page.svelte @@ -77,22 +77,6 @@ window.location.href = "/roles/add"; } - async function roleDelete(id: string) { - const configuration = new Configuration({ - basePath: PUBLIC_BASE_URL, - accessToken: window.localStorage.getItem("session") + " " + window.localStorage.getItem("mfa") - }); - - const rolesApi = new RolesApi(configuration); - - await rolesApi.roleDelete( - { - roleID: id - } - ); - - window.location.reload(); - } @@ -131,8 +115,8 @@ {role.description}
- - + +
diff --git a/tfweb/src/routes/roles/[role_id]/delete/+page.svelte b/tfweb/src/routes/roles/[role_id]/delete/+page.svelte new file mode 100644 index 0000000..e97de91 --- /dev/null +++ b/tfweb/src/routes/roles/[role_id]/delete/+page.svelte @@ -0,0 +1,137 @@ + + + + {$t("common.title", {values: {title: $t("common.page.roles")}})} + + + + +

{$t("roles.delete.title", {values: {rule: role.data.name}})}

+

{$t("roles.delete.explainer")}

+ {#if loading} + + {:else} + + {/if} + + {#if hasFormErr} +

{formErr}

+ {/if} +
+