doti3/bar/src/ip_wan.php
2019-01-28 11:13:11 +01:00

35 lines
687 B
PHP
Executable file

#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$ipv6 = !empty($argv[1]);
$iface = 'wan';
$command = sprintf(
'dig +short myip.opendns.com @resolver1.opendns.com',
$ipv6 ? '-6' : null
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('export DISPLAY=:0; echo '.escapeshellarg($ip).' | xclip');
shell_exec('export DISPLAY=:0; echo '.escapeshellarg($ip).' | xclip -sel clip');
}
$fullText = pspan($iface, '#ccc', '#222').pspan($ip, '#ddd', '#000');
echo block(
'ip_wan',
[
'full_text' => $fullText,
'separator' => false,
'separator_block_width' => 0,
]
);