-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wizard: reimplement system setup, for #8352
- Loading branch information
1 parent
3caf9e1
commit 955db38
Showing
6 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/opnsense/mvc/app/controllers/OPNsense/Core/Api/InitialSetupController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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; | ||
|
||
/** | ||
* Class InitialSetupController | ||
* @package OPNsense\Core | ||
*/ | ||
class InitialSetupController extends ApiMutableModelControllerBase | ||
{ | ||
protected static $internalModelName = 'wizard'; | ||
protected static $internalModelClass = 'OPNsense\Core\InitialSetup'; | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/opnsense/mvc/app/controllers/OPNsense/Core/InitialSetupController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?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('test 3'), | ||
'form' => $this->getForm('wizard_general_info') | ||
], | ||
'step_4' => [ | ||
'title' => gettext('test 4'), | ||
'form' => $this->getForm('wizard_general_info') | ||
] | ||
]; | ||
$this->view->pick('OPNsense/Core/initial_setup'); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/opnsense/mvc/app/controllers/OPNsense/Core/forms/wizard_general_info.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<form> | ||
<field> | ||
<id>wizard.hostname</id> | ||
<label>Hostname</label> | ||
<type>text</type> | ||
</field> | ||
</form> |
57 changes: 57 additions & 0 deletions
57
src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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; | ||
|
||
use OPNsense\Base\BaseModel; | ||
use OPNsense\Core\Config; | ||
|
||
class InitialSetup extends BaseModel | ||
{ | ||
|
||
private function getConfigItem(string $path) | ||
{ | ||
$node = Config::getInstance()->object(); | ||
foreach(explode('.', $path) as $item) { | ||
if (isset($node->$item)) { | ||
$node = $node->$item; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
return (string)$node; | ||
} | ||
|
||
/** | ||
* setup initial values | ||
*/ | ||
protected function init() | ||
{ | ||
$this->hostname = $this->getConfigItem('system.hostname'); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<model> | ||
<mount>:memory:</mount> | ||
<version>1.0.0</version> | ||
<description>Initial setup wizard</description> | ||
<items> | ||
<hostname type="HostnameField"> | ||
<IsDNSName>N</IsDNSName> | ||
<IpAllowed>N</IpAllowed> | ||
<Required>Y</Required> | ||
</hostname> | ||
</items> | ||
</model> |
65 changes: 65 additions & 0 deletions
65
src/opnsense/mvc/app/views/OPNsense/Core/initial_setup.volt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script> | ||
$( document ).ready(function() { | ||
mapDataToFormUI({'frm_wizard':"/api/core/initial_setup/get"}).done(function(data){ | ||
$('.selectpicker').selectpicker('refresh'); | ||
}); | ||
/* next pane */ | ||
$(".action_next").click(function(){ | ||
let target = $("#tab_" + $(this).data('next_index')); | ||
let this_form = $(this).closest('.tab-pane').find('form'); | ||
saveFormToEndpoint("/api/core/initial_setup/set", 'form_root', function(){ | ||
target.parent().removeClass('hidden'); | ||
target.click(); | ||
}, | ||
true, | ||
function (data) { | ||
let failed_here = false; | ||
if (data.validations && this_form) { | ||
let validations = Object.keys(data.validations); | ||
this_form.find('input').each(function(){ | ||
if (validations.includes($(this).attr('id'))) { | ||
failed_here = true; | ||
} | ||
}); | ||
} | ||
if (!failed_here) { | ||
target.parent().removeClass('hidden'); | ||
target.click(); | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> | ||
|
||
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs"> | ||
{% for tabid, tab in all_tabs%} | ||
<li class="{% if loop.first %}active{% else %}hidden{% endif %}"><a data-toggle="tab" id="tab_{{loop.index}}" href="#{{tabid}}">{{ tab['title'] }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
<div class="tab-content content-box" id="form_root"> | ||
{% for tabid, tab in all_tabs%} | ||
<div id="{{tabid}}" class="tab-pane fade in {% if loop.first %}active{% endif %}" style="padding-top:10px;"> | ||
<div class="col-md-12"> | ||
{% if tab['message'] is defined %} | ||
<div class="well"> | ||
{{ tab['message'] }} | ||
</div> | ||
{% elseif tab['form'] is defined %} | ||
{{ partial("layout_partials/base_form",['fields': tab['form'], 'id': 'frm_wizard-' ~ tabid ])}} | ||
<br/> | ||
{% endif %} | ||
|
||
{% if not loop.last %} | ||
<button class="btn btn-primary action_next" id="btn_next_{{loop.index}}" data-next_index="{{loop.index + 1}}"> | ||
{{ lang._('Next') }} | ||
</button> | ||
{% else %} | ||
<button class="btn btn-primary" id="apply"> | ||
{{ lang._('Apply') }} | ||
</button> | ||
{% endif %} | ||
<br/><br/> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> |