wizard.php 31.1 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
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
	Copyright (C) 2004 Scott Ullrich
	Copyright (C) 2010 Ermal Luçi
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

31
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
32 33
require_once("filter.inc");
require_once("rrd.inc");
34
require_once("system.inc");
35
require_once("pfsense-utils.inc");
36
require_once("interfaces.inc");
Ad Schellevis's avatar
Ad Schellevis committed
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
/*
 * find_ip_interface($ip): return the interface where an ip is defined
 *   (or if $bits is specified, where an IP within the subnet is defined)
 */
function find_ip_interface($ip, $bits = null) {
	if (!is_ipaddr($ip))
		return false;

	$isv6ip = is_ipaddrv6($ip);

	/* if list */
	$ifdescrs = get_configured_interface_list();

	foreach ($ifdescrs as $ifdescr => $ifname) {
		$ifip = ($isv6ip) ? get_interface_ipv6($ifname) : get_interface_ip($ifname);
		if (is_null($ifip))
			continue;
		if (is_null($bits)) {
			if ($ip == $ifip) {
				$int = get_real_interface($ifname);
				return $int;
			}
		}
		else {
			if (ip_in_subnet($ifip, $ip . "/" . $bits)) {
				$int = get_real_interface($ifname);
				return $int;
			}
		}
	}

	return false;
}


Ad Schellevis's avatar
Ad Schellevis committed
73 74 75 76 77 78
$stepid = htmlspecialchars($_GET['stepid']);
if (isset($_POST['stepid']))
	$stepid = htmlspecialchars($_POST['stepid']);
if (!$stepid)
	$stepid = "0";

79 80 81 82
$xml = '';
if (isset($_GET['xml'])) {
	$xml = htmlspecialchars($_GET['xml']);
} elseif (isset($_POST['xml'])) {
Ad Schellevis's avatar
Ad Schellevis committed
83
	$xml = htmlspecialchars($_POST['xml']);
84
}
Ad Schellevis's avatar
Ad Schellevis committed
85

86 87 88 89 90 91 92 93
/*
 * XXX If we don't want hardcoding we could
 * probe /usr/local/wizard for viable files.
 */
switch ($xml) {
	case 'openvpn':
		break;
	default:
94
		$xml = 'setup';
95
		break;
Ad Schellevis's avatar
Ad Schellevis committed
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
global $g, $listtags;

$listtags = array_flip(array(
	'additional_files_needed',
	'alias',
	'build_port_path',
	'columnitem',
	'depends_on_package',
	'field',
	'file',
	'item',
	'menu',
	'onetoone',
	'option',
	'package',
	'package',
	'queue',
	'rowhelperfield',
	'rule',
	'servernat',
	'service',
	'step',
	'tab',
	'template',
));

124
$pkg = parse_xml_config_raw("/usr/local/wizard/{$xml}.xml", 'opnsensewizard', false);
Ad Schellevis's avatar
Ad Schellevis committed
125
if (!is_array($pkg)) {
126
	print_info_box(sprintf(gettext("ERROR: Could not parse %s wizard file."), $xml));
Ad Schellevis's avatar
Ad Schellevis committed
127 128 129 130
	die;
}

$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);
131 132
$title = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
$totalsteps = $pkg['totalsteps'];
Ad Schellevis's avatar
Ad Schellevis committed
133

134
if ($pkg['includefile']) {
Ad Schellevis's avatar
Ad Schellevis committed
135
	require_once($pkg['includefile']);
136
}
Ad Schellevis's avatar
Ad Schellevis committed
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218

if($pkg['step'][$stepid]['stepsubmitbeforesave']) {
	eval($pkg['step'][$stepid]['stepsubmitbeforesave']);
}

