diff --git a/src/usr/local/emhttp/plugins/tailscale/daily.php b/src/usr/local/emhttp/plugins/tailscale/daily.php index eb26dc9..ea79ebd 100755 --- a/src/usr/local/emhttp/plugins/tailscale/daily.php +++ b/src/usr/local/emhttp/plugins/tailscale/daily.php @@ -4,6 +4,7 @@ $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'; require_once "{$docroot}/plugins/tailscale/include/common.php"; +require_once "{$docroot}/plugins/tailscale/include/tailscale-status.php"; foreach (glob("{$docroot}/plugins/tailscale/include/daily/*.php") as $file) { require_once $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 bb6c604..ba0ec27 100755 --- a/src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php +++ b/src/usr/local/emhttp/plugins/tailscale/include/daily/ping.php @@ -2,10 +2,24 @@ $endpoint = "https://plugin-usage.edacerton.win/"; -function send_usage($url) +function send_usage($url, $content) { + $body = json_encode($content); + $token = file_get_contents($url . '?connect'); + $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); + + $headers = [ + 'Content-Type: application/json', + 'Authorization: Bearer ' . $token + ]; + + curl_setopt($c, CURLOPT_POST, true); + curl_setopt($c, CURLOPT_POSTFIELDS, $body); + curl_setopt($c, CURLOPT_HTTPHEADER, $headers); + curl_setopt($c, CURLOPT_USERAGENT, 'plugin-metrics/1.0.0'); + curl_exec($c); if ( ! curl_errno($c)) { $info = curl_getinfo($c); @@ -20,17 +34,38 @@ function send_usage($url) } $version = parse_ini_file('/var/local/emhttp/plugins/tailscale/tailscale.ini'); - $query = array( + + $prefs = getTailscalePrefs(); + + $exit = false; + $subnet = false; + foreach($prefs->AdvertiseRoutes as $net) + { + switch ($net) { + case "0.0.0.0/0": + case "::/0": + $exit = true; + break; + default: + $subnet = true; + break; + } + } + + $content = array( 'clientId' => hash("crc32b", $var['flashGUID']), 'plugin' => 'tailscale', - 'version' => $version['VERSION'], - 'branch' => $version['BRANCH'], - 'unraid' => $var['version'] + 'plugin_version' => $version['VERSION'], + 'plugin_branch' => $version['BRANCH'], + 'unraid_version' => $var['version'], + 'bool1' => boolval($tailscale_config['ACCEPT_DNS']), + 'bool2' => boolval($tailscale_config['ACCEPT_ROUTES']), + 'bool3' => boolval($tailscale_config['INCLUDE_INTERFACE']), + 'bool4' => $subnet, + 'bool5' => $exit ); - $queryString = http_build_query($query); - - logmsg("Sending usage data: {$queryString}"); + logmsg("Sending usage data"); $attempts = 0; $delay = 0; do { @@ -38,10 +73,10 @@ function send_usage($url) $delay = 300; $attempts++; - $result = send_usage("{$endpoint}?{$queryString}"); - } while (($result != '201') && ($attempts < 3)); + $result = send_usage($endpoint, $content); + } while (($result != '200') && ($attempts < 3)); - if ($result != '201') { + if ($result != '200') { logmsg("Error occurred while transmitting usage data."); } } else {