diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2004-11-10 23:43:56 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2004-11-10 23:43:56 +0000 |
commit | a25183c5b81471ac9de99b39f9d42b861451f24e (patch) | |
tree | 9f0978d917d9268f4e7c893701ae60ff394230dc /etc/inc/services.inc | |
parent | 16d9e6e48d3a7f311673cdda7e0bf46cffa4d257 (diff) | |
download | pfsense-a25183c5b81471ac9de99b39f9d42b861451f24e.zip pfsense-a25183c5b81471ac9de99b39f9d42b861451f24e.tar.gz |
add interface selection screen for proxyarp
Diffstat (limited to 'etc/inc/services.inc')
-rw-r--r-- | etc/inc/services.inc | 161 |
1 files changed, 82 insertions, 79 deletions
diff --git a/etc/inc/services.inc b/etc/inc/services.inc index 17bc959..bcc9dd9 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -2,20 +2,20 @@ /* services.inc part of m0n0wall (http://m0n0.ch/wall) - + Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. 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 @@ -33,13 +33,13 @@ require_once("functions.inc"); function services_dhcpd_configure() { global $config, $g; - + /* kill any running dhcpd */ killbypid("{$g['varrun_path']}/dhcpd.pid"); - + $syscfg = $config['system']; $dhcpdcfg = $config['dhcpd']; - + /* DHCP enabled on any interfaces? */ $dhcpdenable = false; foreach ($dhcpdcfg as $dhcpif => $dhcpifconf) { @@ -49,22 +49,22 @@ function services_dhcpd_configure() { $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 = <<<EOD option domain-name "{$syscfg['domain']}"; default-lease-time 7200; @@ -74,26 +74,26 @@ log-facility local7; ddns-update-style none; EOD; - + $dhcpdifs = array(); foreach ($dhcpdcfg as $dhcpif => $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'])) { @@ -104,14 +104,14 @@ EOD; $dhcpdconf .= "subnet $subnet netmask $subnetmask {\n"; $dhcpdconf .= " pool {\n"; - if (isset($dhcpifconf['denyunknown'])) + if (isset($dhcpifconf['denyunknown'])) $dhcpdconf .= " deny unknown clients;\n"; - + if ($dhcpifconf['gateway']) $routers = $dhcpifconf['gateway']; else $routers = $ifcfg['ipaddr']; - + $dhcpdconf .= <<<EOD range {$dhcpifconf['range']['from']} {$dhcpifconf['range']['to']}; } @@ -124,17 +124,17 @@ EOD; $dhcpdconf .= " default-lease-time {$dhcpifconf['defaultleasetime']};\n"; if ($dhcpifconf['maxleasetime']) $dhcpdconf .= " max-lease-time {$dhcpifconf['maxleasetime']};\n"; - + if (is_array($dhcpifconf['winsserver']) && $dhcpifconf['winsserver'][0]) { $dhcpdconf .= " option netbios-name-servers " . join(",", $dhcpifconf['winsserver']) . ";\n"; $dhcpdconf .= " option netbios-node-type 8;\n"; } - + if ($dhcpifconf['next-server']) $dhcpdconf .= " next-server {$dhcpifconf['next-server']};\n"; if ($dhcpifconf['filename']) $dhcpdconf .= " filename \"{$dhcpifconf['filename']}\";\n"; - + $dhcpdconf .= <<<EOD } @@ -142,7 +142,7 @@ EOD; /* add static mappings */ if (is_array($dhcpifconf['staticmap'])) { - + $i = 0; foreach ($dhcpifconf['staticmap'] as $sm) { $dhcpdconf .= <<<EOD @@ -152,12 +152,12 @@ host s_{$dhcpif}_{$i} { EOD; if ($sm['ipaddr']) $dhcpdconf .= " fixed-address {$sm['ipaddr']};\n"; - + $dhcpdconf .= "}\n"; $i++; } } - + $dhcpdifs[] = $ifcfg['if']; } @@ -166,27 +166,27 @@ EOD; /* create an empty leases database */ touch("{$g['vardb_path']}/dhcpd.leases"); - + /* fire up dhcpd */ - mwexec("/usr/local/sbin/dhcpd -cf {$g['varetc_path']}/dhcpd.conf " . + mwexec("/usr/local/sbin/dhcpd -cf {$g['varetc_path']}/dhcpd.conf " . join(" ", $dhcpdifs)); - + if (!$g['booting']) { filter_configure(); } else echo "done\n"; - + return 0; } function services_dhcrelay_configure() { global $config, $g; - + /* kill any running dhcrelay */ killbypid("{$g['varrun_path']}/dhcrelay.pid"); - + $dhcrelaycfg = $config['dhcrelay']; - + /* DHCPRelay enabled on any interfaces? */ $dhcrelayenable = false; foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) { @@ -196,56 +196,56 @@ function services_dhcrelay_configure() { $config['interfaces'][$dhcrelayif]['if'] && (!$config['interfaces'][$dhcrelayif]['bridge'])))) $dhcrelayenable = true; } - + 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 + /* 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 (ip_in_subnet($dhcrelaycfg['server'],$subnet)) + $destif = $ifname['if']; } - - if (!isset($destif)) + + 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'])) + if (isset($dhcrelaycfg['agentoption'])) $cmd .= " -a -m replace"; $cmd .= " {$dhcrelaycfg['server']}"; mwexec($cmd); - + if (!$g['booting']) { filter_configure(); } else echo "done\n"; - + return 0; } @@ -254,44 +254,44 @@ function services_dyndns_reset() { 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']; $wancfg = $config['interfaces']['wan']; - + 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 = <<<EOD service-type={$dyndnscfg['type']} user={$dyndnscfg['username']}:{$dyndnscfg['password']} @@ -309,7 +309,7 @@ EOD; if ($dyndnscfg['mx']) { $ezipupdateconf .= "mx={$dyndnscfg['mx']}\n"; } - + /* enable wildcards? */ if (isset($dyndnscfg['wildcard'])) { $ezipupdateconf .= "wildcard\n"; @@ -317,21 +317,21 @@ EOD; fwrite($fd, $ezipupdateconf); fclose($fd); - + /* if we're booting, copy the cache file from /conf */ if ($g['booting']) { if (file_exists("{$g['conf_path']}/ez-ipupdate.cache")) { copy("{$g['conf_path']}/ez-ipupdate.cache", "{$g['vardb_path']}/ez-ipupdate.cache"); } } - + /* run ez-ipupdate */ mwexec("/usr/local/bin/ez-ipupdate -c {$g['varetc_path']}/ez-ipupdate.conf"); - + if ($g['booting']) echo "done\n"; } - + return 0; } @@ -342,7 +342,7 @@ function services_dnsmasq_configure() { sigkillbypid("{$g['varrun_path']}/dnsmasq.pid", "TERM"); if (isset($config['dnsmasq']['enable'])) { - + if ($g['booting']) echo "Starting DNS forwarder... "; else @@ -350,12 +350,12 @@ function services_dnsmasq_configure() { /* generate hosts file */ system_hosts_generate(); - + $args = ""; - + if (isset($config['dnsmasq']['regdhcp'])) { - - $args .= " -l {$g['vardb_path']}/dhcpd.leases" . + + $args .= " -l {$g['vardb_path']}/dhcpd.leases" . " -s {$config['system']['domain']}"; } @@ -365,7 +365,7 @@ function services_dnsmasq_configure() { if ($g['booting']) echo "done\n"; } - + if (!$g['booting']) { services_dhcpd_configure(); } @@ -380,7 +380,7 @@ function services_snmpd_configure() { sigkillbypid("{$g['varrun_path']}/snmpd.pid", "TERM"); if (isset($config['snmpd']['enable'])) { - + if ($g['booting']) echo "Starting SNMP agent... "; @@ -390,7 +390,7 @@ function services_snmpd_configure() { printf("Error: cannot open snmpd.conf in services_snmpd_configure().\n"); return 1; } - + $snmpdconf = <<<EOD syslocation "{$config['snmpd']['syslocation']}" syscontact "{$config['snmpd']['syscontact']}" @@ -417,22 +417,25 @@ function services_proxyarp_configure() { /* kill any running choparp */ killbyname("choparp"); - + if (is_array($config['proxyarp']) && count($config['proxyarp']) && (is_ipaddr($config['interfaces']['wan']['ipaddr']) || ($config['interfaces']['wan']['ipaddr'] == "dhcp") || ($config['interfaces']['wan']['ipaddr'] == "bigpond"))) { - - $args = $config['interfaces']['wan']['if'] . " auto"; - + + if(isset($config['proxyarp']['proxyarpnet']['interface'])) + $args = $config['proxyarp']['proxyarpnet']['interface']; + else + $args = $config['interfaces']['wan']['if'] . " auto"; + foreach ($config['proxyarp']['proxyarpnet'] as $paent) { if (isset($paent['network'])) $args .= " " . escapeshellarg($paent['network']); else if (isset($paent['range'])) - $args .= " " . escapeshellarg($paent['range']['from'] . "-" . + $args .= " " . escapeshellarg($paent['range']['from'] . "-" . $paent['range']['to']); } - + mwexec_bg("/usr/local/sbin/choparp " . $args); } } |