if ($_POST && !$input_errors) {
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
		if(!empty($field['bindstofield']) and $field['type'] <> "submit") {
			$fieldname = $field['name'];
			$fieldname = str_replace(" ", "", $fieldname);
			$fieldname = strtolower($fieldname);
			// update field with posted values.
			if($field['unsetfield'] <> "")
				$unset_fields = "yes";
			else
				$unset_fields = "";
			if($field['arraynum'] <> "")
				$arraynum = $field['arraynum'];
			else
				$arraynum = "";

			update_config_field( $field['bindstofield'], $_POST[$fieldname], $unset_fields, $arraynum, $field['type']);
		}

	}
	// run custom php code embedded in xml config.
	if($pkg['step'][$stepid]['stepsubmitphpaction'] <> "") {
		eval($pkg['step'][$stepid]['stepsubmitphpaction']);
	}
	if (!$input_errors)
		write_config();
	$stepid++;
	if($stepid > $totalsteps)
		$stepid = $totalsteps;
}

function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) {
	global $config;
	$field_split = explode("->",$field);
	foreach ($field_split as $f)
		$field_conv .= "['" . $f . "']";
	if($field_conv == "")
		return;
	if ($arraynum <> "")
		$field_conv .= "[" . $arraynum . "]";
	if(($field_type == "checkbox" and $updatetext <> "on") || $updatetext == "") {
		/*
		 * item is a checkbox, it should have the value "on"
		 * if it was checked
		 */
		$var = "\$config{$field_conv}";
		$text = "if (isset({$var})) unset({$var});";
		eval($text);
		return;
	}

	if($field_type == "interfaces_selection") {
		$var = "\$config{$field_conv}";
		$text = "if (isset({$var})) unset({$var});";
		$text .= "\$config" . $field_conv . " = \"" . $updatetext . "\";";
		eval($text);
		return;
	}

	if($unset == "yes") {
		$text = "unset(\$config" . $field_conv . ");";
		eval($text);
	}
	$text = "\$config" . $field_conv . " = \"" . addslashes($updatetext) . "\";";
	eval($text);
}

$title       = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['title']);
$description = preg_replace("/pfSense/i", $g['product_name'], $pkg['step'][$stepid]['description']);

// handle before form display event.
do {
	$oldstepid = $stepid;
	if($pkg['step'][$stepid]['stepbeforeformdisplay'] <> "")
		eval($pkg['step'][$stepid]['stepbeforeformdisplay']);
} while ($oldstepid != $stepid);

219

Ad Schellevis's avatar
Ad Schellevis committed
220 221 222
include("head.inc");

?>
Ad Schellevis's avatar
Ad Schellevis committed
223
<body>
224
<?php include("fbegin.inc"); ?>
Ad Schellevis's avatar
Ad Schellevis committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

<?php if($pkg['step'][$stepid]['fields']['field'] <> "") { ?>
<script type="text/javascript">
//<![CDATA[

function  FieldValidate(userinput,  regexp,  message)
{
	if(!userinput.match(regexp))
		alert(message);
}

function enablechange() {
<?php
	foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
		if(isset($field['enablefields']) or isset($field['checkenablefields'])) {
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
			if(isset($field['enablefields'])) {
				$enablefields = explode(',', $field['enablefields']);
				foreach($enablefields as $enablefield) {
					$enablefield = strtolower($enablefield);
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
				}
			}
			if(isset($field['checkenablefields'])) {
				$checkenablefields = explode(',', $field['checkenablefields']);
				foreach($checkenablefields as $checkenablefield) {
					$checkenablefield = strtolower($checkenablefield);
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
				}
			}
			print "\t" . '} else {' . "\n";
			if(isset($field['enablefields'])) {
				$enablefields = explode(',', $field['enablefields']);
				foreach($enablefields as $enablefield) {
					$enablefield = strtolower($enablefield);
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
				}
			}
			if(isset($field['checkenablefields'])) {
				$checkenablefields = explode(',', $field['checkenablefields']);
				foreach($checkenablefields as $checkenablefield) {
					$checkenablefield = strtolower($checkenablefield);
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
				}
			}
			print "\t" . '}' . "\n";
		}
	}
?>
}

