net/wireguard: Late Spring Cleaning (#3116)

This commit is contained in:
Patrik Kernstock
2022-10-12 13:32:20 +02:00
committed by GitHub
parent 3e0372e05b
commit 1a9b9a4212
5 changed files with 37 additions and 13 deletions
@@ -41,23 +41,28 @@ class ClientController extends ApiMutableModelControllerBase
{
return $this->searchBase('clients.client', array("enabled", "name", "pubkey", "tunneladdress", "serveraddress", "serverport"));
}
public function getClientAction($uuid = null)
{
$this->sessionClose();
return $this->getBase('client', 'clients.client', $uuid);
}
public function addClientAction()
{
return $this->addBase('client', 'clients.client');
}
public function delClientAction($uuid)
{
return $this->delBase('clients.client', $uuid);
}
public function setClientAction($uuid)
{
return $this->setBase('client', 'clients.client', $uuid);
}
public function toggleClientAction($uuid)
{
return $this->toggleBase('clients.client', $uuid);
@@ -38,13 +38,20 @@ class ServerController extends ApiMutableModelControllerBase
public function searchServerAction()
{
return $this->searchBase('servers.server', array("enabled", "name", "networks", "pubkey", "port", "tunneladdress"));
$search = $this->searchBase('servers.server', array("enabled", "instance", "peers", "name", "networks", "pubkey", "port", "tunneladdress"));
// prepend "wg" to all instance IDs to use as interface name
foreach ($search["rows"] as $key => $server) {
$search["rows"][$key]["interface"] = "wg" . $server["instance"];
}
return $search;
}
public function getServerAction($uuid = null)
{
$this->sessionClose();
return $this->getBase('server', 'servers.server', $uuid);
}
public function addServerAction($uuid = null)
{
if ($this->request->isPost() && $this->request->hasPost("server")) {
@@ -66,10 +73,12 @@ class ServerController extends ApiMutableModelControllerBase
}
return array("result" => "failed");
}
public function delServerAction($uuid)
{
return $this->delBase('servers.server', $uuid);
}
public function setServerAction($uuid = null)
{
if ($this->request->isPost() && $this->request->hasPost("server")) {
@@ -91,6 +100,7 @@ class ServerController extends ApiMutableModelControllerBase
}
return array("result" => "failed");
}
public function toggleServerAction($uuid)
{
return $this->toggleBase('servers.server', $uuid);
@@ -21,7 +21,7 @@
<id>client.psk</id>
<label>Shared Secret</label>
<type>text</type>
<help>Shared secret (PSK) for this peer.</help>
<help>Shared secret (PSK) for this peer. You can generate a key using "wg genpsk" on a client with WireGuard installed.</help>
</field>
<field>
<id>client.tunneladdress</id>
@@ -45,8 +45,8 @@
</field>
<field>
<id>client.keepalive</id>
<label>Keepalive</label>
<label>Keepalive Interval</label>
<type>text</type>
<help>Set persistent keepalive interval.</help>
<help>Set persistent keepalive interval in seconds.</help>
</field>
</form>
@@ -15,19 +15,19 @@
<id>server.instance</id>
<label>Instance</label>
<type>info</type>
<help>Set the instance number needed for interface calculation. It has to be unique for each instance.</help>
<help>This is the instance number to give the wg interface a unique name (wgX).</help>
</field>
<field>
<id>server.pubkey</id>
<label>Public Key</label>
<type>text</type>
<help>Public key of this instance. After saving you will see here your public key.</help>
<help>Public key of this instance. You can specify your own one, or a key will be generated after saving.</help>
</field>
<field>
<id>server.privkey</id>
<label>Private Key</label>
<type>text</type>
<help>Private key of this instance. After saving you will see here your private key, please keep it safe.</help>
<help>Private key of this instance. You can specify your own one, or a key will be generated after saving. Please keep this key safe.</help>
</field>
<field>
<id>server.port</id>
@@ -30,7 +30,7 @@
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
<li><a data-toggle="tab" href="#servers">{{ lang._('Local') }}</a></li>
<li><a data-toggle="tab" href="#clients">{{ lang._('Endpoints') }}</a></li>
<li><a data-toggle="tab" href="#showconf">{{ lang._('List Configuration') }}</a></li>
<li><a data-toggle="tab" href="#showconf">{{ lang._('Status') }}</a></li>
<li><a data-toggle="tab" href="#showhandshake">{{ lang._('Handshakes') }}</a></li>
</ul>
@@ -51,6 +51,7 @@
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
<th data-column-id="serveraddress" data-type="string" data-visible="true">{{ lang._('Endpoint Address') }}</th>
<th data-column-id="serverport" data-type="string" data-visible="true">{{ lang._('Endpoint Port') }}</th>
<th data-column-id="tunneladdress" data-type="string" data-visible="true">{{ lang._('Allowed IPs') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
@@ -60,7 +61,7 @@
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td colspan="6"></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
</td>
@@ -79,8 +80,10 @@
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
<th data-column-id="port" data-type="string" data-visible="true">{{ lang._('Port') }}</th>
<th data-column-id="interface" data-type="string" data-visible="true">{{ lang._('Interface') }}</th>
<th data-column-id="tunneladdress" data-type="string" data-visible="true">{{ lang._('Tunnel Address') }}</th>
<th data-column-id="port" data-type="string" data-visible="true">{{ lang._('Port') }}</th>
<th data-column-id="peers" data-type="string" data-visible="true">{{ lang._('Endpoints') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
@@ -89,7 +92,7 @@
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td colspan="7"></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
</td>
@@ -136,7 +139,8 @@ $( document ).ready(function() {
});
$("#grid-clients").UIBootgrid(
{ 'search':'/api/wireguard/client/searchClient',
{
'search':'/api/wireguard/client/searchClient',
'get':'/api/wireguard/client/getClient/',
'set':'/api/wireguard/client/setClient/',
'add':'/api/wireguard/client/addClient/',
@@ -146,7 +150,8 @@ $( document ).ready(function() {
);
$("#grid-servers").UIBootgrid(
{ 'search':'/api/wireguard/server/searchServer',
{
'search':'/api/wireguard/server/searchServer',
'get':'/api/wireguard/server/getServer/',
'set':'/api/wireguard/server/setServer/',
'add':'/api/wireguard/server/addServer/',
@@ -155,6 +160,10 @@ $( document ).ready(function() {
}
);
// Call update funcs once when page loaded
update_showconf();
update_showhandshake();
// Call function update_neighbor with a auto-refresh of 5 seconds
setInterval(update_showconf, 5000);
setInterval(update_showhandshake, 5000);