Project

General

Profile

Download (12.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 6b07c15a Matthew Grooms
##|+PRIV
33
##|*IDENT=page-services-dnsforwarder
34
##|*NAME=Services: DNS Forwarder page
35
##|*DESCR=Allow access to the 'Services: DNS Forwarder' page.
36
##|*MATCH=services_dnsmasq.php*
37
##|-PRIV
38
39
40 5b237745 Scott Ullrich
require("guiconfig.inc");
41
42 4d6ba181 Scott Ullrich
$pconfig['enable']  = isset($config['dnsmasq']['enable']);
43 5b237745 Scott Ullrich
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
44 6a01ea44 Bill Marquette
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
45 5b237745 Scott Ullrich
46 4d6ba181 Scott Ullrich
if (!is_array($config['dnsmasq']['hosts'])) 
47 5b237745 Scott Ullrich
	$config['dnsmasq']['hosts'] = array();
48 0c2b5df7 Scott Ullrich
49 4d6ba181 Scott Ullrich
if (!is_array($config['dnsmasq']['domainoverrides'])) 
50 0c2b5df7 Scott Ullrich
       $config['dnsmasq']['domainoverrides'] = array();
51
52 5b237745 Scott Ullrich
hosts_sort();
53 4d6ba181 Scott Ullrich
54
$a_hosts 	   = &$config['dnsmasq']['hosts'];
55 0c2b5df7 Scott Ullrich
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
56 5b237745 Scott Ullrich
57
if ($_POST) {
58
59
	$pconfig = $_POST;
60
61
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
62
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
63 6a01ea44 Bill Marquette
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
64 5b237745 Scott Ullrich
65
	write_config();
66 f0fe3d30 Scott Ullrich
67 5b237745 Scott Ullrich
	$retval = 0;
68 920b3bb0 Scott Ullrich
69
	config_lock();
70
	$retval = services_dnsmasq_configure();
71
	config_unlock();
72
73 5b237745 Scott Ullrich
	$savemsg = get_std_save_message($retval);
74
75
	if ($retval == 0) {
76
		if (file_exists($d_hostsdirty_path))
77
			unlink($d_hostsdirty_path);
78
	}
79
}
80
81
if ($_GET['act'] == "del") {
82 0c2b5df7 Scott Ullrich
       if ($_GET['type'] == 'host') {
83
               if ($a_hosts[$_GET['id']]) {
84
                       unset($a_hosts[$_GET['id']]);
85
                       write_config();
86 4d6ba181 Scott Ullrich
                       touch($d_hostsdirty_path);
87 0c2b5df7 Scott Ullrich
                       header("Location: services_dnsmasq.php");
88
                       exit;
89
               }
90
       }
91
       elseif ($_GET['type'] == 'doverride') {
92
               if ($a_domainOverrides[$_GET['id']]) {
93
                       unset($a_domainOverrides[$_GET['id']]);
94
                       write_config();
95 4d6ba181 Scott Ullrich
                       touch($d_hostsdirty_path);
96 0c2b5df7 Scott Ullrich
                       header("Location: services_dnsmasq.php");
97
                       exit;
98
               }
99
       }
100 5b237745 Scott Ullrich
}
101 0c2b5df7 Scott Ullrich
102 d88c6a9f Scott Ullrich
$pgtitle = array("Services","DNS forwarder");
103 b63695db Scott Ullrich
include("head.inc");
104 0c2b5df7 Scott Ullrich
105 5b237745 Scott Ullrich
?>
106
107 6a01ea44 Bill Marquette
<script language="JavaScript">
108
<!--
109
function enable_change(enable_over) {
110
	var endis;
111
	endis = !(document.iform.enable.checked || enable_over);
112
	document.iform.regdhcp.disabled = endis;
113
	document.iform.regdhcpstatic.disabled = endis;
114
}
115
//-->
116
</script>
117
118 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
119
<?php include("fbegin.inc"); ?>
120 6a01ea44 Bill Marquette
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
121 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
122
<?php if (file_exists($d_hostsdirty_path)): ?><p>
123
<?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>
124
<?php endif; ?>
125 4d6ba181 Scott Ullrich
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
126 f0fe3d30 Scott Ullrich
                <tr>
127
                  <td class="vtable"><p>
128 6a01ea44 Bill Marquette
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
129 5b237745 Scott Ullrich
                      <strong>Enable DNS forwarder<br>
130
                      </strong></p></td>
131
                </tr>
132 f0fe3d30 Scott Ullrich
                <tr>
133
                  <td class="vtable"><p>
134 5b237745 Scott Ullrich
                      <input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
135
                      <strong>Register DHCP leases in DNS forwarder<br>
136 f0fe3d30 Scott Ullrich
                      </strong>If this option is set, then machines that specify
137
                      their hostname when requesting a DHCP lease will be registered
138
                      in the DNS forwarder, so that their name can be resolved.
139
                      You should also set the domain in <a href="system.php">System:
140 5b237745 Scott Ullrich
                      General setup</a> to the proper value.</p>
141
                    </td>
142
                </tr>
143 f0fe3d30 Scott Ullrich
                <tr>
144 6a01ea44 Bill Marquette
                  <td class="vtable"><p>
145
                      <input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
146
                      <strong>Register DHCP static mappings in DNS forwarder<br>
147
                      </strong>If this option is set, then DHCP static mappings will 
148
					  be registered in the DNS forwarder, so that their name can be 
149
					  resolved. You should also set the domain in <a href="system.php">
150
					  System: General setup</a> to the proper value.</p>
151
                    </td>
152
                </tr>				
153
                <tr>
154
                  <td> <input name="submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
155 5b237745 Scott Ullrich
                  </td>
156
                </tr>
157 f0fe3d30 Scott Ullrich
                <tr>
158 5b237745 Scott Ullrich
                  <td><p><span class="vexpl"><span class="red"><strong>Note:<br>
159 f0fe3d30 Scott Ullrich
                      </strong></span>If the DNS forwarder is enabled, the DHCP
160
                      service (if enabled) will automatically serve the LAN IP
161
                      address as a DNS server to DHCP clients so they will use
162
                      the forwarder. The DNS forwarder will use the DNS servers
163
                      entered in <a href="system.php">System: General setup</a>
164
                      or those obtained via DHCP or PPP on WAN if the &quot;Allow
165 dacefa7f Scott Ullrich
                      DNS server list to be overridden by DHCP/PPP on WAN&quot;
166 f0fe3d30 Scott Ullrich
                      is checked. If you don't use that option (or if you use
167
                      a static IP address on WAN), you must manually specify at