function disablechange() {
<?php
	foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
		if(isset($field['disablefields']) or isset($field['checkdisablefields'])) {
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked) {' . "\n";
			if(isset($field['disablefields'])) {
				$enablefields = explode(',', $field['disablefields']);
				foreach($enablefields as $enablefield) {
					$enablefield = strtolower($enablefield);
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 1;' . "\n";
				}
			}
			if(isset($field['checkdisablefields'])) {
				$checkenablefields = explode(',', $field['checkdisablefields']);
				foreach($checkenablefields as $checkenablefield) {
					$checkenablefield = strtolower($checkenablefield);
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 1;' . "\n";
				}
			}
			print "\t" . '} else {' . "\n";
			if(isset($field['disablefields'])) {
				$enablefields = explode(',', $field['disablefields']);
				foreach($enablefields as $enablefield) {
					$enablefield = strtolower($enablefield);
					print "\t\t" . 'document.iform.' . $enablefield . '.disabled = 0;' . "\n";
				}
			}
			if(isset($field['checkdisablefields'])) {
				$checkenablefields = explode(',', $field['checkdisablefields']);
				foreach($checkenablefields as $checkenablefield) {
					$checkenablefield = strtolower($checkenablefield);
					print "\t\t" . 'document.iform.' . $checkenablefield . '.checked = 0;' . "\n";
				}
			}
			print "\t" . '}' . "\n";
		}
	}
?>
}

function showchange() {
<?php
	foreach($pkg['step'][$stepid]['fields']['field'] as $field) {
		if(isset($field['showfields'])) {
			print "\t" . 'if (document.iform.' . strtolower($field['name']) . '.checked == false) {' . "\n";
			if(isset($field['showfields'])) {
				$showfields = explode(',', $field['showfields']);
				foreach($showfields as $showfield) {
					$showfield = strtolower($showfield);
					//print "\t\t" . 'document.iform.' . $showfield . ".display =\"none\";\n";
					print "\t\t jQuery('#". $showfield . "').hide();";
				}
			}
			print "\t" . '} else {' . "\n";
			if(isset($field['showfields'])) {
				$showfields = explode(',', $field['showfields']);
				foreach($showfields as $showfield) {
					$showfield = strtolower($showfield);
					#print "\t\t" . 'document.iform.' . $showfield . ".display =\"\";\n";
					print "\t\t jQuery('#". $showfield . "').show();";
				}
			}
			print "\t" . '}' . "\n";
		}
	}
?>
}
//]]>
</script>
<?php } ?>

347

Ad Schellevis's avatar
Ad Schellevis committed
348 349 350 351 352 353 354 355
<?php
	if($title == "Reload in progress") {
		$ip = fixup_string("\$myurl");
	} else {
		$ip = "/";
	}
?>

Ad Schellevis's avatar
Ad Schellevis committed
356 357 358 359

<section class="page-content-main">
	<div class="container-fluid col-xs-12 col-sm-10 col-md-9">
		<div class="row">
360

Ad Schellevis's avatar
Ad Schellevis committed
361
			<?php
362
				if (isset($input_errors) && count($input_errors) > 0)
Ad Schellevis's avatar
Ad Schellevis committed
363
					print_input_errors($input_errors);
364
				if (isset($savemsg))
Ad Schellevis's avatar
Ad Schellevis committed
365 366 367 368 369 370 371 372
					print_info_box($savemsg);
				if ($_GET['message'] != "")
					print_info_box(htmlspecialchars($_GET['message']));
				if ($_POST['message'] != "")
					print_info_box(htmlspecialchars($_POST['message']));
			?>

		    <section class="col-xs-12">
373
			     <div class="content-box">
Ad Schellevis's avatar
Ad Schellevis committed
374 375

					 <form action="wizard.php" method="post" name="iform" id="iform">
376 377 378 379 380 381 382
						<input type="hidden" name="xml" value="<?= htmlspecialchars($xml) ?>" />
						<input type="hidden" name="stepid" value="<?= htmlspecialchars($stepid) ?>" />

						<?php if(!$pkg['step'][$stepid]['disableheader']): ?>
						<header class="content-box-head container-fluid">
						<h3><?= fixup_string($title) ?></h3>
					</header>
