doti3/bar/src/wireguard.php

40 lines
914 B
PHP
Executable file

#!/usr/bin/env php
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'wg0';
$name = $argv[2] ?? strtoupper($iface);
$command = 'sudo wg show '.escapeshellarg($iface).' 2>/dev/null';
$output = trim(shell_exec($command));
if (empty($output)) {
echo block(
'wireguard_'.$iface,
[
'full_text' => pspan($name, color('warning'), '#000'),
'color' => color('warning'),
]
);
if (getenv('BLOCK_BUTTON') === '1') {
$command = 'sudo wg-quick up '.escapeshellarg($iface);
shell_exec($command);
}
} else {
echo block(
'wireguard_'.$iface,
[
'full_text' => pspan($name, color('normal'), '#000'),
'color' => color('normal'),
]
);
if (getenv('BLOCK_BUTTON') === '1') {
$command = 'sudo wg-quick down '.escapeshellarg($iface);
shell_exec($command);
}
}