168
                      least one DNS server on the <a href="system.php">System:
169 5b237745 Scott Ullrich
                      General setup</a> page.<br>
170
                      <br>
171 f0fe3d30 Scott Ullrich
                      You may enter records that override the results from the
172 dacefa7f Scott Ullrich
                      forwarders below.</span></p></td>
173 5b237745 Scott Ullrich
                </tr>
174 4d6ba181 Scott Ullrich
        </table>
175
        &nbsp;<br>
176
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
177 5b237745 Scott Ullrich
                <tr>
178
                  <td width="20%" class="listhdrr">Host</td>
179
                  <td width="25%" class="listhdrr">Domain</td>
180
                  <td width="20%" class="listhdrr">IP</td>
181
                  <td width="25%" class="listhdr">Description</td>
182 d415d821 Seth Mos
                  <td width="10%" class="list">
183
                    <table border="0" cellspacing="0" cellpadding="1">
184
                      <tr>
185
			<td width="17"></td>
186
                        <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>
187
                      </tr>
188
                    </table>
189
		  </td>
190
		</tr>
191 5b237745 Scott Ullrich
			  <?php $i = 0; foreach ($a_hosts as $hostent): ?>
192
                <tr>
193 835f9aca Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
194 5b237745 Scott Ullrich
                    <?=strtolower($hostent['host']);?>&nbsp;
