doti3/bar/src/ip.php
2021-03-03 21:31:06 +01:00

40 lines
839 B
PHP
Executable file

#!/usr/bin/env php
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
$name = ($argv[3] ?? $iface);
$command = sprintf(
'ip address show %s | grep %s | awk \'{ print $2 }\' | tail -n 1 | cut -d/ -f1 | head -n 1',
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
$fullText = pspan($name, '#ccc', '#222').pspan($ip, '#ddd', '#000');
if (getenv('BLOCK_BUTTON') === '1') {
shell_exec('
export DISPLAY=:0
printf '.escapeshellarg($ip).' | xclip -sel clip
notify-send "Valeur copiée" '.escapeshellarg($ip).'
');
}
echo block(
'ip_'.$iface.'_'.trim($inet),
[
'full_text' => $fullText,
'separator' => false,
'separator_block_width' => 0,
]
);