update firewall api routes

This commit is contained in:
axolotle 2021-03-22 20:30:04 +01:00
parent e94d43566a
commit 6438ea5414

View file

@ -115,8 +115,8 @@ export default {
// Ports form data // Ports form data
actionChoices: [ actionChoices: [
{ value: 'open', text: this.$i18n.t('open') }, { value: 'allow', text: this.$i18n.t('open') },
{ value: 'close', text: this.$i18n.t('close') } { value: 'disallow', text: this.$i18n.t('close') }
], ],
connectionChoices: [ connectionChoices: [
{ value: 'ipv4', text: this.$i18n.t('ipv4') }, { value: 'ipv4', text: this.$i18n.t('ipv4') },
@ -128,7 +128,7 @@ export default {
{ value: 'Both', text: this.$i18n.t('both') } { value: 'Both', text: this.$i18n.t('both') }
], ],
form: { form: {
action: 'open', action: 'allow',
port: undefined, port: undefined,
connection: 'ipv4', connection: 'ipv4',
protocol: 'TCP' protocol: 'TCP'
@ -176,27 +176,17 @@ export default {
this.upnpEnabled = data.uPnP.enabled this.upnpEnabled = data.uPnP.enabled
}, },
togglePort ({ action, port, protocol, connection }) { async togglePort ({ action, port, protocol, connection }) {
return new Promise((resolve, reject) => { const confirmed = await this.$askConfirmation(
this.$askConfirmation(
this.$i18n.t('confirm_firewall_' + action, { port, protocol, connection }) this.$i18n.t('confirm_firewall_' + action, { port, protocol, connection })
).then(confirmed => { )
if (confirmed) { if (!confirmed) {
const method = action === 'open' ? 'post' : 'delete' return Promise.resolve(confirmed)
api[method](
`/firewall/port?${connection}_only`,
{ port, protocol },
{ wait: false }
).then(() => {
resolve(confirmed)
}).catch(error => {
reject(error)
})
} else {
resolve(confirmed)
} }
}) return api.put(
}) `firewall/${protocol}/${action}/${port}?${connection}_only`,
{ wait: false }
).then(() => confirmed)
}, },
async toggleUpnp (value) { async toggleUpnp (value) {
@ -204,7 +194,7 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_upnp_' + action)) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_upnp_' + action))
if (!confirmed) return if (!confirmed) return
api.get('firewall/upnp?action=' + action, null, { websocket: true, wait: true }).then(() => { api.put('firewall/upnp/' + action).then(() => {
// FIXME Couldn't test when it works. // FIXME Couldn't test when it works.
this.$refs.view.fetchQueries() this.$refs.view.fetchQueries()
}).catch(err => { }).catch(err => {
@ -215,7 +205,7 @@ export default {
onTablePortToggling (port, protocol, connection, index, value) { onTablePortToggling (port, protocol, connection, index, value) {
this.$set(this.protocols[protocol][index], connection, value) this.$set(this.protocols[protocol][index], connection, value)
const action = value ? 'open' : 'close' const action = value ? 'allow' : 'disallow'
this.togglePort({ action, port, protocol, connection }).then(toggled => { this.togglePort({ action, port, protocol, connection }).then(toggled => {
// Revert change on cancel // Revert change on cancel
if (!toggled) { if (!toggled) {