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
c2a5f03c
Commit
c2a5f03c
authored
Feb 15, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) curly braces and spaces in pfsense-utils.inc
parent
1e884f54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
721 additions
and
732 deletions
+721
-732
pfsense-utils.inc
src/etc/inc/pfsense-utils.inc
+721
-732
No files found.
src/etc/inc/pfsense-utils.inc
View file @
c2a5f03c
<?php
<?php
/*
/*
* Copyright (C) 2004-2007 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2004-2007 Scott Ullrich <sullrich@gmail.com>
* All rights reserved.
All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
POSSIBILITY OF SUCH DAMAGE.
*
*/
*/
/****f* legacy/is_private_ip
/****f* legacy/is_private_ip
* NAME
* NAME
...
@@ -35,7 +34,8 @@
...
@@ -35,7 +34,8 @@
* RESULT
* RESULT
* returns true if an ip address is in a private range
* returns true if an ip address is in a private range
******/
******/
function
is_private_ip
(
$iptocheck
)
{
function
is_private_ip
(
$iptocheck
)
{
$isprivate
=
false
;
$isprivate
=
false
;
$ip_private_list
=
array
(
$ip_private_list
=
array
(
"10.0.0.0/8"
,
"10.0.0.0/8"
,
...
@@ -44,15 +44,16 @@ function is_private_ip($iptocheck) {
...
@@ -44,15 +44,16 @@ function is_private_ip($iptocheck) {
"192.168.0.0/16"
,
"192.168.0.0/16"
,
);
);
foreach
(
$ip_private_list
as
$private
)
{
foreach
(
$ip_private_list
as
$private
)
{
if
(
ip_in_subnet
(
$iptocheck
,
$private
)
==
true
)
if
(
ip_in_subnet
(
$iptocheck
,
$private
)
==
true
)
{
$isprivate
=
true
;
$isprivate
=
true
;
}
}
}
return
$isprivate
;
return
$isprivate
;
}
}
/****f* legacy/get_dns_servers
/****f* legacy/get_dns_servers
* NAME
* NAME
* get_dns_serv
re
s - get system dns servers
* get_dns_serv
er
s - get system dns servers
* INPUTS
* INPUTS
* $dns_servers - an array of the dns servers
* $dns_servers - an array of the dns servers
* RESULT
* RESULT
...
@@ -63,9 +64,10 @@ function get_dns_servers() {
...
@@ -63,9 +64,10 @@ function get_dns_servers() {
$dns_s
=
file
(
"/etc/resolv.conf"
,
FILE_IGNORE_NEW_LINES
|
FILE_SKIP_EMPTY_LINES
);
$dns_s
=
file
(
"/etc/resolv.conf"
,
FILE_IGNORE_NEW_LINES
|
FILE_SKIP_EMPTY_LINES
);
foreach
(
$dns_s
as
$dns
)
{
foreach
(
$dns_s
as
$dns
)
{
$matches
=
""
;
$matches
=
""
;
if
(
preg_match
(
"/nameserver (.*)/"
,
$dns
,
$matches
))
if
(
preg_match
(
"/nameserver (.*)/"
,
$dns
,
$matches
))
{
$dns_servers
[]
=
$matches
[
1
];
$dns_servers
[]
=
$matches
[
1
];
}
}
}
return
array_unique
(
$dns_servers
);
return
array_unique
(
$dns_servers
);
}
}
...
@@ -134,7 +136,6 @@ function setup_polling()
...
@@ -134,7 +136,6 @@ function setup_polling()
* This function only supports the fxp driver's loadable microcode.
* This function only supports the fxp driver's loadable microcode.
******/
******/
function
setup_microcode
()
{
function
setup_microcode
()
{
/* if list */
/* if list */
$ifs
=
legacy_interface_listget
();
$ifs
=
legacy_interface_listget
();
...
@@ -154,13 +155,14 @@ function get_carp_interface_status($carpinterface) {
...
@@ -154,13 +155,14 @@ function get_carp_interface_status($carpinterface) {
$interface
=
get_real_interface
(
$interface
);
$interface
=
get_real_interface
(
$interface
);
exec
(
"/sbin/ifconfig
$interface
| /usr/bin/grep -v grep | /usr/bin/grep carp: | /usr/bin/grep 'vhid
{
$vhid
}
'"
,
$carp_query
);
exec
(
"/sbin/ifconfig
$interface
| /usr/bin/grep -v grep | /usr/bin/grep carp: | /usr/bin/grep 'vhid
{
$vhid
}
'"
,
$carp_query
);
foreach
(
$carp_query
as
$int
)
{
foreach
(
$carp_query
as
$int
)
{
if
(
stristr
(
$int
,
"MASTER"
))
if
(
stristr
(
$int
,
"MASTER"
))
{
return
gettext
(
"MASTER"
);
return
gettext
(
"MASTER"
);
if
(
stristr
(
$int
,
"BACKUP"
))
}
elseif
(
stristr
(
$int
,
"BACKUP"
))
{
return
gettext
(
"BACKUP"
);
return
gettext
(
"BACKUP"
);
if
(
stristr
(
$int
,
"INIT"
))
}
elseif
(
stristr
(
$int
,
"INIT"
))
{
return
gettext
(
"INIT"
);
return
gettext
(
"INIT"
);
}
}
}
return
;
return
;
}
}
...
@@ -187,7 +189,6 @@ function backup_config_section($section_name) {
...
@@ -187,7 +189,6 @@ function backup_config_section($section_name) {
function
restore_config_section
(
$section_name
,
$new_contents
)
function
restore_config_section
(
$section_name
,
$new_contents
)
{
{
global
$config
;
global
$config
;
$tmpxml
=
'/tmp/tmpxml'
;
$tmpxml
=
'/tmp/tmpxml'
;
$fout
=
fopen
(
$tmpxml
,
'w'
);
$fout
=
fopen
(
$tmpxml
,
'w'
);
...
@@ -353,13 +354,14 @@ function setup_serial_port($sync = true)
...
@@ -353,13 +354,14 @@ function setup_serial_port($sync = true)
}
}
foreach
(
$ttys_split
as
$tty
)
{
foreach
(
$ttys_split
as
$tty
)
{
if
(
stristr
(
$tty
,
"ttyv0"
))
if
(
stristr
(
$tty
,
"ttyv0"
))
{
fwrite
(
$fd
,
"ttyv0
\"
/usr/libexec/getty
{
$console_type
}
\"
cons25 on secure
\n
"
);
fwrite
(
$fd
,
"ttyv0
\"
/usr/libexec/getty
{
$console_type
}
\"
cons25 on secure
\n
"
);
else
if
(
stristr
(
$tty
,
"ttyu0"
))
}
elseif
(
stristr
(
$tty
,
"ttyu0"
))
{
fwrite
(
$fd
,
"ttyu0
\"
/usr/libexec/getty
{
$serial_type
}
\"
cons25
{
$on_off
}
secure
\n
"
);
fwrite
(
$fd
,
"ttyu0
\"
/usr/libexec/getty
{
$serial_type
}
\"
cons25
{
$on_off
}
secure
\n
"
);
else
}
else
{
fwrite
(
$fd
,
$tty
.
"
\n
"
);
fwrite
(
$fd
,
$tty
.
"
\n
"
);
}
}
}
unset
(
$on_off
,
$console_type
,
$serial_type
);
unset
(
$on_off
,
$console_type
,
$serial_type
);
fclose
(
$fd
);
fclose
(
$fd
);
...
@@ -377,23 +379,25 @@ function reload_ttys()
...
@@ -377,23 +379,25 @@ function reload_ttys()
/* Any PPPoE servers enabled? */
/* Any PPPoE servers enabled? */
function
is_pppoe_server_enabled
()
{
function
is_pppoe_server_enabled
()
{
global
$config
;
global
$config
;
$pppoeenable
=
false
;
$pppoeenable
=
false
;
if
(
!
isset
(
$config
[
'pppoes'
][
'pppoe'
])
||
!
is_array
(
$config
[
'pppoes'
][
'pppoe'
]))
{
if
(
!
isset
(
$config
[
'pppoes'
][
'pppoe'
])
||
!
is_array
(
$config
[
'pppoes'
][
'pppoe'
]))
return
false
;
return
false
;
}
foreach
(
$config
[
'pppoes'
][
'pppoe'
]
as
$pppoes
)
foreach
(
$config
[
'pppoes'
][
'pppoe'
]
as
$pppoes
)
{
if
(
$pppoes
[
'mode'
]
==
'server'
)
if
(
$pppoes
[
'mode'
]
==
'server'
)
{
$pppoeenable
=
true
;
$pppoeenable
=
true
;
}
}
return
$pppoeenable
;
return
$pppoeenable
;
}
}
function
add_hostname_to_watch
(
$hostname
)
{
function
add_hostname_to_watch
(
$hostname
)
{
if
(
!
is_dir
(
"/var/db/dnscache"
))
{
if
(
!
is_dir
(
"/var/db/dnscache"
))
{
mkdir
(
"/var/db/dnscache"
);
mkdir
(
"/var/db/dnscache"
);
}
}
$result
=
array
();
$result
=
array
();
...
@@ -427,16 +431,16 @@ function add_hostname_to_watch($hostname) {
...
@@ -427,16 +431,16 @@ function add_hostname_to_watch($hostname) {
function
is_fqdn
(
$fqdn
)
{
function
is_fqdn
(
$fqdn
)
{
$hostname
=
false
;
$hostname
=
false
;
if
(
preg_match
(
"/[-A-Z0-9\.]+\.[-A-Z0-9\.]+/i"
,
$fqdn
))
{
if
(
preg_match
(
"/[-A-Z0-9\.]+\.[-A-Z0-9\.]+/i"
,
$fqdn
))
{
$hostname
=
true
;
$hostname
=
true
;
}
}
if
(
preg_match
(
"/\.\./"
,
$fqdn
))
{
if
(
preg_match
(
"/\.\./"
,
$fqdn
))
{
$hostname
=
false
;
$hostname
=
false
;
}
}
if
(
preg_match
(
"/^\./i"
,
$fqdn
))
{
if
(
preg_match
(
"/^\./i"
,
$fqdn
))
{
$hostname
=
false
;
$hostname
=
false
;
}
}
if
(
preg_match
(
"/\//i"
,
$fqdn
))
{
if
(
preg_match
(
"/\//i"
,
$fqdn
))
{
$hostname
=
false
;
$hostname
=
false
;
}
}
return
(
$hostname
);
return
(
$hostname
);
...
@@ -486,8 +490,9 @@ function download_file($url, $destination, $verify_ssl = false, $connect_timeout
...
@@ -486,8 +490,9 @@ function download_file($url, $destination, $verify_ssl = false, $connect_timeout
$fp
=
fopen
(
$destination
,
"wb"
);
$fp
=
fopen
(
$destination
,
"wb"
);
if
(
!
$fp
)
if
(
!
$fp
)
{
return
false
;
return
false
;
}
$ch
=
curl_init
();
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
...
@@ -501,8 +506,9 @@ function download_file($url, $destination, $verify_ssl = false, $connect_timeout
...
@@ -501,8 +506,9 @@ function download_file($url, $destination, $verify_ssl = false, $connect_timeout
if
(
!
empty
(
$config
[
'system'
][
'proxyurl'
]))
{
if
(
!
empty
(
$config
[
'system'
][
'proxyurl'
]))
{
curl_setopt
(
$ch
,
CURLOPT_PROXY
,
$config
[
'system'
][
'proxyurl'
]);
curl_setopt
(
$ch
,
CURLOPT_PROXY
,
$config
[
'system'
][
'proxyurl'
]);
if
(
!
empty
(
$config
[
'system'
][
'proxyport'
]))
if
(
!
empty
(
$config
[
'system'
][
'proxyport'
]))
{
curl_setopt
(
$ch
,
CURLOPT_PROXYPORT
,
$config
[
'system'
][
'proxyport'
]);
curl_setopt
(
$ch
,
CURLOPT_PROXYPORT
,
$config
[
'system'
][
'proxyport'
]);
}
if
(
!
empty
(
$config
[
'system'
][
'proxyuser'
])
&&
!
empty
(
$config
[
'system'
][
'proxypass'
]))
{
if
(
!
empty
(
$config
[
'system'
][
'proxyuser'
])
&&
!
empty
(
$config
[
'system'
][
'proxypass'
]))
{
@
curl_setopt
(
$ch
,
CURLOPT_PROXYAUTH
,
CURLAUTH_ANY
|
CURLAUTH_ANYSAFE
);
@
curl_setopt
(
$ch
,
CURLOPT_PROXYAUTH
,
CURLAUTH_ANY
|
CURLAUTH_ANYSAFE
);
curl_setopt
(
$ch
,
CURLOPT_PROXYUSERPWD
,
"
{
$config
[
'system'
][
'proxyuser'
]
}
:
{
$config
[
'system'
][
'proxypass'
]
}
"
);
curl_setopt
(
$ch
,
CURLOPT_PROXYUSERPWD
,
"
{
$config
[
'system'
][
'proxyuser'
]
}
:
{
$config
[
'system'
][
'proxypass'
]
}
"
);
...
@@ -517,7 +523,7 @@ function download_file($url, $destination, $verify_ssl = false, $connect_timeout
...
@@ -517,7 +523,7 @@ function download_file($url, $destination, $verify_ssl = false, $connect_timeout
}
}
/* Split() is being DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. */
/* Split() is being DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. */
if
(
!
function_exists
(
"split"
))
{
if
(
!
function_exists
(
"split"
))
{
function
split
(
$separator
,
$haystack
,
$limit
=
null
)
{
function
split
(
$separator
,
$haystack
,
$limit
=
null
)
{
log_error
(
"deprecated split() call with separator '
{
$separator
}
'"
);
log_error
(
"deprecated split() call with separator '
{
$separator
}
'"
);
return
preg_split
(
$separator
,
$haystack
,
$limit
);
return
preg_split
(
$separator
,
$haystack
,
$limit
);
...
@@ -526,33 +532,33 @@ if(!function_exists("split")) {
...
@@ -526,33 +532,33 @@ if(!function_exists("split")) {
function
update_alias_names_upon_change
(
$section
,
$field
,
$new_alias_name
,
$origname
)
function
update_alias_names_upon_change
(
$section
,
$field
,
$new_alias_name
,
$origname
)
{
{
global
$config
,
$pconfig
;
global
$config
;
if
(
!
$origname
)
{
if
(
!
$origname
)
{
return
;
return
;
}
}
$sectionref
=
&
$config
;
$sectionref
=
&
$config
;
foreach
(
$section
as
$sectionname
)
{
foreach
(
$section
as
$sectionname
)
{
if
(
is_array
(
$sectionref
)
&&
isset
(
$sectionref
[
$sectionname
]))
if
(
is_array
(
$sectionref
)
&&
isset
(
$sectionref
[
$sectionname
]))
{
$sectionref
=
&
$sectionref
[
$sectionname
];
$sectionref
=
&
$sectionref
[
$sectionname
];
else
}
else
{
return
;
return
;
}
}
}
if
(
is_array
(
$sectionref
))
{
if
(
is_array
(
$sectionref
))
{
foreach
(
$sectionref
as
$itemkey
=>
$item
)
{
foreach
(
$sectionref
as
$itemkey
=>
$item
)
{
$fieldfound
=
true
;
$fieldfound
=
true
;
$fieldref
=
&
$sectionref
[
$itemkey
];
$fieldref
=
&
$sectionref
[
$itemkey
];
foreach
(
$field
as
$fieldname
)
{
foreach
(
$field
as
$fieldname
)
{
if
(
is_array
(
$fieldref
)
&&
isset
(
$fieldref
[
$fieldname
]))
if
(
is_array
(
$fieldref
)
&&
isset
(
$fieldref
[
$fieldname
]))
{
$fieldref
=
&
$fieldref
[
$fieldname
];
$fieldref
=
&
$fieldref
[
$fieldname
];
else
{
}
else
{
$fieldfound
=
false
;
$fieldfound
=
false
;
break
;
break
;
}
}
}
}
if
(
$fieldfound
&&
$fieldref
==
$origname
)
{
if
(
$fieldfound
&&
$fieldref
==
$origname
)
{
$fieldref
=
$new_alias_name
;
$fieldref
=
$new_alias_name
;
}
}
}
}
...
@@ -561,7 +567,7 @@ function update_alias_names_upon_change($section, $field, $new_alias_name, $orig
...
@@ -561,7 +567,7 @@ function update_alias_names_upon_change($section, $field, $new_alias_name, $orig
function
process_alias_unzip
(
$temp_filename
)
{
function
process_alias_unzip
(
$temp_filename
)
{
if
(
!
file_exists
(
"/usr/local/bin/unzip"
))
{
if
(
!
file_exists
(
"/usr/local/bin/unzip"
))
{
log_error
(
gettext
(
"Alias archive is a .zip file which cannot be decompressed because utility is missing!"
));
log_error
(
gettext
(
"Alias archive is a .zip file which cannot be decompressed because utility is missing!"
));
return
false
;
return
false
;
}
}
...
@@ -581,8 +587,9 @@ function process_alias_unzip($temp_filename) {
...
@@ -581,8 +587,9 @@ function process_alias_unzip($temp_filename) {
log_error
(
sprintf
(
gettext
(
'The following file could not be read %s from %s'
),
$f2p
,
$temp_filename
));
log_error
(
sprintf
(
gettext
(
'The following file could not be read %s from %s'
),
$f2p
,
$temp_filename
));
continue
;
continue
;
}
}
while
((
$tmpbuf
=
fread
(
$tmpfd
,
65536
))
!==
FALSE
)
while
((
$tmpbuf
=
fread
(
$tmpfd
,
65536
))
!==
FALSE
)
{
fwrite
(
$fd
,
$tmpbuf
);
fwrite
(
$fd
,
$tmpbuf
);
}
fclose
(
$tmpfd
);
fclose
(
$tmpfd
);
unlink
(
$f2p
);
unlink
(
$f2p
);
}
}
...
@@ -593,7 +600,7 @@ function process_alias_unzip($temp_filename) {
...
@@ -593,7 +600,7 @@ function process_alias_unzip($temp_filename) {
}
}
function
process_alias_tgz
(
$temp_filename
)
{
function
process_alias_tgz
(
$temp_filename
)
{
if
(
!
file_exists
(
'/usr/bin/tar'
))
{
if
(
!
file_exists
(
'/usr/bin/tar'
))
{
log_error
(
gettext
(
"Alias archive is a .tar/tgz file which cannot be decompressed because utility is missing!"
));
log_error
(
gettext
(
"Alias archive is a .tar/tgz file which cannot be decompressed because utility is missing!"
));
return
false
;
return
false
;
}
}
...
@@ -613,8 +620,9 @@ function process_alias_tgz($temp_filename) {
...
@@ -613,8 +620,9 @@ function process_alias_tgz($temp_filename) {
log_error
(
sprintf
(
gettext
(
'The following file could not be read %s from %s'
),
$f2p
,
$temp_filename
));
log_error
(
sprintf
(
gettext
(
'The following file could not be read %s from %s'
),
$f2p
,
$temp_filename
));
continue
;
continue
;
}
}
while
((
$tmpbuf
=
fread
(
$tmpfd
,
65536
))
!==
FALSE
)
while
((
$tmpbuf
=
fread
(
$tmpfd
,
65536
))
!==
FALSE
)
{
fwrite
(
$fd
,
$tmpbuf
);
fwrite
(
$fd
,
$tmpbuf
);
}
fclose
(
$tmpfd
);
fclose
(
$tmpfd
);
unlink
(
$f2p
);
unlink
(
$f2p
);
}
}
...
@@ -639,10 +647,7 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) {
...
@@ -639,10 +647,7 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) {
}
}
// If the file doesn't exist or is older than update_freq days, fetch a new copy.
// If the file doesn't exist or is older than update_freq days, fetch a new copy.
if
(
!
file_exists
(
$urltable_filename
)
if
(
!
file_exists
(
$urltable_filename
)
||
((
time
()
-
filemtime
(
$urltable_filename
))
>
(
$freq
*
86400
-
90
))
||
$forceupdate
)
{
||
((
time
()
-
filemtime
(
$urltable_filename
))
>
(
$freq
*
86400
-
90
))
||
$forceupdate
)
{
// Try to fetch the URL supplied
// Try to fetch the URL supplied
@
unlink
(
"
{
$urltable_filename
}
.tmp"
);
@
unlink
(
"
{
$urltable_filename
}
.tmp"
);
$verify_ssl
=
isset
(
$config
[
'system'
][
'checkaliasesurlcert'
]);
$verify_ssl
=
isset
(
$config
[
'system'
][
'checkaliasesurlcert'
]);
...
@@ -683,64 +688,54 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag')
...
@@ -683,64 +688,54 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag')
xml_parser_set_option
(
$parser
,
XML_OPTION_SKIP_WHITE
,
1
);
xml_parser_set_option
(
$parser
,
XML_OPTION_SKIP_WHITE
,
1
);
xml_parse_into_struct
(
$parser
,
trim
(
$contents
),
$xml_values
);
xml_parse_into_struct
(
$parser
,
trim
(
$contents
),
$xml_values
);
xml_parser_free
(
$parser
);
xml_parser_free
(
$parser
);
if
(
!
$xml_values
)
if
(
!
$xml_values
)
{
return
;
//Hmm...
return
;
//Hmm...
}
$xml_array
=
array
();
$xml_array
=
array
();
$parents
=
array
();
$parents
=
array
();
$opened_tags
=
array
();
$opened_tags
=
array
();
$arr
=
array
();
$arr
=
array
();
$current
=
&
$xml_array
;
$current
=
&
$xml_array
;
$repeated_tag_index
=
array
();
$repeated_tag_index
=
array
();
foreach
(
$xml_values
as
$data
)
foreach
(
$xml_values
as
$data
)
{
{
unset
(
$attributes
,
$value
);
unset
(
$attributes
,
$value
);
extract
(
$data
);
extract
(
$data
);
$result
=
array
();
$result
=
array
();
$attributes_data
=
array
();
$attributes_data
=
array
();
if
(
isset
(
$value
))
if
(
isset
(
$value
))
{
{
if
(
$priority
==
'tag'
)
if
(
$priority
==
'tag'
)
{
$result
=
$value
;
$result
=
$value
;
else
}
else
{
$result
[
'value'
]
=
$value
;
$result
[
'value'
]
=
$value
;
}
}
if
(
isset
(
$attributes
)
and
$get_attributes
)
}
{
if
(
isset
(
$attributes
)
and
$get_attributes
)
{
foreach
(
$attributes
as
$attr
=>
$val
)
foreach
(
$attributes
as
$attr
=>
$val
)
{
{
if
(
$priority
==
'tag'
)
{
if
(
$priority
==
'tag'
)
$attributes_data
[
$attr
]
=
$val
;
$attributes_data
[
$attr
]
=
$val
;
else
}
else
{
$result
[
'attr'
][
$attr
]
=
$val
;
//Set all the attributes in a array called 'attr'
$result
[
'attr'
][
$attr
]
=
$val
;
//Set all the attributes in a array called 'attr'
}
}
}
}
if
(
$type
==
"open"
)
}
{
if
(
$type
==
"open"
)
{
$parent
[
$level
-
1
]
=
&
$current
;
$parent
[
$level
-
1
]
=
&
$current
;
if
(
!
is_array
(
$current
)
or
(
!
in_array
(
$tag
,
array_keys
(
$current
))))
if
(
!
is_array
(
$current
)
||
(
!
in_array
(
$tag
,
array_keys
(
$current
))))
{
{
$current
[
$tag
]
=
$result
;
$current
[
$tag
]
=
$result
;
if
(
$attributes_data
)
if
(
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$current
=
&
$current
[
$tag
];
$current
=
&
$current
[
$tag
];
}
}
else
{
else
if
(
isset
(
$current
[
$tag
][
0
]))
{
{
if
(
isset
(
$current
[
$tag
][
0
]))
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
}
}
else
{
else
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
{
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
2
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
2
;
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
unset
(
$current
[
$tag
.
'_attr'
]);
unset
(
$current
[
$tag
.
'_attr'
]);
}
}
...
@@ -748,52 +743,36 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag')
...
@@ -748,52 +743,36 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag')
$last_item_index
=
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
-
1
;
$last_item_index
=
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
-
1
;
$current
=
&
$current
[
$tag
][
$last_item_index
];
$current
=
&
$current
[
$tag
][
$last_item_index
];
}
}
}
}
elseif
(
$type
==
"complete"
)
{
elseif
(
$type
==
"complete"
)
if
(
!
isset
(
$current
[
$tag
]))
{
{
if
(
!
isset
(
$current
[
$tag
]))
{
$current
[
$tag
]
=
$result
;
$current
[
$tag
]
=
$result
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
if
(
$priority
==
'tag'
and
$attributes_data
)
if
(
$priority
==
'tag'
and
$attributes_data
)
{
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
$current
[
$tag
.
'_attr'
]
=
$attributes_data
;
}
}
else
}
else
{
{
if
(
isset
(
$current
[
$tag
][
0
])
and
is_array
(
$current
[
$tag
]))
{
if
(
isset
(
$current
[
$tag
][
0
])
and
is_array
(
$current
[
$tag
]))
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]]
=
$result
;
if
(
$priority
==
'tag'
and
$get_attributes
and
$attributes_data
)
if
(
$priority
==
'tag'
and
$get_attributes
and
$attributes_data
)
{
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
}
}
else
{
else
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
{
$current
[
$tag
]
=
array
(
$current
[
$tag
],
$result
);
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
=
1
;
if
(
$priority
==
'tag'
and
$get_attributes
)
if
(
$priority
==
'tag'
and
$get_attributes
)
{
{
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
if
(
isset
(
$current
[
$tag
.
'_attr'
]))
{
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
$current
[
$tag
][
'0_attr'
]
=
$current
[
$tag
.
'_attr'
];
unset
(
$current
[
$tag
.
'_attr'
]);
unset
(
$current
[
$tag
.
'_attr'
]);
}
}
if
(
$attributes_data
)
if
(
$attributes_data
)
{
{
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
$current
[
$tag
][
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
.
'_attr'
]
=
$attributes_data
;
}
}
}
}
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
//0 and 1 index is already taken
$repeated_tag_index
[
$tag
.
'_'
.
$level
]
++
;
//0 and 1 index is already taken
}
}
}
}
}
}
elseif
(
$type
==
'close'
)
{
elseif
(
$type
==
'close'
)
{
$current
=
&
$parent
[
$level
-
1
];
$current
=
&
$parent
[
$level
-
1
];
}
}
}
}
...
@@ -806,26 +785,27 @@ function filter_rules_sort() {
...
@@ -806,26 +785,27 @@ function filter_rules_sort() {
global
$config
;
global
$config
;
/* mark each rule with the sequence number (to retain the order while sorting) */
/* mark each rule with the sequence number (to retain the order while sorting) */
for
(
$i
=
0
;
isset
(
$config
[
'filter'
][
'rule'
][
$i
]);
$i
++
)
for
(
$i
=
0
;
isset
(
$config
[
'filter'
][
'rule'
][
$i
]);
$i
++
)
{
$config
[
'filter'
][
'rule'
][
$i
][
'seq'
]
=
$i
;
$config
[
'filter'
][
'rule'
][
$i
][
'seq'
]
=
$i
;
}
usort
(
$config
[
'filter'
][
'rule'
],
"filter_rules_compare"
);
usort
(
$config
[
'filter'
][
'rule'
],
"filter_rules_compare"
);
/* strip the sequence numbers again */
/* strip the sequence numbers again */
for
(
$i
=
0
;
isset
(
$config
[
'filter'
][
'rule'
][
$i
]);
$i
++
)
for
(
$i
=
0
;
isset
(
$config
[
'filter'
][
'rule'
][
$i
]);
$i
++
)
{
unset
(
$config
[
'filter'
][
'rule'
][
$i
][
'seq'
]);
unset
(
$config
[
'filter'
][
'rule'
][
$i
][
'seq'
]);
}
}
}
function
filter_rules_compare
(
$a
,
$b
)
{
function
filter_rules_compare
(
$a
,
$b
)
{
if
(
isset
(
$a
[
'floating'
])
&&
isset
(
$b
[
'floating'
]))
if
(
isset
(
$a
[
'floating'
])
&&
isset
(
$b
[
'floating'
]))
{
return
$a
[
'seq'
]
-
$b
[
'seq'
];
return
$a
[
'seq'
]
-
$b
[
'seq'
];
else
if
(
isset
(
$a
[
'floating'
]))
}
elseif
(
isset
(
$a
[
'floating'
]))
{
return
-
1
;
return
-
1
;
else
if
(
isset
(
$b
[
'floating'
]))
}
elseif
(
isset
(
$b
[
'floating'
]))
{
return
1
;
return
1
;
else
if
(
$a
[
'interface'
]
==
$b
[
'interface'
])
}
elseif
(
$a
[
'interface'
]
==
$b
[
'interface'
])
{
return
$a
[
'seq'
]
-
$b
[
'seq'
];
return
$a
[
'seq'
]
-
$b
[
'seq'
];
else
}
else
{
return
compare_interface_friendly_names
(
$a
[
'interface'
],
$b
[
'interface'
]);
return
compare_interface_friendly_names
(
$a
[
'interface'
],
$b
[
'interface'
]);
}
}
}
...
@@ -840,8 +820,9 @@ function filter_rules_compare($a, $b) {
...
@@ -840,8 +820,9 @@ function filter_rules_compare($a, $b) {
function
load_mac_manufacturer_table
()
{
function
load_mac_manufacturer_table
()
{
/* load MAC-Manufacture data from the file */
/* load MAC-Manufacture data from the file */
$macs
=
false
;
$macs
=
false
;
if
(
file_exists
(
"/usr/local/share/nmap/nmap-mac-prefixes"
))
if
(
file_exists
(
"/usr/local/share/nmap/nmap-mac-prefixes"
))
{
$macs
=
file
(
"/usr/local/share/nmap/nmap-mac-prefixes"
);
$macs
=
file
(
"/usr/local/share/nmap/nmap-mac-prefixes"
);
}
if
(
$macs
){
if
(
$macs
){
foreach
(
$macs
as
$line
){
foreach
(
$macs
as
$line
){
if
(
preg_match
(
'/([0-9A-Fa-f]{6}) (.*)$/'
,
$line
,
$matches
)){
if
(
preg_match
(
'/([0-9A-Fa-f]{6}) (.*)$/'
,
$line
,
$matches
)){
...
@@ -850,8 +831,9 @@ function load_mac_manufacturer_table() {
...
@@ -850,8 +831,9 @@ function load_mac_manufacturer_table() {
}
}
}
}
return
$mac_man
;
return
$mac_man
;
} else
} else {
return -1;
return -1;
}
}
}
...
@@ -868,12 +850,12 @@ function is_ipaddr_configured($ipaddr, $ignore_if = "", $check_localip = false,
...
@@ -868,12 +850,12 @@ function is_ipaddr_configured($ipaddr, $ignore_if = "", $check_localip = false,
global
$config
;
global
$config
;
$isipv6
= is_ipaddrv6(
$ipaddr
);
$isipv6
= is_ipaddrv6(
$ipaddr
);
if (
$check_subnets
) {
if (
$check_subnets
) {
$iflist
= get_configured_interface_list();
$iflist
= get_configured_interface_list();
foreach (
$iflist
as
$if
=>
$ifname
) {
foreach (
$iflist
as
$if
=>
$ifname
) {
if (
$ignore_if
==
$if
)
if (
$ignore_if
==
$if
) {
continue;
continue;
}
if (
$isipv6
=== true) {
if (
$isipv6
=== true) {
$bitmask
= get_interface_subnetv6(
$if
);
$bitmask
= get_interface_subnetv6(
$if
);
...
@@ -883,39 +865,46 @@ function is_ipaddr_configured($ipaddr, $ignore_if = "", $check_localip = false,
...
@@ -883,39 +865,46 @@ function is_ipaddr_configured($ipaddr, $ignore_if = "", $check_localip = false,
$subnet
= gen_subnet(get_interface_ip(
$if
),
$bitmask
);
$subnet
= gen_subnet(get_interface_ip(
$if
),
$bitmask
);
}
}
if (ip_in_subnet(
$ipaddr
,
$subnet
. '/' .
$bitmask
))
if (ip_in_subnet(
$ipaddr
,
$subnet
. '/' .
$bitmask
)) {
return true;
return true;
}
}
}
} else {
} else {
if (
$isipv6
=== true)
if (
$isipv6
=== true) {
$interface_list_ips
= get_configured_ipv6_addresses();
$interface_list_ips
= get_configured_ipv6_addresses();
else
} else {
$interface_list_ips
= get_configured_ip_addresses();
$interface_list_ips
= get_configured_ip_addresses();
}
foreach(
$interface_list_ips
as
$if
=>
$ilips
) {
foreach(
$interface_list_ips
as
$if
=>
$ilips
) {
/* Also ignore CARP interfaces, it'll be checked below */
/* Also ignore CARP interfaces, it'll be checked below */
if (
$ignore_if
==
$if
|| strstr(
$ignore_if
, "
_vip
"))
if (
$ignore_if
==
$if
|| strstr(
$ignore_if
, "
_vip
")) {
continue;
continue;
if (strcasecmp(
$ipaddr
,
$ilips
) == 0)
}
if (strcasecmp(
$ipaddr
,
$ilips
) == 0) {
return true;
return true;
}
}
}
}
}
$interface_list_vips
= get_configured_vips_list(true);
$interface_list_vips
= get_configured_vips_list(true);
foreach (
$interface_list_vips
as
$id
=>
$vip
) {
foreach (
$interface_list_vips
as
$id
=>
$vip
) {
if (
$ignore_if
==
$vip['if']
)
if (
$ignore_if
==
$vip['if']
) {
continue;
continue;
if (strcasecmp(
$ipaddr
,
$vip['ipaddr']
) == 0)
}
if (strcasecmp(
$ipaddr
,
$vip['ipaddr']
) == 0) {
return true;
return true;
}
}
}
if (
$check_localip
) {
if (
$check_localip
) {
if (is_array(
$config['pptpd']
) && !empty(
$config['pptpd']['localip']
) && (strcasecmp(
$ipaddr
,
$config['pptpd']['localip']
) == 0))
if (is_array(
$config['pptpd']
) && !empty(
$config['pptpd']['localip']
) && (strcasecmp(
$ipaddr
,
$config['pptpd']['localip']
) == 0)) {
return true;
return true;
}
if (!is_array(
$config['l2tp']
) && !empty(
$config['l2tp']['localip']
) && (strcasecmp(
$ipaddr
,
$config['l2tp']['localip']
) == 0))
if (!is_array(
$config['l2tp']
) && !empty(
$config['l2tp']['localip']
) && (strcasecmp(
$ipaddr
,
$config['l2tp']['localip']
) == 0)) {
return true;
return true;
}
}
}
return false;
return false;
}
}
...
@@ -932,7 +921,7 @@ function calculate_ipv6_delegation_length($if) {
...
@@ -932,7 +921,7 @@ function calculate_ipv6_delegation_length($if) {
if(!isset(
$config['interfaces'][$if]
) || !is_array(
$config['interfaces'][$if]
)) {
if(!isset(
$config['interfaces'][$if]
) || !is_array(
$config['interfaces'][$if]
)) {
return false;
return false;
} elseif (!isset(
$config['interfaces'][$if]['ipaddrv6']
)) {
} elseif (!isset(
$config['interfaces'][$if]['ipaddrv6']
)) {
return (0)
;
return 0
;
}
}
switch(
$config['interfaces'][$if]['ipaddrv6']
) {
switch(
$config['interfaces'][$if]['ipaddrv6']
) {
...
@@ -952,5 +941,5 @@ function calculate_ipv6_delegation_length($if) {
...
@@ -952,5 +941,5 @@ function calculate_ipv6_delegation_length($if) {
$pdlen
= 0;
$pdlen
= 0;
break;
break;
}
}
return(
$pdlen
)
;
return
$pdlen
;
}
}
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