Add some colored output for logs in C&C

This commit is contained in:
cytopia 2022-12-25 15:40:45 +01:00
parent 0e3b963df2
commit 55f0447ce1
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2

View File

@ -24,7 +24,6 @@ function run_supervisor_command($command) {
?> ?>
<?php if ( isset($_POST['watcherd']) && $_POST['watcherd'] == 'reload' ) { <?php if ( isset($_POST['watcherd']) && $_POST['watcherd'] == 'reload' ) {
run_supervisor_command('restart watcherd'); run_supervisor_command('restart watcherd');
//loadClass('Helper')->exec('supervisorctl -c /etc/supervisor/custom.d/supervisorctl.conf restart watcherd');
sleep(1); sleep(1);
loadClass('Helper')->redirect('/cnc.php'); loadClass('Helper')->redirect('/cnc.php');
} }
@ -49,22 +48,20 @@ function run_supervisor_command($command) {
<?php <?php
$status_w = run_supervisor_command('status watcherd'); $status_w = run_supervisor_command('status watcherd');
$status_h = run_supervisor_command('status httpd'); $status_h = run_supervisor_command('status httpd');
//$status_w = loadClass('Helper')->exec('supervisorctl -c /etc/supervisor/custom.d/supervisorctl.conf status watcherd');
//$status_h = loadClass('Helper')->exec('supervisorctl -c /etc/supervisor/custom.d/supervisorctl.conf status httpd');
$words = preg_split("/\s+/", $status_w); $words = preg_split("/\s+/", $status_w);
$data_w = array( $data_w = array(
'name' => $words[0], 'name' => isset($words[0]) ? $words[0] : '',
'state' => $words[1], 'state' => isset($words[1]) ? $words[1] : '',
'pid' => preg_replace('/,$/', '', $words[3]), 'pid' => isset($words[3]) ? preg_replace('/,$/', '', $words[3]) : '',
'uptime' => $words[5], 'uptime' => isset($words[5]) ? $words[5] : '',
); );
$words = preg_split("/\s+/", $status_h); $words = preg_split("/\s+/", $status_h);
$data_h = array( $data_h = array(
'name' => $words[0], 'name' => isset($words[0]) ? $words[0] : '',
'state' => $words[1], 'state' => isset($words[1]) ? $words[1] : '',
'pid' => preg_replace('/,$/', '', $words[3]), 'pid' => isset($words[3]) ? preg_replace('/,$/', '', $words[3]) : '',
'uptime' => $words[5], 'uptime' => isset($words[5]) ? $words[5] : '',
); );
?> ?>
<h3>Daemon overview</h3><br/> <h3>Daemon overview</h3><br/>
@ -103,15 +100,41 @@ function run_supervisor_command($command) {
<br/> <br/>
<?php <?php
$output = run_supervisor_command('tail -1000000 watcherd stderr'); $output = run_supervisor_command('tail -1000000 watcherd stderr');
//$output = loadClass('Helper')->exec('supervisorctl -c /etc/supervisor/custom.d/supervisorctl.conf tail -1000000 watcherd stderr'); echo '<pre>';
echo '<pre>' . $output . '</pre>'; foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) {
if ( strpos($line, "[ERR]") !== false ) {
echo '<span style="color: #ff0000">' . $line . '</span>';
} else if ( strpos($line, "[emerg]") !== false ) {
echo '<span style="color: #ff0000">' . $line . '</span>';
} else if ( strpos($line, "Syntax error") !== false ) {
echo '<span style="color: #ff0000">' . $line . '</span>';
} else if ( strpos($line, "[WARN]") !== false ) {
echo '<span style="color: #ccaa00">' . $line . '</span>';
} else {
echo $line;
}
echo "\n";
}
echo '</pre>';
?> ?>
<h3>watcherd stdout</h3> <h3>watcherd stdout</h3>
<br/> <br/>
<?php <?php
$output = run_supervisor_command('tail -1000000 watcherd'); $output = run_supervisor_command('tail -1000000 watcherd');
//$output = loadClass('Helper')->exec('supervisorctl -c /etc/supervisor/custom.d/supervisorctl.conf tail -1000000 watcherd'); echo '<pre>';
echo '<pre>' . $output . '</pre>'; foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) {
$pos_info = strpos($line, "[INFO]");
$pos_ok = strpos($line, "[OK]");
if ( $pos_ok !== false ) {
echo '<span style="color: #669a00"><strong>' . $line . '</strong></span>';
} else if ( $pos_info !== false && $pos_info == 0 ) {
echo '<span style="color: #0088cd">' . $line . '</span>';
} else {
echo $line;
}
echo "\n";
}
echo '</pre>';
?> ?>
</div> </div>