commit f1ac1733362f22aa14930d3ac83579bd29ff082d
Author: Erik Fonnesbeck <efonnes@gmail.com>
Date:   Sun Feb 13 06:44:22 2011 -0700

    In update_alias_names_upon_change function add capability to access more deeply nested sections and fields.

diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index b90246e839..0cdaa85f1a 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -1564,29 +1564,39 @@ if(!function_exists("split")) {
 	}
 }
 
-function update_alias_names_upon_change($section, $subsection, $fielda, $fieldb, $new_alias_name, $origname) {
+function update_alias_names_upon_change($section, $field, $new_alias_name, $origname) {
 	global $g, $config, $pconfig, $debug;
 	if(!$origname) 
 		return;
 
+	$sectionref = &$config;
+	foreach($section as $sectionname) {
+		if(is_array($sectionref) && isset($sectionref[$sectionname]))
+			$sectionref = &$sectionref[$sectionname];
+		else
+			return;
+	}
+
 	if($debug) $fd = fopen("{$g['tmp_path']}/print_r", "a");
 	if($debug) fwrite($fd, print_r($pconfig, true));
 
-	if($fieldb) {
-		if($debug) fwrite($fd, "fieldb exists\n");
-		for ($i = 0; isset($config["$section"]["$subsection"][$i]["$fielda"]); $i++) {
-			if($debug) fwrite($fd, "$i\n");
-			if($config["$section"]["$subsection"][$i]["$fielda"]["$fieldb"] == $origname) {
-				if($debug) fwrite($fd, "Setting old alias value $origname to $new_alias_name\n");
-				$config["$section"]["$subsection"][$i]["$fielda"]["$fieldb"] = $new_alias_name;
+	if(is_array($sectionref)) {
+		foreach($sectionref as $itemkey => $item) {
+			if($debug) fwrite($fd, "$itemkey\n");
+
+			$fieldfound = true;
+			$fieldref = &$sectionref[$itemkey];
+			foreach($field as $fieldname) {
+				if(is_array($fieldref) && isset($fieldref[$fieldname]))
+					$fieldref = &$fieldref[$fieldname];
+				else {
+					$fieldfound = false;
+					break;
+				}
 			}
-		}	
-	} else {
-		if($debug) fwrite($fd, "fieldb does not exist\n");
-		for ($i = 0; isset($config["$section"]["$subsection"][$i]["$fielda"]); $i++) {
-			if($config["$section"]["$subsection"][$i]["$fielda"] == $origname) {
-				$config["$section"]["$subsection"][$i]["$fielda"] = $new_alias_name;
+			if($fieldfound && $fieldref == $origname) {
 				if($debug) fwrite($fd, "Setting old alias value $origname to $new_alias_name\n");
+				$fieldref = $new_alias_name;
 			}
 		}
 	}
diff --git a/usr/local/www/diag_backup.php b/usr/local/www/diag_backup.php
index 5892f062c8..598f4d6db7 100755
--- a/usr/local/www/diag_backup.php
+++ b/usr/local/www/diag_backup.php
@@ -355,17 +355,14 @@ if ($_POST) {
 												// Firewall rules
 												$origname = $config['interfaces'][$iface]['descr'];
 												$newname  = $config['interfaces'][$iface]['descr'] . "Alias";
-												update_alias_names_upon_change('filter', 'rule', 'source', 'address', $newname, $origname);
-												update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $newname, $origname);
+												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
+												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
 												// NAT Rules
-												update_alias_names_upon_change('nat', 'rule', 'source', 'address', $newname, $origname);
-												update_alias_names_upon_change('nat', 'rule', 'source', 'port', $newname, $origname);
-												update_alias_names_upon_change('nat', 'rule', 'destination', 'address', $newname, $origname);
-												update_alias_names_upon_change('nat', 'rule', 'destination', 'port', $newname, $origname);
-												update_alias_names_upon_change('nat', 'rule', 'target', '', $newname, $origname);
-												update_alias_names_upon_change('nat', 'rule', 'local-port', '', $newname, $origname);
+												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
+												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
+												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
 												// Alias in an alias
-												update_alias_names_upon_change('aliases', 'alias', 'address', '', $newname, $origname);
+												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
 											}
 										}
 									}
diff --git a/usr/local/www/firewall_aliases_edit.php b/usr/local/www/firewall_aliases_edit.php
index 7307366e6a..48e86d43d9 100755
--- a/usr/local/www/firewall_aliases_edit.php
+++ b/usr/local/www/firewall_aliases_edit.php
@@ -293,19 +293,19 @@ if ($_POST) {
 		 */
 		if ($_POST['name'] <> $_POST['origname']) {
 			// Firewall rules
-			update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name'], $origname);
-			update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name'], $origname);
-			update_alias_names_upon_change('filter', 'rule', 'source', 'port', $_POST['name'], $origname);
-			update_alias_names_upon_change('filter', 'rule', 'destination', 'port', $_POST['name'], $origname);
+			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
 			// NAT Rules
-			update_alias_names_upon_change('nat', 'rule', 'source', 'address', $_POST['name'], $origname);
-			update_alias_names_upon_change('nat', 'rule', 'source', 'port', $_POST['name'], $origname);
-			update_alias_names_upon_change('nat', 'rule', 'destination', 'address', $_POST['name'], $origname);
-			update_alias_names_upon_change('nat', 'rule', 'destination', 'port', $_POST['name'], $origname);
-			update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name'], $origname);
-			update_alias_names_upon_change('nat', 'rule', 'local-port', ''	, $_POST['name'], $origname);
+			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
+			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
 			// Alias in an alias
-			update_alias_names_upon_change('aliases', 'alias', 'address', ''	, $_POST['name'], $origname);
+			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
 		}
 
 		if (isset($id) && $a_aliases[$id]) {
