mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Merge pull request #1465 from RaspAP/feat/set-loglimit
Feature: Set diagnostic log size limit
This commit is contained in:
commit
1a16f3c8a3
@ -8,6 +8,7 @@ define('RASPI_ADMIN_DETAILS', RASPI_CONFIG.'/raspap.auth');
|
|||||||
define('RASPI_WIFI_AP_INTERFACE', 'wlan0');
|
define('RASPI_WIFI_AP_INTERFACE', 'wlan0');
|
||||||
define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
|
define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
|
||||||
define('RASPI_DEBUG_LOG', 'raspap_debug.log');
|
define('RASPI_DEBUG_LOG', 'raspap_debug.log');
|
||||||
|
define('RASPI_LOG_SIZE_LIMIT', 64);
|
||||||
|
|
||||||
// Constants for configuration file paths.
|
// Constants for configuration file paths.
|
||||||
// These are typical for default RPi installs. Modify if needed.
|
// 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_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf');
|
||||||
define('RASPI_DHCPCD_CONFIG', '/etc/dhcpcd.conf');
|
define('RASPI_DHCPCD_CONFIG', '/etc/dhcpcd.conf');
|
||||||
define('RASPI_DHCPCD_LOG', '/var/log/dnsmasq.log');
|
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_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf');
|
||||||
define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd');
|
define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd');
|
||||||
define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant');
|
define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant');
|
||||||
|
@ -92,6 +92,7 @@ function DisplayAdBlockConfig()
|
|||||||
} else {
|
} else {
|
||||||
$adblock_log = "Unable to open log file";
|
$adblock_log = "Unable to open log file";
|
||||||
}
|
}
|
||||||
|
$logdata = getLogLimited(RASPI_DHCPCD_LOG, $adblock_log);
|
||||||
|
|
||||||
echo renderTemplate(
|
echo renderTemplate(
|
||||||
"adblock", compact(
|
"adblock", compact(
|
||||||
@ -101,7 +102,7 @@ function DisplayAdBlockConfig()
|
|||||||
"enabled",
|
"enabled",
|
||||||
"custom_enabled",
|
"custom_enabled",
|
||||||
"adblock_custom_content",
|
"adblock_custom_content",
|
||||||
"adblock_log"
|
"logdata"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ $defaults = [
|
|||||||
'RASPI_WIFI_AP_INTERFACE' => 'wlan0',
|
'RASPI_WIFI_AP_INTERFACE' => 'wlan0',
|
||||||
'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap',
|
'RASPI_CACHE_PATH' => sys_get_temp_dir() . '/raspap',
|
||||||
'RASPI_DEBUG_LOG' => 'raspap_debug.log',
|
'RASPI_DEBUG_LOG' => 'raspap_debug.log',
|
||||||
|
'RASPI_LOG_SIZE_LIMIT' => 64,
|
||||||
|
|
||||||
// Constants for configuration file paths.
|
// Constants for configuration file paths.
|
||||||
// These are typical for default RPi installs. Modify if needed.
|
// These are typical for default RPi installs. Modify if needed.
|
||||||
@ -23,6 +24,7 @@ $defaults = [
|
|||||||
'RASPI_HOSTAPD_CONFIG' => '/etc/hostapd/hostapd.conf',
|
'RASPI_HOSTAPD_CONFIG' => '/etc/hostapd/hostapd.conf',
|
||||||
'RASPI_DHCPCD_CONFIG' => '/etc/dhcpcd.conf',
|
'RASPI_DHCPCD_CONFIG' => '/etc/dhcpcd.conf',
|
||||||
'RASPI_DHCPCD_LOG' => '/var/log/dnsmasq.log',
|
'RASPI_DHCPCD_LOG' => '/var/log/dnsmasq.log',
|
||||||
|
'RASPI_HOSTAPD_LOG' => '/tmp/hostapd.log',
|
||||||
'RASPI_WPA_SUPPLICANT_CONFIG' => '/etc/wpa_supplicant/wpa_supplicant.conf',
|
'RASPI_WPA_SUPPLICANT_CONFIG' => '/etc/wpa_supplicant/wpa_supplicant.conf',
|
||||||
'RASPI_HOSTAPD_CTRL_INTERFACE' => '/var/run/hostapd',
|
'RASPI_HOSTAPD_CTRL_INTERFACE' => '/var/run/hostapd',
|
||||||
'RASPI_WPA_CTRL_INTERFACE' => '/var/run/wpa_supplicant',
|
'RASPI_WPA_CTRL_INTERFACE' => '/var/run/wpa_supplicant',
|
||||||
|
@ -60,6 +60,9 @@ function DisplayDHCPConfig()
|
|||||||
count($log_dhcp) > 0 ? $conf['log-dhcp'] = true : false ;
|
count($log_dhcp) > 0 ? $conf['log-dhcp'] = true : false ;
|
||||||
count($log_queries) > 0 ? $conf['log-queries'] = 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(
|
echo renderTemplate(
|
||||||
"dhcp", compact(
|
"dhcp", compact(
|
||||||
"status",
|
"status",
|
||||||
@ -70,7 +73,8 @@ function DisplayDHCPConfig()
|
|||||||
"hosts",
|
"hosts",
|
||||||
"upstreamServers",
|
"upstreamServers",
|
||||||
"interfaces",
|
"interfaces",
|
||||||
"leases"
|
"leases",
|
||||||
|
"logdata"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -924,3 +924,26 @@ function checkReleaseVersion($installed, $latest) {
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -135,6 +135,8 @@ function DisplayHostAPDConfig()
|
|||||||
$selectedHwMode = 'w';
|
$selectedHwMode = 'w';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG);
|
||||||
|
$logdata = getLogLimited(RASPI_HOSTAPD_LOG);
|
||||||
|
|
||||||
echo renderTemplate(
|
echo renderTemplate(
|
||||||
"hostapd", compact(
|
"hostapd", compact(
|
||||||
@ -153,7 +155,8 @@ function DisplayHostAPDConfig()
|
|||||||
"arrHostapdConf",
|
"arrHostapdConf",
|
||||||
"operatingSystem",
|
"operatingSystem",
|
||||||
"selectedHwMode",
|
"selectedHwMode",
|
||||||
"countryCodes"
|
"countryCodes",
|
||||||
|
"logdata"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,16 @@ function DisplaySystem(&$extraFooterScripts)
|
|||||||
$serverBind = escapeshellarg($_POST['serverBind']);
|
$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
|
// Save settings
|
||||||
if ($good_input) {
|
if ($good_input) {
|
||||||
exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort $serverBind " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return);
|
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'=>'dist/huebee/huebee.pkgd.min.js', 'defer'=>false);
|
||||||
$extraFooterScripts[] = array('src'=>'app/js/huebee.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(
|
echo renderTemplate("system", compact(
|
||||||
"arrLocales",
|
"arrLocales",
|
||||||
@ -166,6 +177,7 @@ function DisplaySystem(&$extraFooterScripts)
|
|||||||
"hostapd_status",
|
"hostapd_status",
|
||||||
"hostapd_led",
|
"hostapd_led",
|
||||||
"themes",
|
"themes",
|
||||||
"selectedTheme"
|
"selectedTheme",
|
||||||
|
"logLimit"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -911,6 +911,12 @@ msgstr "Generate debug log"
|
|||||||
msgid "Debug log generation in progress..."
|
msgid "Debug log generation in progress..."
|
||||||
msgstr "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
|
#: includes/data_usage.php
|
||||||
msgid "Data usage"
|
msgid "Data usage"
|
||||||
msgstr "Data usage"
|
msgstr "Data usage"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<h4 class="mt-3"><?php echo _("Logging"); ?></h4>
|
<h4 class="mt-3"><?php echo _("Logging"); ?></h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-md-8">
|
<div class="form-group col-md-8">
|
||||||
<?php echo '<textarea class="logoutput">'.htmlspecialchars($adblock_log, ENT_QUOTES).'</textarea>'; ?>
|
<?php echo '<textarea class="logoutput">'.htmlspecialchars($logdata, ENT_QUOTES).'</textarea>'; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div><!-- /.tab-pane -->
|
</div><!-- /.tab-pane -->
|
||||||
|
@ -17,9 +17,7 @@
|
|||||||
<div class="form-group col-md-8 mt-2">
|
<div class="form-group col-md-8 mt-2">
|
||||||
<?php
|
<?php
|
||||||
if ($conf['log-dhcp'] == 1 || $conf['log-queries'] == 1) {
|
if ($conf['log-dhcp'] == 1 || $conf['log-queries'] == 1) {
|
||||||
exec('sudo /bin/chmod o+r '.RASPI_DHCPCD_LOG);
|
echo '<textarea class="logoutput" id="dnsmasq-log">'.htmlspecialchars($logdata, ENT_QUOTES).'</textarea>';
|
||||||
$log = file_get_contents(RASPI_DHCPCD_LOG);
|
|
||||||
echo '<textarea class="logoutput" id="dnsmasq-log">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
|
|
||||||
} else {
|
} else {
|
||||||
echo '<textarea class="logoutput my-3"></textarea>';
|
echo '<textarea class="logoutput my-3"></textarea>';
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,7 @@
|
|||||||
<div class="form-group col-md-8 mt-2">
|
<div class="form-group col-md-8 mt-2">
|
||||||
<?php
|
<?php
|
||||||
if ($arrHostapdConf['LogEnable'] == 1) {
|
if ($arrHostapdConf['LogEnable'] == 1) {
|
||||||
exec('sudo /bin/chmod o+r /tmp/hostapd.log');
|
echo '<textarea class="logoutput" id="hostapd-log">'.htmlspecialchars($logdata, ENT_QUOTES).'</textarea>';
|
||||||
$log = file_get_contents('/tmp/hostapd.log');
|
|
||||||
echo '<textarea class="logoutput" id="hostapd-log">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
|
|
||||||
} else {
|
} else {
|
||||||
echo '<textarea class="logoutput my-3"></textarea>';
|
echo '<textarea class="logoutput my-3"></textarea>';
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,15 @@
|
|||||||
<input type="text" class="form-control" name="serverBind" value="<?php echo htmlspecialchars($serverBind, ENT_QUOTES); ?>" />
|
<input type="text" class="form-control" name="serverBind" value="<?php echo htmlspecialchars($serverBind, ENT_QUOTES); ?>" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label for="code"><?php echo _("Diagnostic log size limit (KB)") ;?></label>
|
||||||
|
<input type="text" class="form-control" name="logLimit" value="<?php echo htmlspecialchars($logLimit, ENT_QUOTES); ?>" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<input type="submit" class="btn btn-outline btn-primary" name="SaveServerSettings" value="<?php echo _("Save settings"); ?>" />
|
<input type="submit" class="btn btn-outline btn-primary" name="SaveServerSettings" value="<?php echo _("Save settings"); ?>" />
|
||||||
<input type="submit" class="btn btn-warning" name="RestartLighttpd" value="<?php echo _("Restart lighttpd"); ?>" />
|
<input type="submit" class="btn btn-warning" name="RestartLighttpd" value="<?php echo _("Restart lighttpd"); ?>" />
|
||||||
</form>
|
</form>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user