Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / services_unbound_host_edit.php @ a1b66bec

1
<?php 
2
/* $Id$ */
3
/*
4
	services_unbound_edit_host.php
5
	part of the pfSense project (https://www.pfsense.org)
6
	Copyright (C) 2014 Warren Baker (warren@decoy.co.za)
7
	All rights reserved.
8
	
9
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14
	
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
	
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21
	
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	dnsforwarder
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-services-dnsresolver-edithost
39
##|*NAME=Services: DNS Forwarder: Edit host page
40
##|*DESCR=Allow access to the 'Services: DNS Forwarder: Edit host' page.
41
##|*MATCH=services_unbound_host_edit.php*
42
##|-PRIV
43

    
44
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_unbound.php');
45

    
46
function hostcmp($a, $b) {
47
	return strcasecmp($a['host'], $b['host']);
48
}
49

    
50
function hosts_sort() {
51
	global $g, $config;
52

    
53
	if (!is_array($config['unbound']['hosts']))
54
		return;
55

    
56
	usort($config['unbound']['hosts'], "hostcmp");
57
}
58

    
59
require("guiconfig.inc");
60

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

    
64
$a_hosts = &$config['unbound']['hosts'];
65

    
66
if (is_numericint($_GET['id']))
67
	$id = $_GET['id'];
68
if (isset($_POST['id']) && is_numericint($_POST['id']))
69
	$id = $_POST['id'];
70

    
71
if (isset($id) && $a_hosts[$id]) {
72
	$pconfig['host'] = $a_hosts[$id]['host'];
73
	$pconfig['domain'] = $a_hosts[$id]['domain'];
74
	$pconfig['ip'] = $a_hosts[$id]['ip'];
75
	$pconfig['descr'] = $a_hosts[$id]['descr'];
76
	$pconfig['aliases'] = $a_hosts[$id]['aliases'];
77
}
78

    
79
if ($_POST) {
80

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

    
84
	/* input validation */
85
	$reqdfields = explode(" ", "domain ip");
86
	$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
87
	
88
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
89
	
90
	if (($_POST['host'] && !is_hostname($_POST['host']))) 
91
		$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
92

    
93
	if (($_POST['domain'] && !is_domain($_POST['domain']))) 
94
		$input_errors[] = gettext("A valid domain must be specified.");
95
		
96
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) 
97
		$input_errors[] = gettext("A valid IP address must be specified.");
98

    
99
	/* collect aliases */
100
	$aliases = array();
101
	foreach ($_POST as $key => $value) {
102
		$entry = '';
103
		if (!substr_compare('aliashost', $key, 0, 9)) {
104
			$entry = substr($key, 9);
105
			$field = 'host';
106
		}
107
		elseif (!substr_compare('aliasdomain', $key, 0, 11)) {
108
			$entry = substr($key, 11);
109
			$field = 'domain';
110
		}
111
		elseif (!substr_compare('aliasdescription', $key, 0, 16)) {
112
			$entry = substr($key, 16);
113
			$field = 'description';
114
		}
115
		if (ctype_digit($entry)) {
116
			$aliases[$entry][$field] = $value;
117
		}
118
	}
119
	$pconfig['aliases']['item'] = $aliases;
120

    
121
	/* validate aliases */
122
	foreach ($aliases as $idx => $alias) {
123
		$aliasreqdfields = array('aliasdomain' . $idx);
124
		$aliasreqdfieldsn = array(gettext("Alias Domain"));
125

    
126
		var_dump(array('fields' => $aliasreqdfields, 'names' => $aliasreqdfieldsn, 'alias' => $alias));
127
		do_input_validation($_POST, $aliasreqdfields, $aliasreqdfieldsn, $input_errors);
128
		if (($alias['host'] && !is_hostname($alias['host'])))
129
			$input_errors[] = gettext("Hostnames in alias list can only contain the characters A-Z, 0-9 and '-'.");
130
		if (($alias['domain'] && !is_domain($alias['domain'])))
131
			$input_errors[] = gettext("A valid domain must be specified in alias list.");
132
	}
133

    
134
	/* check for overlaps */
135
	foreach ($a_hosts as $hostent) {
136
		if (isset($id) && ($a_hosts[$id]) && ($a_hosts[$id] === $hostent))
137
			continue;
138

    
139
		if (($hostent['host'] == $_POST['host']) && ($hostent['domain'] == $_POST['domain'])
140
			&& ((is_ipaddrv4($hostent['ip']) && is_ipaddrv4($_POST['ip'])) || (is_ipaddrv6($hostent['ip']) && is_ipaddrv6($_POST['ip'])))) {
141
			$input_errors[] = gettext("This host/domain already exists.");
142
			break;
143
		}
144
	}
145

    
146
	if (!$input_errors) {
147
		$hostent = array();
148
		$hostent['host'] = $_POST['host'];
149
		$hostent['domain'] = $_POST['domain'];
150
		$hostent['ip'] = $_POST['ip'];
151
		$hostent['descr'] = $_POST['descr'];
152
		$hostent['aliases']['item'] = $aliases;
153

    
154
		if (isset($id) && $a_hosts[$id])
155
			$a_hosts[$id] = $hostent;
156
		else
157
			$a_hosts[] = $hostent;
158
		hosts_sort();
159
		
160
		mark_subsystem_dirty('unbound');
161
		
162
		write_config();
163
		
164
		header("Location: services_unbound.php");
165
		exit;
166
	}
