Project

General

Profile

Download (7.41 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
if (isset($id) && isset($a_rfc2136[$id])) {
50
	$pconfig['enable'] = isset($a_rfc2136[$id]['enable']);
51
	$pconfig['host'] = $a_rfc2136[$id]['host'];
52
	$pconfig['ttl'] = $a_rfc2136[$id]['ttl'];
53
	if (!$pconfig['ttl'])
54
		$pconfig['ttl'] = 60;
55
	$pconfig['keydata'] = $a_rfc2136[$id]['keydata'];
56
	$pconfig['keyname'] = $a_rfc2136[$id]['keyname'];
57
	$pconfig['keytype'] = $a_rfc2136[$id]['keytype'];
58
	if (!$pconfig['keytype'])
59
		$pconfig['keytype'] = "zone";
60
	$pconfig['server'] = $a_rfc2136[$id]['server'];
61
	$pconfig['interface'] = $a_rfc2136[$id]['interface'];
62
	$pconfig['usetcp'] = isset($a_rfc2136[$id]['usetcp']);
63
	$pconfig['usepublicip'] = isset($a_rfc2136[$id]['usepublicip']);
64
	$pconfig['recordtype'] = $a_rfc2136[$id]['recordtype'];
65
	if (!$pconfig['recordtype'])
66
		$pconfig['recordtype'] = "both";
67
	$pconfig['descr'] = $a_rfc2136[$id]['descr'];
68

    
69
}
70

    
71
if ($_POST) {
72

    
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

    
76
	/* input validation */
77
	$reqdfields = array();
78
	$reqdfieldsn = array();
79
	$reqdfields = array_merge($reqdfields, explode(" ", "host ttl keyname keydata"));
80
	$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Hostname"), gettext("TTL"), gettext("Key name"), gettext("Key")));
81

    
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
83

    
84
	if (($_POST['host'] && !is_domain($_POST['host'])))
85
		$input_errors[] = gettext("The DNS update host name contains invalid characters.");
86
	if (($_POST['ttl'] && !is_numericint($_POST['ttl'])))
87
		$input_errors[] = gettext("The DNS update TTL must be an integer.");
88
	if (($_POST['keyname'] && !is_domain($_POST['keyname'])))
89
		$input_errors[] = gettext("The DNS update key name contains invalid characters.");
90

    
91
	if (!$input_errors) {
92
		$rfc2136 = array();
93
		$rfc2136['enable'] = $_POST['enable'] ? true : false;
94
		$rfc2136['host'] = $_POST['host'];
95
		$rfc2136['ttl'] = $_POST['ttl'];
96
		$rfc2136['keyname'] = $_POST['keyname'];
97
		$rfc2136['keytype'] = $_POST['keytype'];
98
		$rfc2136['keydata'] = $_POST['keydata'];
99
		$rfc2136['server'] = $_POST['server'];
100
		$rfc2136['usetcp'] = $_POST['usetcp'] ? true : false;
101
		$rfc2136['usepublicip'] = $_POST['usepublicip'] ? true : false;
102
		$rfc2136['recordtype'] = $_POST['recordtype'];
103
		$rfc2136['interface'] = $_POST['interface'];
104
		$rfc2136['descr'] = $_POST['descr'];
105

    
106
		if (isset($id) && $a_rfc2136[$id])
107
			$a_rfc2136[$id] = $rfc2136;
108
		else
109
			$a_rfc2136[] = $rfc2136;
110

    
111
		write_config(gettext("New/Edited RFC2136 dnsupdate entry was posted."));
112

    
113
		if ($_POST['Submit'] == gettext("Save & Force Update"))
114
			$retval = services_dnsupdate_process("", $rfc2136['host'], true);
115
		else
116
			$retval = services_dnsupdate_process();
117

    
118
		header("Location: services_rfc2136.php");
119
		exit;
120
	}
121
}
122

    
123
$pgtitle = array(gettext("Services"),gettext("RFC 2136 client"), gettext("Edit"));
124
include("head.inc");
125

    
126
require('classes/Form.class.php');
127

    
128
if ($input_errors)
129
	print_input_errors($input_errors);
130

    
131
if ($savemsg)
132
	print_info_box($savemsg);
133

    
134
$form = new Form;
135

    
136
$section = new Form_Section('RFC 2136 client');
137

    
138
$section->addInput(new Form_Checkbox(
139
	'enable',
140
	'Enable',
141
	null,
142
	$pconfig['enable']
143
));
144

    
145
$optionlist = array();
146
$iflist = get_configured_interface_with_descr();
147

    
148
foreach ($iflist as $ifnam => $ifdescr)
149
	$optionlist[$ifnam] = $ifdescr;
150

    
151
$section->addInput(new Form_Select(
152
	'ifname',
153
	'Interface',
154
	$pconfig['ifname'],
155
	$optionlist
156
));
157

    
158
$section->addInput(new Form_Input(
159
	'host',
160
	'Hostname',
161
	'text',
162
	$pconfig['host']
163
))->setHelp('Fully qualified hostname of the host to be updated');
164

    
165
$section->addInput(new Form_Input(
166
	'ttl',
167
	'TTL (seconds)',
168
	'number',
169
	$pconfig['ttl']
170
));
171

    
172
$section->addInput(new Form_Input(
173
	'keyname',
174
	'Key name',
175
	'text',
176
	$pconfig['keyname']
177
))->setHelp('This must match the setting on the DNS server.');
178

    
179
$group = new Form_Group('Key Type');
180

    
181
$group->add(new Form_Checkbox(
182
	'keytype',
183
	'Key Type',
184
	'Zone',
185
	($pconfig['keytype']=='zone'),
186
	'zone'
187
))->displayAsRadio();
188

    
189
$group->add($input = new Form_Checkbox(
190
	'keytype',
191
	'Key Type',
192
	'Host',
193
	($pconfig['keytype']=='host'),
194
	'host'
195
))->displayAsRadio();
196

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

    
205
$section->add($group);
206

    
207
$section->addInput(new Form_Input(
208
	'keydata',
209
	'Key',
210
	'text',
211
	$pconfig['keydata']
212
))->setHelp('Paste an HMAC-MD5 key here.');
213

    
214
$section->addInput(new Form_Input(
215
	'server',
216
	'Server',
217
	'text',
218
	$pconfig['server']
219
));
220

    
221
$section->addInput(new Form_Checkbox(
222
	'usetcp',
223
	'Protocol',
224
	'Use TCP instead of UDP',
225
	$pconfig['usetcp']
226
));
227

    
228
$section->addInput(new Form_Checkbox(
229
	'usepublicip',
230
	'Use public IP',
231
	'If the interface IP is private, attempt to fetch and use the public IP instead.',
232
	$pconfig['usepublicip']
233
));
234

    
235
$group = new Form_Group('Record Type');
236

    
237
$group->add(new Form_Checkbox(
238
	'recordtype',
239
	'Record Type',
240
	'A (IPv4)',
241
	($pconfig['keytype']=='A'),
242
	'A'
243
))->displayAsRadio();
244

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

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

    
261
$section->add($group);
262

    
263
$section->addInput(new Form_Input(
264
	'descr',
265
	'Description',
266
	'text',
267
	$pconfig['descr']
268
))->setHelp('You may enter a description here for your reference (not parsed).');
269

    
270
$form->addGlobal(new Form_Button(
271
	'cancel',
272
	'Cancel',
273
	'services_rfc2136.php'
274
));
275

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

    
285
$form->add($section);
286
print($form);
287

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

    
292
include("foot.inc");
(153-153/241)