From c131c6f53a29144128644a53b234fbb92ea05c7a Mon Sep 17 00:00:00 2001 From: Derek Kaser Date: Sat, 15 Jul 2023 23:28:45 -0400 Subject: [PATCH] feat: check result when changing tailscale settings --- .../local/emhttp/plugins/tailscale/daily.php | 2 +- .../plugins/tailscale/include/daily/ping.php | 11 ++++--- .../tailscale-watcher/apply-settings.php | 30 ++++++++++++------- .../plugins/tailscale/tailscale-watcher.php | 1 - 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/usr/local/emhttp/plugins/tailscale/daily.php b/src/usr/local/emhttp/plugins/tailscale/daily.php index 742699a..eb26dc9 100755 --- a/src/usr/local/emhttp/plugins/tailscale/daily.php +++ b/src/usr/local/emhttp/plugins/tailscale/daily.php @@ -7,4 +7,4 @@ foreach (glob("{$docroot}/plugins/tailscale/include/daily/*.php") as $file) { require_once $file; -} \ No newline at end of file +} diff --git a/src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php b/src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php index d262321..6ba8d6d 100755 --- a/src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php +++ b/src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php @@ -3,15 +3,15 @@ $endpoint = "https://plugin-usage.edacerton.win/"; if ($tailscale_config['USAGE']) { - if (! isset($var)) { + if ( ! isset($var)) { $var = parse_ini_file('/usr/local/emhttp/state/var.ini'); } $version = parse_ini_file('/var/local/emhttp/plugins/tailscale/tailscale.ini'); - $query = array( + $query = array( 'clientId' => hash("crc32b", $var['flashGUID']), - 'plugin' => 'tailscale', - 'version' => $version['VERSION'] + 'plugin' => 'tailscale', + 'version' => $version['VERSION'] ); $queryString = http_build_query($query); @@ -20,8 +20,7 @@ $request = file_get_contents("{$endpoint}?{$queryString}"); - if( ! mb_strpos($http_response_header[0],'201')) - { + if ( ! mb_strpos($http_response_header[0], '201')) { logmsg("Error occurred while transmitting usage data."); } } else { diff --git a/src/usr/local/emhttp/plugins/tailscale/include/tailscale-watcher/apply-settings.php b/src/usr/local/emhttp/plugins/tailscale/include/tailscale-watcher/apply-settings.php index 086053b..97fd58d 100644 --- a/src/usr/local/emhttp/plugins/tailscale/include/tailscale-watcher/apply-settings.php +++ b/src/usr/local/emhttp/plugins/tailscale/include/tailscale-watcher/apply-settings.php @@ -1,27 +1,35 @@ &1", $output, $retval); + if ($retval != 0) { + logmsg("Command returned {$retval}" . PHP_EOL . implode(PHP_EOL, $output)); + } +} + $command = "Ignoring accept-routes"; switch ($settings_config['ACCEPT_ROUTES']) { case 0: - $command = "/usr/local/sbin/tailscale set --accept-routes=false"; - exec($command); + run_command("/usr/local/sbin/tailscale set --accept-routes=false"); break; case 1: - $command = "/usr/local/sbin/tailscale set --accept-routes=true"; - exec($command); + run_command("/usr/local/sbin/tailscale set --accept-routes=true"); break; + default: + logmsg("Ignoring accept-routes"); } -logmsg($command); -$command = "Ignoring accept-dns"; switch ($settings_config['ACCEPT_DNS']) { case 0: - $command = "/usr/local/sbin/tailscale set --accept-dns=false"; - exec($command); + run_command("/usr/local/sbin/tailscale set --accept-dns=false"); break; case 1: - $command = "/usr/local/sbin/tailscale set --accept-dns=true"; - exec($command); + run_command("/usr/local/sbin/tailscale set --accept-dns=true"); break; + default: + logmsg("Ignoring accept-dns"); } -logmsg($command); \ No newline at end of file diff --git a/src/usr/local/emhttp/plugins/tailscale/tailscale-watcher.php b/src/usr/local/emhttp/plugins/tailscale/tailscale-watcher.php index 6541a50..5fa7c57 100755 --- a/src/usr/local/emhttp/plugins/tailscale/tailscale-watcher.php +++ b/src/usr/local/emhttp/plugins/tailscale/tailscale-watcher.php @@ -30,6 +30,5 @@ foreach (glob("{$docroot}/plugins/tailscale/include/tailscale-watcher/*.php") as $file) { require_once $file; } - } }