Project

General

Profile

Download (12.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php 
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_dnsmasq_edit.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 6317d31d Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9 5b237745 Scott Ullrich
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	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
	
21
	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 1d333258 Scott Ullrich
/*
33
	pfSense_MODULE:	dnsforwarder
34
*/
35 5b237745 Scott Ullrich
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-services-dnsforwarder-edithost
38
##|*NAME=Services: DNS Forwarder: Edit host page
39
##|*DESCR=Allow access to the 'Services: DNS Forwarder: Edit host' page.
40
##|*MATCH=services_dnsmasq_edit.php*
41
##|-PRIV
42
43 4504a769 Ermal Lu?i
function hostcmp($a, $b) {
44
	return strcasecmp($a['host'], $b['host']);
45
}
46
47 0d64af59 Ermal Lu?i
function hosts_sort() {
48
        global $g, $config;
49
50
        if (!is_array($config['dnsmasq']['hosts']))
51
                return;
52
53
        usort($config['dnsmasq']['hosts'], "hostcmp");
54
}
55 6b07c15a Matthew Grooms
56 5b237745 Scott Ullrich
require("guiconfig.inc");
57
58 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_dnsmasq.php');
59
60 4d6ba181 Scott Ullrich
if (!is_array($config['dnsmasq']['hosts'])) 
61 5b237745 Scott Ullrich
	$config['dnsmasq']['hosts'] = array();
62 4d6ba181 Scott Ullrich
63 5b237745 Scott Ullrich
$a_hosts = &$config['dnsmasq']['hosts'];
64
65 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
66
	$id = $_GET['id'];
67
if (isset($_POST['id']) && is_numericint($_POST['id']))
68 5b237745 Scott Ullrich
	$id = $_POST['id'];
69
70
if (isset($id) && $a_hosts[$id]) {
71
	$pconfig['host'] = $a_hosts[$id]['host'];
72
	$pconfig['domain'] = $a_hosts[$id]['domain'];
73
	$pconfig['ip'] = $a_hosts[$id]['ip'];
74
	$pconfig['descr'] = $a_hosts[$id]['descr'];
75 5a2a8349 Lorenz Schori
	$pconfig['aliases'] = $a_hosts[$id]['aliases'];
76 5b237745 Scott Ullrich
}
77
78
if ($_POST) {
79
80
	unset($input_errors);
81
	$pconfig = $_POST;
82
83
	/* input validation */
84
	$reqdfields = explode(" ", "domain ip");
85 065bc89a Rafael Lucas
	$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
86 5b237745 Scott Ullrich
	
87 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88 5b237745 Scott Ullrich
	
89 84c4efc4 Phil Davis
	if ($_POST['host']) {
90
		if (!is_hostname($_POST['host'])) { 
91
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'. It may not start or end with '-'.");
92
		} else {
93
			if (!is_unqualified_hostname($_POST['host'])) {
94
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
95
			}
96
		}
97
	}
98 4d6ba181 Scott Ullrich
99
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
100 065bc89a Rafael Lucas
		$input_errors[] = gettext("A valid domain must be specified.");
101 4d6ba181 Scott Ullrich
		
102
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
103 065bc89a Rafael Lucas
		$input_errors[] = gettext("A valid IP address must be specified.");
104 5b237745 Scott Ullrich
105 5a2a8349 Lorenz Schori
	/* collect aliases */
106
	$aliases = array();
107
	foreach ($_POST as $key => $value) {
108
		$entry = '';
109
		if (!substr_compare('aliashost', $key, 0, 9)) {
110
			$entry = substr($key, 9);
111
			$field = 'host';
112
		}
113
		elseif (!substr_compare('aliasdomain', $key, 0, 11)) {
114
			$entry = substr($key, 11);
115
			$field = 'domain';
116
		}
117
		elseif (!substr_compare('aliasdescription', $key, 0, 16)) {
118
			$entry = substr($key, 16);
119
			$field = 'description';
120
		}
121
		if (ctype_digit($entry)) {
122
			$aliases[$entry][$field] = $value;
123
		}
124
	}
125
	$pconfig['aliases']['item'] = $aliases;
126
127
	/* validate aliases */
128
	foreach ($aliases as $idx => $alias) {
129
		$aliasreqdfields = array('aliasdomain' . $idx);
130
		$aliasreqdfieldsn = array(gettext("Alias Domain"));
131
132 1e9b4611 Renato Botelho
		do_input_validation($_POST, $aliasreqdfields, $aliasreqdfieldsn, $input_errors);
133 84c4efc4 Phil Davis
		if ($alias['host']) {
134
			if (!is_hostname($alias['host'])) {
135
				$input_errors[] = gettext("Hostnames in an alias list can only contain the characters A-Z, 0-9 and '-'. They may not start or end with '-'.");
136
			} else {
137
				if (!is_unqualified_hostname($alias['host'])) {
138
					$input_errors[] = gettext("A valid alias hostname is specified, but the domain name part should be omitted");
139
				}
140
			}
141 5a2a8349 Lorenz Schori
		}
142
		if (($alias['domain'] && !is_domain($alias['domain']))) {
143
			$input_errors[] = gettext("A valid domain must be specified in alias list.");
144
		}
145
	}
146
147 5b237745 Scott Ullrich
	/* check for overlaps */
148
	foreach ($a_hosts as $hostent) {
149
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
150
			continue;
151
152 424be584 jim-p
		if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])
153
			&& ((is_ipaddrv4($hostent['ip']) && is_ipaddrv4($_POST['ip'])) || (is_ipaddrv6($hostent['ip']) && is_ipaddrv6($_POST['ip'])))) {
154 065bc89a Rafael Lucas
			$input_errors[] = gettext("This host/domain already exists.");
155 5b237745 Scott Ullrich
			break;
156
		}
