Merge pull request #1437 from RaspAP/feat/debug-tools

Feature: Debug log generator
This commit is contained in:
Bill Zimmerman 2023-11-02 08:24:12 +01:00 committed by GitHub
commit 21b588282f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 454 additions and 26 deletions

23
ajax/system/sys_debug.php Normal file
View file

@ -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();
}

View file

@ -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();
}

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;

View file

@ -7,6 +7,7 @@ define('RASPI_CONFIG_PROVIDERS', 'config/vpn-providers.json');
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.

View file

@ -12,6 +12,7 @@ $defaults = [
'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.

View file

@ -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
}

314
installers/debuglog.sh Executable file
View file

@ -0,0 +1,314 @@
#!/bin/bash
#
# RaspAP Debug log generator
# Author: @billz <billzimmerman@gmail.com>
# Author URI: https://github.com/billz/
# License: GNU General Public License v3.0
# License URI: https://github.com/raspap/raspap-webgui/blob/master/LICENSE
#
# Typically used in an ajax call from the RaspAP UI, this utility may also
# be invoked directly to generate a detailed system debug log.
#
# Usage: debuglog.sh [options]
#
# OPTIONS:
# -w, --write Writes the debug log to /tmp (useful if sourced directly)
# -i, --install Overrides the default RaspAP install location (/var/www/html)
#
# NOTE
# Detailed system information is gathered for debugging and/or troubleshooting
# purposes only. Passwords or other sensitive data are NOT included.
#
# You are not obligated to bundle the LICENSE file with your RaspAP projects as long
# as you leave these references intact in the header comments of your source files.
# Exit on error
set -o errexit
# Exit on error inside functions
set -o errtrace
# Turn on traces, disabled by default
# set -o xtrace
# Set defaults
readonly RASPAP_DIR="/etc/raspap"
readonly DNSMASQ_D_DIR="/etc/dnsmasq.d"
readonly RASPAP_DHCDPCD="/etc/dhcpcd.conf"
readonly RASPAP_HOSTAPD="$RASPAP_DIR/hostapd.ini"
readonly RASPAP_PROVIDER="$RASPAP_DIR/provider.ini"
readonly RASPAP_LOGPATH="/tmp"
readonly RASPAP_LOGFILE="$RASPAP_LOGPATH/raspap_debug.log"
readonly RASPAP_DEBUG_VERSION="1.0"
readonly PREAMBLE="
888888ba .d888888 888888ba
88 8b d8 88 88 8b
a88aaaa8P' .d8888b. .d8888b. 88d888b. 88aaaaa88a a88aaaa8P
88 8b. 88 88 Y8ooooo. 88 88 88 88 88
88 88 88. .88 88 88. .88 88 88 88
dP dP 88888P8 88888P 88Y888P 88 88 dP
88
dP Debug Log Generator $RASPAP_DEBUG_VERSION
This process collects debug and troubleshooting information about your RaspAP installation.
It is intended to assist users with a self-diagnosis of their installations, as well as
provide useful information as a starting point for others to assist with troubleshooting.
Debug log information contains the RaspAP version, current state and configuration of AP
related services, relevant installed package versions, Linux kernel version and local
networking configuration details.
If you wish to share your debug info, paste the output to one of the following:
https://pastebin.com/
https://paste.ubuntu.com/
Please do NOT paste the log in its entirety to RaspAP's discussions, issues or other
support channels. Use one of the above links instead.
DISCLAIMER: This log DOES contain details about your system, including networking
settings. However, NO passwords or other sensitive data are included in the debug output.
========================================================================================"
function _main() {
_parse_params "$@"
_initialize
_output_preamble
_generate_log
}
function _parse_params() {
# default option values
install_dir="/var/www/html"
writelog=0
while :; do
case "${1-}" in
-w|--write)
writelog=1
;;
-i|--install)
install_dir="$2"
shift
;;
-*|--*)
echo "Unknown option: $1"
_usage
exit 1
;;
*)
break
;;
esac
shift
done
}
function _generate_log() {
_log_write "Debug log generation started at $(date)"
_system_info
_packages_info
_raspap_info
_usb_info
_wpa_info
_dnsmasq_info
_interface_info
_routing_info
_iw_dev_info
_iw_reg_info
_systemd_info
_log_write "RaspAP debug log generation complete."
exit 0
}
# Fetches hardware, OS, uptime & used memory
function _system_info() {
local model=$(tr -d '\0' < /proc/device-tree/model)
local system_uptime=$(uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/){if ($9=="min") {d=$6;m=$8} else {d=$6;h=$8;m=$9}} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes"}')
local free_mem=$(free -m | awk 'NR==2{ total=$2 ; used=$3 } END { print used/total*100}')
_log_separator "System Info"
_log_write "Hardware: ${model}"
_log_write "Detected OS: ${DESC} ${LONG_BIT}-bit"
_log_write "Kernel: ${KERNEL}"
_log_write "System Uptime: ${system_uptime}"
_log_write "Memory Usage: ${free_mem}%"
}
# Fetch installed package versions
function _packages_info() {
local php_version="Not present"
local dnsmasq_version="Not present"
local dhcpcd_version="Not present"
local lighttpd_version="Not present"
local vnstat_version="Not present"
if [ -x "$(command -v php)" ]; then
php_version=$(php -v | grep -oP "PHP \K[0-9]+\.[0-9]+.*")
fi
if [ -x "$(command -v dnsmasq)" ]; then
dnsmasq_version=$(dnsmasq -v | grep -oP "Dnsmasq version \K[0-9]+\.[0-9]+")
fi
if [ -x "$(command -v dhcpcd)" ]; then
dhcpcd_version=$(dhcpcd --version | grep -oP '\d+\.\d+\.\d+')
fi
if [ -x "$(command -v dhcpcd)" ]; then
lighttpd_version=$(lighttpd -v | grep -oP '(\d+\.\d+\.\d+)')
fi
if [ -x "$(command -v dhcpcd)" ]; then
vnstat_version=$(vnstat -v | grep -oP "vnStat \K[0-9]+\.[0-9]+")
fi
_log_separator "Installed Packages"
_log_write "PHP Version: ${php_version}"
_log_write "Dnsmasq Version: ${dnsmasq_version}"
_log_write "dhcpcd Version: ${dhcpcd_version}"
_log_write "lighttpd Version: ${lighttpd_version}"
_log_write "vnStat Version: ${vnstat_version}"
}
# Outputs installed RaspAP version & settings
function _raspap_info() {
local version="Not present"
local hostapd_ini="Not present"
local provider_ini="Not present"
if [ -f ${install_dir}/includes/defaults.php ]; then
version=$(grep "RASPI_VERSION" $install_dir/includes/defaults.php | awk -F"'" '{print $4}')
fi
if [ -f ${RASPAP_HOSTAPD} ]; then
hostapd_ini=$(cat ${RASPAP_HOSTAPD})
fi
if [ -f ${RASPAP_PROVIDER} ]; then
provider_ini=$(cat ${RASPAP_PROVIDER})
fi
_log_separator "RaspAP Install"
_log_write "RaspAP Version: ${version}"
_log_write "RaspAP Installation Directory: ${install_dir}"
_log_write "RaspAP hostapd.ini contents:\n${hostapd_ini}"
_log_write "RaspAP provider.ini: ${provider_ini}"
}
function _usb_info() {
local stdout=$(lsusb)
_log_separator "USB Devices"
_log_write "${stdout}"
}
function _wpa_info() {
local stdout=$(wpa_cli status)
_log_separator "WPA Supplicant"
_log_write "${stdout}"
}
# Iterates the contents of RaspAP's 090_*.conf files in dnsmasq.d
function _dnsmasq_info() {
local stdout=$(ls -h ${DNSMASQ_D_DIR}/090_*.conf)
local contents
_log_separator "Dnsmasq Contents"
_log_write "${stdout}"
IFS= # set IFS to empty
if [ -d "${DNSMASQ_D_DIR}" ]; then
for file in "${DNSMASQ_D_DIR}"/090_*.conf; do
if [ -f "$file" ]; then
contents+="\n$file contents:\n"
contents+="$(cat $file)"
contents="${contents}$\n"
fi
done
_log_write $contents
else
_log_write "Not found: ${DNSMASQ_D_DIR}"
fi
}
function _interface_info() {
local stdout=$(ip a)
_log_separator "Interfaces"
_log_write "${stdout}"
}
function _iw_reg_info() {
local stdout=$(iw reg get)
_log_separator "IW Regulatory Info"
_log_write "${stdout}"
}
function _iw_dev_info() {
local stdout=$(iw dev)
_log_separator "IW Device Info"
_log_write "${stdout}"
}
function _routing_info() {
local stdout=$(ip route)
_log_separator "Routing Table"
_log_write "${stdout}"
}
# Status of systemd services
function _systemd_info() {
local SYSTEMD_SERVICES=(
"hostapd"
"dnsmasq"
"dhcpcd"
"systemd-networkd"
"wg-quick@wg0"
"openvpn-client@client"
"lighttpd")
_log_separator "Systemd Services"
for i in "${!SYSTEMD_SERVICES[@]}"; do
_log_write "${SYSTEMD_SERVICES[$i]} status:"
stdout=$(systemctl status "${SYSTEMD_SERVICES[$i]}" || echo "")
_log_write "${stdout}\n"
done
}
function _output_preamble() {
_log_write "${PREAMBLE}\n"
}
# Fetches host Linux distribution details
function _get_linux_distro() {
if type lsb_release >/dev/null 2>&1; then # linuxbase.org
OS=$(lsb_release -si)
RELEASE=$(lsb_release -sr)
CODENAME=$(lsb_release -sc)
DESC=$(lsb_release -sd)
LONG_BIT=$(getconf LONG_BIT)
elif [ -f /etc/os-release ]; then # freedesktop.org
. /etc/os-release
OS=$ID
RELEASE=$VERSION_ID
CODENAME=$VERSION_CODENAME
DESC=$PRETTY_NAME
else
OS="Unsupported Linux distribution"
fi
KERNEL=$(uname -a)
}
function _initialize() {
if [ -e "${RASPAP_LOGFILE}" ] && [ "${writelog}" = 1 ]; then
rm "${RASPAP_LOGFILE}"
fi
_get_linux_distro
}
function _log_separator(){
local separator=""
local msg="$1"
local length=${#msg}
_log_write "\n$1"
for ((i=1; i<=length; i++)); do
separator+="="
done
_log_write $separator
}
function _log_write() {
if [ "${writelog}" = 1 ]; then
echo -e "${@}" | tee -a $RASPAP_LOGFILE
else
echo -e "${@}"
fi
}
_main "$@"

View file

@ -41,6 +41,7 @@ www-data ALL=(ALL) NOPASSWD:/etc/raspap/hostapd/servicestart.sh
www-data ALL=(ALL) NOPASSWD:/etc/raspap/lighttpd/configport.sh
www-data ALL=(ALL) NOPASSWD:/etc/raspap/openvpn/configauth.sh
www-data ALL=(ALL) NOPASSWD:/etc/raspap/openvpn/openvpnlog.sh
www-data ALL=(ALL) NOPASSWD:/etc/raspap/system/debuglog.sh
www-data ALL=(ALL) NOPASSWD:/bin/chmod o+r /tmp/hostapd.log
www-data ALL=(ALL) NOPASSWD:/bin/chmod o+r /var/log/dnsmasq.log
www-data ALL=(ALL) NOPASSWD:/bin/chmod o+r /tmp/wireguard.log

Binary file not shown.

View file

@ -821,6 +821,24 @@ msgstr "Select a theme"
msgid "Color"
msgstr "Color"
msgid "Tools"
msgstr "Tools"
msgid "System tools"
msgstr "System tools"
msgid "To generate a system <a href=\"%s\">debug log</a>, click or tap the button below."
msgstr "To generate a system <a href=\"%s\">debug log</a>, click or tap the button below."
msgid "Debug log information contains the RaspAP version, current state and configuration of AP related services, installed system packages, Linux kernel version and networking details. No passwords or other sensitive data are included."
msgstr "Debug log information contains the RaspAP version, current state and configuration of AP related services, installed system packages, Linux kernel version and networking details. No passwords or other sensitive data are included."
msgid "Generate debug log"
msgstr "Generate debug log"
msgid "Debug log generation in progress..."
msgstr "Debug log generation in progress..."
#: includes/data_usage.php
msgid "Data usage"
msgstr "Data usage"

View file

@ -17,7 +17,7 @@
<li role="presentation" class="nav-item"><a class="nav-link" id="languagetab" href="#language" aria-controls="language" role="tab" data-toggle="tab"><?php echo _("Language"); ?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" id="themetab" href="#theme" aria-controls="theme" role="tab" data-toggle="tab"><?php echo _("Theme"); ?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" id="advancedtab" href="#advanced" aria-controls="advanced" role="tab" data-toggle="tab"><?php echo _("Advanced"); ?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" id="resettab" href="#reset" aria-controls="reset" role="tab" data-toggle="tab"><?php echo _("Reset"); ?></a></li>
<li role="presentation" class="nav-item"><a class="nav-link" id="toolstab" href="#tools" aria-controls="tools" role="tab" data-toggle="tab"><?php echo _("Tools"); ?></a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
@ -25,7 +25,7 @@
<?php echo renderTemplate("system/language", $__template_data) ?>
<?php echo renderTemplate("system/theme", $__template_data) ?>
<?php echo renderTemplate("system/advanced", $__template_data) ?>
<?php echo renderTemplate("system/reset", $__template_data) ?>
<?php echo renderTemplate("system/tools", $__template_data) ?>
</div><!-- /.tab-content -->
</form>
</div><!-- /.card-body -->
@ -88,3 +88,20 @@
</div>
</div>
<!-- modal progress-debug-->
<div class="modal fade" id="debugModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="ModalLabel"><i class="fas fa-sync-alt fa-spin mr-2"></i><?php echo _("Generate debug log"); ?></div>
</div>
<div class="modal-body">
<div class="col-md-12 mb-3 mt-1" id="system-debug-message"><?php echo _("Debug log generation in progress..."); ?></div>
</div>
<div class="modal-footer">
<button type="button" data-message="<?php echo _("Close"); ?>" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
</div>
</div>
</div>
</div>

View file

@ -1,21 +0,0 @@
<!-- reset tab -->
<div role="tabpanel" class="tab-pane" id="reset">
<h4 class="mt-3"><?php echo _("Restore settings") ;?></h4>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-lg-8 col-md-8">
<label for="cbxhwmode">
<?php echo sprintf(_("To reset RaspAP to its <a href=\"%s\">initial configuration</a>, click or tap the button below."), "https://docs.raspap.com/defaults/"); ;?>
</label>
<?php getTooltip('Restores all access point (AP) service settings to their default values. This applies to hostapd, dhcpcd and dnsmasq.', 'tiphwmode', true); ?>
<div class="small">
<?php echo _("Custom files for optional components such as Ad Blocking, WireGuard or OpenVPN will remain on the system."); ?>
</div>
</div>
</div>
<button type="button" class="btn btn-danger" name="system-reset" data-toggle="modal" data-target="#system-confirm-reset" /><?php echo _("Perform reset"); ?></button>
<?php endif ?>
</div>

View file

@ -0,0 +1,39 @@
<!-- reset tab -->
<div role="tabpanel" class="tab-pane" id="tools">
<h4 class="mt-3"><?php echo _("System tools") ;?></h4>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-lg-8 col-md-8">
<label for="debug">
<?php echo sprintf(_("To generate a system <a href=\"%s\">debug log</a>, click or tap the button below."), "https://docs.raspap.com/ap-basics/#debug-log/"); ;?>
</label>
<div class="small">
<?php echo _("Debug log information contains the RaspAP version, current state and configuration of AP related services, installed system packages, Linux kernel version and networking details. No passwords or other sensitive data are included."); ?>
</div>
</div>
</div>
<button type="button" class="btn btn-warning mb-3" name="debug-log" data-toggle="modal" data-target="#debugModal" />
<i class="fas fa-ambulance ml-1 mr-2"></i><?php echo _("Generate debug log"); ?>
</button>
<div class="row">
<div class="form-group col-lg-8 col-md-8">
<label for="reset">
<?php echo sprintf(_("To reset RaspAP to its <a href=\"%s\">initial configuration</a>, click or tap the button below."), "https://docs.raspap.com/defaults/"); ;?>
</label>
<?php getTooltip('Restores all access point (AP) service settings to their default values. This applies to hostapd, dhcpcd and dnsmasq.', 'tiphwmode', true); ?>
<div class="small">
<?php echo _("Custom files for optional components such as Ad Blocking, WireGuard or OpenVPN will remain on the system."); ?>
</div>
</div>
</div>
<button type="button" class="btn btn-danger" name="system-reset" data-toggle="modal" data-target="#system-confirm-reset" />
<i class="fas fa-history ml-1 mr-2"></i><?php echo _("Perform reset"); ?>
</button>
<?php endif ?>
</div>