@@ -18,6 +18,7 @@ require_once("api/framework/APIResponse.inc");
1818
1919class APIFirewallAliasUpdate extends APIModel {
2020 private $ type_changed ;
21+ private $ original_name ;
2122
2223 # Create our method constructor
2324 public function __construct () {
@@ -28,9 +29,10 @@ class APIFirewallAliasUpdate extends APIModel {
2829 }
2930
3031 public function action () {
31- $ this ->config ["aliases " ]["alias " ][$ this ->id ] = $ this ->validated_data ; // Write to our master config
32- $ this ->write_config (); // Apply our configuration change
33- send_event ("filter reload " ); // Ensure our firewall filter is reloaded
32+ $ this ->config ["aliases " ]["alias " ][$ this ->id ] = $ this ->validated_data ;
33+ $ this ->__rename_alias_references__ ();
34+ $ this ->write_config ();
35+ send_event ("filter reload " );
3436 return APIResponse \get (0 , $ this ->config ["aliases " ]["alias " ][$ this ->id ]);
3537 }
3638
@@ -43,6 +45,7 @@ class APIFirewallAliasUpdate extends APIModel {
4345 if ($ this ->initial_data ["id " ] === $ id or $ this ->initial_data ["id " ] === $ alias ["name " ]) {
4446 $ this ->id = $ id ;
4547 $ this ->validated_data = $ alias ;
48+ $ this ->original_name = $ alias ["name " ];
4649 break ;
4750 }
4851 }
@@ -76,7 +79,7 @@ class APIFirewallAliasUpdate extends APIModel {
7679 # Optionally allow clients to update the alias type
7780 if (isset ($ this ->initial_data ['type ' ])) {
7881 # Require alias to not be in use to change the type
79- if (!APITools \alias_in_use ($ this ->validated_data [ " name " ] )) {
82+ if (!APITools \alias_in_use ($ this ->original_name )) {
8083 # Require this type to be supported
8184 if (in_array ($ this ->initial_data ['type ' ], ["host " , "network " , "port " ])) {
8285 $ this ->type_changed = true ;
@@ -193,10 +196,17 @@ class APIFirewallAliasUpdate extends APIModel {
193196
194197 public function validate_payload () {
195198 $ this ->__validate_id ();
196- $ this ->__validate_type (); // Type must be validated before name as it depends on the original name
197199 $ this ->__validate_name ();
200+ $ this ->__validate_type ();
198201 $ this ->__validate_descr ();
199202 $ this ->__validate_address ();
200203 $ this ->__validate_detail ();
201204 }
205+
206+ private function __rename_alias_references__ () {
207+ # Only update alias references if our name was changed
208+ if ($ this ->original_name !== $ this ->validated_data ["name " ]) {
209+ update_alias_name ($ this ->validated_data ["name " ], $ this ->original_name );
210+ }
211+ }
202212}
0 commit comments