Project

General

Profile

Download (12.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_dnsmasq.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	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

    
20
	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
##|+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
require("guiconfig.inc");
41

    
42
$pconfig['enable']  = isset($config['dnsmasq']['enable']);
43
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
44
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
45

    
46
if (!is_array($config['dnsmasq']['hosts'])) 
47
	$config['dnsmasq']['hosts'] = array();
48

    
49
if (!is_array($config['dnsmasq']['domainoverrides'])) 
50
       $config['dnsmasq']['domainoverrides'] = array();
51

    
52
hosts_sort();
53

    
54
$a_hosts 	   = &$config['dnsmasq']['hosts'];
55
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
56

    
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
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
64

    
65
	write_config();
66

    
67
	$retval = 0;
68
	$retval = services_dnsmasq_configure();
69
	$savemsg = get_std_save_message($retval);
70

    
71
	if ($retval == 0) {
72
		if (file_exists($d_hostsdirty_path))
73
			unlink($d_hostsdirty_path);
74
	}
75
}
76

    
77
if ($_GET['act'] == "del") {
78
       if ($_GET['type'] == 'host') {
79
               if ($a_hosts[$_GET['id']]) {
80
                       unset($a_hosts[$_GET['id']]);
81
                       write_config();
82
                       touch($d_hostsdirty_path);
83
                       header("Location: services_dnsmasq.php");
84
                       exit;
85
               }
86
       }
87
       elseif ($_GET['type'] == 'doverride') {
88
               if ($a_domainOverrides[$_GET['id']]) {
89
                       unset($a_domainOverrides[$_GET['id']]);
90
                       write_config();
91
                       touch($d_hostsdirty_path);
92
                       header("Location: services_dnsmasq.php");
93
                       exit;
94
               }
95
       }
96
}
97

    
98
$pgtitle = array("Services","DNS forwarder");
99
include("head.inc");
100

    
101
?>
102

    
103
<script language="JavaScript">
104
<!--
105
function enable_change(enable_over) {
106
	var endis;
107
	endis = !(document.iform.enable.checked || enable_over);
108
	document.iform.regdhcp.disabled = endis;
109
	document.iform.regdhcpstatic.disabled = endis;
110
}
111
//-->
112
</script>
113

    
114
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
115
<?php include("fbegin.inc"); ?>
116
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
117
<?php if ($savemsg) print_info_box($savemsg); ?>
118
<?php if (file_exists($d_hostsdirty_path)): ?><p>
119
<?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>
120
<?php endif; ?>
121
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
122
                <tr>
123
                  <td class="vtable"><p>
124
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
125
                      <strong>Enable DNS forwarder<br>
126
                      </strong></p></td>
127
                </tr>
128
                <tr>
129
                  <td class="vtable"><p>
130
                      <input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
131
                      <strong>Register DHCP leases in DNS forwarder<br>
132
                      </strong>If this option is set, then machines that specify
133
                      their hostname when requesting a DHCP lease will be registered
134
                      in the DNS forwarder, so that their name can be resolved.
135
                      You should also set the domain in <a href="system.php">System:
136
                      General setup</a> to the proper value.</p>
137
                    </td>
138
                </tr>
139
                <tr>
140
                  <td class="vtable"><p>
141
                      <input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
142
                      <strong>Register DHCP static mappings in DNS forwarder<br>
143
                      </strong>If this option is set, then DHCP static mappings will 
144
					  be registered in the DNS forwarder, so that their name can be 
145
					  resolved. You should also set the domain in <a href="system.php">
146
					  System: General setup</a> to the proper value.</p>
147
                    </td>
148
                </tr>				
149
                <tr>
150
                  <td> <input name="submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
151
                  </td>
152
                </tr>
153
                <tr>
154
                  <td><p><span class="vexpl"><span class="red"><strong>Note:<br>
155
                      </strong></span>If the DNS forwarder is enabled, the DHCP
156
                      service (if enabled) will automatically serve the LAN IP
157
                      address as a DNS server to DHCP clients so they will use
158
                      the forwarder. The DNS forwarder will use the DNS servers
159
                      entered in <a href="system.php">System: General setup</a>
