role page update

This commit is contained in:
core 2023-07-26 21:42:55 -04:00
parent 31d6611d79
commit e44f170c6e
Signed by: core
GPG Key ID: FDBF740DADDCEECF
3 changed files with 91 additions and 4 deletions

View File

@ -79,6 +79,9 @@
"create": "Add", "create": "Add",
"explain": "Roles control how hosts, lighthouses, and relays communicate through firewall rules.", "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.", "noroles": "You don't have any roles. You'll need to add at least one before you can add any hosts.",
"name": "Name",
"rules": "Rule count",
"description": "Description",
"add": { "add": {
"any": "Any", "any": "Any",
"name": "Role name", "name": "Role name",
@ -118,7 +121,9 @@
"2fa": "2-Factor Authentication", "2fa": "2-Factor Authentication",
"networkcreate": "Create Network", "networkcreate": "Create Network",
"hosts": "Hosts", "hosts": "Hosts",
"roles": "Roles" "roles": "Roles",
"lighthouses": "Lighthouses",
"relays": "Relays"
} }
} }
} }

View File

@ -92,6 +92,20 @@
{#if (roles.data.length === 0)} {#if (roles.data.length === 0)}
<p>{$t("roles.noroles")}</p> <p>{$t("roles.noroles")}</p>
{:else}
<table>
<tr>
<th>{$t("roles.name")}</th>
<th>{$t("roles.rules")}</th>
<th>{$t("roles.description")}</th>
</tr>
{#each roles.data as role}
<tr>
<td>{role.name}</td>
<td>{role.firewallRules.length}</td>
<td>{role.description}</td>
</tr>
{/each}
</table>
{/if} {/if}
</LoadingWrapper> </LoadingWrapper>

View File

@ -6,7 +6,8 @@
import {Logger, logSetup} from "$lib/logger"; import {Logger, logSetup} from "$lib/logger";
import type {APIError} from "$lib/auth.ts"; import type {APIError} from "$lib/auth.ts";
import {PUBLIC_BASE_URL} from "$env/static/public"; import {PUBLIC_BASE_URL} from "$env/static/public";
import {Configuration, NetworksApi, RolesApi} from "$lib/api"; import {Configuration, NetworksApi, RolesApi, FirewallRuleProtocolEnum} from "$lib/api";
import type {FirewallRule} from "$lib/api";
import AdminBar from "$components/AdminBar.svelte"; import AdminBar from "$components/AdminBar.svelte";
let loading = true; let loading = true;
@ -221,8 +222,75 @@
editingExistingTheRule = null; editingExistingTheRule = null;
} }
async function roleAdd() { function convertRule(rule: Rule): FirewallRule {
let protocol;
if (rule.protocol == RuleProtocol.ANY) {
protocol = FirewallRuleProtocolEnum.Any;
} else if (rule.protocol == RuleProtocol.TCP) {
protocol = FirewallRuleProtocolEnum.Tcp;
} else if (rule.protocol == RuleProtocol.UDP) {
protocol = FirewallRuleProtocolEnum.Udp;
} else if (rule.protocol == RuleProtocol.ICMP) {
protocol = FirewallRuleProtocolEnum.Icmp;
}
let allowedRole = undefined;
if (rule.allowedRole == null) {
allowedRole = undefined;
} else {
allowedRole = rule.allowedRole;
}
let portRange;
if (typeof rule.portRange === "number") {
portRange = {
from: rule.portRange,
to: rule.portRange
}
} else if (rule.portRange === null) {
portRange = undefined;
} else {
portRange = {
from: rule.portRange[0],
to: rule.portRange[1]
}
}
return {
protocol: protocol,
description: rule.description,
allowedRoleID: allowedRole,
portRange: portRange
};
}
async function roleAdd() {
const configuration = new Configuration({
basePath: PUBLIC_BASE_URL,
accessToken: window.localStorage.getItem("session") + " " + window.localStorage.getItem("mfa")
});
const rolesApi = new RolesApi(configuration);
let apirules = [];
for (let i = 0; i < rules.length; i++) {
apirules.push(convertRule(rules[i]));
}
await rolesApi.roleCreate(
{
roleCreateRequest: {
name: roleName,
description: roleDescription,
firewallRules: apirules
}
}
);
window.location.href = "/roles"
} }
</script> </script>