doti3/bar/src/ip.php

40 lines
839 B
PHP
Raw Normal View History

2021-03-03 21:31:06 +01:00
#!/usr/bin/env php
2017-06-19 16:36:59 +02:00
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
2021-03-03 21:31:06 +01:00
$name = ($argv[3] ?? $iface);
2017-06-19 16:36:59 +02:00
$command = sprintf(
2021-03-03 21:31:06 +01:00
'ip address show %s | grep %s | awk \'{ print $2 }\' | tail -n 1 | cut -d/ -f1 | head -n 1',
2017-06-19 16:36:59 +02:00
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
2021-03-03 21:31:06 +01:00
$fullText = pspan($name, '#ccc', '#222').pspan($ip, '#ddd', '#000');
2017-06-19 16:36:59 +02:00
2017-12-04 19:41:16 +01:00
if (getenv('BLOCK_BUTTON') === '1') {
2020-01-14 11:35:27 +01:00
shell_exec('
export DISPLAY=:0
printf '.escapeshellarg($ip).' | xclip -sel clip
notify-send "Valeur copiée" '.escapeshellarg($ip).'
');
2017-12-04 19:41:16 +01:00
}
2017-06-19 16:36:59 +02:00
echo block(
2017-12-04 19:41:16 +01:00
'ip_'.$iface.'_'.trim($inet),
2017-06-19 16:36:59 +02:00
[
'full_text' => $fullText,
2019-01-21 16:20:04 +01:00
'separator' => false,
'separator_block_width' => 0,
2017-06-19 16:36:59 +02:00
]
);