mirror of
https://github.com/opnsense/plugins.git
synced 2026-06-03 22:08:11 -04:00
netbird: add option/auth banner (#5404)
This commit is contained in:
parent
0ae49cfafc
commit
0a45144c4e
8 changed files with 62 additions and 36 deletions
|
|
@ -1,5 +1,5 @@
|
|||
PLUGIN_NAME= netbird
|
||||
PLUGIN_VERSION= 1.2
|
||||
PLUGIN_VERSION= 1.3
|
||||
PLUGIN_DEPENDS= netbird
|
||||
PLUGIN_COMMENT= Peer-to-peer VPN that seamlessly connects your devices
|
||||
PLUGIN_MAINTAINER= dev@netbird.io
|
||||
|
|
|
|||
|
|
@ -48,23 +48,21 @@ class AuthenticationController extends ApiMutableModelControllerBase
|
|||
{
|
||||
$mdl = new Authentication();
|
||||
|
||||
$managementUrl = $mdl->managementUrl->__toString();
|
||||
$setupKey = $mdl->setupKey->__toString();
|
||||
$managementUrl = $mdl->managementUrl->getValue();
|
||||
$setupKey = $mdl->setupKey->getValue();
|
||||
|
||||
$defaultKey = '00000000-0000-0000-0000-000000000000';
|
||||
if (!empty($setupKey) && $setupKey !== $defaultKey) {
|
||||
$visiblePart = substr($setupKey, 0, 4);
|
||||
$maskedKey = $visiblePart . str_repeat('*', max(4, strlen($setupKey) - 4));
|
||||
} else {
|
||||
$maskedKey = $defaultKey;
|
||||
}
|
||||
|
||||
return [
|
||||
$result = [
|
||||
'authentication' => [
|
||||
'managementUrl' => $managementUrl,
|
||||
'setupKey' => $maskedKey
|
||||
'setupKey' => '',
|
||||
]
|
||||
];
|
||||
|
||||
if (!empty($setupKey)) {
|
||||
$result['authentication']['%setupKey'] = substr($setupKey, 0, 5) . str_repeat('*', max(0, strlen($setupKey) - 7));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function upAction()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<id>authentication.setupKey</id>
|
||||
<label>Setup Key</label>
|
||||
<type>text</type>
|
||||
<hint>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</hint>
|
||||
<help>Set the authentication setup key</help>
|
||||
</field>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,14 @@
|
|||
<type>text</type>
|
||||
<help>Wireguard interface listening port</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>settings.general.ipmapping</id>
|
||||
<label>Force IP Mapping</label>
|
||||
<type>text</type>
|
||||
<hint>12.34.56.78</hint>
|
||||
<help>Forces external IPs maps between local addresses and interfaces. You can specify a comma-separated list with a single IP or IP/IP or IP/Interface Name. Leave empty for automatic mapping.</help>
|
||||
<advanced>true</advanced>
|
||||
</field>
|
||||
<field>
|
||||
<type>header</type>
|
||||
<label>Client Firewall</label>
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
<items>
|
||||
<managementUrl type="UrlField">
|
||||
<Required>Y</Required>
|
||||
<Default>https://api.netbird.io:443</Default>
|
||||
<Default>https://api.netbird.io</Default>
|
||||
</managementUrl>
|
||||
<setupKey type="TextField">
|
||||
<!-- XXX fails migration for obvious reasons <Required>Y</Required> -->
|
||||
<setupKey type="UpdateOnlyTextField">
|
||||
<Mask>/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i</Mask>
|
||||
<ValidationMessage>Please specify a valid setup key.</ValidationMessage>
|
||||
</setupKey>
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ class Settings extends BaseModel
|
|||
|
||||
$config["WgPort"] = (int)$this->general->wireguardPort->__toString();
|
||||
$config["ServerSSHAllowed"] = $this->ssh->enable->__toString() == 1;
|
||||
$config["IpMapping"] = $this->general->ipmapping->__toString();
|
||||
$config["EnableSSHRoot"] = $this->ssh->enableRoot->__toString() == 1;
|
||||
$config["EnableSSHSFTP"] = $this->ssh->enableSFTP->__toString() == 1;
|
||||
$config["EnableSSHLocalPortForwarding"] = $this->ssh->enableLocalPortForwarding->__toString() == 1;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@
|
|||
<maximum>65535</maximum>
|
||||
<ValidationMessage>Please specify a valid port.</ValidationMessage>
|
||||
</wireguardPort>
|
||||
<ipmapping type="TextField">
|
||||
<MaskPerItem>Y</MaskPerItem>
|
||||
<Mask>/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}(?:\/(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}|[a-zA-Z][a-zA-Z0-9_.-]*))?$/u</Mask>
|
||||
<ValidationMessage>Invalid syntax. E.g. 12.34.56.78 or 12.34.56.78/10.0.0.1 or 12.34.56.200,12.34.56.78/10.0.0.1,12.34.56.80/eth1</ValidationMessage>
|
||||
</ipmapping>
|
||||
</general>
|
||||
<firewall>
|
||||
<allowConfig type="BooleanField">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{#
|
||||
# Copyright (C) 2026 Konstantinos Spartalis <cspartalis@potatonetworks.com>
|
||||
# Copyright (C) 2025 Ralph Moser, PJ Monitoring GmbH
|
||||
# Copyright (C) 2025 squared GmbH
|
||||
# Copyright (C) 2025 Christopher Linn, BackendMedia IT-Services GmbH
|
||||
|
|
@ -29,20 +30,39 @@
|
|||
|
||||
<script>
|
||||
function updateNetBirdStatusUI() {
|
||||
ajaxGet('/api/netbird/status/status', {}, (data) => {
|
||||
const $connectBtn = $("#connectBtn");
|
||||
const $disconnectBtn = $("#disconnectBtn");
|
||||
ajaxGet('/api/netbird/settings/get', {}, (settings) => {
|
||||
const isEnabled = settings.settings?.general?.enable === '1';
|
||||
|
||||
$("#netbird-actions").removeClass("hidden");
|
||||
const updateUI = (isConnected) => {
|
||||
const $connectBtn = $("#connectBtn");
|
||||
const $disconnectBtn = $("#disconnectBtn");
|
||||
|
||||
const isConnected = data.management?.connected === true;
|
||||
const message = isConnected ? "NetBird is connected" : "NetBird is not connected";
|
||||
const type = isConnected ? "info" : "warning";
|
||||
$("#netbird-actions").removeClass("hidden");
|
||||
|
||||
$connectBtn.toggleClass("hidden", isConnected);
|
||||
$disconnectBtn.toggleClass("hidden", !isConnected);
|
||||
let message;
|
||||
let type;
|
||||
if (!isEnabled) {
|
||||
message = "Enable NetBird first";
|
||||
type = "warning";
|
||||
} else {
|
||||
message = isConnected ? "NetBird is connected" : "NetBird is not connected";
|
||||
type = isConnected ? "info" : "warning";
|
||||
}
|
||||
|
||||
$("#status").removeClass().addClass("alert alert-" + type).text(message).show();
|
||||
$connectBtn.toggleClass("hidden", isConnected);
|
||||
$disconnectBtn.toggleClass("hidden", !isConnected);
|
||||
|
||||
$("#status").removeClass().addClass("alert alert-" + type).text(message).show();
|
||||
};
|
||||
|
||||
if (!isEnabled) {
|
||||
updateUI(false);
|
||||
} else {
|
||||
ajaxGet('/api/netbird/status/status', {}, (data) => {
|
||||
const isConnected = data.management?.connected === true;
|
||||
updateUI(isConnected);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -57,17 +77,11 @@
|
|||
$("#connectBtn").SimpleActionButton({
|
||||
onPreAction: () => {
|
||||
const dfObj = new $.Deferred();
|
||||
const setupKey = $("#authentication\\.setupKey").val();
|
||||
|
||||
if (setupKey.includes("*")) {
|
||||
saveFormToEndpoint("/api/netbird/authentication/set", 'frmAuthentication', () => {
|
||||
dfObj.resolve();
|
||||
} else {
|
||||
saveFormToEndpoint("/api/netbird/authentication/set", 'frmAuthentication', () => {
|
||||
dfObj.resolve();
|
||||
}, true, () => {
|
||||
dfObj.reject();
|
||||
});
|
||||
}
|
||||
}, true, () => {
|
||||
dfObj.reject();
|
||||
});
|
||||
return dfObj;
|
||||
},
|
||||
onAction: () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue