Project

General

Profile

Download (7.39 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_rfc2136_edit.php
5

    
6
	Copyright (C) 2008 Ermal Luçi
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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
	pfSense_MODULE: dnsupdate
33
*/
34

    
35
require("guiconfig.inc");
36

    
37
if (!is_array($config['dnsupdates']['dnsupdate'])) {
38
	$config['dnsupdates']['dnsupdate'] = array();
39
}
40

    
41
$a_rfc2136 = &$config['dnsupdates']['dnsupdate'];
42

    
43
if (is_numericint($_GET['id'])) {
44
	$id = $_GET['id'];
45
}
46
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
47
	$id = $_POST['id'];
48
}
49

    
50
if (isset($id) && isset($a_rfc2136[$id])) {
51
	$pconfig['enable'] = isset($a_rfc2136[$id]['enable']);
52
	$pconfig['host'] = $a_rfc2136[$id]['host'];
53
	$pconfig['ttl'] = $a_rfc2136[$id]['ttl'];
54
	if (!$pconfig['ttl']) {
55
		$pconfig['ttl'] = 60;
56
	}
57
	$pconfig['keydata'] = $a_rfc2136[$id]['keydata'];
58
	$pconfig['keyname'] = $a_rfc2136[$id]['keyname'];
59
	$pconfig['keytype'] = $a_rfc2136[$id]['keytype'];
60
	if (!$pconfig['keytype']) {
61
		$pconfig['keytype'] = "zone";
62
	}
63
	$pconfig['server'] = $a_rfc2136[$id]['server'];
64
	$pconfig['interface'] = $a_rfc2136[$id]['interface'];
65
	$pconfig['usetcp'] = isset($a_rfc2136[$id]['usetcp']);
66
	$pconfig['usepublicip'] = isset($a_rfc2136[$id]['usepublicip']);
67
	$pconfig['recordtype'] = $a_rfc2136[$id]['recordtype'];
68
	if (!$pconfig['recordtype']) {
69
		$pconfig['recordtype'] = "both";
70
	}
71
	$pconfig['descr'] = $a_rfc2136[$id]['descr'];
72

    
73
}
74

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	/* input validation */
81
	$reqdfields = array();
82
	$reqdfieldsn = array();
83
	$reqdfields = array_merge($reqdfields, explode(" ", "host ttl keyname keydata"));
84
	$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Hostname"), gettext("TTL"), gettext("Key name"), gettext("Key")));
85

    
86
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
87

    
88
	if (($_POST['host'] && !is_domain($_POST['host']))) {
89
		$input_errors[] = gettext("The DNS update host name contains invalid characters.");
90
	}
91
	if (($_POST['ttl'] && !is_numericint($_POST['ttl']))) {
92
		$input_errors[] = gettext("The DNS update TTL must be an integer.");
93
	}
94
	if (($_POST['keyname'] && !is_domain($_POST['keyname']))) {
95
		$input_errors[] = gettext("The DNS update key name contains invalid characters.");
96
	}
97

    
98
	if (!$input_errors) {
99
		$rfc2136 = array();
100
		$rfc2136['enable'] = $_POST['enable'] ? true : false;
101
		$rfc2136['host'] = $_POST['host'];
102
		$rfc2136['ttl'] = $_POST['ttl'];
103
		$rfc2136['keyname'] = $_POST['keyname'];
104
		$rfc2136['keytype'] = $_POST['keytype'];
105
		$rfc2136['keydata'] = $_POST['keydata'];
106
		$rfc2136['server'] = $_POST['server'];
107
		$rfc2136['usetcp'] = $_POST['usetcp'] ? true : false;
108
		$rfc2136['usepublicip'] = $_POST['usepublicip'] ? true : false;
109
		$rfc2136['recordtype'] = $_POST['recordtype'];
110
		$rfc2136['interface'] = $_POST['interface'];
111
		$rfc2136['descr'] = $_POST['descr'];
112

    
113
		if (isset($id) && $a_rfc2136[$id]) {
114
			$a_rfc2136[$id] = $rfc2136;
115
		} else {
116
			$a_rfc2136[] = $rfc2136;
117
		}
118

    
119
		write_config(gettext("New/Edited RFC2136 dnsupdate entry was posted."));
120

    
121
		if ($_POST['Submit'] == gettext("Save & Force Update")) {
122
			$retval = services_dnsupdate_process("", $rfc2136['host'], true);
123
		} else {
124
			$retval = services_dnsupdate_process();
125
		}
126

    
127
		header("Location: services_rfc2136.php");
128
		exit;
129
	}
