1
|
<?php
|
2
|
/*
|
3
|
* wizard.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
* you may not use this file except in compliance with the License.
|
11
|
* You may obtain a copy of the License at
|
12
|
*
|
13
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14
|
*
|
15
|
* Unless required by applicable law or agreed to in writing, software
|
16
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
* See the License for the specific language governing permissions and
|
19
|
* limitations under the License.
|
20
|
*/
|
21
|
|
22
|
##|+PRIV
|
23
|
##|*IDENT=page-pfsensewizardsubsystem
|
24
|
##|*NAME=pfSense wizard subsystem
|
25
|
##|*DESCR=Allow access to the 'pfSense wizard subsystem' page.
|
26
|
##|*MATCH=wizard.php*
|
27
|
##|-PRIV
|
28
|
|
29
|
require_once("globals.inc");
|
30
|
require_once("guiconfig.inc");
|
31
|
require_once("functions.inc");
|
32
|
require_once("filter.inc");
|
33
|
require_once("shaper.inc");
|
34
|
require_once("rrd.inc");
|
35
|
require_once("system.inc");
|
36
|
|
37
|
// This causes the step #, field type and field name to be printed at the top of the page
|
38
|
define('DEBUG', false);
|
39
|
|
40
|
global $g;
|
41
|
|
42
|
$stepid = htmlspecialchars($_REQUEST['stepid']);
|
43
|
|
44
|
|
45
|
if (!$stepid) {
|
46
|
$stepid = "0";
|
47
|
}
|
48
|
|
49
|
$xml = htmlspecialchars($_REQUEST['xml']);
|
50
|
|
51
|
if (empty($xml)) {
|
52
|
$xml = "not_defined";
|
53
|
print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
|
54
|
die;
|
55
|
} else {
|
56
|
$wizard_xml_prefix = "{$g['www_path']}/wizards";
|
57
|
$wizard_full_path = "{$wizard_xml_prefix}/{$xml}";
|
58
|
if (substr_compare(realpath($wizard_full_path), $wizard_xml_prefix, 0, strlen($wizard_xml_prefix))) {
|
59
|
print_info_box(gettext("Invalid path specified."), 'danger');
|
60
|
die;
|
61
|
}
|
62
|
if (file_exists($wizard_full_path)) {
|
63
|
$pkg = parse_xml_config_pkg($wizard_full_path, "pfsensewizard");
|
64
|
} else {
|
65
|
print_info_box(sprintf(gettext("Could not open %s."), $xml), 'danger');
|
66
|
die;
|
67
|
}
|
68
|
}
|
69
|
|
70
|
if (!is_array($pkg)) {
|
71
|
print_info_box(sprintf(gettext('Could not parse %1$s/wizards/%2$s file.'), $g['www_path'], $xml), 'danger');
|
72
|
die;
|
73
|
}
|
74
|
|
75
|
$totalsteps = $pkg['totalsteps'];
|
76
|
|
77
|
if ($pkg['includefile']) {
|
78
|
require_once($pkg['includefile']);
|
79
|
}
|
80
|
|
81
|
if ($pkg['step'][$stepid]['includefile']) {
|
82
|
require_once($pkg['step'][$stepid]['includefile']);
|
83
|
}
|
84
|
|
85
|
if ($pkg['step'][$stepid]['stepsubmitbeforesave']) {
|
86
|
eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
|
87
|
}
|
88
|
|
89
|
if ($_POST && !$input_errors) {
|
90
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
91
|
if (!empty($field['bindstofield']) and $field['type'] != "submit") {
|
92
|
$fieldname = $field['name'];
|
93
|
$fieldname = str_replace(" ", "", $fieldname);
|
94
|
$fieldname = strtolower($fieldname);
|
95
|
// update field with posted values.
|
96
|
if ($field['unsetfield'] != "") {
|
97
|
$unset_fields = "yes";
|
98
|
} else {
|
99
|
$unset_fields = "";
|
100
|
}
|
101
|
|
102
|
if ($field['arraynum'] != "") {
|
103
|
$arraynum = $field['arraynum'];
|
104
|
} else {
|
105
|
$arraynum = "";
|
106
|
}
|
107
|
|
108
|
update_config_field($field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
|
109
|
}
|
110
|
|
111
|
}
|
112
|
// run custom php code embedded in xml config.
|
113
|
if ($pkg['step'][$stepid]['stepsubmitphpaction'] != "") {
|
114
|
eval($pkg['step'][$stepid]['stepsubmitphpaction']);
|
115
|
}
|
116
|
if (!$input_errors) {
|
117
|
write_config(gettext("Configuration changed via the pfSense wizard subsystem."));
|
118
|
}
|
119
|
|
120
|
$stepid++;
|
121
|
}
|
122
|
|
123
|
while (!empty($pkg['step'][$stepid]['skip_flavors'])) {
|
124
|
$skip = false;
|
125
|
foreach (explode(',', $pkg['step'][$stepid]['skip_flavors']) as $flavor) {
|
126
|
if ($flavor == $g['default-config-flavor']) {
|
127
|
$skip = true;
|
128
|
break;
|
129
|
}
|
130
|
}
|
131
|
if ($skip) {
|
132
|
$stepid++;
|
133
|
} else {
|
134
|
break;
|
135
|
}
|
136
|
}
|
137
|
|
138
|
if ($stepid > $totalsteps) {
|
139
|
$stepid = $totalsteps;
|
140
|
}
|
141
|
|
142
|
function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
|
143
|
global $config;
|
144
|
$field_split = explode("->", $field);
|
145
|
$thisvar = null;
|
146
|
foreach ($field_split as $f) {
|
147
|
$field_conv .= "['" . $f . "']";
|
148
|
}
|
149
|
if ($field_conv == "") {
|
150
|
return;
|
151
|
}
|
152
|
if ($arraynum != "") {
|
153
|
$field_conv .= "[" . $arraynum . "]";
|
154
|
}
|
155
|
if (($field_type == "checkbox" and $updatetext != "on") || $updatetext == "") {
|
156
|
/*
|
157
|
* item is a checkbox, it should have the value "on"
|
158
|
* if it was checked
|
159
|
*/
|
160
|
$var = "\$config{$field_conv}";
|
161
|
$text = "if (isset({$var})) unset({$var});";
|
162
|
eval($text);
|
163
|
return;
|
164
|
}
|
165
|
|
166
|
if ($field_type == "interfaces_selection") {
|
167
|
$var = "\$config{$field_conv}";
|
168
|
$text = "if (isset({$var})) unset({$var});";
|
169
|
$text .= "\$thisvar = &\$config" . $field_conv . ";";
|
170
|
eval($text);
|
171
|
$thisvar = $updatetext;
|
172
|
return;
|
173
|
}
|
174
|
|
175
|
if ($unset == "yes") {
|
176
|
$text = "unset(\$config" . $field_conv . ");";
|
177
|
eval($text);
|
178
|
}
|
179
|
$text .= "\$thisvar = &\$config" . $field_conv . ";";
|
180
|
eval($text);
|
181
|
$thisvar = $updatetext;
|
182
|
}
|
183
|
|
184
|
$title = $pkg['step'][$stepid]['title'];
|
185
|
$description = $pkg['step'][$stepid]['description'];
|
186
|
|
187
|
// handle before form display event.
|
188
|
do {
|
189
|
$oldstepid = $stepid;
|
190
|
if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != "") {
|
191
|
eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
|
192
|
}
|
193
|
} while ($oldstepid != $stepid);
|
194
|
|
195
|
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title'])); //First step is main title of the wizard in the breadcrumb
|
196
|
$pglinks = array("", "wizard.php?xml=" . $xml);
|
197
|
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):' '); //Following steps are sub-level breadcrumbs.
|
198
|
$pglinks[] = ($stepid > 0 ? "wizard.php?xml=" . $xml . "&stepid=" . $stepid:' ');
|
199
|
$shortcut_section = "Wizard";
|
200
|
include("head.inc");
|
201
|
|
202
|
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
|
203
|
<script type="text/javascript">
|
204
|
//<![CDATA[
|
205
|
|
206
|
|
207
|
function FieldValidate(userinput, regexp, message) {
|
208
|
if (!userinput.match(regexp)) {
|
209
|
alert(message);
|
210
|
}
|
211
|
}
|
212
|
|
213
|
function enablechange() {
|
214
|
|
215
|
<?php
|
216
|
|
217
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
218
|
if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
|
219
|
print "\t" . 'if ( $("#" + "' . strtolower($field['name']) . '").prop("checked") ) {' . "\n";
|
220
|
|
221
|
if (isset($field['enablefields'])) {
|
222
|
$enablefields = explode(',', $field['enablefields']);
|
223
|
foreach ($enablefields as $enablefield) {
|
224
|
$enablefield = strtolower($enablefield);
|
225
|
print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
|
226
|
}
|
227
|
}
|
228
|
|
229
|
if (isset($field['checkenablefields'])) {
|
230
|
$checkenablefields = explode(',', $field['checkenablefields']);
|
231
|
foreach ($checkenablefields as $checkenablefield) {
|
232
|
$checkenablefield = strtolower($checkenablefield);
|
233
|
print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
|
234
|
}
|
235
|
}
|
236
|
|
237
|
print "\t" . '} else {' . "\n";
|
238
|
if (isset($field['enablefields'])) {
|
239
|
$enablefields = explode(',', $field['enablefields']);
|
240
|
foreach ($enablefields as $enablefield) {
|
241
|
$enablefield = strtolower($enablefield);
|
242
|
print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
|
243
|
|
244
|
}
|
245
|
}
|
246
|
|
247
|
if (isset($field['checkdisablefields'])) {
|
248
|
$checkenablefields = explode(',', $field['checkdisablefields']);
|
249
|
foreach ($checkenablefields as $checkenablefield) {
|
250
|
$checkenablefield = strtolower($checkenablefield);
|
251
|
print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
|
252
|
}
|
253
|
}
|
254
|
|
255
|
print "\t" . '}' . "\n";
|
256
|
}
|
257
|
}
|
258
|
?>
|
259
|
|
260
|
}
|
261
|
|
262
|
function disablechange() {
|
263
|
<?php
|
264
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
265
|
if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
|
266
|
|
267
|
print "\t" . 'if ( $("#" + "' . strtolower($field['name']) . '").prop("checked") ) {' . "\n";
|
268
|
|
269
|
if (isset($field['disablefields'])) {
|
270
|
$enablefields = explode(',', $field['disablefields']);
|
271
|
foreach ($enablefields as $enablefield) {
|
272
|
$enablefield = strtolower($enablefield);
|
273
|
|
274
|
print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", true);' . "\n";
|
275
|
}
|
276
|
}
|
277
|
if (isset($field['checkdisablefields'])) {
|
278
|
$checkenablefields = explode(',', $field['checkdisablefields']);
|
279
|
foreach ($checkenablefields as $checkenablefield) {
|
280
|
$checkenablefield = strtolower($checkenablefield);
|
281
|
print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", true);' . "\n";
|
282
|
}
|
283
|
}
|
284
|
print "\t" . '} else {' . "\n";
|
285
|
if (isset($field['disablefields'])) {
|
286
|
$enablefields = explode(',', $field['disablefields']);
|
287
|
foreach ($enablefields as $enablefield) {
|
288
|
$enablefield = strtolower($enablefield);
|
289
|
print "\t\t" . '$("#" + "' . $enablefield . '").prop("disabled", false);' . "\n";
|
290
|
}
|
291
|
}
|
292
|
if (isset($field['checkdisablefields'])) {
|
293
|
$checkenablefields = explode(',', $field['checkdisablefields']);
|
294
|
foreach ($checkenablefields as $checkenablefield) {
|
295
|
$checkenablefield = strtolower($checkenablefield);
|
296
|
print "\t\t" . '$("#" + "' . $checkenablefield . '").prop("checked", false);' . "\n";
|
297
|
}
|
298
|
}
|
299
|
print "\t" . '}' . "\n";
|
300
|
}
|
301
|
}
|
302
|
?>
|
303
|
}
|
304
|
|
305
|
function showchange() {
|
306
|
<?php
|
307
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
308
|
if (isset($field['showfields'])) {
|
309
|
print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
|
310
|
if (isset($field['showfields'])) {
|
311
|
$showfields = explode(',', $field['showfields']);
|
312
|
foreach ($showfields as $showfield) {
|
313
|
$showfield = strtolower($showfield);
|
314
|
//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
|
315
|
print "\t\t $('#". $showfield . "').hide();";
|
316
|
}
|
317
|
}
|
318
|
print "\t" . '} else {' . "\n";
|
319
|
if (isset($field['showfields'])) {
|
320
|
$showfields = explode(',', $field['showfields']);
|
321
|
foreach ($showfields as $showfield) {
|
322
|
$showfield = strtolower($showfield);
|
323
|
#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
|
324
|
print "\t\t $('#". $showfield . "').show();";
|
325
|
}
|
326
|
}
|
327
|
print "\t" . '}' . "\n";
|
328
|
}
|
329
|
}
|
330
|
?>
|
331
|
}
|
332
|
|
333
|
//]]>
|
334
|
</script>
|
335
|
<?php }
|
336
|
|
337
|
function fixup_string($string) {
|
338
|
global $config, $g, $myurl, $title;
|
339
|
$newstring = $string;
|
340
|
// fixup #1: $myurl -> http[s]://ip_address:port/
|
341
|
switch ($config['system']['webgui']['protocol']) {
|
342
|
case "http":
|
343
|
$proto = "http";
|
344
|
break;
|
345
|
case "https":
|
346
|
$proto = "https";
|
347
|
break;
|
348
|
default:
|
349
|
$proto = "http";
|
350
|
break;
|
351
|
}
|
352
|
$port = $config['system']['webgui']['port'];
|
353
|
if ($port != "") {
|
354
|
if (($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
|
355
|
$urlport = ":" . $port;
|
356
|
} elseif ($port != "80" and $port != "443") {
|
357
|
$urlport = ":" . $port;
|
358
|
} else {
|
359
|
$urlport = "";
|
360
|
}
|
361
|
}
|
362
|
|
363
|
$http_host = $_SERVER['HTTP_HOST'];
|
364
|
$urlhost = $http_host;
|
365
|
// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
|
366
|
if ($title == "Reload in progress") {
|
367
|
if (is_ipaddr($urlhost)) {
|
368
|
$host_if = find_ip_interface($urlhost);
|
369
|
if ($host_if) {
|
370
|
$host_if = convert_real_interface_to_friendly_interface_name($host_if);
|
371
|
if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr'])) {
|
372
|
$urlhost = $config['interfaces'][$host_if]['ipaddr'];
|
373
|
}
|
374
|
}
|
375
|
} else if ($urlhost == $config['system']['hostname']) {
|
376
|
$urlhost = $config['wizardtemp']['system']['hostname'];
|
377
|
} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
|
378
|
$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
|
379
|
}
|
380
|
}
|
381
|
|
382
|
if ($urlhost != $http_host) {
|
383
|
file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
|
384
|
}
|
385
|
|
386
|
$myurl = $proto . "://" . $urlhost . $urlport . "/";
|
387
|
|
388
|
if (strstr($newstring, "\$myurl")) {
|
389
|
$newstring = str_replace("\$myurl", $myurl, $newstring);
|
390
|
}
|
391
|
// fixup #2: $wanip
|
392
|
if (strstr($newstring, "\$wanip")) {
|
393
|
$curwanip = get_interface_ip();
|
394
|
$newstring = str_replace("\$wanip", $curwanip, $newstring);
|
395
|
}
|
396
|
// fixup #3: $lanip
|
397
|
if (strstr($newstring, "\$lanip")) {
|
398
|
$lanip = get_interface_ip("lan");
|
399
|
$newstring = str_replace("\$lanip", $lanip, $newstring);
|
400
|
}
|
401
|
// fixup #4: fix'r'up here.
|
402
|
return $newstring;
|
403
|
}
|
404
|
|
405
|
function is_timezone($elt) {
|
406
|
return !preg_match("/\/$/", $elt);
|
407
|
}
|
408
|
|
409
|
if ($title == "Reload in progress") {
|
410
|
$ip = fixup_string("\$myurl");
|
411
|
} else {
|
412
|
$ip = "/";
|
413
|
}
|
414
|
|
415
|
if ($input_errors) {
|
416
|
print_input_errors($input_errors);
|
417
|
}
|
418
|
if ($savemsg) {
|
419
|
print_info_box($savemsg, 'success');
|
420
|
}
|
421
|
if ($_REQUEST['message'] != "") {
|
422
|
print_info_box(htmlspecialchars($_REQUEST['message']));
|
423
|
}
|
424
|
|
425
|
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
|
426
|
$pbclass = ($completion == 100) ? "progress-bar progress-bar-success":"progress-bar progress-bar-danger";
|
427
|
?>
|
428
|
|
429
|
<!-- Draw a progress bar to show step progress -->
|
430
|
<div class="progress">
|
431
|
<div class="<?=$pbclass?>" role="progressbar" aria-valuenow="<?=$completion?>" aria-valuemin="0" aria-valuemax="100" style="width:<?=$completion?>%; line-height: 15px;">
|
432
|
<?php print(sprintf(gettext("Step %s of %s"), $stepid, $totalsteps-1)); ?>
|
433
|
</div>
|
434
|
</div>
|
435
|
<br />
|
436
|
|
437
|
<?php
|
438
|
|
439
|
$form = new Form(false);
|
440
|
|
441
|
$form->addGlobal(new Form_Input(
|
442
|
'stepid',
|
443
|
null,
|
444
|
'hidden',
|
445
|
$stepid
|
446
|
));
|
447
|
|
448
|
$form->addGlobal(new Form_Input(
|
449
|
'xml',
|
450
|
null,
|
451
|
'hidden',
|
452
|
$xml
|
453
|
));
|
454
|
|
455
|
$section = new Form_Section(fixup_string($title));
|
456
|
|
457
|
if ($description) {
|
458
|
$section->addInput(new Form_StaticText(
|
459
|
null,
|
460
|
fixup_string($description)
|
461
|
));
|
462
|
}
|
463
|
|
464
|
$inputaliases = array();
|
465
|
if ($pkg['step'][$stepid]['fields']['field'] != "") {
|
466
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
467
|
|
468
|
$value = $field['value'];
|
469
|
$name = $field['name'];
|
470
|
|
471
|
$name = preg_replace("/\s+/", "", $name);
|
472
|
$name = strtolower($name);
|
473
|
|
474
|
if ($field['bindstofield'] != "") {
|
475
|
$arraynum = "";
|
476
|
$field_conv = "";
|
477
|
$field_split = explode("->", $field['bindstofield']);
|
478
|
// arraynum is used in cases where there is an array of the same field
|
479
|
// name such as dnsserver (2 of them)
|
480
|
if ($field['arraynum'] != "") {
|
481
|
$arraynum = "[" . $field['arraynum'] . "]";
|
482
|
}
|
483
|
|
484
|
foreach ($field_split as $f) {
|
485
|
$field_conv .= "['" . $f . "']";
|
486
|
}
|
487
|
|
488
|
if ($field['type'] == "checkbox") {
|
489
|
$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
|
490
|
} else {
|
491
|
$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
|
492
|
}
|
493
|
|
494
|
eval($toeval);
|
495
|
}
|
496
|
|
497
|
|
498
|
if (DEBUG) {
|
499
|
print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '<br />');
|
500
|
}
|
501
|
|
502
|
switch ($field['type']) {
|
503
|
case "input":
|
504
|
if ($field['displayname']) {
|
505
|
$etitle = $field['displayname'];
|
506
|
|
507
|
} else if (!$field['dontdisplayname']) {
|
508
|
$etitle = fixup_string($field['name']);
|
509
|
}
|
510
|
|
511
|
$section->addInput(new Form_Input(
|
512
|
$name,
|
513
|
$etitle,
|
514
|
'text',
|
515
|
$value
|
516
|
))->setHelp($field['description'])
|
517
|
->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
|
518
|
|
519
|
break;
|
520
|
case "text":
|
521
|
$section->addInput(new Form_StaticText(
|
522
|
null,
|
523
|
$field['description']
|
524
|
));
|
525
|
|
526
|
break;
|
527
|
case "inputalias":
|
528
|
if ($field['displayname']) {
|
529
|
$etitle = $field['displayname'];
|
530
|
|
531
|
} else if (!$field['dontdisplayname']) {
|
532
|
$etitle = fixup_string($field['name']);
|
533
|
}
|
534
|
|
535
|
$onchange = "";
|
536
|
|
537
|
if ($field['validate']) {
|
538
|
$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
|
539
|
}
|
540
|
|
541
|
$section->addInput(new Form_Input(
|
542
|
$name,
|
543
|
$etitle,
|
544
|
'text',
|
545
|
$value
|
546
|
))->setAttribute('autocomplete', 'off')
|
547
|
->setOnchange($onchange)
|
548
|
->setHelp($field['description']);
|
549
|
|
550
|
break;
|
551
|
case "interfaces_selection":
|
552
|
case "interface_select":
|
553
|
|
554
|
$name = strtolower($name);
|
555
|
$options = array();
|
556
|
$selected = array();
|
557
|
|
558
|
$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
|
559
|
|
560
|
if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
|
561
|
$multiple = true;
|
562
|
} else {
|
563
|
$multiple = false;
|
564
|
}
|
565
|
|
566
|
if ($field['add_to_interfaces_selection'] != "") {
|
567
|
if ($field['add_to_interfaces_selection'] == $value) {
|
568
|
array_push($selected, $value);
|
569
|
}
|
570
|
|
571
|
$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
|
572
|
}
|
573
|
|
574
|
if ($field['type'] == "interface_select") {
|
575
|
$interfaces = get_interface_list();
|
576
|
} else {
|
577
|
$interfaces = get_configured_interface_with_descr();
|
578
|
}
|
579
|
|
580
|
foreach ($interfaces as $ifname => $iface) {
|
581
|
if ($field['type'] == "interface_select") {
|
582
|
$iface = $ifname;
|
583
|
if ($iface['mac']) {
|
584
|
$iface .= " ({$iface['mac']})";
|
585
|
}
|
586
|
}
|
587
|
|
588
|
if ($value == $ifname) {
|
589
|
array_push($selected, $value);
|
590
|
}
|
591
|
|
592
|
$canecho = 0;
|
593
|
if ($field['interface_filter'] != "") {
|
594
|
if (stristr($ifname, $field['interface_filter']) == true) {
|
595
|
$canecho = 1;
|
596
|
}
|
597
|
} else {
|
598
|
$canecho = 1;
|
599
|
}
|
600
|
|
601
|
if ($canecho == 1) {
|
602
|
$options[$ifname] = $iface;
|
603
|
}
|
604
|
}
|
605
|
|
606
|
$section->addInput(new Form_Select(
|
607
|
$name,
|
608
|
$etitle,
|
609
|
($multiple) ? $selected:$selected[0],
|
610
|
$options,
|
611
|
$multiple
|
612
|
))->setHelp($field['description']);
|
613
|
|
614
|
break;
|
615
|
case "password":
|
616
|
if ($field['displayname']) {
|
617
|
$etitle = $field['displayname'];
|
618
|
} else if (!$field['dontdisplayname']) {
|
619
|
$etitle = fixup_string($field['name']);
|
620
|
}
|
621
|
|
622
|
$section->addInput(new Form_Input(
|
623
|
$name,
|
624
|
$etitle,
|
625
|
'password',
|
626
|
$value
|
627
|
))->setHelp($field['description'])
|
628
|
->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
|
629
|
|
630
|
break;
|
631
|
case "certca_selection":
|
632
|
$options = array();
|
633
|
$selected = "";
|
634
|
|
635
|
$name = strtolower($name);
|
636
|
|
637
|
$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
|
638
|
|
639
|
if ($field['add_to_certca_selection'] != "") {
|
640
|
if ($field['add_to_certca_selection'] == $value) {
|
641
|
$selected = $value;
|
642
|
}
|
643
|
|
644
|
$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
|
645
|
}
|
646
|
|
647
|
if (!is_array($config['ca'])) {
|
648
|
$config['ca'] = array();
|
649
|
}
|
650
|
|
651
|
foreach ($config['ca'] as $ca) {
|
652
|
$caname = htmlspecialchars($ca['descr']);
|
653
|
|
654
|
if ($value == $caname) {
|
655
|
$selected = $value;
|
656
|
}
|
657
|
|
658
|
$canecho = 0;
|
659
|
if ($field['certca_filter'] != "") {
|
660
|
if (stristr($caname, $field['certca_filter']) == true) {
|
661
|
$canecho = 1;
|
662
|
}
|
663
|
} else {
|
664
|
$canecho = 1;
|
665
|
}
|
666
|
if ($canecho == 1) {
|
667
|
$options[$ca['refid']] = $caname;
|
668
|
}
|
669
|
}
|
670
|
|
671
|
$section->addInput(new Form_Select(
|
672
|
$name,
|
673
|
$etitle,
|
674
|
$selected,
|
675
|
$options
|
676
|
))->setHelp($field['description']);
|
677
|
|
678
|
break;
|
679
|
case "cert_selection":
|
680
|
$options = array();
|
681
|
$selected = array();
|
682
|
|
683
|
$multiple = false;
|
684
|
$name = strtolower($name);
|
685
|
|
686
|
$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
|
687
|
|
688
|
if ($field['add_to_cert_selection'] != "") {
|
689
|
if ($field['add_to_cert_selection'] == $value) {
|
690
|
array_push($selected, $value);
|
691
|
}
|
692
|
|
693
|
$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
|
694
|
}
|
695
|
|
696
|
if (!is_array($config['cert'])) {
|
697
|
$config['cert'] = array();
|
698
|
}
|
699
|
|
700
|
foreach ($config['cert'] as $ca) {
|
701
|
if (stristr($ca['descr'], "webconf")) {
|
702
|
continue;
|
703
|
}
|
704
|
|
705
|
$caname = htmlspecialchars($ca['descr']);
|
706
|
|
707
|
if ($value == $caname) {
|
708
|
array_push($selected, $value);
|
709
|
}
|
710
|
|
711
|
|
712
|
$canecho = 0;
|
713
|
if ($field['cert_filter'] != "") {
|
714
|
if (stristr($caname, $field['cert_filter']) == true) {
|
715
|
$canecho = 1;
|
716
|
}
|
717
|
} else {
|
718
|
$canecho = 1;
|
719
|
}
|
720
|
|
721
|
if ($canecho == 1) {
|
722
|
$options[$ca['refid']] = $caname;
|
723
|
}
|
724
|
}
|
725
|
|
726
|
$section->addInput(new Form_Select(
|
727
|
$name,
|
728
|
$etitle,
|
729
|
($multiple) ? $selected:$selected[0],
|
730
|
$options,
|
731
|
$multiple
|
732
|
))->setHelp($field['description']);
|
733
|
|
734
|
break;
|
735
|
case "select":
|
736
|
if ($field['displayname']) {
|
737
|
$etitle = $field['displayname'];
|
738
|
} else if (!$field['dontdisplayname']) {
|
739
|
$etitle = fixup_string($field['name']);
|
740
|
}
|
741
|
|
742
|
if ($field['size']) {
|
743
|
$size = " size='" . $field['size'] . "' ";
|
744
|
}
|
745
|
|
746
|
$multiple = ($field['multiple'] == "yes");
|
747
|
|
748
|
$onchange = "";
|
749
|
foreach ($field['options']['option'] as $opt) {
|
750
|
if ($opt['enablefields'] != "") {
|
751
|
$onchange = "Javascript:enableitems(this.selectedIndex);";
|
752
|
}
|
753
|
}
|
754
|
|
755
|
$options = array();
|
756
|
$selected = array();
|
757
|
|
758
|
foreach ($field['options']['option'] as $opt) {
|
759
|
if ($value == $opt['value']) {
|
760
|
array_push($selected, $value);
|
761
|
}
|
762
|
|
763
|
if ($opt['displayname']) {
|
764
|
$options[$opt['value']] = $opt['displayname'];
|
765
|
} else {
|
766
|
$options[$opt['value']] = $opt['name'];
|
767
|
}
|
768
|
|
769
|
}
|
770
|
|
771
|
$section->addInput(new Form_Select(
|
772
|
$name,
|
773
|
$etitle,
|
774
|
($multiple) ? $selected:$selected[0],
|
775
|
$options,
|
776
|
$multiple
|
777
|
))->setHelp($field['description'])->setOnchange($onchange);
|
778
|
|
779
|
break;
|
780
|
case "textarea":
|
781
|
if ($field['displayname']) {
|
782
|
$etitle = $field['displayname'];
|
783
|
} else if (!$field['dontdisplayname']) {
|
784
|
$etitle = fixup_string($field['name']);
|
785
|
}
|
786
|
|
787
|
$section->addInput(new Form_Textarea(
|
788
|
$name,
|
789
|
$etitle,
|
790
|
$value
|
791
|
))->setHelp($field['description'])
|
792
|
->setAttribute('rows', $field['rows'])
|
793
|
->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
|
794
|
|
795
|
break;
|
796
|
case "submit":
|
797
|
$form->addGlobal(new Form_Button(
|
798
|
$name,
|
799
|
$field['name'],
|
800
|
null,
|
801
|
'fa-angle-double-right'
|
802
|
))->addClass('btn-primary');
|
803
|
|
804
|
break;
|
805
|
case "listtopic":
|
806
|
$form->add($section);
|
807
|
$section = new Form_Section($field['name']);
|
808
|
|
809
|
break;
|
810
|
case "subnet_select":
|
811
|
if ($field['displayname']) {
|
812
|
$etitle = $field['displayname'];
|
813
|
} else /* if (!$field['dontdisplayname']) */ {
|
814
|
$etitle = fixup_string($field['name']);
|
815
|
}
|
816
|
|
817
|
$section->addInput(new Form_Select(
|
818
|
$name,
|
819
|
$etitle,
|
820
|
$value,
|
821
|
array_combine(range(32, 1, -1), range(32, 1, -1))
|
822
|
))->setHelp($field['description']);
|
823
|
|
824
|
break;
|
825
|
case "timezone_select":
|
826
|
$timezonelist = system_get_timezone_list();
|
827
|
|
828
|
/* kill carriage returns */
|
829
|
for ($x = 0; $x < count($timezonelist); $x++) {
|
830
|
$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
|
831
|
}
|
832
|
|
833
|
if ($field['displayname']) {
|
834
|
$etitle = $field['displayname'];
|
835
|
} else if (!$field['dontdisplayname']) {
|
836
|
$etitle = fixup_string($field['name']);
|
837
|
}
|
838
|
|
839
|
if (!$field['dontcombinecells']) {
|
840
|
//echo "<td class=\"vtable\">";
|
841
|
}
|
842
|
|
843
|
$section->addInput(new Form_Select(
|
844
|
$name,
|
845
|
$etitle,
|
846
|
($value == "") ? $g['default_timezone'] : $value,
|
847
|
array_combine($timezonelist, $timezonelist)
|
848
|
))->setHelp($field['description']);
|
849
|
|
850
|
break;
|
851
|
case "checkbox":
|
852
|
if ($field['displayname']) {
|
853
|
$etitle = $field['displayname'];
|
854
|
|
855
|
} else if (!$field['dontdisplayname']) {
|
856
|
$etitle = fixup_string($field['name']);
|
857
|
}
|
858
|
|
859
|
if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
|
860
|
$onclick = "enablechange()";
|
861
|
} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
|
862
|
$onclick = "disablechange()";
|
863
|
}
|
864
|
|
865
|
$section->addInput(new Form_Checkbox(
|
866
|
$name,
|
867
|
$etitle,
|
868
|
$field['typehint'],
|
869
|
($value != ""),
|
870
|
'on'
|
871
|
))->setHelp($field['description'])
|
872
|
->setOnclick($onclick);
|
873
|
|
874
|
break;
|
875
|
} // e-o-switch
|
876
|
} // e-o-foreach (package)
|
877
|
} // e-o-if (we have fields)
|
878
|
|
879
|
$form->add($section);
|
880
|
print($form);
|
881
|
?>
|
882
|
|
883
|
<script type="text/javascript">
|
884
|
//<![CDATA[
|
885
|
|
886
|
if (typeof ext_change != 'undefined') {
|
887
|
ext_change();
|
888
|
}
|
889
|
if (typeof proto_change != 'undefined') {
|
890
|
ext_change();
|
891
|
}
|
892
|
if (typeof proto_change != 'undefined') {
|
893
|
proto_change();
|
894
|
}
|
895
|
|
896
|
<?php
|
897
|
$isfirst = 0;
|
898
|
$aliases = "";
|
899
|
$addrisfirst = 0;
|
900
|
$aliasesaddr = "";
|
901
|
if ($config['aliases']['alias'] != "" and is_array($config['aliases']['alias'])) {
|
902
|
foreach ($config['aliases']['alias'] as $alias_name) {
|
903
|
if ($isfirst == 1) {
|
904
|
$aliases .= ",";
|
905
|
}
|
906
|
$aliases .= "'" . $alias_name['name'] . "'";
|
907
|
$isfirst = 1;
|
908
|
}
|
909
|
}
|
910
|
?>
|
911
|
|
912
|
var customarray=new Array(<?=$aliases; ?>);
|
913
|
|
914
|
window.onload = function () {
|
915
|
|
916
|
<?php
|
917
|
$counter = 0;
|
918
|
foreach ($inputaliases as $alias) {
|
919
|
?>
|
920
|
$('#' + '<?=$alias;?>').autocomplete({
|
921
|
source: customarray
|
922
|
});
|
923
|
<?php
|
924
|
}
|
925
|
?>
|
926
|
}
|
927
|
|
928
|
//]]>
|
929
|
</script>
|
930
|
|
931
|
<?php
|
932
|
|
933
|
$fieldnames_array = Array();
|
934
|
if ($pkg['step'][$stepid]['disableallfieldsbydefault'] != "") {
|
935
|
// create a fieldname loop that can be used with javascript
|
936
|
// hide and enable features.
|
937
|
echo "\n<script type=\"text/javascript\">\n";
|
938
|
echo "//<![CDATA[\n";
|
939
|
echo "function disableall() {\n";
|
940
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
941
|
if ($field['type'] != "submit" and $field['type'] != "listtopic") {
|
942
|
if (!$field['donotdisable'] != "") {
|
943
|
array_push($fieldnames_array, $field['name']);
|
944
|
$fieldname = preg_replace("/\s+/", "", $field['name']);
|
945
|
$fieldname = strtolower($fieldname);
|
946
|
echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
|
947
|
}
|
948
|
}
|
949
|
}
|
950
|
echo "}\ndisableall();\n";
|
951
|
echo "function enableitems(selectedindex) {\n";
|
952
|
echo "disableall();\n";
|
953
|
$idcounter = 0;
|
954
|
if ($pkg['step'][$stepid]['fields']['field'] != "") {
|
955
|
echo "\tswitch (selectedindex) {\n";
|
956
|
foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
|
957
|
if ($field['options']['option'] != "") {
|
958
|
foreach ($field['options']['option'] as $opt) {
|
959
|
if ($opt['enablefields'] != "") {
|
960
|
echo "\t\tcase " . $idcounter . ":\n";
|
961
|
$enablefields_split = explode(",", $opt['enablefields']);
|
962
|
foreach ($enablefields_split as $efs) {
|
963
|
$fieldname = preg_replace("/\s+/", "", $efs);
|
964
|
$fieldname = strtolower($fieldname);
|
965
|
if ($fieldname != "") {
|
966
|
$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
|
967
|
echo $onchange;
|
968
|
}
|
969
|
}
|
970
|
echo "\t\t\tbreak;\n";
|
971
|
}
|
972
|
$idcounter = $idcounter + 1;
|
973
|
}
|
974
|
}
|
975
|
}
|
976
|
echo "\t}\n";
|
977
|
}
|
978
|
echo "}\n";
|
979
|
echo "//]]>\n";
|
980
|
echo "</script>\n\n";
|
981
|
}
|
982
|
?>
|
983
|
|
984
|
<script type="text/javascript">
|
985
|
//<![CDATA[
|
986
|
events.push(function() {
|
987
|
enablechange();
|
988
|
disablechange();
|
989
|
showchange();
|
990
|
});
|
991
|
//]]>
|
992
|
</script>
|
993
|
|
994
|
<?php
|
995
|
if ($pkg['step'][$stepid]['stepafterformdisplay'] != "") {
|
996
|
// handle after form display event.
|
997
|
eval($pkg['step'][$stepid]['stepafterformdisplay']);
|
998
|
}
|
999
|
|
1000
|
if ($pkg['step'][$stepid]['javascriptafterformdisplay'] != "") {
|
1001
|
// handle after form display event.
|
1002
|
echo "\n<script type=\"text/javascript\">\n";
|
1003
|
echo "//<![CDATA[\n";
|
1004
|
echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
|
1005
|
echo "//]]>\n";
|
1006
|
echo "</script>\n\n";
|
1007
|
}
|
1008
|
|
1009
|
include("foot.inc");
|