Merge branch 'master' into fix/theme-options

This commit is contained in:
Bill Zimmerman
2023-11-29 17:28:37 +01:00
committed by GitHub
13 changed files with 66 additions and 13 deletions

View File

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

View File

@@ -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',

View File

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

View File

@@ -924,6 +924,29 @@ 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;
}
/**
* Function to darken a color by a percentage
* From @marek-guran's material-dark theme for RaspAP
@@ -961,4 +984,3 @@ function lightenColor($color, $percent)
return sprintf("#%02x%02x%02x", $r, $g, $b);
}

View File

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

View File

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