Skip to content

Commit

Permalink
wizard: reimplement system setup (#8378)
Browse files Browse the repository at this point in the history
* wizard: reimplement system setup, for #8352

This commit implements our replacement for the setup wizard. The questions are roughly the same as in the legacy version.
Some less relevant options have been removed (pppoe ondemand for example) and isc-dhcpd has been replaced with dnsmasq.

Only standard tools have been used, a memory model to validate the data and simple input forms in tabs.

The in memory model acts as a wrapper around a legacy configuration data and a couple of component models to apply the requested settings.

Some legacy settings using isset() have been altered to use their empty() equivalent.

* wizard: as we're changing to dnsmasq as default, we need to make sure the console setup configures the same (#8352)

Fix some small php arnings in the process, but further than that just rewrite the dhcpd console handling to use dnsmasq instead of isc.
Eventually we will need to rewrite the console tools as well, but let's try to keep this compatible with minimal impact.

* wizard: change other occurrences of isset($config['dnsallowoverride']) for #8352

* wizard: sort listtags() and some other minor review comments for #8352
  • Loading branch information
AdSchellevis authored Mar 3, 2025
1 parent d32ec31 commit 592a62b
Show file tree
Hide file tree
Showing 31 changed files with 1,023 additions and 2,100 deletions.
15 changes: 10 additions & 5 deletions plist
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/HasyncController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/HasyncStatusController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/InitialSetupController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/MenuController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/ServiceController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/Api/SnapshotsController.php
Expand All @@ -259,6 +260,7 @@
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/HasyncController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/HasyncStatusController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/IndexController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/InitialSetupController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/LicenseController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/RebootController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/ServiceController.php
Expand All @@ -267,6 +269,10 @@
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/hasyncSettings.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/snapshot.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/tunable.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_general_info.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_lan.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_network_wan.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_root_password.xml
/usr/local/opnsense/mvc/app/controllers/OPNsense/Cron/Api/ServiceController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Cron/Api/SettingsController.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Cron/IndexController.php
Expand Down Expand Up @@ -686,6 +692,8 @@
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Hasync.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Hasync.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_0.php
/usr/local/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_1.php
Expand Down Expand Up @@ -904,6 +912,7 @@
/usr/local/opnsense/mvc/app/views/OPNsense/Core/halt.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/hasync.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/hasync_status.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/initial_setup.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/license.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/not_found.volt
/usr/local/opnsense/mvc/app/views/OPNsense/Core/reboot.volt
Expand Down Expand Up @@ -1309,6 +1318,7 @@
/usr/local/opnsense/scripts/system/crl_fetch.py
/usr/local/opnsense/scripts/system/flush_config_history
/usr/local/opnsense/scripts/system/get_locales.php
/usr/local/opnsense/scripts/system/get_timezones.php
/usr/local/opnsense/scripts/system/ha_xmlrpc_exec.php
/usr/local/opnsense/scripts/system/list_shells.py
/usr/local/opnsense/scripts/system/nameservers.php
Expand Down Expand Up @@ -2407,7 +2417,6 @@
/usr/local/share/man/man8/opnsense-log.8.gz
/usr/local/share/man/man8/opnsense-shell.8.gz
/usr/local/share/man/man8/opnsense-version.8.gz
/usr/local/wizard/system.xml
/usr/local/www/authgui.inc
/usr/local/www/crash_reporter.php
/usr/local/www/csrf.inc
Expand Down Expand Up @@ -2440,9 +2449,6 @@
/usr/local/www/interfaces_wireless.php
/usr/local/www/interfaces_wireless_edit.php
/usr/local/www/javascript/opnsense_legacy.js
/usr/local/www/javascript/wizard/autosuggest.js
/usr/local/www/javascript/wizard/disablekeys.js
/usr/local/www/javascript/wizard/suggestions.js
/usr/local/www/reporting_settings.php
/usr/local/www/services_dhcp.php
/usr/local/www/services_dhcp_edit.php
Expand Down Expand Up @@ -2470,7 +2476,6 @@
/usr/local/www/vpn_ipsec_phase2.php
/usr/local/www/vpn_openvpn_client.php
/usr/local/www/vpn_openvpn_server.php
/usr/local/www/wizard.php
/usr/local/www/xmlrpc.php
@sample /usr/local/etc/bogons.sample
@sample /usr/local/etc/bogonsv6.sample
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TREES= bin etc libexec man opnsense root sbin wizard www
TREES= bin etc libexec man opnsense root sbin www
ROOT= /usr/local
ROOT_man= /usr/local/share
ROOT_root= /
Expand Down
19 changes: 10 additions & 9 deletions src/etc/config.xml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@
<track6-prefix-id>0</track6-prefix-id>
</lan>
</interfaces>
<dhcpd>
<lan>
<enable/>
<range>
<from>192.168.1.100</from>
<to>192.168.1.199</to>
</range>
</lan>
</dhcpd>
<unbound>
<enable>1</enable>
</unbound>
<dnsmasq>
<enable>1</enable>
<port>0</port>
<interface>lan</interface>
<dhcp_ranges>
<interface>lan</interface>
<start_addr>192.168.1.100</start_addr>
<end_addr>192.168.1.199</end_addr>
</dhcp_ranges>
</dnsmasq>
<snmpd>
<syslocation/>
<syscontact/>
Expand Down
20 changes: 16 additions & 4 deletions src/etc/inc/console.inc
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,22 @@ EOD;
$config['interfaces']['lan']['subnetv6'] = '64';
}

