Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
516be375
Commit
516be375
authored
Mar 13, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync with master
parent
32359545
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
31 deletions
+15
-31
Config.php
src/opnsense/mvc/app/library/OPNsense/Core/Config.php
+15
-31
No files found.
src/opnsense/mvc/app/library/OPNsense/Core/Config.php
View file @
516be375
...
@@ -43,12 +43,6 @@ class Config extends Singleton
...
@@ -43,12 +43,6 @@ class Config extends Singleton
*/
*/
private
$config_file
=
""
;
private
$config_file
=
""
;
/**
* XMLDocument type reference to config
* @var \DOMDocument
*/
private
$configxml
=
null
;
/**
/**
* SimpleXML type reference to config
* SimpleXML type reference to config
* @var SimpleXML
* @var SimpleXML
...
@@ -140,9 +134,7 @@ class Config extends Singleton
...
@@ -140,9 +134,7 @@ class Config extends Singleton
// root node
// root node
if
(
$node
==
null
)
{
if
(
$node
==
null
)
{
$this
->
configxml
=
new
\DOMDocument
(
'1.0'
);
$this
->
simplexml
=
simplexml_load_string
(
'<'
.
$this
->
simplexml
[
0
]
->
getName
()
.
'/>'
);
$this
->
configxml
->
loadXML
(
'<'
.
$this
->
simplexml
[
0
]
->
getName
()
.
'/>'
);
$this
->
simplexml
=
simplexml_import_dom
(
$this
->
configxml
);
$node
=
$this
->
simplexml
;
$node
=
$this
->
simplexml
;
}
}
...
@@ -179,7 +171,7 @@ class Config extends Singleton
...
@@ -179,7 +171,7 @@ class Config extends Singleton
/**
/**
* Execute a xpath expression on config.xml
* Execute a xpath expression on config.xml
(full DOM implementation)
* @param $query
* @param $query
* @return \DOMNodeList
* @return \DOMNodeList
* @throws ConfigException
* @throws ConfigException
...
@@ -187,7 +179,12 @@ class Config extends Singleton
...
@@ -187,7 +179,12 @@ class Config extends Singleton
public
function
xpath
(
$query
)
public
function
xpath
(
$query
)
{
{
$this
->
checkvalid
();
$this
->
checkvalid
();
$xpath
=
new
\DOMXPath
(
$this
->
configxml
);
$configxml
=
dom_import_simplexml
(
$this
->
simplexml
);
$dom
=
new
\DOMDocument
(
'1.0'
);
$dom_sxe
=
$dom
->
importNode
(
$configxml
,
true
);
$dom
->
appendChild
(
$dom_sxe
);
$xpath
=
new
\DOMXPath
(
$dom
);
return
$xpath
->
query
(
$query
);
return
$xpath
->
query
(
$query
);
}
}
...
@@ -203,18 +200,6 @@ class Config extends Singleton
...
@@ -203,18 +200,6 @@ class Config extends Singleton
return
$this
->
simplexml
;
return
$this
->
simplexml
;
}
}
/**
* get DOMDocument
* @return XMLDocument
* @throws ConfigException
*/
public
function
getDOM
()
{
$this
->
checkvalid
();
return
$this
->
configxml
;
}
/**
/**
* init new config object, try to load current configuration
* init new config object, try to load current configuration
...
@@ -226,7 +211,7 @@ class Config extends Singleton
...
@@ -226,7 +211,7 @@ class Config extends Singleton
try
{
try
{
$this
->
load
();
$this
->
load
();
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
$this
->
config
xml
=
null
;
$this
->
simple
xml
=
null
;
}
}
}
}
...
@@ -253,9 +238,7 @@ class Config extends Singleton
...
@@ -253,9 +238,7 @@ class Config extends Singleton
}
}
);
);
$this
->
configxml
=
new
\DOMDocument
(
'1.0'
);
$this
->
simplexml
=
simplexml_load_string
(
$xml
);
$this
->
configxml
->
loadXML
(
$xml
);
$this
->
simplexml
=
simplexml_import_dom
(
$this
->
configxml
);
restore_error_handler
();
restore_error_handler
();
$this
->
statusIsValid
=
true
;
$this
->
statusIsValid
=
true
;
...
@@ -268,10 +251,13 @@ class Config extends Singleton
...
@@ -268,10 +251,13 @@ class Config extends Singleton
public
function
__toString
()
public
function
__toString
()
{
{
// reformat XML (pretty print)
// reformat XML (pretty print)
$dom
=
new
\DOMDocument
;
$configxml
=
dom_import_simplexml
(
$this
->
simplexml
);
$dom
=
new
\DOMDocument
(
'1.0'
);
$dom_sxe
=
$dom
->
importNode
(
$configxml
,
true
);
$dom
->
appendChild
(
$dom_sxe
);
$dom
->
formatOutput
=
true
;
$dom
->
formatOutput
=
true
;
$dom
->
preserveWhiteSpace
=
false
;
$dom
->
preserveWhiteSpace
=
false
;
$dom
->
loadXML
(
$
this
->
configxml
->
saveXML
());
$dom
->
loadXML
(
$
dom
->
saveXML
());
return
$dom
->
saveXML
();
return
$dom
->
saveXML
();
...
@@ -369,7 +355,6 @@ class Config extends Singleton
...
@@ -369,7 +355,6 @@ class Config extends Singleton
if
(
$this
->
statusIsValid
)
{
if
(
$this
->
statusIsValid
)
{
// if current config is valid,
// if current config is valid,
$configxml
=
$this
->
configxml
;
$simplexml
=
$this
->
simplexml
;
$simplexml
=
$this
->
simplexml
;
try
{
try
{
// try to restore config
// try to restore config
...
@@ -378,7 +363,6 @@ class Config extends Singleton
...
@@ -378,7 +363,6 @@ class Config extends Singleton
return
true
;
return
true
;
}
catch
(
ConfigException
$e
)
{
}
catch
(
ConfigException
$e
)
{
// copy / load failed, restore previous version
// copy / load failed, restore previous version
$this
->
configxml
=
$configxml
;
$this
->
simplexml
=
$simplexml
;
$this
->
simplexml
=
$simplexml
;
$this
->
statusIsValid
=
true
;
$this
->
statusIsValid
=
true
;
$this
->
save
(
null
,
true
);
$this
->
save
(
null
,
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment