mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
net/wireguard: use syncconf on newwanip event
This commit is contained in:
@@ -144,7 +144,7 @@ function wireguard_prepare($device)
|
||||
function wireguard_configure()
|
||||
{
|
||||
return [
|
||||
'newwanip' => ['wireguard_renew:2'],
|
||||
'newwanip' => ['wireguard_sync:2'],
|
||||
'vpn' => ['wireguard_configure_do:2'],
|
||||
];
|
||||
}
|
||||
@@ -162,15 +162,33 @@ function wireguard_configure_do($verbose = false, $unused = '')
|
||||
service_log("done.\n", $verbose);
|
||||
}
|
||||
|
||||
function wireguard_renew($verbose = false, $unused = '')
|
||||
function wireguard_sync($verbose = false, $unused = '')
|
||||
{
|
||||
if (!wireguard_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
service_log('Renewing WireGuard VPN...', $verbose);
|
||||
$instances = [];
|
||||
foreach ((new OPNsense\Wireguard\Server())->servers->server->iterateItems() as $node) {
|
||||
if (!empty((string)$node->enabled)) {
|
||||
$instances[(string)$node->interface] = (string)$node->cnfFilename;
|
||||
}
|
||||
}
|
||||
|
||||
configd_run('wireguard renew');
|
||||
if (!count($instances)) {
|
||||
return;
|
||||
}
|
||||
|
||||
service_log('Synchronizing WireGuard VPN...', $verbose);
|
||||
|
||||
openlog('wireguard', LOG_ODELAY, LOG_AUTH);
|
||||
|
||||
foreach ($instances as $device => $config) {
|
||||
mwexecf('/usr/bin/wg syncconf %s %s', [$device, $config]);
|
||||
}
|
||||
|
||||
closelog();
|
||||
reopenlog();
|
||||
|
||||
service_log("done.\n", $verbose);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user