157
	}
158
159
	if (!$input_errors) {
160
		$hostent = array();
161
		$hostent['host'] = $_POST['host'];
162
		$hostent['domain'] = $_POST['domain'];
163
		$hostent['ip'] = $_POST['ip'];
164
		$hostent['descr'] = $_POST['descr'];
165 5a2a8349 Lorenz Schori
		$hostent['aliases']['item'] = $aliases;
166 5b237745 Scott Ullrich
167
		if (isset($id) && $a_hosts[$id])
168
			$a_hosts[$id] = $hostent;
169
		else
170
			$a_hosts[] = $hostent;
171 0e3aa71c Erik Fonnesbeck
		hosts_sort();
172 5b237745 Scott Ullrich
		
173 a368a026 Ermal Lu?i
		mark_subsystem_dirty('hosts');
174 5b237745 Scott Ullrich
		
175
		write_config();
176
		
177
		header("Location: services_dnsmasq.php");
178
		exit;
179
	}
180
}
181 b63695db Scott Ullrich
182 065bc89a Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"),gettext("Edit host"));
183 8f6875de Phil Davis
$shortcut_section = "forwarder";
184 b63695db Scott Ullrich
include("head.inc");
185
186 5b237745 Scott Ullrich
?>
187
188 5a2a8349 Lorenz Schori
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
189 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
190 5a2a8349 Lorenz Schori
191
<script type="text/javascript" src="/javascript/row_helper.js">
192
</script>
193
194
<script type="text/javascript">
195 7bd5b320 Colin Fleming
//<![CDATA[
196 5a2a8349 Lorenz Schori
	rowname[0] = "aliashost";
197
	rowtype[0] = "textbox";
198
	rowsize[0] = "20";
199
	rowname[1] = "aliasdomain";
200
	rowtype[1] = "textbox";
201
	rowsize[1] = "20";
202
	rowname[2] = "aliasdescription";
203
	rowtype[2] = "textbox";
204
	rowsize[2] = "20";
205 7bd5b320 Colin Fleming
//]]>
206 5a2a8349 Lorenz Schori
</script>
207
208 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
209 4d6ba181 Scott Ullrich
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
210 7bd5b320 Colin Fleming
        <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="dns edit">
211 e22987a4 Scott Ullrich
				<tr>
212 065bc89a Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Forwarder entry");?></td>
213 e22987a4 Scott Ullrich
				</tr>	
214 5b237745 Scott Ullrich
                <tr>
215 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
216 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
217 aab23249 Phil Davis
                    <input name="host" type="text" class="formfld unknown" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>" />
