From f395db329cb4f62603fd036d41a3c7e22c09380e Mon Sep 17 00:00:00 2001 From: Anita Date: Tue, 2 Aug 2022 23:58:26 +0530 Subject: [PATCH 1/2] Fix Wrong log path issue --- .gitignore | 3 +- .../LaravelLogViewer/LaravelLogViewer.php | 30 ++++++++++++++----- .../LaravelLogViewerServiceProvider.php | 2 +- src/config/logviewer.php | 4 +++ src/controllers/LogViewerController.php | 8 +++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 8c551bf..bc0db67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.lock /.idea -/build \ No newline at end of file +/build +.gitconfig \ No newline at end of file diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index b224eda..998bd7e 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -170,7 +170,16 @@ public function all() 'stack' => '', ]]; } - + if (is_dir($this->file)) + { + return [[ + 'context' => '', + 'level' => '', + 'date' => null, + 'text' => 'Log file "' . $this->file . '" is DIR', + 'stack' => '', + ]]; + } $file = app('files')->get($this->file); preg_match_all($this->pattern->getPattern('logs'), $file, $headings); @@ -245,13 +254,18 @@ public function foldersAndFiles($path = null) { $contents = array(); $dir = $path ? $path : $this->storage_path; + $ignoreFiles = function_exists('config') ? config('logviewer.ignore_files', []) : []; + foreach (scandir($dir) as $node) { if ($node == '.' || $node == '..') continue; $path = $dir . '\\' . $node; + $fpath = $dir . '/' . $node; if (is_dir($path)) { $contents[$path] = $this->foldersAndFiles($path); } else { - $contents[] = $path; + if (!empty($ignoreFiles) && in_array($node, $ignoreFiles)) continue; + + $contents[] = $fpath; } } @@ -283,9 +297,11 @@ public function getFolders($folder = '') * @param bool $basename * @return array */ - public function getFolderFiles($basename = false) + public function getFolderFiles($basename = false, $fullPath = false) { - return $this->getFiles($basename, $this->folder); + $folder = $fullPath ? $this->folder : str_replace($this->storage_path, '', $this->folder); + + return $this->getFiles($basename, $folder); } /** @@ -335,15 +351,15 @@ public function setStoragePath($path) public static function directoryTreeStructure($storage_path, array $array) { foreach ($array as $k => $v) { - if (is_dir($k)) { + if (is_dir($v)) { $exploded = explode("\\", $k); $show = last($exploded); echo '
- +        ' . $show . ' + class="fa fa-folder"> ' . basename($v) . '
'; diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php index 18114b3..27f156b 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php @@ -44,7 +44,7 @@ public function boot() */ public function register() { - // + $this->mergeConfigFrom(realpath(__DIR__ . '/../../config/logviewer.php'), 'logviewer'); } /** diff --git a/src/config/logviewer.php b/src/config/logviewer.php index 90c2a6f..0338a4e 100644 --- a/src/config/logviewer.php +++ b/src/config/logviewer.php @@ -12,4 +12,8 @@ 'max_file_size' => 52428800, // size in Byte 'pattern' => env('LOGVIEWER_PATTERN', '*.log'), 'storage_path' => env('LOGVIEWER_STORAGE_PATH', storage_path('logs')), + 'ignore_files' => [ + '.DS_Store', + '.gitignore' + ] ]; diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php index f8cf62a..8411642 100644 --- a/src/controllers/LogViewerController.php +++ b/src/controllers/LogViewerController.php @@ -49,7 +49,7 @@ public function index() $folderFiles = []; if ($this->request->input('f')) { $this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f'))); - $folderFiles = $this->log_viewer->getFolderFiles(true); + $folderFiles = $this->log_viewer->getFolderFiles(false); } if ($this->request->input('l')) { $this->log_viewer->setFile(Crypt::decrypt($this->request->input('l'))); @@ -62,9 +62,9 @@ public function index() $data = [ 'logs' => $this->log_viewer->all(), 'folders' => $this->log_viewer->getFolders(), - 'current_folder' => $this->log_viewer->getFolderName(), + 'current_folder' => $this->log_viewer->getFolderName() ?? $this->log_viewer->getStoragePath(), 'folder_files' => $folderFiles, - 'files' => $this->log_viewer->getFiles(true), + 'files' => $this->log_viewer->getFiles(false), 'current_file' => $this->log_viewer->getFileName(), 'standardFormat' => true, 'structure' => $this->log_viewer->foldersAndFiles(), @@ -85,6 +85,8 @@ public function index() } } + $data['show_files'] = (!empty($data['folder_files']) ? $data['folder_files'] : $data['files']); + return app('view')->make($this->view_log, $data); } From a2ed1e8bdabe309f4d1b1a1f447f2f6135e95b28 Mon Sep 17 00:00:00 2001 From: anitamourya4it Date: Wed, 10 Aug 2022 10:45:09 +0530 Subject: [PATCH 2/2] fix files structure --- .../LaravelLogViewer/LaravelLogViewer.php | 19 ++++++++++++------- src/controllers/LogViewerController.php | 2 +- src/views/log.blade.php | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index 998bd7e..8db4d27 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -133,6 +133,11 @@ public function getFolderName() return $this->folder; } + public function getCurrentFolder() + { + return str_replace($this->storage_path, '', $this->folder); + } + /** * @return string */ @@ -299,7 +304,7 @@ public function getFolders($folder = '') */ public function getFolderFiles($basename = false, $fullPath = false) { - $folder = $fullPath ? $this->folder : str_replace($this->storage_path, '', $this->folder); + $folder = $fullPath ? $this->folder : $this->getCurrentFolder(); return $this->getFiles($basename, $folder); } @@ -375,12 +380,12 @@ class="fa fa-folder"> ' . basename($v) . ' $file = $v; - echo ''; +// echo ''; } } diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php index 8411642..ff3793e 100644 --- a/src/controllers/LogViewerController.php +++ b/src/controllers/LogViewerController.php @@ -64,7 +64,7 @@ public function index() 'folders' => $this->log_viewer->getFolders(), 'current_folder' => $this->log_viewer->getFolderName() ?? $this->log_viewer->getStoragePath(), 'folder_files' => $folderFiles, - 'files' => $this->log_viewer->getFiles(false), + 'files' => $this->log_viewer->getFiles(false, $this->log_viewer->getCurrentFolder()), 'current_file' => $this->log_viewer->getFileName(), 'standardFormat' => true, 'structure' => $this->log_viewer->foldersAndFiles(), diff --git a/src/views/log.blade.php b/src/views/log.blade.php index 92ede04..7dd76ee 100644 --- a/src/views/log.blade.php +++ b/src/views/log.blade.php @@ -185,15 +185,22 @@ function resetTheme() { @foreach($folders as $folder) '; + \Rap2hpoutre\LaravelLogViewer\LaravelLogViewer::DirectoryTreeStructure( $storage_path, $structure ); ?> @endforeach - @foreach($files as $file) - - {{$file}} + {{basename($file)}} @endforeach @@ -204,6 +211,9 @@ class="list-group-item @if ($current_file == $file) llv-active @endif"> Log file >50M, please download it. @else + +

{{ str_replace($storage_path, '', $current_folder)}}

+