Skip to content

Commit

Permalink
Tailscale integrations - Cleanup and fix bugs in tailscale cli invoca…
Browse files Browse the repository at this point in the history
…tion flows
  • Loading branch information
SneWs committed Jul 10, 2024
1 parent 9bfe932 commit a87a890
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 130 deletions.
124 changes: 9 additions & 115 deletions TailRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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=";
}
}

Expand All @@ -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) {
Expand Down
15 changes: 0 additions & 15 deletions TailRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a87a890

Please sign in to comment.