$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);
$pgtitle = array(gettext("Wizard"), gettext($pkg['step'][0]['title'])); //First step is main title of the wizard in the breadcrumb
$pgtitle[] = ($stepid > 0 ? gettext($pkg['step'][$stepid]['title']):' '); //Following steps are sub-level breadcrumbs.
$shortcut_section = "Wizard";
include("head.inc");
if ($pkg['step'][$stepid]['fields']['field'] != "") { ?>
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'];
}
}
if ($urlhost != $http_host) {
file_put_contents("{$g['tmp_path']}/setupwizard_lastreferrer", $proto . "://" . $http_host . $urlport . $_SERVER['REQUEST_URI']);
}
$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);
}
if ($title == "Reload in progress") {
$ip = fixup_string("\$myurl");
} else {
$ip = "/";
}
if ($input_errors) {
print_input_errors($input_errors);
}
if ($savemsg) {
print_info_box($savemsg, 'success');
}
if ($_GET['message'] != "") {
print_info_box(htmlspecialchars($_GET['message']));
}
if ($_POST['message'] != "") {
print_info_box(htmlspecialchars($_POST['message']));
}
$completion = ($stepid == 0) ? 0:($stepid * 100) / ($totalsteps -1);
?>
![logo-black](logo-black.png)
addGlobal(new Form_Input(
'stepid',
null,
'hidden',
$stepid
));
$form->addGlobal(new Form_Input(
'xml',
null,
'hidden',
$xml
));
$section = new Form_Section(fixup_string($title));
if ($description) {
$section->addInput(new Form_StaticText(
null,
fixup_string($description)
));
}
$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 (DEBUG) {
print('Step: ' . $pkg['step'][$stepid]['id'] . ', Field: ' . $field['type'] . ', Name: ' . $name . '
');
}
switch ($field['type']) {
case "input":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
$section->addInput(new Form_Input(
$name,
$etitle,
'text',
$value
))->setHelp($field['description'])
->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
break;
case "text":
$section->addInput(new Form_StaticText(
null,
$field['description']
));
break;
case "inputalias":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
$onchange = "";
if ($field['validate']) {
$onchange="FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")";
}
$section->addInput(new Form_Input(
$name,
$etitle,
'text',
$value
))->setAttribute('autocomplete', 'off')
->setOnchange($onchange)
->setHelp($field['description']);
break;
case "interfaces_selection":
case "interface_select":
$name = strtolower($name);
$options = array();
$selected = array();
$etitle = (fixup_string($field['displayname'])) ? $field['displayname'] : $field['name'];
if (($field['multiple'] != "") && ($field['multiple'] != "0")) {
$multiple = true;
} else {
$multiple = false;
}
if ($field['add_to_interfaces_selection'] != "") {
if ($field['add_to_interfaces_selection'] == $value) {
array_push($selected, $value);
}
$options[$field['add_to_interfaces_selection']] = $field['add_to_interfaces_selection'];
}
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']})";
}
}
if ($value == $ifname) {
array_push($selected, $value);
}
$canecho = 0;
if ($field['interface_filter'] != "") {
if (stristr($ifname, $field['interface_filter']) == true) {
$canecho = 1;
}
} else {
$canecho = 1;
}
if ($canecho == 1) {
$options[$ifname] = $iface;
}
}
$section->addInput(new Form_Select(
$name,
$etitle,
($multiple) ? $selected:$selected[0],
$options,
$multiple
))->setHelp($field['description']);
break;
case "password":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
$section->addInput(new Form_Input(
$name,
$etitle,
'password',
$value
))->setHelp($field['description'])
->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] ."\")":"");
break;
case "certca_selection":
$options = array();
$selected = "";
$name = strtolower($name);
$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
if ($field['add_to_certca_selection'] != "") {
if ($field['add_to_certca_selection'] == $value) {
$selected = $value;
}
$options[$field['add_to_certca_selection']] = $field['add_to_certca_selection'];
}
foreach ($config['ca'] as $ca) {
$caname = htmlspecialchars($ca['descr']);
if ($value == $caname) {
$selected = $value;
}
$canecho = 0;
if ($field['certca_filter'] != "") {
if (stristr($caname, $field['certca_filter']) == true) {
$canecho = 1;
}
} else {
$canecho = 1;
}
if ($canecho == 1) {
$options[$ca['refid']] = $caname;
}
}
$section->addInput(new Form_Select(
$name,
$etitle,
$selected,
$options
))->setHelp($field['description']);
break;
case "cert_selection":
$options = array();
$selected = array();
$multiple = false;
$name = strtolower($name);
$etitle = (fixup_string($field['displayname']) ? $field['displayname'] : $field['name']);
if ($field['add_to_cert_selection'] != "") {
if ($field['add_to_cert_selection'] == $value) {
array_push($selected, $value);
}
$options[$field['add_to_cert_selection']] = $field['add_to_cert_selection'];
}
foreach ($config['cert'] as $ca) {
if (stristr($ca['descr'], "webconf")) {
continue;
}
$caname = htmlspecialchars($ca['descr']);
if ($value == $caname) {
array_push($selected, $value);
}
$canecho = 0;
if ($field['cert_filter'] != "") {
if (stristr($caname, $field['cert_filter']) == true) {
$canecho = 1;
}
} else {
$canecho = 1;
}
if ($canecho == 1) {
$options[$ca['refid']] = $caname;
}
}
$section->addInput(new Form_Select(
$name,
$etitle,
($multiple) ? $selected:$selected[0],
$options,
$multiple
))->setHelp($field['description']);
break;
case "select":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
if ($field['size']) {
$size = " size='" . $field['size'] . "' ";
}
$multiple = ($field['multiple'] == "yes");
$onchange = "";
foreach ($field['options']['option'] as $opt) {
if ($opt['enablefields'] != "") {
$onchange = "Javascript:enableitems(this.selectedIndex);";
}
}
$options = array();
$selected = array();
foreach ($field['options']['option'] as $opt) {
if ($value == $opt['value']) {
array_push($selected, $value);
}
if ($opt['displayname']) {
$options[$opt['value']] = $opt['displayname'];
} else {
$options[$opt['value']] = $opt['name'];
}
}
$section->addInput(new Form_Select(
$name,
$etitle,
($multiple) ? $selected:$selected[0],
$options,
$multiple
))->setHelp($field['description'])->setOnchange($onchange);
break;
case "textarea":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
$section->addInput(new Form_Textarea(
$name,
$etitle,
$value
))->setHelp($field['description'])
->setAttribute('rows', $field['rows'])
->setOnchange(($field['validate']) ? "FieldValidate(this.value, \"" . $field['validate'] . "\", \"" . $field['message'] . "\")":"");
break;
case "submit":
$form->addGlobal(new Form_Button(
$name,
$field['name']
));
break;
case "listtopic":
$form->add($section);
$section = new Form_Section($field['name']);
break;
case "subnet_select":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else /* if (!$field['dontdisplayname']) */ {
$etitle = fixup_string($field['name']);
}
$section->addInput(new Form_Select(
$name,
$etitle,
$value,
array_combine(range(32, 1, -1), range(32, 1, -1))
))->setHelp($field['description']);
break;
case "timezone_select":
$timezonelist = system_get_timezone_list();
/* kill carriage returns */
for ($x = 0; $x < count($timezonelist); $x++) {
$timezonelist[$x] = str_replace("\n", "", $timezonelist[$x]);
}
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
if (!$field['dontcombinecells']) {
//echo "";
}
$section->addInput(new Form_Select(
$name,
$etitle,
($value == "") ? $g['default_timezone'] : $value,
array_combine($timezonelist, $timezonelist)
))->setHelp($field['description']);
break;
case "checkbox":
if ($field['displayname']) {
$etitle = $field['displayname'];
} else if (!$field['dontdisplayname']) {
$etitle = fixup_string($field['name']);
}
if (isset($field['enablefields']) or isset($field['checkenablefields'])) {
$onclick = "enablechange()";
} else if (isset($field['disablefields']) or isset($field['checkdisablefields'])) {
$onclick = "disablechange()";
}
$section->addInput(new Form_Checkbox(
$name,
$etitle,
$field['typehint'],
($value != ""),
'on'
))->setHelp($field['description'])
->setOnclick($onclick);
break;
} // e-o-switch
} // e-o-foreach(package)
} // e-o- if(we have fields)
$form->add($section);
print($form);
?>
\n";
echo "//\n";
echo "\n\n";
}
?>
\n";
echo "//\n";
echo "\n\n";
}
include("foot.inc");
|