From a87a8904dfa930afcfd6f8ebf6c85e6db5fe899a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Gren=C3=A4ngen?= Date: Wed, 10 Jul 2024 21:16:05 +0200 Subject: [PATCH] Tailscale integrations - Cleanup and fix bugs in tailscale cli invocation flows --- TailRunner.cpp | 124 ++++--------------------------------------------- TailRunner.h | 15 ------ 2 files changed, 9 insertions(+), 130 deletions(-) diff --git a/TailRunner.cpp b/TailRunner.cpp index 4dd6400..e90576a 100644 --- a/TailRunner.cpp +++ b/TailRunner.cpp @@ -47,19 +47,22 @@ void TailRunner::start(bool usePkExec) { if (settings.advertiseAsExitNode()) { args << "--advertise-exit-node"; - if (settings.exitNodeAllowLanAccess()) - args << "--exit-node-allow-lan-access"; - else - args << "--exit-node-allow-lan-access=false"; } else { - args << "--advertise-exit-node=false"; - // Check if we have a exit node that we should use auto exitNode = settings.exitNodeInUse(); if (!exitNode.isEmpty()) { qDebug() << "Will use exit node" << exitNode; args << "--exit-node" << exitNode; + + if (settings.exitNodeAllowLanAccess()) + args << "--exit-node-allow-lan-access"; + else + args << "--exit-node-allow-lan-access=false"; + } + else { + + args << "--exit-node="; } } @@ -71,115 +74,6 @@ void TailRunner::stop() { runCommand("down", QStringList()); } -void TailRunner::setUseTailscaleDns(bool use) { - eCommand = Command::SettingsChange; - QStringList args; - if (use) { - args << "--accept-dns"; - } - else { - args << "--accept-dns=false"; - } - runCommand("set", args); -} - -void TailRunner::setAcceptRoutes(bool accept) { - eCommand = Command::SettingsChange; - QStringList args; - if (accept) { - args << "--accept-routes"; - } - else { - args << "--accept-routes=false"; - } - runCommand("set", args); -} - -void TailRunner::allowIncomingConnections(bool allow) { - eCommand = Command::SettingsChange; - QStringList args; - if (allow) { - args << "--shields-up=false"; - } - else { - args << "--shields-up"; - } - runCommand("set", args, false, true); -} - -void TailRunner::setOperator(const QString& username) { - eCommand = Command::SettingsChange; - QStringList args; - if (!username.isEmpty()) { - qDebug() << "Setting operator to " << username; - args << "--operator" << username; - } - else { - args << "--operator"; - } - runCommand("set", args, false, true); -} - -void TailRunner::useExitNode(const TailDeviceInfo* exitNode) { - eCommand = Command::SettingsChange; - QStringList args; - if (exitNode != nullptr) { - args << "--exit-node" << exitNode->tailscaleIPs.first(); - } - else { - args << "--exit-node" << ""; - } - runCommand("set", args); -} - -void TailRunner::advertiseAsExitNode(bool enabled) { - eCommand = Command::SettingsChange; - QStringList args; - if (enabled) { - args << "--advertise-exit-node"; - } - else { - args << "--advertise-exit-node=false"; - } - runCommand("set", args); -} - -void TailRunner::exitNodeAllowLanAccess(bool enabled) { - eCommand = Command::SettingsChange; - QStringList args; - if (enabled) { - args << "--exit-node-allow-lan-access"; - } - else { - args << "--exit-node-allow-lan-access=false"; - } - - runCommand("set", args); -} - -void TailRunner::useExitNode(const QString & exitNodeName) { - // - eCommand = Command::SettingsChange; - QStringList args; - if (!exitNodeName.isEmpty()) { - args << "--exit-node=" + exitNodeName; - } - else { - args << "--exit-node="; - } - - runCommand("set", args); -} - -void TailRunner::setAsExitNode(TailDeviceInfo* thisDevice, bool allowLocalNetworkAccess) { - eCommand = Command::SettingsChange; - QStringList args; - args << "--advertise-exit-node"; - if (allowLocalNetworkAccess) - args << "--exit-node-allow-lan-access"; - runCommand("set", args); -} - void TailRunner::runCommand(QString cmd, QStringList args, bool jsonResult, bool usePkExec) { if (pProcess != nullptr) { if (pProcess->state() == QProcess::Running) { diff --git a/TailRunner.h b/TailRunner.h index c5c3591..41dcb21 100644 --- a/TailRunner.h +++ b/TailRunner.h @@ -21,21 +21,6 @@ class TailRunner : public QObject void start(bool usePkExec = false); void stop(); - void setUseTailscaleDns(bool use); - void setAcceptRoutes(bool accept); - void allowIncomingConnections(bool allow); - void setOperator(const QString &username); - void useExitNode(const TailDeviceInfo* exitNode); - - void setAsExitNode(TailDeviceInfo* thisDevice, bool allowLocalNetworkAccess); - - // For this machine to be a exit node - void advertiseAsExitNode(bool enabled); - void exitNodeAllowLanAccess(bool enabled); - - // For this machine to use a exit node - void useExitNode(const QString& exitNodeName); - private: const TailSettings& settings; QProcess* pProcess;