Skip to content

Commit

Permalink
Merge pull request #1437 from RaspAP/feat/debug-tools
Browse files Browse the repository at this point in the history
Feature: Debug log generator
  • Loading branch information
billz authored Nov 2, 2023
2 parents 2b543c6 + 3eb8e5a commit 21b5882
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 26 deletions.
23 changes: 23 additions & 0 deletions ajax/system/sys_debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require '../../includes/csrf.php';
require_once '../../includes/config.php';

if (isset($_POST['csrf_token'])) {
if (csrfValidateRequest() && !CSRFValidate()) {
handleInvalidCSRFToken();
}
$root = getenv("DOCUMENT_ROOT");
exec('sudo '.RASPI_CONFIG.'/system/debuglog.sh -i '.$root, $return);

$logOutput = implode(PHP_EOL, $return);
$tempDir = sys_get_temp_dir();
$filePath = $tempDir . DIRECTORY_SEPARATOR . RASPI_DEBUG_LOG;
$handle = fopen($filePath, "w");
fwrite($handle, $logOutput);
fclose($handle);
echo json_encode($filePath);
} else {
handleInvalidCSRFToken();
}

21 changes: 21 additions & 0 deletions ajax/system/sys_get_logfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require '../../includes/csrf.php';
require_once '../../includes/config.php';

$filePath = $_GET['filePath'];

if (isset($filePath) && strpos($filePath, RASPI_DEBUG_LOG) !== 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();
}

11 changes: 9 additions & 2 deletions app/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
define('RASPI_WIFI_AP_INTERFACE', 'wlan0');
define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
define('RASPI_DEBUG_LOG', 'raspap_debug.log');

// Constants for configuration file paths.
// These are typical for default RPi installs. Modify if needed.
Expand Down
1 change: 1 addition & 0 deletions includes/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth',
'RASPI_WIFI_AP_INTERFACE' => 'wlan0',
'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap',
'RASPI_DEBUG_LOG' => 'raspap_debug.log',

// Constants for configuration file paths.
// These are typical for default RPi installs. Modify if needed.
Expand Down
9 changes: 8 additions & 1 deletion installers/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,19 @@ function _create_openvpn_scripts() {
_install_log "Creating OpenVPN control scripts"
sudo mkdir $raspap_dir/openvpn || _install_status 1 "Unable to create directory '$raspap_dir/openvpn'"

# Move service auth control & logging shell scripts
_install_log "Creating RaspAP debug log control script"
sudo mkdir $raspap_dir/system || _install_status 1 "Unable to create directory '$raspap_dir/system'"

# Move service auth control, logging and debug shell scripts
sudo cp "$webroot_dir/installers/"configauth.sh "$raspap_dir/openvpn" || _install_status 1 "Unable to move auth control script"
sudo cp "$webroot_dir/installers/"openvpnlog.sh "$raspap_dir/openvpn" || _install_status 1 "Unable to move logging script"
sudo cp "$webroot_dir/installers/"debuglog.sh "$raspap_dir/system" || _install_status 1 "Unable to move debug logging script"
# Restrict script execution to root user
sudo chown -c root:root "$raspap_dir/openvpn/"*.sh || _install_status 1 "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/openvpn/"*.sh || _install_status 1 "Unable to change file permissions"
sudo chown -c root:root "$raspap_dir/system/"*.sh || _install_status 1 "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/system/"*.sh || _install_status 1 "Unable to change file permissions"

_install_status 0
}

Expand Down
Loading

0 comments on commit 21b5882

Please sign in to comment.