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

    
69
	config_lock();
70
	$retval = services_dnsmasq_configure();
71
	config_unlock();
72

    
73
	$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
       if ($_GET['type'] == 'host') {
83
               if ($a_hosts[$_GET['id']]) {
84
                       unset($a_hosts[$_GET['id']]);
85
                       write_config();
86
                       touch($d_hostsdirty_path);
87
                       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
                       touch($d_hostsdirty_path);
96
                       header("Location: services_dnsmasq.php");
97
                       exit;
98
               }
99
       }
100
}
101

    
102
$pgtitle = array("Services","DNS forwarder");
103
include("head.inc");
104

    
105
?>
106

    
107
<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
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
119
<?php include("fbegin.inc"); ?>
120
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
121
<?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
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
126
                <tr>
127
                  <td class="vtable"><p>
128
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
129
                      <strong>Enable DNS forwarder<br>
130
                      </strong></p></td>
131
                </tr>
132
                <tr>
133
                  <td class="vtable"><p>
134
                      <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
                      </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
                      General setup</a> to the proper value.</p>
141
                    </td>
142
                </tr>
143
                <tr>
144
                  <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
                  </td>
156
                </tr>
157
                <tr>
158
                  <td><p><span class="vexpl"><span class="red"><strong>Note:<br>
159
                      </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
                      DNS server list to be overridden by DHCP/PPP on WAN&quot;
166
                      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
                      General setup</a> page.<br>
170
                      <br>
171
                      You may enter records that override the results from the
172
                      forwarders below.</span></p></td>
173
                </tr>
174
        </table>
175
        &nbsp;<br>
176
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
177
                <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
                  <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
			  <?php $i = 0; foreach ($a_hosts as $hostent): ?>
192
                <tr>
193
                  <td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
194
                    <?=strtolower($hostent['host']);?>&nbsp;
195
                  </td>
196
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
197
                    <?=strtolower($hostent['domain']);?>&nbsp;
198
                  </td>
199
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
200
                    <?=$hostent['ip'];?>&nbsp;
201
                  </td>
202
                  <td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
203
                    <font color="#FFFFFF"><?=htmlspecialchars($hostent['descr']);?>&nbsp;
204
                  </td>
205
                  <td valign="middle" nowrap class="list">
206
                    <table border="0" cellspacing="0" cellpadding="1">
207
                      <tr>
208
                        <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
		      </tr>
211
                   </table>
212
                </tr>
213
		<?php $i++; endforeach; ?>
214
                <tr>
215
                  <td class="list" colspan="4"></td>
216
                  <td class="list">
217
                    <table border="0" cellspacing="0" cellpadding="1">
218
                      <tr>
219
			<td width="17"></td>
220
                        <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
                      </tr>
222
                    </table>
223
		   </td>
224
	</table>
225
<!-- update to enable domain overrides -->
226
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
227
	       <tr><td>&nbsp;</td></tr>
228
               <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
        </table>
233
	&nbsp;<br>
234
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
235
               <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
                 <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
                              </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
                 <td class="listbg"><font color="#FFFFFF">
257
                   <?=htmlspecialchars($doment['descr']);?>&nbsp;
258
                 </td>
259
                 <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
                              </tr>
262
                        <?php $i++; endforeach; ?>
263
               <tr>
264
                 <td class="list" colspan="3"></td>
265
                 <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
	       </tr>
274
        </table>
275
        </form>
276
<script language="JavaScript">
277
<!--
278
enable_change(false);
279
//-->
280
</script>
281
<?php include("fend.inc"); ?>
282
</body>
283
</html>
(131-131/210)