383
					<?php endif; ?>
384

Ad Schellevis's avatar
Ad Schellevis committed
385 386 387
						<div class="content-box-main">
							<div style="padding:20px !important;">
								<p><br /><?=fixup_string($description) ?></p>
388

Ad Schellevis's avatar
Ad Schellevis committed
389 390 391 392 393 394
							</div>
							<div class="table-responsive">
								<table class="table table-striped">



Ad Schellevis's avatar
Ad Schellevis committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
<?php
	$inputaliases = array();
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {

			$value = $field['value'];
			$name  = $field['name'];

			$name = preg_replace("/\s+/", "", $name);
			$name = strtolower($name);

			if($field['bindstofield'] <> "") {
				$arraynum = "";
				$field_conv = "";
				$field_split = explode("->", $field['bindstofield']);
				// arraynum is used in cases where there is an array of the same field
				// name such as dnsserver (2 of them)
				if($field['arraynum'] <> "")
					$arraynum = "[" . $field['arraynum'] . "]";
				foreach ($field_split as $f)
					$field_conv .= "['" . $f . "']";
				if($field['type'] == "checkbox")
					$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) { \$value = \$config" . $field_conv . $arraynum . "; if (empty(\$value)) \$value = true; }";
				else
					$toeval = "if (isset(\$config" . $field_conv . $arraynum . ")) \$value = \$config" . $field_conv . $arraynum . ";";
				eval($toeval);
			}

			if(!$field['combinefieldsend'])
				echo "<tr>";

			switch ($field['type']) {
			case "input":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>\n";
				}
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">\n";

440
				echo "<input class='form-control unknown' type='text' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\"";
Ad Schellevis's avatar
Ad Schellevis committed
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
				if($field['size'])
					echo " size='" . $field['size'] . "' ";
				if($field['validate'])
					echo " onchange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
				echo " />\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}
				break;
			case "text":
				echo "<td colspan=\"2\" align=\"center\" class=\"vncell\">\n";
				if($field['description'] <> "") {
					echo "<center><br /> " . $field['description'] . "</center>";
				}
				break;
			case "inputalias":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>\n";
				}
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">\n";

				$inputaliases[] = $name;
Ad Schellevis's avatar
Ad Schellevis committed
471
				echo "<input class='form-control alias' autocomplete='off' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\"";
Ad Schellevis's avatar
Ad Schellevis committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
				if($field['size'])
					echo " size='" . $field['size'] . "' ";
				if($field['validate'])
					echo " onchange='FieldValidate(this.value, \"{$field['validate']}\", \"{$field['message']}\");'";
				echo " />\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}
				break;
			case "interfaces_selection":
			case "interface_select":
				$size = "";
				$multiple = "";
				$name = strtolower($name);
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
				echo "</td>";
				echo "<td class=\"vtable\">\n";
				if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
				if($field['multiple'] <> "" and $field['multiple'] <> "0") {
					$multiple = "multiple=\"multiple\"";
					$name .= "[]";
				}
Ad Schellevis's avatar
Ad Schellevis committed
496
				echo "<select class='form-control' id='{$name}' name='{$name}' {$size} {$multiple}>\n";
Ad Schellevis's avatar
Ad Schellevis committed
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
				if($field['add_to_interfaces_selection'] <> "") {
					$SELECTED = "";
					if($field['add_to_interfaces_selection'] == $value) $SELECTED = " selected=\"selected\"";
					echo "<option value='" . $field['add_to_interfaces_selection'] . "'" . $SELECTED . ">" . $field['add_to_interfaces_selection'] . "</option>\n";
				}
				if($field['type'] == "interface_select")
					$interfaces = get_interface_list();
				else
					$interfaces = get_configured_interface_with_descr();
				foreach ($interfaces as $ifname => $iface) {
					if ($field['type'] == "interface_select") {
						$iface = $ifname;
						if ($iface['mac'])
							$iface .= " ({$iface['mac']})";
					}
					$SELECTED = "";
					if ($value == $ifname) $SELECTED = " selected=\"selected\"";
					$to_echo = "<option value='" . $ifname . "'" . $SELECTED . ">" . $iface . "</option>\n";
					$to_echo .= "<!-- {$value} -->";
					$canecho = 0;
					if($field['interface_filter'] <> "") {
						if(stristr($ifname, $field['interface_filter']) == true)
							$canecho = 1;
					} else
						$canecho = 1;
					if($canecho == 1)
						echo $to_echo;
				}
				echo "</select>\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "password":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>\n";
				}
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">";
Ad Schellevis's avatar
Ad Schellevis committed
544
				echo "<input class='form-control pwd' id='" . $name . "' name='" . $name . "' value=\"" . htmlspecialchars($value) . "\" type='password' ";
