Project

General

Profile

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