2004-11-07 04:06:49 +01:00
|
|
|
<?php
|
2005-03-28 00:43:48 +02:00
|
|
|
/* $Id$ */
|
2004-11-07 04:06:49 +01:00
|
|
|
/*
|
|
|
|
system.inc
|
|
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
|
|
|
All rights reserved.
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer.
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2009-09-12 21:34:07 +02:00
|
|
|
/*
|
2014-07-08 01:06:37 +02:00
|
|
|
pfSense_BUILDER_BINARIES: /usr/sbin/powerd /usr/bin/killall /sbin/route
|
2011-07-25 19:56:25 +02:00
|
|
|
pfSense_BUILDER_BINARIES: /bin/hostname /bin/ls /usr/sbin/syslogd
|
2009-09-12 21:34:07 +02:00
|
|
|
pfSense_BUILDER_BINARIES: /usr/sbin/pccardd /usr/local/sbin/lighttpd /bin/chmod /bin/mkdir
|
2014-01-15 18:35:50 +01:00
|
|
|
pfSense_BUILDER_BINARIES: /usr/bin/tar /usr/local/sbin/ntpd /usr/local/sbin/ntpdate
|
2010-06-29 17:26:31 +02:00
|
|
|
pfSense_BUILDER_BINARIES: /usr/bin/nohup /sbin/dmesg /usr/local/sbin/atareinit /sbin/kldload
|
2013-05-27 12:23:55 +02:00
|
|
|
pfSense_BUILDER_BINARIES: /usr/local/sbin/filterdns
|
2009-09-12 21:34:07 +02:00
|
|
|
pfSense_MODULE: utils
|
|
|
|
*/
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2009-04-05 21:38:00 +02:00
|
|
|
function activate_powerd() {
|
|
|
|
global $config, $g;
|
2011-08-17 04:15:18 +02:00
|
|
|
if ($g['platform'] == 'jail')
|
|
|
|
return;
|
2012-04-11 03:12:30 +02:00
|
|
|
if(is_process_running("powerd"))
|
|
|
|
exec("/usr/bin/killall powerd");
|
2009-04-05 21:38:00 +02:00
|
|
|
if(isset($config['system']['powerd_enable'])) {
|
2010-06-29 17:26:31 +02:00
|
|
|
if ($g["platform"] == "nanobsd")
|
|
|
|
exec("/sbin/kldload cpufreq");
|
2013-02-09 02:09:42 +01:00
|
|
|
|
|
|
|
$ac_mode = "hadp";
|
|
|
|
if (!empty($config['system']['powerd_ac_mode']))
|
|
|
|
$ac_mode = $config['system']['powerd_ac_mode'];
|
|
|
|
|
|
|
|
$battery_mode = "hadp";
|
|
|
|
if (!empty($config['system']['powerd_battery_mode']))
|
|
|
|
$battery_mode = $config['system']['powerd_battery_mode'];
|
|
|
|
|
2014-10-06 00:35:08 +02:00
|
|
|
$normal_mode = "hadp";
|
|
|
|
if (!empty($config['system']['powerd_normal_mode']))
|
|
|
|
$normal_mode = $config['system']['powerd_normal_mode'];
|
|
|
|
|
|
|
|
mwexec("/usr/sbin/powerd -b $battery_mode -a $ac_mode -n $normal_mode");
|
2009-04-05 21:38:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-20 23:57:14 +01:00
|
|
|
function get_default_sysctl_value($id) {
|
|
|
|
global $sysctls;
|
2010-11-29 03:19:27 +01:00
|
|
|
|
|
|
|
if (isset($sysctls[$id]))
|
|
|
|
return $sysctls[$id];
|
2010-01-20 23:57:14 +01:00
|
|
|
}
|
|
|
|
|
2007-05-27 00:00:36 +02:00
|
|
|
function activate_sysctls() {
|
|
|
|
global $config, $g;
|
2014-07-08 01:06:37 +02:00
|
|
|
|
2011-08-17 04:15:18 +02:00
|
|
|
if ($g['platform'] == 'jail')
|
|
|
|
return;
|
2014-07-08 01:06:37 +02:00
|
|
|
|
|
|
|
$sysctls = array(
|
|
|
|
"net.enc.out.ipsec_bpf_mask" => "0x0001",
|
|
|
|
"net.enc.out.ipsec_filter_mask" => "0x0001",
|
|
|
|
"net.enc.in.ipsec_bpf_mask" => "0x0002",
|
|
|
|
"net.enc.in.ipsec_filter_mask" => "0x0002"
|
|
|
|
);
|
2008-11-04 23:47:03 +01:00
|
|
|
|
2010-01-20 23:57:14 +01:00
|
|
|
if(is_array($config['sysctl'])) {
|
2010-01-20 23:33:36 +01:00
|
|
|
foreach($config['sysctl']['item'] as $tunable) {
|
2014-07-08 01:06:37 +02:00
|
|
|
if($tunable['value'] == "default")
|
2010-01-20 23:13:17 +01:00
|
|
|
$value = get_default_sysctl_value($tunable['tunable']);
|
2014-07-08 01:06:37 +02:00
|
|
|
else
|
|
|
|
$value = $tunable['value'];
|
|
|
|
|
|
|
|
$sysctls[$tunable['tunable']] = $value;
|
2009-12-06 06:48:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-08 01:06:37 +02:00
|
|
|
|
|
|
|
set_sysctl($sysctls);
|
2007-05-27 00:00:36 +02:00
|
|
|
}
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
function system_resolvconf_generate($dynupdate = false) {
|
2008-11-12 00:26:10 +01:00
|
|
|
global $config, $g;
|
|
|
|
|
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
echo "system_resolvconf_generate() being called $mt\n";
|
|
|
|
}
|
2005-08-24 22:31:49 +02:00
|
|
|
|
2009-10-26 02:47:22 +01:00
|
|
|
$syscfg = $config['system'];
|
2005-08-24 22:31:49 +02:00
|
|
|
|
2014-04-23 16:14:59 +02:00
|
|
|
if (((isset($config['dnsmasq']['enable']) && (empty($config['dnsmasq']['interface']) || in_array("lo0", explode(",", $config['dnsmasq']['interface']))))
|
|
|
|
|| (isset($config['unbound']['enable'])) && (empty($config['unbound']['active_interface']) || in_array("lo0", explode(",", $config['unbound']['active_interface']))))
|
|
|
|
&& !isset($config['system']['dnslocalhost']))
|
2011-08-12 13:46:58 +02:00
|
|
|
$resolvconf .= "nameserver 127.0.0.1\n";
|
2011-08-08 19:15:52 +02:00
|
|
|
|
2009-10-26 02:47:22 +01:00
|
|
|
if (isset($syscfg['dnsallowoverride'])) {
|
2008-11-12 00:26:10 +01:00
|
|
|
/* get dynamically assigned DNS servers (if any) */
|
2010-09-17 00:42:22 +02:00
|
|
|
$ns = array_unique(get_searchdomains());
|
|
|
|
foreach($ns as $searchserver) {
|
2011-08-08 19:19:13 +02:00
|
|
|
if($searchserver)
|
2010-09-17 00:42:22 +02:00
|
|
|
$resolvconf .= "search {$searchserver}\n";
|
|
|
|
}
|
2008-11-12 00:26:10 +01:00
|
|
|
$ns = array_unique(get_nameservers());
|
|
|
|
foreach($ns as $nameserver) {
|
2011-08-08 19:19:13 +02:00
|
|
|
if($nameserver)
|
2008-11-12 00:26:10 +01:00
|
|
|
$resolvconf .= "nameserver $nameserver\n";
|
|
|
|
}
|
2014-10-26 04:09:37 +01:00
|
|
|
} else {
|
|
|
|
// Do not create blank search/domain lines, it can break tools like dig.
|
|
|
|
if($syscfg['domain'])
|
|
|
|
$resolvconf = "search {$syscfg['domain']}\n";
|
2009-10-26 02:47:22 +01:00
|
|
|
}
|
2011-08-08 19:19:13 +02:00
|
|
|
if (is_array($syscfg['dnsserver'])) {
|
2008-11-12 00:26:10 +01:00
|
|
|
foreach ($syscfg['dnsserver'] as $ns) {
|
2011-08-08 19:19:13 +02:00
|
|
|
if ($ns)
|
2008-11-12 00:26:10 +01:00
|
|
|
$resolvconf .= "nameserver $ns\n";
|
2007-12-09 00:05:08 +01:00
|
|
|
}
|
2008-11-12 00:26:10 +01:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2014-01-29 16:06:42 +01:00
|
|
|
// Add EDNS support
|
|
|
|
if (isset($config['unbound']['enable']) && isset($config['unbound']['edns']))
|
|
|
|
$resolvconf .= "options edns0\n";
|
|
|
|
|
2011-05-30 15:11:03 +02:00
|
|
|
$dnslock = lock('resolvconf', LOCK_EX);
|
|
|
|
|
2011-01-03 22:49:24 +01:00
|
|
|
$fd = fopen("{$g['varetc_path']}/resolv.conf", "w");
|
|
|
|
if (!$fd) {
|
|
|
|
printf("Error: cannot open resolv.conf in system_resolvconf_generate().\n");
|
2011-05-30 15:11:03 +02:00
|
|
|
unlock($dnslock);
|
2011-01-03 22:49:24 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-10-26 02:47:22 +01:00
|
|
|
fwrite($fd, $resolvconf);
|
|
|
|
fclose($fd);
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2009-10-26 02:47:22 +01:00
|
|
|
if (!$g['booting']) {
|
2008-11-12 00:26:10 +01:00
|
|
|
/* restart dhcpd (nameservers may have changed) */
|
|
|
|
if (!$dynupdate)
|
|
|
|
services_dhcpd_configure();
|
2009-10-26 02:47:22 +01:00
|
|
|
}
|
2005-08-24 22:31:49 +02:00
|
|
|
|
2008-11-12 00:26:10 +01:00
|
|
|
/* setup static routes for DNS servers. */
|
|
|
|
for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
|
|
|
|
/* setup static routes for dns servers */
|
2011-08-24 10:51:03 +02:00
|
|
|
$dnsgw = "dns{$dnscounter}gw";
|
2008-11-12 00:26:10 +01:00
|
|
|
if (isset($config['system'][$dnsgw])) {
|
2011-08-24 10:51:03 +02:00
|
|
|
$gwname = $config['system'][$dnsgw];
|
|
|
|
if (($gwname <> "") && ($gwname <> "none")) {
|
|
|
|
$gatewayip = lookup_gateway_ip_by_name($gwname);
|
|
|
|
if (is_ipaddrv4($gatewayip)) {
|
2008-11-12 00:26:10 +01:00
|
|
|
/* dns server array starts at 0 */
|
2007-12-09 07:09:10 +01:00
|
|
|
$dnscountermo = $dnscounter - 1;
|
2013-06-17 09:44:53 +02:00
|
|
|
mwexec("/sbin/route change -host " . $syscfg['dnsserver'][$dnscountermo] . " {$gatewayip}");
|
2014-11-07 03:19:24 +01:00
|
|
|
if (isset($config['system']['route-debug'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
log_error("ROUTING debug: $mt - route change -host {$syscfg['dnsserver'][$dnscountermo]} $gatewayip ");
|
|
|
|
}
|
2007-12-09 07:09:10 +01:00
|
|
|
}
|
2011-08-24 10:51:03 +02:00
|
|
|
if (is_ipaddrv6($gatewayip)) {
|
|
|
|
/* dns server array starts at 0 */
|
|
|
|
$dnscountermo = $dnscounter - 1;
|
2013-06-17 09:44:53 +02:00
|
|
|
mwexec("/sbin/route change -host -inet6 " . $syscfg['dnsserver'][$dnscountermo] . " {$gatewayip}");
|
2014-11-07 03:19:24 +01:00
|
|
|
if (isset($config['system']['route-debug'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
log_error("ROUTING debug: $mt - route change -host -inet6 {$syscfg['dnsserver'][$dnscountermo]} $gatewayip ");
|
|
|
|
}
|
2011-08-24 10:51:03 +02:00
|
|
|
}
|
2007-12-09 07:09:10 +01:00
|
|
|
}
|
2007-12-09 00:05:08 +01:00
|
|
|
}
|
2008-11-12 00:26:10 +01:00
|
|
|
}
|
2011-05-30 15:11:03 +02:00
|
|
|
|
|
|
|
unlock($dnslock);
|
|
|
|
|
2008-11-12 00:26:10 +01:00
|
|
|
return 0;
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
2010-09-17 00:42:22 +02:00
|
|
|
function get_searchdomains() {
|
|
|
|
global $config, $g;
|
|
|
|
|
|
|
|
$master_list = array();
|
|
|
|
|
|
|
|
// Read in dhclient nameservers
|
2011-01-03 22:49:24 +01:00
|
|
|
$search_list = glob("/var/etc/searchdomain_*");
|
2014-01-28 20:01:02 +01:00
|
|
|
if (is_array($search_list)) {
|
|
|
|
foreach($search_list as $fdns) {
|
2011-01-04 19:32:52 +01:00
|
|
|
$contents = file($fdns, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
if (!is_array($contents))
|
|
|
|
continue;
|
|
|
|
foreach ($contents as $dns) {
|
|
|
|
if(is_hostname($dns))
|
|
|
|
$master_list[] = $dns;
|
|
|
|
}
|
2010-09-17 00:42:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $master_list;
|
|
|
|
}
|
|
|
|
|
2005-12-04 19:32:28 +01:00
|
|
|
function get_nameservers() {
|
|
|
|
global $config, $g;
|
|
|
|
$master_list = array();
|
2009-10-26 02:47:22 +01:00
|
|
|
|
2009-10-26 03:03:18 +01:00
|
|
|
// Read in dhclient nameservers
|
2011-01-03 22:49:24 +01:00
|
|
|
$dns_lists = glob("/var/etc/nameserver_*");
|
2010-03-23 22:13:32 +01:00
|
|
|
if (is_array($dns_lists)) {
|
2011-01-04 19:32:52 +01:00
|
|
|
foreach($dns_lists as $fdns) {
|
|
|
|
$contents = file($fdns, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
if (!is_array($contents))
|
|
|
|
continue;
|
|
|
|
foreach ($contents as $dns) {
|
|
|
|
if(is_ipaddr($dns))
|
|
|
|
$master_list[] = $dns;
|
|
|
|
}
|
2009-03-08 20:27:34 +01:00
|
|
|
}
|
2005-12-04 19:32:28 +01:00
|
|
|
}
|
2009-10-26 03:03:18 +01:00
|
|
|
|
|
|
|
// Read in any extra nameservers
|
|
|
|
if(file_exists("/var/etc/nameservers.conf")) {
|
2011-01-03 22:51:47 +01:00
|
|
|
$dns_s = file("/var/etc/nameservers.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
2011-01-03 22:49:24 +01:00
|
|
|
if(is_array($dns_s)) {
|
2009-10-26 03:03:18 +01:00
|
|
|
foreach($dns_s as $dns)
|
2010-03-23 22:13:32 +01:00
|
|
|
if (is_ipaddr($dns))
|
|
|
|
$master_list[] = $dns;
|
2011-01-03 22:49:24 +01:00
|
|
|
}
|
2009-10-26 03:03:18 +01:00
|
|
|
}
|
|
|
|
|
2005-12-04 19:32:28 +01:00
|
|
|
return $master_list;
|
|
|
|
}
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
function system_hosts_generate() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2014-04-28 22:00:25 +02:00
|
|
|
if (isset($config['system']['developerspew'])) {
|
2005-10-12 01:44:53 +02:00
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_hosts_generate() being called $mt\n";
|
2005-10-12 03:10:10 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
$syscfg = $config['system'];
|
|
|
|
$dnsmasqcfg = $config['dnsmasq'];
|
|
|
|
|
2010-11-08 23:42:27 +01:00
|
|
|
$hosts = "127.0.0.1 localhost localhost.{$syscfg['domain']}\n";
|
2011-07-12 05:35:14 +02:00
|
|
|
$lhosts = "";
|
|
|
|
$dhosts = "";
|
2009-03-30 02:37:45 +02:00
|
|
|
|
2010-05-04 00:22:51 +02:00
|
|
|
if ($config['interfaces']['lan']) {
|
|
|
|
$cfgip = get_interface_ip("lan");
|
2010-03-24 16:48:11 +01:00
|
|
|
if (is_ipaddr($cfgip))
|
|
|
|
$hosts .= "{$cfgip} {$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}\n";
|
2010-05-04 00:22:51 +02:00
|
|
|
} else {
|
|
|
|
$sysiflist = get_configured_interface_list();
|
|
|
|
foreach ($sysiflist as $sysif) {
|
|
|
|
if (!interface_has_gateway($sysif)) {
|
|
|
|
$cfgip = get_interface_ip($sysif);
|
|
|
|
if (is_ipaddr($cfgip)) {
|
|
|
|
$hosts .= "{$cfgip} {$syscfg['hostname']}.{$syscfg['domain']} {$syscfg['hostname']}\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-24 16:48:11 +01:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2013-05-05 02:19:17 +02:00
|
|
|
if (isset($dnsmasqcfg['enable'])) {
|
2013-05-01 18:09:04 +02:00
|
|
|
if (!is_array($dnsmasqcfg['hosts']))
|
|
|
|
$dnsmasqcfg['hosts'] = array();
|
|
|
|
|
|
|
|
foreach ($dnsmasqcfg['hosts'] as $host) {
|
|
|
|
if ($host['host'])
|
|
|
|
$lhosts .= "{$host['ip']} {$host['host']}.{$host['domain']} {$host['host']}\n";
|
2012-05-05 13:07:04 +02:00
|
|
|
else
|
2013-05-01 18:09:04 +02:00
|
|
|
$lhosts .= "{$host['ip']} {$host['domain']}\n";
|
|
|
|
if (!is_array($host['aliases']) || !is_array($host['aliases']['item']))
|
|
|
|
continue;
|
|
|
|
foreach ($host['aliases']['item'] as $alias) {
|
|
|
|
if ($alias['host'])
|
|
|
|
$lhosts .= "{$host['ip']} {$alias['host']}.{$alias['domain']} {$alias['host']}\n";
|
|
|
|
else
|
|
|
|
$lhosts .= "{$host['ip']} {$alias['domain']}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($dnsmasqcfg['regdhcpstatic']) && is_array($config['dhcpd'])) {
|
|
|
|
foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf)
|
|
|
|
if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
|
|
|
|
foreach ($dhcpifconf['staticmap'] as $host)
|
2013-07-30 07:48:00 +02:00
|
|
|
if ($host['ipaddr'] && $host['hostname'] && $host['domain'])
|
|
|
|
$dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
|
|
|
|
else if ($host['ipaddr'] && $host['hostname'] && $dhcpifconf['domain'])
|
|
|
|
$dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$dhcpifconf['domain']} {$host['hostname']}\n";
|
|
|
|
else if ($host['ipaddr'] && $host['hostname'])
|
2013-05-01 18:09:04 +02:00
|
|
|
$dhosts .= "{$host['ipaddr']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
|
|
|
|
}
|
|
|
|
if (isset($dnsmasqcfg['regdhcpstatic']) && is_array($config['dhcpdv6'])) {
|
|
|
|
foreach ($config['dhcpdv6'] as $dhcpif => $dhcpifconf)
|
|
|
|
if(is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
|
|
|
|
foreach ($dhcpifconf['staticmap'] as $host)
|
2013-07-30 07:48:00 +02:00
|
|
|
if ($host['ipaddrv6'] && $host['hostname'] && $host['domain'])
|
|
|
|
$dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$host['domain']} {$host['hostname']}\n";
|
|
|
|
else if ($host['ipaddrv6'] && $host['hostname'] && $dhcpifconf['domain'])
|
|
|
|
$dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$dhcpifconf['domain']} {$host['hostname']}\n";
|
|
|
|
else if ($host['ipaddrv6'] && $host['hostname'])
|
2013-05-01 18:09:04 +02:00
|
|
|
$dhosts .= "{$host['ipaddrv6']} {$host['hostname']}.{$syscfg['domain']} {$host['hostname']}\n";
|
2012-05-05 13:07:04 +02:00
|
|
|
}
|
2010-11-08 23:42:27 +01:00
|
|
|
|
2013-05-01 18:09:04 +02:00
|
|
|
if (isset($dnsmasqcfg['dhcpfirst']))
|
|
|
|
$hosts .= $dhosts . $lhosts;
|
|
|
|
else
|
|
|
|
$hosts .= $lhosts . $dhosts;
|
|
|
|
}
|
2011-07-12 05:35:14 +02:00
|
|
|
|
2010-11-08 23:42:27 +01:00
|
|
|
/*
|
|
|
|
* Do not remove this because dhcpleases monitors with kqueue it needs to be
|
|
|
|
* killed before writing to hosts files.
|
|
|
|
*/
|
|
|
|
if (file_exists("{$g['varrun_path']}/dhcpleases.pid")) {
|
|
|
|
sigkillbypid("{$g['varrun_path']}/dhcpleases.pid", "TERM");
|
2013-05-01 18:09:04 +02:00
|
|
|
@unlink("{$g['varrun_path']}/dhcpleases.pid");
|
2010-11-08 23:42:27 +01:00
|
|
|
}
|
|
|
|
$fd = fopen("{$g['varetc_path']}/hosts", "w");
|
|
|
|
if (!$fd) {
|
|
|
|
log_error("Error: cannot open hosts file in system_hosts_generate().\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2004-11-07 04:06:49 +01:00
|
|
|
fwrite($fd, $hosts);
|
|
|
|
fclose($fd);
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2014-04-28 22:36:48 +02:00
|
|
|
if (isset($config['unbound']['enable'])) {
|
|
|
|
require_once("unbound.inc");
|
2014-04-28 22:00:25 +02:00
|
|
|
unbound_hosts_generate();
|
2014-04-28 22:36:48 +02:00
|
|
|
}
|
2014-04-28 22:00:25 +02:00
|
|
|
|
2010-08-23 16:47:45 +02:00
|
|
|
system_dhcpleases_configure();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_dhcpleases_configure() {
|
2010-08-24 10:38:45 +02:00
|
|
|
global $config, $g;
|
|
|
|
|
2011-08-17 04:15:18 +02:00
|
|
|
if ($g['platform'] == 'jail')
|
|
|
|
return;
|
2010-06-04 17:57:08 +02:00
|
|
|
/* Start the monitoring process for dynamic dhcpclients. */
|
2014-04-28 22:00:25 +02:00
|
|
|
if ((isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcp']))
|
|
|
|
|| (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcp']))) {
|
2010-06-04 17:57:08 +02:00
|
|
|
/* Make sure we do not error out */
|
2013-01-26 12:59:53 +01:00
|
|
|
mwexec("/bin/mkdir -p {$g['dhcpd_chroot_path']}/var/db");
|
|
|
|
if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases"))
|
|
|
|
@touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases");
|
|
|
|
if (isvalidpid("{$g['varrun_path']}/dhcpleases.pid"))
|
|
|
|
sigkillbypid("{$g['varrun_path']}/dhcpleases.pid", "HUP");
|
2014-04-07 16:10:48 +02:00
|
|
|
else {
|
|
|
|
/* To ensure we do not start multiple instances of dhcpleases, perform some clean-up first. */
|
|
|
|
if (is_process_running("dhcpleases"))
|
|
|
|
mwexec('/bin/pkill dhcpleases');
|
|
|
|
@unlink("{$g['varrun_path']}/dhcpleases.pid");
|
2014-07-21 23:56:07 +02:00
|
|
|
if (isset($config['unbound']['enable']))
|
|
|
|
$dns_pid = "unbound.pid";
|
|
|
|
else
|
|
|
|
$dns_pid = "dnsmasq.pid";
|
|
|
|
mwexec("/usr/local/sbin/dhcpleases -l {$g['dhcpd_chroot_path']}/var/db/dhcpd.leases -d {$config['system']['domain']} -p {$g['varrun_path']}/{$dns_pid} -h {$g['varetc_path']}/hosts");
|
2014-04-07 16:10:48 +02:00
|
|
|
}
|
2010-08-24 10:38:45 +02:00
|
|
|
} else {
|
|
|
|
sigkillbypid("{$g['varrun_path']}/dhcpleases.pid", "TERM");
|
|
|
|
@unlink("{$g['varrun_path']}/dhcpleases.pid");
|
|
|
|
}
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function system_hostname_configure() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_hostname_configure() being called $mt\n";
|
2006-07-10 01:48:33 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
$syscfg = $config['system'];
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
/* set hostname */
|
2009-05-31 08:32:19 +02:00
|
|
|
$status = mwexec("/bin/hostname " .
|
2004-11-07 04:06:49 +01:00
|
|
|
escapeshellarg("{$syscfg['hostname']}.{$syscfg['domain']}"));
|
2009-05-31 08:32:19 +02:00
|
|
|
|
|
|
|
/* Setup host GUID ID. This is used by ZFS. */
|
|
|
|
mwexec("/etc/rc.d/hostid start");
|
|
|
|
|
|
|
|
return $status;
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
2010-06-18 20:46:06 +02:00
|
|
|
function system_routing_configure($interface = "") {
|
2010-05-21 22:45:57 +02:00
|
|
|
global $config, $g;
|
2011-08-17 04:15:18 +02:00
|
|
|
if ($g['platform'] == 'jail')
|
|
|
|
return;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_routing_configure() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2006-07-10 01:48:33 +02:00
|
|
|
|
2010-04-29 01:16:42 +02:00
|
|
|
$gatewayip = "";
|
|
|
|
$interfacegw = "";
|
2010-10-22 16:01:30 +02:00
|
|
|
$gatewayipv6 = "";
|
|
|
|
$interfacegwv6 = "";
|
2014-11-01 18:42:41 +01:00
|
|
|
$foundgw = false;
|
2010-10-22 16:01:30 +02:00
|
|
|
$foundgwv6 = false;
|
2010-04-29 01:16:42 +02:00
|
|
|
/* tack on all the hard defined gateways as well */
|
|
|
|
if (is_array($config['gateways']['gateway_item'])) {
|
2014-02-03 17:55:01 +01:00
|
|
|
array_map('unlink', glob("{$g['tmp_path']}/*_defaultgw{,v6}", GLOB_BRACE));
|
2010-04-29 01:16:42 +02:00
|
|
|
foreach ($config['gateways']['gateway_item'] as $gateway) {
|
2013-02-09 10:36:50 +01:00
|
|
|
if (isset($gateway['defaultgw'])) {
|
2014-11-01 18:42:41 +01:00
|
|
|
if ($foundgw == false && ($gateway['ipprotocol'] != "inet6" && (is_ipaddrv4($gateway['gateway']) || $gateway['gateway'] == "dynamic"))) {
|
|
|
|
if(strpos($gateway['gateway'], ":"))
|
2013-02-09 10:36:50 +01:00
|
|
|
continue;
|
|
|
|
if ($gateway['gateway'] == "dynamic")
|
|
|
|
$gateway['gateway'] = get_interface_gateway($gateway['interface']);
|
2013-02-10 12:26:12 +01:00
|
|
|
$gatewayip = $gateway['gateway'];
|
2013-02-14 13:18:01 +01:00
|
|
|
$interfacegw = $gateway['interface'];
|
2013-02-09 10:36:50 +01:00
|
|
|
if (!empty($gateway['interface'])) {
|
|
|
|
$defaultif = get_real_interface($gateway['interface']);
|
|
|
|
if ($defaultif)
|
|
|
|
@file_put_contents("{$g['tmp_path']}/{$defaultif}_defaultgw", $gateway['gateway']);
|
|
|
|
}
|
|
|
|
$foundgw = true;
|
2014-11-01 18:42:41 +01:00
|
|
|
} else if ($foundgwv6 == false && ($gateway['ipprotocol'] == "inet6" && (is_ipaddrv6($gateway['gateway']) || $gateway['gateway'] == "dynamic"))) {
|
2014-03-03 17:30:57 +01:00
|
|
|
if ($gateway['gateway'] == "dynamic")
|
2013-02-09 10:36:50 +01:00
|
|
|
$gateway['gateway'] = get_interface_gateway_v6($gateway['interface']);
|
2013-02-10 12:26:12 +01:00
|
|
|
$gatewayipv6 = $gateway['gateway'];
|
2013-02-14 13:18:01 +01:00
|
|
|
$interfacegwv6 = $gateway['interface'];
|
2013-02-09 10:36:50 +01:00
|
|
|
if (!empty($gateway['interface'])) {
|
2014-02-18 10:25:41 +01:00
|
|
|
$defaultifv6 = get_real_interface($gateway['interface']);
|
2013-02-09 10:36:50 +01:00
|
|
|
if ($defaultifv6)
|
|
|
|
@file_put_contents("{$g['tmp_path']}/{$defaultifv6}_defaultgwv6", $gateway['gateway']);
|
|
|
|
}
|
|
|
|
$foundgwv6 = true;
|
2010-05-31 21:14:29 +02:00
|
|
|
}
|
2010-04-29 01:16:42 +02:00
|
|
|
}
|
2013-02-09 10:36:50 +01:00
|
|
|
if ($foundgw === true && $foundgwv6 === true)
|
2010-10-22 16:01:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-02-15 01:45:37 +01:00
|
|
|
}
|
2010-07-21 22:24:13 +02:00
|
|
|
if ($foundgw == false) {
|
|
|
|
$defaultif = get_real_interface("wan");
|
|
|
|
$interfacegw = "wan";
|
|
|
|
$gatewayip = get_interface_gateway("wan");
|
2014-11-01 18:42:41 +01:00
|
|
|
@file_put_contents("{$g['tmp_path']}/{$defaultif}_defaultgw", $gatewayip);
|
2010-07-21 22:24:13 +02:00
|
|
|
}
|
2010-10-22 16:01:30 +02:00
|
|
|
if ($foundgwv6 == false) {
|
2014-02-18 10:25:41 +01:00
|
|
|
$defaultifv6 = get_real_interface("wan");
|
2011-03-04 16:51:39 +01:00
|
|
|
$interfacegwv6 = "wan";
|
|
|
|
$gatewayipv6 = get_interface_gateway_v6("wan");
|
2014-11-01 18:42:41 +01:00
|
|
|
@file_put_contents("{$g['tmp_path']}/{$defaultifv6}_defaultgwv6", $gatewayipv6);
|
2011-03-04 17:01:52 +01:00
|
|
|
}
|
2007-10-19 21:10:16 +02:00
|
|
|
$dont_add_route = false;
|
|
|
|
/* if OLSRD is enabled, allow WAN to house DHCP. */
|
2013-02-09 10:36:50 +01:00
|
|
|
if (is_array($config['installedpackages']['olsrd'])) {
|
2007-10-19 21:10:16 +02:00
|
|
|
foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
|
2012-02-22 13:01:17 +01:00
|
|
|
if(($olsrd['enabledyngw'] == "on") && ($olsrd['enable'] == "on")) {
|
2007-10-19 21:10:16 +02:00
|
|
|
$dont_add_route = true;
|
2012-02-22 13:01:17 +01:00
|
|
|
log_error(sprintf(gettext("Not adding default route because OLSR dynamic gateway is enabled.")));
|
2009-05-06 01:47:55 +02:00
|
|
|
break;
|
2007-10-19 21:10:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-14 16:45:31 +02:00
|
|
|
|
2010-06-18 20:46:06 +02:00
|
|
|
if ($dont_add_route == false ) {
|
2010-09-30 17:54:42 +02:00
|
|
|
if (!empty($interface) && $interface != $interfacegw)
|
2010-06-18 20:46:06 +02:00
|
|
|
;
|
2014-05-31 02:57:51 +02:00
|
|
|
else if (is_ipaddrv4($gatewayip)) {
|
2011-07-25 19:56:25 +02:00
|
|
|
log_error("ROUTING: setting default route to $gatewayip");
|
|
|
|
mwexec("/sbin/route change -inet default " . escapeshellarg($gatewayip));
|
2007-10-19 21:10:16 +02:00
|
|
|
}
|
|
|
|
|
2011-03-04 17:01:52 +01:00
|
|
|
if (!empty($interface) && $interface != $interfacegwv6)
|
2010-10-22 16:01:30 +02:00
|
|
|
;
|
2014-05-31 02:57:51 +02:00
|
|
|
else if (is_ipaddrv6($gatewayipv6)) {
|
2013-02-09 10:26:33 +01:00
|
|
|
$ifscope = "";
|
2013-06-17 10:26:49 +02:00
|
|
|
if (is_linklocal($gatewayipv6))
|
2011-09-03 11:13:12 +02:00
|
|
|
$ifscope = "%{$defaultifv6}";
|
2011-09-03 12:17:15 +02:00
|
|
|
log_error("ROUTING: setting IPv6 default route to {$gatewayipv6}{$ifscope}");
|
2014-07-21 23:57:08 +02:00
|
|
|
mwexec("/sbin/route change -inet6 default " . escapeshellarg("{$gatewayipv6}{$ifscope}"));
|
2010-10-22 16:01:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 12:49:10 +02:00
|
|
|
system_staticroutes_configure($interface, false);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_staticroutes_configure($interface = "", $update_dns = false) {
|
|
|
|
global $config, $g, $aliastable;
|
|
|
|
|
2013-05-27 12:23:55 +02:00
|
|
|
$filterdns_list = array();
|
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
$static_routes = get_staticroutes(false, true);
|
2012-04-11 17:58:21 +02:00
|
|
|
if (count($static_routes)) {
|
2012-06-04 10:20:58 +02:00
|
|
|
$gateways_arr = return_gateways_array(false, true);
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2012-04-11 17:58:21 +02:00
|
|
|
foreach ($static_routes as $rtent) {
|
2010-09-30 18:04:54 +02:00
|
|
|
if (empty($gateways_arr[$rtent['gateway']])) {
|
2010-08-17 22:23:58 +02:00
|
|
|
log_error(sprintf(gettext("Static Routes: Gateway IP could not be found for %s"), $rtent['network']));
|
2010-04-29 01:16:42 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-09-30 18:04:54 +02:00
|
|
|
$gateway = $gateways_arr[$rtent['gateway']];
|
2011-01-20 18:52:38 +01:00
|
|
|
if (!empty($interface) && $interface != $gateway['friendlyiface'])
|
2010-09-30 18:04:54 +02:00
|
|
|
continue;
|
2011-01-26 15:40:32 +01:00
|
|
|
|
2010-09-30 18:04:54 +02:00
|
|
|
$gatewayip = $gateway['gateway'];
|
|
|
|
$interfacegw = $gateway['interface'];
|
2010-04-29 01:16:42 +02:00
|
|
|
|
2012-06-08 08:33:27 +02:00
|
|
|
$blackhole = "";
|
2013-02-09 10:26:33 +01:00
|
|
|
if (!strcasecmp("Null", substr($rtent['gateway'], 0, 3)))
|
2012-06-08 08:33:27 +02:00
|
|
|
$blackhole = "-blackhole";
|
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
if (!is_fqdn($rtent['network']) && !is_subnet($rtent['network']))
|
2013-05-23 12:49:10 +02:00
|
|
|
continue;
|
2013-05-22 17:18:30 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
$dnscache = array();
|
|
|
|
if ($update_dns === true) {
|
|
|
|
if (is_subnet($rtent['network']))
|
2013-05-23 12:49:10 +02:00
|
|
|
continue;
|
2013-05-27 15:17:46 +02:00
|
|
|
$dnscache = explode("\n", trim(compare_hostname_to_dnscache($rtent['network'])));
|
|
|
|
if (empty($dnscache))
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-22 17:18:30 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
if (is_subnet($rtent['network']))
|
|
|
|
$ips = array($rtent['network']);
|
|
|
|
else {
|
|
|
|
if (!isset($rtent['disabled']))
|
|
|
|
$filterdns_list[] = $rtent['network'];
|
|
|
|
$ips = add_hostname_to_watch($rtent['network']);
|
|
|
|
}
|
2013-05-23 12:49:10 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
foreach ($dnscache as $ip) {
|
|
|
|
if (in_array($ip, $ips))
|
|
|
|
continue;
|
|
|
|
mwexec("/sbin/route delete " . escapeshellarg($ip), true);
|
2014-11-07 03:19:24 +01:00
|
|
|
if (isset($config['system']['route-debug'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
log_error("ROUTING debug: $mt - route delete $ip ");
|
|
|
|
}
|
2013-05-27 15:17:46 +02:00
|
|
|
}
|
2013-05-23 12:49:10 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
if (isset($rtent['disabled'])) {
|
2014-10-14 20:44:56 +02:00
|
|
|
/* XXX: This can break things by deleting routes that shouldn't be deleted - OpenVPN, dynamic routing scenarios, etc. redmine #3709 */
|
2014-11-07 03:19:24 +01:00
|
|
|
foreach ($ips as $ip) {
|
2013-05-23 12:49:10 +02:00
|
|
|
mwexec("/sbin/route delete " . escapeshellarg($ip), true);
|
2014-11-07 03:19:24 +01:00
|
|
|
if (isset($config['system']['route-debug'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
log_error("ROUTING debug: $mt - route delete $ip ");
|
|
|
|
}
|
|
|
|
}
|
2013-05-27 15:17:46 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-05-23 12:49:10 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
foreach ($ips as $ip) {
|
|
|
|
if (is_ipaddrv4($ip))
|
|
|
|
$ip .= "/32";
|
|
|
|
else if (is_ipaddrv6($ip))
|
|
|
|
$ip .= "/128";
|
2013-05-23 12:49:10 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
$inet = (is_subnetv6($ip) ? "-inet6" : "-inet");
|
2013-05-23 12:49:10 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
$cmd = "/sbin/route change {$inet} {$blackhole} " . escapeshellarg($ip) . " ";
|
|
|
|
|
|
|
|
if (is_subnet($ip))
|
2014-11-07 03:19:24 +01:00
|
|
|
if (is_ipaddr($gatewayip)) {
|
2013-05-27 15:17:46 +02:00
|
|
|
mwexec($cmd . escapeshellarg($gatewayip));
|
2014-11-07 03:19:24 +01:00
|
|
|
if (isset($config['system']['route-debug'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
log_error("ROUTING debug: $mt - $cmd $gatewayip");
|
|
|
|
}
|
|
|
|
} else if (!empty($interfacegw)) {
|
2013-05-27 15:17:46 +02:00
|
|
|
mwexec($cmd . "-iface " . escapeshellarg($interfacegw));
|
2014-11-07 03:19:24 +01:00
|
|
|
if (isset($config['system']['route-debug'])) {
|
|
|
|
$mt = microtime();
|
|
|
|
log_error("ROUTING debug: $mt - $cmd -iface $interfacegw ");
|
|
|
|
}
|
|
|
|
}
|
2013-05-23 12:49:10 +02:00
|
|
|
}
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
2013-02-10 12:26:54 +01:00
|
|
|
unset($gateways_arr);
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
2013-02-10 12:26:54 +01:00
|
|
|
unset($static_routes);
|
2008-07-14 22:43:59 +02:00
|
|
|
|
2013-05-27 15:17:46 +02:00
|
|
|
if ($update_dns === false) {
|
|
|
|
if (count($filterdns_list)) {
|
|
|
|
$interval = 60;
|
|
|
|
$hostnames = "";
|
|
|
|
array_unique($filterdns_list);
|
|
|
|
foreach ($filterdns_list as $hostname)
|
|
|
|
$hostnames .= "cmd {$hostname} '/usr/local/sbin/pfSctl -c \"service reload routedns\"'\n";
|
|
|
|
file_put_contents("{$g['varetc_path']}/filterdns-route.hosts", $hostnames);
|
|
|
|
unset($hostnames);
|
|
|
|
|
|
|
|
if (isvalidpid("{$g['varrun_path']}/filterdns-route.pid"))
|
|
|
|
sigkillbypid("{$g['varrun_path']}/filterdns-route.pid", "HUP");
|
|
|
|
else
|
|
|
|
mwexec("/usr/local/sbin/filterdns -p {$g['varrun_path']}/filterdns-route.pid -i {$interval} -c {$g['varetc_path']}/filterdns-route.hosts -d 1");
|
|
|
|
} else {
|
|
|
|
killbypid("{$g['varrun_path']}/filterdns-route.pid");
|
|
|
|
@unlink("{$g['varrun_path']}/filterdns-route.pid");
|
|
|
|
}
|
2013-05-27 12:23:55 +02:00
|
|
|
}
|
2013-05-27 15:17:46 +02:00
|
|
|
unset($filterdns_list);
|
2013-05-27 12:23:55 +02:00
|
|
|
|
2008-07-01 21:21:45 +02:00
|
|
|
return 0;
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function system_routing_enable() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_routing_enable() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2014-07-08 01:06:37 +02:00
|
|
|
set_sysctl(array(
|
|
|
|
"net.inet.ip.forwarding" => "1",
|
|
|
|
"net.inet6.ip6.forwarding" => "1"
|
|
|
|
));
|
|
|
|
|
2010-11-03 11:32:34 +01:00
|
|
|
return;
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
2012-04-12 17:07:25 +02:00
|
|
|
function system_syslogd_fixup_server($server) {
|
|
|
|
/* If it's an IPv6 IP alone, encase it in brackets */
|
|
|
|
if (is_ipaddrv6($server))
|
|
|
|
return "[$server]";
|
|
|
|
else
|
|
|
|
return $server;
|
|
|
|
}
|
|
|
|
|
2011-10-26 23:13:01 +02:00
|
|
|
function system_syslogd_get_remote_servers($syslogcfg, $facility = "*.*") {
|
|
|
|
// Rather than repeatedly use the same code, use this function to build a list of remote servers.
|
|
|
|
$facility .= " ".
|
|
|
|
$remote_servers = "";
|
|
|
|
$pad_to = 56;
|
|
|
|
$padding = ceil(($pad_to - strlen($facility))/8)+1;
|
|
|
|
if($syslogcfg['remoteserver'])
|
2012-04-12 17:07:25 +02:00
|
|
|
$remote_servers .= "{$facility}" . str_repeat("\t", $padding) . "@" . system_syslogd_fixup_server($syslogcfg['remoteserver']) . "\n";
|
2011-10-26 23:13:01 +02:00
|
|
|
if($syslogcfg['remoteserver2'])
|
2012-04-12 17:07:25 +02:00
|
|
|
$remote_servers .= "{$facility}" . str_repeat("\t", $padding) . "@" . system_syslogd_fixup_server($syslogcfg['remoteserver2']) . "\n";
|
2011-10-26 23:13:01 +02:00
|
|
|
if($syslogcfg['remoteserver3'])
|
2012-04-12 17:07:25 +02:00
|
|
|
$remote_servers .= "{$facility}" . str_repeat("\t", $padding) . "@" . system_syslogd_fixup_server($syslogcfg['remoteserver3']) . "\n";
|
2011-10-26 23:13:01 +02:00
|
|
|
return $remote_servers;
|
|
|
|
}
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
function system_syslogd_start() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_syslogd_start() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2011-08-01 20:15:24 +02:00
|
|
|
mwexec("/etc/rc.d/hostid start");
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
$syslogcfg = $config['syslog'];
|
|
|
|
|
2004-11-21 19:41:42 +01:00
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("Starting syslog...");
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2013-02-12 21:18:46 +01:00
|
|
|
if (is_process_running("fifolog_writer"))
|
2011-10-26 23:13:01 +02:00
|
|
|
mwexec('/bin/pkill fifolog_writer');
|
2009-04-01 02:45:09 +02:00
|
|
|
|
|
|
|
// Which logging type are we using this week??
|
2013-02-12 21:18:46 +01:00
|
|
|
if (isset($config['system']['disablesyslogclog'])) {
|
|
|
|
$log_directive = "";
|
|
|
|
$log_create_directive = "/usr/bin/touch ";
|
|
|
|
$log_size = "";
|
|
|
|
} else if (isset($config['system']['usefifolog'])) {
|
|
|
|
$log_directive = "|/usr/sbin/fifolog_writer ";
|
2013-12-26 21:25:46 +01:00
|
|
|
$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "10240";
|
2013-02-12 21:18:46 +01:00
|
|
|
$log_create_directive = "/usr/sbin/fifolog_create -s ";
|
2009-04-01 02:45:09 +02:00
|
|
|
} else { // Defaults to CLOG
|
2013-02-12 21:18:46 +01:00
|
|
|
$log_directive = "%";
|
2013-12-26 21:25:46 +01:00
|
|
|
$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "10240";
|
2014-04-28 16:54:22 +02:00
|
|
|
$log_create_directive = "/usr/local/sbin/clog -i -s ";
|
2009-04-01 02:45:09 +02:00
|
|
|
}
|
2014-04-28 23:12:20 +02:00
|
|
|
|
|
|
|
$syslogd_extra = "";
|
2005-08-08 00:05:35 +02:00
|
|
|
if (isset($syslogcfg)) {
|
2014-11-07 14:37:09 +01:00
|
|
|
$separatelogfacilities = array('ntp','ntpd','ntpdate','charon','ipsec_starter','openvpn','pptps','poes','l2tps','relayd','hostapd','dnsmasq','filterdns','unbound','dhcpd','dhcrelay','dhclient','dhcp6c','apinger','radvd','routed','olsrd','zebra','ospfd','bgpd','miniupnpd','filterlog');
|
2012-11-20 17:10:05 +01:00
|
|
|
$syslogconf = "";
|
2005-06-22 03:24:25 +02:00
|
|
|
if($config['installedpackages']['package']) {
|
2009-03-19 02:54:28 +01:00
|
|
|
foreach($config['installedpackages']['package'] as $package) {
|
|
|
|
if($package['logging']) {
|
2010-12-02 18:01:27 +01:00
|
|
|
array_push($separatelogfacilities, $package['logging']['facilityname']);
|
2013-02-12 21:18:46 +01:00
|
|
|
mwexec("{$log_create_directive} {$log_size} {$g['varlog_path']}/{$package['logging']['logfilename']}");
|
2010-12-02 15:56:14 +01:00
|
|
|
$syslogconf .= "!{$package['logging']['facilityname']}\n*.*\t\t\t\t\t\t {$log_directive}{$g['varlog_path']}/{$package['logging']['logfilename']}\n";
|
2005-06-22 03:24:25 +02:00
|
|
|
}
|
2009-03-19 02:54:28 +01:00
|
|
|
}
|
|
|
|
}
|
2006-10-27 18:29:25 +02:00
|
|
|
$facilitylist = implode(',', array_unique($separatelogfacilities));
|
2013-05-08 21:09:28 +02:00
|
|
|
$syslogconf .= "!radvd,routed,olsrd,zebra,ospfd,bgpd,miniupnpd\n";
|
2012-05-01 22:00:10 +02:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/routing.log\n";
|
|
|
|
|
|
|
|
$syslogconf .= "!ntp,ntpd,ntpdate\n";
|
2009-03-19 02:54:28 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/ntpd.log\n";
|
|
|
|
|
2009-10-26 06:48:52 +01:00
|
|
|
$syslogconf .= "!ppp\n";
|
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/ppp.log\n";
|
|
|
|
|
2010-11-02 20:14:11 +01:00
|
|
|
$syslogconf .= "!pptps\n";
|
2010-03-23 23:13:01 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/pptps.log\n";
|
|
|
|
|
2010-11-02 20:14:11 +01:00
|
|
|
$syslogconf .= "!poes\n";
|
2010-03-23 23:13:01 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/poes.log\n";
|
|
|
|
|
2010-11-02 20:14:11 +01:00
|
|
|
$syslogconf .= "!l2tps\n";
|
2010-03-23 23:13:01 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/l2tps.log\n";
|
|
|
|
|
2014-11-07 14:37:09 +01:00
|
|
|
$syslogconf .= "!charon,ipsec_starter\n";
|
2009-03-19 02:54:28 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/ipsec.log\n";
|
|
|
|
if (isset($syslogcfg['vpn']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2006-10-27 18:29:25 +02:00
|
|
|
$syslogconf .= "!openvpn\n";
|
2009-03-19 02:54:28 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/openvpn.log\n";
|
|
|
|
if (isset($syslogcfg['vpn']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2010-07-16 16:23:39 +02:00
|
|
|
$syslogconf .= "!apinger\n";
|
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2012-03-29 12:20:03 +02:00
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/gateways.log\n";
|
|
|
|
if (isset($syslogcfg['apinger']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2013-05-08 18:46:02 +02:00
|
|
|
$syslogconf .= "!dnsmasq,filterdns,unbound\n";
|
2012-03-29 12:20:03 +02:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/resolver.log\n";
|
|
|
|
|
2014-08-11 16:47:14 +02:00
|
|
|
$syslogconf .= "!dhcpd,dhcrelay,dhclient,dhcp6c\n";
|
2012-03-29 12:20:03 +02:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/dhcpd.log\n";
|
2014-04-21 06:57:58 +02:00
|
|
|
if (isset($syslogcfg['dhcp']))
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2010-07-12 01:57:36 +02:00
|
|
|
$syslogconf .= "!relayd\n";
|
2011-10-26 23:13:01 +02:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/relayd.log\n";
|
|
|
|
if (isset($syslogcfg['relayd']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2011-10-01 01:57:03 +02:00
|
|
|
$syslogconf .= "!hostapd\n";
|
2011-10-26 23:13:01 +02:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/wireless.log\n";
|
|
|
|
if (isset($syslogcfg['hostapd']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2014-04-28 10:08:59 +02:00
|
|
|
$syslogconf .= "!filterlog\n";
|
|
|
|
$syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/filter.log\n";
|
|
|
|
if (isset($syslogcfg['filter']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
|
2006-10-27 18:29:25 +02:00
|
|
|
$syslogconf .= "!-{$facilitylist}\n";
|
2009-03-19 02:54:28 +01:00
|
|
|
if (!isset($syslogcfg['disablelocallogging']))
|
2004-11-07 04:06:49 +01:00
|
|
|
$syslogconf .= <<<EOD
|
2011-10-26 23:13:01 +02:00
|
|
|
local3.* {$log_directive}{$g['varlog_path']}/vpn.log
|
|
|
|
local4.* {$log_directive}{$g['varlog_path']}/portalauth.log
|
|
|
|
local7.* {$log_directive}{$g['varlog_path']}/dhcpd.log
|
2013-01-03 14:08:20 +01:00
|
|
|
*.notice;kern.debug;lpr.info;mail.crit;daemon.none; {$log_directive}{$g['varlog_path']}/system.log
|
2011-10-26 23:13:01 +02:00
|
|
|
news.err;local0.none;local3.none;local4.none; {$log_directive}{$g['varlog_path']}/system.log
|
|
|
|
local7.none {$log_directive}{$g['varlog_path']}/system.log
|
|
|
|
security.* {$log_directive}{$g['varlog_path']}/system.log
|
|
|
|
auth.info;authpriv.info;daemon.info {$log_directive}{$g['varlog_path']}/system.log
|
|
|
|
auth.info;authpriv.info |exec /usr/local/sbin/sshlockout_pf 15
|
|
|
|
*.emerg *
|
2009-08-25 04:17:45 +02:00
|
|
|
|
|
|
|
EOD;
|
2011-10-26 23:13:01 +02:00
|
|
|
if (isset($syslogcfg['vpn']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "local3.*");
|
|
|
|
if (isset($syslogcfg['portalauth']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "local4.*");
|
|
|
|
if (isset($syslogcfg['dhcp']))
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "local7.*");
|
2009-08-25 04:17:45 +02:00
|
|
|
if (isset($syslogcfg['system'])) {
|
2011-10-26 23:13:01 +02:00
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.notice;kern.debug;lpr.info;mail.crit;");
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "news.err;local0.none;local3.none;local7.none");
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "security.*");
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "auth.info;authpriv.info;daemon.info");
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.emerg");
|
|
|
|
}
|
2009-08-10 00:38:01 +02:00
|
|
|
if (isset($syslogcfg['logall'])) {
|
2011-10-26 23:13:01 +02:00
|
|
|
// Make everything mean everything, including facilities excluded above.
|
|
|
|
$syslogconf .= "!*\n";
|
|
|
|
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
|
|
|
|
}
|
2009-08-25 04:17:45 +02:00
|
|
|
|
2011-07-13 06:20:52 +02:00
|
|
|
if (isset($syslogcfg['zmqserver'])) {
|
|
|
|
$syslogconf .= <<<EOD
|
|
|
|
*.* ^{$syslogcfg['zmqserver']}
|
|
|
|
|
|
|
|
EOD;
|
|
|
|
}
|
2012-11-20 17:10:05 +01:00
|
|
|
/* write syslog.conf */
|
|
|
|
if (!@file_put_contents("{$g['varetc_path']}/syslog.conf", $syslogconf)) {
|
|
|
|
printf(gettext("Error: cannot open syslog.conf in system_syslogd_start().%s"), "\n");
|
|
|
|
unset($syslogconf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
unset($syslogconf);
|
2010-12-18 20:57:42 +01:00
|
|
|
|
|
|
|
// Ensure that the log directory exists
|
2012-11-20 17:10:05 +01:00
|
|
|
if (!is_dir("{$g['dhcpd_chroot_path']}/var/run"))
|
2010-12-18 20:57:42 +01:00
|
|
|
exec("/bin/mkdir -p {$g['dhcpd_chroot_path']}/var/run");
|
|
|
|
|
2013-10-24 22:32:12 +02:00
|
|
|
$sourceip = "";
|
|
|
|
if (!empty($syslogcfg['sourceip'])) {
|
|
|
|
if ($syslogcfg['ipproto'] == "ipv6") {
|
|
|
|
$ifaddr = is_ipaddr($syslogcfg['sourceip']) ? $syslogcfg['sourceip'] : get_interface_ipv6($syslogcfg['sourceip']);
|
|
|
|
if (!is_ipaddr($ifaddr))
|
|
|
|
$ifaddr = get_interface_ip($syslogcfg['sourceip']);
|
|
|
|
} else {
|
|
|
|
$ifaddr = is_ipaddr($syslogcfg['sourceip']) ? $syslogcfg['sourceip'] : get_interface_ip($syslogcfg['sourceip']);
|
|
|
|
if (!is_ipaddr($ifaddr))
|
|
|
|
$ifaddr = get_interface_ipv6($syslogcfg['sourceip']);
|
|
|
|
}
|
|
|
|
if (is_ipaddr($ifaddr)) {
|
|
|
|
$sourceip = "-b {$ifaddr}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 23:12:20 +02:00
|
|
|
$syslogd_extra = "-f {$g['varetc_path']}/syslog.conf {$sourceip}";
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2014-04-28 23:12:20 +02:00
|
|
|
if (isvalidpid("{$g['varrun_path']}/syslog.pid"))
|
|
|
|
sigkillbypid("{$g['varrun_path']}/syslog.pid", "HUP");
|
|
|
|
else
|
|
|
|
$retval = mwexec_bg("/usr/sbin/syslogd -s -c -c -l {$g['dhcpd_chroot_path']}/var/run/log -P {$g['varrun_path']}/syslog.pid {$syslogd_extra}");
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("done.") . "\n";
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2014-10-14 21:28:48 +02:00
|
|
|
function system_webgui_create_certificate() {
|
|
|
|
global $config, $g;
|
|
|
|
|
|
|
|
if (!is_array($config['ca']))
|
|
|
|
$config['ca'] = array();
|
|
|
|
$a_ca =& $config['ca'];
|
|
|
|
if (!is_array($config['cert']))
|
|
|
|
$config['cert'] = array();
|
|
|
|
$a_cert =& $config['cert'];
|
|
|
|
log_error("Creating SSL Certificate for this host");
|
|
|
|
|
|
|
|
$cert = array();
|
|
|
|
$cert['refid'] = uniqid();
|
2014-10-15 20:01:00 +02:00
|
|
|
$cert['descr'] = gettext("webConfigurator default ({$cert['refid']})");
|
2014-10-14 21:28:48 +02:00
|
|
|
|
|
|
|
$dn = array(
|
|
|
|
'countryName' => "US",
|
|
|
|
'stateOrProvinceName' => "State",
|
|
|
|
'localityName' => "Locality",
|
|
|
|
'organizationName' => "{$g['product_name']} webConfigurator Self-Signed Certificate",
|
|
|
|
'emailAddress' => "admin@{$config['system']['hostname']}.{$config['system']['domain']}",
|
2014-10-15 20:01:00 +02:00
|
|
|
'commonName' => "{$config['system']['hostname']}-{$cert['refid']}");
|
2014-10-14 21:28:48 +02:00
|
|
|
$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
|
|
|
|
if (!cert_create($cert, null, 2048, 2000, $dn, "self-signed", "sha256")){
|
|
|
|
while($ssl_err = openssl_error_string()){
|
|
|
|
log_error("Error creating WebGUI Certificate: openssl library returns: " . $ssl_err);
|
|
|
|
}
|
|
|
|
error_reporting($old_err_level);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
error_reporting($old_err_level);
|
|
|
|
|
|
|
|
$a_cert[] = $cert;
|
|
|
|
$config['system']['webgui']['ssl-certref'] = $cert['refid'];
|
2014-10-15 20:01:00 +02:00
|
|
|
write_config(gettext("Generated new self-signed HTTPS certificate ({$cert['refid']})"));
|
2014-10-14 21:28:48 +02:00
|
|
|
return $cert;
|
|
|
|
}
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
function system_webgui_start() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-11-26 23:06:23 +01:00
|
|
|
|
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("Starting webConfigurator...");
|
2005-11-26 23:06:23 +01:00
|
|
|
|
|
|
|
chdir($g['www_path']);
|
|
|
|
|
2008-09-09 06:08:22 +02:00
|
|
|
/* defaults */
|
|
|
|
$portarg = "80";
|
|
|
|
$crt = "";
|
|
|
|
$key = "";
|
2009-05-24 08:36:21 +02:00
|
|
|
$ca = "";
|
2008-09-09 06:08:22 +02:00
|
|
|
|
2005-11-26 23:06:23 +01:00
|
|
|
/* non-standard port? */
|
2009-07-28 12:00:26 +02:00
|
|
|
if (isset($config['system']['webgui']['port']) && $config['system']['webgui']['port'] <> "")
|
2005-11-27 04:21:48 +01:00
|
|
|
$portarg = "{$config['system']['webgui']['port']}";
|
2005-11-26 23:06:23 +01:00
|
|
|
|
|
|
|
if ($config['system']['webgui']['protocol'] == "https") {
|
2009-12-02 22:51:04 +01:00
|
|
|
// Ensure that we have a webConfigurator CERT
|
2008-09-09 06:08:22 +02:00
|
|
|
$cert =& lookup_cert($config['system']['webgui']['ssl-certref']);
|
2014-10-28 17:55:07 +01:00
|
|
|
if(!is_array($cert) || !$cert['crt'] || !$cert['prv'])
|
2014-10-14 21:28:48 +02:00
|
|
|
$cert = system_webgui_create_certificate();
|
2014-10-28 17:55:07 +01:00
|
|
|
$crt = base64_decode($cert['crt']);
|
|
|
|
$key = base64_decode($cert['prv']);
|
2014-10-14 21:28:48 +02:00
|
|
|
|
|
|
|
if(!$config['system']['webgui']['port'])
|
|
|
|
$portarg = "443";
|
|
|
|
$ca = ca_chain($cert);
|
2005-11-26 23:06:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* generate lighttpd configuration */
|
|
|
|
system_generate_lighty_config("{$g['varetc_path']}/lighty-webConfigurator.conf",
|
2011-06-17 19:53:42 +02:00
|
|
|
$crt, $key, $ca, "lighty-webConfigurator.pid", $portarg, "/usr/local/www/",
|
2012-05-10 20:17:55 +02:00
|
|
|
"cert.pem", "ca.pem");
|
2005-11-26 23:06:23 +01:00
|
|
|
|
2013-02-05 17:04:29 +01:00
|
|
|
/* kill any running lighttpd */
|
|
|
|
killbypid("{$g['varrun_path']}/lighty-webConfigurator.pid");
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
@unlink("{$g['varrun_path']}/lighty-webConfigurator.pid");
|
|
|
|
|
2005-11-26 23:06:23 +01:00
|
|
|
/* attempt to start lighthttpd */
|
|
|
|
$res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-webConfigurator.conf");
|
|
|
|
|
|
|
|
if ($g['booting']) {
|
|
|
|
if ($res == 0)
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("done.") . "\n";
|
2005-11-26 23:06:23 +01:00
|
|
|
else
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("failed!") . "\n";
|
2005-11-26 23:06:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2005-12-03 20:40:04 +01:00
|
|
|
function system_generate_lighty_config($filename,
|
|
|
|
$cert,
|
|
|
|
$key,
|
2009-05-24 08:36:21 +02:00
|
|
|
$ca,
|
2005-12-03 20:40:04 +01:00
|
|
|
$pid_file,
|
|
|
|
$port = 80,
|
|
|
|
$document_root = "/usr/local/www/",
|
|
|
|
$cert_location = "cert.pem",
|
2009-05-24 08:36:21 +02:00
|
|
|
$ca_location = "ca.pem",
|
2005-12-03 20:40:04 +01:00
|
|
|
$captive_portal = false) {
|
2005-10-12 01:44:53 +02:00
|
|
|
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
|
|
|
|
2009-12-28 10:41:47 +01:00
|
|
|
if(!is_dir("{$g['tmp_path']}/lighttpdcompress"))
|
|
|
|
mkdir("{$g['tmp_path']}/lighttpdcompress");
|
2009-12-02 21:49:58 +01:00
|
|
|
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_generate_lighty_config() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 10:51:12 +01:00
|
|
|
if ($captive_portal !== false) {
|
2013-01-03 11:22:56 +01:00
|
|
|
$captiveportal = ",\"mod_rewrite\",\"mod_evasive\"";
|
2011-09-07 08:42:58 +02:00
|
|
|
$captive_portal_rewrite = "url.rewrite-once = ( \"(.*captiveportal.*)\" => \"$1\", \"(.*)\" => \"/index.php?zone={$captive_portal}&redirurl=$1\" )\n";
|
2012-08-01 10:04:49 +02:00
|
|
|
|
2012-06-09 17:52:51 +02:00
|
|
|
$maxprocperip = $config['captiveportal'][$captive_portal]['maxprocperip'];
|
2013-01-04 10:51:12 +01:00
|
|
|
if (empty($maxprocperip))
|
2013-01-03 11:22:56 +01:00
|
|
|
$maxprocperip = 10;
|
2012-08-01 10:04:49 +02:00
|
|
|
$captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}";
|
|
|
|
|
2009-12-28 10:41:47 +01:00
|
|
|
$server_upload_dirs = "server.upload-dirs = ( \"{$g['tmp_path']}/captiveportal/\" )\n";
|
2014-02-11 04:05:26 +01:00
|
|
|
if(!is_dir("{$g['tmp_path']}/captiveportal"))
|
2014-02-20 10:02:55 +01:00
|
|
|
@mkdir("{$g['tmp_path']}/captiveportal", 0555);
|
2007-12-10 23:06:48 +01:00
|
|
|
$server_max_request_size = "server.max-request-size = 384";
|
2013-01-21 15:35:31 +01:00
|
|
|
$cgi_config = "";
|
2006-10-10 01:54:25 +02:00
|
|
|
} else {
|
2013-01-21 15:35:31 +01:00
|
|
|
$captiveportal = ",\"mod_cgi\"";
|
2010-03-05 16:44:31 +01:00
|
|
|
$captive_portal_rewrite = "";
|
2006-10-10 01:54:25 +02:00
|
|
|
$captive_portal_mod_evasive = "";
|
2009-12-28 10:41:47 +01:00
|
|
|
$server_upload_dirs = "server.upload-dirs = ( \"{$g['upload_path']}/\", \"{$g['tmp_path']}/\", \"/var/\" )\n";
|
2007-12-10 23:06:48 +01:00
|
|
|
$server_max_request_size = "server.max-request-size = 2097152";
|
2013-01-21 15:35:31 +01:00
|
|
|
$cgi_config = "cgi.assign = ( \".cgi\" => \"\" )";
|
2005-12-03 20:40:04 +01:00
|
|
|
}
|
2007-12-10 22:52:59 +01:00
|
|
|
|
2013-01-04 10:51:12 +01:00
|
|
|
if (empty($port))
|
2005-09-17 21:31:27 +02:00
|
|
|
$lighty_port = "80";
|
2013-01-04 10:51:12 +01:00
|
|
|
else
|
|
|
|
$lighty_port = $port;
|
2005-11-28 01:10:01 +01:00
|
|
|
|
|
|
|
$memory = get_memory();
|
2013-08-28 22:11:11 +02:00
|
|
|
$realmem = $memory[1];
|
2005-11-28 01:10:01 +01:00
|
|
|
|
2012-05-10 20:17:55 +02:00
|
|
|
// Determine web GUI process settings and take into account low memory systems
|
2013-08-28 22:11:11 +02:00
|
|
|
if ($realmem < 255)
|
2013-01-04 10:51:12 +01:00
|
|
|
$max_procs = 1;
|
|
|
|
else
|
2012-05-10 20:17:55 +02:00
|
|
|
$max_procs = ($config['system']['webgui']['max_procs']) ? $config['system']['webgui']['max_procs'] : 2;
|
2009-07-27 00:49:45 +02:00
|
|
|
|
2012-05-10 20:17:55 +02:00
|
|
|
// Ramp up captive portal max procs, assuming each PHP process can consume up to 64MB RAM
|
2013-01-04 11:00:37 +01:00
|
|
|
if ($captive_portal !== false) {
|
2013-08-28 22:11:11 +02:00
|
|
|
if ($realmem > 135 and $realmem < 256) {
|
2012-05-10 20:17:55 +02:00
|
|
|
$max_procs += 1; // 2 worker processes
|
2013-08-28 22:11:11 +02:00
|
|
|
} else if ($realmem > 255 and $realmem < 513) {
|
2013-01-04 10:51:12 +01:00
|
|
|
$max_procs += 2; // 3 worker processes
|
2013-08-28 22:11:11 +02:00
|
|
|
} else if ($realmem > 512) {
|
2012-05-10 20:17:55 +02:00
|
|
|
$max_procs += 4; // 6 worker processes
|
2010-06-09 23:07:43 +02:00
|
|
|
}
|
2013-01-04 10:51:12 +01:00
|
|
|
if ($max_procs > 1)
|
|
|
|
$max_php_children = intval($max_procs/2);
|
|
|
|
else
|
|
|
|
$max_php_children = 1;
|
|
|
|
|
2013-01-04 11:55:18 +01:00
|
|
|
} else {
|
2013-08-28 22:11:11 +02:00
|
|
|
if ($realmem < 78)
|
2013-01-04 11:55:18 +01:00
|
|
|
$max_php_children = 0;
|
|
|
|
else
|
|
|
|
$max_php_children = 1;
|
|
|
|
}
|
2009-11-21 22:30:54 +01:00
|
|
|
|
2013-07-09 18:00:43 +02:00
|
|
|
if(!isset($config['syslog']['nologlighttpd'])) {
|
|
|
|
$lighty_use_syslog = <<<EOD
|
|
|
|
## where to send error-messages to
|
|
|
|
server.errorlog-use-syslog="enable"
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-14 20:20:39 +01:00
|
|
|
if ($captive_portal !== false) {
|
|
|
|
$fast_cgi_path = "{$g['tmp_path']}/php-fastcgi-{$captive_portal}.socket";
|
|
|
|
$fastcgi_config = <<<EOD
|
2005-09-18 22:36:16 +02:00
|
|
|
#### fastcgi module
|
|
|
|
## read fastcgi.txt for more info
|
2006-10-10 01:54:25 +02:00
|
|
|
fastcgi.server = ( ".php" =>
|
2013-01-04 10:51:12 +01:00
|
|
|
( "localhost" =>
|
|
|
|
(
|
|
|
|
"socket" => "{$fast_cgi_path}",
|
|
|
|
"max-procs" => {$max_procs},
|
2013-01-04 11:00:37 +01:00
|
|
|
"bin-environment" => (
|
|
|
|
"PHP_FCGI_CHILDREN" => "{$max_php_children}",
|
|
|
|
"PHP_FCGI_MAX_REQUESTS" => "500"
|
|
|
|
),
|
2013-01-04 10:51:12 +01:00
|
|
|
"bin-path" => "/usr/local/bin/php"
|
|
|
|
)
|
2006-10-10 01:54:25 +02:00
|
|
|
)
|
|
|
|
)
|
2006-07-10 01:48:33 +02:00
|
|
|
|
2005-09-18 22:36:16 +02:00
|
|
|
EOD;
|
2013-12-14 20:20:39 +01:00
|
|
|
} else {
|
|
|
|
$fast_cgi_path = "{$g['varrun_path']}/php-fpm.socket";
|
|
|
|
$fastcgi_config = <<<EOD
|
|
|
|
#### fastcgi module
|
|
|
|
## read fastcgi.txt for more info
|
|
|
|
fastcgi.server = ( ".php" =>
|
|
|
|
( "localhost" =>
|
|
|
|
(
|
|
|
|
"socket" => "{$fast_cgi_path}",
|
|
|
|
"broken-scriptfilename" => "enable"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
|
2006-07-10 01:48:33 +02:00
|
|
|
|
2013-01-04 10:51:12 +01:00
|
|
|
$lighty_config = <<<EOD
|
2005-09-17 21:31:27 +02:00
|
|
|
#
|
2005-09-17 20:57:25 +02:00
|
|
|
# lighttpd configuration file
|
|
|
|
#
|
|
|
|
# use a it as base for lighttpd 1.0.0 and above
|
2005-09-17 21:31:27 +02:00
|
|
|
#
|
2005-09-17 20:57:25 +02:00
|
|
|
############ Options you really have to take care of ####################
|
|
|
|
|
2006-12-21 22:08:10 +01:00
|
|
|
## FreeBSD!
|
2009-03-14 06:48:28 +01:00
|
|
|
server.event-handler = "freebsd-kqueue"
|
|
|
|
server.network-backend = "writev"
|
2010-11-11 16:26:49 +01:00
|
|
|
#server.use-ipv6 = "enable"
|
2006-01-05 01:32:43 +01:00
|
|
|
|
2005-09-17 20:57:25 +02:00
|
|
|
## modules to load
|
2013-01-03 11:22:56 +01:00
|
|
|
server.modules = ( "mod_access", "mod_expire", "mod_compress", "mod_redirect",
|
|
|
|
{$captiveportal}, "mod_fastcgi"
|
2011-03-14 18:49:50 +01:00
|
|
|
)
|
2005-09-17 21:31:27 +02:00
|
|
|
|
2009-03-12 02:40:31 +01:00
|
|
|
server.max-keep-alive-requests = 15
|
|
|
|
server.max-keep-alive-idle = 30
|
|
|
|
|
2005-09-17 20:57:25 +02:00
|
|
|
## a static document-root, for virtual-hosting take look at the
|
|
|
|
## server.virtual-* options
|
2005-09-18 02:42:54 +02:00
|
|
|
server.document-root = "{$document_root}"
|
2005-12-03 20:40:04 +01:00
|
|
|
{$captive_portal_rewrite}
|
2005-09-17 20:57:25 +02:00
|
|
|
|
2009-02-10 21:57:41 +01:00
|
|
|
# Maximum idle time with nothing being written (php downloading)
|
|
|
|
server.max-write-idle = 999
|
|
|
|
|
2013-07-09 18:00:43 +02:00
|
|
|
{$lighty_use_syslog}
|
2005-09-17 20:57:25 +02:00
|
|
|
|
|
|
|
# files to check for if .../ is requested
|
|
|
|
server.indexfiles = ( "index.php", "index.html",
|
|
|
|
"index.htm", "default.htm" )
|
|
|
|
|
|
|
|
# mimetype mapping
|
|
|
|
mimetype.assign = (
|
|
|
|
".pdf" => "application/pdf",
|
|
|
|
".sig" => "application/pgp-signature",
|
|
|
|
".spl" => "application/futuresplash",
|
|
|
|
".class" => "application/octet-stream",
|
|
|
|
".ps" => "application/postscript",
|
|
|
|
".torrent" => "application/x-bittorrent",
|
|
|
|
".dvi" => "application/x-dvi",
|
|
|
|
".gz" => "application/x-gzip",
|
|
|
|
".pac" => "application/x-ns-proxy-autoconfig",
|
|
|
|
".swf" => "application/x-shockwave-flash",
|
|
|
|
".tar.gz" => "application/x-tgz",
|
|
|
|
".tgz" => "application/x-tgz",
|
|
|
|
".tar" => "application/x-tar",
|
|
|
|
".zip" => "application/zip",
|
|
|
|
".mp3" => "audio/mpeg",
|
|
|
|
".m3u" => "audio/x-mpegurl",
|
|
|
|
".wma" => "audio/x-ms-wma",
|
|
|
|
".wax" => "audio/x-ms-wax",
|
|
|
|
".ogg" => "audio/x-wav",
|
|
|
|
".wav" => "audio/x-wav",
|
|
|
|
".gif" => "image/gif",
|
|
|
|
".jpg" => "image/jpeg",
|
|
|
|
".jpeg" => "image/jpeg",
|
|
|
|
".png" => "image/png",
|
|
|
|
".xbm" => "image/x-xbitmap",
|
|
|
|
".xpm" => "image/x-xpixmap",
|
|
|
|
".xwd" => "image/x-xwindowdump",
|
|
|
|
".css" => "text/css",
|
|
|
|
".html" => "text/html",
|
|
|
|
".htm" => "text/html",
|
|
|
|
".js" => "text/javascript",
|
|
|
|
".asc" => "text/plain",
|
|
|
|
".c" => "text/plain",
|
|
|
|
".conf" => "text/plain",
|
|
|
|
".text" => "text/plain",
|
|
|
|
".txt" => "text/plain",
|
|
|
|
".dtd" => "text/xml",
|
|
|
|
".xml" => "text/xml",
|
|
|
|
".mpeg" => "video/mpeg",
|
|
|
|
".mpg" => "video/mpeg",
|
|
|
|
".mov" => "video/quicktime",
|
|
|
|
".qt" => "video/quicktime",
|
|
|
|
".avi" => "video/x-msvideo",
|
|
|
|
".asf" => "video/x-ms-asf",
|
|
|
|
".asx" => "video/x-ms-asf",
|
|
|
|
".wmv" => "video/x-ms-wmv",
|
|
|
|
".bz2" => "application/x-bzip",
|
|
|
|
".tbz" => "application/x-bzip-compressed-tar",
|
|
|
|
".tar.bz2" => "application/x-bzip-compressed-tar"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Use the "Content-Type" extended attribute to obtain mime type if possible
|
|
|
|
#mimetypes.use-xattr = "enable"
|
|
|
|
|
|
|
|
## deny access the file-extensions
|
|
|
|
#
|
|
|
|
# ~ is for backupfiles from vi, emacs, joe, ...
|
|
|
|
# .inc is often used for code includes which should in general not be part
|
|
|
|
# of the document-root
|
|
|
|
url.access-deny = ( "~", ".inc" )
|
|
|
|
|
|
|
|
|
|
|
|
######### Options that are good to be but not neccesary to be changed #######
|
|
|
|
|
|
|
|
## bind to port (default: 80)
|
2010-11-03 14:25:54 +01:00
|
|
|
|
|
|
|
EOD;
|
|
|
|
|
2012-08-01 09:30:35 +02:00
|
|
|
$lighty_config .= "server.bind = \"0.0.0.0\"\n";
|
|
|
|
$lighty_config .= "server.port = {$lighty_port}\n";
|
|
|
|
$lighty_config .= "\$SERVER[\"socket\"] == \"0.0.0.0:{$lighty_port}\" { }\n";
|
|
|
|
$lighty_config .= "\$SERVER[\"socket\"] == \"[::]:{$lighty_port}\" { \n";
|
|
|
|
if($cert <> "" and $key <> "") {
|
|
|
|
$lighty_config .= "\n";
|
|
|
|
$lighty_config .= "## ssl configuration\n";
|
|
|
|
$lighty_config .= "ssl.engine = \"enable\"\n";
|
|
|
|
$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
|
|
|
|
if($ca <> "")
|
|
|
|
$lighty_config .= "ssl.ca-file = \"{$g['varetc_path']}/{$ca_location}\"\n\n";
|
2010-11-11 16:26:49 +01:00
|
|
|
}
|
2012-08-01 09:30:35 +02:00
|
|
|
$lighty_config .= " }\n";
|
2010-11-11 16:26:49 +01:00
|
|
|
|
2010-11-03 14:25:54 +01:00
|
|
|
|
|
|
|
$lighty_config .= <<<EOD
|
2005-09-17 20:57:25 +02:00
|
|
|
|
|
|
|
## error-handler for status 404
|
|
|
|
#server.error-handler-404 = "/error-handler.html"
|
|
|
|
#server.error-handler-404 = "/error-handler.php"
|
|
|
|
|
|
|
|
## to help the rc.scripts
|
2013-02-05 17:12:59 +01:00
|
|
|
server.pid-file = "{$g['varrun_path']}/{$pid_file}"
|
2005-09-17 20:57:25 +02:00
|
|
|
|
|
|
|
## virtual directory listings
|
2005-09-17 21:31:27 +02:00
|
|
|
server.dir-listing = "disable"
|
2005-09-17 20:57:25 +02:00
|
|
|
|
|
|
|
## enable debugging
|
2005-09-17 21:31:27 +02:00
|
|
|
debug.log-request-header = "disable"
|
|
|
|
debug.log-response-header = "disable"
|
|
|
|
debug.log-request-handling = "disable"
|
|
|
|
debug.log-file-not-found = "disable"
|
2005-09-17 20:57:25 +02:00
|
|
|
|
2009-12-02 21:49:58 +01:00
|
|
|
# gzip compression
|
2009-12-28 10:41:47 +01:00
|
|
|
compress.cache-dir = "{$g['tmp_path']}/lighttpdcompress/"
|
2009-12-02 21:49:58 +01:00
|
|
|
compress.filetype = ("text/plain","text/css", "text/xml", "text/javascript" )
|
|
|
|
|
2007-12-10 22:52:59 +01:00
|
|
|
{$server_upload_dirs}
|
2006-09-01 20:08:42 +02:00
|
|
|
|
2007-12-10 23:00:11 +01:00
|
|
|
{$server_max_request_size}
|
2006-09-01 23:53:00 +02:00
|
|
|
|
2005-09-18 22:36:16 +02:00
|
|
|
{$fastcgi_config}
|
|
|
|
|
2013-01-21 15:35:31 +01:00
|
|
|
{$cgi_config}
|
|
|
|
|
2006-10-10 01:54:25 +02:00
|
|
|
{$captive_portal_mod_evasive}
|
|
|
|
|
2008-07-27 06:05:42 +02:00
|
|
|
expire.url = (
|
2008-08-12 04:50:02 +02:00
|
|
|
"" => "access 50 hours",
|
2008-07-27 06:05:42 +02:00
|
|
|
)
|
|
|
|
|
2005-09-17 20:57:25 +02:00
|
|
|
EOD;
|
|
|
|
|
2006-03-11 01:55:31 +01:00
|
|
|
$cert = str_replace("\r", "", $cert);
|
2006-07-10 01:48:33 +02:00
|
|
|
$key = str_replace("\r", "", $key);
|
2009-05-24 08:36:21 +02:00
|
|
|
$ca = str_replace("\r", "", $ca);
|
2006-03-11 01:55:31 +01:00
|
|
|
|
|
|
|
$cert = str_replace("\n\n", "\n", $cert);
|
2006-07-10 01:48:33 +02:00
|
|
|
$key = str_replace("\n\n", "\n", $key);
|
2009-05-24 08:36:21 +02:00
|
|
|
$ca = str_replace("\n\n", "\n", $ca);
|
2006-03-11 01:55:31 +01:00
|
|
|
|
2005-09-17 20:57:25 +02:00
|
|
|
if($cert <> "" and $key <> "") {
|
2005-09-18 04:21:42 +02:00
|
|
|
$fd = fopen("{$g['varetc_path']}/{$cert_location}", "w");
|
2004-11-07 04:06:49 +01:00
|
|
|
if (!$fd) {
|
2010-08-17 22:23:58 +02:00
|
|
|
printf(gettext("Error: cannot open cert.pem in system_webgui_start().%s"), "\n");
|
2004-11-07 04:06:49 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2005-09-18 04:21:42 +02:00
|
|
|
chmod("{$g['varetc_path']}/{$cert_location}", 0600);
|
2004-11-07 04:06:49 +01:00
|
|
|
fwrite($fd, $cert);
|
|
|
|
fwrite($fd, "\n");
|
|
|
|
fwrite($fd, $key);
|
|
|
|
fclose($fd);
|
2011-01-14 18:20:16 +01:00
|
|
|
if(!(empty($ca) || (strlen(trim($ca)) == 0))) {
|
2009-05-24 08:36:21 +02:00
|
|
|
$fd = fopen("{$g['varetc_path']}/{$ca_location}", "w");
|
|
|
|
if (!$fd) {
|
2010-08-17 22:23:58 +02:00
|
|
|
printf(gettext("Error: cannot open ca.pem in system_webgui_start().%s"), "\n");
|
2009-05-24 08:36:21 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
chmod("{$g['varetc_path']}/{$ca_location}", 0600);
|
|
|
|
fwrite($fd, $ca);
|
|
|
|
fclose($fd);
|
|
|
|
}
|
2009-03-01 02:19:24 +01:00
|
|
|
$lighty_config .= "\n";
|
2010-08-17 22:23:58 +02:00
|
|
|
$lighty_config .= "## " . gettext("ssl configuration") . "\n";
|
2005-09-17 20:57:25 +02:00
|
|
|
$lighty_config .= "ssl.engine = \"enable\"\n";
|
2006-07-10 01:48:33 +02:00
|
|
|
$lighty_config .= "ssl.pemfile = \"{$g['varetc_path']}/{$cert_location}\"\n\n";
|
2011-04-19 23:06:00 +02:00
|
|
|
|
2014-11-04 20:31:38 +01:00
|
|
|
// SSLv2/3 is deprecated, force use of TLS
|
2011-04-19 23:06:00 +02:00
|
|
|
$lighty_config .= "ssl.use-sslv2 = \"disable\"\n";
|
2014-10-15 14:40:36 +02:00
|
|
|
$lighty_config .= "ssl.use-sslv3 = \"disable\"\n";
|
2013-07-18 15:30:20 +02:00
|
|
|
|
|
|
|
/* Hifn accelerators do NOT work with the BEAST mitigation code. Do not allow it to be enabled if a Hifn card has been detected. */
|
|
|
|
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
|
|
|
|
if ($fd) {
|
|
|
|
while (!feof($fd)) {
|
|
|
|
$dmesgl = fgets($fd);
|
|
|
|
if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches) && isset($config['system']['webgui']['beast_protection'])) {
|
|
|
|
unset($config['system']['webgui']['beast_protection']);
|
|
|
|
log_error("BEAST Protection disabled because a conflicting cryptographic accelerator card has been detected (" . $matches[1] . ")");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['system']['webgui']['beast_protection'])) {
|
|
|
|
$lighty_config .= "ssl.honor-cipher-order = \"enable\"\n";
|
|
|
|
$lighty_config .= "ssl.cipher-list = \"ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM\"\n";
|
|
|
|
} else {
|
|
|
|
$lighty_config .= "ssl.cipher-list = \"DHE-RSA-CAMELLIA256-SHA:DHE-DSS-CAMELLIA256-SHA:CAMELLIA256-SHA:DHE-DSS-AES256-SHA:AES256-SHA:DHE-RSA-CAMELLIA128-SHA:DHE-DSS-CAMELLIA128-SHA:CAMELLIA128-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:AES128-SHA:RC4-SHA:RC4-MD5:!aNULL:!eNULL:!3DES:@STRENGTH\"\n";
|
|
|
|
}
|
2011-04-19 23:06:00 +02:00
|
|
|
|
2011-01-14 20:14:58 +01:00
|
|
|
if(!(empty($ca) || (strlen(trim($ca)) == 0)))
|
2009-05-24 08:36:21 +02:00
|
|
|
$lighty_config .= "ssl.ca-file = \"{$g['varetc_path']}/{$ca_location}\"\n\n";
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
2010-01-05 05:37:32 +01:00
|
|
|
|
|
|
|
// Add HTTP to HTTPS redirect
|
2012-08-01 09:30:35 +02:00
|
|
|
if ($captive_portal === false && $config['system']['webgui']['protocol'] == "https" && !isset($config['system']['webgui']['disablehttpredirect'])) {
|
2009-12-28 00:39:48 +01:00
|
|
|
if($lighty_port != "443")
|
|
|
|
$redirectport = ":{$lighty_port}";
|
2009-12-28 00:08:02 +01:00
|
|
|
$lighty_config .= <<<EOD
|
|
|
|
\$SERVER["socket"] == ":80" {
|
|
|
|
\$HTTP["host"] =~ "(.*)" {
|
2009-12-28 00:39:48 +01:00
|
|
|
url.redirect = ( "^/(.*)" => "https://%1{$redirectport}/$1" )
|
2009-12-28 00:08:02 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 18:20:39 +02:00
|
|
|
\$SERVER["socket"] == "[::]:80" {
|
|
|
|
\$HTTP["host"] =~ "(.*)" {
|
|
|
|
url.redirect = ( "^/(.*)" => "https://%1{$redirectport}/$1" )
|
|
|
|
}
|
|
|
|
}
|
2009-12-28 00:08:02 +01:00
|
|
|
EOD;
|
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2005-11-27 04:15:44 +01:00
|
|
|
$fd = fopen("{$filename}", "w");
|
2005-09-17 20:57:25 +02:00
|
|
|
if (!$fd) {
|
2010-08-17 22:23:58 +02:00
|
|
|
printf(gettext("Error: cannot open %s in system_generate_lighty_config().%s"), $filename, "\n");
|
2005-09-17 20:57:25 +02:00
|
|
|
return 1;
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
2005-09-17 20:57:25 +02:00
|
|
|
fwrite($fd, $lighty_config);
|
|
|
|
fclose($fd);
|
|
|
|
|
|
|
|
return 0;
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function system_timezone_configure() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_timezone_configure() being called $mt\n";
|
2006-07-10 01:48:33 +02:00
|
|
|
}
|
2004-11-07 04:06:49 +01:00
|
|
|
|
|
|
|
$syscfg = $config['system'];
|
|
|
|
|
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("Setting timezone...");
|
2004-11-07 04:06:49 +01:00
|
|
|
|
|
|
|
/* extract appropriate timezone file */
|
|
|
|
$timezone = $syscfg['timezone'];
|
2013-11-01 15:21:54 +01:00
|
|
|
if ($timezone) {
|
|
|
|
exec('/usr/bin/tar -tvzf /usr/share/zoneinfo.tgz', $tzs);
|
|
|
|
foreach ($tzs as $tz) {
|
|
|
|
if (preg_match(",{$timezone}$,", $tz))
|
|
|
|
break;
|
|
|
|
if (preg_match(",{$timezone} link to *(.*)$,", $tz, $matches)) {
|
|
|
|
$timezone = $matches[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2004-11-07 04:06:49 +01:00
|
|
|
$timezone = "Etc/UTC";
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2005-03-20 21:25:52 +01:00
|
|
|
conf_mount_rw();
|
|
|
|
|
2006-11-10 17:06:03 +01:00
|
|
|
exec("LANG=C /usr/bin/tar xzfO /usr/share/zoneinfo.tgz " .
|
2004-11-07 04:06:49 +01:00
|
|
|
escapeshellarg($timezone) . " > /etc/localtime");
|
|
|
|
|
2008-02-14 19:40:01 +01:00
|
|
|
mwexec("sync");
|
2005-03-20 20:59:28 +01:00
|
|
|
conf_mount_ro();
|
2005-03-20 21:25:52 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("done.") . "\n";
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
2012-08-21 22:22:31 +02:00
|
|
|
function system_ntp_setup_gps($serialport) {
|
2014-02-18 15:12:43 +01:00
|
|
|
global $config, $g;
|
2012-08-21 22:22:31 +02:00
|
|
|
$gps_device = '/dev/gps0';
|
|
|
|
$serialport = '/dev/'.$serialport;
|
|
|
|
|
|
|
|
if (!file_exists($serialport))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
conf_mount_rw();
|
|
|
|
// Create symlink that ntpd requires
|
|
|
|
unlink_if_exists($gps_device);
|
|
|
|
symlink($serialport, $gps_device);
|
|
|
|
|
|
|
|
/* Send the following to the GPS port to initialize the GPS */
|
2014-02-19 16:43:37 +01:00
|
|
|
if (is_array($config['ntpd']) && is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['type'])) {
|
2014-02-18 15:12:43 +01:00
|
|
|
$gps_init = base64_decode($config['ntpd']['gps']['initcmd']);
|
|
|
|
}else{
|
|
|
|
$gps_init = base64_decode('JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ==');
|
|
|
|
}
|
2014-02-19 16:43:37 +01:00
|
|
|
|
|
|
|
/* XXX: Why not file_put_contents to the device */
|
|
|
|
@file_put_contents('/tmp/gps.init', $gps_init);
|
2012-08-21 22:47:44 +02:00
|
|
|
`cat /tmp/gps.init > $serialport`;
|
2012-08-21 22:22:31 +02:00
|
|
|
|
|
|
|
/* Add /etc/remote entry in case we need to read from the GPS with tip */
|
2014-02-19 16:43:37 +01:00
|
|
|
if (intval(`grep -c '^gps0' /etc/remote`) == 0) {
|
2014-02-18 15:12:43 +01:00
|
|
|
$gpsbaud = '4800';
|
2014-02-19 16:43:37 +01:00
|
|
|
if (is_array($config['ntpd']) && is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['speed'])) {
|
2014-02-18 15:12:43 +01:00
|
|
|
switch($config['ntpd']['gps']['speed']) {
|
|
|
|
case '16':
|
|
|
|
$gpsbaud = '9600';
|
|
|
|
break;
|
|
|
|
case '32':
|
|
|
|
$gpsbaud = '19200';
|
|
|
|
break;
|
|
|
|
case '48':
|
|
|
|
$gpsbaud = '38400';
|
|
|
|
break;
|
|
|
|
case '64':
|
|
|
|
$gpsbaud = '57600';
|
|
|
|
break;
|
|
|
|
case '80':
|
|
|
|
$gpsbaud = '115200';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-19 16:43:37 +01:00
|
|
|
@file_put_contents("/etc/remote", "gps0:dv={$serialport}:br#{$gpsbaud}:pa=none:", FILE_APPEND);
|
|
|
|
}
|
2012-08-21 22:22:31 +02:00
|
|
|
|
|
|
|
conf_mount_ro();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-18 15:12:43 +01:00
|
|
|
function system_ntp_setup_pps($serialport) {
|
|
|
|
global $config, $g;
|
2014-02-19 16:43:37 +01:00
|
|
|
|
2014-02-18 15:12:43 +01:00
|
|
|
$pps_device = '/dev/pps0';
|
|
|
|
$serialport = '/dev/'.$serialport;
|
|
|
|
|
|
|
|
if (!file_exists($serialport))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
conf_mount_rw();
|
|
|
|
// Create symlink that ntpd requires
|
|
|
|
unlink_if_exists($pps_device);
|
2014-02-19 16:43:37 +01:00
|
|
|
@symlink($serialport, $pps_device);
|
2014-02-18 15:12:43 +01:00
|
|
|
|
|
|
|
conf_mount_ro();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-16 16:48:26 +02:00
|
|
|
function system_ntp_configure($start_ntpd=true) {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2014-02-19 16:43:37 +01:00
|
|
|
|
2012-05-14 21:44:37 +02:00
|
|
|
$driftfile = "/var/db/ntpd.drift";
|
2012-08-21 22:22:31 +02:00
|
|
|
$statsdir = "/var/log/ntp";
|
|
|
|
$gps_device = '/dev/gps0';
|
2004-11-07 04:06:49 +01:00
|
|
|
|
2011-08-17 04:15:18 +02:00
|
|
|
if ($g['platform'] == 'jail')
|
|
|
|
return;
|
|
|
|
|
2012-08-21 22:22:31 +02:00
|
|
|
safe_mkdir($statsdir);
|
|
|
|
|
2014-02-19 16:43:37 +01:00
|
|
|
if (!is_array($config['ntpd']))
|
|
|
|
$config['ntpd'] = array();
|
|
|
|
|
2011-03-18 23:09:33 +01:00
|
|
|
$ntpcfg = "# \n";
|
2012-05-14 21:44:37 +02:00
|
|
|
$ntpcfg .= "# pfSense ntp configuration file \n";
|
2011-03-18 23:09:33 +01:00
|
|
|
$ntpcfg .= "# \n\n";
|
2012-09-24 01:21:00 +02:00
|
|
|
$ntpcfg .= "tinker panic 0 \n";
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2014-02-18 15:12:43 +01:00
|
|
|
/* Add Orphan mode */
|
|
|
|
$ntpcfg .= "# Orphan mode stratum\n";
|
|
|
|
$ntpcfg .= 'tos orphan ';
|
|
|
|
if (!empty($config['ntpd']['orphan'])) {
|
|
|
|
$ntpcfg .= $config['ntpd']['orphan'];
|
|
|
|
}else{
|
|
|
|
$ntpcfg .= '12';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
|
|
|
|
/* Add PPS configuration */
|
|
|
|
if (!empty($config['ntpd']['pps'])
|
|
|
|
&& file_exists('/dev/'.$config['ntpd']['pps']['port'])
|
|
|
|
&& system_ntp_setup_pps($config['ntpd']['pps']['port'])) {
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
$ntpcfg .= "# PPS Setup\n";
|
|
|
|
$ntpcfg .= 'server 127.127.22.0';
|
|
|
|
$ntpcfg .= ' minpoll 4 maxpoll 4';
|
|
|
|
if (empty($config['ntpd']['pps']['prefer'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' prefer';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['pps']['noselect'])) {
|
|
|
|
$ntpcfg .= ' noselect ';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
$ntpcfg .= 'fudge 127.127.22.0';
|
|
|
|
if (!empty($config['ntpd']['pps']['fudge1'])) {
|
|
|
|
$ntpcfg .= ' time1 ';
|
|
|
|
$ntpcfg .= $config['ntpd']['pps']['fudge1'];
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['pps']['flag2'])) {
|
|
|
|
$ntpcfg .= ' flag2 1';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['pps']['flag3'])) {
|
|
|
|
$ntpcfg .= ' flag3 1';
|
|
|
|
}else{
|
|
|
|
$ntpcfg .= ' flag3 0';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['pps']['flag4'])) {
|
|
|
|
$ntpcfg .= ' flag4 1';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['pps']['refid'])) {
|
|
|
|
$ntpcfg .= ' refid ';
|
|
|
|
$ntpcfg .= $config['ntpd']['pps']['refid'];
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
}
|
|
|
|
/* End PPS configuration */
|
|
|
|
|
|
|
|
/* Add GPS configuration */
|
|
|
|
if (!empty($config['ntpd']['gps'])
|
|
|
|
&& file_exists('/dev/'.$config['ntpd']['gps']['port'])
|
|
|
|
&& system_ntp_setup_gps($config['ntpd']['gps']['port'])) {
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
$ntpcfg .= "# GPS Setup\n";
|
|
|
|
$ntpcfg .= 'server 127.127.20.0 mode ';
|
|
|
|
if (!empty($config['ntpd']['gps']['nmea']) || !empty($config['ntpd']['gps']['speed']) || !empty($config['ntpd']['gps']['subsec'])) {
|
|
|
|
if (!empty($config['ntpd']['gps']['nmea'])) {
|
|
|
|
$ntpmode = (int) $config['ntpd']['gps']['nmea'];
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['speed'])) {
|
|
|
|
$ntpmode += (int) $config['ntpd']['gps']['speed'];
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['subsec'])) {
|
|
|
|
$ntpmode += 128;
|
|
|
|
}
|
|
|
|
$ntpcfg .= (string) $ntpmode;
|
|
|
|
}else{
|
|
|
|
$ntpcfg .= '0';
|
|
|
|
}
|
|
|
|
$ntpcfg .= ' minpoll 4 maxpoll 4';
|
|
|
|
if (empty($config['ntpd']['gps']['prefer'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' prefer';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['noselect'])) {
|
|
|
|
$ntpcfg .= ' noselect ';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
$ntpcfg .= 'fudge 127.127.20.0';
|
|
|
|
if (!empty($config['ntpd']['gps']['fudge1'])) {
|
|
|
|
$ntpcfg .= ' time1 ';
|
|
|
|
$ntpcfg .= $config['ntpd']['gps']['fudge1'];
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['fudge2'])) {
|
|
|
|
$ntpcfg .= ' time2 ';
|
|
|
|
$ntpcfg .= $config['ntpd']['gps']['fudge2'];
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['flag1'])) {
|
|
|
|
$ntpcfg .= ' flag1 1';
|
|
|
|
}else{
|
|
|
|
$ntpcfg .= ' flag1 0';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['flag2'])) {
|
|
|
|
$ntpcfg .= ' flag2 1';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['flag3'])) {
|
|
|
|
$ntpcfg .= ' flag3 1';
|
|
|
|
}else{
|
|
|
|
$ntpcfg .= ' flag3 0';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['flag4'])) {
|
|
|
|
$ntpcfg .= ' flag4 1';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['gps']['refid'])) {
|
|
|
|
$ntpcfg .= ' refid ';
|
|
|
|
$ntpcfg .= $config['ntpd']['gps']['refid'];
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
}elseif (!empty($config['ntpd']['gpsport'])
|
2012-08-21 22:22:31 +02:00
|
|
|
&& file_exists('/dev/'.$config['ntpd']['gpsport'])
|
|
|
|
&& system_ntp_setup_gps($config['ntpd']['gpsport'])) {
|
2014-02-18 15:12:43 +01:00
|
|
|
/* This handles a 2.1 and earlier config */
|
2012-08-21 22:22:31 +02:00
|
|
|
$ntpcfg .= "# GPS Setup\n";
|
|
|
|
$ntpcfg .= "server 127.127.20.0 mode 0 minpoll 4 maxpoll 4 prefer\n";
|
|
|
|
$ntpcfg .= "fudge 127.127.20.0 time1 0.155 time2 0.000 flag1 1 flag2 0 flag3 1\n";
|
|
|
|
// Fall back to local clock if GPS is out of sync?
|
|
|
|
$ntpcfg .= "server 127.127.1.0\n";
|
|
|
|
$ntpcfg .= "fudge 127.127.1.0 stratum 12\n";
|
|
|
|
}
|
2014-02-18 15:12:43 +01:00
|
|
|
/* End GPS configuration */
|
|
|
|
|
2012-08-21 22:22:31 +02:00
|
|
|
$ntpcfg .= "\n\n# Upstream Servers\n";
|
2014-02-18 15:12:43 +01:00
|
|
|
/* foreach through ntp servers and write out to ntpd.conf */
|
|
|
|
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
|
|
|
|
$ntpcfg .= "server {$ts} iburst maxpoll 9";
|
|
|
|
if (substr_count($config['ntpd']['prefer'], $ts)) $ntpcfg .= ' prefer';
|
|
|
|
if (substr_count($config['ntpd']['noselect'], $ts)) $ntpcfg .= ' noselect';
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
}
|
|
|
|
unset($ts);
|
|
|
|
|
|
|
|
$ntpcfg .= "\n\n";
|
2014-03-15 01:30:56 +01:00
|
|
|
$ntpcfg .= "disable monitor\n"; //prevent NTP reflection attack, see https://forum.pfsense.org/index.php/topic,67189.msg389132.html#msg389132
|
2014-02-18 15:12:43 +01:00
|
|
|
if (!empty($config['ntpd']['clockstats']) || !empty($config['ntpd']['loopstats']) || !empty($config['ntpd']['peerstats'])) {
|
|
|
|
$ntpcfg .= "enable stats\n";
|
|
|
|
$ntpcfg .= 'statistics';
|
|
|
|
if (!empty($config['ntpd']['clockstats'])) {
|
|
|
|
$ntpcfg .= ' clockstats';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['loopstats'])) {
|
|
|
|
$ntpcfg .= ' loopstats';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['peerstats'])) {
|
|
|
|
$ntpcfg .= ' peerstats';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
}
|
2012-08-21 22:22:31 +02:00
|
|
|
$ntpcfg .= "statsdir {$statsdir}\n";
|
2014-02-18 15:12:43 +01:00
|
|
|
$ntpcfg .= 'logconfig =syncall +clockall';
|
|
|
|
if (!empty($config['ntpd']['logpeer'])) {
|
|
|
|
$ntpcfg .= ' +peerall';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['logsys'])) {
|
|
|
|
$ntpcfg .= ' +sysall';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
2012-05-14 21:44:37 +02:00
|
|
|
$ntpcfg .= "driftfile {$driftfile}\n";
|
2014-02-18 15:12:43 +01:00
|
|
|
/* Access restrictions */
|
|
|
|
$ntpcfg .= 'restrict default';
|
|
|
|
if (empty($config['ntpd']['kod'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' kod limited';
|
|
|
|
}
|
|
|
|
if (empty($config['ntpd']['nomodify'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' nomodify';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['noquery'])) {
|
|
|
|
$ntpcfg .= ' noquery';
|
|
|
|
}
|
|
|
|
if (empty($config['ntpd']['nopeer'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' nopeer';
|
|
|
|
}
|
|
|
|
if (empty($config['ntpd']['notrap'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' notrap';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['noserve'])) {
|
|
|
|
$ntpcfg .= ' noserve';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\nrestrict -6 default";
|
|
|
|
if (empty($config['ntpd']['kod'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' kod limited';
|
|
|
|
}
|
|
|
|
if (empty($config['ntpd']['nomodify'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' nomodify';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['noquery'])) {
|
|
|
|
$ntpcfg .= ' noquery';
|
|
|
|
}
|
|
|
|
if (empty($config['ntpd']['nopeer'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' nopeer';
|
|
|
|
}
|
|
|
|
if (!empty($config['ntpd']['noserve'])) {
|
|
|
|
$ntpcfg .= ' noserve';
|
|
|
|
}
|
|
|
|
if (empty($config['ntpd']['notrap'])) { /*note: this one works backwards */
|
|
|
|
$ntpcfg .= ' notrap';
|
|
|
|
}
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
|
|
|
|
/* A leapseconds file is really only useful if this clock is stratum 1 */
|
|
|
|
$ntpcfg .= "\n";
|
|
|
|
if (!empty($config['ntpd']['leapsec'])) {
|
|
|
|
$leapsec .= base64_decode($config['ntpd']['leapsec']);
|
|
|
|
file_put_contents('/var/db/leap-seconds', $leapsec);
|
|
|
|
$ntpcfg .= "leapfile /var/db/leap-seconds\n";
|
|
|
|
}
|
|
|
|
|
2007-03-20 18:24:17 +01:00
|
|
|
|
2012-05-30 18:44:55 +02:00
|
|
|
if (empty($config['ntpd']['interface']))
|
2012-07-08 17:48:59 +02:00
|
|
|
if (is_array($config['installedpackages']['openntpd']) && !empty($config['installedpackages']['openntpd']['config'][0]['interface']))
|
2012-05-30 18:44:55 +02:00
|
|
|
$interfaces = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
|
|
|
|
else
|
|
|
|
$interfaces = array();
|
|
|
|
else
|
|
|
|
$interfaces = explode(",", $config['ntpd']['interface']);
|
|
|
|
|
|
|
|
if (is_array($interfaces) && count($interfaces)) {
|
|
|
|
$ntpcfg .= "interface ignore all\n";
|
|
|
|
foreach ($interfaces as $interface) {
|
|
|
|
if (!is_ipaddr($interface)) {
|
|
|
|
$interface = get_real_interface($interface);
|
|
|
|
}
|
2014-03-20 17:08:37 +01:00
|
|
|
if (!empty($interface))
|
|
|
|
$ntpcfg .= "interface listen {$interface}\n";
|
2012-05-30 18:44:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 23:09:33 +01:00
|
|
|
/* open configuration for wrting or bail */
|
2013-02-09 22:17:16 +01:00
|
|
|
if (!@file_put_contents("{$g['varetc_path']}/ntpd.conf", $ntpcfg)) {
|
2011-03-18 23:09:33 +01:00
|
|
|
log_error("Could not open {$g['varetc_path']}/ntpd.conf for writing");
|
|
|
|
return;
|
|
|
|
}
|
2006-10-02 23:12:58 +02:00
|
|
|
|
2012-05-16 16:48:26 +02:00
|
|
|
/* At bootup we just want to write out the config. */
|
|
|
|
if (!$start_ntpd)
|
|
|
|
return;
|
|
|
|
|
2012-05-14 21:44:37 +02:00
|
|
|
/* if ntpd is running, kill it */
|
2013-02-10 12:13:58 +01:00
|
|
|
while (isvalidpid("{$g['varrun_path']}/ntpd.pid")) {
|
2013-02-09 22:17:16 +01:00
|
|
|
killbypid("{$g['varrun_path']}/ntpd.pid");
|
2006-10-03 02:18:32 +02:00
|
|
|
}
|
2013-02-09 22:17:16 +01:00
|
|
|
@unlink("{$g['varrun_path']}/ntpd.pid");
|
2006-10-03 02:18:32 +02:00
|
|
|
|
|
|
|
/* if /var/empty does not exist, create it */
|
|
|
|
if(!is_dir("/var/empty"))
|
2014-02-18 16:06:07 +01:00
|
|
|
mkdir("/var/empty", 0775, true);
|
2006-10-03 02:18:32 +02:00
|
|
|
|
2006-10-02 23:12:58 +02:00
|
|
|
/* start opentpd, set time now and use /var/etc/ntpd.conf */
|
2014-02-18 16:06:07 +01:00
|
|
|
mwexec("/usr/local/sbin/ntpd -g -c {$g['varetc_path']}/ntpd.conf -p {$g['varrun_path']}/ntpd.pid", false, true);
|
2009-08-24 23:47:19 +02:00
|
|
|
|
|
|
|
// Note that we are starting up
|
2012-05-14 21:44:37 +02:00
|
|
|
log_error("NTPD is starting up.");
|
2012-05-16 16:48:26 +02:00
|
|
|
return;
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
2007-02-20 09:08:04 +01:00
|
|
|
function sync_system_time() {
|
|
|
|
global $config, $g;
|
|
|
|
|
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("Syncing system time before startup...");
|
2007-02-20 09:08:04 +01:00
|
|
|
|
|
|
|
/* foreach through servers and write out to ntpd.conf */
|
2011-03-18 23:09:33 +01:00
|
|
|
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
|
2014-01-15 18:35:50 +01:00
|
|
|
mwexec("/usr/local/sbin/ntpdate -s $ts");
|
2007-02-20 09:08:04 +01:00
|
|
|
}
|
2007-03-09 00:19:11 +01:00
|
|
|
|
|
|
|
if ($g['booting'])
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("done.") . "\n";
|
2007-03-09 00:19:11 +01:00
|
|
|
|
2007-02-20 09:08:04 +01:00
|
|
|
}
|
|
|
|
|
2004-12-28 21:52:33 +01:00
|
|
|
function system_halt() {
|
|
|
|
global $g;
|
|
|
|
|
|
|
|
system_reboot_cleanup();
|
|
|
|
|
2009-09-12 21:34:07 +02:00
|
|
|
mwexec("/usr/bin/nohup /etc/rc.halt > /dev/null 2>&1 &");
|
2004-12-28 21:52:33 +01:00
|
|
|
}
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
function system_reboot() {
|
|
|
|
global $g;
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
system_reboot_cleanup();
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &");
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_reboot_sync() {
|
|
|
|
global $g;
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
system_reboot_cleanup();
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
mwexec("/etc/rc.reboot > /dev/null 2>&1");
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_reboot_cleanup() {
|
2013-02-15 00:19:06 +01:00
|
|
|
global $config, $cpzone;
|
|
|
|
|
2005-10-01 20:32:21 +02:00
|
|
|
mwexec("/usr/local/bin/beep.sh stop");
|
2009-11-29 17:48:53 +01:00
|
|
|
require_once("captiveportal.inc");
|
2013-02-25 13:32:11 +01:00
|
|
|
if (is_array($config['captiveportal'])) {
|
2013-02-18 03:21:48 +01:00
|
|
|
foreach ($config['captiveportal'] as $cpzone=>$cp) {
|
|
|
|
captiveportal_radius_stop_all();
|
|
|
|
captiveportal_send_server_accounting(true);
|
|
|
|
}
|
2013-02-15 00:19:06 +01:00
|
|
|
}
|
2009-06-13 19:24:28 +02:00
|
|
|
require_once("voucher.inc");
|
|
|
|
voucher_save_db_to_config();
|
2012-04-30 21:32:47 +02:00
|
|
|
require_once("pkg-utils.inc");
|
|
|
|
stop_packages();
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function system_do_shell_commands($early = 0) {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_do_shell_commands() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
if ($early)
|
|
|
|
$cmdn = "earlyshellcmd";
|
|
|
|
else
|
|
|
|
$cmdn = "shellcmd";
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
if (is_array($config['system'][$cmdn])) {
|
2006-07-10 01:48:33 +02:00
|
|
|
|
2005-10-05 03:05:19 +02:00
|
|
|
/* *cmd is an array, loop through */
|
2004-11-07 04:06:49 +01:00
|
|
|
foreach ($config['system'][$cmdn] as $cmd) {
|
|
|
|
exec($cmd);
|
|
|
|
}
|
2005-10-05 03:05:19 +02:00
|
|
|
|
|
|
|
} elseif($config['system'][$cmdn] <> "") {
|
2006-07-10 01:48:33 +02:00
|
|
|
|
2005-10-05 03:05:19 +02:00
|
|
|
/* execute single item */
|
|
|
|
exec($config['system'][$cmdn]);
|
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_console_configure() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config, $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_console_configure() being called $mt\n";
|
2006-07-10 01:48:33 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
if (isset($config['system']['disableconsolemenu'])) {
|
|
|
|
touch("{$g['varetc_path']}/disableconsole");
|
|
|
|
} else {
|
|
|
|
unlink_if_exists("{$g['varetc_path']}/disableconsole");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_dmesg_save() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $g;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_dmesg_save() being called $mt\n";
|
2005-10-12 03:10:10 +02:00
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2006-01-15 04:33:18 +01:00
|
|
|
$dmesg = "";
|
2014-03-14 21:35:39 +01:00
|
|
|
$_gb = exec("/sbin/dmesg", $dmesg);
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
/* find last copyright line (output from previous boots may be present) */
|
|
|
|
$lastcpline = 0;
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
for ($i = 0; $i < count($dmesg); $i++) {
|
|
|
|
if (strstr($dmesg[$i], "Copyright (c) 1992-"))
|
|
|
|
$lastcpline = $i;
|
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
$fd = fopen("{$g['varlog_path']}/dmesg.boot", "w");
|
|
|
|
if (!$fd) {
|
2010-08-17 22:23:58 +02:00
|
|
|
printf(gettext("Error: cannot open dmesg.boot in system_dmesg_save().%s"), "\n");
|
2004-11-07 04:06:49 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
for ($i = $lastcpline; $i < count($dmesg); $i++)
|
|
|
|
fwrite($fd, $dmesg[$i] . "\n");
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
fclose($fd);
|
2014-03-14 21:35:39 +01:00
|
|
|
unset($dmesg);
|
2004-11-21 19:41:42 +01:00
|
|
|
|
2004-11-07 04:06:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_set_harddisk_standby() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $g, $config;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_set_harddisk_standby() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2004-11-07 04:06:49 +01:00
|
|
|
|
|
|
|
if (isset($config['system']['harddiskstandby'])) {
|
|
|
|
if ($g['booting']) {
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext('Setting hard disk standby... ');
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$standby = $config['system']['harddiskstandby'];
|
|
|
|
// Check for a numeric value
|
|
|
|
if (is_numeric($standby)) {
|
|
|
|
// Sync the disk(s)
|
2010-11-30 22:48:47 +01:00
|
|
|
pfSense_sync();
|
2014-07-08 01:06:37 +02:00
|
|
|
if (set_single_sysctl('hw.ata.standby', (int)$standby)) {
|
2004-11-07 04:06:49 +01:00
|
|
|
// Reinitialize ATA-drives
|
|
|
|
mwexec('/usr/local/sbin/atareinit');
|
|
|
|
if ($g['booting']) {
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("done.") . "\n";
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
} else if ($g['booting']) {
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("failed!") . "\n";
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
} else if ($g['booting']) {
|
2010-08-17 22:23:58 +02:00
|
|
|
echo gettext("failed!") . "\n";
|
2004-11-07 04:06:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-20 22:41:56 +01:00
|
|
|
function system_setup_sysctl() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_setup_sysctl() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2005-09-01 23:57:20 +02:00
|
|
|
|
2007-05-27 00:00:36 +02:00
|
|
|
activate_sysctls();
|
|
|
|
|
2005-09-01 23:57:20 +02:00
|
|
|
if (isset($config['system']['sharednet'])) {
|
|
|
|
system_disable_arp_wrong_if();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function system_disable_arp_wrong_if() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_disable_arp_wrong_if() being called $mt\n";
|
2006-07-10 01:48:33 +02:00
|
|
|
}
|
2014-07-08 01:06:37 +02:00
|
|
|
set_sysctl(array(
|
|
|
|
"net.link.ether.inet.log_arp_wrong_iface" => "0",
|
|
|
|
"net.link.ether.inet.log_arp_movements" => "0"
|
|
|
|
));
|
2005-02-20 22:41:56 +01:00
|
|
|
}
|
|
|
|
|
2005-09-01 23:57:20 +02:00
|
|
|
function system_enable_arp_wrong_if() {
|
2005-10-12 03:10:10 +02:00
|
|
|
global $config;
|
2005-10-12 01:44:53 +02:00
|
|
|
if(isset($config['system']['developerspew'])) {
|
|
|
|
$mt = microtime();
|
2005-10-12 03:04:23 +02:00
|
|
|
echo "system_enable_arp_wrong_if() being called $mt\n";
|
2005-10-12 01:44:53 +02:00
|
|
|
}
|
2014-07-08 01:06:37 +02:00
|
|
|
set_sysctl(array(
|
|
|
|
"net.link.ether.inet.log_arp_wrong_iface" => "1",
|
|
|
|
"net.link.ether.inet.log_arp_movements" => "1"
|
|
|
|
));
|
2005-09-01 23:57:20 +02:00
|
|
|
}
|
|
|
|
|
2006-04-27 18:53:38 +02:00
|
|
|
function enable_watchdog() {
|
|
|
|
global $config;
|
2009-06-22 18:30:53 +02:00
|
|
|
return;
|
2006-04-27 18:53:38 +02:00
|
|
|
$install_watchdog = false;
|
|
|
|
$supported_watchdogs = array("Geode");
|
|
|
|
$file = file_get_contents("/var/log/dmesg.boot");
|
|
|
|
foreach($supported_watchdogs as $sd) {
|
|
|
|
if(stristr($file, "Geode")) {
|
|
|
|
$install_watchdog = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($install_watchdog == true) {
|
2006-09-02 02:11:22 +02:00
|
|
|
if(is_process_running("watchdogd"))
|
2008-11-06 16:23:00 +01:00
|
|
|
mwexec("/usr/bin/killall watchdogd", true);
|
2006-07-10 01:48:33 +02:00
|
|
|
exec("/usr/sbin/watchdogd");
|
2006-04-27 18:53:38 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 23:27:15 +02:00
|
|
|
|
|
|
|
function system_check_reset_button() {
|
2010-05-18 23:59:41 +02:00
|
|
|
global $g;
|
2010-05-19 03:06:30 +02:00
|
|
|
if($g['platform'] != "nanobsd")
|
2010-05-18 23:59:41 +02:00
|
|
|
return 0;
|
2010-05-18 23:27:15 +02:00
|
|
|
|
2010-05-19 00:03:02 +02:00
|
|
|
$specplatform = system_identify_specific_platform();
|
|
|
|
|
2010-05-18 23:27:15 +02:00
|
|
|
if ($specplatform['name'] != "wrap" && $specplatform['name'] != "alix")
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
$retval = mwexec("/usr/local/sbin/" . $specplatform['name'] . "resetbtn");
|
|
|
|
|
|
|
|
if ($retval == 99) {
|
|
|
|
/* user has pressed reset button for 2 seconds -
|
|
|
|
reset to factory defaults */
|
|
|
|
echo <<<EOD
|
|
|
|
|
|
|
|
***********************************************************************
|
|
|
|
* Reset button pressed - resetting configuration to factory defaults. *
|
|
|
|
* The system will reboot after this completes. *
|
|
|
|
***********************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
EOD;
|
|
|
|
|
|
|
|
reset_factory_defaults();
|
|
|
|
system_reboot_sync();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-19 00:03:02 +02:00
|
|
|
/* attempt to identify the specific platform (for embedded systems)
|
|
|
|
Returns an array with two elements:
|
|
|
|
name => platform string (e.g. 'wrap', 'alix' etc.)
|
|
|
|
descr => human-readable description (e.g. "PC Engines WRAP")
|
|
|
|
*/
|
|
|
|
function system_identify_specific_platform() {
|
|
|
|
global $g;
|
|
|
|
|
|
|
|
if ($g['platform'] == 'generic-pc')
|
2010-08-17 22:23:58 +02:00
|
|
|
return array('name' => 'generic-pc', 'descr' => gettext("Generic PC"));
|
2010-05-19 00:03:02 +02:00
|
|
|
|
|
|
|
if ($g['platform'] == 'generic-pc-cdrom')
|
2010-08-17 22:23:58 +02:00
|
|
|
return array('name' => 'generic-pc-cdrom', 'descr' => gettext("Generic PC (CD-ROM)"));
|
2010-05-19 00:03:02 +02:00
|
|
|
|
|
|
|
/* the rest of the code only deals with 'embedded' platforms */
|
2010-05-19 03:16:46 +02:00
|
|
|
if ($g['platform'] != 'nanobsd')
|
2010-05-19 00:03:02 +02:00
|
|
|
return array('name' => $g['platform'], 'descr' => $g['platform']);
|
2014-03-11 16:40:07 +01:00
|
|
|
|
2014-07-08 01:06:37 +02:00
|
|
|
$dmesg = get_single_sysctl('hw.model');
|
2014-03-11 16:40:07 +01:00
|
|
|
|
2010-05-19 00:03:02 +02:00
|
|
|
if (strpos($dmesg, "PC Engines WRAP") !== false)
|
2010-08-17 22:23:58 +02:00
|
|
|
return array('name' => 'wrap', 'descr' => gettext('PC Engines WRAP'));
|
2010-05-19 00:03:02 +02:00
|
|
|
|
|
|
|
if (strpos($dmesg, "PC Engines ALIX") !== false)
|
2010-08-17 22:23:58 +02:00
|
|
|
return array('name' => 'alix', 'descr' => gettext('PC Engines ALIX'));
|
2010-05-19 00:03:02 +02:00
|
|
|
|
|
|
|
if (preg_match("/Soekris net45../", $dmesg, $matches))
|
|
|
|
return array('name' => 'net45xx', 'descr' => $matches[0]);
|
|
|
|
|
|
|
|
if (preg_match("/Soekris net48../", $dmesg, $matches))
|
|
|
|
return array('name' => 'net48xx', 'descr' => $matches[0]);
|
|
|
|
|
|
|
|
if (preg_match("/Soekris net55../", $dmesg, $matches))
|
|
|
|
return array('name' => 'net55xx', 'descr' => $matches[0]);
|
|
|
|
|
|
|
|
/* unknown embedded platform */
|
2010-08-17 22:23:58 +02:00
|
|
|
return array('name' => 'embedded', 'descr' => gettext('embedded (unknown)'));
|
2010-05-19 00:03:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function system_get_dmesg_boot() {
|
|
|
|
global $g;
|
2010-05-19 00:08:09 +02:00
|
|
|
|
2010-05-19 00:03:02 +02:00
|
|
|
return file_get_contents("{$g['varlog_path']}/dmesg.boot");
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:07:47 +02:00
|
|
|
function get_possible_listen_ips($include_ipv6_link_local=false) {
|
2011-06-08 23:32:42 +02:00
|
|
|
$interfaces = get_configured_interface_with_descr();
|
|
|
|
$carplist = get_configured_carp_interface_list();
|
|
|
|
$listenips = array();
|
|
|
|
foreach ($carplist as $cif => $carpip)
|
|
|
|
$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
|
|
|
|
$aliaslist = get_configured_ip_aliases_list();
|
|
|
|
foreach ($aliaslist as $aliasip => $aliasif)
|
|
|
|
$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
|
|
|
|
foreach ($interfaces as $iface => $ifacename) {
|
|
|
|
$tmp["name"] = $ifacename;
|
|
|
|
$tmp["value"] = $iface;
|
|
|
|
$listenips[] = $tmp;
|
2013-04-26 19:07:47 +02:00
|
|
|
if ($include_ipv6_link_local) {
|
|
|
|
$llip = find_interface_ipv6_ll(get_real_interface($iface));
|
|
|
|
if (!empty($llip)) {
|
|
|
|
$tmp["name"] = "{$ifacename} IPv6 Link-Local";
|
|
|
|
$tmp["value"] = $llip;
|
|
|
|
$listenips[] = $tmp;
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 23:32:42 +02:00
|
|
|
}
|
|
|
|
$tmp["name"] = "Localhost";
|
|
|
|
$tmp["value"] = "lo0";
|
|
|
|
$listenips[] = $tmp;
|
|
|
|
return $listenips;
|
|
|
|
}
|
2012-01-18 21:05:39 +01:00
|
|
|
|
2013-04-26 19:07:47 +02:00
|
|
|
function get_possible_traffic_source_addresses($include_ipv6_link_local=false) {
|
2013-04-02 17:12:48 +02:00
|
|
|
global $config;
|
2013-04-26 19:07:47 +02:00
|
|
|
$sourceips = get_possible_listen_ips($include_ipv6_link_local);
|
2013-04-02 17:12:48 +02:00
|
|
|
foreach (array('server', 'client') as $mode) {
|
|
|
|
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
|
|
|
|
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
|
|
|
|
if (!isset($setting['disable'])) {
|
|
|
|
$vpn = array();
|
|
|
|
$vpn['value'] = 'ovpn' . substr($mode, 0, 1) . $setting['vpnid'];
|
|
|
|
$vpn['name'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
|
|
|
|
$sourceips[] = $vpn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $sourceips;
|
|
|
|
}
|
2012-03-02 20:07:24 +01:00
|
|
|
?>
|