Use new Components in services list

This commit is contained in:
Samuel Lorch 2024-08-02 12:01:06 +02:00
parent 3c49416732
commit 05b6a2c5d1

View file

@ -2,16 +2,26 @@
import { apiCall } from '../../api'; import { apiCall } from '../../api';
import getPlugins from '../../plugins'; import getPlugins from '../../plugins';
import EnumTypeDisplay from '~/components/display/EnumTypeDisplay.vue'; import EnumTypeDisplay from '~/components/display/EnumTypeDisplay.vue';
import EnumValueDisplay from '~/components/display/EnumValueDisplay.vue';
import PortServiceDisplay from '~/components/display/PortServiceDisplay.vue';
import ArrayDisplay from '~/components/display/ArrayDisplay.vue';
const p = getPlugins(); const p = getPlugins();
let services = $ref({}); let services = $ref({});
let loading = $ref(false); let loading = $ref(false);
let selection = $ref([] as number[]); let selection = $ref([] as number[]);
const serviceValueDefinition: { [key: string]: { path: string, component: Component | undefined } } = {
'tcp': { path: 'tcp', component: PortServiceDisplay },
'udp': { path: 'udp', component: PortServiceDisplay },
'icmp': { path: 'icmp.code', component: undefined },
'group': { path: 'group.members', component: ArrayDisplay },
};
const columns = [ const columns = [
{ heading: 'Name', path: 'name' }, { heading: 'Name', path: 'name' },
{ heading: 'Type', path: 'type', component: markRaw(EnumTypeDisplay), componentProp: 'data' }, { heading: 'Type', path: 'service_type', component: markRaw(EnumTypeDisplay), componentProp: 'data', props: { definition: serviceValueDefinition } },
{ heading: 'Value', path: 'value' }, { heading: 'Value', path: 'service_type', component: markRaw(EnumValueDisplay), componentProp: 'data', props: { definition: serviceValueDefinition } },
{ heading: 'Comment', path: 'comment' }, { heading: 'Comment', path: 'comment' },
]; ];
@ -21,38 +31,13 @@ const displayData = $computed(() => {
for (const index in services) { for (const index in services) {
data.push({ data.push({
name: services[index].name, name: services[index].name,
value: getServiceValue(services[index]), service_type: services[index].service_type,
type: Object.keys(services[index].service_type)[0],
comment: services[index].comment, comment: services[index].comment,
}); });
} }
return data; return data;
}); });
function getServiceValue(s: any): string {
console.debug('test', Object.keys(s.service_type)[0]);
let value: string;
switch (Object.keys(s.service_type)[0]) {
case 'tcp':
case 'udp':
value = getServicePortRange(s.service_type[Object.keys(s.service_type)[0]]);
break;
case 'icmp':
value = 'icmp';
break;
case 'group':
value = s.children;
break;
default:
value = 'unkown';
}
return value;
}
function getServicePortRange(s:any): string {
return `${s.source}-${s.destination}`;
}
async function load(){ async function load(){
loading = true; loading = true;
let res = await apiCall('object.services.list', {}); let res = await apiCall('object.services.list', {});