diff --git a/lib/units/device/plugins/forward/index.js b/lib/units/device/plugins/forward/index.js index 98ad63d7..018b0e4e 100644 --- a/lib/units/device/plugins/forward/index.js +++ b/lib/units/device/plugins/forward/index.js @@ -112,7 +112,7 @@ module.exports = syrup.serial() } plugin.reset = function() { - manager.removeAll() + manager.removeAll(manager) } group.on('leave', plugin.reset) diff --git a/lib/units/device/plugins/forward/util/manager.js b/lib/units/device/plugins/forward/util/manager.js index dea09e81..113d09cd 100644 --- a/lib/units/device/plugins/forward/util/manager.js +++ b/lib/units/device/plugins/forward/util/manager.js @@ -1,3 +1,7 @@ +/** +* Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 +**/ + var util = require('util') var events = require('events') var net = require('net') @@ -76,7 +80,6 @@ function ForwardHandler(conn, options) { function packetListener(id, packet) { var dest = destHandlersById[id] - if (packet) { if (!dest) { // Let's create a new connection @@ -132,6 +135,13 @@ function ForwardManager() { this.remove(id) } + for(const handlerId in handlersById) { + if (handlersById[handlerId].options.devicePort === options.devicePort) { + this.remove(handlerId) + break + } + } + var handler = new ForwardHandler(conn, options) handler.on('end', endListener.bind(this)) @@ -145,11 +155,15 @@ function ForwardManager() { if (handler) { handler.end() } + delete handlersById[id] + this.emit('remove', id) } - this.removeAll = function() { + this.removeAll = function(manager) { Object.keys(handlersById).forEach(function(id) { handlersById[id].end() + delete handlersById[id] + manager.emit('remove', id) }) } diff --git a/res/app/control-panes/advanced/port-forwarding/index.js b/res/app/control-panes/advanced/port-forwarding/index.js index 7898ec01..944c616a 100644 --- a/res/app/control-panes/advanced/port-forwarding/index.js +++ b/res/app/control-panes/advanced/port-forwarding/index.js @@ -1,9 +1,11 @@ +/** +* Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 +**/ + require('./port-forwarding.css') module.exports = angular.module('stf.port-forwarding', [ - require('stf/common-ui/table').name, - require('stf/settings').name, - require('gettext').name + require('stf/common-ui/table').name ]) .run(['$templateCache', function($templateCache) { $templateCache.put( diff --git a/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js b/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js index 0ece63fa..579df59a 100644 --- a/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js +++ b/res/app/control-panes/advanced/port-forwarding/port-forwarding-controller.js @@ -1,9 +1,12 @@ +/** +* Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 +**/ + var uuid = require('uuid') var Promise = require('bluebird') module.exports = function PortForwardingCtrl( $scope -, SettingsService ) { function defaults(id) { return { @@ -17,25 +20,26 @@ module.exports = function PortForwardingCtrl( $scope.reversePortForwards = [defaults('_default')] - SettingsService.bind($scope, { - target: 'reversePortForwards' - , source: 'reversePortForwards' - }) - $scope.$watch('device.reverseForwards', function(newValue) { - var map = Object.create(null) + let map = Object.create(null) if (newValue) { newValue.forEach(function(forward) { map[forward.id] = forward }) - } - $scope.reversePortForwards.forEach(function(forward) { - var deviceForward = map[forward.id] - forward.enabled = !!(deviceForward && deviceForward.id === forward.id && - deviceForward.devicePort === forward.devicePort) - }) + $scope.reversePortForwards.forEach(function(forward) { + let deviceForward = map[forward.id] + + if (deviceForward) { + forward.enabled = !!(deviceForward.id === forward.id && + deviceForward.devicePort === Number(forward.devicePort)) + } + else if (forward.enabled) { + $scope.removeRow(forward) + } + }) + } }) $scope.applyForward = function(forward) { diff --git a/res/app/control-panes/advanced/port-forwarding/port-forwarding.pug b/res/app/control-panes/advanced/port-forwarding/port-forwarding.pug index ed9aea50..45defc26 100644 --- a/res/app/control-panes/advanced/port-forwarding/port-forwarding.pug +++ b/res/app/control-panes/advanced/port-forwarding/port-forwarding.pug @@ -1,3 +1,7 @@ +// + Copyright © 2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 +// + .widget-container.fluid-height.stf-port-forwarding(ng-controller='PortForwardingCtrl') .heading span @@ -34,13 +38,13 @@ div.input-group.input-group-sm span.input-group-addon input(type='checkbox', ng-model='forward.enabled', ng-change='applyForward(forward)') - input.form-control(type='text', min='0', ng-model='forward.devicePort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)') + input.form-control(type='text', min='0', ng-disabled='forward.enabled', ng-model='forward.devicePort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)') td(width='40%') - input.form-control.input-sm(type='text', ng-model='forward.targetHost', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Hostname"|translate}}', ng-change='disableForward(forward)') + input.form-control.input-sm(type='text', ng-disabled='forward.enabled', ng-model='forward.targetHost', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Hostname"|translate}}', ng-change='disableForward(forward)') td span : td(width='25%') - input.form-control.input-sm(type='text', min='0', ng-model='forward.targetPort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)') + input.form-control.input-sm(type='text', min='0', ng-disabled='forward.enabled', ng-model='forward.targetPort', ng-model-options="{ updateOn: 'default blur' }", placeholder='{{"Port"|translate}}', ng-change='disableForward(forward)') td button.btn.btn-sm.btn-danger-outline(ng-click='removeRow(forward)') i.fa.fa-trash-o