config_read_array('dhcpd', 'lan', 'range');
$config['dhcpd']['lan']['enable'] = true;
$config['dhcpd']['lan']['range']['from'] = '192.168.1.100';
$config['dhcpd']['lan']['range']['to'] = '192.168.1.199';
if (isset($config['dhcpd']['lan'])) {
unset($config['dhcpd']['lan']);
}

config_read_array('dnsmasq', 'dhcp_ranges');
foreach ($config['dnsmasq']['dhcp_ranges'] as $idx => $range) {
if ($range['interface'] == 'lan') {
unset($config['dnsmasq']['dhcp_ranges'][$idx]);
}
}
$config['dnsmasq']['enable'] = '1';
$config['dnsmasq']['dhcp_ranges'][] = [
'interface' => 'lan',
'start_addr' => '192.168.1.100',
'end_addr' => '192.168.1.200'
];

config_read_array('nat', 'outbound');
$config['nat']['outbound']['mode'] = 'automatic';
Expand Down
8 changes: 4 additions & 4 deletions src/etc/inc/filter.lib.inc
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ function filter_core_rules_system($fw, $defaults)
['from' => "<bogons>", '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' => "<bogonsv6>", '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
Expand All @@ -326,15 +326,15 @@ 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(
5,
['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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ EOD;
$mpdconf .= " set ipcp no vjcomp\n";
}

if (isset($config['system']['dnsallowoverride'])) {
if (!empty($config['system']['dnsallowoverride'])) {
$mpdconf .= " set ipcp enable req-pri-dns\n";
$mpdconf .= " set ipcp enable req-sec-dns\n";
}
Expand Down
4 changes: 2 additions & 2 deletions src/etc/inc/system.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -372,7 +372,7 @@ function get_nameservers($interface = null, $with_gateway = false)
if (!empty($list)) {
$dns_lists[] = $list;
}
} elseif (isset($syscfg['dnsallowoverride'])) {
} elseif (!empty($syscfg['dnsallowoverride'])) {
/* return dynamic servers as required by configuration */
$list = shell_safe('/usr/local/sbin/ifctl -nl');
if (!empty($list)) {
Expand Down
4 changes: 2 additions & 2 deletions src/etc/inc/xmlparse.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function listtags()
'acls', 'alias', 'aliasurl', 'allowedip', 'allowedhostname', 'authserver',
'bridged', 'build_port_path',
'ca', 'cacert', 'cert', 'crl', 'clone', 'config', 'container', 'columnitem',
'disk', 'dnsserver', 'dnsupdate', 'domainoverrides',
'dhcp_ranges', 'disk', 'dnsserver', 'dnsupdate', 'domainoverrides',
'element', 'encryption-algorithm-option',
'field', 'fieldname',
'gateway_item', 'gateway_group', 'gif', 'gre', 'group',
Expand All @@ -50,7 +50,7 @@ function listtags()
'tab', 'timerange', 'tunnel',
'user',
'vip', 'virtual_server', 'vlan',
'winsserver', 'wolentry', 'widget',
'winsserver', 'wolentry', 'widget'
);

return array_flip($ret);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* Copyright (c) 2025 Deciso B.V.
* 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.
*/

namespace OPNsense\Core\Api;

use OPNsense\Base\ApiMutableModelControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Core\Config;

/**
* Class InitialSetupController
* @package OPNsense\Core
*/
class InitialSetupController extends ApiMutableModelControllerBase
{
protected static $internalModelName = 'wizard';
protected static $internalModelClass = 'OPNsense\Core\InitialSetup';

public function configureAction()
{
$result = parent::setAction();
if ($result['result'] == 'saved') {
$result = $this->getModel()->updateConfig();
(new Backend())->configdRun("service reload delay", true);
return $result;
} else {
return $result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* Copyright (C) 2025 Deciso B.V.
*
* 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.
*
*/

namespace OPNsense\Core;

class InitialSetupController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->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');
}
}
Loading

0 comments on commit 592a62b

Please sign in to comment.