Commit 9f7e1b89 authored by Ad Schellevis's avatar Ad Schellevis

first step in moving firmware settings to firmware page,...

first step in moving firmware settings to firmware page, https://github.com/opnsense/core/issues/834
parent 6dcded9f
......@@ -32,6 +32,7 @@ namespace OPNsense\Core\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Core\Backend;
use OPNsense\Core\Config;
/**
* Class FirmwareController
......@@ -384,4 +385,95 @@ class FirmwareController extends ApiControllerBase
return $response;
}
/**
* list firmware mirror and flavour options
* @return array
*/
public function getFirmwareOptionsAction()
{
// todo: we might want to move these into configuration files later
$mirrors = array();
$mirrors['default'] = '(default)';
$mirrors['https://opnsense.aivian.org'] = 'Aivian (Shaoxing, CN)';
$mirrors['https://mirror.auf-feindgebiet.de/opnsense'] = 'auf-feindgebiet.de (Karlsruhe, DE)';
$mirrors['https://opnsense.c0urier.net'] = 'c0urier.net (Lund, SE)';
$mirrors['https://fleximus.org/mirror/opnsense'] = 'Fleximus (Roubaix, FR)';
$mirrors['http://mirror.ams1.nl.leaseweb.net/opnsense'] = 'LeaseWeb (Amsterdam, NL)';
$mirrors['http://mirror.fra10.de.leaseweb.net/opnsense'] = 'LeaseWeb (Frankfurt, DE)';
$mirrors['http://mirror.sfo12.us.leaseweb.net/opnsense'] = 'LeaseWeb (San Francisco, US)';
$mirrors['http://mirror.wdc1.us.leaseweb.net/opnsense'] = 'LeaseWeb (Washington, D.C., US)';
$mirrors['http://mirrors.nycbug.org/pub/opnsense'] = 'NYC*BUG (New York, US)';
$mirrors['http://pkg.opnsense.org'] = 'OPNsense (Amsterdam, NL)';
$mirrors['http://mirror.ragenetwork.de/opnsense'] = 'RageNetwork (Munich, DE)';
$mirrors['http://mirrors.supranet.net/pub/opnsense'] = 'Supranet Communications (Middleton, US)';
$mirrors['http://mirror.wjcomms.co.uk/opnsense'] = 'WJComms (London, GB)';
$flavours = array();
$flavours['default'] = '(default)';
$flavours['libressl'] = 'LibreSSL';
$flavours['latest'] = 'OpenSSL';
return array("mirrors"=>$mirrors, "flavours" => $flavours);
}
/**
* retrieve current firmware configuration options
* @return array
*/
function getFirmwareConfigAction()
{
$result = array();
if (!empty(Config::getInstance()->object()->system->firmware->mirror)) {
$result['mirror'] = (string)Config::getInstance()->object()->system->firmware->mirror;
} else {
$result['mirror'] = '(default)';
}
if (!empty(Config::getInstance()->object()->system->firmware->flavour)) {
$result['flavour'] = (string)Config::getInstance()->object()->system->firmware->flavour;
} else {
$result['flavour'] = '(default)';
}
return $result;
}
/**
* set firmware configuration options
* @return array status
*/
function setFirmwareConfigAction()
{
$response = array("status" => "failure");
if ($this->request->isPost()) {
$response['status'] = 'ok';
// config data without model, prepare xml structure and write data
if (!isset(Config::getInstance()->object()->system->firmware)) {
Config::getInstance()->object()->system->addChild('firmware');
}
if (!isset(Config::getInstance()->object()->system->firmware->mirror)) {
Config::getInstance()->object()->system->firmware->addChild('mirror');
}
if (!isset(Config::getInstance()->object()->system->firmware->flavour)) {
Config::getInstance()->object()->system->firmware->addChild('flavour');
}
$selectedMirror = filter_var($this->request->getPost("mirror", null, ""), FILTER_SANITIZE_URL);
$selectedFlavour = filter_var($this->request->getPost("flavour", null, ""), FILTER_SANITIZE_URL);
if (!empty($selectedMirror)) {
Config::getInstance()->object()->system->firmware->mirror = $selectedMirror;
} else {
Config::getInstance()->object()->system->firmware->mirror = 'default';
}
if (!empty($selectedFlavour)) {
Config::getInstance()->object()->system->firmware->flavour = $selectedFlavour;
} else {
Config::getInstance()->object()->system->firmware->mirror = 'default';
}
Config::getInstance()->save();
}
return $response;
}
}
......@@ -305,6 +305,36 @@ POSSIBILITY OF SUCH DAMAGE.
updateStatus();
}
});
// fetch firmware options
ajaxGet('/api/core/firmware/getFirmwareOptions',{},function(firmwareoptions, status) {
ajaxGet('/api/core/firmware/getFirmwareConfig',{},function(firmwareconfig, status) {
$.each(firmwareoptions.mirrors, function(key, value) {
var selected = false;
if (firmwareconfig['mirror'].indexOf(key) == 0) {
selected = true;
}
$("#firmware_mirror").append($("<option/>").attr("value",key).text(value).prop('selected', selected));
});
$("#firmware_mirror").selectpicker('refresh');
$.each(firmwareoptions.flavours, function(key, value) {
var selected = false;
if (key == firmwareconfig['flavour']) {
selected = true;
}
$("#firmware_flavour").append($("<option/>").attr("value",key).text(value).prop('selected', selected));
});
$("#firmware_flavour").selectpicker('refresh');
});
});
$("#change_mirror").click(function(){
var confopt = {};
confopt.mirror = $("#firmware_mirror").val()
confopt.flavour = $("#firmware_flavour").val()
ajaxCall(url='/api/core/firmware/setFirmwareConfig',sendData=confopt);
});
});
</script>
......@@ -320,13 +350,43 @@ POSSIBILITY OF SUCH DAMAGE.
<div class="row">
<div class="col-md-12" id="content">
<ul class="nav nav-tabs" data-tabs="tabs">
<li id="packagestab" class="active"><a data-toggle="tab" href="#packages">{{ lang._('Packages') }}</a></li>
<li id="settingstab" class="active"><a data-toggle="tab" href="#settings">{{ lang._('Settings') }}</a></li>
<li id="packagestab"><a data-toggle="tab" href="#packages">{{ lang._('Packages') }}</a></li>
<li id="plugintab"><a data-toggle="tab" href="#plugins">{{ lang._('Plugins') }}</a></li>
<li id="updatetab"><a data-toggle="tab" href="#updates">{{ lang._('Updates') }}</a></li>
<li id="progresstab"><a data-toggle="tab" href="#progress">{{ lang._('Progress') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="packages" class="tab-pane fade in active">
<div id="settings" class="tab-pane fade in active">
<table class="table table-striped table-responsive">
<tbody>
<tr>
<td style="width: 150px;">{{ lang._('Firmware Mirror') }}</td>
<td>
<select class="selectpicker" id="firmware_mirror">
</select>
</td>
<td></td>
</tr>
<tr>
<td>{{ lang._('Firmware Flavour') }}</td>
<td>
<select class="selectpicker" id="firmware_flavour">
</select>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<button class="btn btn-primary" id="change_mirror" type="button"><b>{{ lang._('Change') }}</b></button>
</td>
<td></td>
</tr>
</tbody>
</table>
</div>
<div id="packages" class="tab-pane fade in">
<table class="table table-striped table-condensed table-responsive" id="packageslist">
</table>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment