<?xml version="1.0" encoding="utf-8" ?>
<pfsensewizard>
<copyright>
/*
 * setup_wizard.xml
 *
 * part of pfSense (https://www.pfsense.org)
 * Copyright (c) 2004-2013 BSD Perimeter
 * Copyright (c) 2013-2016 Electric Sheep Fencing
 * Copyright (c) 2014-2021 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.
 */
</copyright>
<totalsteps>10</totalsteps>
<step>
	<id>1</id>
	<title>pfSense Setup</title>
	<disableheader>true</disableheader>
	<description>
		<![CDATA[
		<p><h4>Welcome to pfSense® software!</h4></p>
		<p>This wizard will provide guidance through the initial configuration of pfSense.</p>
		<p>The wizard may be stopped at any time by clicking the logo image at the top of the screen.</p>
		<p><strong>pfSense® software is developed and maintained by Netgate®<strong></p>
		<br />
		<p><a href="https://www.netgate.com/pfw1" class="btn btn-info" target="_blank">Learn more</a></p>
		]]>
	</description>
	<fields>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
	<stepbeforeformdisplay>
		unlink_if_exists("{$g['conf_path']}/trigger_initial_wizard");
		unlink_if_exists("{$g['conf_path']}/assign_complete");
	</stepbeforeformdisplay>
</step>
<step>
	<id>2</id>
	<title>Netgate® Global Support is available 24/7</title>
	<disableheader>true</disableheader>
	<description>
	<![CDATA[
		<p>Our 24/7 worldwide team of support engineers are the most qualified to diagnose your issue and resolve it quickly, from branch office to enterprise — on premises to cloud.</p>
		<p>We offer several support subscription plans tailored to fit different environment sizes and requirements. Many companies around the world choose Netgate support because:</p>
		<p>
		<ul>
			<li>Support is available 24 hours a day, seven days a week, including holidays.</li>
			<li>Support engineers are located around the world, ensuring that no support call is missed.</li>
			<li>Our support engineers hold many prestigious network engineer certificates and have years of hands-on experience with networking.</li>
		</ul>
		</p>
		<br />
		<p><a href="https://www.netgate.com/pfw2" class="btn btn-info" target="_blank">Learn more</a></p>
    ]]>
  </description>
	<fields>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
</step>
<step>
	<id>3</id>
	<title>General Information</title>
	<description>On this screen the general pfSense parameters will be set.</description>
	<fields>
		<field>
			<name>Hostname</name>
			<type>input</type>
			<bindstofield>wizardtemp->system->hostname</bindstofield>
			<description>EXAMPLE: myserver</description>
			<validate>^[a-zA-Z0-9-]+$</validate>
			<message>Invalid Hostname</message>
		</field>
		<field>
			<name>Domain</name>
			<type>input</type>
			<bindstofield>wizardtemp->system->domain</bindstofield>
			<description>EXAMPLE: mydomain.com</description>
			<validate>^[a-zA-Z0-9.-]+$</validate>
			<message>Domain name field is invalid</message>
		</field>
		<field>
			<name>DNS Resolver Behavior</name>
			<type>text</type>
			<description>The default behavior of the DNS Resolver will ignore manually configured DNS servers for client queries and query root DNS servers directly. To use the manually configured DNS servers below for client queries, visit Services &gt; DNS Resolver and enable DNS Query Forwarding after completing the wizard.</description>
		</field>
		<field>
			<name>Primary DNS Server</name>
			<type>input</type>
			<bindstofield>system->dnsserver</bindstofield>
			<!-- we must unset the fields because this is an array. -->
			<unsetfield>yes</unsetfield>
			<arraynum>0</arraynum>
			<validate>^$|^(?:((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|([0-9a-f:]{3,39}|[0-9a-f:]{2,30}[0-9.]{7,15}))$</validate>
			<message>Primary DNS Server field is invalid</message>
		</field>
		<field>
			<name>Secondary DNS Server</name>
			<type>input</type>
			<bindstofield>system->dnsserver</bindstofield>
			<arraynum>1</arraynum>
			<validate>^$|^(?:((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|([0-9a-f:]{3,39}|[0-9a-f:]{2,30}[0-9.]{7,15}))$</validate>
			<message>Secondary DNS Server field is invalid</message>
		</field>
		<field>
			<name>Override DNS</name>
			<description>Allow DNS servers to be overridden by DHCP/PPP on WAN</description>
			<type>checkbox</type>
			<bindstofield>system->dnsallowoverride</bindstofield>
		</field>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
	<stepbeforeformdisplay>
		<![CDATA[
		init_config_arr(array('wizardtemp', 'system'));
		$config['wizardtemp']['system']['hostname'] = $config['system']['hostname'];
		$config['wizardtemp']['system']['domain'] = $config['system']['domain'];
		]]>
	</stepbeforeformdisplay>
	<stepsubmitphpaction>
		<![CDATA[
		if (empty($_POST['hostname']) || !is_unqualified_hostname($_POST['hostname'])) {
			include("head.inc");
			$input_errors[] = "Hostname is invalid. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (empty($_POST['domain']) || !is_domain($_POST['domain'])) {
			include("head.inc");
			$input_errors[] = "Domain is invalid. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (!empty($_POST['primarydnsserver']) && !is_ipaddr($_POST['primarydnsserver'])) {
			include("head.inc");
			$input_errors[] = "Primary DNS server is invalid. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (!empty($_POST['secondarydnsserver']) && !is_ipaddr($_POST['secondarydnsserver'])) {
			include("head.inc");
			$input_errors[] = "Second DNS server is invalid. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		]]>
	</stepsubmitphpaction>
</step>
<step>
	<id>4</id>
	<title>Time Server Information</title>
	<description>Please enter the time, date and time zone.</description>
	<fields>
		<field>
			<name>Time server hostname</name>
			<description>Enter the hostname (FQDN) of the time server.</description>
			<type>input</type>
			<bindstofield>system->timeservers</bindstofield>
		</field>
		<field>
			<name>Timezone</name>
			<type>timezone_select</type>
			<bindstofield>system->timezone</bindstofield>
		</field>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
	<stepsubmitphpaction>
		<![CDATA[
		foreach (explode(' ', $_POST['timeserverhostname']) as $ts) {
			if (!is_domain($ts)) {
				$input_errors[] = gettext("NTP Time Server names may only contain the characters a-z, 0-9, '-' and '.'. Entries may be separated by spaces. Please press back in the browser window and correct.");
				print_input_errors($input_errors);
				include("foot.inc");
				die;
			}
		}
		]]>
	</stepsubmitphpaction>
</step>
<step>
	<id>5</id>
	<skip_flavors>ec2,ec2-ic</skip_flavors>
	<disableallfieldsbydefault>true</disableallfieldsbydefault>
	<title>Configure WAN Interface</title>
	<description>On this screen the Wide Area Network information will be configured.</description>
	<javascriptafterformdisplay>
		var selectedItem = 0;
		if (document.forms[0].ipaddress.value == 'dhcp') {
			selectedItem = 1;
			document.forms[0].ipaddress.value = '';
		} else if (document.forms[0].ipaddress.value == 'pppoe') {
			selectedItem = 2;
			document.forms[0].ipaddress.value = '';
		} else if (document.forms[0].ipaddress.value == 'pptp') {
			selectedItem = 3;
			document.forms[0].ipaddress.value = '';
		} else if (document.forms[0].ipaddress.value == 'ppp' || document.forms[0].ipaddress.value == 'l2tp') {
			document.forms[0].ipaddress.value = '';
		} else {
			selectedItem = 0;
		}
		document.forms[0].selectedtype.selectedIndex = selectedItem;
		enableitems(selectedItem);

		events.push(function(){
			$('#showpppoepassword').click(function(event) {
				if (this.checked) {
					$('#pppoepassword').attr('type', 'text');
				} else {
					$('#pppoepassword').attr('type', 'password');
				}
			});

			$('#showpptppassword').click(function(event) {
				if (this.checked) {
					$('#pptppassword').attr('type', 'text');
				} else {
					$('#pptppassword').attr('type', 'password');
				}
			});
		});

	</javascriptafterformdisplay>
	<fields>
		<field>
			<name>SelectedType</name>
			<type>select</type>
			<donotdisable>true</donotdisable>
			<options>
				<option>
					<name>Static</name>
					<value>Static</value>
					<enablefields>ipaddress,subnetmask,upstreamgateway</enablefields>
				</option>
				<option>
					<name>DHCP</name>
					<value>dhcp</value>
					<enablefields>dhcphostname</enablefields>
				</option>
				<option>
					<name>PPPoE</name>
					<value>pppoe</value>
					<enablefields>pppoeusername,pppoepassword,pppoeservicename,pppoedialondemand,pppoeidletimeout,showpppoepassword</enablefields>
				</option>
				<option>
					<name>PPTP</name>
					<value>pptp</value>
					<enablefields>pptpusername,pptppassword,pptplocalipaddress,pptplocalsubnet,pptpremoteipaddress,pptpdialondemand,pptpidletimeout,showpptppassword
					</enablefields>
				</option>
			</options>
		</field>
		<field>
			<name>General configuration</name>
			<type>listtopic</type>
		</field>
		<field>
			<donotdisable>true</donotdisable>
			<name>MAC Address</name>
			<bindstofield>interfaces->wan->spoofmac</bindstofield>
			<type>input</type>
			<description> This field can be used to modify ("spoof") the MAC address of the WAN interface (may be required with some cable connections). Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx or leave blank.</description>
			<validate>^([0-9a-f]{2}([:-]||$)){6}$</validate>
			<message>MAC Address field is invalid</message>
		</field>
		<field>
			<donotdisable>true</donotdisable>
			<name>MTU</name>
			<type>input</type>
			<bindstofield>interfaces->wan->mtu</bindstofield>
			<description> Set the MTU of the WAN interface. If this field is left blank, an MTU of 1492 bytes for PPPoE and 1500 bytes for all other connection types will be assumed.</description>
		</field>
		<field>
			<donotdisable>true</donotdisable>
			<name>MSS</name>
			<type>input</type>
			<bindstofield>interfaces->wan->mss</bindstofield>
			<description> If a value is entered in this field, then MSS clamping for TCP connections to the value entered above minus 40 (TCP/IP header size) will be in effect. If this field is left blank, an MSS of 1492 bytes for PPPoE and 1500 bytes for all other connection types will be assumed. This should match the above MTU value in most all cases.</description>
		</field>
		<field>
			<name>Static IP Configuration</name>
			<type>listtopic</type>
		</field>
		<field>
			<name>IP Address</name>
			<bindstofield>interfaces->wan->ipaddr</bindstofield>
			<type>input</type>
			<typehint> / </typehint>
			<combinefieldsbegin>true</combinefieldsbegin>
			<validate>^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$</validate>
			<message>IP Address field is invalid</message>
		</field>
		<field>
			<combinefieldsend>true</combinefieldsend>
			<dontdisplayname>true</dontdisplayname>
			<dontcombinecells>true</dontcombinecells>
			<name>Subnet Mask</name>
			<bindstofield>interfaces->wan->subnet</bindstofield>
			<type>subnet_select</type>
		</field>
		<field>
			<name>Upstream Gateway</name>
			<bindstofield>wizardtemp->wangateway</bindstofield>
			<type>input</type>
			<validate>^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$</validate>
			<message>Gateway IP Address field is invalid</message>
		</field>
		<field>
			<name>DHCP client configuration</name>
			<type>listtopic</type>
		</field>
		<field>
			<name>DHCP Hostname</name>
			<type>input</type>
			<bindstofield>interfaces->wan->dhcphostname</bindstofield>
			<description> The value in this field is sent as the DHCP client identifier and hostname when requesting a DHCP lease. Some ISPs may require this (for client identification).</description>
		</field>
		<field>
			<name>PPPoE configuration</name>
			<type>listtopic</type>
		</field>
		<field>
			<name>PPPoE Username</name>
			<type>input</type>
			<bindstofield>wizardtemp->wan->username</bindstofield>
		</field>
		<field>
			<name>PPPoE Password</name>
			<type>password</type>
			<bindstofield>wizardtemp->wan->password</bindstofield>
		</field>
		<field>
			<name>Show PPPoE password</name>
			<type>checkbox</type>
			<typehint>Reveal password characters</typehint>
		</field>
		<field>
			<name>PPPoE Service name</name>
			<type>input</type>
			<description>Hint: this field can usually be left empty</description>
			<bindstofield>wizardtemp->wan->provider</bindstofield>
		</field>
		<field>
			<name>PPPoE Dial on demand</name>
			<typehint>Enable Dial-On-Demand mode</typehint>
			<type>checkbox</type>
			<description>This option causes the interface to operate in dial-on-demand mode, allowing a virtual full time connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.</description>
			<bindstofield>wizardtemp->wan->ondemand</bindstofield>
		</field>
		<field>
			<name>PPPoE Idle timeout</name>
			<type>input</type>
			<description>If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. An idle timeout of zero disables this feature.</description>
			<bindstofield>wizardtemp->wan->idletimeout</bindstofield>
		</field>
		<field>
			<name>PPTP configuration</name>
			<type>listtopic</type>
		</field>
		<field>
			<name>PPTP Username</name>
			<type>input</type>
			<bindstofield>wizardtemp->wan->pptpusername</bindstofield>
		</field>
		<field>
			<name>PPTP Password</name>
			<type>password</type>
			<bindstofield>wizardtemp->wan->pptppassword</bindstofield>
		</field>
		<field>
			<name>Show PPTP password</name>
			<type>checkbox</type>
			<typehint>Reveal password characters</typehint>
		</field>
		<field>
			<combinefieldsbegin>true</combinefieldsbegin>
			<name>PPTP Local IP Address</name>
			<type>input</type>
			<typehint> / </typehint>
			<bindstofield>wizardtemp->wan->localip</bindstofield>
			<validate>^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$</validate>
			<message>PPTP Local IP Address field is invalid</message>
		</field>
		<field>
			<combinefieldsend>true</combinefieldsend>
			<dontdisplayname>true</dontdisplayname>
			<dontcombinecells>true</dontcombinecells>
			<name>pptplocalsubnet</name>
			<bindstofield>wizardtemp->wan->subnet</bindstofield>
			<type>subnet_select</type>
		</field>
		<field>
			<name>PPTP Remote IP Address</name>
			<bindstofield>wizardtemp->wan->gateway</bindstofield>
			<type>input</type>
			<validate>^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$</validate>
			<message>PPTP Remote IP Address field is invalid</message>
		</field>
		<field>
			<name>PPTP Dial on demand</name>
			<typehint>Enable Dial-On-Demand mode</typehint>
			<type>checkbox</type>
			<bindstofield>wizardtemp->wan->pptpondemand</bindstofield>
			<description>This option causes the interface to operate in dial-on-demand mode, allowing a virtual full time connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.</description>
		</field>
		<field>
			<name>PPTP Idle timeout</name>
			<type>input</type>
			<bindstofield>wizardtemp->wan->pptpidletimeout</bindstofield>
			<description>If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. An idle timeout of zero disables this feature.</description>
		</field>
		<field>
			<name>RFC1918 Networks</name>
			<type>listtopic</type>
		</field>
		<field>
			<donotdisable>true</donotdisable>
			<name>Block RFC1918 Private Networks</name>
			<description> When set, this option blocks traffic from IP addresses that are reserved for private networks as per RFC 1918 (10/8, 172.16/12, 192.168/16) as well as loopback addresses (127/8). This option should generally be left turned on, unless the WAN network lies in such a private address space, too.</description>
			<type>checkbox</type>
			<bindstofield>interfaces->wan->blockpriv</bindstofield>
			<typehint>Block private networks from entering via WAN</typehint>
		</field>
		<field>
			<name>Block bogon networks</name>
			<type>listtopic</type>
		</field>
		<field>
			<donotdisable>true</donotdisable>
			<name>Block bogon networks</name>
			<description>When set, this option blocks traffic from IP addresses that are reserved (but not RFC 1918) or not yet assigned by IANA. Bogons are prefixes that should never appear in the Internet routing table, and obviously should not appear as the source address in any packets received.</description>
			<type>checkbox</type>
			<bindstofield>interfaces->wan->blockbogons</bindstofield>
			<typehint>Block non-Internet routed networks from entering via WAN</typehint>
		</field>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
	<stepbeforeformdisplay>
		<![CDATA[
		if (empty($config['interfaces']['wan']['gateway'])) {
			$wangw_name = "WANGW";
		} else {
			$wangw_name = $config['interfaces']['wan']['gateway'];
		}
		if (is_array($config['gateways']['gateway_item']))
			foreach ($config['gateways']['gateway_item'] as $gw)
				if ($gw['name'] == $wangw_name || (!empty($config['wizardtemp']['wangateway']) && $gw['gateway'] == $config['wizardtemp']['wangateway']))
					$config['wizardtemp']['wangateway'] = $gw['gateway'];
		]]>
	</stepbeforeformdisplay>
	<stepsubmitphpaction>
		<![CDATA[
		if (!empty($_POST['mtu']) && ($_POST['mtu'] < 576)) {
			include("head.inc");
			$input_errors[] = "MTU Must be at least 576 (Per RFC 791). Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (!empty($_POST['macaddress']) && !is_macaddr($_POST['macaddress'])) {
			include("head.inc");
			$input_errors[] = "Invalid MAC Address. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (!empty($_POST['ipaddress']) && ($_POST['selectedtype'] == "Static")) {
			if (!is_ipaddr($_POST['ipaddress'])) {
				include("head.inc");
				$input_errors[] = "Invalid WAN IP Address. Please press back in the browser window and correct.";
				print_input_errors($input_errors);
				include("foot.inc");
				die;
			}
			if ($_POST['subnetmask'] < 31 &&
			    ($_POST['ipaddress'] == gen_subnet($_POST['ipaddress'], $_POST['subnetmask']) ||
			     $_POST['ipaddress'] == gen_subnet_max($_POST['ipaddress'], $_POST['subnetmask']))) {
			    include("head.inc");
				$input_errors[] = "Invalid WAN IP Address. Please press back in the browser window and correct.";
				print_input_errors($input_errors);
				include("foot.inc");
				die;
			}
		}
		if (!empty($_POST['dhcphostname']) && !is_hostname($_POST['dhcphostname'])) {
			include("head.inc");
			$input_errors[] = "Invalid DHCP Hostname. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (!empty($_POST['pptplocalipaddress']) && !is_ipaddr($_POST['pptplocalipaddress'])) {
		    include("head.inc");
			$input_errors[] = "Invalid PPTP Local IP Address. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		if (!empty($_POST['pptpremoteipaddress']) && !is_ipaddr($_POST['pptpremoteipaddress'])) {
			include("head.inc");
			$input_errors[] = "Invalid PPTP Remote IP Address. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}
		$type = $_POST['selectedtype'];

		init_config_arr(array('ppps', 'ppp'));
		if (count($config['ppps']['ppp'])) {
			foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
				if ($ppp['ptpid'] == "0") {
					if ((substr($config['interfaces']['wan']['if'],0,5) == "pppoe") || (substr($config['interfaces']['wan']['if'],0,4) == "pptp")) {
						$oldif = explode(",", $ppp['ports']);
						$config['interfaces']['wan']['if'] = $oldif[0];
					}
					if ($type == "pppoe" || $type == "pptp")
						unset($config['ppps']['ppp'][$pppid]);
				}
			}
		}

		if ($type == "pppoe" || $type == "pptp") {
			if ($type == "pptp") {
				$config['wizardtemp']['wan']['username'] = $config['wizardtemp']['wan']['pptpusername'];
				$config['wizardtemp']['wan']['password'] = $config['wizardtemp']['wan']['pptppassword'];
				$config['wizardtemp']['wan']['ondemand'] = $config['wizardtemp']['wan']['pptpondemand'];
				$config['wizardtemp']['wan']['idletimeout'] = $config['wizardtemp']['wan']['pptpidletimeout'];
				unset($config['wizardtemp']['wan']['pptpusername']);
				unset($config['wizardtemp']['wan']['pptppassword']);
				unset($config['wizardtemp']['wan']['pptpondemand']);
				unset($config['wizardtemp']['wan']['pptpidletimeout']);
			}
			$config['wizardtemp']['wan']['password'] = base64_encode($config['wizardtemp']['wan']['password']);
			$tmp = array();
			$tmp['ptpid'] = "0";
			$tmp['type'] = $type;
			$tmp['if'] = $type . "0";
			$tmp['ports'] = $config['interfaces']['wan']['if'];
			$config['ppps']['ppp'][] = array_merge($tmp, $config['wizardtemp']['wan']);
			unset($tmp);
			$config['interfaces']['wan']['if'] = $type."0";
		}
		unset($config['wizardtemp']['wan']);
		]]>
	</stepsubmitphpaction>
	<stepsubmitbeforesave>
		<![CDATA[
			if ($_POST['selectedtype'] == "Static") {

			} else {
				$_POST['ipaddress'] = $_POST['selectedtype'];
				$config['interfaces']['wan']['ipaddr'] = $_POST['selectedtype'];
				write_config(gettext("WAN interface configuration saved via pfSense setup wizard."));
			}
			if (!$config['interfaces']['lan']) {
				header("Location: /wizard.php?xml=setup_wizard.xml&stepid=6&next=Next");
			}
		]]>
	</stepsubmitbeforesave>
</step>
<step>
	<id>6</id>
	<skip_flavors>ec2,ec2-ic</skip_flavors>
	<title>Configure LAN Interface</title>
	<description>On this screen the Local Area Network information will be configured.</description>
	<fields>
		<field>
			<name>LAN IP Address</name>
			<type>input</type>
			<bindstofield>interfaces->lan->ipaddr</bindstofield>
			<description>Type dhcp if this interface uses DHCP to obtain its IP address.</description>
			<validate>^(dhcp|DHCP|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))$</validate>

			<message>LAN IP Address field is invalid</message>
		</field>
				<field>
			<name>Subnet Mask</name>
			<type>subnet_select</type>
			<bindstofield>interfaces->lan->subnet</bindstofield>
		</field>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
	<stepsubmitbeforesave>
		<![CDATA[
		/*
		 * Store the old LAN IP address so it doesn't trip up the security checks
		 * between the time it is saved here and applied at the end of the wizard.
		 * See https://redmine.pfsense.org/issues/8524
		 */
		$althosts_before = $config['system']['webgui']['althostnames'];
		$althosts = explode(' ', $config['system']['webgui']['althostnames']);
		$althosts[] = get_interface_ip('lan');
		$config['system']['webgui']['althostnames'] = implode(' ', $althosts);
		]]>
	</stepsubmitbeforesave>
	<stepsubmitphpaction>
		<![CDATA[
		if (empty($_POST['lanipaddress']) || (!is_ipaddr($_POST['lanipaddress']) && (strtolower($_POST['lanipaddress']) != "dhcp"))) {
			print_info_box("Invalid LAN IP address. Please press back in the browser window and correct.");
			die;
		}

		$lowestip = gen_subnet($_POST['lanipaddress'], $_POST['subnetmask']);
		$highestip = gen_subnet_max($_POST['lanipaddress'], $_POST['subnetmask']);

		if ($_POST['subnetmask'] < 31) {
			if ($_POST['lanipaddress'] == $lowestip) {
				include("head.inc");
				$input_errors[] = "LAN IP Address equals subnet network address. This is not allowed. Please press back in the browser window and correct.";
				print_input_errors($input_errors);
				include("foot.inc");
				die;
			}
			if ($_POST['lanipaddress'] == $highestip) {
				include("head.inc");
				$input_errors[] = "LAN IP Address equals subnet broadcast address. This is not allowed. Please press back in the browser window and correct.";
				print_input_errors($input_errors);
				include("foot.inc");
				die;
			}
		} else {
			include("head.inc");
			$input_errors[] = "Invalid subnet mask, choose a mask less than 31. Please press back in the browser window and correct.";
			print_input_errors($input_errors);
			include("foot.inc");
			die;
		}

		/*
		   If the existing DHCP range on LAN is not in the new subnet or
		   is invalid, then replace the range with a newly crafted one.
		*/
		init_config_arr(array('dhcpd', 'lan', 'range', 'from'));
		init_config_arr(array('dhcpd', 'lan', 'range', 'to'));
		if (!ip_in_subnet($config['dhcpd']['lan']['range']['from'], "{$_POST['lanipaddress']}/{$_POST['subnetmask']}") ||
		    !ip_in_subnet($config['dhcpd']['lan']['range']['to'], "{$_POST['lanipaddress']}/{$_POST['subnetmask']}")) {

			$ipaddresses_before = ip_range_size_v4($lowestip, $_POST['lanipaddress']);
			$ipaddresses_after = ip_range_size_v4($_POST['lanipaddress'], $highestip);
			if ($ipaddresses_after >= $ipaddresses_before) {
				// The LAN IP is in the 1st half of the subnet, so put DHCP in the 2nd half.
				if ($ipaddresses_after > 30) {
					// There is reasonable space in the subnet, use a smaller chunk of the space for DHCP
					// This case will work out like the old defaults if the user has specified the ".1" address.
					// The range will be something like ".10" to ".245"
					$config['dhcpd']['lan']['range']['from'] = ip_after($_POST['lanipaddress'], 9);
					$config['dhcpd']['lan']['range']['to'] = ip_before($highestip, 10);
				} else {
					// There is not much space in the subnet, so allocate everything above the LAN IP to DHCP.
					$config['dhcpd']['lan']['range']['from'] = ip_after($_POST['lanipaddress']);
					$config['dhcpd']['lan']['range']['to'] = ip_before($highestip);
				}
			} else {
				// The LAN IP is in the 2nd half of the subnet, so put DHCP in the 1st half.
				if ($ipaddresses_before > 30) {
					// There is reasonable space in the subnet, use a smaller chunk of the space for DHCP
					$config['dhcpd']['lan']['range']['from'] = ip_after($lowestip, 10);
					$config['dhcpd']['lan']['range']['to'] = ip_before($_POST['lanipaddress'], 9);
				} else {
					// There is not much space in the subnet, so allocate everything below the LAN IP to DHCP.
					$config['dhcpd']['lan']['range']['from'] = ip_after($lowestip);
					$config['dhcpd']['lan']['range']['to'] = ip_before($_POST['lanipaddress']);
				}
			}
		}
		]]>
	</stepsubmitphpaction>
</step>
<step>
	<id>7</id>
	<title>Set Admin WebGUI Password</title>
	<description>On this screen the admin password will be set, which is used to access the WebGUI and also SSH services if enabled.</description>
	<fields>
		<field>
			<name>Admin Password</name>
			<type>password</type>
		</field>
		<field>
			<name>Admin Password AGAIN</name>
			<type>password</type>
		</field>
		<field>
			<name>Next</name>
			<type>submit</type>
		</field>
	</fields>
	<stepsubmitphpaction>
	<![CDATA[
	if ($_POST['adminpassword'] != "") {
		if ($_POST['adminpassword'] == $_POST['adminpasswordagain']) {
			$admin_user =& getUserEntryByUID(0);
			local_user_set_password($admin_user, $_POST['adminpassword']);
			local_user_set($admin_user);
			write_config(gettext("Admin WebGUI password saved via pfSense setup wizard."));
		} else {
			print_info_box("Passwords do not match! Please press back in the browser window and correct.");
			die;
		}
	}
	]]>
	</stepsubmitphpaction>
</step>
<step>
	<id>8</id>
	<title>Reload configuration</title>
	<disableheader>true</disableheader>
	<description>Click 'Reload' to reload pfSense with new changes.</description>
	<fields>
		<field>
			<name>Reload</name>
			<type>submit</type>
		</field>
	</fields>
</step>
<step>
	<id>9</id>
	<title>Reload in progress</title>
	<description>
		A reload is now in progress.  Please wait. &lt;p&gt;
		&lt;meta http-equiv="refresh" content="5; url=wizard.php?xml=setup_wizard.xml&amp;stepid=9" &gt;
		&lt;p&gt;
		The wizard will redirect to the next step once the reload is completed.
	</description>
	<stepafterformdisplay>
		<![CDATA[
		$config['system']['hostname'] = $config['wizardtemp']['system']['hostname'];
		$config['system']['domain'] = $config['wizardtemp']['system']['domain'];
		if (!empty($config['wizardtemp']['wangateway'])) {
			init_config_arr(array('gateways', 'gateway_item'));
			$found = false;
			$defaultgw_found = false;
			foreach ($config['gateways']['gateway_item'] as & $gw) {
				if ($gw['interface'] != "wan")
					continue;
				if (isset($gw['defaultgw']))
					$defaultgw_found = true;
				if ($gw['name'] == 'WANGW' || (!empty($config['wizardtemp']['wangateway']) && $gw['gateway'] == $config['wizardtemp']['wangateway'])) {
					$found = true;
					$gw['gateway'] = $config['wizardtemp']['wangateway'];
					$config['interfaces']['wan']['gateway'] = $gw['name'];
				}
			}
			if (!$found) {
				$newgw = array();
				$newgw['interface'] = "wan";
				$newgw['gateway'] = $config['wizardtemp']['wangateway'];
				$newgw['name'] = "WANGW";
				$newgw['weight'] = 1;
				$newgw['descr'] = "WAN Gateway";
				$newgw['defaultgw'] = !$defaultgw_found;
				$config['gateways']['gateway_item'][] = $newgw;
				$config['interfaces']['wan']['gateway'] = "WANGW";
			}
		}
		unset($config['wizardtemp']);
		/* See https://redmine.pfsense.org/issues/8524 */
		$config['system']['webgui']['althostnames'] = $althosts_before;
		write_config(gettext("Configuration saved on completion of the pfSense setup wizard."));
		reload_all();
		mwexec_bg("/etc/rc.update_bogons.sh now");
		touch("{$g['cf_conf_path']}/copynotice_display");
		]]>
	</stepafterformdisplay>
</step>
<step>
	<id>10</id>
	<title>Wizard completed.</title>
	<stepbeforeformdisplay>
	<![CDATA[
		if ($g['product_name'] <> 'pfSense') {
			header("Location: " . fixup_string("\$myurl"));
			exit;
		}
	]]>
	</stepbeforeformdisplay>
	<description>
	<![CDATA[
	<div style="padding-right:25px;">
		<p><h4>Congratulations! pfSense is now configured.</h4></p>
		<p>
		We recommend that you check to see if there are any software updates available. Keeping your software up to date is
		one of the most important things you can do to maintain the security of your network.</p>
		<input type="button" onclick="window.location.href='$myurlpkg_mgr_install.php?id=firmware'" class="btn btn-xs btn-success" value="Check for updates"/>
		</br></br>
		<p><h4>Remember, we're here to help.</h4></p>
		<p><a target='_blank' href='https://www.netgate.com/pfw2'><strong><span style="font-size:16px">Click here</span></strong></a> to learn about Netgate 24/7/365 support services.</p>
		<br />
		<p><h4>User survey</h4></p>
		<p>Please help all the people involved in improving and expanding pfSense software by taking a moment to answer this short survey (all answers are anonymous)<br />
		<a href="https://redirects.netgate.com/survey_1" target="_blank"><strong><span style="font-size:16px">Anonymous User Survey</span></a></p>
		<br />
		<p><h4>Useful resources.</h4></p>
		<p>
			<ul>
				<li>Learn more about Netgate's product line, services, and pfSense software from our <a target='_blank' href='https://www.netgate.com/pfw3'>website</a></li>
				<li>To learn about Netgate appliances and other offers, <a target='_blank' href='https://www.netgate.com/pfw4'>visit our store</a></li>
				<li>Become part of the pfSense community. Visit our <a target='_blank' href='https://www.netgate.com/pfw5'>forum</a></li>
				<li>Subscribe to our <a target='_blank' href='https://www.netgate.com/pfw6'>newsletter</a> for ongoing product information, software announcements and special offers.</li>
			</ul>
		</p>
		</br>
		<input type="button" onclick="window.location.href='$myurl'" class="btn btn-sm btn-primary" value="Finish"/>
		</p>
	</div>
	]]>
	</description>
</step>
</pfsensewizard>
