summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2013-09-03 12:35:13 -0300
committerRenato Botelho <garga@FreeBSD.org>2013-09-03 13:36:00 -0300
commitc59e21b5c706b46159ecc19b33977299754b07b9 (patch)
tree8daa4fcd1fc9c7f7977e6687c5358d3eeee215b5 /etc
parent7050776a100b4dada4b0865c1bfe99906551e29f (diff)
downloadpfsense-c59e21b5c706b46159ecc19b33977299754b07b9.zip
pfsense-c59e21b5c706b46159ecc19b33977299754b07b9.tar.gz
Fix #3004:
. Create a function to replace strings on deep associative arrays . Use the recent created function array_replace_values_recursive to fix VIP interface names instead of touch config.xml directly
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/upgrade_config.inc15
-rw-r--r--etc/inc/util.inc16
2 files changed, 21 insertions, 10 deletions
diff --git a/etc/inc/upgrade_config.inc b/etc/inc/upgrade_config.inc
index a78c393..569dd3a 100644
--- a/etc/inc/upgrade_config.inc
+++ b/etc/inc/upgrade_config.inc
@@ -2898,16 +2898,11 @@ function upgrade_085_to_086() {
foreach ($config['virtualip']['vip'] as $vip) {
if ($vip['mode'] != "carp")
continue;
- $vipchg[] = "s/\\([^_]\\)vip{$vip['vhid']}\\([^0-9]\\)/\\1{$vip['interface']}_vip{$vip['vhid']}\\2/g\n";
- }
- if (!empty($vipchg)) {
- file_put_contents("{$g['tmp_path']}/vipreplace", $vipchg);
- write_config();
- mwexec("/usr/bin/sed -I \"\" -f {$g['tmp_path']}/vipreplace {$g['conf_path']}/config.xml");
- require_once("config.lib.inc");
- unset($config);
- $config = parse_config(true);
- @unlink("{$g['tmp_path']}/vipreplace");
+ $config = array_replace_values_recursive(
+ $config,
+ '^vip' . $vip['vhid'] . '$',
+ "{$vip['interface']}_vip{$vip['vhid']}"
+ );
}
}
}
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index d6d05ac..6a62563 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -1778,6 +1778,22 @@ function is_file_included($file = "") {
}
/*
+ * Replace a value on a deep associative array using regex
+ */
+function array_replace_values_recursive($data, $match, $replace) {
+ if (empty($data))
+ return $data;
+
+ if (is_string($data))
+ $data = preg_replace("/{$match}/", $replace, $data);
+ else if (is_array($data))
+ foreach ($data as $k => $v)
+ $data[$k] = array_replace_values_recursive($v, $match, $replace);
+
+ return $data;
+}
+
+/*
This function was borrowed from a comment on PHP.net at the following URL:
http://www.php.net/manual/en/function.array-merge-recursive.php#73843
*/
OpenPOWER on IntegriCloud