summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/services_checkip_edit.php
blob: 932366eb077a367da892ee3681c708cd59e31d8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/*
 * services_checkip_edit.php
 *
 * part of pfSense (https://www.pfsense.org)
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

##|+PRIV
##|*IDENT=page-services-checkipedit
##|*NAME=Services: Check IP Service: Edit
##|*DESCR=Allow access to the 'Services: Check IP Service: Edit' page.
##|*MATCH=services_checkip_edit.php*
##|-PRIV

require_once("guiconfig.inc");

if (!is_array($config['checkipservices']['checkipservice'])) {
	$config['checkipservices']['checkipservice'] = array();
}

$a_checkip = &$config['checkipservices']['checkipservice'];

if (is_numericint($_GET['id'])) {
	$id = $_GET['id'];
}

if (isset($_POST['id']) && is_numericint($_POST['id'])) {
	$id = $_POST['id'];
}

if (isset($id) && isset($a_checkip[$id])) {
	$pconfig['enable'] = isset($a_checkip[$id]['enable']);
	$pconfig['name'] = $a_checkip[$id]['name'];
	$pconfig['url'] = $a_checkip[$id]['url'];
	$pconfig['username'] = $a_checkip[$id]['username'];
	$pconfig['password'] = $a_checkip[$id]['password'];
	$pconfig['verifysslpeer'] = isset($a_checkip[$id]['verifysslpeer']);
	$pconfig['descr'] = $a_checkip[$id]['descr'];
}

if ($_POST) {
	unset($input_errors);
	$pconfig = $_POST;

	/* input validation */
	$reqdfields = array();
	$reqdfieldsn = array();
	$reqdfields = array_merge($reqdfields, explode(" ", "name url"));
	$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Name"), gettext("URL")));

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

	if (($_POST['name'] && !is_validaliasname($_POST['name']))) {
		$input_errors[] = gettext("The Check IP Service name contains invalid characters.");
	}
	if (($_POST['url'] && !is_URL($_POST['url']))) {
		$input_errors[] = gettext("The Check IP Service URL is not valid.");
	}
	if ($_POST['passwordfld'] != $_POST['passwordfld_confirm']) {
		$input_errors[] = gettext("Password and confirmed password must match.");
	}

	if (!$input_errors) {
		$checkip = array();
		$checkip['enable'] = $_POST['enable'] ? true : false;
		$checkip['name'] = $_POST['name'];
		$checkip['url'] = $_POST['url'];
		$checkip['username'] = $_POST['username'];

		if ($_POST['passwordfld'] != DMYPWD) {
			$checkip['password'] = $_POST['passwordfld'];
		} else {
			$checkip['password'] = $a_checkip[$id]['password'];;
		}

		$checkip['verifysslpeer'] = $_POST['verifysslpeer'] ? true : false;
		$checkip['descr'] = $_POST['descr'];

		if (isset($id) && $a_checkip[$id]) {
			$a_checkip[$id] = $checkip;
		} else {
			$a_checkip[] = $checkip;
		}

		write_config(gettext("New/Edited Check IP Services entry was posted."));

		header("Location: services_checkip.php");
		exit;
	}
}

$pgtitle = array(gettext("Services"), gettext("Dynamic DNS"), gettext("Check IP Services"), gettext("Edit"));
include("head.inc");

if ($input_errors) {
	print_input_errors($input_errors);
}

if ($savemsg) {
	print_info_box($savemsg, 'success');
}

$form = new Form;

$section = new Form_Section('Check IP Service');

$section->addInput(new Form_Checkbox(
	'enable',
	'Enable',
	null,
	$pconfig['enable']
));

$section->addInput(new Form_Input(
	'name',
	'Name',
	'text',
	$pconfig['name']
))->setHelp('The name of the service may only consist of the characters "a-z, A-Z, 0-9 and _".');

$section->addInput(new Form_Input(
	'url',
	'URL',
	'text',
	$pconfig['url']
));

$section->addInput(new Form_Input(
	'username',
	'User name',
	'text',
	$pconfig['username']
));

$section->addPassword(new Form_Input(
	'passwordfld',
	'Password',
	'password',
	$pconfig['password']
));

$section->addInput(new Form_Checkbox(
	'verifysslpeer',
	'Verify SSL Peer',
	'Verify SSL Peer',
	$pconfig['verifysslpeer']
));

$section->addInput(new Form_Input(
	'descr',
	'Description',
	'text',
	$pconfig['descr']
))->setHelp('A description may be entered here for administrative reference (not parsed).');

if (isset($id) && $a_checkip[$id]) {
	$section->addInput(new Form_Input(
		'id',
		null,
		'hidden',
		$id
	));
}

$form->add($section);
print($form);

include("foot.inc");
OpenPOWER on IntegriCloud