. 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 system_resolvconf_generate($dynupdate = false) { global $config, $g; $syscfg = $config['system']; $fd = fopen("{$g['varetc_path']}/resolv.conf.new", "w"); if (!$fd) { printf("Error: cannot open resolv.conf.new in system_resolvconf_generate().\n"); return 1; } $resolvconf = "domain {$syscfg['domain']}\n"; $havedns = false; if (isset($syscfg['dnsallowoverride'])) { /* get dynamically assigned DNS servers for ppp (if any) */ $nfd = @fopen("{$g['varetc_path']}/nameservers.conf", "r"); if ($nfd) { while (!feof($nfd)) { $dnss = trim(fgets($nfd)); if ($dnss) { $resolvconf .= "nameserver $dnss\n"; $havedns = true; } } fclose($nfd); } } /* if we didn't get assigned DNS servers and have some set add 'em */ if (!$havedns && is_array($syscfg['dnsserver'])) { foreach ($syscfg['dnsserver'] as $ns) { if ($ns) $resolvconf .= "nameserver $ns\n"; $havedns = true; } } fwrite($fd, $resolvconf); fclose($fd); /* If we now have DNS servers, overwrite resolv.conf */ if ($havedns) { if (file_exists("{$g['varetc_path']}/resolv.conf")) unlink("{$g['varetc_path']}/resolv.conf"); rename("{$g['varetc_path']}/resolv.conf.new", "{$g['varetc_path']}/resolv.conf"); } else { unlink("{$g['varetc_path']}/resolv.conf.new"); } if (!$g['booting']) { /* restart dhcpd (nameservers may have changed) */ if (!$dynupdate) services_dhcpd_configure(); } return 0; } function system_hosts_generate() { global $config, $g; $syscfg = $config['system']; $lancfg = $config['interfaces']['lan']; $dnsmasqcfg = $config['dnsmasq']; if (!is_array($dnsmasqcfg['hosts'])) { $dnsmasqcfg['hosts'] = array(); } $hostscfg = $dnsmasqcfg['hosts']; $fd = fopen("{$g['varetc_path']}/hosts", "w"); if (!$fd) { printf("Error: cannot open hosts file in system_hosts_generate().\n"); return 1; } $hosts = << /etc/localtime"); if ($g['booting']) echo "done\n"; } function system_ntp_configure() { global $config, $g; $syscfg = $config['system']; if ($g['booting']) echo "Starting NTP client... "; else { killbypid("{$g['varrun_path']}/runmsntp.pid"); killbypid("{$g['varrun_path']}/msntp.pid"); } /* start ntp client if needed - needs to be forced into background */ $updateinterval = $syscfg['time-update-interval']; if ($updateinterval > 0) { if ($updateinterval < 6) $updateinterval = 6; $timeservers = ""; foreach (explode(' ', $syscfg['timeservers']) as $ts) $timeservers .= " " . $ts; mwexec_bg("/usr/local/bin/runmsntp.sh " . escapeshellarg("{$g['varrun_path']}/runmsntp.pid") . " " . escapeshellarg("{$g['varrun_path']}/msntp.pid") . " " . escapeshellarg($updateinterval) . " " . escapeshellarg($timeservers)); } if ($g['booting']) echo "done\n"; } function system_halt() { global $g; system_reboot_cleanup(); mwexec("nohup /etc/rc.halt > /dev/null 2>&1 &"); } function system_reboot() { global $g; system_reboot_cleanup(); mwexec("nohup /etc/rc.reboot > /dev/null 2>&1 &"); } function system_reboot_sync() { global $g; system_reboot_cleanup(); mwexec("/etc/rc.reboot > /dev/null 2>&1"); } function system_reboot_cleanup() { captiveportal_radius_stop_all(); } function system_do_shell_commands($early = 0) { global $config, $g; if ($early) $cmdn = "earlyshellcmd"; else $cmdn = "shellcmd"; if (is_array($config['system'][$cmdn])) { foreach ($config['system'][$cmdn] as $cmd) { exec($cmd); } } } function system_do_extensions($early = false) { global $config, $g; if (!is_dir("{$g['etc_path']}/inc/ext")) return; $dh = @opendir("{$g['etc_path']}/inc/ext"); if ($dh) { while (($extd = readdir($dh)) !== false) { if (($extd === ".") || ($extd === "..")) continue; $rcfile = "{$g['etc_path']}/inc/ext/" . $extd . "/" . ($early ? "rc.early" : "rc"); if (file_exists($rcfile)) passthru($rcfile); } closedir($dh); } } function system_console_configure() { global $config, $g; if (isset($config['system']['disableconsolemenu'])) { touch("{$g['varetc_path']}/disableconsole"); } else { unlink_if_exists("{$g['varetc_path']}/disableconsole"); } } function system_dmesg_save() { global $g; exec("/sbin/dmesg", $dmesg); /* find last copyright line (output from previous boots may be present) */ $lastcpline = 0; for ($i = 0; $i < count($dmesg); $i++) { if (strstr($dmesg[$i], "Copyright (c) 1992-")) $lastcpline = $i; } $fd = fopen("{$g['varlog_path']}/dmesg.boot", "w"); if (!$fd) { printf("Error: cannot open dmesg.boot in system_dmesg_save().\n"); return 1; } for ($i = $lastcpline; $i < count($dmesg); $i++) fwrite($fd, $dmesg[$i] . "\n"); fclose($fd); return 0; } function system_set_harddisk_standby() { global $g, $config; if ($g['platform'] != "generic-pc") return; if (isset($config['system']['harddiskstandby'])) { if ($g['booting']) { echo 'Setting harddisk standby time... '; } $standby = $config['system']['harddiskstandby']; // Check for a numeric value if (is_numeric($standby)) { // Sync the disk(s) mwexec('/bin/sync'); if (!mwexec('/sbin/sysctl hw.ata.standby=' . ((int)$standby))) { // Reinitialize ATA-drives mwexec('/usr/local/sbin/atareinit'); if ($g['booting']) { echo "done\n"; } } else if ($g['booting']) { echo "failed\n"; } } else if ($g['booting']) { echo "failed\n"; } } } function system_setup_sysctl() { $sysctl = return_filename_as_array("/etc/sysctl.conf"); foreach($sysctl as $sysc) { if($sysc <> "") mwexec("sysctl {$sysc}"); } } ?>