Ad Schellevis's avatar
Ad Schellevis committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
				if($field['size'])
					echo " size='" . $field['size'] . "' ";
				echo " />\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "certca_selection":
				$size = "";
				$multiple = "";
				$name = strtolower($name);
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
				echo "</td>";
				echo "<td class=\"vtable\">\n";
				if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
				if($field['add_to_certca_selection'] <> "") {
					$SELECTED = "";
					if($field['add_to_certca_selection'] == $value) $SELECTED = " selected=\"selected\"";
					echo "<option value='" . $field['add_to_certca_selection'] . "'" . $SELECTED . ">" . $field['add_to_certca_selection'] . "</option>\n";
				}
				foreach($config['ca'] as $ca) {
					$name = htmlspecialchars($ca['descr']);
					$SELECTED = "";
					if ($value == $name) $SELECTED = " selected=\"selected\"";
					$to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
					$to_echo .= "<!-- {$value} -->";
					$canecho = 0;
					if($field['certca_filter'] <> "") {
						if(stristr($name, $field['certca_filter']) == true)
							$canecho = 1;
					} else {
						$canecho = 1;
					}
					if($canecho == 1)
						echo $to_echo;
				}
				echo "</select>\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "cert_selection":
				$size = "";
				$multiple = "";
				$name = strtolower($name);
				echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
				echo fixup_string($field['displayname'] ? $field['displayname'] : $field['name']) . ":\n";
				echo "</td>";
				echo "<td class=\"vtable\">\n";
				if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
				echo "<select id='{$name}' name='{$name}' {$size}>\n";
				if($field['add_to_cert_selection'] <> "") {
					$SELECTED = "";
					if($field['add_to_cert_selection'] == $value) $SELECTED = " selected=\"selected\"";
					echo "<option value='" . $field['add_to_cert_selection'] . "'" . $SELECTED . ">" . $field['add_to_cert_selection'] . "</option>\n";
				}
				foreach($config['cert'] as $ca) {
					if (stristr($ca['descr'], "webconf"))
						continue;
					$name = htmlspecialchars($ca['descr']);
					$SELECTED = "";
					if ($value == $name) $SELECTED = " selected=\"selected\"";
					$to_echo = "<option value='" . $ca['refid'] . "'" . $SELECTED . ">" . $name . "</option>\n";
					$to_echo .= "<!-- {$value} -->";
					$canecho = 0;
					if($field['cert_filter'] <> "") {
						if(stristr($name, $field['cert_filter']) == true)
							$canecho = 1;
					} else {
						$canecho = 1;
					}
					if($canecho == 1)
						echo $to_echo;
				}
				echo "</select>\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "select":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>\n";
				}
				if($field['size']) $size = " size='" . $field['size'] . "' ";
				if($field['multiple'] == "yes") $multiple = "multiple=\"multiple\" ";
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">\n";
				$onchange = "";
				foreach ($field['options']['option'] as $opt) {
					if($opt['enablefields'] <> "") {
						$onchange = "onchange=\"enableitems(this.selectedIndex);\" ";
					}
				}
Ad Schellevis's avatar
Ad Schellevis committed
652
				echo "<select class='form-control' " . $onchange . $multiple . $size . "id='" . $name . "' name='" . $name . "'>\n";