218 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without".
219
                   " domain part"); ?><br />
220 463def4b Carlos Eduardo Ramos
                   <?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span></td>
221 5b237745 Scott Ullrich
                </tr>
222
				<tr>
223 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
224 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
225 aab23249 Phil Davis
                    <input name="domain" type="text" class="formfld unknown" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>" />
226 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("Domain of the host"); ?><br />
227 463def4b Carlos Eduardo Ramos
                   <?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span></td>
228 5b237745 Scott Ullrich
                </tr>
229
				<tr>
230 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
231 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
232 aab23249 Phil Davis
                    <input name="ip" type="text" class="formfld unknown" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>" />
233 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("IP address of the host"); ?><br />
234 4af6167d jim-p
                   <?=gettext("e.g."); ?> <em>192.168.100.100</em> <?=gettext("or"); ?> <em>fd00:abcd::1</em></span></td>
235 5b237745 Scott Ullrich
                </tr>
236
				<tr>
237 065bc89a Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
238 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
239 aab23249 Phil Davis
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
240 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
241 065bc89a Rafael Lucas
                   " for your reference (not parsed).");?></span></td>
242 5b237745 Scott Ullrich
                </tr>
243 5a2a8349 Lorenz Schori
				<tr>
244 85d1b51b Lorenz Schori
                  <td width="22%" valign="top" class="vncell"><div id="addressnetworkport"><?=gettext("Aliases"); ?></div></td>
245
                  <td width="78%" class="vtable">
246 7bd5b320 Colin Fleming
                    <table id="maintable" summary="aliases">
247 85d1b51b Lorenz Schori
                      <tbody>
248
                        <tr>
249
                          <td colspan="4">
250
                            <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
251
                              <?=gettext("Enter additional names for this host."); ?>
252
                            </div>
253
                          </td>
254
                        </tr>
255
                        <tr>
256
                          <td><div id="onecolumn"><?=gettext("Host");?></div></td>
257
                          <td><div id="twocolumn"><?=gettext("Domain");?></div></td>
258
                          <td><div id="threecolumn"><?=gettext("Description");?></div></td>
259
                        </tr>
260
                        <?php
261
                          $counter = 0;
262
                          if($pconfig['aliases']['item']):
263
                            foreach($pconfig['aliases']['item'] as $item):
264
                              $host = $item['host'];
265
                              $domain = $item['domain'];
266
                              $description = $item['description'];
267
                        ?>
268
                        <tr>
269
                          <td>
270
                            <input autocomplete="off" name="aliashost<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliashost<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($host);?>" />
271
                          </td>
272
                          <td>
273
                            <input autocomplete="off" name="aliasdomain<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdomain<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($domain);?>" />
274
                          </td>
275
                          <td>
276
                            <input name="aliasdescription<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdescription<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($description);?>" />
277
                          </td>
278
                          <td>
279
                            <a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="" title="<?=gettext("remove this entry"); ?>" /></a>
280
                          </td>
281
                        </tr>
282
                        <?php
283
                              $counter++;
284
                            endforeach;
285
                          endif;
286
                        ?>
287
                      </tbody>
288
                    </table>
289
                    <a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
290
                      <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
291
                    </a>
292
                    <script type="text/javascript">
293 7bd5b320 Colin Fleming
                    //<![CDATA[
294 85d1b51b Lorenz Schori
                      field_counter_js = 3;
295
                      rows = 1;
296
                      totalrows = <?php echo $counter; ?>;
297
                      loaded = <?php echo $counter; ?>;
298 7bd5b320 Colin Fleming
                    //]]>
299 85d1b51b Lorenz Schori
                    </script>
300
                  </td>
301
                </tr>
302 5b237745 Scott Ullrich
                <tr>
303
                  <td width="22%" valign="top">&nbsp;</td>
304
                  <td width="78%"> 
305 62424bdb Renato Botelho
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
306
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
307 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_hosts[$id]): ?>
308 7bd5b320 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
309 5b237745 Scott Ullrich
                    <?php endif; ?>
310
                  </td>
311
                </tr>
312 4d6ba181 Scott Ullrich
        </table>
313 5b237745 Scott Ullrich
</form>
314
<?php include("fend.inc"); ?>
315
</body>
316
</html>