Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
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
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
9
	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
/*
33
	pfSense_MODULE:	dnsforwarder
34
*/
35

    
36
##|+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
function hostcmp($a, $b) {
44
	return strcasecmp($a['host'], $b['host']);
45
}
46

    
47
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

    
56
require("guiconfig.inc");
57

    
58
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_dnsmasq.php');
59

    
60
if (!is_array($config['dnsmasq']['hosts'])) 
61
	$config['dnsmasq']['hosts'] = array();
62

    
63
$a_hosts = &$config['dnsmasq']['hosts'];
64

    
65
if (is_numericint($_GET['id']))
66
	$id = $_GET['id'];
67
if (isset($_POST['id']) && is_numericint($_POST['id']))
68
	$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
	$pconfig['aliases'] = $a_hosts[$id]['aliases'];
76
}
77

    
78
if ($_POST) {
79

    
80
	unset($input_errors);
81
	$pconfig = $_POST;
82

    
83
	/* input validation */
84
	$reqdfields = explode(" ", "domain ip");
85
	$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
86
	
87
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88
	
89
	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

    
99
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
100
		$input_errors[] = gettext("A valid domain must be specified.");
101
		
102
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
103
		$input_errors[] = gettext("A valid IP address must be specified.");
104

    
105
	/* 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
		do_input_validation($_POST, $aliasreqdfields, $aliasreqdfieldsn, $input_errors);
133
		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
		}
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
	/* check for overlaps */
148
	foreach ($a_hosts as $hostent) {
149
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
150
			continue;
151

    
152
		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
			$input_errors[] = gettext("This host/domain already exists.");
155
			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
		$hostent['aliases']['item'] = $aliases;
166

    
167
		if (isset($id) && $a_hosts[$id])
168
			$a_hosts[$id] = $hostent;
169
		else
170
			$a_hosts[] = $hostent;
171
		hosts_sort();
172
		
173
		mark_subsystem_dirty('hosts');
174
		
175
		write_config();
176
		
177
		header("Location: services_dnsmasq.php");
178
		exit;
179
	}
180
}
181

    
182
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"),gettext("Edit host"));
183
$shortcut_section = "forwarder";
184
include("head.inc");
185

    
186
?>
187

    
188
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
189
<?php include("fbegin.inc"); ?>
190

    
191
<script type="text/javascript" src="/javascript/row_helper.js">
192
</script>
193

    
194
<script type="text/javascript">
195
//<![CDATA[
196
	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
//]]>
206
</script>
207

    
208
<?php if ($input_errors) print_input_errors($input_errors); ?>
209
        <form action="services_dnsmasq_edit.php" method="post" name="iform" id="iform">
210
        <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="dns edit">
211
				<tr>
212
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Forwarder entry");?></td>
213
				</tr>	
214
                <tr>
215
                  <td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
216
                  <td width="78%" class="vtable"> 
217
                    <input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>" />
218
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without".
219
                   " domain part"); ?><br />
220
                   <?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span></td>
221
                </tr>
222
				<tr>
223
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
224
                  <td width="78%" class="vtable"> 
225
                    <input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>" />
226
                    <br /> <span class="vexpl"><?=gettext("Domain of the host"); ?><br />
227
                   <?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span></td>
228
                </tr>
229
				<tr>
230
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
231
                  <td width="78%" class="vtable"> 
232
                    <input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>" />
233
                    <br /> <span class="vexpl"><?=gettext("IP address of the host"); ?><br />
234
                   <?=gettext("e.g."); ?> <em>192.168.100.100</em> <?=gettext("or"); ?> <em>fd00:abcd::1</em></span></td>
235
                </tr>
236
				<tr>
237
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
238
                  <td width="78%" class="vtable"> 
239
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
240
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
241
                   " for your reference (not parsed).");?></span></td>
242
                </tr>
243
				<tr>
244
                  <td width="22%" valign="top" class="vncell"><div id="addressnetworkport"><?=gettext("Aliases"); ?></div></td>
245
                  <td width="78%" class="vtable">
246
                    <table id="maintable" summary="aliases">
247
                      <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
                    //<![CDATA[
294
                      field_counter_js = 3;
295
                      rows = 1;
296
                      totalrows = <?php echo $counter; ?>;
297
                      loaded = <?php echo $counter; ?>;
298
                    //]]>
299
                    </script>
300
                  </td>
301
                </tr>
302
                <tr>
303
                  <td width="22%" valign="top">&nbsp;</td>
304
                  <td width="78%"> 
305
                    <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
                    <?php if (isset($id) && $a_hosts[$id]): ?>
308
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
309
                    <?php endif; ?>
310
                  </td>
311
                </tr>
312
        </table>
313
</form>
314
<?php include("fend.inc"); ?>
315
</body>
316
</html>
(158-158/256)