Project

General

Profile

Download (10.4 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
require("guiconfig.inc");
33

    
34
$pconfig['enable']  = isset($config['dnsmasq']['enable']);
35
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
36

    
37
if (!is_array($config['dnsmasq']['hosts'])) 
38
	$config['dnsmasq']['hosts'] = array();
39

    
40
if (!is_array($config['dnsmasq']['domainoverrides'])) 
41
       $config['dnsmasq']['domainoverrides'] = array();
42

    
43
hosts_sort();
44

    
45
$a_hosts 	   = &$config['dnsmasq']['hosts'];
46
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
47

    
48
if ($_POST) {
49

    
50
	$pconfig = $_POST;
51

    
52
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
53
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
54

    
55
	write_config();
56

    
57
	$retval = 0;
58

    
59
	config_lock();
60
	$retval = services_dnsmasq_configure();
61
	config_unlock();
62

    
63
	$savemsg = get_std_save_message($retval);
64

    
65
	if ($retval == 0) {
66
		if (file_exists($d_hostsdirty_path))
67
			unlink($d_hostsdirty_path);
68
	}
69
}
70

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

    
92
$pgtitle = "Services: DNS forwarder";
93
include("head.inc");
94

    
95
?>
96

    
97
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
98
<?php include("fbegin.inc"); ?>
99
<p class="pgtitle"><?=$pgtitle?></p>
100
<form action="services_dnsmasq.php" method="post">
101
<?php if ($savemsg) print_info_box($savemsg); ?>
102
<?php if (file_exists($d_hostsdirty_path)): ?><p>
103
<?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>
104
<?php endif; ?>
105
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
106
                <tr>
107
                  <td class="vtable"><p>
108
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
109
                      <strong>Enable DNS forwarder<br>
110
                      </strong></p></td>
111
                </tr>
112
                <tr>
113
                  <td class="vtable"><p>
114
                      <input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
115
                      <strong>Register DHCP leases in DNS forwarder<br>
116
                      </strong>If this option is set, then machines that specify
117
                      their hostname when requesting a DHCP lease will be registered
118
                      in the DNS forwarder, so that their name can be resolved.
119
                      You should also set the domain in <a href="system.php">System:
120
                      General setup</a> to the proper value.</p>
121
                    </td>
122
                </tr>
123
                <tr>
124
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
125
                  </td>
126
                </tr>
127
                <tr>
128
                  <td><p><span class="vexpl"><span class="red"><strong>Note:<br>
129
                      </strong></span>If the DNS forwarder is enabled, the DHCP
130
                      service (if enabled) will automatically serve the LAN IP
131
                      address as a DNS server to DHCP clients so they will use
132
                      the forwarder. The DNS forwarder will use the DNS servers
133
                      entered in <a href="system.php">System: General setup</a>
134
                      or those obtained via DHCP or PPP on WAN if the &quot;Allow
135
                      DNS server list to be overridden by DHCP/PPP on WAN&quot;
136
                      is checked. If you don't use that option (or if you use
137
                      a static IP address on WAN), you must manually specify at
138
                      least one DNS server on the <a href="system.php">System:
139
                      General setup</a> page.<br>
140
                      <br>
141
                      You may enter records that override the results from the
142
                      forwarders below.</span></p></td>
143
                </tr>
144
        </table>
145
        &nbsp;<br>
146
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
147
                <tr>
148
                  <td width="20%" class="listhdrr">Host</td>
149
                  <td width="25%" class="listhdrr">Domain</td>
150
                  <td width="20%" class="listhdrr">IP</td>
151
                  <td width="25%" class="listhdr">Description</td>
152
                  <td width="10%" class="list"></td>
153
				</tr>
154
			  <?php $i = 0; foreach ($a_hosts as $hostent): ?>
155
                <tr>
156
                  <td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
157
                    <?=strtolower($hostent['host']);?>&nbsp;
158
                  </td>
159
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
160
                    <?=strtolower($hostent['domain']);?>&nbsp;
161
                  </td>
162
                  <td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
163
                    <?=$hostent['ip'];?>&nbsp;
164
                  </td>
165
                  <td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
166
                    <font color="#FFFFFF"><?=htmlspecialchars($hostent['descr']);?>&nbsp;
167
                  </td>
168
                  <td valign="middle" nowrap class="list">
169
                    <table border="0" cellspacing="0" cellpadding="1">
170
                      <tr>
171
                        <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>
172
                        <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>
173
		      </tr>
174
                   </table>
175
                </tr>
176
		<?php $i++; endforeach; ?>
177
                <tr>
178
                  <td class="list" colspan="4"></td>
179
                  <td class="list">
180
                    <table border="0" cellspacing="0" cellpadding="1">
181
                      <tr>
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
	</table>
187
<!-- update to enable domain overrides -->
188
        <table width="100%" border="0" cellpadding="6" cellspacing="0">
189
	       <tr><td>&nbsp;</td></tr>
190
               <tr>
191
                 <td><p>Below you can override an entire domain by specifying an
192
                        authoritative dns server to be queried for that domain.</p></td>
193
               </tr>
194
        </table>
195
	&nbsp;<br>
196
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
197
               <tr>
198
                 <td width="35%" class="listhdrr">Domain</td>
199
                 <td width="20%" class="listhdrr">IP</td>
200
                 <td width="35%" class="listhdr">Description</td>
201
                 <td width="10%" class="list"></td>
202
                              </tr>
203
                        <?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
204
               <tr>
205
                 <td class="listlr">
206
                   <?=strtolower($doment['domain']);?>&nbsp;
207
                 </td>
208
                 <td class="listr">
209
                   <?=$doment['ip'];?>&nbsp;
210
                 </td>
211
                 <td class="listbg"><font color="#FFFFFF">
212
                   <?=htmlspecialchars($doment['descr']);?>&nbsp;
213
                 </td>
214
                 <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>
215
                    &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>
216
                              </tr>
217
                        <?php $i++; endforeach; ?>
218
               <tr>
219
                 <td class="list" colspan="3"></td>
220
                 <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>
221
	       </tr>
222
        </table>
223
        </form>
224
<?php include("fend.inc"); ?>
225
</body>
226
</html>
(105-105/159)