Ad Schellevis's avatar
Ad Schellevis committed
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
				foreach ($field['options']['option'] as $opt) {
					$selected = "";
					if($value == $opt['value'])
						$selected = " selected=\"selected\"";
					echo "\t<option value='" . $opt['value'] . "'" . $selected . ">";
					if ($opt['displayname'])
						echo $opt['displayname'];
					else
						echo $opt['name'];
					echo "</option>\n";
				}
				echo "</select>\n";
				echo "<!-- {$value} -->\n";

				if($field['description'] <> "") {
					echo $field['description'];
				}

				break;
			case "textarea":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>";
				}
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">";
				echo "<textarea class='formpre' id='" . $name . "' name='" . $name . "'";
				if ($field['rows'])
					echo " rows='" . $field['rows'] . "' ";
				if ($field['cols'])
					echo " cols='" . $field['cols'] . "' ";
				echo ">" . $value . "</textarea>\n";


				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "submit":
Ad Schellevis's avatar
Ad Schellevis committed
698
				echo "<td colspan=\"2\">&nbsp;</td></tr>";
Ad Schellevis's avatar
Ad Schellevis committed
699
				echo "<tr><td colspan=\"2\" align=\"center\">";
Ad Schellevis's avatar
Ad Schellevis committed
700
				echo "<input type='submit' class=\"btn btn-primary\" name='" . $name . "' value=\"" . htmlspecialchars($field['name']) . "\" />\n";
Ad Schellevis's avatar
Ad Schellevis committed
701 702 703 704 705 706 707

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "listtopic":
Ad Schellevis's avatar
Ad Schellevis committed
708
				echo "<td colspan=\"2\">&nbsp;</td></tr>";
Ad Schellevis's avatar
Ad Schellevis committed
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
				echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $field['name'] . "<br />\n";

				break;
			case "subnet_select":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>";
				}
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">";
724
				echo "<select class='form-control' name='{$name}' style='max-width:5em;'>\n";
725 726 727 728 729 730 731 732 733 734 735 736 737
				$CHECKED = ' selected="selected"';
				for ($x = 1; $x <= 32; $x++) {
					if ($x == 31) {
						continue;
					}
					if ($value == $x) $CHECKED = " selected=\"selected\"";
					echo "<option value='{$x}'";
					if ($value == $x || $x == 32) {
						echo $CHECKED;
						/* only used once */
						$CHECKED = '';
					}
					echo ">{$x}</option>\n";
Ad Schellevis's avatar
Ad Schellevis committed
738 739 740 741 742 743 744 745 746
				}
				echo "</select>\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "timezone_select":
747
				$timezonelist = get_zoneinfo();
Ad Schellevis's avatar
Ad Schellevis committed
748 749 750 751 752 753 754 755 756 757 758 759

				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo fixup_string($field['name']);
					echo ":</td>";
				}
				if(!$field['dontcombinecells'])
					echo "<td class=\"vtable\">";
Ad Schellevis's avatar
Ad Schellevis committed
760
				echo "<select class='form-control' name='{$name}'>\n";
Ad Schellevis's avatar
Ad Schellevis committed
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
				foreach ($timezonelist as $tz) {
					if(strstr($tz, "GMT"))
						continue;
					$SELECTED = "";
					if ($value == $tz) $SELECTED = " selected=\"selected\"";
					echo "<option value=\"" . htmlspecialchars($tz) . "\" {$SELECTED}>";
					echo htmlspecialchars($tz);
					echo "</option>\n";
				}
				echo "</select>\n";

				if($field['description'] <> "") {
					echo "<br /> " . $field['description'];
				}

				break;
			case "checkbox":
				if ($field['displayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['displayname'];
					echo ":</td>\n";
				} else if(!$field['dontdisplayname']) {
					echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
					echo $field['name'];
					echo ":</td>";
				}
				$checked = "";
				if($value <> "")
					$checked = " checked=\"checked\"";
				echo "<td class=\"vtable\"><input value=\"on\" type='checkbox' id='" . $name . "' name='" . $name . "' " . $checked;
				if(isset($field['enablefields']) or isset($field['checkenablefields']))
					echo " onclick=\"enablechange()\"";
				else if(isset($field['disablefields']) or isset($field['checkdisablefields']))
					echo " onclick=\"disablechange()\"";
				echo " />\n";

				if($field['description'] <> "") {
					echo $field['description'];
				}

				break;
			}

			if($field['typehint'] <> "") {
				echo $field['typehint'];
			}
			if($field['warning'] <> "") {
				echo "<br /><b><font color=\"red\">" . $field['warning'] . "</font></b>";
			}

			if(!$field['combinefieldsbegin']) {
				if (!$field['dontcombinecells'])
					echo "</td>";

				echo "</tr>\n";
			}

		}
	}
