Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(port forward): support multiple object types #382

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@
"enter_restricted_addresses": "Enter restricted addresses",
"restricted_addresses": "Restricted addresses",
"restricted_object": "Restricted object",
"restricted_object_tooltip": "All objects supported, except host sets with IP ranges",
"no_object": "No object",
"port_forwards_for_destination_name": "Port forwards for destination '{name}'"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,15 @@ async function createOrEditPortForward() {
:selected-label="t('ne_combobox.selected')"
:user-input-label="t('ne_combobox.user_input_label')"
ref="restrictObjectRef"
/>
>
<template #tooltip>
<NeTooltip
><template #content>{{
t('standalone.port_forward.restricted_object_tooltip')
}}</template></NeTooltip
>
</template>
</NeCombobox>
<NeToggle
:topLabel="t('standalone.port_forward.log')"
:label="
Expand Down
16 changes: 11 additions & 5 deletions src/components/standalone/users_objects/ObjectTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ function isHostSet(object: HostSet | DomainSet): object is HostSet {
<template v-if="isHostSet(object)">
<ul class="space-y-1" :class="{ 'list-inside list-disc': multipleEntries }">
<li v-for="ipaddr in object.ipaddr" :key="ipaddr">
{{ ipaddr }}
</li>
<li v-for="children in object.children" :key="children.id">
<FontAwesomeIcon v-if="icon" :icon="icon" aria-hidden="true" class="h-4 w-4" />
{{ children.name }}
<span class="inline-flex items-center gap-1.5">
<span v-if="ipaddr.includes('/ns_')">
<font-awesome-icon
:icon="objects.getObjectIcon(objects.getRecord(ipaddr)?.subtype || '')"
class="h-4 w-4"
aria-hidden="true"
/>
{{ objects.getRecord(ipaddr)?.name || '-' }}
</span>
<span v-else>{{ ipaddr }}</span>
</span>
</li>
</ul>
</template>
Expand Down
38 changes: 37 additions & 1 deletion src/stores/standalone/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { computed, ref } from 'vue'
import type { IpVersion } from '@/composables/useObjects'
import { ubusCall } from '@/lib/standalone/ubus'
import type { AxiosResponse } from 'axios'
import {
faDesktop,
faNetworkWired,
faArrowsLeftRightToLine,
faAddressCard,
faBoxArchive,
faGlobe,
faCloud,
faCircleQuestion
} from '@fortawesome/free-solid-svg-icons'

export type NsObject = {
id: string
Expand Down Expand Up @@ -70,12 +80,38 @@ export const useObjectStore = defineStore('objects', () => {
})
}

function getObjectIcon(subtype: string) {
switch (subtype) {
case 'host':
case 'dns_record':
return faDesktop
case 'cidr':
return faNetworkWired
case 'range':
return faArrowsLeftRightToLine
case 'dhcp_static_lease':
return faAddressCard
case 'host_set':
return faBoxArchive
case 'vpn_user':
return faGlobe
case 'domain_set':
return faCloud
default:
return faCircleQuestion
}
}

function getRecord(record: string) {
return objects.value.find((obj) => obj.id === record)
}

const objects = computed<Array<HostSet | DomainSet>>(() => {
return [...hostSets.value, ...domainSets.value]
})

// loading objects on store usage
load()

return { loading, load, hostSets, error, objects }
return { loading, load, hostSets, error, objects, getObjectIcon, getRecord }
})
7 changes: 1 addition & 6 deletions src/views/standalone/firewall/PortForward.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ async function listObjectSuggestions() {
try {
const res = await ubusCall('ns.redirects', 'list-object-suggestions')
destinationObjectSuggestions.value = res.data.objects.ns_dst
restrictObjectSuggestions.value = res.data.objects.ns_src.map((domainSet: DomainSet) => {
return {
...domainSet,
id: `objects/${domainSet.id}`
}
})
restrictObjectSuggestions.value = res.data.objects.ns_src
} catch (err: any) {
console.error(err)
error.value.listObjectSuggestions = t(getAxiosErrorMessage(err))
Expand Down