Write debug log to tempDir, redirect + download w/ readfile()

This commit is contained in:
billz 2023-10-31 20:31:27 +00:00
parent e99e98d8ca
commit 97a9cac5e8
3 changed files with 40 additions and 3 deletions

View file

@ -8,7 +8,16 @@ if (isset($_POST['csrf_token'])) {
handleInvalidCSRFToken();
}
exec( RASPI_CONFIG.'/system/debuglog.sh', $return);
echo json_encode(end($return));
$logOutput = implode(PHP_EOL, $return);
$filename = "raspap_debug.log";
$tempDir = sys_get_temp_dir();
$filePath = $tempDir . DIRECTORY_SEPARATOR . $filename;
$handle = fopen($filePath, "w");
fwrite($handle, $logOutput);
fclose($handle);
echo json_encode($filePath);
} else {
handleInvalidCSRFToken();
}

View file

@ -0,0 +1,21 @@
<?php
require '../../includes/csrf.php';
$filePath = $_GET['filePath'];
$filename = "raspap_debug.log";
if (isset($filePath) && strpos($filePath, $filename) !== false) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filePath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: '.filesize($filePath));
readfile($filePath);
exit();
} else {
header('Location: '.'/system_info');
exit();
}

View file

@ -260,10 +260,8 @@ function setDHCPToggles(state) {
if ($('#dhcp-iface').is(':checked') && !state) {
$('#dhcp-iface').prop('checked', state);
}
$('#chkfallback').prop('disabled', state);
$('#dhcp-iface').prop('disabled', !state);
//$('#dhcp-iface').prop('checked', state);
}
function loadChannel() {
@ -273,6 +271,15 @@ function loadChannel() {
});
}
$('#debugModal').on('shown.bs.modal', function (e) {
var csrfToken = $('meta[name=csrf_token]').attr('content');
$.post('ajax/system/sys_debug.php',{'csrf_token': csrfToken},function(data){
var filePath = JSON.parse(data);
window.location.replace('/ajax/system/sys_get_logfile.php?filePath='+filePath);
$('#debugModal').modal('hide');
});
});
$('#hostapdModal').on('shown.bs.modal', function (e) {
var seconds = 3;
var pct = 0;