195
                  </td>
196 835f9aca Bill Marquette
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
197 5b237745 Scott Ullrich
                    <?=strtolower($hostent['domain']);?>&nbsp;
198
                  </td>
199 835f9aca Bill Marquette
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
200 5b237745 Scott Ullrich
                    <?=$hostent['ip'];?>&nbsp;
201
                  </td>
202 835f9aca Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
203 0e1dce26 Scott Ullrich
                    <?=htmlspecialchars($hostent['descr']);?>&nbsp;
204 5b237745 Scott Ullrich
                  </td>
205 ebe566eb Bill Marquette
                  <td valign="middle" nowrap class="list">
206
                    <table border="0" cellspacing="0" cellpadding="1">
207
                      <tr>
208 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>
209
                        <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>
210 ebe566eb Bill Marquette
		      </tr>
211
                   </table>
212
                </tr>
213
		<?php $i++; endforeach; ?>
214 f0fe3d30 Scott Ullrich
                <tr>
215 5b237745 Scott Ullrich
                  <td class="list" colspan="4"></td>
216 ebe566eb Bill Marquette
                  <td class="list">
217
                    <table border="0" cellspacing="0" cellpadding="1">
218
                      <tr>
219 d415d821 Seth Mos
			<td width="17"></td>
220 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>
221 ebe566eb Bill Marquette
                      </tr>
222
                    </table>
223 ed137452 Scott Ullrich
		   </td>
224 4d6ba181 Scott Ullrich
	</table>
225 0c2b5df7 Scott Ullrich
<!-- update to enable domain overrides -->
226 4d6ba181 Scott Ullrich
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
227 c21d4582 Scott Ullrich
	       <tr><td>&nbsp;</td></tr>
228 0c2b5df7 Scott Ullrich
               <tr>
229
                 <td><p>Below you can override an entire domain by specifying an
230
                        authoritative dns server to be queried for that domain.</p></td>
231
               </tr>
232 4d6ba181 Scott Ullrich
        </table>
233
	&nbsp;<br>
234
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
235 0c2b5df7 Scott Ullrich
               <tr>
236
                 <td width="35%" class="listhdrr">Domain</td>
237
                 <td width="20%" class="listhdrr">IP</td>
238
                 <td width="35%" class="listhdr">Description</td>
239 d415d821 Seth Mos
                 <td width="10%" class="list">
240
			<table border="0" cellspacing="0" cellpadding="1">
241
			    <tr>
242
				<td width="17" heigth="17"></td>			
243
				<td><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
			    </tr>
245
			</table>
246
		 </td>
247 0c2b5df7 Scott Ullrich
                              </tr>
248
                        <?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
249
               <tr>
250
                 <td class="listlr">
251
                   <?=strtolower($doment['domain']);?>&nbsp;
252
                 </td>
253
                 <td class="listr">
254
                   <?=$doment['ip'];?>&nbsp;
255
                 </td>
256 d4da6249 Scott Ullrich
                 <td class="listbg">
257 0c2b5df7 Scott Ullrich
                   <?=htmlspecialchars($doment['descr']);?>&nbsp;
258
                 </td>
259 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>
260
                    &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>
261 0c2b5df7 Scott Ullrich
                              </tr>
262
                        <?php $i++; endforeach; ?>
263
               <tr>
264
                 <td class="list" colspan="3"></td>
265 d415d821 Seth Mos
                 <td class="list">
266
			<table border="0" cellspacing="0" cellpadding="1">
267
			    <tr>
268
				<td width="17" heigth="17"></td>			
269
				<td><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>
270
			    </tr>
271
			</table>
272
		 </td>
273 0c2b5df7 Scott Ullrich
	       </tr>
274 4d6ba181 Scott Ullrich
        </table>
275
        </form>
276 6a01ea44 Bill Marquette
<script language="JavaScript">
277
<!--
278
enable_change(false);
279
//-->
280
</script>
281 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
282
</body>
283
</html>