forked from dkaser/unraid-tailscale-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add filter and ping to status page (#20)
- Loading branch information
Showing
3 changed files
with
127 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/usr/local/emhttp/plugins/tailscale/include/data/Status.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Tailscale; | ||
|
||
require_once "/usr/local/emhttp/plugins/tailscale/include/common.php"; | ||
|
||
$tailscaleConfig = $tailscaleConfig ?? new Config(); | ||
$tr = $tr ?? new Translator(); | ||
|
||
switch ($_POST['action']) { | ||
case 'get': | ||
if ( ! $tailscaleConfig->Enable) { | ||
echo("{}"); | ||
return; | ||
} | ||
|
||
$tailscaleInfo = $tailscaleInfo ?? new Info($tr); | ||
$rows = ""; | ||
|
||
foreach ($tailscaleInfo->getPeerStatus() as $peer) { | ||
$user = $peer->SharedUser ? $tr->tr('status_page.shared') : $peer->Name; | ||
$online = $peer->Online ? ($peer->Active ? $tr->tr('status_page.active') : $tr->tr('status_page.idle')) : $tr->tr('status_page.offline'); | ||
$exitNode = $peer->ExitNodeActive ? $tr->tr('status_page.exit_active') : ($peer->ExitNodeAvailable ? $tr->tr('status_page.exit_available') : ""); | ||
$connection = $peer->Active ? ($peer->Relayed ? $tr->tr('status_page.relay') : $tr->tr('status_page.direct')) : ""; | ||
$active = $peer->Active ? $peer->Address : ""; | ||
$txBytes = $peer->Traffic ? $peer->TxBytes : ""; | ||
$rxBytes = $peer->Traffic ? $peer->RxBytes : ""; | ||
$pingHost = ($peer->SharedUser || $peer->Active || ! $peer->Online) ? "" : "<input type='button' class='ping' value='Ping' onclick='pingHost(\"{$peer->Name}\")'>"; | ||
|
||
$rows .= <<<EOT | ||
<tr> | ||
<td>{$user}</td> | ||
<td>{$peer->IP}</td> | ||
<td>{$peer->LoginName}</td> | ||
<td>{$online}</td> | ||
<td>{$exitNode}</td> | ||
<td>{$connection}</td> | ||
<td>{$active}</td> | ||
<td>{$txBytes}</td> | ||
<td>{$rxBytes}</td> | ||
<td>{$pingHost}</td> | ||
</tr> | ||
EOT; | ||
} | ||
|
||
$output = <<<EOT | ||
<table id="t1" class="unraid t1"> | ||
<thead> | ||
<tr> | ||
<td>{$tr->tr('info.dns')}</td> | ||
<td>{$tr->tr('info.ip')}</td> | ||
<td>{$tr->tr('status_page.login_name')}</td> | ||
<td>{$tr->tr('status')}</td> | ||
<td>{$tr->tr('status_page.exit_node')}</td> | ||
<td>{$tr->tr('status_page.connection_type')}</td> | ||
<td>{$tr->tr('status_page.connection_addr')}</td> | ||
<td>{$tr->tr('status_page.tx_bytes')}</td> | ||
<td>{$tr->tr('status_page.rx_bytes')}</td> | ||
<td>{$tr->tr('status_page.action')}</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{$rows} | ||
</tbody> | ||
</table> | ||
EOT; | ||
|
||
$rtn = array(); | ||
$rtn['html'] = $output; | ||
echo json_encode($rtn); | ||
break; | ||
case 'ping': | ||
$pingHost = escapeshellarg($_POST['host']); | ||
|
||
$out = Utils::run_command("tailscale ping --c 3 {$pingHost}"); | ||
echo implode("<br>", $out); | ||
|
||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters