From 9731fe97ea713bc9e379ad55dacda176104fc5f0 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 20 Feb 2025 18:31:37 +0100 Subject: [PATCH] wizard: reimplement system setup, for https://github.com/opnsense/core/issues/8352 --- src/etc/inc/filter.lib.inc | 8 +- src/etc/inc/system.inc | 2 +- .../Core/Api/InitialSetupController.php | 55 + .../OPNsense/Core/InitialSetupController.php | 70 ++ .../Core/forms/wizard_general_info.xml | 68 ++ .../Core/forms/wizard_network_lan.xml | 20 + .../Core/forms/wizard_network_wan.xml | 83 ++ .../Core/forms/wizard_root_password.xml | 13 + .../mvc/app/models/OPNsense/Core/ACL/ACL.xml | 3 +- .../app/models/OPNsense/Core/InitialSetup.php | 371 ++++++ .../app/models/OPNsense/Core/InitialSetup.xml | 100 ++ .../app/models/OPNsense/Core/Menu/Menu.xml | 2 +- .../views/OPNsense/Core/initial_setup.volt | 92 ++ src/opnsense/scripts/system/get_timezones.php | 36 + .../conf/actions.d/actions_system.conf | 7 + src/wizard/system.xml | 658 ----------- src/www/index.php | 2 +- src/www/interfaces.php | 4 +- src/www/javascript/wizard/autosuggest.js | 335 ------ src/www/javascript/wizard/disablekeys.js | 6 - src/www/javascript/wizard/suggestions.js | 33 - src/www/wizard.php | 1014 ----------------- 22 files changed, 926 insertions(+), 2056 deletions(-) create mode 100644 src/opnsense/mvc/app/controllers/OPNsense/Core/Api/InitialSetupController.php create mode 100644 src/opnsense/mvc/app/controllers/OPNsense/Core/InitialSetupController.php create mode 100644 src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_general_info.xml create mode 100644 src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_lan.xml create mode 100644 src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_wan.xml create mode 100644 src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_root_password.xml create mode 100644 src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php create mode 100644 src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.xml create mode 100644 src/opnsense/mvc/app/views/OPNsense/Core/initial_setup.volt create mode 100755 src/opnsense/scripts/system/get_timezones.php delete mode 100644 src/wizard/system.xml delete mode 100644 src/www/javascript/wizard/autosuggest.js delete mode 100644 src/www/javascript/wizard/disablekeys.js delete mode 100644 src/www/javascript/wizard/suggestions.js delete mode 100644 src/www/wizard.php diff --git a/src/etc/inc/filter.lib.inc b/src/etc/inc/filter.lib.inc index e2e7e575adf..123b33f47b4 100644 --- a/src/etc/inc/filter.lib.inc +++ b/src/etc/inc/filter.lib.inc @@ -310,13 +310,13 @@ function filter_core_rules_system($fw, $defaults) ['from' => "", 'direction' => 'in', 'interface' => $intf, 'ipprotocol' => 'inet', 'descr' => "Block bogon IPv4 networks from " . $intfinfo['descr'], '#ref' => "interfaces.php?if=" . $intf . "#blockbogons", - 'disabled' => !isset($intfinfo['blockbogons'])], + 'disabled' => empty($intfinfo['blockbogons'])], $bogontmpl ); $fw->registerFilterRule( 5, ['from' => "", 'direction' => 'in', 'interface' => $intf, 'ipprotocol' => 'inet6', - 'disabled' => $ipv6_disabled || !isset($intfinfo['blockbogons']), + 'disabled' => $ipv6_disabled || empty($intfinfo['blockbogons']), '#ref' => "interfaces.php?if=" . $intf . "#blockbogons", 'descr' => "Block bogon IPv6 networks from " . $intfinfo['descr']], $bogontmpl @@ -326,7 +326,7 @@ function filter_core_rules_system($fw, $defaults) ['direction' => 'in', 'interface' => $intf, 'ipprotocol' => 'inet', '#ref' => "interfaces.php?if=" . $intf . "#blockpriv", 'descr' => "Block private networks from " . $intfinfo['descr'], - 'disabled' => !isset($intfinfo['blockpriv'])], + 'disabled' => empty($intfinfo['blockpriv'])], $privtmpl ); $fw->registerFilterRule( @@ -334,7 +334,7 @@ function filter_core_rules_system($fw, $defaults) ['direction' => 'in', 'interface' => $intf, 'ipprotocol' => 'inet6', '#ref' => "interfaces.php?if=" . $intf . "#blockpriv", 'descr' => "Block private networks from " . $intfinfo['descr'], 'from' => 'fc00::/7', - 'disabled' => $ipv6_disabled || !isset($intfinfo['blockpriv'])], + 'disabled' => $ipv6_disabled || empty($intfinfo['blockpriv'])], $privtmpl ); } diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 16873561e5d..84034929873 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -328,7 +328,7 @@ function get_searchdomains() $master_list[] = $syscfg['dnssearchdomain']; } - if (isset($syscfg['dnsallowoverride'])) { + if (!empty($syscfg['dnsallowoverride'])) { /* return domains as required by configuration */ $list = shell_safe('/usr/local/sbin/ifctl -sl'); if (!empty($list)) { diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/InitialSetupController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/InitialSetupController.php new file mode 100644 index 00000000000..bec155981e8 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/InitialSetupController.php @@ -0,0 +1,55 @@ +getModel()->updateConfig(); + (new Backend())->configdRun("service reload delay", true); + return $result; + } else { + return $result; + } + } +} diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/InitialSetupController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/InitialSetupController.php new file mode 100644 index 00000000000..e9e898aac00 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/InitialSetupController.php @@ -0,0 +1,70 @@ +view->all_tabs = [ + 'step_0' => [ + 'title' => gettext('Welcome'), + 'message' => gettext( + 'This wizard will guide you through the initial system configuration. '. + 'The wizard may be stopped at any time by clicking the logo image at the top of the screen.' + ) + ], + 'step_1' => [ + 'title' => gettext('General Information'), + 'form' => $this->getForm('wizard_general_info') + ], + 'step_2' => [ + 'title' => gettext('Network [WAN]'), + 'form' => $this->getForm('wizard_network_wan') + ], + 'step_3' => [ + 'title' => gettext('Network [LAN]'), + 'form' => $this->getForm('wizard_network_lan') + ], + 'step_4' => [ + 'title' => gettext('Set initial password'), + 'form' => $this->getForm('wizard_root_password') + ], + 'step_final' => [ + 'title' => gettext('Finish'), + 'message' => gettext( + 'This is the last step in the wizard, click apply to reconfigure the firewall.' + ) + ], + ]; + $this->view->pick('OPNsense/Core/initial_setup'); + } +} diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_general_info.xml b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_general_info.xml new file mode 100644 index 00000000000..222c0901065 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_general_info.xml @@ -0,0 +1,68 @@ +
+ + wizard.hostname + + text + + + wizard.domain + + text + + + wizard.language + + dropdown + + + wizard.dns_servers + + select_multiple + + true + Set primary domain name server IPv4 or IPv6 address. Repeat this option to set secondary DNS server addresses. + + + wizard.dnsallowoverride + + checkbox + Allow DNS servers to be overridden by DHCP/PPP on WAN + + + header + + + + wizard.unbound.enabled + + checkbox + + + wizard.unbound.dnssec + + checkbox + + + wizard.unbound.dnssecstripped + + checkbox + DNSSEC data is required for trust-anchored zones. If such data is absent, the zone becomes bogus. If this is disabled and no DNSSEC data is received, then the zone is made insecure. + + + header + + + + wizard.timeservers + + select_multiple + + true + Hostnames of the timeservers to use to acquire time for this firewall. + + + wizard.timezone + + dropdown + +
\ No newline at end of file diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_lan.xml b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_lan.xml new file mode 100644 index 00000000000..7cf40efe7aa --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_lan.xml @@ -0,0 +1,20 @@ +
+ + wizard.interfaces.lan.disable + + checkbox + Disable LAN, usually only relevant in "wan" only scenarios. + + + wizard.interfaces.lan.ipaddr + + text + Ip address and cidr to configure on this interface, e.g. 192.168.1.1/24. + + + wizard.interfaces.lan.configure_dhcp + + checkbox + Configure DHCP server for this network, when disabled dhcp services will not be available on this network after finishing the wizard. + +
\ No newline at end of file diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_wan.xml b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_wan.xml new file mode 100644 index 00000000000..dedb0b1e365 --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_wan.xml @@ -0,0 +1,83 @@ +
+ + wizard.interfaces.wan.ipv4_type + + dropdown + + + wizard.interfaces.wan.spoofmac + + text + Usually this option is left empty, unless your provider requires you to connect using a specific mac address. + + + wizard.interfaces.wan.mtu + + text + Set the MTU of the WAN interface. If you leave this field blank, an MTU of 1492 bytes for PPPoE and 1500 bytes for all other connection types will be assumed. + + + wizard.interfaces.wan.mss + + text + If you enter a value 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 you leave this field 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. + + + wizard.interfaces.wan.ipaddr + + text + + Ip address and cidr to configure on this interface, e.g. 192.168.1.1/24. + + + wizard.interfaces.wan.gateway + + text + + Gateway address to use, e.g. 192.168.1.254. + + + wizard.interfaces.wan.dhcphostname + + text + + 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). + + + wizard.interfaces.wan.pppoe_username + + text + + + + + wizard.interfaces.wan.pppoe_password + + password + + + + + wizard.interfaces.wan.pppoe_provider + + text + + + + + header + + + + wizard.interfaces.wan.blockpriv + + checkbox + 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) and Carrier-grade NAT addresses (100.64/10). This option should only be set for WAN interfaces that use the public IP address space. + + + wizard.interfaces.wan.blockbogons + + checkbox + When set, this option blocks traffic from IP addresses that are reserved (but not RFC 1918) or not yet assigned by IANA. + +
\ No newline at end of file diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_root_password.xml b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_root_password.xml new file mode 100644 index 00000000000..859e226a60c --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_root_password.xml @@ -0,0 +1,13 @@ +
+ + wizard.password + + password + Leave empty to keep current one + + + wizard.password_confirm + + password + +
\ No newline at end of file diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml b/src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml index 1623bbd10d3..3f270d2434b 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml @@ -365,7 +365,8 @@ System Setup Wizard - wizard.php?xml=system + ui/core/initial_setup + api/core/initial_setup/* diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php b/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php new file mode 100644 index 00000000000..9f1db2931ca --- /dev/null +++ b/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php @@ -0,0 +1,371 @@ +object(); + foreach(explode('.', $path) as $item) { + if (isset($node->$item)) { + $node = $node->$item; + } else { + return $isBoolean ? '0' : ''; + } + } + if (count($node) > 1) { + $tmp = []; + foreach ($node as $item) { + $tmp[] = (string)$item; + } + return implode(',', $tmp); + } + if ($isBoolean && (string)$node == '') { + return '0'; + } else { + return (string)$node; + } + } + + /** + * setup initial values, read from configuration + */ + protected function init() + { + $this->hostname = $this->getConfigItem('system.hostname'); + $this->domain = $this->getConfigItem('system.domain'); + $this->language = $this->getConfigItem('system.language'); + $this->dns_servers = $this->getConfigItem('system.dnsserver'); + $this->timeservers = str_replace(' ', ',', $this->getConfigItem('system.timeservers')); + $this->timezone = $this->getConfigItem('system.timezone'); + $this->unbound->enabled = $this->getConfigItem('OPNsense.unboundplus.general.enabled', true); + $this->unbound->dnssec = $this->getConfigItem('OPNsense.unboundplus.general.dnssec', true); + $this->unbound->dnssecstripped = $this->getConfigItem('OPNsense.unboundplus.advanced.dnssecstripped'); + if (str_starts_with($this->getConfigItem('interfaces.wan.if'), 'pppoe')) { + $ipv4_type = 'pppoe'; + } elseif ($this->getConfigItem('interfaces.wan.ipaddr') == 'dhcp') { + $ipv4_type = 'dhcp'; + } else { + $ipv4_type = 'static'; + } + $this->interfaces->wan->ipv4_type = $ipv4_type; + $this->interfaces->wan->spoofmac = $this->getConfigItem('interfaces.wan.spoofmac'); + $this->interfaces->wan->mtu = $this->getConfigItem('interfaces.wan.mtu'); + $this->interfaces->wan->mss = $this->getConfigItem('interfaces.wan.mss'); + $this->interfaces->wan->dhcphostname = $this->getConfigItem('interfaces.wan.dhcphostname'); + $this->interfaces->wan->blockpriv = $this->getConfigItem('interfaces.wan.blockpriv', true); + $this->interfaces->wan->blockbogons = $this->getConfigItem('interfaces.wan.blockbogons', true); + + if ($ipv4_type == 'static') { + $this->interfaces->wan->ipaddr = sprintf( + "%s/%s", + $this->getConfigItem('interfaces.wan.ipaddr'), + $this->getConfigItem('interfaces.wan.subnet') + ); + } elseif ($ipv4_type == 'pppoe') { + $pppoeif = $this->getConfigItem('interfaces.wan.if'); + foreach (Config::getInstance()->object()->ppps->children() as $ppp) { + if ($ppp->if == $pppoeif) { + $this->interfaces->wan->pppoe_username = (string)$ppp->username; + if (!empty((string)$ppp->password)) { + $this->interfaces->wan->pppoe_password = base64_decode((string)$ppp->password); + } + $this->interfaces->wan->pppoe_provider = (string)$ppp->provider; + } + } + } + $this->interfaces->lan->ipaddr = sprintf( + "%s/%s", + $this->getConfigItem('interfaces.lan.ipaddr'), + $this->getConfigItem('interfaces.lan.subnet') + ); + } + + /** + * {@inheritdoc} + */ + public function performValidation($validateFullModel = false) + { + $messages = parent::performValidation($validateFullModel); + if ((string)$this->password != (string)$this->password_confirm) { + $messages->appendMessage( + new Message( + gettext("The passwords do not match."), + "password" + ) + ); + } + if ($this->interfaces->wan->ipv4_type == 'pppoe') { + /* PPPoE requires credentials */ + if ($this->interfaces->wan->pppoe_username->isEmpty()) { + $messages->appendMessage( + new Message( + gettext("A username is required."), + "interfaces.wan.pppoe_username" + ) + ); + } + if ($this->interfaces->wan->pppoe_password->isEmpty()) { + $messages->appendMessage( + new Message( + gettext("A password is required."), + "interfaces.wan.pppoe_password" + ) + ); + } + } elseif ($this->interfaces->wan->ipv4_type == 'static') { + if (!empty($this->interfaces->wan->gateway) && + !Util::isIPInCIDR($this->interfaces->wan->gateway, $this->interfaces->wan->ipaddr) + ) { + $messages->appendMessage( + new Message( + gettext("Please make sure the gateway address is reachable from the choosen subnet."), + "interfaces.wan.gateway" + ) + ); + } + } + + if ($this->interfaces->lan->disable == '0') { + $cnt = count(iterator_to_array(Util::cidrRangeIterator($this->interfaces->lan->ipaddr))); + if (!$this->interfaces->lan->configure_dhcp->isEmpty() && $cnt < 50) { + $messages->appendMessage( + new Message( + gettext("Automatic DHCP server configuration is only supported for networks larger than /27."), + "interfaces.lan.configure_dhcp" + ) + ); + } + } + + + return $messages; + } + + /** + * flush general settings from in-memory model back to config + */ + private function flush_general() + { + $target = Config::getInstance()->object(); + /* system settings */ + $target->system->timeservers = str_replace(',', ' ', (string)$this->timeservers); + $target->system->timezone = (string)$this->timezone; + unset($target->system->dnsserver); + foreach ( explode(',', (string)$this->dns_servers) as $dnsserver) { + $target->system->addChild('dnsserver', $dnsserver); + } + $target->system->dnsallowoverride = (string)$this->dnsallowoverride; + $target->system->language = (string)$this->language; + $target->system->hostname = (string)$this->hostname; + $target->system->domain = (string)$this->domain; + + /* configure unbound dns */ + $target->OPNsense->unboundplus->general->enabled = (string)$this->unbound->enabled; + $target->OPNsense->unboundplus->general->dnssec = (string)$this->unbound->dnssec; + $target->OPNsense->unboundplus->advanced->dnssecstripped = (string)$this->unbound->dnssecstripped; + } + + /** + * flush wan interface configuration from in-memory model back to config + */ + private function flush_network_wan() + { + $target = Config::getInstance()->object(); + /* configure wan */ + $gateways = new Gateways(); + foreach ($gateways->gateway_item->iterateItems() as $uuid => $node) { + if ($node->interface == 'wan' && $node->ipprotocol == 'inet') { + $gateways->gateway_item->del($uuid); + } + } + + $wanif = $this->getConfigItem('interfaces.wan.if'); + if ($this->interfaces->wan->ipv4_type == 'pppoe') { + /* PPPoE configuration will nest interfaces, make sure we can still update the interface once configured */ + if (!isset($target->ppps)) { + $target->addChild('ppps'); + } + $pppoe_idx = -1; + $max_ptpid = 0; + for ($idx = 0 ; $idx < count($target->ppps->ppp); ++$idx) { + if ($target->ppps->ppp[$idx]->if == $wanif) { + $pppoe_idx = $idx; + } + $max_ptpid = max($max_ptpid, $target->ppps->ppp[$idx]->ptpid); + } + + if ($pppoe_idx == -1) { + /* add pppoe on top of current configured wan */ + $node = $target->ppps->addChild('ppp'); + $node->addChild('ports', $wanif); + $node->addChild('ptpid', (string)($max_ptpid + 1)); + $node->addChild('if', 'pppoe' . $node->ptpid); + $target->interfaces->wan->if = (string)$node->if; + } else { + $node = $target->ppps->ppp[$pppoe_idx]; + } + $node->type = 'pppoe'; + $node->username = (string)$this->interfaces->wan->pppoe_username; + $node->password = base64_encode((string)$this->interfaces->wan->pppoe_password); + + } + unset($target->interfaces->wan->dhcphostname); + if (in_array($this->interfaces->wan->ipv4_type, ['pppoe', 'dhcp'])) { + $target->interfaces->wan->ipaddr = (string)$this->interfaces->wan->ipv4_type; + $target->interfaces->wan->subnet = ''; + if ($this->interfaces->wan->ipv4_type == 'dhcp') { + $target->interfaces->wan->dhcphostname = (string)$this->interfaces->wan->dhcphostname; + } + } else { + $parts = explode('/', $this->interfaces->wan->ipaddr); + $target->interfaces->wan->ipaddr = $parts[0]; + $target->interfaces->wan->subnet = $parts[1]; + if (!$this->interfaces->wan->gateway->isEmpty()) { + $gateways->createOrUpdateGateway([ + 'interface' => 'wan', + 'gateway' => (string)$this->interfaces->wan->gateway, + 'name' => 'WAN_GW', + 'weight' => 1, + 'monitor_disable' => 1, + 'descr' => "WAN Gateway", + 'defaultgw' => true, + ]); + } + } + $target->interfaces->wan->enable = '1'; + $target->interfaces->wan->spoofmac = (string)$this->interfaces->wan->spoofmac; + $target->interfaces->wan->mtu = (string)$this->interfaces->wan->mtu; + $target->interfaces->wan->mss = (string)$this->interfaces->wan->mss; + $target->interfaces->wan->blockpriv = (string)$this->interfaces->wan->blockpriv; + $target->interfaces->wan->blockbogons = (string)$this->interfaces->wan->blockbogons; + $gateways->serializeToConfig(false, true); + } + + /** + * flush lan interface configuration from in-memory model back to config + */ + private function flush_network_lan() + { + $target = Config::getInstance()->object(); + /* configure lan */ + if (!isset($target->interfaces->lan)) { + $target->interfaces->addChild('lan'); + } + $target->interfaces->lan->enable = $this->interfaces->lan->disable->isEmpty() ? '1' : '0'; + $dnsmasq = new Dnsmasq(); + foreach ($dnsmasq->dhcp_ranges->iterateItems() as $uuid => $node) { + if ($node->interface == 'lan') { + /* always remove lan dhcp ranges */ + $dnsmasq->dhcp_ranges->del($uuid); + } + } + if ($target->interfaces->lan->enable == '1') { + $parts = explode('/', $this->interfaces->lan->ipaddr); + $target->interfaces->lan->ipaddr = $parts[0]; + $target->interfaces->lan->subnet = $parts[1]; + // configure_dhcp + if (!$this->interfaces->lan->configure_dhcp->isEmpty()) { + $avail_addrs = iterator_to_array(Util::cidrRangeIterator($this->interfaces->lan->ipaddr)); + if (!$dnsmasq->interface->isEmpty() && !in_array('lan', explode(',', $dnsmasq->interface))) { + $dnsmasq->interface = (string)$dnsmasq->interface . ',lan'; + } + $dnsmasq->port = '0'; + $dnsmasq->enable = '1'; + $dhcprange = $dnsmasq->dhcp_ranges->Add(); + $dhcprange->interface = 'lan'; + $dhcprange->start_addr = $avail_addrs[40]; + $dhcprange->end_addr = $avail_addrs[count($avail_addrs)-10]; + } + } + $dnsmasq->serializeToConfig(false, true); + } + + /** + * reset root password when offered + */ + private function flush_initial_pass() + { + /* update root password */ + if (!$this->password->isEmpty()) { + $usermdl = new User(); + $rootuser = $usermdl->getUserByName('root'); + if ($rootuser) { + $hash = $usermdl->generatePasswordHash((string)$this->password); + if ($hash !== false && strpos($hash, '$') === 0) { + $rootuser->password = $hash; + $usermdl->serializeToConfig(false, true); + } + } + } + } + + /** + * remove initial wizard tag + */ + private function unset_initial_wizard() + { + unset(Config::getInstance()->object()->trigger_initial_wizard); + } + + + /** + * update configuration + */ + public function updateConfig() + { + $this->flush_general(); + $this->flush_network_wan(); + $this->flush_network_lan(); + $this->flush_initial_pass(); + $this->unset_initial_wizard(); + + Config::getInstance()->save(); + return ['status' => 'done']; + } +} diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.xml b/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.xml new file mode 100644 index 00000000000..e41a5e95512 --- /dev/null +++ b/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.xml @@ -0,0 +1,100 @@ + + :memory: + 1.0.0 + Initial setup wizard + + + N + N + Y + + + N + N + Y + + + system list locales + Y + + + N + , + Y + + + Y + + + + Y + + + Y + + + Y + + + + Y + , + Y + + + system list timezones + Y + + + + + Y + static + + Static + DHCP + PPPoE + + + + + 576 + 65535 + + + 576 + 65535 + + + Y + Please specify a valid address and cidr mask to use. + + + N + + + Y + N + + + + + + + + + + Y + Please specify a valid address and cidr mask to use. + + + + Y + 1 + + + + + + + \ No newline at end of file diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml b/src/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml index 9fa7470abb5..ae8f391518b 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml @@ -72,7 +72,7 @@ - + diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/initial_setup.volt b/src/opnsense/mvc/app/views/OPNsense/Core/initial_setup.volt new file mode 100644 index 00000000000..7e88355801e --- /dev/null +++ b/src/opnsense/mvc/app/views/OPNsense/Core/initial_setup.volt @@ -0,0 +1,92 @@ + + + +
+ {% for tabid, tab in all_tabs%} +
+
+ {% if tab['message'] is defined %} +
+ {{ tab['message'] }} +
+ {% elseif tab['form'] is defined %} + {{ partial("layout_partials/base_form",['fields': tab['form'], 'id': 'frm_wizard-' ~ tabid ])}} +
+ {% endif %} + + {% if not loop.last %} + + {% else %} + + {% endif %} +

+
+
+ {% endfor %} +
\ No newline at end of file diff --git a/src/opnsense/scripts/system/get_timezones.php b/src/opnsense/scripts/system/get_timezones.php new file mode 100755 index 00000000000..142e14f352d --- /dev/null +++ b/src/opnsense/scripts/system/get_timezones.php @@ -0,0 +1,36 @@ +#!/usr/local/bin/php + - - - Copyright (C) 2014 Deciso B.V. - Copyright (C) 2004-2005 Scott Ullrich - 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. -*/ -]]> - 9 - - 1 - General Setup - - - text - This wizard will guide you through the initial system configuration. The wizard may be stopped at any time by clicking the logo image at the top of the screen. - - - Next - submit - - - - if (isset($config['wizardtemp'])) { - unset($config['wizardtemp']); - } - - - if (isset($config['trigger_initial_wizard'])) { - unset($config['trigger_initial_wizard']); - write_config('Triggered initial wizard'); - } - - - - 2 - General Information - - - General Information - listtopic - - - Hostname - input - wizardtemp->system->hostname - ^[A-Za-z0-9.|-]+$ - Invalid Hostname - - - Domain - input - wizardtemp->system->domain - ^[a-z0-9.|-]+$ - Domain name field is invalid - - - Language - language_select - system->language - - - Primary DNS Server - input - system->dnsserver - - yes - 0 - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - Primary DNS Server field is invalid - - - Secondary DNS Server - input - system->dnsserver - 1 - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - Secondary DNS Server field is invalid - - - Override DNS - Allow DNS servers to be overridden by DHCP/PPP on WAN - checkbox - system->dnsallowoverride - - - Unbound DNS - listtopic - - - Enable Resolver - checkbox - yes - OPNsense->unboundplus->general->enabled - - - Enable DNSSEC Support - checkbox - - OPNsense->unboundplus->general->dnssec - - - Harden DNSSEC data - checkbox - - OPNsense->unboundplus->advanced->dnssecstripped - - - Next - submit - - - - - - - 3 - Time Server Information - - - Time server hostname - Enter the hostname (FQDN) of the time server. - input - system->timeservers - - - Timezone - timezone_select - system->timezone - - - Next - submit - - - - - - 4 - true - Configure WAN Interface - - var selectedItem = 0; - if (jQuery('#ipaddress').val() == 'dhcp') { - selectedItem = 1; - jQuery('#ipaddress').val(''); - } else if (jQuery('#ipaddress').val() == 'pppoe') { - selectedItem = 2; - jQuery('#ipaddress').val(''); - } else if (jQuery('#ipaddress').val() == 'pptp') { - selectedItem = 3; - jQuery('#ipaddress').val(''); - } else if (jQuery('#ipaddress').val() == 'ppp' || jQuery('#ipaddress').val() == 'l2tp') { - jQuery('#ipaddress').val(''); - } else { - selectedItem = 0; - } - jQuery('#selectedtype').prop('selectedIndex',selectedItem); - enableitems(selectedItem); - - - - SelectedType - IPv4 Configuration Type - select - true - - - - - - - - - General configuration - listtopic - - - true - MAC Address - interfaces->wan->spoofmac - input - 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. - ^([0-9a-f]{2}([:-]||$)){6}$ - MAC Address field is invalid - - - true - MTU - input - interfaces->wan->mtu - Set the MTU of the WAN interface. If you leave this field blank, an MTU of 1492 bytes for PPPoE and 1500 bytes for all other connection types will be assumed. - - - true - MSS - input - interfaces->wan->mss - If you enter a value 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 you leave this field 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. - - - Static IP Configuration - listtopic - - - IP Address - interfaces->wan->ipaddr - input - true - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - IP Address field is invalid - - - true - true - true - Subnet Mask - interfaces->wan->subnet - subnet_select - - - Upstream Gateway - wizardtemp->wangateway - input - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - Gateway IP Address field is invalid - - - DHCP client configuration - listtopic - - - DHCP Hostname - input - interfaces->wan->dhcphostname - 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). - - - PPPoE configuration - listtopic - - - PPPoE Username - input - wizardtemp->wan->username - - - PPPoE Password - input - wizardtemp->wan->password - - - PPPoE Service name - input - wizardtemp->wan->provider - - - PPPoE Dial on demand - Enable Dial-On-Demand mode - checkbox - This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected. - wizardtemp->wan->ondemand - - - PPPoE Idle timeout - input - 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. - wizardtemp->wan->idletimeout - - - PPTP configuration - listtopic - - - PPTP Username - input - wizardtemp->wan->pptpusername - - - PPTP Password - input - wizardtemp->wan->pptppassword - - - true - PPTP Local IP Address - input - wizardtemp->wan->localip - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - PPTP Local IP Address field is invalid - - - true - true - true - pptplocalsubnet - wizardtemp->wan->subnet - subnet_select - - - PPTP Remote IP Address - wizardtemp->wan->gateway - input - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - PPTP Remote IP Address field is invalid - - - PPTP Dial on demand - Enable Dial-On-Demand mode - checkbox - wizardtemp->wan->pptpondemand - This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected. - - - PPTP Idle timeout - input - wizardtemp->wan->pptpidletimeout - 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. - - - RFC1918 Networks - listtopic - - - true - Block RFC1918 Private Networks - 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) and Carrier-grade NAT addresses (100.64/10). This option should only be set for WAN interfaces that use the public IP address space. - checkbox - interfaces->wan->blockpriv - Block private networks from entering via WAN - - - Block bogon networks - listtopic - - - true - Block bogon networks - When set, this option blocks traffic from IP addresses that are reserved (but not RFC 1918) or not yet assigned by IANA. - checkbox - interfaces->wan->blockbogons - Block non-Internet routed networks from entering via WAN - - - Next - submit - - - gatewayIterator() as $gw) { - if (empty($config['wizardtemp']['wangateway']) && $gw['name'] == 'WAN_GW') { - $config['wizardtemp']['wangateway'] = $gw['gateway']; - } -} - ]]> - $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']); -} - ]]> - - - - 5 - Configure LAN Interface - On this screen we will configure the Local Area Network information. - - - LAN IP Address - input - interfaces->lan->ipaddr - ^(?:[0]*(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:[0]*(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))$ - (leave empty for none) - LAN IP Address field is invalid - - - Subnet Mask - subnet_select - interfaces->lan->subnet - - - Next - submit - - - - - - 6 - Set Root Password - - - Root Password - password - (leave empty to keep current one) - - - Root Password Confirmation - password - - - Next - submit - - - - - - 7 - Reload Configuration - - - text - Click 'Reload' to apply the changes. - - - Reload - submit - - - gatewayIterator() as $gw) { - if (!empty($gw['defaultgw'])) { - $defaultgw_found = true; - } - - if ($gw['name'] == 'WAN_GW' && !empty($gw['uuid'])) { - $gateways->createOrUpdateGateway(['gateway' => $config['wizardtemp']['wangateway']], $gw['uuid']); - $found = true; - } -} - -if (!$found) { - $gateways->createOrUpdateGateway([ - 'interface' => 'wan', - 'gateway' => $config['wizardtemp']['wangateway'], - 'name' => 'WAN_GW', - 'weight' => 1, - 'monitor_disable' => 1, - 'descr' => "WAN Gateway", - 'defaultgw' => !$defaultgw_found, - ]); -} - -/* Assignments to $config only after this went through! */ -$config = OPNsense\Core\Config::getInstance()->toArray(listtags()); - -$config['system']['hostname'] = $config['wizardtemp']['system']['hostname']; -$config['system']['domain'] = $config['wizardtemp']['system']['domain']; -$config['interfaces']['wan']['gateway'] = 'WAN_GW'; -unset($config['wizardtemp']); - -write_config(); - ]]> - - - 8 - Reload in progress - - - text - A reload is now in progress. The wizard will redirect you to the dashboard once the reload is completed. - - - refresh - - index.php?wizard_done - - - - - diff --git a/src/www/index.php b/src/www/index.php index 1d3a94fc5db..a824b30423a 100644 --- a/src/www/index.php +++ b/src/www/index.php @@ -93,7 +93,7 @@ - + 0) { - if (bTypeAhead) { - this.typeAhead(aSuggestions[0]); - } - - this.showSuggestions(aSuggestions); - } else { - this.hideSuggestions(); - } -}; - -/** - * Creates the dropdown layer to display multiple suggestions. - * @scope private - */ -AutoSuggestControl.prototype.createDropDown = function () { - - var oThis = this; - - //create the layer and assign styles - this.layer = document.createElement("div"); - this.layer.className = "suggestions"; - this.layer.style.visibility = "hidden"; - this.layer.style.width = this.textbox.offsetWidth; - - //when the user clicks on the a suggestion, get the text (innerHTML) - //and place it into a textbox - this.layer.onmousedown = - this.layer.onmouseup = - this.layer.onmouseover = function (oEvent) { - oEvent = oEvent || window.event; - let oTarget = oEvent.target || oEvent.srcElement; - - if (oEvent.type == "mousedown") { - oThis.textbox.value = oTarget.firstChild.nodeValue; - oThis.hideSuggestions(); - } else if (oEvent.type == "mouseover") { - oThis.highlightSuggestion(oTarget); - } else { - oThis.textbox.focus(); - } - }; - - - document.body.appendChild(this.layer); -}; - -/** - * Gets the left coordinate of the textbox. - * @scope private - * @return The left coordinate of the textbox in pixels. - */ -AutoSuggestControl.prototype.getLeft = function () /*:int*/ { - - var oNode = this.textbox; - var iLeft = 0; - - while(oNode.tagName != "BODY") { - iLeft += oNode.offsetLeft; - oNode = oNode.offsetParent; - } - - return iLeft; -}; - -/** - * Gets the top coordinate of the textbox. - * @scope private - * @return The top coordinate of the textbox in pixels. - */ -AutoSuggestControl.prototype.getTop = function () /*:int*/ { - - var oNode = this.textbox; - var iTop = 0; - - while(oNode.tagName != "BODY") { - iTop += oNode.offsetTop; - oNode = oNode.offsetParent; - } - - return iTop; -}; - -/** - * Handles three keydown events. - * @scope private - * @param oEvent The event object for the keydown event. - */ -AutoSuggestControl.prototype.handleKeyDown = function (oEvent /*:Event*/) { - - switch(oEvent.keyCode) { - case 38: //up arrow - this.previousSuggestion(); - break; - case 40: //down arrow - this.nextSuggestion(); - break; - case 13: //enter - this.hideSuggestions(); - break; - } - -}; - -/** - * Handles keyup events. - * @scope private - * @param oEvent The event object for the keyup event. - */ -AutoSuggestControl.prototype.handleKeyUp = function (oEvent /*:Event*/) { - - var iKeyCode = oEvent.keyCode; - - //for backspace (8) and delete (46), shows suggestions without typeahead - if (iKeyCode == 8 || iKeyCode == 46) { - this.provider.requestSuggestions(this, false); - - //make sure not to interfere with non-character keys - } else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)) { - //ignore - } else { - //request suggestions from the suggestion provider with typeahead - this.provider.requestSuggestions(this, true); - } -}; - -/** - * Hides the suggestion dropdown. - * @scope private - */ -AutoSuggestControl.prototype.hideSuggestions = function () { - this.layer.style.visibility = "hidden"; -}; - -/** - * Highlights the given node in the suggestions dropdown. - * @scope private - * @param oSuggestionNode The node representing a suggestion in the dropdown. - */ -AutoSuggestControl.prototype.highlightSuggestion = function (oSuggestionNode) { - - for (var i=0; i < this.layer.childNodes.length; i++) { - var oNode = this.layer.childNodes[i]; - if (oNode == oSuggestionNode) { - oNode.className = "current"; - } else if (oNode.className == "current") { - oNode.className = ""; - } - } -}; - -/** - * Initializes the textbox with event handlers for - * auto suggest functionality. - * @scope private - */ -AutoSuggestControl.prototype.init = function () { - - //save a reference to this object - var oThis = this; - - //assign the onkeyup event handler - this.textbox.onkeyup = function (oEvent) { - - //check for the proper location of the event object - if (!oEvent) { - oEvent = window.event; - } - - //call the handleKeyUp() method with the event object - oThis.handleKeyUp(oEvent); - }; - - //assign onkeydown event handler - this.textbox.onkeydown = function (oEvent) { - - //check for the proper location of the event object - if (!oEvent) { - oEvent = window.event; - } - - //call the handleKeyDown() method with the event object - oThis.handleKeyDown(oEvent); - }; - - //assign onblur event handler (hides suggestions) - this.textbox.onblur = function () { - oThis.hideSuggestions(); - }; - - //create the suggestions dropdown - this.createDropDown(); -}; - -/** - * Highlights the next suggestion in the dropdown and - * places the suggestion into the textbox. - * @scope private - */ -AutoSuggestControl.prototype.nextSuggestion = function () { - var cSuggestionNodes = this.layer.childNodes; - - if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length-1) { - var oNode = cSuggestionNodes[++this.cur]; - this.highlightSuggestion(oNode); - this.textbox.value = oNode.firstChild.nodeValue; - } -}; - -/** - * Highlights the previous suggestion in the dropdown and - * places the suggestion into the textbox. - * @scope private - */ -AutoSuggestControl.prototype.previousSuggestion = function () { - var cSuggestionNodes = this.layer.childNodes; - - if (cSuggestionNodes.length > 0 && this.cur > 0) { - var oNode = cSuggestionNodes[--this.cur]; - this.highlightSuggestion(oNode); - this.textbox.value = oNode.firstChild.nodeValue; - } -}; - -/** - * Selects a range of text in the textbox. - * @scope public - * @param iStart The start index (base 0) of the selection. - * @param iLength The number of characters to select. - */ -AutoSuggestControl.prototype.selectRange = function (iStart /*:int*/, iLength /*:int*/) { - - //use text ranges for Internet Explorer - if (this.textbox.createTextRange) { - var oRange = this.textbox.createTextRange(); - oRange.moveStart("character", iStart); - oRange.moveEnd("character", iLength - this.textbox.value.length); - oRange.select(); - - //use setSelectionRange() for Mozilla - } else if (this.textbox.setSelectionRange) { - this.textbox.setSelectionRange(iStart, iLength); - } - - //set focus back to the textbox - this.textbox.focus(); -}; - -/** - * Builds the suggestion layer contents, moves it into position, - * and displays the layer. - * @scope private - * @param aSuggestions An array of suggestions for the control. - */ -AutoSuggestControl.prototype.showSuggestions = function (aSuggestions /*:Array*/) { - - var oDiv = null; - this.layer.innerHTML = ""; //clear contents of the layer - - for (var i=0; i < aSuggestions.length; i++) { - oDiv = document.createElement("div"); - oDiv.appendChild(document.createTextNode(aSuggestions[i])); - this.layer.appendChild(oDiv); - } - - this.layer.style.left = this.getLeft() + "px"; - this.layer.style.top = (this.getTop()+this.textbox.offsetHeight) + "px"; - this.layer.style.visibility = "visible"; - -}; - -/** - * Inserts a suggestion into the textbox, highlighting the - * suggested part of the text. - * @scope private - * @param sSuggestion The suggestion for the textbox. - */ -AutoSuggestControl.prototype.typeAhead = function (sSuggestion /*:String*/) { - - //check for support of typeahead functionality - if (this.textbox.createTextRange || this.textbox.setSelectionRange){ - var iLen = this.textbox.value.length; - this.textbox.value = sSuggestion; - this.selectRange(iLen, sSuggestion.length); - } -}; diff --git a/src/www/javascript/wizard/disablekeys.js b/src/www/javascript/wizard/disablekeys.js deleted file mode 100644 index b5a1da14363..00000000000 --- a/src/www/javascript/wizard/disablekeys.js +++ /dev/null @@ -1,6 +0,0 @@ -function kH(e) { - var pK = document.all? window.event.keyCode:e.which; - return pK != 13; -} -document.onkeypress = kH; -if (document.layers) document.captureEvents(Event.KEYPRESS); diff --git a/src/www/javascript/wizard/suggestions.js b/src/www/javascript/wizard/suggestions.js deleted file mode 100644 index 99f8fc16f78..00000000000 --- a/src/www/javascript/wizard/suggestions.js +++ /dev/null @@ -1,33 +0,0 @@ - -/** - * Provides suggestions for state names (USA). - * @class - * @scope public - */ -function StateSuggestions(text) { - this.states = text; -} - -/** - * Request suggestions for the given autosuggest control. - * @scope protected - * @param oAutoSuggestControl The autosuggest control to provide suggestions for. - */ -StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/, - bTypeAhead /*:boolean*/) { - var aSuggestions = []; - var sTextboxValue = oAutoSuggestControl.textbox.value; - - if (sTextboxValue.length > 0){ - - //search for matching states - for (var i=0; i < this.states.length; i++) { - if (this.states[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) == 0) { - aSuggestions.push(this.states[i]); - } - } - } - - //provide suggestions to the control - oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead); -}; diff --git a/src/www/wizard.php b/src/www/wizard.php deleted file mode 100644 index 732ad25f665..00000000000 --- a/src/www/wizard.php +++ /dev/null @@ -1,1014 +0,0 @@ - - * 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. - */ - -require_once("guiconfig.inc"); -require_once("filter.inc"); -require_once("system.inc"); -require_once("interfaces.inc"); - -/* - * 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); - - foreach (array_keys(get_configured_interface_with_descr()) as $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; -} - - -$stepid = '0'; - -if (isset($_POST['stepid'])) { - $stepid = htmlspecialchars($_POST['stepid']); -} elseif (isset($_GET['stepid'])) { - $stepid = htmlspecialchars($_GET['stepid']); -} - -$xml = ''; -if (isset($_GET['xml'])) { - $xml = htmlspecialchars($_GET['xml']); -} elseif (isset($_POST['xml'])) { - $xml = htmlspecialchars($_POST['xml']); -} - -switch ($xml) { - case 'openvpn': - case 'system': - break; - default: - print_info_box(gettext('ERROR: Could not find wizard file.')); - die; -} - -$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', -)); - -$pkg = parse_xml_config_raw("/usr/local/wizard/{$xml}.xml", 'wizard', false); -if (!is_array($pkg)) { - print_info_box(sprintf(gettext("ERROR: Could not parse %s wizard file."), $xml)); - die; -} - -$totalsteps = $pkg['totalsteps']; - -if ($pkg['includefile']) { - require_once($pkg['includefile']); -} - -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']) && $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; - } -} - -$extraBreadcrumb = $pkg['step'][$stepid]['title']; - -function update_config_field($field, $updatetext, $unset, $arraynum, $field_type) -{ - global $config; - $field_split = explode('->', $field); - $field_conv = ''; - foreach ($field_split as $f) - $field_conv .= "['" . $f . "']"; - if ($field_conv == '') - return; - if ($arraynum != '') - $field_conv .= "[" . $arraynum . "]"; - if (($field_type == 'checkbox' && $updatetext != '1') || $updatetext == '') { - /* - * item is a checkbox, it should have the value "1" - * 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 . " = '" . addslashes($updatetext) . "';"; - eval($text); - return; - } - - if ($unset == "yes") { - $text = "unset(\$config" . $field_conv . ");"; - eval($text); - } - $text = "\$config" . $field_conv . " = '" . addslashes($updatetext) . "';"; - eval($text); -} - -function redirect_url() -{ - global $config, $title; - $urlport = ''; - - 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' && $proto != 'https') || ($port == '80' && $proto != 'http')) { - $urlport = ':' . $port; - } elseif ($port != '80' && $port != '443') { - $urlport = ':' . $port; - } - } - $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']; - } - } - - return $proto . '://' . $urlhost . $urlport; -} - -// handle before form display event. -do { - $oldstepid = $stepid; - if ($pkg['step'][$stepid]['stepbeforeformdisplay'] != '') { - eval($pkg['step'][$stepid]['stepbeforeformdisplay']); - } -} while ($oldstepid != $stepid); - - -include("head.inc"); - -?> - - - - - - - - - - - -
-
- - 0) - print_input_errors($input_errors); - if (isset($savemsg)) - print_info_box($savemsg); - if ($_GET['message'] != '') - print_info_box(htmlspecialchars($_GET['message'])); - if ($_POST['message'] != '') - print_info_box(htmlspecialchars($_POST['message'])); - ?> - -
-
- -
- - -
- - ", $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 ""; - } - - switch ($field['type']) { - case "input": - if ($field['displayname']) { - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo "\n"; - } - if (!$field['dontcombinecells']) - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo "\n"; - } - if (!$field['dontcombinecells']) - echo ""; - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo "\n"; - } - if (!$field['dontcombinecells']) - echo ""; - echo ""; - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo "\n"; - } - if ($field['size']) $size = " size='" . $field['size'] . "' "; - if ($field['multiple'] == "yes") $multiple = "multiple=\"multiple\" "; - if (!$field['dontcombinecells']) - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo ""; - } - if (!$field['dontcombinecells']) - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo ""; - } - if (!$field['dontcombinecells']) - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo ""; - } - if (!$field['dontcombinecells']) - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo ""; - } - if (!$field['dontcombinecells']) - echo "\n"; - } else if (!$field['dontdisplayname']) { - echo ""; - } - $checked = ''; - if ($value != '') - $checked = " checked=\"checked\""; - echo ""; - - echo "\n"; - } - - } - } - ?> - -
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":\n"; - - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - break; - case "text": - echo "
\n"; - if ($field['description'] != '') { - echo "

