diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php index 2ea79077b..6122208d8 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php @@ -321,10 +321,11 @@ abstract class BaseModel * mountpoints starting with a single / */ if (strpos($model_xml->mount, "//") === 0) { - $this->internal_mountpoint = $model_xml->mount; + $src_mountpoint = $model_xml->mount; } else { - $this->internal_mountpoint = "/opnsense{$model_xml->mount}"; + $src_mountpoint = "/opnsense{$model_xml->mount}"; } + $this->internal_mountpoint = $model_xml->mount; if (!empty($model_xml->version)) { $this->internal_model_version = (string)$model_xml->version; @@ -336,7 +337,7 @@ abstract class BaseModel // use an xpath expression to find the root of our model in the config.xml file // if found, convert the data to a simple structure (or create an empty array) - $tmp_config_data = $internalConfigHandle->xpath($this->internal_mountpoint); + $tmp_config_data = $internalConfigHandle->xpath($src_mountpoint); if ($tmp_config_data->length > 0) { $config_array = simplexml_import_dom($tmp_config_data->item(0)); } else { @@ -490,17 +491,11 @@ abstract class BaseModel { // calculate root node from mountpoint $xml_root_node = ""; - $str_parts = explode("/", str_replace("//", "/", $this->internal_mountpoint)); - - for ($i = 0; $i < count($str_parts); $i++) { - if ($str_parts[$i] != "") { - $xml_root_node .= "<" . $str_parts[$i] . ">"; - } + foreach (explode("/", ltrim($this->internal_mountpoint, "/")) as $part) { + $xml_root_node .= "<" . $part . ">"; } - for ($i = count($str_parts) - 1; $i >= 0; $i--) { - if ($str_parts[$i] != "") { - $xml_root_node .= ""; - } + foreach (array_reverse(explode("/", ltrim($this->internal_mountpoint, "/"))) as $part) { + $xml_root_node .= ""; } $xml = new SimpleXMLElement($xml_root_node); @@ -532,14 +527,11 @@ abstract class BaseModel // find parent of mountpoint (create if it doesn't exists) $target_node = $config_xml; - $str_parts = explode("/", str_replace("//", "/", $this->internal_mountpoint)); - for ($i = 0; $i < count($str_parts); $i++) { - if ($str_parts[$i] != "") { - if (count($target_node->xpath($str_parts[$i])) == 0) { - $target_node = $target_node->addChild($str_parts[$i]); - } else { - $target_node = $target_node->xpath($str_parts[$i])[0]; - } + foreach (explode("/", ltrim($this->internal_mountpoint, "/")) as $part) { + if (count($target_node->xpath($part)) == 0) { + $target_node = $target_node->addChild($part); + } else { + $target_node = $target_node->xpath($part)[0]; } }