160
                      or those obtained via DHCP or PPP on WAN if the &quot;Allow
161
                      DNS server list to be overridden by DHCP/PPP on WAN&quot;
162
                      is checked. If you don't use that option (or if you use
163
                      a static IP address on WAN), you must manually specify at
164
                      least one DNS server on the <a href="system.php">System:
165
                      General setup</a> page.<br>
166
                      <br>
167
                      You may enter records that override the results from the
168
                      forwarders below.</span></p></td>
169
                </tr>
170
        </table>
171
        &nbsp;<br>
172
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
173
                <tr>
174
                  <td width="20%" class="listhdrr">Host</td>
175
                  <td width="25%" class="listhdrr">Domain</td>
176
                  <td width="20%" class="listhdrr">IP</td>
177
                  <td width="25%" class="listhdr">Description</td>
178
                  <td width="10%" class="list">
179
                    <table border="0" cellspacing="0" cellpadding="1">
180
                      <tr>
181
			<td width="17"></td>
182
                        <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>
183
                      </tr>
184
                    </table>
185
		  </td>
186
		</tr>
187
			  <?php $i = 0; foreach ($a_hosts as $hostent): ?>
188
                <tr>
189
                  <td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
190
                    <?=strtolower($hostent['host']);?>&nbsp;
191
                  </td>
192
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
193
                    <?=strtolower($hostent['domain']);?>&nbsp;
194
                  </td>
195
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
196
                    <?=$hostent['ip'];?>&nbsp;
197
                  </td>
198
                  <td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
199
                    <?=htmlspecialchars($hostent['descr']);?>&nbsp;
200
                  </td>
201
                  <td valign="middle" nowrap class="list">
202
                    <table border="0" cellspacing="0" cellpadding="1">
203
                      <tr>
204
                        <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>
205
                        <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>
206
		      </tr>
207
                   </table>
208
                </tr>
209
		<?php $i++; endforeach; ?>
210
                <tr>
211
                  <td class="list" colspan="4"></td>
212
                  <td class="list">
213
                    <table border="0" cellspacing="0" cellpadding="1">
214
                      <tr>
215
			<td width="17"></td>
216
                        <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>
217
                      </tr>
218
                    </table>
219
		   </td>
220
	</table>
221
<!-- update to enable domain overrides -->
222
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
223
	       <tr><td>&nbsp;</td></tr>
224
               <tr>
225
                 <td><p>Below you can override an entire domain by specifying an
226
                        authoritative dns server to be queried for that domain.</p></td>
227
               </tr>
228
        </table>
229
	&nbsp;<br>
230
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
231
               <tr>
232
                 <td width="35%" class="listhdrr">Domain</td>
233
                 <td width="20%" class="listhdrr">IP</td>
234
                 <td width="35%" class="listhdr">Description</td>
235
                 <td width="10%" class="list">
236
			<table border="0" cellspacing="0" cellpadding="1">
237
			    <tr>
238
				<td width="17" heigth="17"></td>			
239
				<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>
240
			    </tr>
241
			</table>
242
		 </td>
243
                              </tr>
244
                        <?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
245
               <tr>
246
                 <td class="listlr">
247
                   <?=strtolower($doment['domain']);?>&nbsp;
248
                 </td>
249
                 <td class="listr">
250
                   <?=$doment['ip'];?>&nbsp;
251
                 </td>
252
                 <td class="listbg">
253
                   <?=htmlspecialchars($doment['descr']);?>&nbsp;
254
                 </td>
255
                 <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>
256
                    &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>
257
                              </tr>
258
                        <?php $i++; endforeach; ?>
259
               <tr>
260
                 <td class="list" colspan="3"></td>
261
                 <td class="list">
262
			<table border="0" cellspacing="0" cellpadding="1">
263
			    <tr>
264
				<td width="17" heigth="17"></td>			
265
				<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>
266
			    </tr>
267
			</table>
268
		 </td>
269
	       </tr>
270
        </table>
271
        </form>
272
<script language="JavaScript">
273
<!--
274
enable_change(false);
275
//-->
276
</script>
277
<?php include("fend.inc"); ?>
278
</body>
279
</html>
(124-124/206)