" . gettext($field['description']) . "
"; - } - break; - case "inputalias": - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":\n"; - - $inputaliases[] = $name; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - break; - case "interfaces_selection": - $size = ''; - $multiple = ''; - $name = strtolower($name); - echo "
\n"; - echo ($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n"; - echo "\n"; - if ($field['size'] != '') $size = "size=\"{$field['size']}\""; - if ($field['multiple'] != '' and $field['multiple'] != '0') { - $multiple = "multiple=\"multiple\""; - $name .= "[]"; - } - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "password": - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":"; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "certca_selection": - $size = ''; - $multiple = ''; - $name = strtolower($name); - echo "
\n"; - echo ($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n"; - echo "\n"; - if ($field['size'] != '') $size = "size=\"{$field['size']}\""; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "cert_selection": - $size = ''; - $multiple = ''; - $name = strtolower($name); - echo "
\n"; - echo ($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n"; - echo "\n"; - if ($field['size'] != '') $size = "size=\"{$field['size']}\""; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "select": - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":\n"; - $onchange = ''; - foreach ($field['options']['option'] as $opt) { - if ($opt['enablefields'] != '') { - $onchange = "onchange=\"enableitems(this.selectedIndex);\" "; - } - } - echo "\n"; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "textarea": - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":"; - echo "\n"; - - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "submit": - echo "
"; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "listtopic": - echo "
" . gettext($field['name']) . "\n"; - - break; - case "subnet_select": - if ($field['displayname']) { - echo "\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":"; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "language_select": - $languagelist = get_locale_list(); - - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":"; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "timezone_select": - $timezonelist = get_zoneinfo(); - - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":"; - echo "\n"; - - if ($field['description'] != '') { - echo "
" . gettext($field['description']); - } - - break; - case "checkbox": - if ($field['displayname']) { - echo "
\n"; - echo gettext($field['displayname']); - echo ":\n"; - echo gettext($field['name']); - echo ":\n"; - - if ($field['typehint'] != '') { - echo gettext($field['typehint']); - } - - if ($field['description'] != '') { - echo '

' . gettext($field['description']); - } - - break; - } - - if ($field['type'] != 'checkbox' && $field['typehint'] != '') { - echo gettext($field['typehint']); - } - - if (!$field['combinefieldsbegin']) { - if (!$field['dontcombinecells']) - echo "
- '; - } - break 2; - } - } - } - ?> -
-
-
-
-
-
- - - - -\n"; - echo "//\n"; - echo "\n\n"; -} -?> - - - -\n"; - echo "//\n"; - echo "\n\n"; -} - -include('foot.inc');