. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 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. 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. */ /* include all configuration functions */ require_once("functions.inc"); function services_dhcp6s_configure() { global $config, $g; /* kill any running dhcp6s */ $dircont = opendir($g['varrun_path']); while ($file = readdir($dircont)) { if (preg_match("/dhcp6s/",$file)) killbypid("{$g['varrun_path']}/$file"); } closedir($dircont); killbypid("{$g['varrun_path']}/dhcp6s.pid"); if (!file_exists("{$g['varrun_path']}/dhcp6sctlkey")) mwexec("touch {$g['varrun_path']}/dhcp6sctlkey"); $syscfg = $config['system']; $dhcp6scfg = $config['dhcpd']; /* DHCPv6 enabled on any interfaces? */ $dhcp6senable = false; foreach ($dhcp6scfg as $dhcpif => $dhcpifconf) { if (isset($dhcpifconf['v6enable']) && (($dhcpif == "lan") || (isset($config['interfaces'][$dhcpif]['v6enable']) && $config['interfaces'][$dhcpif]['if'] && (!$config['interfaces'][$dhcpif]['bridge'])))) $dhcp6senable = true; } if (!$dhcp6senable) return 0; if ($g['booting']) echo "Starting DHCPv6 service... "; else sleep(1); $dhcp6sifs = array(); foreach ($dhcp6scfg as $dhcpif => $dhcpifconf) { $ifcfg = $config['interfaces'][$dhcpif]; /* write dhcp6s.conf */ $fd = fopen("{$g['varetc_path']}/dhcp6s.{$ifcfg['if']}.conf", "w"); if (!$fd) { printf("Error: cannot open dhcp6s.conf in services_dhcp6s_configure().\n"); return 1; } $dhcp6sconf = << $dhcpifconf) { if (isset($dhcpifconf['enable']) && (($dhcpif == "lan") || (isset($config['interfaces'][$dhcpif]['enable']) && $config['interfaces'][$dhcpif]['if'] && (!$config['interfaces'][$dhcpif]['bridge'])))) $dhcpdenable = true; } if (!$dhcpdenable) return 0; if ($g['booting']) echo "Starting DHCP service... "; else sleep(1); /* write dhcpd.conf */ $fd = fopen("{$g['varetc_path']}/dhcpd.conf", "w"); if (!$fd) { printf("Error: cannot open dhcpd.conf in services_dhcpd_configure().\n"); return 1; } $dhcpdconf = << $dhcpifconf) { $ifcfg = $config['interfaces'][$dhcpif]; if (!isset($dhcpifconf['enable']) || (($dhcpif != "lan") && (!isset($ifcfg['enable']) || !$ifcfg['if'] || $ifcfg['bridge']))) continue; $subnet = gen_subnet($ifcfg['ipaddr'], $ifcfg['subnet']); $subnetmask = gen_subnet_mask($ifcfg['subnet']); $dnscfg = ""; if ($dhcpifconf['domain']) { $dnscfg .= " option domain-name \"{$dhcpifconf['domain']}\";\n"; } if (is_array($dhcpifconf['dnsserver']) && ($dhcpifconf['dnsserver'][0])) { $dnscfg .= " option domain-name-servers " . join(",", $dhcpifconf['dnsserver']) . ";"; } else if (isset($config['dnsmasq']['enable'])) { $dnscfg .= " option domain-name-servers " . $ifcfg['ipaddr'] . ";"; } else if (is_array($syscfg['dnsserver']) && ($syscfg['dnsserver'][0])) { $dnscfg .= " option domain-name-servers " . join(",", $syscfg['dnsserver']) . ";"; } $dhcpdconf .= "subnet $subnet netmask $subnetmask {\n"; $dhcpdconf .= " pool {\n"; if (isset($dhcpifconf['denyunknown'])) $dhcpdconf .= " deny unknown clients;\n"; if ($dhcpifconf['gateway']) $routers = $dhcpifconf['gateway']; else $routers = $ifcfg['ipaddr']; $dhcpdconf .= << $dhcrelayifconf) { if (isset($dhcrelayifconf['enable']) && (($dhcrelayif == "lan") || (isset($config['interfaces'][$dhcrelayif]['enable']) && $config['interfaces'][$dhcrelayif]['if'] && (!$config['interfaces'][$dhcrelayif]['bridge'])))) { $dhcrelayenable = true; break; } } } if (!$dhcrelayenable) return 0; if ($g['booting']) echo "Starting DHCP relay service... "; else sleep(1); $dhcrelayifs = array(); foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) { $ifcfg = $config['interfaces'][$dhcrelayif]; if (!isset($dhcrelayifconf['enable']) || (($dhcrelayif != "lan") && (!isset($ifcfg['enable']) || !$ifcfg['if'] || $ifcfg['bridge']))) continue; $dhcrelayifs[] = $ifcfg['if']; } /* In order for the relay to work, it needs to be active on the interface in which the destination server sits */ foreach ($config['interfaces'] as $ifname) { $subnet = $ifname['ipaddr'] . "/" . $ifname['subnet']; if (ip_in_subnet($dhcrelaycfg['server'],$subnet)) $destif = $ifname['if']; } if (!isset($destif)) $destif = $config['interfaces']['wan']['if']; $dhcrelayifs[] = $destif; $dhcrelayifs = array_unique($dhcrelayifs); /* fire up dhcrelay */ $cmd = "/usr/local/sbin/dhcrelay -i " . join(" -i ", $dhcrelayifs); if (isset($dhcrelaycfg['agentoption'])) $cmd .= " -a -m replace"; $cmd .= " {$dhcrelaycfg['server']}"; mwexec($cmd); if (!$g['booting']) { filter_configure(); } else echo "done\n"; return 0; } function services_dyndns_reset() { global $config, $g; if (file_exists("{$g['vardb_path']}/ez-ipupdate.cache")) { unlink("{$g['vardb_path']}/ez-ipupdate.cache"); } if (file_exists("{$g['conf_path']}/ez-ipupdate.cache")) { conf_mount_rw(); unlink("{$g['conf_path']}/ez-ipupdate.cache"); conf_mount_ro(); } return 0; } function services_dyndns_configure() { global $config, $g; /* kill any running ez-ipupdate */ /* ez-ipupdate needs SIGQUIT instead of SIGTERM */ sigkillbypid("{$g['varrun_path']}/ez-ipupdate.pid", "QUIT"); $dyndnscfg = $config['dyndns']; if (isset($dyndnscfg['enable'])) { if ($g['booting']) echo "Starting DynDNS client... "; else sleep(1); /* determine WAN interface name */ $wanif = get_real_wan_interface(); /* write ez-ipupdate.conf */ $fd = fopen("{$g['varetc_path']}/ez-ipupdate.conf", "w"); if (!$fd) { printf("Error: cannot open ez-ipupdate.conf in services_dyndns_configure().\n"); return 1; } $ezipupdateconf = << $paents) { if ($paif == "wan" && !(is_ipaddr($config['interfaces']['wan']['ipaddr']) || ($config['interfaces']['wan']['ipaddr'] == "dhcp"))) continue; $args = $config['interfaces'][$paif]['if'] . " auto"; foreach ($paents as $paent) { if (isset($paent['network'])) $args .= " " . escapeshellarg($paent['network']); else if (isset($paent['range'])) $args .= " " . escapeshellarg($paent['range']['from'] . "-" . $paent['range']['to']); } mwexec_bg("/usr/local/sbin/choparp " . $args); } } } function services_dnsupdate_process() { global $config, $g; /* Dynamic DNS updating active? */ if (isset($config['dnsupdate']['enable'])) { $wanip = get_current_wan_address(); if ($wanip) { $keyname = $config['dnsupdate']['keyname']; /* trailing dot */ if (substr($keyname, -1) != ".") $keyname .= "."; $hostname = $config['dnsupdate']['host']; /* trailing dot */ if (substr($hostname, -1) != ".") $hostname .= "."; /* write private key file this is dumb - public and private keys are the same for HMAC-MD5, but nsupdate insists on having both */ $fd = fopen("{$g['varetc_path']}/K{$keyname}+157+00000.private", "w"); $privkey .= <<