doti3/bar/src/ip.php
2017-12-04 19:41:16 +01:00

35 lines
645 B
PHP
Executable file

#!/usr/bin/php
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
$command = sprintf(
'ip address show %s | grep %s | awk \'{ print $2 }\'',
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$fullText = sprintf('[%s] %s', $iface, $ip);
$shortText = sprintf('%s: %s', $iface, $ip);
if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('echo "'.escapeshellarg($ip).'" | xclip');
}
echo block(
'ip_'.$iface.'_'.trim($inet),
[
'full_text' => $fullText,
'short_text' => $shortText,
]
);