diff --git a/html/launcher.php b/html/launcher.php index 8008684..0825574 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -423,9 +423,50 @@ if ($type == "set_RTC_withBrowser") { if ($type == "clear_loopLogs") { - $command = 'truncate -s 0 /var/www/nebuleair_pro_4g/logs/loop.log'; - $output = shell_exec($command); - echo $output; + $response = array(); + + try { + $logPath = '/var/www/nebuleair_pro_4g/logs/master.log'; + + // Check if file exists and is writable + if (!file_exists($logPath)) { + throw new Exception("Log file does not exist"); + } + + if (!is_writable($logPath)) { + throw new Exception("Log file is not writable"); + } + + // Execute the command + $command = 'truncate -s 0 ' . escapeshellarg($logPath); + $output = shell_exec($command . ' 2>&1'); + + // Check if there was any error output + if (!empty($output)) { + throw new Exception("Command error: " . $output); + } + + // Success response + $response = array( + 'status' => 'success', + 'message' => 'Logs cleared successfully', + 'timestamp' => date('Y-m-d H:i:s') + ); + } catch (Exception $e) { + // Error response + $response = array( + 'status' => 'error', + 'message' => $e->getMessage(), + 'timestamp' => date('Y-m-d H:i:s') + ); + } + + // Set content type to JSON + header('Content-Type: application/json'); + + // Return the JSON response + echo json_encode($response); + exit; } if ($type == "database_size") { diff --git a/html/logs.html b/html/logs.html index d3d97ed..d2c7aef 100755 --- a/html/logs.html +++ b/html/logs.html @@ -56,7 +56,10 @@
${formattedLog}`;
- loop_card_content.scrollTop = loop_card_content.scrollHeight; // Scroll to the bottom
-
- })
- .catch((error) => {
- console.error(error);
- loop_card_content.textContent = 'Error loading log file.';
- });
-
- console.log("Getting app/boot logs");
-
- //Getting App logs
- fetch('../logs/app.log')
- .then((response) => {
- console.log("OK");
-
- if (!response.ok) {
- throw new Error('Failed to fetch the log file.');
- }
- return response.text();
- })
- .then((data) => {
- const lines = data.split('\n');
-
- // Format log content
- const formattedLog = lines
- .map((line) => line.trim()) // Remove extra whitespace
- .filter((line) => line) // Remove empty lines
- .join('${formattedLog}`;
- boot_card_content.scrollTop = loop_card_content.scrollHeight; // Scroll to the bottom
-
- })
- .catch((error) => {
- console.error(error);
- boot_card_content.textContent = 'Error loading log file.';
- });
-
+ // Setup master log with refresh button
+ setupLogRefreshButton('refresh-master-log', '../logs/master.log', 'card_loop_content', 3000);
+
+ // Setup boot log with refresh button
+ setupLogRefreshButton('refresh-boot-log', '../logs/app.log', 'card_boot_content', 300);
});
@@ -220,6 +176,75 @@ window.onload = function() {
}//end onload
+function displayLogFile(logFilePath, containerElement, scrollToBottom = true, maxLines = 0) {
+ // Show loading indicator
+ containerElement.innerHTML = '${formattedLog}`;
+
+ // Scroll to bottom if requested
+ if (scrollToBottom) {
+ containerElement.scrollTop = containerElement.scrollHeight;
+ }
+
+ return formattedLog; // Return the formatted log in case the caller needs it
+ })
+ .catch((error) => {
+ console.error(`Error loading log file ${logFilePath}:`, error);
+ containerElement.innerHTML = `