39 lines
779 B
PHP
Executable file
39 lines
779 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 }\' | cut -d/ -f1',
|
|
escapeshellarg($iface),
|
|
escapeshellarg($inet)
|
|
);
|
|
|
|
$ip = trim(shell_exec($command));
|
|
|
|
if (empty($ip)) {
|
|
die;
|
|
}
|
|
|
|
$bwidth = explode(' ', preg_replace('/ +/', ' ', trim(shell_exec('ifstat -i '.escapeshellcmd($iface).' 0.1 1 | tail -n 1'))));
|
|
|
|
if (empty($bwidth)) {
|
|
die;
|
|
}
|
|
|
|
$down = pemoji(0xf0ab).$bwidth[0].'Ko/s ';
|
|
$up = $bwidth[1].'Ko/s'.pemoji(0xf0aa);
|
|
|
|
$fullText = pspan($name, '#ccc', '#222').span($down.$up, '#ddd', '#000');
|
|
|
|
echo block(
|
|
'bandwidth_'.$iface,
|
|
[
|
|
'full_text' => $fullText,
|
|
]
|
|
);
|