@@ -119,7 +119,7 @@ function create_jwt_server_key($rotate=false) {
119119 # Create a new server key if one is not set
120120 if (empty ($ api_config ["server_key " ]) or $ rotate === true ) {
121121 $ config ["installedpackages " ]["package " ][$ pkg_index ]["conf " ]["server_key " ] = bin2hex (random_bytes (32 ));
122- write_config ();
122+ write_config (" API server key created " );
123123 }
124124}
125125
@@ -345,10 +345,11 @@ function get_pfsense_if_id($interface) {
345345 }
346346}
347347
348- // Check if input is valid for rule source and destination
348+ # Check if input is valid for rule source and destination
349+ # TODO: this function is messy, clean it up
349350function is_valid_rule_addr ($ addr , $ direction ) {
350351 // Variables
351- $ addr_types = array ("any " , "pppoe " , "l2tp " ); // Array of special src/dst types
352+ $ addr_types = array ("any " , "pppoe " , "l2tp " , " (self) " ); // Array of special src/dst types
352353 $ ret_val = array ("valid " => true , "data " => array ());
353354 // Check if our source values are valid
354355 if (is_string ($ addr )) {
@@ -357,24 +358,34 @@ function is_valid_rule_addr($addr, $direction) {
357358 $ addr_not = true ;
358359 $ addr = str_replace ("! " , "" , $ addr );
359360 }
360- // Check if our source data is valid
361- $ addr_if = str_replace ("ip " , "" , $ addr ); // Save seperate variable to check for interface sourcees
361+
362+ // Check if our data is valid
363+ $ addr_if = str_replace ("ip " , "" , $ addr );
364+
362365 if (is_ipaddr ($ addr ) or is_subnet ($ addr )) {
363366 $ ret_val ["data " ] = array ($ direction => array ("address " => $ addr ));
364367 } elseif (is_alias ($ addr )) {
365368 $ ret_val ["data " ] = array ($ direction => array ("address " => $ addr ));
366369 } elseif (get_pfsense_if_id ($ addr_if )) {
367370 $ addr_pfif = get_pfsense_if_id ($ addr_if ); // Save our interface pfid
371+
368372 // If source was interface address (ending in ip), otherwise assume entire subnet
369373 if (str_replace ($ addr_if , "" , $ addr ) === "ip " ) {
370374 $ ret_val ["data " ] = array ($ direction => array ("network " => $ addr_pfif . "ip " ));
371375 } else {
372376 $ ret_val ["data " ] = array ($ direction => array ("network " => $ addr_pfif ));
373377 }
374378 } elseif (in_array ($ addr , $ addr_types )) {
379+ # Format config for any address
375380 if ($ addr === "any " ) {
376381 $ ret_val ["data " ] = array ($ direction => array ("any " => "" ));
377- } else {
382+ }
383+ # Do not allow (self) address if direction is source
384+ elseif ($ addr === "(self) " and $ direction === "source " ) {
385+ $ ret_val ["valid " ] = false ;
386+ }
387+ # Otherwise, Format config as network
388+ else {
378389 $ ret_val ["data " ] = array ($ direction => array ("network " => $ addr ));
379390 }
380391 } else {
@@ -690,36 +701,6 @@ function unbound_reload_config() {
690701 }
691702}
692703
693- // Check if a DNS Resolver (Unbound) host override already exists
694- function is_unbound_fqdn ($ hostname , $ domain , $ instance_id =null ) {
695- # Local variables
696- global $ config ;
697- $ curr_hosts = (array_key_exists ("hosts " , $ config ["unbound " ])) ? $ config ["unbound " ]["hosts " ] : [];
698- $ host_exists = false ;
699- $ index = 0 ;
700-
701- # Loop through each host override and check if the FQDN already exists
702- foreach ($ curr_hosts as $ host_ent ) {
703- # Check the FQDN matches this entry
704- if ($ host_ent ["host " ] === $ hostname and $ host_ent ["domain " ] === $ domain ) {
705- # If we are working with an existing instance, allow existing FQDN if ID matches
706- if ($ index !== $ instance_id ) {
707- return true ;
708- }
709- }
710-
711- # Check FQDN within host override aliases as well
712- if (is_array ($ host_ent ["aliases " ])) {
713- foreach ($ host_ent ["aliases " ]["item " ] as $ alias_ent ) {
714- if ($ alias_ent ["host " ] === $ hostname and $ alias_ent ["domain " ] === $ domain ) {
715- return true ;
716- }
717- }
718- }
719- $ index ++;
720- }
721- return $ host_exists ;
722- }
723704
724705// Get a complete config list of ALL interfaces. Based off interfaces_assign.php
725706function get_all_avail_interfaces () {
0 commit comments