@@ -21,6 +21,7 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
2121 private $ nat_reflection ;
2222 private $ updated_by_msg ;
2323 private $ port_required ;
24+ private $ port_protocol ;
2425
2526 # Create our method constructor
2627 public function __construct () {
@@ -30,6 +31,7 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
3031 $ this ->protocols = ["tcp " , "udp " , "tcp/udp " , "icmp " , "esp " , "ah " , "gre " , "ipv6 " , "igmp " , "pim " , "ospf " ];
3132 $ this ->nat_reflection = ["enable " , "disable " , "purenat " ];
3233 $ this ->port_required = false ;
34+ $ this ->port_protocol = false ;
3335 }
3436
3537 public function action () {
@@ -48,6 +50,11 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
4850 if (array_key_exists ($ this ->initial_data ["id " ], $ this ->config ["nat " ]["rule " ])) {
4951 $ this ->id = $ this ->initial_data ["id " ];
5052 $ this ->validated_data = $ this ->config ["nat " ]["rule " ][$ this ->id ];
53+
54+ # Check if current protocol is a port based protocol
55+ if (in_array ($ this ->validated_data ["protocol " ], ["tcp " , "udp " , "tcp/udp " ])) {
56+ $ this ->port_protocol = true ;
57+ }
5158 } else {
5259 $ this ->errors [] = APIResponse \get (4016 );
5360 }
@@ -74,11 +81,15 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
7481 if (isset ($ this ->initial_data ['protocol ' ])) {
7582 # Require protocol to be a known/supported protocol
7683 if (in_array ($ this ->initial_data ['protocol ' ], $ this ->protocols )) {
77- # Only require ports if updating to port protocol from non- port protocol
84+ # Check if we are updating to a port based protocol
7885 if (in_array ($ this ->initial_data ["protocol " ], ["tcp " , "udp " , "tcp/udp " ])) {
86+ $ this ->port_protocol = true ;
87+ # Only require ports if updating to port protocol from non-port protocol
7988 if (!in_array ($ this ->validated_data ["protocol " ], ["tcp " , "udp " , "tcp/udp " ])) {
8089 $ this ->port_required = true ;
8190 }
91+ } else {
92+ $ this ->port_protocol = false ;
8293 }
8394 $ this ->validated_data ["protocol " ] = $ this ->initial_data ['protocol ' ];
8495 } else {
@@ -103,7 +114,7 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
103114
104115 private function __validate_local_port () {
105116 # Only require a local port if the protocol requires a port
106- if ($ this ->port_required ) {
117+ if ($ this ->port_required or ( isset ( $ this -> initial_data [ ' local-port ' ]) and $ this -> port_protocol ) ) {
107118 # Require client to pass in a local port to forward to the target
108119 if (isset ($ this ->initial_data ['local-port ' ])) {
109120 # Require the port to be a valid TCP/UDP port or range
@@ -159,7 +170,7 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
159170
160171 private function __validate_srcport () {
161172 # Only require a source port value if our protocol requires ports
162- if ($ this ->port_required ) {
173+ if ($ this ->port_required or ( isset ( $ this -> initial_data [ ' srcport ' ]) and $ this -> port_protocol ) ) {
163174 $ this ->initial_data ['srcport ' ] = str_replace ("- " , ": " , $ this ->initial_data ['srcport ' ]);
164175 # Require port to be a valid port or range, or be any
165176 if (!is_port_or_range ($ this ->initial_data ['srcport ' ]) and $ this ->initial_data ['srcport ' ] !== "any " ) {
@@ -174,7 +185,7 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
174185
175186 private function __validate_dstport () {
176187 # Only require a destination port value if our protocol requires ports
177- if ($ this ->port_required ) {
188+ if ($ this ->port_required or ( isset ( $ this -> initial_data [ ' dstport ' ]) and $ this -> port_protocol ) ) {
178189 $ this ->initial_data ['dstport ' ] = str_replace ("- " , ": " , $ this ->initial_data ['dstport ' ]);
179190 # Require port to be a valid port or range, or be any
180191 if (!is_port_or_range ($ this ->initial_data ['dstport ' ]) and $ this ->initial_data ['dstport ' ] !== "any " ) {
0 commit comments