?>
821

Ad Schellevis's avatar
Ad Schellevis committed
822 823 824 825 826 827 828 829 830 831 832 833
								</table>
								<br /><br /><br />
							</div>
						</div>
					 </form>
			     </div>
		    </section>
		</div>
	</div>
</section>


Ad Schellevis's avatar
Ad Schellevis committed
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
<script type="text/javascript">
//<![CDATA[
	if (typeof ext_change != 'undefined') {
		ext_change();
	}
	if (typeof proto_change != 'undefined') {
		ext_change();
	}
	if (typeof proto_change != 'undefined') {
		proto_change();
	}

<?php
	$isfirst = 0;
	$aliases = "";
	$addrisfirst = 0;
	$aliasesaddr = "";
851 852 853
	if (isset($config['aliases']['alias'])) {
		foreach ($config['aliases']['alias'] as $alias_name) {
				if ($isfirst == 1) {
Ad Schellevis's avatar
Ad Schellevis committed
854
					$aliases .= ",";
855
				}
Ad Schellevis's avatar
Ad Schellevis committed
856 857 858
				$aliases .= "'" . $alias_name['name'] . "'";
				$isfirst = 1;
		}
859
	}
Ad Schellevis's avatar
Ad Schellevis committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
?>

	var customarray=new Array(<?php echo $aliases; ?>);

	window.onload = function () {

		<?php
			$counter=0;
			foreach($inputaliases as $alias) {
				echo "var oTextbox$counter = new AutoSuggestControl(document.getElementById(\"$alias\"), new StateSuggestions(customarray));\n";
				$counter++;
			}
		?>

	}

//]]>
</script>

<?php

$fieldnames_array = Array();
if($pkg['step'][$stepid]['disableallfieldsbydefault'] <> "") {
	// create a fieldname loop that can be used with javascript
	// hide and enable features.
	echo "\n<script type=\"text/javascript\">\n";
	echo "//<![CDATA[\n";
	echo "function disableall() {\n";
	foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
		if($field['type'] <> "submit" and $field['type'] <> "listtopic") {
			if(!$field['donotdisable'] <> "") {
				array_push($fieldnames_array, $field['name']);
				$fieldname = preg_replace("/\s+/", "", $field['name']);
				$fieldname = strtolower($fieldname);
894 895
				//echo "\tdocument.forms[0]." . $fieldname . ".disabled = 1;\n";
				echo "\tjQuery('#". $fieldname . "').prop('disabled', true);\n";
Ad Schellevis's avatar
Ad Schellevis committed
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
			}
		}
	}
	echo "}\ndisableall();\n";
	echo "function enableitems(selectedindex) {\n";
	echo "disableall();\n";
	$idcounter = 0;
	if($pkg['step'][$stepid]['fields']['field'] <> "") {
		echo "\tswitch(selectedindex) {\n";
		foreach ($pkg['step'][$stepid]['fields']['field'] as $field) {
			if($field['options']['option'] <> "") {
				foreach ($field['options']['option'] as $opt) {
					if($opt['enablefields'] <> "") {
						echo "\t\tcase " . $idcounter . ":\n";
						$enablefields_split = explode(",", $opt['enablefields']);
						foreach ($enablefields_split as $efs) {
							$fieldname = preg_replace("/\s+/", "", $efs);
							$fieldname = strtolower($fieldname);
							if($fieldname <> "") {
915 916
								//$onchange = "\t\t\tdocument.forms[0]." . $fieldname . ".disabled = 0; \n";
								$onchange = "\t\t\tjQuery('#" . $fieldname . "').prop('disabled',false)\n";
Ad Schellevis's avatar
Ad Schellevis committed
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
								echo $onchange;
							}
						}
						echo "\t\t\tbreak;\n";
					}
					$idcounter = $idcounter + 1;
				}
			}
		}
		echo "\t}\n";
	}
	echo "}\n";
	echo "//]]>\n";
	echo "</script>\n\n";
}
?>

