Skip to content

Commit

Permalink
net/wireguard: Late Spring Cleaning (#3116)
Browse files Browse the repository at this point in the history
  • Loading branch information
patschi committed Oct 12, 2022
1 parent 3e0372e commit 1a9b9a4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,28 @@ public function searchClientAction()
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -66,10 +73,12 @@ public function addServerAction($uuid = null)
}
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")) {
Expand All @@ -91,6 +100,7 @@ public function setServerAction($uuid = null)
}
return array("result" => "failed");
}

public function toggleServerAction($uuid)
{
return $this->toggleBase('servers.server', $uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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/',
Expand All @@ -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/',
Expand All @@ -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);
Expand Down

0 comments on commit 1a9b9a4

Please sign in to comment.