Commit de30d51a authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(mvc) add default config revision if none is given, fix for...

(mvc) add default config revision if none is given, fix for https://github.com/opnsense/core/issues/386

(cherry picked from commit 11913af8)
parent 784d1e70
......@@ -344,27 +344,48 @@ class Config extends Singleton
*/
private function updateRevision($revision, $node = null)
{
// input must be an array
if (is_array($revision)) {
if ($node == null) {
if (isset($this->simplexml->revision)) {
$node = $this->simplexml->revision;
} else {
$node = $this->simplexml->addChild("revision");
}
// if revision info is not provided, create a default.
if (!is_array($revision)) {
$revision = array();
// try to fetch userinfo from session
if (!empty($_SESSION["Username"])) {
$revision['username'] = $_SESSION["Username"];
} else {
$revision['username'] = "(system)";
}
foreach ($revision as $revKey => $revItem) {
if (isset($node->{$revKey})) {
// key already in revision object
$childNode = $node->{$revKey};
} else {
$childNode = $node->addChild($revKey);
}
if (is_array($revItem)) {
$this->updateRevision($revItem, $childNode);
} else {
$childNode[0] = $revItem;
}
if (!empty($_SERVER['REMOTE_ADDR'])) {
$revision['username'] .= "@".$_SERVER['REMOTE_ADDR'];
}
if (!empty($_SERVER['REQUEST_URI'])) {
// when update revision is called from a controller, log the endpoint uri
$revision['description'] = sprintf(gettext("%s made unknown change"), $_SERVER['REQUEST_URI']);
} else {
// called from a script, log script name and path
$revision['description'] = sprintf(gettext("%s made unknown change"), $_SERVER['SCRIPT_NAME']);
}
}
// always set timestamp
$revision['time'] = microtime(true);
if ($node == null) {
if (isset($this->simplexml->revision)) {
$node = $this->simplexml->revision;
} else {
$node = $this->simplexml->addChild("revision");
}
}
foreach ($revision as $revKey => $revItem) {
if (isset($node->{$revKey})) {
// key already in revision object
$childNode = $node->{$revKey};
} else {
$childNode = $node->addChild($revKey);
}
if (is_array($revItem)) {
$this->updateRevision($revItem, $childNode);
} else {
$childNode[0] = $revItem;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment