net/haproxy: allow to enable/disable servers, closes #1208

This commit is contained in:
Frank Wall
2019-02-25 23:57:44 +01:00
parent efd35b1984
commit 1cfc259e0b
6 changed files with 63 additions and 1 deletions
@@ -123,9 +123,14 @@ class SettingsController extends ApiMutableModelControllerBase
return $this->delBase('servers.server', $uuid);
}
public function toggleServerAction($uuid, $enabled = null)
{
return $this->toggleBase('servers.server', $uuid);
}
public function searchServersAction()
{
return $this->searchBase('servers.server', array('name', 'address', 'port', 'description'), 'name');
return $this->searchBase('servers.server', array('enabled', 'name', 'address', 'port', 'description'), 'name');
}
public function getHealthcheckAction($uuid = null)
@@ -1,4 +1,10 @@
<form>
<field>
<id>server.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Enable this server.</help>
</field>
<field>
<id>server.name</id>
<label>Name</label>
@@ -1008,6 +1008,10 @@
<id type="UniqueIdField">
<Required>Y</Required>
</id>
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<name type="TextField">
<mask>/^([0-9a-zA-Z._]){1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters.</ValidationMessage>
@@ -0,0 +1,42 @@
<?php
/**
* Copyright (C) 2019 Frank Wall
*
* 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\HAProxy\Migrations;
use OPNsense\Base\BaseModelMigration;
class M2_7_0 extends BaseModelMigration
{
public function run($model)
{
// Servers have an 'enabled' field now
foreach ($model->getNodeByReference('servers.servers')->iterateItems() as $server) {
$server->enabled = '1';
}
}
}
@@ -79,6 +79,7 @@ POSSIBILITY OF SUCH DAMAGE.
set:'/api/haproxy/settings/setServer/',
add:'/api/haproxy/settings/addServer/',
del:'/api/haproxy/settings/delServer/',
toggle:'/api/haproxy/settings/toggleServer/',
options: {
rowCount:[10,25,50,100,500,1000]
}
@@ -716,6 +717,7 @@ POSSIBILITY OF SUCH DAMAGE.
<table id="grid-servers" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogServer">
<thead>
<tr>
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="serverid" data-type="number" data-visible="false">{{ lang._('Server ID') }}</th>
<th data-column-id="name" data-type="string">{{ lang._('Server Name') }}</th>
<th data-column-id="address" data-type="string">{{ lang._('Server Address') }}</th>
@@ -1373,7 +1373,10 @@ backend {{backend.name}}
{% if server_data.advanced|default("") != "" %}
{% do server_options.append(server_data.advanced) %}
{% endif %}
{# # server enabled? #}
{% if server_data.enabled == '1' %}
server {{server_data.name}} {{server_data.address}}:{% if backend.tuning_noport != '1' %}{% if server_data.port|default("") != "" %}{{server_data.port}}{% endif %}{% endif %} {{server_options|join(' ')}}
{% endif %}
{% endif %}
{% endfor %}