diff --git a/var/www/lib/functions-ui.php b/var/www/lib/functions-ui.php index f7f15b02..f1992fdf 100644 --- a/var/www/lib/functions-ui.php +++ b/var/www/lib/functions-ui.php @@ -828,4 +828,32 @@ function componentFeatureRepoBrancheStatus($fb_project, $cherry_commits_display $content.=''; return $content; } -?> + +/* + * Convert ANSI color codes to HTML + * + * @param string $text The text with ANSI codes + * @return string The text with HTML tags + */ +function ansi_to_html($text) { + // Escape HTML characters first + $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); + + // ANSI code to HTML map (common for logback + tomcat) + $ansiMap = [ + "\033[0;39m" => '', + "\033[0m" => '', + "\033[1m" => '', + "\033[31m" => '', // ERROR + "\033[33m" => '', // WARN + "\033[34m" => '', // INFO + "\033[32m" => '', // Logger/Context + "\033[36m" => '', // Thread (e.g.,
) + "\033[90m" => '', // DEBUG + ]; + + // Replace known ANSI sequences + return str_replace(array_keys($ansiMap), array_values($ansiMap), $text); +} + +?> \ No newline at end of file diff --git a/var/www/logStream.php b/var/www/logStream.php new file mode 100644 index 00000000..417b37ab --- /dev/null +++ b/var/www/logStream.php @@ -0,0 +1,39 @@ + 'Unauthorized']); + exit; +} + +if (!file_exists($file_path)) { + echo json_encode(['error' => 'File not found']); + exit; +} + +$filesize = filesize($file_path); + +if ($filesize > $offset) { + $handle = fopen($file_path, "rb"); + fseek($handle, $offset); + $content = fread($handle, $filesize - $offset); + fclose($handle); + + echo json_encode([ + 'offset' => $filesize, + 'content' => ansi_to_html($content) + ]); +} else { + // Nothing new to read — just return current offset and empty content + echo json_encode([ + 'offset' => $filesize, + 'content' => '' + ]); +} \ No newline at end of file diff --git a/var/www/logs.php b/var/www/logs.php index 05c95d60..ccd4d1b5 100644 --- a/var/www/logs.php +++ b/var/www/logs.php @@ -8,7 +8,18 @@ ?> - + + @@ -20,26 +31,70 @@
+ // Read file only if the type of file is ok. + if (isAuthorizedToReadFile($log_type, $file_path) == true){ + ?>
- Download file () : + Download file () : +

- This file is too large to be viewed. Please download it."); - } else { - printf("
");
-                                $data = file_get_contents($file_path);
-                                echo htmlspecialchars($data, ENT_NOQUOTES, 'UTF-8');
-                                printf("
"); - } + This file is too large to be viewed. Please download it."; } else { - printf("Not authorized to read this file."); + ?> +
Loading logs...
+ + + } else { + echo "Not authorized to read this file."; + } + ?>