130
}
131

    
132
$pgtitle = array(gettext("Services"), gettext("RFC 2136 client"), gettext("Edit"));
133
include("head.inc");
134

    
135
require('classes/Form.class.php');
136

    
137
if ($input_errors)
138
	print_input_errors($input_errors);
139

    
140
if ($savemsg)
141
	print_info_box($savemsg);
142

    
143
$form = new Form;
144

    
145
$section = new Form_Section('RFC 2136 client');
146

    
147
$section->addInput(new Form_Checkbox(
148
	'enable',
149
	'Enable',
150
	null,
151
	$pconfig['enable']
152
));
153

    
154
$optionlist = array();
155
$iflist = get_configured_interface_with_descr();
156

    
157
foreach ($iflist as $ifnam => $ifdescr)
158
	$optionlist[$ifnam] = $ifdescr;
159

    
160
$section->addInput(new Form_Select(
161
	'ifname',
162
	'Interface',
163
	$pconfig['ifname'],
164
	$optionlist
165
));
166

    
167
$section->addInput(new Form_Input(
168
	'host',
169
	'Hostname',
170
	'text',
171
	$pconfig['host']
172
))->setHelp('Fully qualified hostname of the host to be updated');
173

    
174
$section->addInput(new Form_Input(
175
	'ttl',
176
	'TTL (seconds)',
177
	'number',
178
	$pconfig['ttl']
179
));
180

    
181
$section->addInput(new Form_Input(
182
	'keyname',
183
	'Key name',
184
	'text',
185
	$pconfig['keyname']
186
))->setHelp('This must match the setting on the DNS server.');
187

    
188
$group = new Form_Group('Key Type');
189

    
190
$group->add(new Form_Checkbox(
191
	'keytype',
192
	'Key Type',
193
	'Zone',
194
	($pconfig['keytype']=='zone'),
195
	'zone'
196
))->displayAsRadio();
197

    
198
$group->add($input = new Form_Checkbox(
199
	'keytype',
200
	'Key Type',
201
	'Host',
202
	($pconfig['keytype']=='host'),
203
	'host'
204
))->displayAsRadio();
205

    
206
$group->add($input = new Form_Checkbox(
207
	'keytype',
208
	'Key Type',
209
	'User',
210
	($pconfig['keytype']=='user'),
211
	'user'
212
))->displayAsRadio();
213

    
214
$section->add($group);
215

    
216
$section->addInput(new Form_Input(
217
	'keydata',
218
	'Key',
219
	'text',
220
	$pconfig['keydata']
221
))->setHelp('Paste an HMAC-MD5 key here.');
222

    
223
$section->addInput(new Form_Input(
224
	'server',
225
	'Server',
226
	'text',
227
	$pconfig['server']
228
));
229

    
230
$section->addInput(new Form_Checkbox(
231
	'usetcp',
232
	'Protocol',
233
	'Use TCP instead of UDP',
234
	$pconfig['usetcp']
235
));
236

    
237
$section->addInput(new Form_Checkbox(
238
	'usepublicip',
239
	'Use public IP',
240
	'If the interface IP is private, attempt to fetch and use the public IP instead.',
241
	$pconfig['usepublicip']
242
));
243

    
244
$group = new Form_Group('Record Type');
245

    
246
$group->add(new Form_Checkbox(
247
	'recordtype',
248
	'Record Type',
249
	'A (IPv4)',
250
	($pconfig['keytype']=='A'),
251
	'A'
252
))->displayAsRadio();
253

    
254
$group->add($input = new Form_Checkbox(
255
	'recordtype',
256
	'Record Type',
257
	'AAAA (IPv6)',
258
	($pconfig['keytype']=='AAAA'),
259
	'AAAA'
260
))->displayAsRadio();
261

    
262
$group->add($input = new Form_Checkbox(
263
	'recordtype',
264
	'Record Type',
265
	'Both',
266
	($pconfig['keytype']=='both'),
267
	'both'
268
))->displayAsRadio();
269

    
270
$section->add($group);
271

    
272
$section->addInput(new Form_Input(
273
	'descr',
274
	'Description',
275
	'text',
276
	$pconfig['descr']
277
))->setHelp('You may enter a description here for your reference (not parsed).');
278

    
279
if (isset($id) && $a_rfc2136[$id]){
280
    	$section->addInput(new Form_Input(
281
    	'id',
282
    	null,
283
    	'hidden',
284
    	$id
285
	));
286
}
287

    
288
$form->add($section);
289
print($form);
290

    
291
print_info_box(sprintf('You must configure a DNS server in %sSystem: ' .
292
					'General setup %sor allow the DNS server list to be overridden ' .
293
					'by DHCP/PPP on WAN for dynamic DNS updates to work.','<a href="system.php">', '</a>'));
294

    
295
include("foot.inc");
(150-150/238)