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
8a13c8a7
Commit
8a13c8a7
authored
Feb 08, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) spaces and curly brances in services.inc
parent
70445dcb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2485 additions
and
2365 deletions
+2485
-2365
services.inc
src/etc/inc/services.inc
+2485
-2365
No files found.
src/etc/inc/services.inc
View file @
8a13c8a7
...
@@ -32,15 +32,17 @@ require_once('dyndns.class');
...
@@ -32,15 +32,17 @@ require_once('dyndns.class');
require_once
(
'unbound.inc'
);
require_once
(
'unbound.inc'
);
require_once
(
'miniupnpd.inc'
);
require_once
(
'miniupnpd.inc'
);
function
generate_ipv6_from_mac
(
$mac
)
{
function
generate_ipv6_from_mac
(
$mac
)
{
$elements
=
explode
(
":"
,
$mac
);
$elements
=
explode
(
":"
,
$mac
);
if
(
count
(
$elements
)
<>
6
)
if
(
count
(
$elements
)
<>
6
)
{
return
false
;
return
false
;
}
$i
=
0
;
$i
=
0
;
$ipv6
=
"fe80::"
;
$ipv6
=
"fe80::"
;
foreach
(
$elements
as
$byte
)
{
foreach
(
$elements
as
$byte
)
{
if
(
$i
==
0
)
{
if
(
$i
==
0
)
{
$hexadecimal
=
substr
(
$byte
,
1
,
2
);
$hexadecimal
=
substr
(
$byte
,
1
,
2
);
$bitmap
=
base_convert
(
$hexadecimal
,
16
,
2
);
$bitmap
=
base_convert
(
$hexadecimal
,
16
,
2
);
$bitmap
=
str_pad
(
$bitmap
,
4
,
"0"
,
STR_PAD_LEFT
);
$bitmap
=
str_pad
(
$bitmap
,
4
,
"0"
,
STR_PAD_LEFT
);
...
@@ -48,13 +50,13 @@ function generate_ipv6_from_mac($mac) {
...
@@ -48,13 +50,13 @@ function generate_ipv6_from_mac($mac) {
$byte
=
substr
(
$byte
,
0
,
1
)
.
base_convert
(
$bitmap
,
2
,
16
);
$byte
=
substr
(
$byte
,
0
,
1
)
.
base_convert
(
$bitmap
,
2
,
16
);
}
}
$ipv6
.=
$byte
;
$ipv6
.=
$byte
;
if
(
$i
==
1
)
{
if
(
$i
==
1
)
{
$ipv6
.=
":"
;
$ipv6
.=
":"
;
}
}
if
(
$i
==
3
)
{
if
(
$i
==
3
)
{
$ipv6
.=
":"
;
$ipv6
.=
":"
;
}
}
if
(
$i
==
2
)
{
if
(
$i
==
2
)
{
$ipv6
.=
"ff:fe"
;
$ipv6
.=
"ff:fe"
;
}
}
...
@@ -63,19 +65,20 @@ function generate_ipv6_from_mac($mac) {
...
@@ -63,19 +65,20 @@ function generate_ipv6_from_mac($mac) {
return
$ipv6
;
return
$ipv6
;
}
}
function
get_pppoes_child_interfaces
(
$ifpattern
)
{
function
get_pppoes_child_interfaces
(
$ifpattern
)
{
$if_arr
=
array
();
$if_arr
=
array
();
if
(
$ifpattern
==
""
)
if
(
$ifpattern
==
""
)
{
return
;
return
;
}
exec
(
"ifconfig"
,
$out
,
$ret
);
exec
(
"ifconfig"
,
$out
,
$ret
);
foreach
(
$out
as
$line
)
{
foreach
(
$out
as
$line
)
{
if
(
preg_match
(
"/^(
{
$ifpattern
}
[0-9]+):/i"
,
$line
,
$match
))
{
if
(
preg_match
(
"/^(
{
$ifpattern
}
[0-9]+):/i"
,
$line
,
$match
))
{
$if_arr
[]
=
$match
[
1
];
$if_arr
[]
=
$match
[
1
];
}
}
}
}
return
$if_arr
;
return
$if_arr
;
}
}
function
get_configured_pppoe_server_interfaces
()
function
get_configured_pppoe_server_interfaces
()
...
@@ -91,7 +94,6 @@ function get_configured_pppoe_server_interfaces()
...
@@ -91,7 +94,6 @@ function get_configured_pppoe_server_interfaces()
}
}
}
}
}
}
return
$iflist
;
return
$iflist
;
}
}
...
@@ -115,23 +117,26 @@ function services_radvd_configure($blacklist = array())
...
@@ -115,23 +117,26 @@ function services_radvd_configure($blacklist = array())
/* handle manually configured DHCP6 server settings first */
/* handle manually configured DHCP6 server settings first */
foreach
(
$config
[
'dhcpdv6'
]
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
foreach
(
$config
[
'dhcpdv6'
]
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
if
(
!
is_array
(
$config
[
'interfaces'
][
$dhcpv6if
]))
if
(
!
is_array
(
$config
[
'interfaces'
][
$dhcpv6if
]))
{
continue
;
continue
;
if
(
!
isset
(
$config
[
'interfaces'
][
$dhcpv6if
][
'enable'
]))
}
elseif
(
!
isset
(
$config
[
'interfaces'
][
$dhcpv6if
][
'enable'
]))
{
continue
;
continue
;
}
elseif
(
isset
(
$blacklist
[
$dhcpv6if
]))
{
/* Do not put in the config an interface which is down */
/* Do not put in the config an interface which is down */
if
(
isset
(
$blacklist
[
$dhcpv6if
]))
continue
;
continue
;
if
(
!
isset
(
$dhcpv6ifconf
[
'ramode'
]))
}
if
(
!
isset
(
$dhcpv6ifconf
[
'ramode'
]))
{
$dhcpv6ifconf
[
'ramode'
]
=
$dhcpv6ifconf
[
'mode'
];
$dhcpv6ifconf
[
'ramode'
]
=
$dhcpv6ifconf
[
'mode'
];
}
/* are router advertisements enabled? */
/* are router advertisements enabled? */
if
(
$dhcpv6ifconf
[
'ramode'
]
==
"disabled"
)
if
(
$dhcpv6ifconf
[
'ramode'
]
==
"disabled"
)
{
continue
;
continue
;
}
if
(
!
isset
(
$dhcpv6ifconf
[
'rapriority'
]))
if
(
!
isset
(
$dhcpv6ifconf
[
'rapriority'
]))
{
$dhcpv6ifconf
[
'rapriority'
]
=
"medium"
;
$dhcpv6ifconf
[
'rapriority'
]
=
"medium"
;
}
/* always start with the real parent, we override with the carp if later */
/* always start with the real parent, we override with the carp if later */
$carpif
=
false
;
$carpif
=
false
;
...
@@ -144,12 +149,14 @@ function services_radvd_configure($blacklist = array())
...
@@ -144,12 +149,14 @@ function services_radvd_configure($blacklist = array())
}
}
$realif
=
get_real_interface
(
$dhcpv6if
,
"inet6"
);
$realif
=
get_real_interface
(
$dhcpv6if
,
"inet6"
);
if
(
isset
(
$radvdifs
[
$realif
]))
if
(
isset
(
$radvdifs
[
$realif
]))
{
continue
;
continue
;
}
$ifcfgipv6
=
get_interface_ipv6
(
$dhcpv6if
);
$ifcfgipv6
=
get_interface_ipv6
(
$dhcpv6if
);
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
{
continue
;
continue
;
}
$ifcfgsnv6
=
get_interface_subnetv6
(
$dhcpv6if
);
$ifcfgsnv6
=
get_interface_subnetv6
(
$dhcpv6if
);
$subnetv6
=
gen_subnetv6
(
$ifcfgipv6
,
$ifcfgsnv6
);
$subnetv6
=
gen_subnetv6
(
$ifcfgipv6
,
$ifcfgsnv6
);
...
@@ -161,11 +168,12 @@ function services_radvd_configure($blacklist = array())
...
@@ -161,11 +168,12 @@ function services_radvd_configure($blacklist = array())
$radvdconf
.=
"
\t
MinRtrAdvInterval 5;
\n
"
;
$radvdconf
.=
"
\t
MinRtrAdvInterval 5;
\n
"
;
$radvdconf
.=
"
\t
MaxRtrAdvInterval 20;
\n
"
;
$radvdconf
.=
"
\t
MaxRtrAdvInterval 20;
\n
"
;
$mtu
=
legacy_interface_stats
(
$realif
)[
'mtu'
];
$mtu
=
legacy_interface_stats
(
$realif
)[
'mtu'
];
if
(
is_numeric
(
$mtu
))
if
(
is_numeric
(
$mtu
))
{
$radvdconf
.=
"
\t
AdvLinkMTU
{
$mtu
}
;
\n
"
;
$radvdconf
.=
"
\t
AdvLinkMTU
{
$mtu
}
;
\n
"
;
else
}
else
{
$radvdconf
.=
"
\t
AdvLinkMTU 1280;
\n
"
;
$radvdconf
.=
"
\t
AdvLinkMTU 1280;
\n
"
;
// $radvdconf .= "\tDeprecatePrefix on;\n";
}
switch
(
$dhcpv6ifconf
[
'rapriority'
])
{
switch
(
$dhcpv6ifconf
[
'rapriority'
])
{
case
"low"
:
case
"low"
:
$radvdconf
.=
"
\t
AdvDefaultPreference low;
\n
"
;
$radvdconf
.=
"
\t
AdvDefaultPreference low;
\n
"
;
...
@@ -185,7 +193,7 @@ function services_radvd_configure($blacklist = array())
...
@@ -185,7 +193,7 @@ function services_radvd_configure($blacklist = array())
break
;
break
;
}
}
$radvdconf
.=
"
\t
prefix
{
$subnetv6
}
/
{
$ifcfgsnv6
}
{\n"
;
$radvdconf
.=
"
\t
prefix
{
$subnetv6
}
/
{
$ifcfgsnv6
}
{\n"
;
if
(
$carpif
==
true
)
{
if
(
$carpif
==
true
)
{
$radvdconf
.=
"
\t\t
DeprecatePrefix off;
\n
"
;
$radvdconf
.=
"
\t\t
DeprecatePrefix off;
\n
"
;
}
else
{
}
else
{
$radvdconf
.=
"
\t\t
DeprecatePrefix on;
\n
"
;
$radvdconf
.=
"
\t\t
DeprecatePrefix on;
\n
"
;
...
@@ -214,7 +222,7 @@ function services_radvd_configure($blacklist = array())
...
@@ -214,7 +222,7 @@ function services_radvd_configure($blacklist = array())
}
}
$radvdconf
.=
"
\t
};
\n
"
;
$radvdconf
.=
"
\t
};
\n
"
;
if
(
$carpif
===
true
)
{
if
(
$carpif
===
true
)
{
$radvdconf
.=
"
\t
route ::/0 {\n"
;
$radvdconf
.=
"
\t
route ::/0 {\n"
;
$radvdconf
.=
"
\t\t
RemoveRoute off;
\n
"
;
$radvdconf
.=
"
\t\t
RemoveRoute off;
\n
"
;
$radvdconf
.=
"
\t
};
\n
"
;
$radvdconf
.=
"
\t
};
\n
"
;
...
@@ -227,26 +235,32 @@ function services_radvd_configure($blacklist = array())
...
@@ -227,26 +235,32 @@ function services_radvd_configure($blacklist = array())
/* add DNS servers */
/* add DNS servers */
$dnslist
=
array
();
$dnslist
=
array
();
if
(
isset
(
$dhcpv6ifconf
[
'rasamednsasdhcp6'
])
&&
is_array
(
$dhcpv6ifconf
[
'dnsserver'
])
&&
!
empty
(
$dhcpv6ifconf
[
'dnsserver'
]))
{
if
(
isset
(
$dhcpv6ifconf
[
'rasamednsasdhcp6'
])
&&
is_array
(
$dhcpv6ifconf
[
'dnsserver'
])
&&
!
empty
(
$dhcpv6ifconf
[
'dnsserver'
]))
{
foreach
(
$dhcpv6ifconf
[
'dnsserver'
]
as
$server
)
foreach
(
$dhcpv6ifconf
[
'dnsserver'
]
as
$server
)
{
if
(
is_ipaddrv6
(
$server
))
if
(
is_ipaddrv6
(
$server
))
{
$dnslist
[]
=
$server
;
$dnslist
[]
=
$server
;
}
}
}
elseif
(
!
isset
(
$dhcpv6ifconf
[
'rasamednsasdhcp6'
])
&&
isset
(
$dhcpv6ifconf
[
'radnsserver'
])
&&
is_array
(
$dhcpv6ifconf
[
'radnsserver'
]))
{
}
elseif
(
!
isset
(
$dhcpv6ifconf
[
'rasamednsasdhcp6'
])
&&
isset
(
$dhcpv6ifconf
[
'radnsserver'
])
&&
is_array
(
$dhcpv6ifconf
[
'radnsserver'
]))
{
foreach
(
$dhcpv6ifconf
[
'radnsserver'
]
as
$server
)
foreach
(
$dhcpv6ifconf
[
'radnsserver'
]
as
$server
)
{
if
(
is_ipaddrv6
(
$server
))
if
(
is_ipaddrv6
(
$server
))
{
$dnslist
[]
=
$server
;
$dnslist
[]
=
$server
;
}
}
}
elseif
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
}
elseif
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
$dnslist
[]
=
get_interface_ipv6
(
$realif
);
$dnslist
[]
=
get_interface_ipv6
(
$realif
);
}
elseif
(
is_array
(
$config
[
'system'
][
'dnsserver'
])
&&
!
empty
(
$config
[
'system'
][
'dnsserver'
]))
{
}
elseif
(
is_array
(
$config
[
'system'
][
'dnsserver'
])
&&
!
empty
(
$config
[
'system'
][
'dnsserver'
]))
{
foreach
(
$config
[
'system'
][
'dnsserver'
]
as
$server
)
{
foreach
(
$config
[
'system'
][
'dnsserver'
]
as
$server
)
{
if
(
is_ipaddrv6
(
$server
))
if
(
is_ipaddrv6
(
$server
))
{
$dnslist
[]
=
$server
;
$dnslist
[]
=
$server
;
}
}
}
}
}
if
(
count
(
$dnslist
)
>
0
)
{
if
(
count
(
$dnslist
)
>
0
)
{
$dnsstring
=
implode
(
" "
,
$dnslist
);
$dnsstring
=
implode
(
" "
,
$dnslist
);
if
(
$dnsstring
<>
""
)
if
(
$dnsstring
<>
""
)
{
$radvdconf
.=
"
\t
RDNSS
{
$dnsstring
}
{ };
\n
"
;
$radvdconf
.=
"
\t
RDNSS
{
$dnsstring
}
{ };
\n
"
;
}
}
}
if
(
!
empty
(
$dhcpv6ifconf
[
'domain'
]))
{
if
(
!
empty
(
$dhcpv6ifconf
[
'domain'
]))
{
$radvdconf
.=
"
\t
DNSSL
{
$dhcpv6ifconf
[
'domain'
]
}
{ };
\n
"
;
$radvdconf
.=
"
\t
DNSSL
{
$dhcpv6ifconf
[
'domain'
]
}
{ };
\n
"
;
}
elseif
(
!
empty
(
$config
[
'system'
][
'domain'
]))
{
}
elseif
(
!
empty
(
$config
[
'system'
][
'domain'
]))
{
...
@@ -257,24 +271,27 @@ function services_radvd_configure($blacklist = array())
...
@@ -257,24 +271,27 @@ function services_radvd_configure($blacklist = array())
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
foreach
(
$Iflist
as
$if
=>
$ifdescr
)
{
foreach
(
$Iflist
as
$if
=>
$ifdescr
)
{
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'track6-interface'
]))
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'track6-interface'
]))
{
continue
;
continue
;
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'enable'
]))
}
elseif
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'enable'
]))
{
continue
;
continue
;
}
elseif
(
isset
(
$blacklist
[
$if
]))
{
/* Do not put in the config an interface which is down */
/* Do not put in the config an interface which is down */
if
(
isset
(
$blacklist
[
$if
]))
continue
;
continue
;
}
$trackif
=
$config
[
'interfaces'
][
$if
][
'track6-interface'
];
$trackif
=
$config
[
'interfaces'
][
$if
][
'track6-interface'
];
if
(
empty
(
$config
[
'interfaces'
][
$trackif
]))
if
(
empty
(
$config
[
'interfaces'
][
$trackif
]))
{
continue
;
continue
;
}
$realif
=
get_real_interface
(
$if
,
"inet6"
);
$realif
=
get_real_interface
(
$if
,
"inet6"
);
/* prevent duplicate entries, manual overrides */
/* prevent duplicate entries, manual overrides */
if
(
isset
(
$radvdifs
[
$realif
]))
if
(
isset
(
$radvdifs
[
$realif
]))
{
continue
;
continue
;
}
$ifcfgipv6
=
get_interface_ipv6
(
$if
);
$ifcfgipv6
=
get_interface_ipv6
(
$if
);
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
{
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
{
$subnetv6
=
"::"
;
$subnetv6
=
"::"
;
$ifcfgsnv6
=
"64"
;
$ifcfgsnv6
=
"64"
;
}
else
{
}
else
{
...
@@ -293,10 +310,11 @@ function services_radvd_configure($blacklist = array())
...
@@ -293,10 +310,11 @@ function services_radvd_configure($blacklist = array())
$radvdconf
.=
"
\t
MinRtrAdvInterval 3;
\n
"
;
$radvdconf
.=
"
\t
MinRtrAdvInterval 3;
\n
"
;
$radvdconf
.=
"
\t
MaxRtrAdvInterval 10;
\n
"
;
$radvdconf
.=
"
\t
MaxRtrAdvInterval 10;
\n
"
;
$mtu
=
legacy_interface_stats
(
$realif
)[
'mtu'
];
$mtu
=
legacy_interface_stats
(
$realif
)[
'mtu'
];
if
(
is_numeric
(
$mtu
))
if
(
is_numeric
(
$mtu
))
{
$radvdconf
.=
"
\t
AdvLinkMTU
{
$mtu
}
;
\n
"
;
$radvdconf
.=
"
\t
AdvLinkMTU
{
$mtu
}
;
\n
"
;
else
}
else
{
$radvdconf
.=
"
\t
AdvLinkMTU 1280;
\n
"
;
$radvdconf
.=
"
\t
AdvLinkMTU 1280;
\n
"
;
}
$radvdconf
.=
"
\t
AdvOtherConfigFlag on;
\n
"
;
$radvdconf
.=
"
\t
AdvOtherConfigFlag on;
\n
"
;
$radvdconf
.=
"
\t\t
prefix
{
$subnetv6
}
/
{
$ifcfgsnv6
}
{\n"
;
$radvdconf
.=
"
\t\t
prefix
{
$subnetv6
}
/
{
$ifcfgsnv6
}
{\n"
;
$radvdconf
.=
"
\t\t
AdvOnLink on;
\n
"
;
$radvdconf
.=
"
\t\t
AdvOnLink on;
\n
"
;
...
@@ -310,15 +328,17 @@ function services_radvd_configure($blacklist = array())
...
@@ -310,15 +328,17 @@ function services_radvd_configure($blacklist = array())
$dnslist
[]
=
$ifcfgipv6
;
$dnslist
[]
=
$ifcfgipv6
;
}
elseif
(
is_array
(
$config
[
'system'
][
'dnsserver'
])
&&
!
empty
(
$config
[
'system'
][
'dnsserver'
]))
{
}
elseif
(
is_array
(
$config
[
'system'
][
'dnsserver'
])
&&
!
empty
(
$config
[
'system'
][
'dnsserver'
]))
{
foreach
(
$config
[
'system'
][
'dnsserver'
]
as
$server
)
{
foreach
(
$config
[
'system'
][
'dnsserver'
]
as
$server
)
{
if
(
is_ipaddrv6
(
$server
))
if
(
is_ipaddrv6
(
$server
))
{
$dnslist
[]
=
$server
;
$dnslist
[]
=
$server
;
}
}
}
}
}
if
(
count
(
$dnslist
)
>
0
)
{
if
(
count
(
$dnslist
)
>
0
)
{
$dnsstring
=
implode
(
" "
,
$dnslist
);
$dnsstring
=
implode
(
" "
,
$dnslist
);
if
(
!
empty
(
$dnsstring
))
if
(
!
empty
(
$dnsstring
))
{
$radvdconf
.=
"
\t
RDNSS
{
$dnsstring
}
{ };
\n
"
;
$radvdconf
.=
"
\t
RDNSS
{
$dnsstring
}
{ };
\n
"
;
}
}
}
if
(
!
empty
(
$config
[
'system'
][
'domain'
]))
{
if
(
!
empty
(
$config
[
'system'
][
'domain'
]))
{
$radvdconf
.=
"
\t
DNSSL
{
$config
[
'system'
][
'domain'
]
}
{ };
\n
"
;
$radvdconf
.=
"
\t
DNSSL
{
$config
[
'system'
][
'domain'
]
}
{ };
\n
"
;
}
}
...
@@ -328,9 +348,10 @@ function services_radvd_configure($blacklist = array())
...
@@ -328,9 +348,10 @@ function services_radvd_configure($blacklist = array())
/* write radvd.conf */
/* write radvd.conf */
if
(
!@
file_put_contents
(
"/var/etc/radvd.conf"
,
$radvdconf
))
{
if
(
!@
file_put_contents
(
"/var/etc/radvd.conf"
,
$radvdconf
))
{
log_error
(
"Error: cannot open radvd.conf in services_radvd_configure().
\n
"
);
log_error
(
"Error: cannot open radvd.conf in services_radvd_configure().
\n
"
);
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
printf
(
"Error: cannot open radvd.conf in services_radvd_configure().
\n
"
);
printf
(
"Error: cannot open radvd.conf in services_radvd_configure().
\n
"
);
}
}
}
unset
(
$radvdconf
);
unset
(
$radvdconf
);
if
(
count
(
$radvdifs
)
>
0
)
{
if
(
count
(
$radvdifs
)
>
0
)
{
...
@@ -411,8 +432,9 @@ function services_dhcpdv4_configure()
...
@@ -411,8 +432,9 @@ function services_dhcpdv4_configure()
killbypid
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/run/dhcpd.pid"
);
killbypid
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/run/dhcpd.pid"
);
/* DHCP enabled on any interfaces? */
/* DHCP enabled on any interfaces? */
if
(
!
is_dhcp_server_enabled
())
if
(
!
is_dhcp_server_enabled
())
{
return
0
;
return
0
;
}
if
(
file_exists
(
"/var/run/booting"
))
{
if
(
file_exists
(
"/var/run/booting"
))
{
/* restore the leases, if we have them */
/* restore the leases, if we have them */
...
@@ -421,15 +443,16 @@ function services_dhcpdv4_configure()
...
@@ -421,15 +443,16 @@ function services_dhcpdv4_configure()
$dhcpreturn
=
''
;
$dhcpreturn
=
''
;
exec
(
'cd /;LANG=C /usr/bin/tar -xzf /conf/dhcpleases.tgz 2>&1'
,
$dhcprestore
,
$dhcpreturn
);
exec
(
'cd /;LANG=C /usr/bin/tar -xzf /conf/dhcpleases.tgz 2>&1'
,
$dhcprestore
,
$dhcpreturn
);
$dhcprestore
=
implode
(
' '
,
$dhcprestore
);
$dhcprestore
=
implode
(
' '
,
$dhcprestore
);
if
(
$dhcpreturn
<>
0
)
{
if
(
$dhcpreturn
<>
0
)
{
log_error
(
sprintf
(
gettext
(
'DHCP leases restore failed exited with %s, the error is: %s'
),
$dhcpreturn
,
$dhcprestore
));
log_error
(
sprintf
(
gettext
(
'DHCP leases restore failed exited with %s, the error is: %s'
),
$dhcpreturn
,
$dhcprestore
));
}
}
}
}
}
}
$syscfg
=
$config
[
'system'
];
$syscfg
=
$config
[
'system'
];
if
(
!
is_array
(
$config
[
'dhcpd'
]))
if
(
!
is_array
(
$config
[
'dhcpd'
]))
{
$config
[
'dhcpd'
]
=
array
();
$config
[
'dhcpd'
]
=
array
();
}
$dhcpdcfg
=
$config
[
'dhcpd'
];
$dhcpdcfg
=
$config
[
'dhcpd'
];
$Iflist
=
get_configured_interface_list
();
$Iflist
=
get_configured_interface_list
();
...
@@ -443,24 +466,25 @@ function services_dhcpdv4_configure()
...
@@ -443,24 +466,25 @@ function services_dhcpdv4_configure()
}
}
}
}
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"Starting DHCP service..."
);
echo
gettext
(
"Starting DHCP service..."
);
else
}
else
{
sleep
(
1
);
sleep
(
1
);
}
$custoptions
=
""
;
$custoptions
=
""
;
foreach
(
$dhcpdcfg
as
$dhcpif
=>
$dhcpifconf
)
{
foreach
(
$dhcpdcfg
as
$dhcpif
=>
$dhcpifconf
)
{
if
(
isset
(
$dhcpifconf
[
'numberoptions'
][
'item'
]))
{
if
(
isset
(
$dhcpifconf
[
'numberoptions'
][
'item'
]))
{
foreach
(
$dhcpifconf
[
'numberoptions'
][
'item'
]
as
$itemidx
=>
$item
)
{
foreach
(
$dhcpifconf
[
'numberoptions'
][
'item'
]
as
$itemidx
=>
$item
)
{
if
(
!
empty
(
$item
[
'type'
]))
if
(
!
empty
(
$item
[
'type'
]))
{
$itemtype
=
$item
[
'type'
];
$itemtype
=
$item
[
'type'
];
else
}
else
{
$itemtype
=
"text"
;
$itemtype
=
"text"
;
}
$custoptions
.=
"option custom-
{
$dhcpif
}
-
{
$itemidx
}
code
{
$item
[
'number'
]
}
=
{
$itemtype
}
;
\n
"
;
$custoptions
.=
"option custom-
{
$dhcpif
}
-
{
$itemidx
}
code
{
$item
[
'number'
]
}
=
{
$itemtype
}
;
\n
"
;
}
}
}
}
}
}
$dhcpdconf
=
<<<EOD
$dhcpdconf
=
<<<EOD
option domain-name "{$syscfg['domain']}";
option domain-name "{$syscfg['domain']}";
...
@@ -478,11 +502,13 @@ update-conflict-detection false;
...
@@ -478,11 +502,13 @@ update-conflict-detection false;
EOD;
EOD;
if
(
!
isset
(
$dhcpifconf
[
'disableauthoritative'
]))
if
(
!
isset
(
$dhcpifconf
[
'disableauthoritative'
]))
{
$dhcpdconf
.=
"authoritative;
\n
"
;
$dhcpdconf
.=
"authoritative;
\n
"
;
}
if
(
isset
(
$dhcpifconf
[
'alwaysbroadcast'
]))
if
(
isset
(
$dhcpifconf
[
'alwaysbroadcast'
]))
{
$dhcpdconf
.=
"always-broadcast on
\n
"
;
$dhcpdconf
.=
"always-broadcast on
\n
"
;
}
$dhcpdifs
=
array
();
$dhcpdifs
=
array
();
$add_routers
=
false
;
$add_routers
=
false
;
...
@@ -490,7 +516,7 @@ EOD;
...
@@ -490,7 +516,7 @@ EOD;
/* only add a routers line if the system has any IPv4 gateway at all */
/* only add a routers line if the system has any IPv4 gateway at all */
/* a static route has a gateway, manually overriding this field always works */
/* a static route has a gateway, manually overriding this field always works */
foreach
(
$gateways_arr
as
$gwitem
)
{
foreach
(
$gateways_arr
as
$gwitem
)
{
if
(
$gwitem
[
'ipprotocol'
]
==
"inet"
)
{
if
(
$gwitem
[
'ipprotocol'
]
==
"inet"
)
{
$add_routers
=
true
;
$add_routers
=
true
;
break
;
break
;
}
}
...
@@ -500,26 +526,25 @@ EOD;
...
@@ -500,26 +526,25 @@ EOD;
* failover peer "bleh" entries
* failover peer "bleh" entries
*/
*/
foreach
(
$dhcpdcfg
as
$dhcpif
=>
$dhcpifconf
)
{
foreach
(
$dhcpdcfg
as
$dhcpif
=>
$dhcpifconf
)
{
interfaces_staticarp_configure
(
$dhcpif
);
interfaces_staticarp_configure
(
$dhcpif
);
if
(
!
isset
(
$dhcpifconf
[
'enable'
]))
{
if
(
!
isset
(
$dhcpifconf
[
'enable'
]))
continue
;
continue
;
}
if
(
$dhcpifconf
[
'failover_peerip'
]
<>
""
)
{
if
(
$dhcpifconf
[
'failover_peerip'
]
<>
""
)
{
$intip
=
get_interface_ip
(
$dhcpif
);
$intip
=
get_interface_ip
(
$dhcpif
);
/*
/*
* yep, failover peer is defined.
* yep, failover peer is defined.
* does it match up to a defined vip?
* does it match up to a defined vip?
*/
*/
$skew
=
110
;
$skew
=
110
;
if
(
is_array
(
$config
[
'virtualip'
][
'vip'
]))
{
if
(
is_array
(
$config
[
'virtualip'
][
'vip'
]))
{
foreach
(
$config
[
'virtualip'
][
'vip'
]
as
$vipent
)
{
foreach
(
$config
[
'virtualip'
][
'vip'
]
as
$vipent
)
{
if
(
$vipent
[
'interface'
]
==
$dhcpif
)
{
if
(
$vipent
[
'interface'
]
==
$dhcpif
)
{
$carp_nw
=
gen_subnet
(
$vipent
[
'subnet'
],
$vipent
[
'subnet_bits'
]);
$carp_nw
=
gen_subnet
(
$vipent
[
'subnet'
],
$vipent
[
'subnet_bits'
]);
if
(
ip_in_subnet
(
$dhcpifconf
[
'failover_peerip'
],
"
{
$carp_nw
}
/
{
$vipent
[
'subnet_bits'
]
}
"
))
{
if
(
ip_in_subnet
(
$dhcpifconf
[
'failover_peerip'
],
"
{
$carp_nw
}
/
{
$vipent
[
'subnet_bits'
]
}
"
))
{
/* this is the interface! */
/* this is the interface! */
if
(
is_numeric
(
$vipent
[
'advskew'
])
&&
(
intval
(
$vipent
[
'advskew'
])
<
20
))
{
if
(
is_numeric
(
$vipent
[
'advskew'
])
&&
(
intval
(
$vipent
[
'advskew'
])
<
20
))
{
$skew
=
0
;
$skew
=
0
;
break
;
break
;
}
}
...
@@ -529,7 +554,7 @@ EOD;
...
@@ -529,7 +554,7 @@ EOD;
}
else
{
}
else
{
log_error
(
gettext
(
"Warning! DHCP Failover setup and no CARP virtual IPs defined!"
));
log_error
(
gettext
(
"Warning! DHCP Failover setup and no CARP virtual IPs defined!"
));
}
}
if
(
$skew
>
10
)
{
if
(
$skew
>
10
)
{
$type
=
"secondary"
;
$type
=
"secondary"
;
$my_port
=
"520"
;
$my_port
=
"520"
;
$peer_port
=
"519"
;
$peer_port
=
"519"
;
...
@@ -561,19 +586,20 @@ EOPP;
...
@@ -561,19 +586,20 @@ EOPP;
}
}
foreach
(
$dhcpdcfg
as
$dhcpif
=>
$dhcpifconf
)
{
foreach
(
$dhcpdcfg
as
$dhcpif
=>
$dhcpifconf
)
{
$newzone
=
array
();
$newzone
=
array
();
$ifcfg
=
$config
[
'interfaces'
][
$dhcpif
];
$ifcfg
=
$config
[
'interfaces'
][
$dhcpif
];
if
(
!
isset
(
$dhcpifconf
[
'enable'
])
||
!
isset
(
$Iflist
[
$dhcpif
]))
if
(
!
isset
(
$dhcpifconf
[
'enable'
])
||
!
isset
(
$Iflist
[
$dhcpif
]))
{
continue
;
continue
;
}
$ifcfgip
=
get_interface_ip
(
$dhcpif
);
$ifcfgip
=
get_interface_ip
(
$dhcpif
);
$ifcfgsn
=
get_interface_subnet
(
$dhcpif
);
$ifcfgsn
=
get_interface_subnet
(
$dhcpif
);
$subnet
=
gen_subnet
(
$ifcfgip
,
$ifcfgsn
);
$subnet
=
gen_subnet
(
$ifcfgip
,
$ifcfgsn
);
$subnetmask
=
gen_subnet_mask
(
$ifcfgsn
);
$subnetmask
=
gen_subnet_mask
(
$ifcfgsn
);
if
(
!
is_ipaddr
(
$subnet
))
if
(
!
is_ipaddr
(
$subnet
))
{
continue
;
continue
;
}
$all_pools
=
array
();
$all_pools
=
array
();
$all_pools
[]
=
$dhcpifconf
;
$all_pools
[]
=
$dhcpifconf
;
...
@@ -587,14 +613,14 @@ EOPP;
...
@@ -587,14 +613,14 @@ EOPP;
$dnscfg
.=
" option domain-name
\"
{
$dhcpifconf
[
'domain'
]
}
\"
;
\n
"
;
$dnscfg
.=
" option domain-name
\"
{
$dhcpifconf
[
'domain'
]
}
\"
;
\n
"
;
}
}
if
(
$dhcpifconf
[
'domainsearchlist'
]
<>
""
)
{
if
(
$dhcpifconf
[
'domainsearchlist'
]
<>
""
)
{
$dnscfg
.=
" option domain-search
\"
"
.
join
(
"
\"
,
\"
"
,
preg_split
(
"/[ ;]+/"
,
$dhcpifconf
[
'domainsearchlist'
]))
.
"
\"
;
\n
"
;
$dnscfg
.=
" option domain-search
\"
"
.
join
(
"
\"
,
\"
"
,
preg_split
(
"/[ ;]+/"
,
$dhcpifconf
[
'domainsearchlist'
]))
.
"
\"
;
\n
"
;
}
}
if
(
isset
(
$dhcpifconf
[
'ddnsupdate'
]))
{
if
(
isset
(
$dhcpifconf
[
'ddnsupdate'
]))
{
$need_ddns_updates
=
true
;
$need_ddns_updates
=
true
;
$newzone
=
array
();
$newzone
=
array
();
if
(
$dhcpifconf
[
'ddnsdomain'
]
<>
""
)
{
if
(
$dhcpifconf
[
'ddnsdomain'
]
<>
""
)
{
$newzone
[
'domain-name'
]
=
$dhcpifconf
[
'ddnsdomain'
];
$newzone
[
'domain-name'
]
=
$dhcpifconf
[
'ddnsdomain'
];
$dnscfg
.=
" ddns-domainname
\"
{
$dhcpifconf
[
'ddnsdomain'
]
}
\"
;
\n
"
;
$dnscfg
.=
" ddns-domainname
\"
{
$dhcpifconf
[
'ddnsdomain'
]
}
\"
;
\n
"
;
}
else
{
}
else
{
...
@@ -612,17 +638,20 @@ EOPP;
...
@@ -612,17 +638,20 @@ EOPP;
if
(
is_array
(
$dhcpifconf
[
'dnsserver'
])
&&
(
$dhcpifconf
[
'dnsserver'
][
0
]))
{
if
(
is_array
(
$dhcpifconf
[
'dnsserver'
])
&&
(
$dhcpifconf
[
'dnsserver'
][
0
]))
{
$dnscfg
.=
" option domain-name-servers "
.
join
(
","
,
$dhcpifconf
[
'dnsserver'
])
.
";"
;
$dnscfg
.=
" option domain-name-servers "
.
join
(
","
,
$dhcpifconf
[
'dnsserver'
])
.
";"
;
if
(
$newzone
[
'domain-name'
])
if
(
$newzone
[
'domain-name'
])
{
$newzone
[
'dns-servers'
]
=
$dhcpifconf
[
'dnsserver'
];
$newzone
[
'dns-servers'
]
=
$dhcpifconf
[
'dnsserver'
];
}
else
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
}
}
elseif
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
$dnscfg
.=
" option domain-name-servers
{
$ifcfgip
}
;"
;
$dnscfg
.=
" option domain-name-servers
{
$ifcfgip
}
;"
;
if
(
$newzone
[
'domain-name'
]
&&
is_array
(
$syscfg
[
'dnsserver'
])
&&
(
$syscfg
[
'dnsserver'
][
0
]))
if
(
$newzone
[
'domain-name'
]
&&
is_array
(
$syscfg
[
'dnsserver'
])
&&
(
$syscfg
[
'dnsserver'
][
0
]))
{
$newzone
[
'dns-servers'
]
=
$syscfg
[
'dnsserver'
];
$newzone
[
'dns-servers'
]
=
$syscfg
[
'dnsserver'
];
}
else
if
(
!
empty
(
$dns_arrv4
))
{
}
}
elseif
(
!
empty
(
$dns_arrv4
))
{
$dnscfg
.=
" option domain-name-servers "
.
join
(
","
,
$dns_arrv4
)
.
";"
;
$dnscfg
.=
" option domain-name-servers "
.
join
(
","
,
$dns_arrv4
)
.
";"
;
if
(
$newzone
[
'domain-name'
])
if
(
$newzone
[
'domain-name'
])
{
$newzone
[
'dns-servers'
]
=
$dns_arrv4
;
$newzone
[
'dns-servers'
]
=
$dns_arrv4
;
}
}
}
/* Create classes - These all contain comma separated lists. Join them into one
/* Create classes - These all contain comma separated lists. Join them into one
big comma separated string then split them all up. */
big comma separated string then split them all up. */
...
@@ -637,8 +666,9 @@ EOPP;
...
@@ -637,8 +666,9 @@ EOPP;
$all_mac_strings
[]
=
$dhcpifconf
[
'mac_deny'
];
$all_mac_strings
[]
=
$dhcpifconf
[
'mac_deny'
];
$all_mac_list
=
array_unique
(
explode
(
','
,
implode
(
','
,
$all_mac_strings
)));
$all_mac_list
=
array_unique
(
explode
(
','
,
implode
(
','
,
$all_mac_strings
)));
foreach
(
$all_mac_list
as
$mac
)
{
foreach
(
$all_mac_list
as
$mac
)
{
if
(
empty
(
$mac
))
if
(
empty
(
$mac
))
{
continue
;
continue
;
}
$dhcpdconf
.=
'class "'
.
str_replace
(
':'
,
''
,
$mac
)
.
'" {'
.
"
\n
"
;
$dhcpdconf
.=
'class "'
.
str_replace
(
':'
,
''
,
$mac
)
.
'" {'
.
"
\n
"
;
// Skip the first octet of the MAC address - for media type, typically Ethernet ("01") and match the rest.
// Skip the first octet of the MAC address - for media type, typically Ethernet ("01") and match the rest.
$dhcpdconf
.=
' match if substring (hardware, 1, '
.
(
substr_count
(
$mac
,
':'
)
+
1
)
.
') = '
.
$mac
.
';'
.
"
\n
"
;
$dhcpdconf
.=
' match if substring (hardware, 1, '
.
(
substr_count
(
$mac
,
':'
)
+
1
)
.
') = '
.
$mac
.
';'
.
"
\n
"
;
...
@@ -647,41 +677,47 @@ EOPP;
...
@@ -647,41 +677,47 @@ EOPP;
$dhcpdconf
.=
"subnet
{
$subnet
}
netmask
{
$subnetmask
}
{\n"
;
$dhcpdconf
.=
"subnet
{
$subnet
}
netmask
{
$subnetmask
}
{\n"
;
// Setup pool options
// Setup pool options
foreach
(
$all_pools
as
$poolconf
)
{
foreach
(
$all_pools
as
$poolconf
)
{
$dhcpdconf
.=
" pool {\n"
;
$dhcpdconf
.=
" pool {\n"
;
/* is failover dns setup? */
/* is failover dns setup? */
if
(
is_array
(
$poolconf
[
'dnsserver'
])
&&
$poolconf
[
'dnsserver'
][
0
]
<>
""
)
{
if
(
is_array
(
$poolconf
[
'dnsserver'
])
&&
$poolconf
[
'dnsserver'
][
0
]
<>
""
)
{
$dhcpdconf
.=
" option domain-name-servers
{
$poolconf
[
'dnsserver'
][
0
]
}
"
;
$dhcpdconf
.=
" option domain-name-servers
{
$poolconf
[
'dnsserver'
][
0
]
}
"
;
if
(
$poolconf
[
'dnsserver'
][
1
]
<>
""
)
if
(
$poolconf
[
'dnsserver'
][
1
]
<>
""
)
{
$dhcpdconf
.=
",
{
$poolconf
[
'dnsserver'
][
1
]
}
"
;
$dhcpdconf
.=
",
{
$poolconf
[
'dnsserver'
][
1
]
}
"
;
}
$dhcpdconf
.=
";
\n
"
;
$dhcpdconf
.=
";
\n
"
;
}
}
/* allow/deny MACs */
/* allow/deny MACs */
$mac_allow_list
=
array_unique
(
explode
(
','
,
$poolconf
[
'mac_allow'
]));
$mac_allow_list
=
array_unique
(
explode
(
','
,
$poolconf
[
'mac_allow'
]));
foreach
(
$mac_allow_list
as
$mac
)
{
foreach
(
$mac_allow_list
as
$mac
)
{
if
(
empty
(
$mac
))
if
(
empty
(
$mac
))
{
continue
;
continue
;
}
$dhcpdconf
.=
" allow members of
\"
"
.
str_replace
(
':'
,
''
,
$mac
)
.
"
\"
;
\n
"
;
$dhcpdconf
.=
" allow members of
\"
"
.
str_replace
(
':'
,
''
,
$mac
)
.
"
\"
;
\n
"
;
}
}
$mac_deny_list
=
array_unique
(
explode
(
','
,
$poolconf
[
'mac_deny'
]));
$mac_deny_list
=
array_unique
(
explode
(
','
,
$poolconf
[
'mac_deny'
]));
foreach
(
$mac_deny_list
as
$mac
)
{
foreach
(
$mac_deny_list
as
$mac
)
{
if
(
empty
(
$mac
))
if
(
empty
(
$mac
))
{
continue
;
continue
;
}
$dhcpdconf
.=
" deny members of
\"
"
.
str_replace
(
':'
,
''
,
$mac
)
.
"
\"
;
\n
"
;
$dhcpdconf
.=
" deny members of
\"
"
.
str_replace
(
':'
,
''
,
$mac
)
.
"
\"
;
\n
"
;
}
}
if
(
$poolconf
[
'failover_peerip'
]
<>
""
)
if
(
$poolconf
[
'failover_peerip'
]
<>
""
)
{
$dhcpdconf
.=
" deny dynamic bootp clients;
\n
"
;
$dhcpdconf
.=
" deny dynamic bootp clients;
\n
"
;
}
if
(
isset
(
$poolconf
[
'denyunknown'
]))
if
(
isset
(
$poolconf
[
'denyunknown'
]))
{
$dhcpdconf
.=
" deny unknown-clients;
\n
"
;
$dhcpdconf
.=
" deny unknown-clients;
\n
"
;
}
if
(
$poolconf
[
'gateway'
]
&&
$poolconf
[
'gateway'
]
!=
"none"
&&
(
$poolconf
[
'gateway'
]
!=
$dhcpifconf
[
'gateway'
]))
if
(
$poolconf
[
'gateway'
]
&&
$poolconf
[
'gateway'
]
!=
"none"
&&
(
$poolconf
[
'gateway'
]
!=
$dhcpifconf
[
'gateway'
]))
{
$dhcpdconf
.=
" option routers
{
$poolconf
[
'gateway'
]
}
;
\n
"
;
$dhcpdconf
.=
" option routers
{
$poolconf
[
'gateway'
]
}
;
\n
"
;
}
if
(
$dhcpifconf
[
'failover_peerip'
]
<>
""
)
{
if
(
$dhcpifconf
[
'failover_peerip'
]
<>
""
)
{
$dhcpdconf
.=
" failover peer
\"
dhcp_
{
$dhcpif
}
\"
;
\n
"
;
$dhcpdconf
.=
" failover peer
\"
dhcp_
{
$dhcpif
}
\"
;
\n
"
;
}
}
...
@@ -691,13 +727,14 @@ EOPP;
...
@@ -691,13 +727,14 @@ EOPP;
$pdnscfg
.=
" option domain-name
\"
{
$poolconf
[
'domain'
]
}
\"
;
\n
"
;
$pdnscfg
.=
" option domain-name
\"
{
$poolconf
[
'domain'
]
}
\"
;
\n
"
;
}
}
if
(
!
empty
(
$poolconf
[
'domainsearchlist'
])
&&
(
$poolconf
[
'domainsearchlist'
]
!=
$dhcpifconf
[
'domainsearchlist'
]))
{
if
(
!
empty
(
$poolconf
[
'domainsearchlist'
])
&&
(
$poolconf
[
'domainsearchlist'
]
!=
$dhcpifconf
[
'domainsearchlist'
]))
{
$pdnscfg
.=
" option domain-search
\"
"
.
join
(
"
\"
,
\"
"
,
preg_split
(
"/[ ;]+/"
,
$poolconf
[
'domainsearchlist'
]))
.
"
\"
;
\n
"
;
$pdnscfg
.=
" option domain-search
\"
"
.
join
(
"
\"
,
\"
"
,
preg_split
(
"/[ ;]+/"
,
$poolconf
[
'domainsearchlist'
]))
.
"
\"
;
\n
"
;
}
}
if
(
isset
(
$poolconf
[
'ddnsupdate'
]))
{
if
(
isset
(
$poolconf
[
'ddnsupdate'
]))
{
if
((
$poolconf
[
'ddnsdomain'
]
<>
""
)
&&
(
$poolconf
[
'ddnsdomain'
]
!=
$dhcpifconf
[
'ddnsdomain'
]))
if
((
$poolconf
[
'ddnsdomain'
]
<>
""
)
&&
(
$poolconf
[
'ddnsdomain'
]
!=
$dhcpifconf
[
'ddnsdomain'
]))
{
$pdnscfg
.=
" ddns-domainname
\"
{
$poolconf
[
'ddnsdomain'
]
}
\"
;
\n
"
;
$pdnscfg
.=
" ddns-domainname
\"
{
$poolconf
[
'ddnsdomain'
]
}
\"
;
\n
"
;
}
$pdnscfg
.=
" ddns-update-style interim;
\n
"
;
$pdnscfg
.=
" ddns-update-style interim;
\n
"
;
}
}
...
@@ -707,12 +744,14 @@ EOPP;
...
@@ -707,12 +744,14 @@ EOPP;
$dhcpdconf
.=
"
{
$pdnscfg
}
"
;
$dhcpdconf
.=
"
{
$pdnscfg
}
"
;
// default-lease-time
// default-lease-time
if
(
$poolconf
[
'defaultleasetime'
]
&&
(
$poolconf
[
'defaultleasetime'
]
!=
$dhcpifconf
[
'defaultleasetime'
]))
if
(
$poolconf
[
'defaultleasetime'
]
&&
(
$poolconf
[
'defaultleasetime'
]
!=
$dhcpifconf
[
'defaultleasetime'
]))
{
$dhcpdconf
.=
" default-lease-time
{
$poolconf
[
'defaultleasetime'
]
}
;
\n
"
;
$dhcpdconf
.=
" default-lease-time
{
$poolconf
[
'defaultleasetime'
]
}
;
\n
"
;
}
// max-lease-time
// max-lease-time
if
(
$poolconf
[
'maxleasetime'
]
&&
(
$poolconf
[
'maxleasetime'
]
!=
$dhcpifconf
[
'maxleasetime'
]))
if
(
$poolconf
[
'maxleasetime'
]
&&
(
$poolconf
[
'maxleasetime'
]
!=
$dhcpifconf
[
'maxleasetime'
]))
{
$dhcpdconf
.=
" max-lease-time
{
$poolconf
[
'maxleasetime'
]
}
;
\n
"
;
$dhcpdconf
.=
" max-lease-time
{
$poolconf
[
'maxleasetime'
]
}
;
\n
"
;
}
// netbios-name*
// netbios-name*
if
(
is_array
(
$poolconf
[
'winsserver'
])
&&
$poolconf
[
'winsserver'
][
0
]
&&
(
$poolconf
[
'winsserver'
][
0
]
!=
$dhcpifconf
[
'winsserver'
][
0
]))
{
if
(
is_array
(
$poolconf
[
'winsserver'
])
&&
$poolconf
[
'winsserver'
][
0
]
&&
(
$poolconf
[
'winsserver'
][
0
]
!=
$dhcpifconf
[
'winsserver'
][
0
]))
{
...
@@ -721,19 +760,22 @@ EOPP;
...
@@ -721,19 +760,22 @@ EOPP;
}
}
// ntp-servers
// ntp-servers
if
(
is_array
(
$poolconf
[
'ntpserver'
])
&&
$poolconf
[
'ntpserver'
][
0
]
&&
(
$poolconf
[
'ntpserver'
][
0
]
!=
$dhcpifconf
[
'ntpserver'
][
0
]))
if
(
is_array
(
$poolconf
[
'ntpserver'
])
&&
$poolconf
[
'ntpserver'
][
0
]
&&
(
$poolconf
[
'ntpserver'
][
0
]
!=
$dhcpifconf
[
'ntpserver'
][
0
]))
{
$dhcpdconf
.=
" option ntp-servers "
.
join
(
","
,
$poolconf
[
'ntpserver'
])
.
";
\n
"
;
$dhcpdconf
.=
" option ntp-servers "
.
join
(
","
,
$poolconf
[
'ntpserver'
])
.
";
\n
"
;
}
// tftp-server-name
// tftp-server-name
if
(
!
empty
(
$poolconf
[
'tftp'
])
&&
(
$poolconf
[
'tftp'
]
!=
$dhcpifconf
[
'tftp'
]))
if
(
!
empty
(
$poolconf
[
'tftp'
])
&&
(
$poolconf
[
'tftp'
]
!=
$dhcpifconf
[
'tftp'
]))
{
$dhcpdconf
.=
" option tftp-server-name
\"
{
$poolconf
[
'tftp'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option tftp-server-name
\"
{
$poolconf
[
'tftp'
]
}
\"
;
\n
"
;
}
// ldap-server
// ldap-server
if
(
!
empty
(
$poolconf
[
'ldap'
])
&&
(
$poolconf
[
'ldap'
]
!=
$dhcpifconf
[
'ldap'
]))
if
(
!
empty
(
$poolconf
[
'ldap'
])
&&
(
$poolconf
[
'ldap'
]
!=
$dhcpifconf
[
'ldap'
]))
{
$dhcpdconf
.=
" option ldap-server
\"
{
$poolconf
[
'ldap'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option ldap-server
\"
{
$poolconf
[
'ldap'
]
}
\"
;
\n
"
;
}
// net boot information
// net boot information
if
(
isset
(
$poolconf
[
'netboot'
]))
{
if
(
isset
(
$poolconf
[
'netboot'
]))
{
if
(
!
empty
(
$poolconf
[
'nextserver'
])
&&
(
$poolconf
[
'nextserver'
]
!=
$dhcpifconf
[
'nextserver'
]))
{
if
(
!
empty
(
$poolconf
[
'nextserver'
])
&&
(
$poolconf
[
'nextserver'
]
!=
$dhcpifconf
[
'nextserver'
]))
{
$dhcpdconf
.=
" next-server
{
$poolconf
[
'nextserver'
]
}
;
\n
"
;
$dhcpdconf
.=
" next-server
{
$poolconf
[
'nextserver'
]
}
;
\n
"
;
}
}
...
@@ -747,7 +789,7 @@ EOPP;
...
@@ -747,7 +789,7 @@ EOPP;
$dhcpdconf
.=
" range
{
$poolconf
[
'range'
][
'from'
]
}
{
$poolconf
[
'range'
][
'to'
]
}
;
\n
"
;
$dhcpdconf
.=
" range
{
$poolconf
[
'range'
][
'from'
]
}
{
$poolconf
[
'range'
][
'to'
]
}
;
\n
"
;
$dhcpdconf
.=
" }
\n\n
"
;
$dhcpdconf
.=
" }
\n\n
"
;
}
}
// End of settings inside pools
// End of settings inside pools
if
(
$dhcpifconf
[
'gateway'
]
&&
$dhcpifconf
[
'gateway'
]
!=
"none"
)
{
if
(
$dhcpifconf
[
'gateway'
]
&&
$dhcpifconf
[
'gateway'
]
!=
"none"
)
{
$routers
=
$dhcpifconf
[
'gateway'
];
$routers
=
$dhcpifconf
[
'gateway'
];
...
@@ -757,20 +799,23 @@ EOPP;
...
@@ -757,20 +799,23 @@ EOPP;
}
else
{
}
else
{
$routers
=
$ifcfgip
;
$routers
=
$ifcfgip
;
}
}
if
(
$add_routers
)
if
(
$add_routers
)
{
$dhcpdconf
.=
" option routers
{
$routers
}
;
\n
"
;
$dhcpdconf
.=
" option routers
{
$routers
}
;
\n
"
;
}
$dhcpdconf
.=
<<<EOD
$dhcpdconf
.=
<<<EOD
$dnscfg
$dnscfg
EOD;
EOD;
// default-lease-time
// default-lease-time
if
(
$dhcpifconf
[
'defaultleasetime'
])
if
(
$dhcpifconf
[
'defaultleasetime'
])
{
$dhcpdconf
.=
" default-lease-time
{
$dhcpifconf
[
'defaultleasetime'
]
}
;
\n
"
;
$dhcpdconf
.=
" default-lease-time
{
$dhcpifconf
[
'defaultleasetime'
]
}
;
\n
"
;
}
// max-lease-time
// max-lease-time
if
(
$dhcpifconf
[
'maxleasetime'
])
if
(
$dhcpifconf
[
'maxleasetime'
])
{
$dhcpdconf
.=
" max-lease-time
{
$dhcpifconf
[
'maxleasetime'
]
}
;
\n
"
;
$dhcpdconf
.=
" max-lease-time
{
$dhcpifconf
[
'maxleasetime'
]
}
;
\n
"
;
}
// netbios-name*
// netbios-name*
if
(
is_array
(
$dhcpifconf
[
'winsserver'
])
&&
$dhcpifconf
[
'winsserver'
][
0
])
{
if
(
is_array
(
$dhcpifconf
[
'winsserver'
])
&&
$dhcpifconf
[
'winsserver'
][
0
])
{
...
@@ -779,30 +824,34 @@ EOD;
...
@@ -779,30 +824,34 @@ EOD;
}
}
// ntp-servers
// ntp-servers
if
(
is_array
(
$dhcpifconf
[
'ntpserver'
])
&&
$dhcpifconf
[
'ntpserver'
][
0
])
if
(
is_array
(
$dhcpifconf
[
'ntpserver'
])
&&
$dhcpifconf
[
'ntpserver'
][
0
])
{
$dhcpdconf
.=
" option ntp-servers "
.
join
(
","
,
$dhcpifconf
[
'ntpserver'
])
.
";
\n
"
;
$dhcpdconf
.=
" option ntp-servers "
.
join
(
","
,
$dhcpifconf
[
'ntpserver'
])
.
";
\n
"
;
}
// tftp-server-name
// tftp-server-name
if
(
$dhcpifconf
[
'tftp'
]
<>
""
)
if
(
$dhcpifconf
[
'tftp'
]
<>
""
)
{
$dhcpdconf
.=
" option tftp-server-name
\"
{
$dhcpifconf
[
'tftp'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option tftp-server-name
\"
{
$dhcpifconf
[
'tftp'
]
}
\"
;
\n
"
;
}
// Handle option, number rowhelper values
// Handle option, number rowhelper values
$dhcpdconf
.=
"
\n
"
;
$dhcpdconf
.=
"
\n
"
;
if
(
isset
(
$dhcpifconf
[
'numberoptions'
][
'item'
]))
{
if
(
isset
(
$dhcpifconf
[
'numberoptions'
][
'item'
]))
{
foreach
(
$dhcpifconf
[
'numberoptions'
][
'item'
]
as
$itemidx
=>
$item
)
{
foreach
(
$dhcpifconf
[
'numberoptions'
][
'item'
]
as
$itemidx
=>
$item
)
{
if
(
empty
(
$item
[
'type'
])
||
$item
[
'type'
]
==
"text"
)
if
(
empty
(
$item
[
'type'
])
||
$item
[
'type'
]
==
"text"
)
{
$dhcpdconf
.=
" option custom-
{
$dhcpif
}
-
{
$itemidx
}
\"
{
$item
[
'value'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option custom-
{
$dhcpif
}
-
{
$itemidx
}
\"
{
$item
[
'value'
]
}
\"
;
\n
"
;
else
}
else
{
$dhcpdconf
.=
" option custom-
{
$dhcpif
}
-
{
$itemidx
}
{
$item
[
'value'
]
}
;
\n
"
;
$dhcpdconf
.=
" option custom-
{
$dhcpif
}
-
{
$itemidx
}
{
$item
[
'value'
]
}
;
\n
"
;
}
}
}
}
}
// ldap-server
// ldap-server
if
(
$dhcpifconf
[
'ldap'
]
<>
""
)
if
(
$dhcpifconf
[
'ldap'
]
<>
""
)
{
$dhcpdconf
.=
" option ldap-server
\"
{
$dhcpifconf
[
'ldap'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option ldap-server
\"
{
$dhcpifconf
[
'ldap'
]
}
\"
;
\n
"
;
}
// net boot information
// net boot information
if
(
isset
(
$dhcpifconf
[
'netboot'
]))
{
if
(
isset
(
$dhcpifconf
[
'netboot'
]))
{
if
(
$dhcpifconf
[
'nextserver'
]
<>
""
)
{
if
(
$dhcpifconf
[
'nextserver'
]
<>
""
)
{
$dhcpdconf
.=
" next-server
{
$dhcpifconf
[
'nextserver'
]
}
;
\n
"
;
$dhcpdconf
.=
" next-server
{
$dhcpifconf
[
'nextserver'
]
}
;
\n
"
;
}
}
...
@@ -829,47 +878,51 @@ EOD;
...
@@ -829,47 +878,51 @@ EOD;
/* add static mappings */
/* add static mappings */
if
(
is_array
(
$dhcpifconf
[
'staticmap'
]))
{
if
(
is_array
(
$dhcpifconf
[
'staticmap'
]))
{
$i
=
0
;
$i
=
0
;
foreach
(
$dhcpifconf
[
'staticmap'
]
as
$sm
)
{
foreach
(
$dhcpifconf
[
'staticmap'
]
as
$sm
)
{
$dhcpdconf
.=
"host s_
{
$dhcpif
}
_
{
$i
}
{\n"
;
$dhcpdconf
.=
"host s_
{
$dhcpif
}
_
{
$i
}
{\n"
;
if
(
$sm
[
'mac'
])
{
if
(
$sm
[
'mac'
])
$dhcpdconf
.=
" hardware ethernet
{
$sm
[
'mac'
]
}
;
\n
"
;
$dhcpdconf
.=
" hardware ethernet
{
$sm
[
'mac'
]
}
;
\n
"
;
}
if
(
$sm
[
'cid'
])
if
(
$sm
[
'cid'
])
{
$dhcpdconf
.=
" option dhcp-client-identifier
\"
{
$sm
[
'cid'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option dhcp-client-identifier
\"
{
$sm
[
'cid'
]
}
\"
;
\n
"
;
}
if
(
$sm
[
'ipaddr'
])
if
(
$sm
[
'ipaddr'
])
{
$dhcpdconf
.=
" fixed-address
{
$sm
[
'ipaddr'
]
}
;
\n
"
;
$dhcpdconf
.=
" fixed-address
{
$sm
[
'ipaddr'
]
}
;
\n
"
;
}
if
(
$sm
[
'hostname'
])
{
if
(
$sm
[
'hostname'
])
{
$dhhostname
=
str_replace
(
" "
,
"_"
,
$sm
[
'hostname'
]);
$dhhostname
=
str_replace
(
" "
,
"_"
,
$sm
[
'hostname'
]);
$dhhostname
=
str_replace
(
"."
,
"_"
,
$dhhostname
);
$dhhostname
=
str_replace
(
"."
,
"_"
,
$dhhostname
);
$dhcpdconf
.=
" option host-name
\"
{
$dhhostname
}
\"
;
\n
"
;
$dhcpdconf
.=
" option host-name
\"
{
$dhhostname
}
\"
;
\n
"
;
}
}
if
(
$sm
[
'filename'
])
if
(
$sm
[
'filename'
])
{
$dhcpdconf
.=
" filename
\"
{
$sm
[
'filename'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" filename
\"
{
$sm
[
'filename'
]
}
\"
;
\n
"
;
}
if
(
$sm
[
'rootpath'
])
if
(
$sm
[
'rootpath'
])
{
$dhcpdconf
.=
" option root-path
\"
{
$sm
[
'rootpath'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option root-path
\"
{
$sm
[
'rootpath'
]
}
\"
;
\n
"
;
}
if
(
$sm
[
'gateway'
]
&&
(
$sm
[
'gateway'
]
!=
$dhcpifconf
[
'gateway'
]))
if
(
$sm
[
'gateway'
]
&&
(
$sm
[
'gateway'
]
!=
$dhcpifconf
[
'gateway'
]))
{
$dhcpdconf
.=
" option routers
{
$sm
[
'gateway'
]
}
;
\n
"
;
$dhcpdconf
.=
" option routers
{
$sm
[
'gateway'
]
}
;
\n
"
;
}
$smdnscfg
=
""
;
$smdnscfg
=
""
;
if
(
$sm
[
'domain'
]
&&
(
$sm
[
'domain'
]
!=
$dhcpifconf
[
'domain'
]))
{
if
(
$sm
[
'domain'
]
&&
(
$sm
[
'domain'
]
!=
$dhcpifconf
[
'domain'
]))
{
$smdnscfg
.=
" option domain-name
\"
{
$sm
[
'domain'
]
}
\"
;
\n
"
;
$smdnscfg
.=
" option domain-name
\"
{
$sm
[
'domain'
]
}
\"
;
\n
"
;
}
}
if
(
!
empty
(
$sm
[
'domainsearchlist'
])
&&
(
$sm
[
'domainsearchlist'
]
!=
$dhcpifconf
[
'domainsearchlist'
]))
{
if
(
!
empty
(
$sm
[
'domainsearchlist'
])
&&
(
$sm
[
'domainsearchlist'
]
!=
$dhcpifconf
[
'domainsearchlist'
]))
{
$smdnscfg
.=
" option domain-search
\"
"
.
join
(
"
\"
,
\"
"
,
preg_split
(
"/[ ;]+/"
,
$sm
[
'domainsearchlist'
]))
.
"
\"
;
\n
"
;
$smdnscfg
.=
" option domain-search
\"
"
.
join
(
"
\"
,
\"
"
,
preg_split
(
"/[ ;]+/"
,
$sm
[
'domainsearchlist'
]))
.
"
\"
;
\n
"
;
}
}
if
(
isset
(
$sm
[
'ddnsupdate'
]))
{
if
(
isset
(
$sm
[
'ddnsupdate'
]))
{
if
((
$sm
[
'ddnsdomain'
]
<>
""
)
&&
(
$sm
[
'ddnsdomain'
]
!=
$dhcpifconf
[
'ddnsdomain'
]))
if
((
$sm
[
'ddnsdomain'
]
<>
""
)
&&
(
$sm
[
'ddnsdomain'
]
!=
$dhcpifconf
[
'ddnsdomain'
]))
{
$pdnscfg
.=
" ddns-domainname
\"
{
$sm
[
'ddnsdomain'
]
}
\"
;
\n
"
;
$pdnscfg
.=
" ddns-domainname
\"
{
$sm
[
'ddnsdomain'
]
}
\"
;
\n
"
;
}
$pdnscfg
.=
" ddns-update-style interim;
\n
"
;
$pdnscfg
.=
" ddns-update-style interim;
\n
"
;
}
}
...
@@ -879,12 +932,14 @@ EOD;
...
@@ -879,12 +932,14 @@ EOD;
$dhcpdconf
.=
"
{
$smdnscfg
}
"
;
$dhcpdconf
.=
"
{
$smdnscfg
}
"
;
// default-lease-time
// default-lease-time
if
(
$sm
[
'defaultleasetime'
]
&&
(
$sm
[
'defaultleasetime'
]
!=
$dhcpifconf
[
'defaultleasetime'
]))
if
(
$sm
[
'defaultleasetime'
]
&&
(
$sm
[
'defaultleasetime'
]
!=
$dhcpifconf
[
'defaultleasetime'
]))
{
$dhcpdconf
.=
" default-lease-time
{
$sm
[
'defaultleasetime'
]
}
;
\n
"
;
$dhcpdconf
.=
" default-lease-time
{
$sm
[
'defaultleasetime'
]
}
;
\n
"
;
}
// max-lease-time
// max-lease-time
if
(
$sm
[
'maxleasetime'
]
&&
(
$sm
[
'maxleasetime'
]
!=
$dhcpifconf
[
'maxleasetime'
]))
if
(
$sm
[
'maxleasetime'
]
&&
(
$sm
[
'maxleasetime'
]
!=
$dhcpifconf
[
'maxleasetime'
]))
{
$dhcpdconf
.=
" max-lease-time
{
$sm
[
'maxleasetime'
]
}
;
\n
"
;
$dhcpdconf
.=
" max-lease-time
{
$sm
[
'maxleasetime'
]
}
;
\n
"
;
}
// netbios-name*
// netbios-name*
if
(
is_array
(
$sm
[
'winsserver'
])
&&
$sm
[
'winsserver'
][
0
]
&&
(
$sm
[
'winsserver'
][
0
]
!=
$dhcpifconf
[
'winsserver'
][
0
]))
{
if
(
is_array
(
$sm
[
'winsserver'
])
&&
$sm
[
'winsserver'
][
0
]
&&
(
$sm
[
'winsserver'
][
0
]
!=
$dhcpifconf
[
'winsserver'
][
0
]))
{
...
@@ -893,12 +948,14 @@ EOD;
...
@@ -893,12 +948,14 @@ EOD;
}
}
// ntp-servers
// ntp-servers
if
(
is_array
(
$sm
[
'ntpserver'
])
&&
$sm
[
'ntpserver'
][
0
]
&&
(
$sm
[
'ntpserver'
][
0
]
!=
$dhcpifconf
[
'ntpserver'
][
0
]))
if
(
is_array
(
$sm
[
'ntpserver'
])
&&
$sm
[
'ntpserver'
][
0
]
&&
(
$sm
[
'ntpserver'
][
0
]
!=
$dhcpifconf
[
'ntpserver'
][
0
]))
{
$dhcpdconf
.=
" option ntp-servers "
.
join
(
","
,
$sm
[
'ntpserver'
])
.
";
\n
"
;
$dhcpdconf
.=
" option ntp-servers "
.
join
(
","
,
$sm
[
'ntpserver'
])
.
";
\n
"
;
}
// tftp-server-name
// tftp-server-name
if
(
!
empty
(
$sm
[
'tftp'
])
&&
(
$sm
[
'tftp'
]
!=
$dhcpifconf
[
'tftp'
]))
if
(
!
empty
(
$sm
[
'tftp'
])
&&
(
$sm
[
'tftp'
]
!=
$dhcpifconf
[
'tftp'
]))
{
$dhcpdconf
.=
" option tftp-server-name
\"
{
$sm
[
'tftp'
]
}
\"
;
\n
"
;
$dhcpdconf
.=
" option tftp-server-name
\"
{
$sm
[
'tftp'
]
}
\"
;
\n
"
;
}
$dhcpdconf
.=
"}
\n
"
;
$dhcpdconf
.=
"}
\n
"
;
$i
++
;
$i
++
;
...
@@ -906,10 +963,8 @@ EOD;
...
@@ -906,10 +963,8 @@ EOD;
}
}
$dhcpdifs
[]
=
get_real_interface
(
$dhcpif
);
$dhcpdifs
[]
=
get_real_interface
(
$dhcpif
);
if
(
$newzone
[
'domain-name'
])
if
(
$newzone
[
'domain-name'
])
{
{
if
(
$need_ddns_updates
)
{
if
(
$need_ddns_updates
)
{
$newzone
[
'dns-servers'
]
=
array
(
$dhcpifconf
[
'ddnsdomainprimary'
]);
$newzone
[
'dns-servers'
]
=
array
(
$dhcpifconf
[
'ddnsdomainprimary'
]);
}
}
$ddns_zones
[]
=
$newzone
;
$ddns_zones
[]
=
$newzone
;
...
@@ -919,7 +974,6 @@ EOD;
...
@@ -919,7 +974,6 @@ EOD;
if
(
$need_ddns_updates
)
{
if
(
$need_ddns_updates
)
{
$dhcpdconf
.=
"ddns-update-style interim;
\n
"
;
$dhcpdconf
.=
"ddns-update-style interim;
\n
"
;
$dhcpdconf
.=
"update-static-leases on;
\n
"
;
$dhcpdconf
.=
"update-static-leases on;
\n
"
;
$dhcpdconf
.=
dhcpdkey
(
$dhcpifconf
);
$dhcpdconf
.=
dhcpdkey
(
$dhcpifconf
);
$dhcpdconf
.=
dhcpdzones
(
$ddns_zones
,
$dhcpifconf
);
$dhcpdconf
.=
dhcpdzones
(
$ddns_zones
,
$dhcpifconf
);
}
}
...
@@ -941,12 +995,12 @@ EOD;
...
@@ -941,12 +995,12 @@ EOD;
/* fire up dhcpd in a chroot */
/* fire up dhcpd in a chroot */
if
(
count
(
$dhcpdifs
)
>
0
)
{
if
(
count
(
$dhcpdifs
)
>
0
)
{
mwexec
(
"/usr/local/sbin/dhcpd -user dhcpd -group dhcpd -chroot
{
$g
[
'dhcpd_chroot_path'
]
}
-cf /etc/dhcpd.conf -pf /var/run/dhcpd.pid "
.
mwexec
(
"/usr/local/sbin/dhcpd -user dhcpd -group dhcpd -chroot
{
$g
[
'dhcpd_chroot_path'
]
}
-cf /etc/dhcpd.conf -pf /var/run/dhcpd.pid "
.
join
(
" "
,
$dhcpdifs
));
join
(
" "
,
$dhcpdifs
));
}
}
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
print
"done.
\n
"
;
print
"done.
\n
"
;
}
return
0
;
return
0
;
}
}
...
@@ -954,8 +1008,7 @@ EOD;
...
@@ -954,8 +1008,7 @@ EOD;
function
dhcpdkey
(
$dhcpifconf
)
function
dhcpdkey
(
$dhcpifconf
)
{
{
$dhcpdconf
=
""
;
$dhcpdconf
=
""
;
if
(
$dhcpifconf
[
'ddnsdomainkeyname'
]
<>
""
&&
$dhcpifconf
[
'ddnsdomainkey'
]
<>
""
)
if
(
$dhcpifconf
[
'ddnsdomainkeyname'
]
<>
""
&&
$dhcpifconf
[
'ddnsdomainkey'
]
<>
""
)
{
{
$dhcpdconf
.=
"key
{
$dhcpifconf
[
'ddnsdomainkeyname'
]
}
{\n"
;
$dhcpdconf
.=
"key
{
$dhcpifconf
[
'ddnsdomainkeyname'
]
}
{\n"
;
$dhcpdconf
.=
" algorithm hmac-md5;
\n
"
;
$dhcpdconf
.=
" algorithm hmac-md5;
\n
"
;
$dhcpdconf
.=
" secret
{
$dhcpifconf
[
'ddnsdomainkey'
]
}
;
\n
"
;
$dhcpdconf
.=
" secret
{
$dhcpifconf
[
'ddnsdomainkey'
]
}
;
\n
"
;
...
@@ -972,8 +1025,9 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
...
@@ -972,8 +1025,9 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
if
(
is_array
(
$ddns_zones
))
{
if
(
is_array
(
$ddns_zones
))
{
$added_zones
=
array
();
$added_zones
=
array
();
foreach
(
$ddns_zones
as
$zone
)
{
foreach
(
$ddns_zones
as
$zone
)
{
if
(
!
is_array
(
$zone
)
||
empty
(
$zone
)
||
!
is_array
(
$zone
[
'dns-servers'
]))
if
(
!
is_array
(
$zone
)
||
empty
(
$zone
)
||
!
is_array
(
$zone
[
'dns-servers'
]))
{
continue
;
continue
;
}
$primary
=
$zone
[
'dns-servers'
][
0
];
$primary
=
$zone
[
'dns-servers'
][
0
];
$secondary
=
empty
(
$zone
[
'dns-servers'
][
1
])
?
""
:
$zone
[
'dns-servers'
][
1
];
$secondary
=
empty
(
$zone
[
'dns-servers'
][
1
])
?
""
:
$zone
[
'dns-servers'
][
1
];
...
@@ -991,20 +1045,24 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
...
@@ -991,20 +1045,24 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
if
(
$zone
[
'domain-name'
]
&&
!
in_array
(
$zone
[
'domain-name'
],
$added_zones
))
{
if
(
$zone
[
'domain-name'
]
&&
!
in_array
(
$zone
[
'domain-name'
],
$added_zones
))
{
$dhcpdconf
.=
"zone
{
$zone
[
'domain-name'
]
}
. {\n"
;
$dhcpdconf
.=
"zone
{
$zone
[
'domain-name'
]
}
. {\n"
;
$dhcpdconf
.=
" primary
{
$primary
}
;
\n
"
;
$dhcpdconf
.=
" primary
{
$primary
}
;
\n
"
;
if
(
is_ipaddrv4
(
$secondary
))
if
(
is_ipaddrv4
(
$secondary
))
{
$dhcpdconf
.=
" secondary
{
$secondary
}
;
\n
"
;
$dhcpdconf
.=
" secondary
{
$secondary
}
;
\n
"
;
if
(
$dhcpifconf
[
'ddnsdomainkeyname'
]
<>
""
&&
$dhcpifconf
[
'ddnsdomainkey'
]
<>
""
)
}
if
(
$dhcpifconf
[
'ddnsdomainkeyname'
]
<>
""
&&
$dhcpifconf
[
'ddnsdomainkey'
]
<>
""
)
{
$dhcpdconf
.=
" key
{
$dhcpifconf
[
'ddnsdomainkeyname'
]
}
;
\n
"
;
$dhcpdconf
.=
" key
{
$dhcpifconf
[
'ddnsdomainkeyname'
]
}
;
\n
"
;
}
$dhcpdconf
.=
"}
\n
"
;
$dhcpdconf
.=
"}
\n
"
;
$added_zones
[]
=
$zone
[
'domain-name'
];
$added_zones
[]
=
$zone
[
'domain-name'
];
}
}
if
(
$zone
[
'ptr-domain'
]
&&
!
in_array
(
$zone
[
'ptr-domain'
],
$added_zones
))
{
if
(
$zone
[
'ptr-domain'
]
&&
!
in_array
(
$zone
[
'ptr-domain'
],
$added_zones
))
{
$dhcpdconf
.=
"zone
{
$zone
[
'ptr-domain'
]
}
{\n"
;
$dhcpdconf
.=
"zone
{
$zone
[
'ptr-domain'
]
}
{\n"
;
$dhcpdconf
.=
" primary
{
$primary
}
;
\n
"
;
$dhcpdconf
.=
" primary
{
$primary
}
;
\n
"
;
if
(
is_ipaddrv4
(
$secondary
))
if
(
is_ipaddrv4
(
$secondary
))
{
$dhcpdconf
.=
" secondary
{
$secondary
}
;
\n
"
;
$dhcpdconf
.=
" secondary
{
$secondary
}
;
\n
"
;
if
(
$dhcpifconf
[
'ddnsdomainkeyname'
]
<>
""
&&
$dhcpifconf
[
'ddnsdomainkey'
]
<>
""
)
}
if
(
$dhcpifconf
[
'ddnsdomainkeyname'
]
<>
""
&&
$dhcpifconf
[
'ddnsdomainkey'
]
<>
""
)
{
$dhcpdconf
.=
" key
{
$dhcpifconf
[
'ddnsdomainkeyname'
]
}
;
\n
"
;
$dhcpdconf
.=
" key
{
$dhcpifconf
[
'ddnsdomainkeyname'
]
}
;
\n
"
;
}
$dhcpdconf
.=
"}
\n
"
;
$dhcpdconf
.=
"}
\n
"
;
$added_zones
[]
=
$zone
[
'ptr-domain'
];
$added_zones
[]
=
$zone
[
'ptr-domain'
];
}
}
...
@@ -1069,13 +1127,15 @@ function services_dhcpdv6_configure($blacklist = array())
...
@@ -1069,13 +1127,15 @@ function services_dhcpdv6_configure($blacklist = array())
/* we add a fake entry for interfaces that are set to track6 another WAN */
/* we add a fake entry for interfaces that are set to track6 another WAN */
foreach
(
$Iflist
as
$ifname
)
{
foreach
(
$Iflist
as
$ifname
)
{
/* Do not put in the config an interface which is down */
/* Do not put in the config an interface which is down */
if
(
isset
(
$blacklist
[
$ifname
]))
if
(
isset
(
$blacklist
[
$ifname
]))
{
continue
;
continue
;
}
if
(
!
empty
(
$config
[
'interfaces'
][
$ifname
][
'track6-interface'
]))
{
if
(
!
empty
(
$config
[
'interfaces'
][
$ifname
][
'track6-interface'
]))
{
$realif
=
get_real_interface
(
$ifname
,
"inet6"
);
$realif
=
get_real_interface
(
$ifname
,
"inet6"
);
$ifcfgipv6
=
get_interface_ipv6
(
$ifname
);
$ifcfgipv6
=
get_interface_ipv6
(
$ifname
);
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
{
continue
;
continue
;
}
$ifcfgipv6
=
Net_IPv6
::
getNetmask
(
$ifcfgipv6
,
64
);
$ifcfgipv6
=
Net_IPv6
::
getNetmask
(
$ifcfgipv6
,
64
);
$trackifname
=
$config
[
'interfaces'
][
$ifname
][
'track6-interface'
];
$trackifname
=
$config
[
'interfaces'
][
$ifname
][
'track6-interface'
];
$trackcfg
=
$config
[
'interfaces'
][
$trackifname
];
$trackcfg
=
$config
[
'interfaces'
][
$trackifname
];
...
@@ -1090,7 +1150,7 @@ function services_dhcpdv6_configure($blacklist = array())
...
@@ -1090,7 +1150,7 @@ function services_dhcpdv6_configure($blacklist = array())
$ifcfgipv6arr
[
7
]
=
"2000"
;
$ifcfgipv6arr
[
7
]
=
"2000"
;
$dhcpdv6cfg
[
$ifname
][
'range'
][
'to'
]
=
Net_IPv6
::
compress
(
implode
(
":"
,
$ifcfgipv6arr
));
$dhcpdv6cfg
[
$ifname
][
'range'
][
'to'
]
=
Net_IPv6
::
compress
(
implode
(
":"
,
$ifcfgipv6arr
));
/* prefix length > 0? We can add dhcp6 prefix delegation server */
/* prefix length > 0? We can add dhcp6 prefix delegation server */
if
(
$pdlen
>
2
)
{
if
(
$pdlen
>
2
)
{
$pdlenmax
=
$pdlen
;
$pdlenmax
=
$pdlen
;
$pdlenhalf
=
$pdlenmax
-
1
;
$pdlenhalf
=
$pdlenmax
-
1
;
$pdlenmin
=
(
64
-
ceil
(
$pdlenhalf
/
4
));
$pdlenmin
=
(
64
-
ceil
(
$pdlenhalf
/
4
));
...
@@ -1114,15 +1174,16 @@ function services_dhcpdv6_configure($blacklist = array())
...
@@ -1114,15 +1174,16 @@ function services_dhcpdv6_configure($blacklist = array())
$custoptionsv6
=
""
;
$custoptionsv6
=
""
;
foreach
(
$dhcpdv6cfg
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
foreach
(
$dhcpdv6cfg
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
if
(
isset
(
$dhcpv6ifconf
[
'numberoptions'
][
'item'
]))
{
if
(
isset
(
$dhcpv6ifconf
[
'numberoptions'
][
'item'
]))
{
foreach
(
$dhcpv6ifconf
[
'numberoptions'
][
'item'
]
as
$itemv6idx
=>
$itemv6
)
{
foreach
(
$dhcpv6ifconf
[
'numberoptions'
][
'item'
]
as
$itemv6idx
=>
$itemv6
)
{
$custoptionsv6
.=
"option custom-
{
$dhcpv6if
}
-
{
$itemv6idx
}
code
{
$itemv6
[
'number'
]
}
= text;
\n
"
;
$custoptionsv6
.=
"option custom-
{
$dhcpv6if
}
-
{
$itemv6idx
}
code
{
$itemv6
[
'number'
]
}
= text;
\n
"
;
}
}
}
}
}
}
if
(
isset
(
$dhcpv6ifconf
[
'netboot'
])
&&
!
empty
(
$dhcpv6ifconf
[
'bootfile_url'
]))
if
(
isset
(
$dhcpv6ifconf
[
'netboot'
])
&&
!
empty
(
$dhcpv6ifconf
[
'bootfile_url'
]))
{
$custoptionsv6
.=
"option dhcp6.bootfile-url code 59 = string;
\n
"
;
$custoptionsv6
.=
"option dhcp6.bootfile-url code 59 = string;
\n
"
;
}
$dhcpdv6conf
=
<<<EOD
$dhcpdv6conf
=
<<<EOD
...
@@ -1140,25 +1201,26 @@ update-conflict-detection false;
...
@@ -1140,25 +1201,26 @@ update-conflict-detection false;
EOD;
EOD;
if
(
!
isset
(
$dhcpv6ifconf
[
'disableauthoritative'
]))
if
(
!
isset
(
$dhcpv6ifconf
[
'disableauthoritative'
]))
{
$dhcpdv6conf
.=
"authoritative;
\n
"
;
$dhcpdv6conf
.=
"authoritative;
\n
"
;
}
if
(
isset
(
$dhcpv6ifconf
[
'alwaysbroadcast'
]))
if
(
isset
(
$dhcpv6ifconf
[
'alwaysbroadcast'
]))
{
$dhcpdv6conf
.=
"always-broadcast on
\n
"
;
$dhcpdv6conf
.=
"always-broadcast on
\n
"
;
}
$dhcpdv6ifs
=
array
();
$dhcpdv6ifs
=
array
();
$dhcpv6num
=
0
;
$dhcpv6num
=
0
;
$nsupdate
=
false
;
$nsupdate
=
false
;
foreach
(
$dhcpdv6cfg
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
foreach
(
$dhcpdv6cfg
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
$ddns_zones
=
array
();
$ddns_zones
=
array
();
$ifcfgv6
=
$config
[
'interfaces'
][
$dhcpv6if
];
$ifcfgv6
=
$config
[
'interfaces'
][
$dhcpv6if
];
if
(
!
isset
(
$dhcpv6ifconf
[
'enable'
])
||
!
isset
(
$Iflist
[
$dhcpv6if
]))
if
(
!
isset
(
$dhcpv6ifconf
[
'enable'
])
||
!
isset
(
$Iflist
[
$dhcpv6if
]))
{
continue
;
continue
;
}
$ifcfgipv6
=
get_interface_ipv6
(
$dhcpv6if
);
$ifcfgipv6
=
get_interface_ipv6
(
$dhcpv6if
);
$ifcfgsnv6
=
get_interface_subnetv6
(
$dhcpv6if
);
$ifcfgsnv6
=
get_interface_subnetv6
(
$dhcpv6if
);
$subnetv6
=
gen_subnetv6
(
$ifcfgipv6
,
$ifcfgsnv6
);
$subnetv6
=
gen_subnetv6
(
$ifcfgipv6
,
$ifcfgsnv6
);
...
@@ -1175,7 +1237,7 @@ EOD;
...
@@ -1175,7 +1237,7 @@ EOD;
}
}
if
(
isset
(
$dhcpv6ifconf
[
'ddnsupdate'
]))
{
if
(
isset
(
$dhcpv6ifconf
[
'ddnsupdate'
]))
{
if
(
$dhcpv6ifconf
[
'ddnsdomain'
]
<>
""
)
{
if
(
$dhcpv6ifconf
[
'ddnsdomain'
]
<>
""
)
{
$dnscfgv6
.=
" ddns-domainname
\"
{
$dhcpv6ifconf
[
'ddnsdomain'
]
}
\"
;
\n
"
;
$dnscfgv6
.=
" ddns-domainname
\"
{
$dhcpv6ifconf
[
'ddnsdomain'
]
}
\"
;
\n
"
;
}
}
$dnscfgv6
.=
" ddns-update-style interim;
\n
"
;
$dnscfgv6
.=
" ddns-update-style interim;
\n
"
;
...
@@ -1193,9 +1255,10 @@ EOD;
...
@@ -1193,9 +1255,10 @@ EOD;
$dns_arrv6
[]
=
$dnsserver
;
$dns_arrv6
[]
=
$dnsserver
;
}
}
}
}
if
(
!
empty
(
$dns_arrv6
))
if
(
!
empty
(
$dns_arrv6
))
{
$dnscfgv6
.=
" option dhcp6.name-servers "
.
join
(
","
,
$dns_arrv6
)
.
";"
;
$dnscfgv6
.=
" option dhcp6.name-servers "
.
join
(
","
,
$dns_arrv6
)
.
";"
;
}
}
}
if
(
!
empty
(
$dhcpv6ifconf
[
'domain'
]))
{
if
(
!
empty
(
$dhcpv6ifconf
[
'domain'
]))
{
$newzone
=
array
();
$newzone
=
array
();
...
@@ -1225,23 +1288,27 @@ EOD;
...
@@ -1225,23 +1288,27 @@ EOD;
$dhcpdv6conf
.=
" option dhcp6.name-servers
{
$dhcpv6ifconf
[
'dns6ip'
]
}
;
\n
"
;
$dhcpdv6conf
.=
" option dhcp6.name-servers
{
$dhcpv6ifconf
[
'dns6ip'
]
}
;
\n
"
;
}
}
// default-lease-time
// default-lease-time
if
(
!
empty
(
$dhcpv6ifconf
[
'defaultleasetime'
]))
if
(
!
empty
(
$dhcpv6ifconf
[
'defaultleasetime'
]))
{
$dhcpdv6conf
.=
" default-lease-time
{
$dhcpv6ifconf
[
'defaultleasetime'
]
}
;
\n
"
;
$dhcpdv6conf
.=
" default-lease-time
{
$dhcpv6ifconf
[
'defaultleasetime'
]
}
;
\n
"
;
}
// max-lease-time
// max-lease-time
if
(
!
empty
(
$dhcpv6ifconf
[
'maxleasetime'
]))
if
(
!
empty
(
$dhcpv6ifconf
[
'maxleasetime'
]))
{
$dhcpdv6conf
.=
" max-lease-time
{
$dhcpv6ifconf
[
'maxleasetime'
]
}
;
\n
"
;
$dhcpdv6conf
.=
" max-lease-time
{
$dhcpv6ifconf
[
'maxleasetime'
]
}
;
\n
"
;
}
// ntp-servers
// ntp-servers
if
(
isset
(
$dhcpv6ifconf
[
'ntpserver'
][
0
]))
{
if
(
isset
(
$dhcpv6ifconf
[
'ntpserver'
][
0
]))
{
$ntpservers
=
array
();
$ntpservers
=
array
();
foreach
(
$dhcpv6ifconf
[
'ntpserver'
]
as
$ntpserver
)
{
foreach
(
$dhcpv6ifconf
[
'ntpserver'
]
as
$ntpserver
)
{
if
(
is_ipaddrv6
(
$ntpserver
))
if
(
is_ipaddrv6
(
$ntpserver
))
{
$ntpservers
[]
=
$ntpserver
;
$ntpservers
[]
=
$ntpserver
;
}
}
if
(
count
(
$ntpservers
)
>
0
)
}
if
(
count
(
$ntpservers
)
>
0
)
{
$dhcpdv6conf
.=
" option dhcp6.sntp-servers "
.
join
(
","
,
$dhcpv6ifconf
[
'ntpserver'
])
.
";
\n
"
;
$dhcpdv6conf
.=
" option dhcp6.sntp-servers "
.
join
(
","
,
$dhcpv6ifconf
[
'ntpserver'
])
.
";
\n
"
;
}
}
}
// tftp-server-name
// tftp-server-name
/* Needs ISC DHCPD support
/* Needs ISC DHCPD support
if ($dhcpv6ifconf['tftp'] <> "")
if ($dhcpv6ifconf['tftp'] <> "")
...
@@ -1257,11 +1324,12 @@ EOD;
...
@@ -1257,11 +1324,12 @@ EOD;
}
}
// ldap-server
// ldap-server
if
(
!
empty
(
$dhcpv6ifconf
[
'ldap'
]))
if
(
!
empty
(
$dhcpv6ifconf
[
'ldap'
]))
{
$dhcpdv6conf
.=
" option ldap-server
\"
{
$dhcpv6ifconf
[
'ldap'
]
}
\"
;
\n
"
;
$dhcpdv6conf
.=
" option ldap-server
\"
{
$dhcpv6ifconf
[
'ldap'
]
}
\"
;
\n
"
;
}
// net boot information
// net boot information
if
(
isset
(
$dhcpv6ifconf
[
'netboot'
]))
{
if
(
isset
(
$dhcpv6ifconf
[
'netboot'
]))
{
if
(
!
empty
(
$dhcpv6ifconf
[
'bootfile_url'
]))
{
if
(
!
empty
(
$dhcpv6ifconf
[
'bootfile_url'
]))
{
$dhcpdv6conf
.=
" option dhcp6.bootfile-url
\"
{
$dhcpv6ifconf
[
'bootfile_url'
]
}
\"
;
\n
"
;
$dhcpdv6conf
.=
" option dhcp6.bootfile-url
\"
{
$dhcpv6ifconf
[
'bootfile_url'
]
}
\"
;
\n
"
;
}
}
...
@@ -1279,33 +1347,35 @@ host s_{$dhcpv6if}_{$i} {
...
@@ -1279,33 +1347,35 @@ host s_{$dhcpv6if}_{$i} {
host-identifier option dhcp6.client-id {$sm['duid']};
host-identifier option dhcp6.client-id {$sm['duid']};
EOD;
EOD;
if
(
$sm
[
'ipaddrv6'
])
if
(
$sm
[
'ipaddrv6'
])
{
$dhcpdv6conf
.=
" fixed-address6
{
$sm
[
'ipaddrv6'
]
}
;
\n
"
;
$dhcpdv6conf
.=
" fixed-address6
{
$sm
[
'ipaddrv6'
]
}
;
\n
"
;
}
if
(
$sm
[
'hostname'
])
{
if
(
$sm
[
'hostname'
])
{
$dhhostname
=
str_replace
(
" "
,
"_"
,
$sm
[
'hostname'
]);
$dhhostname
=
str_replace
(
" "
,
"_"
,
$sm
[
'hostname'
]);
$dhhostname
=
str_replace
(
"."
,
"_"
,
$dhhostname
);
$dhhostname
=
str_replace
(
"."
,
"_"
,
$dhhostname
);
$dhcpdv6conf
.=
" option host-name
{
$dhhostname
}
;
\n
"
;
$dhcpdv6conf
.=
" option host-name
{
$dhhostname
}
;
\n
"
;
}
}
if
(
$sm
[
'filename'
])
if
(
$sm
[
'filename'
])
{
$dhcpdv6conf
.=
" filename
\"
{
$sm
[
'filename'
]
}
\"
;
\n
"
;
$dhcpdv6conf
.=
" filename
\"
{
$sm
[
'filename'
]
}
\"
;
\n
"
;
}
if
(
$sm
[
'rootpath'
])
if
(
$sm
[
'rootpath'
])
{
$dhcpdv6conf
.=
" option root-path
\"
{
$sm
[
'rootpath'
]
}
\"
;
\n
"
;
$dhcpdv6conf
.=
" option root-path
\"
{
$sm
[
'rootpath'
]
}
\"
;
\n
"
;
}
$dhcpdv6conf
.=
"}
\n
"
;
$dhcpdv6conf
.=
"}
\n
"
;
$i
++
;
$i
++
;
}
}
}
}
if
(
!
empty
(
$dhcpv6ifconf
[
'domain'
]))
if
(
!
empty
(
$dhcpv6ifconf
[
'domain'
]))
{
{
$dhcpdv6conf
.=
dhcpdkey
(
$dhcpv6ifconf
);
$dhcpdv6conf
.=
dhcpdkey
(
$dhcpv6ifconf
);
$dhcpdv6conf
.=
dhcpdzones
(
$ddns_zones
,
$dhcpv6ifconf
);
$dhcpdv6conf
.=
dhcpdzones
(
$ddns_zones
,
$dhcpv6ifconf
);
}
}
if
(
isset
(
$config
[
'dhcpdv6'
][
$dhcpv6if
][
'ramode'
])
&&
$config
[
'dhcpdv6'
][
$dhcpv6if
][
'ramode'
]
<>
"unmanaged"
)
{
if
(
isset
(
$config
[
'dhcpdv6'
][
$dhcpv6if
][
'ramode'
])
&&
$config
[
'dhcpdv6'
][
$dhcpv6if
][
'ramode'
]
<>
"unmanaged"
)
{
if
(
preg_match
(
"/poes/si"
,
$dhcpv6if
))
{
if
(
preg_match
(
"/poes/si"
,
$dhcpv6if
))
{
/* magic here */
/* magic here */
$dhcpdv6ifs
=
array_merge
(
$dhcpdv6ifs
,
get_pppoes_child_interfaces
(
$dhcpv6if
));
$dhcpdv6ifs
=
array_merge
(
$dhcpdv6ifs
,
get_pppoes_child_interfaces
(
$dhcpv6if
));
}
else
{
}
else
{
...
@@ -1322,28 +1392,27 @@ EOD;
...
@@ -1322,28 +1392,27 @@ EOD;
}
}
}
}
if
(
$nsupdate
)
if
(
$nsupdate
)
{
{
$dhcpdv6conf
.=
"ddns-update-style interim;
\n
"
;
$dhcpdv6conf
.=
"ddns-update-style interim;
\n
"
;
}
}
else
{
else
{
$dhcpdv6conf
.=
"ddns-update-style none;
\n
"
;
$dhcpdv6conf
.=
"ddns-update-style none;
\n
"
;
}
}
/* write dhcpdv6.conf */
/* write dhcpdv6.conf */
if
(
!@
file_put_contents
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/etc/dhcpdv6.conf"
,
$dhcpdv6conf
))
{
if
(
!@
file_put_contents
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/etc/dhcpdv6.conf"
,
$dhcpdv6conf
))
{
log_error
(
"Error: cannot open
{
$g
[
'dhcpd_chroot_path'
]
}
/etc/dhcpdv6.conf in services_dhcpdv6_configure().
\n
"
);
log_error
(
"Error: cannot open
{
$g
[
'dhcpd_chroot_path'
]
}
/etc/dhcpdv6.conf in services_dhcpdv6_configure().
\n
"
);
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
printf
(
"Error: cannot open
{
$g
[
'dhcpd_chroot_path'
]
}
/etc/dhcpdv6.conf in services_dhcpdv6_configure().
\n
"
);
printf
(
"Error: cannot open
{
$g
[
'dhcpd_chroot_path'
]
}
/etc/dhcpdv6.conf in services_dhcpdv6_configure().
\n
"
);
}
unset
(
$dhcpdv6conf
);
unset
(
$dhcpdv6conf
);
return
1
;
return
1
;
}
}
unset
(
$dhcpdv6conf
);
unset
(
$dhcpdv6conf
);
/* create an empty leases v6 database */
/* create an empty leases v6 database */
if
(
!
file_exists
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
))
if
(
!
file_exists
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
))
{
@
touch
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
);
@
touch
(
"
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
);
}
/* make sure there isn't a stale dhcpdv6.pid file, which may make dhcpdv6 fail to start. */
/* make sure there isn't a stale dhcpdv6.pid file, which may make dhcpdv6 fail to start. */
/* if we get here, dhcpdv6 has been killed and is not started yet */
/* if we get here, dhcpdv6 has been killed and is not started yet */
...
@@ -1355,8 +1424,9 @@ EOD;
...
@@ -1355,8 +1424,9 @@ EOD;
join
(
" "
,
$dhcpdv6ifs
));
join
(
" "
,
$dhcpdv6ifs
));
mwexec
(
"/usr/local/sbin/dhcpleases6 -c
\"
/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh
\"
-l
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
);
mwexec
(
"/usr/local/sbin/dhcpleases6 -c
\"
/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh
\"
-l
{
$g
[
'dhcpd_chroot_path'
]
}
/var/db/dhcpd6.leases"
);
}
}
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
print
gettext
(
"done."
)
.
"
\n
"
;
print
gettext
(
"done."
)
.
"
\n
"
;
}
return
0
;
return
0
;
}
}
...
@@ -1368,8 +1438,9 @@ function services_igmpproxy_configure()
...
@@ -1368,8 +1438,9 @@ function services_igmpproxy_configure()
/* kill any running igmpproxy */
/* kill any running igmpproxy */
killbyname
(
"igmpproxy"
);
killbyname
(
"igmpproxy"
);
if
(
!
isset
(
$config
[
'igmpproxy'
][
'igmpentry'
])
||
!
is_array
(
$config
[
'igmpproxy'
][
'igmpentry'
])
||
(
count
(
$config
[
'igmpproxy'
][
'igmpentry'
])
==
0
))
if
(
!
isset
(
$config
[
'igmpproxy'
][
'igmpentry'
])
||
!
is_array
(
$config
[
'igmpproxy'
][
'igmpentry'
])
||
(
count
(
$config
[
'igmpproxy'
][
'igmpentry'
])
==
0
))
{
return
1
;
return
1
;
}
$iflist
=
get_configured_interface_list
();
$iflist
=
get_configured_interface_list
();
...
@@ -1385,17 +1456,19 @@ EOD;
...
@@ -1385,17 +1456,19 @@ EOD;
foreach
(
$config
[
'igmpproxy'
][
'igmpentry'
]
as
$igmpcf
)
{
foreach
(
$config
[
'igmpproxy'
][
'igmpentry'
]
as
$igmpcf
)
{
unset
(
$iflist
[
$igmpcf
[
'ifname'
]]);
unset
(
$iflist
[
$igmpcf
[
'ifname'
]]);
$realif
=
get_real_interface
(
$igmpcf
[
'ifname'
]);
$realif
=
get_real_interface
(
$igmpcf
[
'ifname'
]);
if
(
empty
(
$igmpcf
[
'threshold'
]))
if
(
empty
(
$igmpcf
[
'threshold'
]))
{
$threshld
=
1
;
$threshld
=
1
;
else
}
else
{
$threshld
=
$igmpcf
[
'threshold'
];
$threshld
=
$igmpcf
[
'threshold'
];
}
$igmpconf
.=
"phyint
{
$realif
}
{
$igmpcf
[
'type'
]
}
ratelimit 0 threshold
{
$threshld
}
\n
"
;
$igmpconf
.=
"phyint
{
$realif
}
{
$igmpcf
[
'type'
]
}
ratelimit 0 threshold
{
$threshld
}
\n
"
;
if
(
$igmpcf
[
'address'
]
<>
""
)
{
if
(
$igmpcf
[
'address'
]
<>
""
)
{
$item
=
explode
(
" "
,
$igmpcf
[
'address'
]);
$item
=
explode
(
" "
,
$igmpcf
[
'address'
]);
foreach
(
$item
as
$iww
)
foreach
(
$item
as
$iww
)
{
$igmpconf
.=
"altnet
{
$iww
}
\n
"
;
$igmpconf
.=
"altnet
{
$iww
}
\n
"
;
}
}
}
$igmpconf
.=
"
\n
"
;
$igmpconf
.=
"
\n
"
;
}
}
foreach
(
$iflist
as
$ifn
)
{
foreach
(
$iflist
as
$ifn
)
{
...
@@ -1432,22 +1505,23 @@ function services_dhcrelay_configure()
...
@@ -1432,22 +1505,23 @@ function services_dhcrelay_configure()
if
(
!
isset
(
$dhcrelaycfg
[
'enable'
]))
if
(
!
isset
(
$dhcrelaycfg
[
'enable'
]))
return
0
;
return
0
;
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"Starting DHCP relay service..."
);
echo
gettext
(
"Starting DHCP relay service..."
);
else
}
else
{
sleep
(
1
);
sleep
(
1
);
}
$iflist
=
get_configured_interface_list
();
$iflist
=
get_configured_interface_list
();
$dhcifaces
=
explode
(
","
,
$dhcrelaycfg
[
'interface'
]);
$dhcifaces
=
explode
(
","
,
$dhcrelaycfg
[
'interface'
]);
foreach
(
$dhcifaces
as
$dhcrelayif
)
{
foreach
(
$dhcifaces
as
$dhcrelayif
)
{
if
(
!
isset
(
$iflist
[
$dhcrelayif
])
||
if
(
!
isset
(
$iflist
[
$dhcrelayif
])
||
link_interface_to_bridge
(
$dhcrelayif
))
{
link_interface_to_bridge
(
$dhcrelayif
))
continue
;
continue
;
}
if
(
is_ipaddr
(
get_interface_ip
(
$dhcrelayif
)))
if
(
is_ipaddr
(
get_interface_ip
(
$dhcrelayif
)))
{
$dhcrelayifs
[]
=
get_real_interface
(
$dhcrelayif
);
$dhcrelayifs
[]
=
get_real_interface
(
$dhcrelayif
);
}
}
}
/*
/*
* In order for the relay to work, it needs to be active
* In order for the relay to work, it needs to be active
...
@@ -1458,8 +1532,9 @@ function services_dhcrelay_configure()
...
@@ -1458,8 +1532,9 @@ function services_dhcrelay_configure()
unset
(
$destif
);
unset
(
$destif
);
foreach
(
$iflist
as
$ifname
)
{
foreach
(
$iflist
as
$ifname
)
{
$subnet
=
get_interface_ip
(
$ifname
);
$subnet
=
get_interface_ip
(
$ifname
);
if
(
!
is_ipaddr
(
$subnet
))
if
(
!
is_ipaddr
(
$subnet
))
{
continue
;
continue
;
}
$subnet
.=
"/"
.
get_interface_subnet
(
$ifname
);
$subnet
.=
"/"
.
get_interface_subnet
(
$ifname
);
if
(
ip_in_subnet
(
$srvip
,
$subnet
))
{
if
(
ip_in_subnet
(
$srvip
,
$subnet
))
{
$destif
=
get_real_interface
(
$ifname
);
$destif
=
get_real_interface
(
$ifname
);
...
@@ -1513,9 +1588,10 @@ function services_dhcrelay_configure()
...
@@ -1513,9 +1588,10 @@ function services_dhcrelay_configure()
$destif
=
get_real_interface
(
"wan"
);
$destif
=
get_real_interface
(
"wan"
);
}
}
if
(
!
empty
(
$destif
))
if
(
!
empty
(
$destif
))
{
$dhcrelayifs
[]
=
$destif
;
$dhcrelayifs
[]
=
$destif
;
}
}
}
$dhcrelayifs
=
array_unique
(
$dhcrelayifs
);
$dhcrelayifs
=
array_unique
(
$dhcrelayifs
);
/* fire up dhcrelay */
/* fire up dhcrelay */
...
@@ -1526,8 +1602,9 @@ function services_dhcrelay_configure()
...
@@ -1526,8 +1602,9 @@ function services_dhcrelay_configure()
$cmd
=
"/usr/local/sbin/dhcrelay -i "
.
implode
(
" -i "
,
$dhcrelayifs
);
$cmd
=
"/usr/local/sbin/dhcrelay -i "
.
implode
(
" -i "
,
$dhcrelayifs
);
if
(
isset
(
$dhcrelaycfg
[
'agentoption'
]))
if
(
isset
(
$dhcrelaycfg
[
'agentoption'
]))
{
$cmd
.=
" -a -m replace"
;
$cmd
.=
" -a -m replace"
;
}
$cmd
.=
" "
.
implode
(
" "
,
$srvips
);
$cmd
.=
" "
.
implode
(
" "
,
$srvips
);
mwexec
(
$cmd
);
mwexec
(
$cmd
);
...
@@ -1546,25 +1623,27 @@ function services_dhcrelay6_configure()
...
@@ -1546,25 +1623,27 @@ function services_dhcrelay6_configure()
$dhcrelaycfg
=&
$config
[
'dhcrelay6'
];
$dhcrelaycfg
=&
$config
[
'dhcrelay6'
];
/* DHCPv6 Relay enabled on any interfaces? */
/* DHCPv6 Relay enabled on any interfaces? */
if
(
!
isset
(
$dhcrelaycfg
[
'enable'
]))
if
(
!
isset
(
$dhcrelaycfg
[
'enable'
]))
{
return
0
;
return
0
;
}
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"Starting DHCPv6 relay service..."
);
echo
gettext
(
"Starting DHCPv6 relay service..."
);
else
}
else
{
sleep
(
1
);
sleep
(
1
);
}
$iflist
=
get_configured_interface_list
();
$iflist
=
get_configured_interface_list
();
$dhcifaces
=
explode
(
","
,
$dhcrelaycfg
[
'interface'
]);
$dhcifaces
=
explode
(
","
,
$dhcrelaycfg
[
'interface'
]);
foreach
(
$dhcifaces
as
$dhcrelayif
)
{
foreach
(
$dhcifaces
as
$dhcrelayif
)
{
if
(
!
isset
(
$iflist
[
$dhcrelayif
])
||
if
(
!
isset
(
$iflist
[
$dhcrelayif
])
||
link_interface_to_bridge
(
$dhcrelayif
))
{
link_interface_to_bridge
(
$dhcrelayif
))
continue
;
continue
;
}
if
(
is_ipaddrv6
(
get_interface_ipv6
(
$dhcrelayif
)))
if
(
is_ipaddrv6
(
get_interface_ipv6
(
$dhcrelayif
)))
{
$dhcrelayifs
[]
=
get_real_interface
(
$dhcrelayif
);
$dhcrelayifs
[]
=
get_real_interface
(
$dhcrelayif
);
}
}
}
$dhcrelayifs
=
array_unique
(
$dhcrelayifs
);
$dhcrelayifs
=
array_unique
(
$dhcrelayifs
);
/*
/*
...
@@ -1577,8 +1656,9 @@ function services_dhcrelay6_configure()
...
@@ -1577,8 +1656,9 @@ function services_dhcrelay6_configure()
unset
(
$destif
);
unset
(
$destif
);
foreach
(
$iflist
as
$ifname
)
{
foreach
(
$iflist
as
$ifname
)
{
$subnet
=
get_interface_ipv6
(
$ifname
);
$subnet
=
get_interface_ipv6
(
$ifname
);
if
(
!
is_ipaddrv6
(
$subnet
))
if
(
!
is_ipaddrv6
(
$subnet
))
{
continue
;
continue
;
}
$subnet
.=
"/"
.
get_interface_subnetv6
(
$ifname
);
$subnet
.=
"/"
.
get_interface_subnetv6
(
$ifname
);
if
(
ip_in_subnet
(
$srvip
,
$subnet
))
{
if
(
ip_in_subnet
(
$srvip
,
$subnet
))
{
$destif
=
get_real_interface
(
$ifname
);
$destif
=
get_real_interface
(
$ifname
);
...
@@ -1622,9 +1702,10 @@ function services_dhcrelay6_configure()
...
@@ -1622,9 +1702,10 @@ function services_dhcrelay6_configure()
break
;
break
;
}
}
}
}
}
else
}
else
{
$destif
=
get_real_interface
(
"wan"
);
$destif
=
get_real_interface
(
"wan"
);
}
}
}
if
(
!
empty
(
$destif
))
{
if
(
!
empty
(
$destif
))
{
$srvifaces
[]
=
"
{
$srvip
}
%
{
$destif
}
"
;
$srvifaces
[]
=
"
{
$srvip
}
%
{
$destif
}
"
;
...
@@ -1687,8 +1768,9 @@ function services_dyndns_list()
...
@@ -1687,8 +1768,9 @@ function services_dyndns_list()
function
services_dyndns_configure_client
(
$conf
)
{
function
services_dyndns_configure_client
(
$conf
)
{
if
(
!
isset
(
$conf
[
'enable'
]))
if
(
!
isset
(
$conf
[
'enable'
]))
{
return
;
return
;
}
$dns
=
new
updatedns
(
$dnsService
=
$conf
[
'type'
],
$dns
=
new
updatedns
(
$dnsService
=
$conf
[
'type'
],
$dnsHost
=
$conf
[
'host'
],
$dnsHost
=
$conf
[
'host'
],
...
@@ -1709,7 +1791,8 @@ function services_dyndns_configure_client($conf) {
...
@@ -1709,7 +1791,8 @@ function services_dyndns_configure_client($conf) {
$dnsID
=
"
{
$conf
[
'id'
]
}
"
,
$dnsID
=
"
{
$conf
[
'id'
]
}
"
,
$dnsVerboseLog
=
$conf
[
'verboselog'
],
$dnsVerboseLog
=
$conf
[
'verboselog'
],
$curlIpresolveV4
=
$conf
[
'curl_ipresolve_v4'
],
$curlIpresolveV4
=
$conf
[
'curl_ipresolve_v4'
],
$curlSslVerifypeer
=
$conf
[
'curl_ssl_verifypeer'
]);
$curlSslVerifypeer
=
$conf
[
'curl_ssl_verifypeer'
]
);
}
}
function
services_dyndns_configure
(
$int
=
''
)
function
services_dyndns_configure
(
$int
=
''
)
...
@@ -1718,11 +1801,11 @@ function services_dyndns_configure($int = '')
...
@@ -1718,11 +1801,11 @@ function services_dyndns_configure($int = '')
if
(
isset
(
$config
[
'dyndnses'
][
'dyndns'
]))
{
if
(
isset
(
$config
[
'dyndnses'
][
'dyndns'
]))
{
$dyndnscfg
=
$config
[
'dyndnses'
][
'dyndns'
];
$dyndnscfg
=
$config
[
'dyndnses'
][
'dyndns'
];
$gwgroups
=
return_gateway_groups_array
();
$gwgroups
=
return_gateway_groups_array
();
if
(
is_array
(
$dyndnscfg
))
{
if
(
is_array
(
$dyndnscfg
))
{
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"Starting dynamic DNS clients..."
);
echo
gettext
(
"Starting dynamic DNS clients..."
);
}
foreach
(
$dyndnscfg
as
$dyndns
)
{
foreach
(
$dyndnscfg
as
$dyndns
)
{
if
((
empty
(
$int
))
||
(
$int
==
$dyndns
[
'interface'
])
||
(
is_array
(
$gwgroups
[
$dyndns
[
'interface'
]])))
{
if
((
empty
(
$int
))
||
(
$int
==
$dyndns
[
'interface'
])
||
(
is_array
(
$gwgroups
[
$dyndns
[
'interface'
]])))
{
...
@@ -1734,10 +1817,11 @@ function services_dyndns_configure($int = '')
...
@@ -1734,10 +1817,11 @@ function services_dyndns_configure($int = '')
}
}
}
}
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"done."
)
.
"
\n
"
;
echo
gettext
(
"done."
)
.
"
\n
"
;
}
}
}
}
}
return
0
;
return
0
;
}
}
...
@@ -1752,8 +1836,9 @@ function dyndnsCheckIP($int)
...
@@ -1752,8 +1836,9 @@ function dyndnsCheckIP($int)
$gateways_status
=
return_gateways_status
(
true
);
$gateways_status
=
return_gateways_status
(
true
);
// If the gateway for this interface is down, then the external check cannot work.
// If the gateway for this interface is down, then the external check cannot work.
// Avoid the long wait for the external check to timeout.
// Avoid the long wait for the external check to timeout.
if
(
stristr
(
$gateways_status
[
$config
[
'interfaces'
][
$int
][
'gateway'
]][
'status'
],
"down"
))
if
(
stristr
(
$gateways_status
[
$config
[
'interfaces'
][
$int
][
'gateway'
]][
'status'
],
"down"
))
{
return
"down"
;
return
"down"
;
}
$hosttocheck
=
"http://checkip.dyndns.org"
;
$hosttocheck
=
"http://checkip.dyndns.org"
;
$ip_ch
=
curl_init
(
$hosttocheck
);
$ip_ch
=
curl_init
(
$hosttocheck
);
curl_setopt
(
$ip_ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ip_ch
,
CURLOPT_RETURNTRANSFER
,
1
);
...
@@ -1787,11 +1872,11 @@ function services_dnsmasq_configure()
...
@@ -1787,11 +1872,11 @@ function services_dnsmasq_configure()
killbypid
(
'/var/run/dnsmasq.pid'
);
killbypid
(
'/var/run/dnsmasq.pid'
);
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
if
(
isset
(
$config
[
'dnsmasq'
][
'enable'
]))
{
if
(
file_exists
(
"/var/run/booting"
))
{
if
(
file_exists
(
"/var/run/booting"
))
echo
gettext
(
"Starting DNS forwarder..."
);
echo
gettext
(
"Starting DNS forwarder..."
);
else
}
else
{
sleep
(
1
);
sleep
(
1
);
}
$args
=
""
;
$args
=
""
;
...
@@ -1805,12 +1890,12 @@ function services_dnsmasq_configure()
...
@@ -1805,12 +1890,12 @@ function services_dnsmasq_configure()
}
}
$listen_addresses
=
""
;
$listen_addresses
=
""
;
if
(
isset
(
$config
[
'dnsmasq'
][
'interface'
]))
{
if
(
isset
(
$config
[
'dnsmasq'
][
'interface'
]))
{
$interfaces
=
explode
(
","
,
$config
[
'dnsmasq'
][
'interface'
]);
$interfaces
=
explode
(
","
,
$config
[
'dnsmasq'
][
'interface'
]);
foreach
(
$interfaces
as
$interface
)
{
foreach
(
$interfaces
as
$interface
)
{
if
(
is_ipaddrv4
(
$interface
))
{
if
(
is_ipaddrv4
(
$interface
))
{
$listen_addresses
.=
" --listen-address=
{
$interface
}
"
;
$listen_addresses
.=
" --listen-address=
{
$interface
}
"
;
}
else
if
(
is_ipaddrv6
(
$interface
))
{
}
else
if
(
is_ipaddrv6
(
$interface
))
{
/*
/*
* XXX: Since dnsmasq does not support link-local address
* XXX: Since dnsmasq does not support link-local address
* with scope specified. These checks are being done.
* with scope specified. These checks are being done.
...
@@ -1818,14 +1903,16 @@ function services_dnsmasq_configure()
...
@@ -1818,14 +1903,16 @@ function services_dnsmasq_configure()
if
(
is_linklocal
(
$interface
)
&&
strstr
(
$interface
,
"%"
))
{
if
(
is_linklocal
(
$interface
)
&&
strstr
(
$interface
,
"%"
))
{
$tmpaddrll6
=
explode
(
"%"
,
$interface
);
$tmpaddrll6
=
explode
(
"%"
,
$interface
);
$listen_addresses
.=
" --listen-address=
{
$tmpaddrll6
[
0
]
}
"
;
$listen_addresses
.=
" --listen-address=
{
$tmpaddrll6
[
0
]
}
"
;
}
else
}
else
{
$listen_addresses
.=
" --listen-address=
{
$interface
}
"
;
$listen_addresses
.=
" --listen-address=
{
$interface
}
"
;
}
}
else
{
}
else
{
$if
=
get_real_interface
(
$interface
);
$if
=
get_real_interface
(
$interface
);
if
(
does_interface_exist
(
$if
))
{
if
(
does_interface_exist
(
$if
))
{
$laddr
=
find_interface_ip
(
$if
);
$laddr
=
find_interface_ip
(
$if
);
if
(
is_ipaddrv4
(
$laddr
))
if
(
is_ipaddrv4
(
$laddr
))
{
$listen_addresses
.=
" --listen-address=
{
$laddr
}
"
;
$listen_addresses
.=
" --listen-address=
{
$laddr
}
"
;
}
$laddr6
=
find_interface_ipv6
(
$if
);
$laddr6
=
find_interface_ipv6
(
$if
);
if
(
is_ipaddrv6
(
$laddr6
)
&&
!
isset
(
$config
[
'dnsmasq'
][
'strictbind'
]))
{
if
(
is_ipaddrv6
(
$laddr6
)
&&
!
isset
(
$config
[
'dnsmasq'
][
'strictbind'
]))
{
/*
/*
...
@@ -1835,18 +1922,20 @@ function services_dnsmasq_configure()
...
@@ -1835,18 +1922,20 @@ function services_dnsmasq_configure()
if
(
is_linklocal
(
$laddr6
)
&&
strstr
(
$laddr6
,
"%"
))
{
if
(
is_linklocal
(
$laddr6
)
&&
strstr
(
$laddr6
,
"%"
))
{
$tmpaddrll6
=
explode
(
"%"
,
$laddr6
);
$tmpaddrll6
=
explode
(
"%"
,
$laddr6
);
$listen_addresses
.=
" --listen-address=
{
$tmpaddrll6
[
0
]
}
"
;
$listen_addresses
.=
" --listen-address=
{
$tmpaddrll6
[
0
]
}
"
;
}
else
}
else
{
$listen_addresses
.=
" --listen-address=
{
$laddr6
}
"
;
$listen_addresses
.=
" --listen-address=
{
$laddr6
}
"
;
}
}
}
}
}
}
}
}
}
if
(
!
empty
(
$listen_addresses
))
{
if
(
!
empty
(
$listen_addresses
))
{
$args
.=
"
{
$listen_addresses
}
"
;
$args
.=
"
{
$listen_addresses
}
"
;
if
(
isset
(
$config
[
'dnsmasq'
][
'strictbind'
]))
if
(
isset
(
$config
[
'dnsmasq'
][
'strictbind'
]))
{
$args
.=
" --bind-interfaces "
;
$args
.=
" --bind-interfaces "
;
}
}
}
}
}
/* If selected, then first forward reverse lookups for private IPv4 addresses to nowhere. */
/* If selected, then first forward reverse lookups for private IPv4 addresses to nowhere. */
/* If any of these are duplicated by a user-specified domain override (e.g. 10.in-addr.arpa) then */
/* If any of these are duplicated by a user-specified domain override (e.g. 10.in-addr.arpa) then */
...
@@ -1874,15 +1963,16 @@ function services_dnsmasq_configure()
...
@@ -1874,15 +1963,16 @@ function services_dnsmasq_configure()
/* Allow DNS Rebind for forwarded domains */
/* Allow DNS Rebind for forwarded domains */
if
(
isset
(
$config
[
'dnsmasq'
][
'domainoverrides'
])
&&
is_array
(
$config
[
'dnsmasq'
][
'domainoverrides'
]))
{
if
(
isset
(
$config
[
'dnsmasq'
][
'domainoverrides'
])
&&
is_array
(
$config
[
'dnsmasq'
][
'domainoverrides'
]))
{
if
(
!
isset
(
$config
[
'system'
][
'webgui'
][
'nodnsrebindcheck'
]))
{
if
(
!
isset
(
$config
[
'system'
][
'webgui'
][
'nodnsrebindcheck'
]))
{
foreach
(
$config
[
'dnsmasq'
][
'domainoverrides'
]
as
$override
)
{
foreach
(
$config
[
'dnsmasq'
][
'domainoverrides'
]
as
$override
)
{
$args
.=
' --rebind-domain-ok=/'
.
$override
[
'domain'
]
.
'/ '
;
$args
.=
' --rebind-domain-ok=/'
.
$override
[
'domain'
]
.
'/ '
;
}
}
}
}
}
}
if
(
!
isset
(
$config
[
'system'
][
'webgui'
][
'nodnsrebindcheck'
]))
if
(
!
isset
(
$config
[
'system'
][
'webgui'
][
'nodnsrebindcheck'
]))
{
$dns_rebind
=
"--rebind-localhost-ok --stop-dns-rebind"
;
$dns_rebind
=
"--rebind-localhost-ok --stop-dns-rebind"
;
}
if
(
isset
(
$config
[
'dnsmasq'
][
'strict_order'
]))
{
if
(
isset
(
$config
[
'dnsmasq'
][
'strict_order'
]))
{
$args
.=
" --strict-order "
;
$args
.=
" --strict-order "
;
...
@@ -1896,10 +1986,11 @@ function services_dnsmasq_configure()
...
@@ -1896,10 +1986,11 @@ function services_dnsmasq_configure()
foreach
(
preg_split
(
'/\s+/'
,
$config
[
'dnsmasq'
][
'custom_options'
])
as
$c
)
{
foreach
(
preg_split
(
'/\s+/'
,
$config
[
'dnsmasq'
][
'custom_options'
])
as
$c
)
{
$args
.=
" "
.
escapeshellarg
(
"--
{
$c
}
"
);
$args
.=
" "
.
escapeshellarg
(
"--
{
$c
}
"
);
$p
=
explode
(
'='
,
$c
);
$p
=
explode
(
'='
,
$c
);
if
(
array_key_exists
(
$p
[
0
],
$standard_args
))
if
(
array_key_exists
(
$p
[
0
],
$standard_args
))
{
unset
(
$standard_args
[
$p
[
0
]]);
unset
(
$standard_args
[
$p
[
0
]]);
}
}
}
}
}
$args
.=
' '
.
implode
(
' '
,
array_values
(
$standard_args
));
$args
.=
' '
.
implode
(
' '
,
array_values
(
$standard_args
));
/* run dnsmasq */
/* run dnsmasq */
...
@@ -1909,14 +2000,16 @@ function services_dnsmasq_configure()
...
@@ -1909,14 +2000,16 @@ function services_dnsmasq_configure()
system_dhcpleases_configure
();
system_dhcpleases_configure
();
unset
(
$args
);
unset
(
$args
);
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"done."
)
.
"
\n
"
;
echo
gettext
(
"done."
)
.
"
\n
"
;
}
}
}
if
(
!
file_exists
(
"/var/run/booting"
))
{
if
(
!
file_exists
(
"/var/run/booting"
))
{
if
(
services_dhcpd_configure
()
!=
0
)
if
(
services_dhcpd_configure
()
!=
0
)
{
$return
=
1
;
$return
=
1
;
}
}
}
return
$return
;
return
$return
;
}
}
...
@@ -1930,21 +2023,24 @@ function services_unbound_configure()
...
@@ -1930,21 +2023,24 @@ function services_unbound_configure()
killbypid
(
'/var/run/unbound.pid'
);
killbypid
(
'/var/run/unbound.pid'
);
if
(
isset
(
$config
[
'unbound'
][
'enable'
]))
{
if
(
isset
(
$config
[
'unbound'
][
'enable'
]))
{
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"Starting DNS Resolver..."
);
echo
gettext
(
"Starting DNS Resolver..."
);
else
}
else
{
sleep
(
1
);
sleep
(
1
);
}
sync_unbound_service
();
sync_unbound_service
();
system_dhcpleases_configure
();
system_dhcpleases_configure
();
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"done."
)
.
"
\n
"
;
echo
gettext
(
"done."
)
.
"
\n
"
;
}
}
}
if
(
!
file_exists
(
"/var/run/booting"
))
{
if
(
!
file_exists
(
"/var/run/booting"
))
{
if
(
services_dhcpd_configure
()
!=
0
)
if
(
services_dhcpd_configure
()
!=
0
)
{
$return
=
1
;
$return
=
1
;
}
}
}
return
$return
;
return
$return
;
}
}
...
@@ -1962,9 +2058,9 @@ function services_snmpd_configure()
...
@@ -1962,9 +2058,9 @@ function services_snmpd_configure()
}
}
if
(
isset
(
$config
[
'snmpd'
][
'enable'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'enable'
]))
{
if
(
file_exists
(
"/var/run/booting"
))
{
if
(
file_exists
(
"/var/run/booting"
))
echo
gettext
(
"Starting SNMP daemon... "
);
echo
gettext
(
"Starting SNMP daemon... "
);
}
/* generate snmpd.conf */
/* generate snmpd.conf */
$fd
=
fopen
(
"/var/etc/snmpd.conf"
,
"w"
);
$fd
=
fopen
(
"/var/etc/snmpd.conf"
,
"w"
);
...
@@ -1992,7 +2088,7 @@ EOD;
...
@@ -1992,7 +2088,7 @@ EOD;
*/
*/
if
(
isset
(
$config
[
'snmpd'
][
'trapenable'
])
&&
preg_match
(
'/^\S+$/'
,
$config
[
'snmpd'
][
'trapserver'
])){
if
(
isset
(
$config
[
'snmpd'
][
'trapenable'
])
&&
preg_match
(
'/^\S+$/'
,
$config
[
'snmpd'
][
'trapserver'
])){
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
# SNMP Trap support.
# SNMP Trap support.
traphost := {$config['snmpd']['trapserver']}
traphost := {$config['snmpd']['trapserver']}
...
@@ -2029,7 +2125,7 @@ EOD;
...
@@ -2029,7 +2125,7 @@ EOD;
*/
*/
if
(
isset
(
$config
[
'snmpd'
][
'trapenable'
])
&&
preg_match
(
'/^\S+$/'
,
$config
[
'snmpd'
][
'trapserver'
])){
if
(
isset
(
$config
[
'snmpd'
][
'trapenable'
])
&&
preg_match
(
'/^\S+$/'
,
$config
[
'snmpd'
][
'trapserver'
])){
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4
begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4
begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2
begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2
...
@@ -2049,17 +2145,18 @@ EOD;
...
@@ -2049,17 +2145,18 @@ EOD;
unset
(
$config
[
'snmpd'
][
'bindlan'
]);
unset
(
$config
[
'snmpd'
][
'bindlan'
]);
}
}
$bind_to_ip
=
"0.0.0.0"
;
$bind_to_ip
=
"0.0.0.0"
;
if
(
isset
(
$config
[
'snmpd'
][
'bindip'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'bindip'
]))
{
if
(
is_ipaddr
(
$config
[
'snmpd'
][
'bindip'
]))
{
if
(
is_ipaddr
(
$config
[
'snmpd'
][
'bindip'
]))
{
$bind_to_ip
=
$config
[
'snmpd'
][
'bindip'
];
$bind_to_ip
=
$config
[
'snmpd'
][
'bindip'
];
}
else
{
}
else
{
$if
=
get_real_interface
(
$config
[
'snmpd'
][
'bindip'
]);
$if
=
get_real_interface
(
$config
[
'snmpd'
][
'bindip'
]);
if
(
does_interface_exist
(
$if
))
if
(
does_interface_exist
(
$if
))
{
$bind_to_ip
=
find_interface_ip
(
$if
);
$bind_to_ip
=
find_interface_ip
(
$if
);
}
}
}
}
}
if
(
is_port
(
$config
[
'snmpd'
][
'pollport'
]
))
{
if
(
is_port
(
$config
[
'snmpd'
][
'pollport'
]
))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1
begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1
...
@@ -2081,14 +2178,14 @@ snmpEnableAuthenTraps = 2
...
@@ -2081,14 +2178,14 @@ snmpEnableAuthenTraps = 2
EOD;
EOD;
if
(
is_array
(
$config
[
'snmpd'
][
'modules'
]
))
{
if
(
is_array
(
$config
[
'snmpd'
][
'modules'
]
))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'mibii'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'mibii'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."mibII" = "/usr/lib/snmp_mibII.so"
begemotSnmpdModulePath."mibII" = "/usr/lib/snmp_mibII.so"
EOD;
EOD;
}
}
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'netgraph'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'netgraph'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"
begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"
%netgraph
%netgraph
...
@@ -2097,33 +2194,33 @@ begemotNgControlNodeName = "snmpd"
...
@@ -2097,33 +2194,33 @@ begemotNgControlNodeName = "snmpd"
EOD;
EOD;
}
}
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'pf'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'pf'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."pf" = "/usr/lib/snmp_pf.so"
begemotSnmpdModulePath."pf" = "/usr/lib/snmp_pf.so"
EOD;
EOD;
}
}
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'hostres'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'hostres'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so"
begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so"
EOD;
EOD;
}
}
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'bridge'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'bridge'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so"
begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so"
# config must end with blank line
# config must end with blank line
EOD;
EOD;
}
}
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'ucd'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'ucd'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
EOD;
EOD;
}
}
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'regex'
]))
{
if
(
isset
(
$config
[
'snmpd'
][
'modules'
][
'regex'
]))
{
$snmpdconf
.=
<<<EOD
$snmpdconf
.=
<<<EOD
begemotSnmpdModulePath."regex" = "/usr/local/lib/snmp_regex.so"
begemotSnmpdModulePath."regex" = "/usr/local/lib/snmp_regex.so"
...
@@ -2143,9 +2240,10 @@ EOD;
...
@@ -2143,9 +2240,10 @@ EOD;
mwexec
(
"/usr/sbin/bsnmpd -c /var/etc/snmpd.conf"
.
mwexec
(
"/usr/sbin/bsnmpd -c /var/etc/snmpd.conf"
.
"
{
$bindlan
}
-p /var/run/snmpd.pid"
);
"
{
$bindlan
}
-p /var/run/snmpd.pid"
);
if
(
file_exists
(
"/var/run/booting"
))
if
(
file_exists
(
"/var/run/booting"
))
{
echo
gettext
(
"done."
)
.
"
\n
"
;
echo
gettext
(
"done."
)
.
"
\n
"
;
}
}
}
return
0
;
return
0
;
}
}
...
@@ -2158,20 +2256,22 @@ function services_dnsupdate_process($int = '', $updatehost = '', $forced = false
...
@@ -2158,20 +2256,22 @@ function services_dnsupdate_process($int = '', $updatehost = '', $forced = false
if
(
isset
(
$config
[
'dnsupdates'
][
'dnsupdate'
])
&&
is_array
(
$config
[
'dnsupdates'
][
'dnsupdate'
]))
{
if
(
isset
(
$config
[
'dnsupdates'
][
'dnsupdate'
])
&&
is_array
(
$config
[
'dnsupdates'
][
'dnsupdate'
]))
{
$notify_text
=
""
;
$notify_text
=
""
;
foreach
(
$config
[
'dnsupdates'
][
'dnsupdate'
]
as
$i
=>
$dnsupdate
)
{
foreach
(
$config
[
'dnsupdates'
][
'dnsupdate'
]
as
$i
=>
$dnsupdate
)
{
if
(
!
isset
(
$dnsupdate
[
'enable'
]))
if
(
!
isset
(
$dnsupdate
[
'enable'
]))
{
continue
;
continue
;
if
(
!
empty
(
$int
)
&&
$int
!=
$dnsupdate
[
'interface'
])
}
elseif
(
!
empty
(
$int
)
&&
$int
!=
$dnsupdate
[
'interface'
])
{
continue
;
continue
;
if
(
!
empty
(
$updatehost
)
&&
(
$updatehost
!=
$dnsupdate
[
'host'
]))
}
elseif
(
!
empty
(
$updatehost
)
&&
(
$updatehost
!=
$dnsupdate
[
'host'
]))
{
continue
;
continue
;
}
/* determine interface name */
/* determine interface name */
$if
=
get_real_interface
(
$dnsupdate
[
'interface'
]);
$if
=
get_real_interface
(
$dnsupdate
[
'interface'
]);
if
(
isset
(
$dnsupdate
[
'usepublicip'
]))
if
(
isset
(
$dnsupdate
[
'usepublicip'
]))
{
$wanip
=
dyndnsCheckIP
(
$dnsupdate
[
'interface'
]);
$wanip
=
dyndnsCheckIP
(
$dnsupdate
[
'interface'
]);
else
}
else
{
$wanip
=
get_interface_ip
(
$dnsupdate
[
'interface'
]);
$wanip
=
get_interface_ip
(
$dnsupdate
[
'interface'
]);
}
$wanipv6
=
get_interface_ipv6
(
$dnsupdate
[
'interface'
]);
$wanipv6
=
get_interface_ipv6
(
$dnsupdate
[
'interface'
]);
$cacheFile
=
"/conf/dyndns_
{
$dnsupdate
[
'interface'
]
}
_rfc2136_"
.
escapeshellarg
(
$dnsupdate
[
'host'
])
.
"_
{
$dnsupdate
[
'server'
]
}
.cache"
;
$cacheFile
=
"/conf/dyndns_
{
$dnsupdate
[
'interface'
]
}
_rfc2136_"
.
escapeshellarg
(
$dnsupdate
[
'host'
])
.
"_
{
$dnsupdate
[
'server'
]
}
.cache"
;
...
@@ -2180,13 +2280,15 @@ function services_dnsupdate_process($int = '', $updatehost = '', $forced = false
...
@@ -2180,13 +2280,15 @@ function services_dnsupdate_process($int = '', $updatehost = '', $forced = false
if
(
$wanip
||
$wanipv6
)
{
if
(
$wanip
||
$wanipv6
)
{
$keyname
=
$dnsupdate
[
'keyname'
];
$keyname
=
$dnsupdate
[
'keyname'
];
/* trailing dot */
/* trailing dot */
if
(
substr
(
$keyname
,
-
1
)
!=
"."
)
if
(
substr
(
$keyname
,
-
1
)
!=
"."
)
{
$keyname
.=
"."
;
$keyname
.=
"."
;
}
$hostname
=
$dnsupdate
[
'host'
];
$hostname
=
$dnsupdate
[
'host'
];
/* trailing dot */
/* trailing dot */
if
(
substr
(
$hostname
,
-
1
)
!=
"."
)
if
(
substr
(
$hostname
,
-
1
)
!=
"."
)
{
$hostname
.=
"."
;
$hostname
.=
"."
;
}
/* write private key file
/* write private key file
this is dumb - public and private keys are the same for HMAC-MD5,
this is dumb - public and private keys are the same for HMAC-MD5,
...
@@ -2219,8 +2321,9 @@ EOD;
...
@@ -2219,8 +2321,9 @@ EOD;
/* generate update instructions */
/* generate update instructions */
$upinst
=
""
;
$upinst
=
""
;
if
(
!
empty
(
$dnsupdate
[
'server'
]))
if
(
!
empty
(
$dnsupdate
[
'server'
]))
{
$upinst
.=
"server
{
$dnsupdate
[
'server'
]
}
\n
"
;
$upinst
.=
"server
{
$dnsupdate
[
'server'
]
}
\n
"
;
}
if
(
file_exists
(
$cacheFile
))
{
if
(
file_exists
(
$cacheFile
))
{
list
(
$cachedipv4
,
$cacheTimev4
)
=
explode
(
"|"
,
file_get_contents
(
$cacheFile
));
list
(
$cachedipv4
,
$cacheTimev4
)
=
explode
(
"|"
,
file_get_contents
(
$cacheFile
));
...
@@ -2245,8 +2348,9 @@ EOD;
...
@@ -2245,8 +2348,9 @@ EOD;
}
else
{
}
else
{
log_error
(
"Dynamic DNS: Not updating
{
$dnsupdate
[
'host'
]
}
A record because the IP address has not changed."
);
log_error
(
"Dynamic DNS: Not updating
{
$dnsupdate
[
'host'
]
}
A record because the IP address has not changed."
);
}
}
}
else
}
else
{
@
unlink
(
$cacheFile
);
@
unlink
(
$cacheFile
);
}
/* Update IPv6 if we have it. */
/* Update IPv6 if we have it. */
if
(
is_ipaddrv6
(
$wanipv6
))
{
if
(
is_ipaddrv6
(
$wanipv6
))
{
...
@@ -2260,8 +2364,9 @@ EOD;
...
@@ -2260,8 +2364,9 @@ EOD;
}
else
{
}
else
{
log_error
(
"Dynamic DNS: Not updating
{
$dnsupdate
[
'host'
]
}
AAAA record because the IPv6 address has not changed."
);
log_error
(
"Dynamic DNS: Not updating
{
$dnsupdate
[
'host'
]
}
AAAA record because the IPv6 address has not changed."
);
}
}
}
else
}
else
{
@
unlink
(
"
{
$cacheFile
}
.ipv6"
);
@
unlink
(
"
{
$cacheFile
}
.ipv6"
);
}
$upinst
.=
"
\n
"
;
/* mind that trailing newline! */
$upinst
.=
"
\n
"
;
/* mind that trailing newline! */
...
@@ -2347,8 +2452,9 @@ function upnp_action($action)
...
@@ -2347,8 +2452,9 @@ function upnp_action($action)
break
;
break
;
case
"stop"
:
case
"stop"
:
killbypid
(
'/var/run/miniupnpd.pid'
);
killbypid
(
'/var/run/miniupnpd.pid'
);
while
((
int
)
exec
(
"/bin/pgrep -a miniupnpd | wc -l"
)
>
0
)
while
((
int
)
exec
(
"/bin/pgrep -a miniupnpd | wc -l"
)
>
0
)
{
mwexec
(
'killall miniupnpd 2>/dev/null'
,
true
);
mwexec
(
'killall miniupnpd 2>/dev/null'
,
true
);
}
mwexec
(
'/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null'
);
mwexec
(
'/sbin/pfctl -aminiupnpd -Fr 2>&1 >/dev/null'
);
mwexec
(
'/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null'
);
mwexec
(
'/sbin/pfctl -aminiupnpd -Fn 2>&1 >/dev/null'
);
break
;
break
;
...
@@ -2376,21 +2482,23 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
...
@@ -2376,21 +2482,23 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
$is_installed
=
false
;
$is_installed
=
false
;
if
(
!
is_array
(
$config
[
'cron'
]))
if
(
!
is_array
(
$config
[
'cron'
]))
{
$config
[
'cron'
]
=
array
();
$config
[
'cron'
]
=
array
();
if
(
!
is_array
(
$config
[
'cron'
][
'item'
]))
}
if
(
!
is_array
(
$config
[
'cron'
][
'item'
]))
{
$config
[
'cron'
][
'item'
]
=
array
();
$config
[
'cron'
][
'item'
]
=
array
();
}
$x
=
0
;
$x
=
0
;
foreach
(
$config
[
'cron'
][
'item'
]
as
$item
)
{
foreach
(
$config
[
'cron'
][
'item'
]
as
$item
)
{
if
(
strstr
(
$item
[
'command'
],
$command
))
{
if
(
strstr
(
$item
[
'command'
],
$command
))
{
$is_installed
=
true
;
$is_installed
=
true
;
break
;
break
;
}
}
$x
++
;
$x
++
;
}
}
if
(
$active
)
{
if
(
$active
)
{
$cron_item
=
array
();
$cron_item
=
array
();
$cron_item
[
'minute'
]
=
$minute
;
$cron_item
[
'minute'
]
=
$minute
;
$cron_item
[
'hour'
]
=
$hour
;
$cron_item
[
'hour'
]
=
$hour
;
...
@@ -2399,7 +2507,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
...
@@ -2399,7 +2507,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
$cron_item
[
'wday'
]
=
$weekday
;
$cron_item
[
'wday'
]
=
$weekday
;
$cron_item
[
'who'
]
=
$who
;
$cron_item
[
'who'
]
=
$who
;
$cron_item
[
'command'
]
=
$command
;
$cron_item
[
'command'
]
=
$command
;
if
(
!
$is_installed
)
{
if
(
!
$is_installed
)
{
$config
[
'cron'
][
'item'
][]
=
$cron_item
;
$config
[
'cron'
][
'item'
][]
=
$cron_item
;
write_config
(
sprintf
(
gettext
(
"Installed cron job for %s"
),
$command
));
write_config
(
sprintf
(
gettext
(
"Installed cron job for %s"
),
$command
));
}
else
{
}
else
{
...
@@ -2407,7 +2515,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
...
@@ -2407,7 +2515,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
write_config
(
sprintf
(
gettext
(
"Updated cron job for %s"
),
$command
));
write_config
(
sprintf
(
gettext
(
"Updated cron job for %s"
),
$command
));
}
}
}
else
{
}
else
{
if
(
$is_installed
==
true
)
{
if
(
$is_installed
==
true
)
{
unset
(
$config
[
'cron'
][
'item'
][
$x
]);
unset
(
$config
[
'cron'
][
'item'
][
$x
]);
write_config
(
sprintf
(
gettext
(
"Removed cron job for %s"
),
$command
));
write_config
(
sprintf
(
gettext
(
"Removed cron job for %s"
),
$command
));
}
}
...
@@ -2474,9 +2582,10 @@ function get_services() {
...
@@ -2474,9 +2582,10 @@ function get_services() {
$ifdescrs
=
get_configured_interface_list
();
$ifdescrs
=
get_configured_interface_list
();
foreach
(
$ifdescrs
as
$if
)
{
foreach
(
$ifdescrs
as
$if
)
{
$oc
=
$config
[
'interfaces'
][
$if
];
$oc
=
$config
[
'interfaces'
][
$if
];
if
(
$oc
[
'if'
]
&&
(
!
link_interface_to_bridge
(
$if
)))
if
(
$oc
[
'if'
]
&&
(
!
link_interface_to_bridge
(
$if
)))
{
$iflist
[
$if
]
=
$if
;
$iflist
[
$if
]
=
$if
;
}
}
}
if
(
isset
(
$config
[
'dhcrelay'
][
'enable'
]))
{
if
(
isset
(
$config
[
'dhcrelay'
][
'enable'
]))
{
$pconfig
=
array
();
$pconfig
=
array
();
...
@@ -2577,16 +2686,19 @@ function get_services() {
...
@@ -2577,16 +2686,19 @@ function get_services() {
function
find_service_by_openvpn_vpnid
(
$vpnid
)
{
function
find_service_by_openvpn_vpnid
(
$vpnid
)
{
$services
=
get_services
();
$services
=
get_services
();
foreach
(
$services
as
$service
)
foreach
(
$services
as
$service
)
{
if
((
$service
[
"name"
]
==
"openvpn"
)
&&
isset
(
$service
[
"vpnid"
])
&&
(
$service
[
"vpnid"
]
==
$vpnid
))
if
((
$service
[
"name"
]
==
"openvpn"
)
&&
isset
(
$service
[
"vpnid"
])
&&
(
$service
[
"vpnid"
]
==
$vpnid
))
{
return
$service
;
return
$service
;
}
}
return
array
();
return
array
();
}
}
function
service_name_compare
(
$a
,
$b
)
{
function
service_name_compare
(
$a
,
$b
)
{
if
(
strtolower
(
$a
[
'name'
])
==
strtolower
(
$b
[
'name'
]))
if
(
strtolower
(
$a
[
'name'
])
==
strtolower
(
$b
[
'name'
]))
{
return
0
;
return
0
;
}
return
(
strtolower
(
$a
[
'name'
])
<
strtolower
(
$b
[
'name'
]))
?
-
1
:
1
;
return
(
strtolower
(
$a
[
'name'
])
<
strtolower
(
$b
[
'name'
]))
?
-
1
:
1
;
}
}
...
@@ -2618,7 +2730,7 @@ function get_service_status($service)
...
@@ -2618,7 +2730,7 @@ function get_service_status($service)
function
get_service_status_icon
(
$service
,
$withtext
=
true
,
$smallicon
=
false
)
function
get_service_status_icon
(
$service
,
$withtext
=
true
,
$smallicon
=
false
)
{
{
$output
=
""
;
$output
=
""
;
if
(
get_service_status
(
$service
))
{
if
(
get_service_status
(
$service
))
{
$statustext
=
gettext
(
"Running"
);
$statustext
=
gettext
(
"Running"
);
$output
.=
'<span class="btn btn-success"><span class="glyphicon glyphicon-play" title="'
.
sprintf
(
gettext
(
'%s Service is'
),
$service
[
'name'
])
.
' '
.
$statustext
.
'" data-toggle="tooltip" data-placement="bottom" ></span></span> '
;
$output
.=
'<span class="btn btn-success"><span class="glyphicon glyphicon-play" title="'
.
sprintf
(
gettext
(
'%s Service is'
),
$service
[
'name'
])
.
' '
.
$statustext
.
'" data-toggle="tooltip" data-placement="bottom" ></span></span> '
;
}
else
{
}
else
{
...
@@ -2632,7 +2744,7 @@ function get_service_control_links($service, $addname = false)
...
@@ -2632,7 +2744,7 @@ function get_service_control_links($service, $addname = false)
{
{
$output
=
""
;
$output
=
""
;
$stitle
=
(
$addname
)
?
$service
[
'name'
]
.
" "
:
""
;
$stitle
=
(
$addname
)
?
$service
[
'name'
]
.
" "
:
""
;
if
(
get_service_status
(
$service
))
{
if
(
get_service_status
(
$service
))
{
switch
(
$service
[
'name'
])
{
switch
(
$service
[
'name'
])
{
case
"openvpn"
:
case
"openvpn"
:
$output
.=
"<a href='status_services.php?mode=restartservice&service=
{
$service
[
'name'
]
}
&vpnmode=
{
$service
[
'mode'
]
}
&id=
{
$service
[
'vpnid'
]
}
' class=
\"
btn btn-default
\"
>"
;
$output
.=
"<a href='status_services.php?mode=restartservice&service=
{
$service
[
'name'
]
}
&vpnmode=
{
$service
[
'mode'
]
}
&id=
{
$service
[
'vpnid'
]
}
' class=
\"
btn btn-default
\"
>"
;
...
@@ -2678,38 +2790,46 @@ function is_radvd_enabled() {
...
@@ -2678,38 +2790,46 @@ function is_radvd_enabled() {
/* handle manually configured DHCP6 server settings first */
/* handle manually configured DHCP6 server settings first */
foreach
(
$dhcpdv6cfg
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
foreach
(
$dhcpdv6cfg
as
$dhcpv6if
=>
$dhcpv6ifconf
)
{
if
(
!
isset
(
$config
[
'interfaces'
][
$dhcpv6if
][
'enable'
]))
if
(
!
isset
(
$config
[
'interfaces'
][
$dhcpv6if
][
'enable'
]))
{
continue
;
continue
;
}
if
(
!
isset
(
$dhcpv6ifconf
[
'ramode'
]))
if
(
!
isset
(
$dhcpv6ifconf
[
'ramode'
]))
{
$dhcpv6ifconf
[
'ramode'
]
=
$dhcpv6ifconf
[
'mode'
];
$dhcpv6ifconf
[
'ramode'
]
=
$dhcpv6ifconf
[
'mode'
];
}
if
(
$dhcpv6ifconf
[
'ramode'
]
==
"disabled"
)
if
(
$dhcpv6ifconf
[
'ramode'
]
==
"disabled"
)
{
continue
;
continue
;
}
$ifcfgipv6
=
get_interface_ipv6
(
$dhcpv6if
);
$ifcfgipv6
=
get_interface_ipv6
(
$dhcpv6if
);
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
{
continue
;
continue
;
}
return
true
;
return
true
;
}
}
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
/* handle DHCP-PD prefixes and 6RD dynamic interfaces */
foreach
(
$Iflist
as
$if
=>
$ifdescr
)
{
foreach
(
$Iflist
as
$if
=>
$ifdescr
)
{
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'track6-interface'
]))
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'track6-interface'
]))
{
continue
;
continue
;
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'enable'
]))
}
if
(
!
isset
(
$config
[
'interfaces'
][
$if
][
'enable'
]))
{
continue
;
continue
;
}
$ifcfgipv6
=
get_interface_ipv6
(
$if
);
$ifcfgipv6
=
get_interface_ipv6
(
$if
);
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
if
(
!
is_ipaddrv6
(
$ifcfgipv6
))
{
continue
;
continue
;
}
$ifcfgsnv6
=
get_interface_subnetv6
(
$if
);
$ifcfgsnv6
=
get_interface_subnetv6
(
$if
);
$subnetv6
=
gen_subnetv6
(
$ifcfgipv6
,
$ifcfgsnv6
);
$subnetv6
=
gen_subnetv6
(
$ifcfgipv6
,
$ifcfgsnv6
);
if
(
!
is_ipaddrv6
(
$subnetv6
))
if
(
!
is_ipaddrv6
(
$subnetv6
))
{
continue
;
continue
;
}
return
true
;
return
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