167
}
168

    
169
$pgtitle = array(gettext("Services"),gettext("DNS Resolver"),gettext("Edit host"));
170
$shortcut_section = "resolver";
171
include("head.inc");
172

    
173
?>
174

    
175
<body onload="<?= $jsevents["body"]["onload"] ?>">
176
<?php include("fbegin.inc"); ?>
177

    
178
<script type="text/javascript" src="/javascript/row_helper.js">
179
</script>
180

    
181
<script type="text/javascript">
182
//<![CDATA[
183
	rowname[0] = "aliashost";
184
	rowtype[0] = "textbox";
185
	rowsize[0] = "20";
186
	rowname[1] = "aliasdomain";
187
	rowtype[1] = "textbox";
188
	rowsize[1] = "20";
189
	rowname[2] = "aliasdescription";
190
	rowtype[2] = "textbox";
191
	rowsize[2] = "20";
192
//]]>
193
</script>
194

    
195
<?php if ($input_errors) print_input_errors($input_errors); ?>
196
	<form action="services_unbound_host_edit.php" method="post" name="iform" id="iform">
197
		<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="host edit">
198
			<tr>
199
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit DNS Resolver entry");?></td>
200
			</tr>
201
			<tr>
202
				<td width="22%" valign="top" class="vncell"><?=gettext("Host");?></td>
203
				<td width="78%" class="vtable">
204
					<input name="host" type="text" class="formfld" id="host" size="40" value="<?=htmlspecialchars($pconfig['host']);?>" /><br />
205
					<span class="vexpl"><?=gettext("Name of the host, without domain part"); ?><br />
206
					<?=gettext("e.g."); ?> <em><?=gettext("myhost"); ?></em></span>
207
				</td>
208
			</tr>
209
			<tr>
210
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Domain");?></td>
211
				<td width="78%" class="vtable">
212
					<input name="domain" type="text" class="formfld" id="domain" size="40" value="<?=htmlspecialchars($pconfig['domain']);?>" /><br />
213
					<span class="vexpl"><?=gettext("Domain of the host"); ?><br />
214
						<?=gettext("e.g."); ?> <em><?=gettext("example.com"); ?></em></span>
215
				</td>
216
			</tr>
217
			<tr>
218
				<td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
219
				<td width="78%" class="vtable">
220
					<input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>" /><br />
221
					<span class="vexpl"><?=gettext("IP address of the host"); ?><br />
222
						<?=gettext("e.g."); ?> <em>192.168.100.100</em> <?=gettext("or"); ?> <em>fd00:abcd::1</em></span>
223
				</td>
224
			</tr>
225
			<tr>
226
				<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
227
				<td width="78%" class="vtable">
228
					<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" /><br />
229
					<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span>
230
				</td>
231
			</tr>
232
			<tr>
233
				<td width="22%" valign="top" class="vncell"><div id="addressnetworkport"><?=gettext("Aliases"); ?></div></td>
234
				<td width="78%" class="vtable">
235
					<table id="maintable" summary="aliases">
236
						<tbody>
237
							<tr>
238
								<td colspan="4">
239
									<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
240
										<?=gettext("Enter additional names for this host."); ?>
241
									</div>
242
								</td>
243
							</tr>
244
							<tr>
245
								<td><div id="onecolumn"><?=gettext("Host");?></div></td>
246
								<td><div id="twocolumn"><?=gettext("Domain");?></div></td>
247
								<td><div id="threecolumn"><?=gettext("Description");?></div></td>
248
							</tr>
249
							<?php
250
								$counter = 0;
251
								if ($pconfig['aliases']['item']):
252
									foreach($pconfig['aliases']['item'] as $item):
253
										$host = $item['host'];
254
										$domain = $item['domain'];
255
										$description = $item['description'];
256
							?>
257
							<tr>
258
								<td>
259
									<input autocomplete="off" name="aliashost<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliashost<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($host);?>" />
260
								</td>
261
								<td>
262
									<input autocomplete="off" name="aliasdomain<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdomain<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($domain);?>" />
263
								</td>
264
								<td>
265
									<input name="aliasdescription<?php echo $counter; ?>" type="text" class="formfld unknown" id="aliasdescription<?php echo $counter; ?>" size="20" value="<?=htmlspecialchars($description);?>" />
266
								</td>
267
								<td>
268
									<a onclick="removeRow(this); return false;" href="#">
269
										<img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="" title="<?=gettext("remove this entry"); ?>" />
270
									</a>
271
								</td>
272
							</tr>
273
							<?php
274
										$counter++;
275
									endforeach;
276
								endif;
277
							?>
278
						</tbody>
279
					</table>
280
					<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
281
						<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
282
					</a>
283
					<script type="text/javascript">
284
					//<![CDATA[
285
						field_counter_js = 3;
286
						rows = 1;
287
						totalrows = <?php echo $counter; ?>;
288
						loaded = <?php echo $counter; ?>;
289
					//]]>
290
					</script>
291
				</td>
292
			</tr>
293
			<tr>
294
				<td width="22%" valign="top">&nbsp;</td>
295
				<td width="78%">
296
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
297
					<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
298
					<?php if (isset($id) && $a_hosts[$id]): ?>
299
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
300
					<?php endif; ?>
301
				</td>
302
			</tr>
303
		</table>
304
	</form>
305
<?php include("fend.inc"); ?>
306
</body>
307
</html>
(174-174/256)