From 46bc6e545a17e77202aaf01ec0cd8d5a46567525 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 25 Aug 2015 08:08:24 -0300 Subject: Move main pfSense content to src/ --- src/usr/local/www/services_dnsmasq.php | 582 +++++++++++++++++++++++++++++++++ 1 file changed, 582 insertions(+) create mode 100644 src/usr/local/www/services_dnsmasq.php (limited to 'src/usr/local/www/services_dnsmasq.php') diff --git a/src/usr/local/www/services_dnsmasq.php b/src/usr/local/www/services_dnsmasq.php new file mode 100644 index 0000000..4abf4d7 --- /dev/null +++ b/src/usr/local/www/services_dnsmasq.php @@ -0,0 +1,582 @@ + and Manuel Kasper . + Copyright (C) 2013-2015 Electric Sheep Fencing, LP + 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. +*/ +/* + pfSense_MODULE: dnsforwarder +*/ + +##|+PRIV +##|*IDENT=page-services-dnsforwarder +##|*NAME=Services: DNS Forwarder page +##|*DESCR=Allow access to the 'Services: DNS Forwarder' page. +##|*MATCH=services_dnsmasq.php* +##|-PRIV + +require("guiconfig.inc"); +require_once("functions.inc"); +require_once("filter.inc"); +require_once("shaper.inc"); +require_once("system.inc"); + +$pconfig['enable'] = isset($config['dnsmasq']['enable']); +$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']); +$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']); +$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']); +$pconfig['strict_order'] = isset($config['dnsmasq']['strict_order']); +$pconfig['domain_needed'] = isset($config['dnsmasq']['domain_needed']); +$pconfig['no_private_reverse'] = isset($config['dnsmasq']['no_private_reverse']); +$pconfig['port'] = $config['dnsmasq']['port']; +$pconfig['custom_options'] = $config['dnsmasq']['custom_options']; + +$pconfig['strictbind'] = isset($config['dnsmasq']['strictbind']); +if (!empty($config['dnsmasq']['interface'])) { + $pconfig['interface'] = explode(",", $config['dnsmasq']['interface']); +} else { + $pconfig['interface'] = array(); +} + +if (!is_array($config['dnsmasq']['hosts'])) { + $config['dnsmasq']['hosts'] = array(); +} + +if (!is_array($config['dnsmasq']['domainoverrides'])) { + $config['dnsmasq']['domainoverrides'] = array(); +} + +$a_hosts = &$config['dnsmasq']['hosts']; +$a_domainOverrides = &$config['dnsmasq']['domainoverrides']; + +if ($_POST) { + + $pconfig = $_POST; + unset($input_errors); + + $config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false; + $config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false; + $config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false; + $config['dnsmasq']['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false; + $config['dnsmasq']['strict_order'] = ($_POST['strict_order']) ? true : false; + $config['dnsmasq']['domain_needed'] = ($_POST['domain_needed']) ? true : false; + $config['dnsmasq']['no_private_reverse'] = ($_POST['no_private_reverse']) ? true : false; + $config['dnsmasq']['custom_options'] = str_replace("\r\n", "\n", $_POST['custom_options']); + $config['dnsmasq']['strictbind'] = ($_POST['strictbind']) ? true : false; + + if (isset($_POST['enable']) && isset($config['unbound']['enable'])) { + if ($_POST['port'] == $config['unbound']['port']) { + $input_errors[] = "The DNS Resolver is enabled using this port. Choose a non-conflicting port, or disable DNS Resolver."; + } + } + + if ($_POST['port']) { + if (is_port($_POST['port'])) { + $config['dnsmasq']['port'] = $_POST['port']; + } else { + $input_errors[] = gettext("You must specify a valid port number"); + } + } else if (isset($config['dnsmasq']['port'])) { + unset($config['dnsmasq']['port']); + } + + if (is_array($_POST['interface'])) { + $config['dnsmasq']['interface'] = implode(",", $_POST['interface']); + } elseif (isset($config['dnsmasq']['interface'])) { + unset($config['dnsmasq']['interface']); + } + + if ($config['dnsmasq']['custom_options']) { + $args = ''; + foreach (preg_split('/\s+/', $config['dnsmasq']['custom_options']) as $c) { + $args .= escapeshellarg("--{$c}") . " "; + } + exec("/usr/local/sbin/dnsmasq --test $args", $output, $rc); + if ($rc != 0) { + $input_errors[] = gettext("Invalid custom options"); + } + } + + if (!$input_errors) { + write_config(); + + $retval = 0; + $retval = services_dnsmasq_configure(); + $savemsg = get_std_save_message($retval); + + // Reload filter (we might need to sync to CARP hosts) + filter_configure(); + /* Update resolv.conf in case the interface bindings exclude localhost. */ + system_resolvconf_generate(); + /* Start or restart dhcpleases when it's necessary */ + system_dhcpleases_configure(); + + if ($retval == 0) { + clear_subsystem_dirty('hosts'); + } + } +} + +if ($_GET['act'] == "del") { + if ($_GET['type'] == 'host') { + if ($a_hosts[$_GET['id']]) { + unset($a_hosts[$_GET['id']]); + write_config(); + mark_subsystem_dirty('hosts'); + header("Location: services_dnsmasq.php"); + exit; + } + } + elseif ($_GET['type'] == 'doverride') { + if ($a_domainOverrides[$_GET['id']]) { + unset($a_domainOverrides[$_GET['id']]); + write_config(); + mark_subsystem_dirty('hosts'); + header("Location: services_dnsmasq.php"); + exit; + } + } +} + +$closehead = false; +$pgtitle = array(gettext("Services"), gettext("DNS forwarder")); +$shortcut_section = "forwarder"; +include("head.inc"); + +?> + + + + + +
+ + +
+" . gettext("You must apply the changes in order for them to take effect."));?>
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ onclick="enable_change(false)" /> + +
+
+

+
+

+ /> + +
+
+ ', '')?> +

+
+

+ /> + +
+
+ ', '');?> +

+
+

+ /> + +
+
+ +

+
+

+ /> + +
+
+ System - General Setup - DNS Servers), ". + "rather than all at once in parallel. "), $g['product_name']); ?> +

+
+

+ /> + +
+
+ +

+
+

+ /> + +
+
+ +

+
+

+ /> +

+ +

+
+ + +

+ +

+
+

+ /> + +
+ +

+ +

+
+
> + " /> - +
+
> +
+
+
+
+
+ " onclick="enable_change(true)" /> +
+ +

+ + + +
+
+
+ ', '', '', '');?>
+
+

+ + 
+ + + + + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ add +
+
+ + + + + +
+ add +
+
+   + +   + +   + +   + + + + + + +
edit + ')">delete +
+
+   + +   + + Alias for   + +   + + edit +
+
+ + + + + + + +
+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ add +
+
+ + + + + +
+ add +
+
+   + +   + +   + + edit +  ')">delete +
+
+ + + + -- cgit v1.1