Files
webgui/plugins/dynamix/scripts/run_cmd
2022-05-28 19:32:36 +02:00

40 lines
1.1 KiB
PHP
Executable File

#!/usr/bin/php
<?PHP
/* Copyright 2005-2022, Lime Technology
* Copyright 2012-2022, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/ColorCoding.php";
$last = "\e[0m";
$color = ['text' => $last, 'login' => "\e[95m", 'warn' => "\e[93m", 'error' => "\e[91m", 'system' => "\e[96m", 'array' => "\e[92m"];
$call = ['tail','docker'];
if (!in_array($argv[1],$call)) exit;
array_shift($argv);
$cmd = popen(implode(' ',array_map('escapeshellarg',$argv)),'r');
while (($line = fgets($cmd))!==false) {
$lead = $last;
foreach ($match as $type) foreach ($type['text'] as $text) {
if (preg_match("/$text/i",$line)) {
$lead = $color[$type['class']];
break 2;
}
}
echo $lead,rtrim($line,"\n"),$last,"\n";
}
pclose($cmd);
?>