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
51c3f922
Commit
51c3f922
authored
Jun 20, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) move xml2array() to upgrade_config.inc, included by config.lib.inc.
parent
8d0e40e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
110 deletions
+109
-110
pfsense-utils.inc
src/etc/inc/pfsense-utils.inc
+0
-108
upgrade_config.inc
src/etc/inc/upgrade_config.inc
+109
-0
getserviceproviders.php
src/www/getserviceproviders.php
+0
-2
No files found.
src/etc/inc/pfsense-utils.inc
View file @
51c3f922
...
...
@@ -27,114 +27,6 @@
*/
/* This xml 2 array function is courtesy of the php.net comment section on xml_parse.
* it is roughly 4 times faster then our existing pfSense parser but due to the large
* size of the RRD xml dumps this is required.
* The reason we do not use it for pfSense is that it does not know about array fields
* which causes it to fail on array fields with single items. Possible Todo?
*/
function
xml2array
(
$contents
,
$get_attributes
=
1
,
$priority
=
'tag'
)
{
if
(
!
function_exists
(
'xml_parser_create'
))
{
return
array
();
}
$parser
=
xml_parser_create
(
''
);
xml_parser_set_option
(
$parser
,
XML_OPTION_TARGET_ENCODING
,
"UTF-8"
);
xml_parser_set_option
(
$parser
,
XML_OPTION_CASE_FOLDING
,
0
);
xml_parser_set_option
(
$parser
,
XML_OPTION_SKIP_WHITE
,
1
);
xml_parse_into_struct
(
$parser
,
trim
(
$contents
),
$xml_values
);
xml_parser_free
(
$parser
);
if
(
!
$xml_values
)
{
return
;
//Hmm...
}
$xml_array
=
array
();
$parents
=
array
();
$opened_tags
=
array
();
$arr
=
array
();
$current
=
&
$xml_array
;
$repeated_tag_index
=
array
();
foreach
(
$xml_values
as
$data
)
{
unset
(
$attributes
,
$value
);
extract
(
$data
);
$result
=
array
();
$attributes_data
=
array
();
if
(
isset
(
$value
))
{
if
(
$priority
==
'tag'
)
{
$result
=
$value
;
}
else
{
$result
[
'value'
]
=
$value
;
}
}
if
(
isset
(
$attributes
)
and
$get_attributes
)
{
foreach
(
$attributes
as
$attr
=>
$val
)
{
if
(
$priority
==
'tag'
)
{
$attributes_data
[
$attr
]
=
$val
;
}
else
{
$result
[
'attr'
][
$attr
]
=
$val
;
//Set all the attributes in a array called 'attr'
}
}
}
if
(
$type
==
"open"
)
{
$parent
[
$level
-
1
]
=
&
$current
;
if
(
!
is_array
(
$current
)
||
(
!
in_array
(
$tag
,
array_keys
(
$current
))))
{
$current
[
$tag
]
=
$result
;
if
(
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$current
=
&
$current
[
$tag
];
}
else
{
if
(
isset
(
$current
[
$tag
][
0
]))
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
}
else
{
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
2
;
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
unset
(
$current
[
$tag
.
'_attr'
]);
}
}
$last_item_index
=
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
-
1
;
$current
=
&
$current
[
$tag
][
$last_item_index
];
}
}
elseif
(
$type
==
"complete"
)
{
if
(
!
isset
(
$current
[
$tag
]))
{
$current
[
$tag
]
=
$result
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
if
(
$priority
==
'tag'
and
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
}
}
else
{
if
(
isset
(
$current
[
$tag
][
0
])
and
is_array
(
$current
[
$tag
]))
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
if
(
$priority
==
'tag'
and
$get_attributes
and
$attributes_data
)
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
}
else
{
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
if
(
$priority
==
'tag'
and
$get_attributes
)
{
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
unset
(
$current
[
$tag
.
'_attr'
]);
}
if
(
$attributes_data
)
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
//0 and 1 index is already taken
}
}
}
elseif
(
$type
==
'close'
)
{
$current
=
&
$parent
[
$level
-
1
];
}
}
return
(
$xml_array
);
}
/* Returns the calculated bit length of the prefix delegation from the WAN interface */
/* DHCP-PD is variable, calculate from the prefix-len on the WAN interface */
...
...
src/etc/inc/upgrade_config.inc
View file @
51c3f922
...
...
@@ -42,6 +42,115 @@ function dump_rrd_to_xml($rrddatabase, $xmldumpfile)
return
(
$dumpret
);
}
/* This xml 2 array function is courtesy of the php.net comment section on xml_parse.
* it is roughly 4 times faster then our existing pfSense parser but due to the large
* size of the RRD xml dumps this is required.
* The reason we do not use it for pfSense is that it does not know about array fields
* which causes it to fail on array fields with single items. Possible Todo?
*/
function
xml2array
(
$contents
,
$get_attributes
=
1
,
$priority
=
'tag'
)
{
if
(
!
function_exists
(
'xml_parser_create'
))
{
return
array
();
}
$parser
=
xml_parser_create
(
''
);
xml_parser_set_option
(
$parser
,
XML_OPTION_TARGET_ENCODING
,
"UTF-8"
);
xml_parser_set_option
(
$parser
,
XML_OPTION_CASE_FOLDING
,
0
);
xml_parser_set_option
(
$parser
,
XML_OPTION_SKIP_WHITE
,
1
);
xml_parse_into_struct
(
$parser
,
trim
(
$contents
),
$xml_values
);
xml_parser_free
(
$parser
);
if
(
!
$xml_values
)
{
return
;
//Hmm...
}
$xml_array
=
array
();
$parents
=
array
();
$opened_tags
=
array
();
$arr
=
array
();
$current
=
&
$xml_array
;
$repeated_tag_index
=
array
();
foreach
(
$xml_values
as
$data
)
{
unset
(
$attributes
,
$value
);
extract
(
$data
);
$result
=
array
();
$attributes_data
=
array
();
if
(
isset
(
$value
))
{
if
(
$priority
==
'tag'
)
{
$result
=
$value
;
}
else
{
$result
[
'value'
]
=
$value
;
}
}
if
(
isset
(
$attributes
)
and
$get_attributes
)
{
foreach
(
$attributes
as
$attr
=>
$val
)
{
if
(
$priority
==
'tag'
)
{
$attributes_data
[
$attr
]
=
$val
;
}
else
{
$result
[
'attr'
][
$attr
]
=
$val
;
//Set all the attributes in a array called 'attr'
}
}
}
if
(
$type
==
"open"
)
{
$parent
[
$level
-
1
]
=
&
$current
;
if
(
!
is_array
(
$current
)
||
(
!
in_array
(
$tag
,
array_keys
(
$current
))))
{
$current
[
$tag
]
=
$result
;
if
(
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$current
=
&
$current
[
$tag
];
}
else
{
if
(
isset
(
$current
[
$tag
][
0
]))
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
}
else
{
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
2
;
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
unset
(
$current
[
$tag
.
'_attr'
]);
}
}
$last_item_index
=
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
-
1
;
$current
=
&
$current
[
$tag
][
$last_item_index
];
}
}
elseif
(
$type
==
"complete"
)
{
if
(
!
isset
(
$current
[
$tag
]))
{
$current
[
$tag
]
=
$result
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
if
(
$priority
==
'tag'
and
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
}
}
else
{
if
(
isset
(
$current
[
$tag
][
0
])
and
is_array
(
$current
[
$tag
]))
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
if
(
$priority
==
'tag'
and
$get_attributes
and
$attributes_data
)
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
}
else
{
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
if
(
$priority
==
'tag'
and
$get_attributes
)
{
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
unset
(
$current
[
$tag
.
'_attr'
]);
}
if
(
$attributes_data
)
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
//0 and 1 index is already taken
}
}
}
elseif
(
$type
==
'close'
)
{
$current
=
&
$parent
[
$level
-
1
];
}
}
return
(
$xml_array
);
}
function
migrate_rrd_format
(
$rrdoldxml
,
$rrdnewxml
)
{
if
(
!
file_exists
(
"/tmp/rrd_notice_sent.txt"
))
{
$_gb
=
exec
(
"echo 'Converting RRD configuration to new format. This might take a bit...' | wall"
);
...
...
src/www/getserviceproviders.php
View file @
51c3f922
...
...
@@ -29,13 +29,11 @@
require_once
(
"guiconfig.inc"
);
require_once
(
"services.inc"
);
require_once
(
"pfsense-utils.inc"
);
require_once
(
"system.inc"
);
$serviceproviders_xml
=
"/usr/local/opnsense/contrib/mobile-broadband-provider-info/serviceproviders.xml"
;
$serviceproviders_contents
=
file_get_contents
(
$serviceproviders_xml
);
$serviceproviders_attr
=
xml2array
(
$serviceproviders_contents
,
1
,
"attr"
);
$serviceproviders
=
&
$serviceproviders_attr
[
'serviceproviders'
][
'country'
];
function
get_country_providers
(
$country
)
...
...
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