Skip to content

Commit 71e119e

Browse files
committed
feat: add configuration option for auto update
Signed-off-by: Derek Kaser <[email protected]>
1 parent a1d5a55 commit 71e119e

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

src/usr/local/emhttp/plugins/tailscale/include/Pages/Tailscale.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ function showTailscaleConfig() {
8181
var res = await $.post('/plugins/tailscale/include/data/Config.php',{action: 'set-feature', feature: feature, enable: enable});
8282
showTailscaleConfig();
8383
}
84+
async function setAutoUpdate(enable) {
85+
$('div.spinner.fixed').show('fast');
86+
tailscaleControlsDisabled(true);
87+
var res = await $.post('/plugins/tailscale/include/data/Config.php',{action: 'set-auto-update', enable: enable});
88+
showTailscaleConfig();
89+
}
8490
async function setAdvertiseExitNode(enable) {
8591
$('div.spinner.fixed').show('fast');
8692
tailscaleControlsDisabled(true);

src/usr/local/emhttp/plugins/tailscale/include/data/Config.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
"<input type='button' value='{$tr->tr("disable")}' onclick='setFeature(\"ssh\", false)'>" :
7171
"<input type='button' value='{$tr->tr("enable")}' onclick='setFeature(\"ssh\", true)'>";
7272

73+
$autoUpdateButton = $tailscaleInfo->autoUpdateEnabled() ?
74+
"<input type='button' value='{$tr->tr("disable")}' onclick='setAutoUpdate(false)'>" :
75+
"<input type='button' value='{$tr->tr("enable")}' onclick='setAutoUpdate(true)'>";
76+
7377
$advertiseExitButton = $tailscaleInfo->usesExitNode() ? "<input type='button' value='{$tr->tr("enable")}' disabled>" :
7478
(
7579
$tailscaleInfo->advertisesExitNode() ?
@@ -103,6 +107,7 @@
103107
$relayPortWarning = $relayPort !== "" && ! $tailscaleInfo->isApprovedPeerRelay() ? $tr->tr("warnings.peer_relay_no_acl") : "&nbsp;";
104108

105109
$configRows = <<<EOT
110+
<tr><td>{$tr->tr("info.auto_update")}</td><td>{$tailscaleConInfo->AutoUpdate}</td><td style="text-align: right;">{$autoUpdateButton}</td></tr>
106111
<tr><td>{$tr->tr("info.accept_routes")}</td><td>{$tailscaleConInfo->AcceptRoutes}</td><td style="text-align: right;">{$acceptRoutesButton}</td></tr>
107112
<tr><td>{$tr->tr("info.accept_dns")}</td><td>{$tailscaleConInfo->AcceptDNS}</td><td style="text-align: right;">{$acceptDNSButton}</td></tr>
108113
<tr><td>{$tr->tr("info.run_ssh")}</td><td>{$tailscaleConInfo->RunSSH}</td><td style="text-align: right;">{$sshButton}</td></tr>
@@ -304,6 +309,16 @@
304309
$utils->logmsg("Expiring node key");
305310
$localAPI->expireKey();
306311
break;
312+
case 'set-auto-update':
313+
if ( ! isset($_POST['enable'])) {
314+
throw new \Exception("Missing enable parameter");
315+
}
316+
317+
$enable = filter_var($_POST['enable'], FILTER_VALIDATE_BOOLEAN);
318+
$utils->logmsg("Setting auto update to " . ($enable ? "true" : "false"));
319+
320+
$localAPI->setAutoUpdate($enable);
321+
break;
307322
case 'exit-node':
308323
if ( ! isset($_POST['node'])) {
309324
throw new \Exception("Missing node parameter");

src/usr/local/emhttp/plugins/tailscale/locales/en_US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"funnel_port": "Funnel Port for WebGUI",
9090
"port_in_use": "Port in Use",
9191
"peer_relay": "Peer Relay Port",
92+
"auto_update": "Auto Update",
9293
"lock": {
9394
"node_key": "Node Key",
9495
"public_key": "Public Key",

src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/ConnectionInfo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ class ConnectionInfo
3232
public string $ExitNodeLocal = "";
3333
public string $AdvertiseExitNode = "";
3434
public string $UseExitNode = "";
35+
public string $AutoUpdate = "";
3536
}

src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Info.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function getConnectionInfo(): ConnectionInfo
116116
$info->RunSSH = isset($prefs->RunSSH) ? ($prefs->RunSSH ? $this->tr("yes") : $this->tr("no")) : $this->tr("unknown");
117117
$info->ExitNodeLocal = isset($prefs->ExitNodeAllowLANAccess) ? ($prefs->ExitNodeAllowLANAccess ? $this->tr("yes") : $this->tr("no")) : $this->tr("unknown");
118118
$info->UseExitNode = $this->usesExitNode() ? $this->tr("yes") : $this->tr("no");
119+
$info->AutoUpdate = $this->autoUpdateEnabled() ? $this->tr("yes") : $this->tr("no");
119120

120121
if ($this->advertisesExitNode()) {
121122
if ($this->status->Self->ExitNodeOption) {
@@ -498,4 +499,9 @@ public function getRelayServerPort(): int|false
498499
}
499500
return false;
500501
}
502+
503+
public function autoUpdateEnabled(): bool
504+
{
505+
return $this->prefs->AutoUpdate->Apply ?? false;
506+
}
501507
}

src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/LocalAPI.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,13 @@ public function expireKey(): void
140140
{
141141
$this->tailscaleLocalAPI('v0/set-expiry-sooner?expiry=0', APIMethods::POST);
142142
}
143+
144+
public function setAutoUpdate(bool $enabled): void
145+
{
146+
$body = [];
147+
$body["AutoUpdate"] = ["Apply" => $enabled, "Check" => $enabled];
148+
$body["AutoUpdateSet"] = ["ApplySet" => true, "CheckSet" => true];
149+
150+
$this->tailscaleLocalAPI("v0/prefs", APIMethods::PATCH, (object) $body);
151+
}
143152
}

0 commit comments

Comments
 (0)