diff --git a/config/config.php b/config/config.php index 1aff2412..bdda1a02 100755 --- a/config/config.php +++ b/config/config.php @@ -8,6 +8,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'); +define('RASPI_LOG_SIZE_LIMIT', 64); // Constants for configuration file paths. // These are typical for default RPi installs. Modify if needed. @@ -18,6 +19,7 @@ define('RASPI_ADBLOCK_CONFIG', RASPI_DNSMASQ_PREFIX.'adblock.conf'); define('RASPI_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf'); define('RASPI_DHCPCD_CONFIG', '/etc/dhcpcd.conf'); define('RASPI_DHCPCD_LOG', '/var/log/dnsmasq.log'); +define('RASPI_HOSTAPD_LOG', '/tmp/hostapd.log'); define('RASPI_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf'); define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd'); define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant'); diff --git a/includes/adblock.php b/includes/adblock.php index 0d171e25..ec6fb38d 100755 --- a/includes/adblock.php +++ b/includes/adblock.php @@ -92,6 +92,7 @@ function DisplayAdBlockConfig() } else { $adblock_log = "Unable to open log file"; } + $logdata = getLogLimited(RASPI_DHCPCD_LOG, $adblock_log); echo renderTemplate( "adblock", compact( @@ -101,7 +102,7 @@ function DisplayAdBlockConfig() "enabled", "custom_enabled", "adblock_custom_content", - "adblock_log" + "logdata" ) ); } diff --git a/includes/defaults.php b/includes/defaults.php index b7c101b3..b5efb0cb 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -13,6 +13,7 @@ $defaults = [ 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', 'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap', 'RASPI_DEBUG_LOG' => 'raspap_debug.log', + 'RASPI_LOG_SIZE_LIMIT' => 64, // Constants for configuration file paths. // These are typical for default RPi installs. Modify if needed. @@ -23,6 +24,7 @@ $defaults = [ 'RASPI_HOSTAPD_CONFIG' => '/etc/hostapd/hostapd.conf', 'RASPI_DHCPCD_CONFIG' => '/etc/dhcpcd.conf', 'RASPI_DHCPCD_LOG' => '/var/log/dnsmasq.log', + 'RASPI_HOSTAPD_LOG' => '/tmp/hostapd.log', 'RASPI_WPA_SUPPLICANT_CONFIG' => '/etc/wpa_supplicant/wpa_supplicant.conf', 'RASPI_HOSTAPD_CTRL_INTERFACE' => '/var/run/hostapd', 'RASPI_WPA_CTRL_INTERFACE' => '/var/run/wpa_supplicant', diff --git a/includes/dhcp.php b/includes/dhcp.php index 1c6b500c..b1167457 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -60,6 +60,9 @@ function DisplayDHCPConfig() count($log_dhcp) > 0 ? $conf['log-dhcp'] = true : false ; count($log_queries) > 0 ? $conf['log-queries'] = true : false ; + exec('sudo /bin/chmod o+r '.RASPI_DHCPCD_LOG); + $logdata = getLogLimited(RASPI_DHCPCD_LOG); + echo renderTemplate( "dhcp", compact( "status", @@ -70,7 +73,8 @@ function DisplayDHCPConfig() "hosts", "upstreamServers", "interfaces", - "leases" + "leases", + "logdata" ) ); } diff --git a/includes/functions.php b/includes/functions.php index f909311d..5d3207e1 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -924,3 +924,26 @@ function checkReleaseVersion($installed, $latest) { return false; } +/** + * Returns logfile contents up to a maximum defined limit, in kilobytes + * + * @param string $file_path + * @param string $file_data optional + * @return string $log_limited + */ +function getLogLimited($file_path, $file_data = null) { + $limit_in_kb = isset($_SESSION['log_limit']) ? $_SESSION['log_limit'] : RASPI_LOG_SIZE_LIMIT; + $limit = $limit_in_kb * 1024; // convert KB to bytes + + if ($file_data === null) { + $file_size = filesize($file_path); + $start_position = max(0, $file_size - $limit); + $log_limited = file_get_contents($file_path, false, null, $start_position); + } else { + $file_size = strlen($file_data); + $start_position = max(0, $file_size - $limit); + $log_limited = substr($file_data, $start_position); + } + return $log_limited; +} + diff --git a/includes/hostapd.php b/includes/hostapd.php index 7fe54134..3ca11356 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -135,6 +135,8 @@ function DisplayHostAPDConfig() $selectedHwMode = 'w'; } } + exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG); + $logdata = getLogLimited(RASPI_HOSTAPD_LOG); echo renderTemplate( "hostapd", compact( @@ -153,7 +155,8 @@ function DisplayHostAPDConfig() "arrHostapdConf", "operatingSystem", "selectedHwMode", - "countryCodes" + "countryCodes", + "logdata" ) ); } diff --git a/includes/system.php b/includes/system.php index ddc462c5..e75a8585 100755 --- a/includes/system.php +++ b/includes/system.php @@ -39,6 +39,16 @@ function DisplaySystem(&$extraFooterScripts) $serverBind = escapeshellarg($_POST['serverBind']); } } + // Validate log limit + if (isset($_POST['logLimit'])) { + if ( strlen($_POST['logLimit']) > 4 || !is_numeric($_POST['logLimit']) ) { + $status->addMessage('Invalid value for log size limit', 'danger'); + $good_input = false; + } else { + $_SESSION['log_limit'] = intval($_POST['logLimit']); + $status->addMessage(sprintf(_('Changing log limit size to %s KB'), $_SESSION['log_limit']), 'info'); + } + } // Save settings if ($good_input) { exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort $serverBind " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return); @@ -141,6 +151,7 @@ function DisplaySystem(&$extraFooterScripts) $extraFooterScripts[] = array('src'=>'dist/huebee/huebee.pkgd.min.js', 'defer'=>false); $extraFooterScripts[] = array('src'=>'app/js/huebee.js', 'defer'=>false); + $logLimit = isset($_SESSION['log_limit']) ? $_SESSION['log_limit'] : RASPI_LOG_SIZE_LIMIT; echo renderTemplate("system", compact( "arrLocales", @@ -166,6 +177,7 @@ function DisplaySystem(&$extraFooterScripts) "hostapd_status", "hostapd_led", "themes", - "selectedTheme" + "selectedTheme", + "logLimit" )); } diff --git a/locale/en_US/LC_MESSAGES/messages.mo b/locale/en_US/LC_MESSAGES/messages.mo index 43c9fc0a..0b0865ab 100644 Binary files a/locale/en_US/LC_MESSAGES/messages.mo and b/locale/en_US/LC_MESSAGES/messages.mo differ diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index 0ab52d0e..7053ad78 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -911,6 +911,12 @@ msgstr "Generate debug log" msgid "Debug log generation in progress..." msgstr "Debug log generation in progress..." +msgid "Diagnostic log size limit (KB)" +msgstr "Diagnostic log size limit (KB)" + +msgid "Changing log limit size to %s KB" +msgstr "Changing log limit size to %s KB" + #: includes/data_usage.php msgid "Data usage" msgstr "Data usage" diff --git a/templates/adblock/logging.php b/templates/adblock/logging.php index 8378e68d..2140ae71 100644 --- a/templates/adblock/logging.php +++ b/templates/adblock/logging.php @@ -3,7 +3,7 @@