Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_dnsmasq.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 f0fe3d30 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 f0fe3d30 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 f0fe3d30 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 f0fe3d30 Scott Ullrich
16 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 f0fe3d30 Scott Ullrich
20 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
require("guiconfig.inc");
33
34 4d6ba181 Scott Ullrich
$pconfig['enable']  = isset($config['dnsmasq']['enable']);
35 5b237745 Scott Ullrich
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
36 6a01ea44 Bill Marquette
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
37 5b237745 Scott Ullrich
38 4d6ba181 Scott Ullrich
if (!is_array($config['dnsmasq']['hosts'])) 
39 5b237745 Scott Ullrich
	$config['dnsmasq']['hosts'] = array();
40 0c2b5df7 Scott Ullrich
41 4d6ba181 Scott Ullrich
if (!is_array($config['dnsmasq']['domainoverrides'])) 
42 0c2b5df7 Scott Ullrich
       $config['dnsmasq']['domainoverrides'] = array();
43
44 5b237745 Scott Ullrich
hosts_sort();
45 4d6ba181 Scott Ullrich
46
$a_hosts 	   = &$config['dnsmasq']['hosts'];
47 0c2b5df7 Scott Ullrich
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
48 5b237745 Scott Ullrich
49
if ($_POST) {
50
51
	$pconfig = $_POST;
52
53
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
54
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
55 6a01ea44 Bill Marquette
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
56 5b237745 Scott Ullrich
57
	write_config();
58 f0fe3d30 Scott Ullrich
59 5b237745 Scott Ullrich
	$retval = 0;
60 920b3bb0 Scott Ullrich
61
	config_lock();
62
	$retval = services_dnsmasq_configure();
63
	config_unlock();
64
65 5b237745 Scott Ullrich
	$savemsg = get_std_save_message($retval);
66
67
	if ($retval == 0) {
68
		if (file_exists($d_hostsdirty_path))
69
			unlink($d_hostsdirty_path);
70
	}
71
}
72
73
if ($_GET['act'] == "del") {
74 0c2b5df7 Scott Ullrich
       if ($_GET['type'] == 'host') {
75
               if ($a_hosts[$_GET['id']]) {
76
                       unset($a_hosts[$_GET['id']]);
77
                       write_config();
78 4d6ba181 Scott Ullrich
                       touch($d_hostsdirty_path);
79 0c2b5df7 Scott Ullrich
                       header("Location: services_dnsmasq.php");
80
                       exit;
81
               }
82
       }
83
       elseif ($_GET['type'] == 'doverride') {
84
               if ($a_domainOverrides[$_GET['id']]) {
85
                       unset($a_domainOverrides[$_GET['id']]);
86
                       write_config();
87 4d6ba181 Scott Ullrich
                       touch($d_hostsdirty_path);
88 0c2b5df7 Scott Ullrich
                       header("Location: services_dnsmasq.php");
89
                       exit;
90
               }
91
       }
92 5b237745 Scott Ullrich
}
93 0c2b5df7 Scott Ullrich
94 b63695db Scott Ullrich
$pgtitle = "Services: DNS forwarder";
95
include("head.inc");
96 0c2b5df7 Scott Ullrich
97 5b237745 Scott Ullrich
?>
98
99 6a01ea44 Bill Marquette
<script language="JavaScript">
100
<!--
101
function enable_change(enable_over) {
102
	var endis;
103
	endis = !(document.iform.enable.checked || enable_over);
104
	document.iform.regdhcp.disabled = endis;
105
	document.iform.regdhcpstatic.disabled = endis;
106
}
107
//-->
108
</script>
109
110 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
111
<?php include("fbegin.inc"); ?>
112 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
113 6a01ea44 Bill Marquette
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
114 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
115
<?php if (file_exists($d_hostsdirty_path)): ?><p>
116
<?php print_info_box_np("The DNS forwarder configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
117
<?php endif; ?>
118 4d6ba181 Scott Ullrich
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
119 f0fe3d30 Scott Ullrich
                <tr>
120
                  <td class="vtable"><p>
121 6a01ea44 Bill Marquette
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
122 5b237745 Scott Ullrich
                      <strong>Enable DNS forwarder<br>
123
                      </strong></p></td>
124
                </tr>
125 f0fe3d30 Scott Ullrich
                <tr>
126
                  <td class="vtable"><p>
127 5b237745 Scott Ullrich
                      <input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
128
                      <strong>Register DHCP leases in DNS forwarder<br>
129 f0fe3d30 Scott Ullrich
                      </strong>If this option is set, then machines that specify
130
                      their hostname when requesting a DHCP lease will be registered
131
                      in the DNS forwarder, so that their name can be resolved.
132
                      You should also set the domain in <a href="system.php">System:
133 5b237745 Scott Ullrich
                      General setup</a> to the proper value.</p>
134
                    </td>
135
                </tr>
136 f0fe3d30 Scott Ullrich
                <tr>
137 6a01ea44 Bill Marquette
                  <td class="vtable"><p>
138
                      <input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
139
                      <strong>Register DHCP static mappings in DNS forwarder<br>
140
                      </strong>If this option is set, then DHCP static mappings will 
141
					  be registered in the DNS forwarder, so that their name can be 
142
					  resolved. You should also set the domain in <a href="system.php">
143
					  System: General setup</a> to the proper value.</p>
144
                    </td>
145
                </tr>				
146
                <tr>
147
                  <td> <input name="submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
148 5b237745 Scott Ullrich
                  </td>
149
                </tr>
150 f0fe3d30 Scott Ullrich
                <tr>
151 5b237745 Scott Ullrich
                  <td><p><span class="vexpl"><span class="red"><strong>Note:<br>
152 f0fe3d30 Scott Ullrich
                      </strong></span>If the DNS forwarder is enabled, the DHCP
153
                      service (if enabled) will automatically serve the LAN IP
154
                      address as a DNS server to DHCP clients so they will use
155
                      the forwarder. The DNS forwarder will use the DNS servers
156
                      entered in <a href="system.php">System: General setup</a>
157
                      or those obtained via DHCP or PPP on WAN if the &quot;Allow
158 dacefa7f Scott Ullrich
                      DNS server list to be overridden by DHCP/PPP on WAN&quot;
159 f0fe3d30 Scott Ullrich
                      is checked. If you don't use that option (or if you use
160
                      a static IP address on WAN), you must manually specify at
