Skip to content

Commit

Permalink
feat: check result when changing tailscale settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaser committed Jul 16, 2023
1 parent 2fe75ae commit c131c6f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/usr/local/emhttp/plugins/tailscale/daily.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

foreach (glob("{$docroot}/plugins/tailscale/include/daily/*.php") as $file) {
require_once $file;
}
}
11 changes: 5 additions & 6 deletions src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<?php

function run_command($command)
{
$output = null;
$retval = null;
logmsg($command);
exec("{$command} 2>&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);
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
foreach (glob("{$docroot}/plugins/tailscale/include/tailscale-watcher/*.php") as $file) {
require_once $file;
}

}
}

0 comments on commit c131c6f

Please sign in to comment.