<script type="text/javascript">
//<![CDATA[
936 937 938 939 940 941 942

// After reload/redirect functions are not loaded, so check first.
if (typeof enablechange == 'function') {
	enablechange();
	disablechange();
	showchange();
}
Ad Schellevis's avatar
Ad Schellevis committed
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
//]]>
</script>

<?php
if($pkg['step'][$stepid]['stepafterformdisplay'] <> "") {
	// handle after form display event.
	eval($pkg['step'][$stepid]['stepafterformdisplay']);
}

if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
	// handle after form display event.
	echo "\n<script type=\"text/javascript\">\n";
	echo "//<![CDATA[\n";
	echo $pkg['step'][$stepid]['javascriptafterformdisplay'] . "\n";
	echo "//]]>\n";
	echo "</script>\n\n";
}

/*
 *  HELPER FUNCTIONS
 */

965 966 967
function fixup_string($string)
{
	global $config, $myurl, $title;
Ad Schellevis's avatar
Ad Schellevis committed
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
	$newstring = $string;
	// fixup #1: $myurl -> http[s]://ip_address:port/
	switch($config['system']['webgui']['protocol']) {
		case "http":
			$proto = "http";
			break;
		case "https":
			$proto = "https";
			break;
		default:
			$proto = "http";
			break;
	}
	$port = $config['system']['webgui']['port'];
	if($port != "") {
		if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
			$urlport = ":" . $port;
		} elseif ($port != "80" and $port != "443") {
			$urlport = ":" . $port;
		} else {
			$urlport = "";
		}
	}
	$http_host = $_SERVER['SERVER_NAME'];
	$urlhost = $http_host;
	// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
	if($title == "Reload in progress") {
		if (is_ipaddr($urlhost)) {
			$host_if = find_ip_interface($urlhost);
			if ($host_if) {
				$host_if = convert_real_interface_to_friendly_interface_name($host_if);
				if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr']))
					$urlhost = $config['interfaces'][$host_if]['ipaddr'];
			}
		} else if ($urlhost == $config['system']['hostname'])
			$urlhost = $config['wizardtemp']['system']['hostname'];
		else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain'])
			$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
	}
1007 1008 1009
	if ($urlhost != $http_host) {
		file_put_contents('/tmp/setupwizard_lastreferrer', $proto . '://' . $http_host . $urlport . $_SERVER['REQUEST_URI']);
	}
Ad Schellevis's avatar
Ad Schellevis committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
	$myurl = $proto . "://" . $urlhost . $urlport . "/";

	if (strstr($newstring, "\$myurl"))
		$newstring = str_replace("\$myurl", $myurl, $newstring);
	// fixup #2: $wanip
	if (strstr($newstring, "\$wanip")) {
		$curwanip = get_interface_ip();
		$newstring = str_replace("\$wanip", $curwanip, $newstring);
	}
	// fixup #3: $lanip
	if (strstr($newstring, "\$lanip")) {
		$lanip = get_interface_ip("lan");
		$newstring = str_replace("\$lanip", $lanip, $newstring);
	}
	// fixup #4: fix'r'up here.
	return $newstring;
}

function is_timezone($elt) {
	return !preg_match("/\/$/", $elt);
}

?>

1034
<?php include('foot.inc'); ?>