161
                      least one DNS server on the <a href="system.php">System:
162 5b237745 Scott Ullrich
                      General setup</a> page.<br>
163
                      <br>
164 f0fe3d30 Scott Ullrich
                      You may enter records that override the results from the
165 dacefa7f Scott Ullrich
                      forwarders below.</span></p></td>
166 5b237745 Scott Ullrich
                </tr>
167 4d6ba181 Scott Ullrich
        </table>
168
        &nbsp;<br>
169
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
170 5b237745 Scott Ullrich
                <tr>
171
                  <td width="20%" class="listhdrr">Host</td>
172
                  <td width="25%" class="listhdrr">Domain</td>
173
                  <td width="20%" class="listhdrr">IP</td>
174
                  <td width="25%" class="listhdr">Description</td>
175
                  <td width="10%" class="list"></td>
176
				</tr>
177
			  <?php $i = 0; foreach ($a_hosts as $hostent): ?>
178
                <tr>
179 835f9aca Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
180 5b237745 Scott Ullrich
                    <?=strtolower($hostent['host']);?>&nbsp;
181
                  </td>
182 835f9aca Bill Marquette
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
183 5b237745 Scott Ullrich
                    <?=strtolower($hostent['domain']);?>&nbsp;
184
                  </td>
185 835f9aca Bill Marquette
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
186 5b237745 Scott Ullrich
                    <?=$hostent['ip'];?>&nbsp;
187
                  </td>
188 835f9aca Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
189 f0fe3d30 Scott Ullrich
                    <font color="#FFFFFF"><?=htmlspecialchars($hostent['descr']);?>&nbsp;
190 5b237745 Scott Ullrich
                  </td>
191 ebe566eb Bill Marquette
                  <td valign="middle" nowrap class="list">
192
                    <table border="0" cellspacing="0" cellpadding="1">
193
                      <tr>
194 677c0869 Erik Kristensen
                        <td valign="middle"><a href="services_dnsmasq_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
195
                        <td><a href="services_dnsmasq.php?type=host&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this host?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
196 ebe566eb Bill Marquette
		      </tr>
197
                   </table>
198
                </tr>
199
		<?php $i++; endforeach; ?>
200 f0fe3d30 Scott Ullrich
                <tr>
201 5b237745 Scott Ullrich
                  <td class="list" colspan="4"></td>
202 ebe566eb Bill Marquette
                  <td class="list">
203
                    <table border="0" cellspacing="0" cellpadding="1">
204
                      <tr>
205 677c0869 Erik Kristensen
                        <td valign="middle"><a href="services_dnsmasq_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
206 ebe566eb Bill Marquette
                      </tr>
207
                    </table>
208 ed137452 Scott Ullrich
		   </td>
209 4d6ba181 Scott Ullrich
	</table>
210 0c2b5df7 Scott Ullrich
<!-- update to enable domain overrides -->
211 4d6ba181 Scott Ullrich
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
212 c21d4582 Scott Ullrich
	       <tr><td>&nbsp;</td></tr>
213 0c2b5df7 Scott Ullrich
               <tr>
214
                 <td><p>Below you can override an entire domain by specifying an
215
                        authoritative dns server to be queried for that domain.</p></td>
216
               </tr>
217 4d6ba181 Scott Ullrich
        </table>
218
	&nbsp;<br>
219
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
220 0c2b5df7 Scott Ullrich
               <tr>
221
                 <td width="35%" class="listhdrr">Domain</td>
222
                 <td width="20%" class="listhdrr">IP</td>
223
                 <td width="35%" class="listhdr">Description</td>
224
                 <td width="10%" class="list"></td>
225
                              </tr>
226
                        <?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
227
               <tr>
228
                 <td class="listlr">
229
                   <?=strtolower($doment['domain']);?>&nbsp;
230
                 </td>
231
                 <td class="listr">
232
                   <?=$doment['ip'];?>&nbsp;
233
                 </td>
234 5015bd61 Scott Ullrich
                 <td class="listbg"><font color="#FFFFFF">
235 0c2b5df7 Scott Ullrich
                   <?=htmlspecialchars($doment['descr']);?>&nbsp;
236
                 </td>
237 677c0869 Erik Kristensen
                 <td valign="middle" nowrap class="list"> <a href="services_dnsmasq_domainoverride_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
238
                    &nbsp;<a href="services_dnsmasq.php?act=del&type=doverride&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this domain override?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
239 0c2b5df7 Scott Ullrich
                              </tr>
240
                        <?php $i++; endforeach; ?>
241
               <tr>
242
                 <td class="list" colspan="3"></td>
243 677c0869 Erik Kristensen
                 <td class="list"> <a href="services_dnsmasq_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
244 0c2b5df7 Scott Ullrich
	       </tr>
245 4d6ba181 Scott Ullrich
        </table>
246
        </form>
247 6a01ea44 Bill Marquette
<script language="JavaScript">
248
<!--
249
enable_change(false);
250
//-->
251
</script>
252 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
253
</body>
254
</html>