Add software availability check API and enhance profile management features
This commit is contained in:
44
logfile.php
44
logfile.php
@@ -7,12 +7,14 @@ if (isAllowed('logfile',$_SESSION['profile'],$_SESSION['permission'],'R') === 0)
|
||||
exit;
|
||||
}
|
||||
|
||||
// Define logs directory path
|
||||
$logs_dir = __DIR__ . '/log/';
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// POST HANDLER - Delete all logs
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
$delete_message = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_all_logs'])) {
|
||||
$logs_dir = __DIR__ . '/log/';
|
||||
$deleted_count = 0;
|
||||
|
||||
if (is_dir($logs_dir)) {
|
||||
@@ -37,6 +39,28 @@ if (isset($_GET['deleted'])) {
|
||||
$delete_message = "Successfully deleted " . intval($_GET['deleted']) . " log file(s).";
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// DOWNLOAD HANDLER
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
if (isset($_GET['download']) && $_GET['download']) {
|
||||
$filename = $_GET['download'];
|
||||
$filepath = $logs_dir . $filename;
|
||||
|
||||
// Security check: ensure file exists and is within logs directory
|
||||
if (file_exists($filepath) && strpos(realpath($filepath), realpath($logs_dir)) === 0) {
|
||||
// Set headers for file download
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Content-Length: ' . filesize($filepath));
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
|
||||
// Output file content
|
||||
readfile($filepath);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// GET HANDLER
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
@@ -45,7 +69,6 @@ if (isset($_GET['deleted'])) {
|
||||
$selected_log = $_GET['log'] ?? '';
|
||||
|
||||
// Scan logs directory for all log files
|
||||
$logs_dir = __DIR__ . '/log/';
|
||||
$log_files = [];
|
||||
|
||||
if (is_dir($logs_dir)) {
|
||||
@@ -113,6 +136,9 @@ if (file_exists($filelocation_webserver)){
|
||||
<button type="button" onclick="refreshLog()" class="btn" >
|
||||
<i class="fas fa-sync-alt"></i>
|
||||
</button>
|
||||
<button type="button" onclick="downloadLogFile()" class="btn" style="background: #3498db; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer;">
|
||||
<i class="fas fa-download"></i>
|
||||
</button>
|
||||
<button type="submit" name="delete_all_logs" onclick="return confirmDeleteAll()" class="btn" style="background: #e74c3c; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer;">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
@@ -165,6 +191,20 @@ function loadLogFile(filename) {
|
||||
}
|
||||
}
|
||||
|
||||
// Download current log file
|
||||
function downloadLogFile() {
|
||||
const selector = document.getElementById('log-file-selector');
|
||||
const selectedFile = selector.value;
|
||||
|
||||
if (selectedFile) {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('download', selectedFile);
|
||||
window.location.href = url.toString();
|
||||
} else {
|
||||
alert('No log file selected to download.');
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh log functionality
|
||||
function refreshLog() {
|
||||
const button = event.target.closest('button');
|
||||
|
||||
Reference in New Issue
Block a user