logging cleanup
This commit is contained in:
@@ -24,6 +24,16 @@
|
||||
{
|
||||
color:white;
|
||||
background-color: black;
|
||||
font-family: 'Courier New', monospace;
|
||||
|
||||
}
|
||||
.logs-small
|
||||
{
|
||||
height: 100px;
|
||||
}
|
||||
.span-padding
|
||||
{
|
||||
padding:10px;
|
||||
}
|
||||
.text-center {
|
||||
text-align: center;
|
||||
|
||||
@@ -67,6 +67,14 @@ function deleteAllCookies() {
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function showModalOk (title, message) {
|
||||
// set captions
|
||||
$('#modal-ok-title').html (title);
|
||||
$('#modal-ok-message').html (message);
|
||||
|
||||
// Show modal
|
||||
$('#modal-ok').modal('show');
|
||||
}
|
||||
function showModalDefault (title, message, btnCancel, btnOK, callbackFunction) {
|
||||
// set captions
|
||||
$('#modal-default-title').html (title);
|
||||
|
||||
@@ -172,16 +172,6 @@ if (submit && isset($_POST['langselector_set'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set Tab ----------------------------------------------------------------------------
|
||||
|
||||
if ($_REQUEST['tab'] == '1') {
|
||||
$pia_tab_setting = 'active'; $pia_tab_tool = ''; $pia_tab_backup = '';
|
||||
} elseif ($_REQUEST['tab'] == '2') {
|
||||
$pia_tab_setting = ''; $pia_tab_tool = 'active'; $pia_tab_backup = '';
|
||||
} elseif ($_REQUEST['tab'] == '3') {
|
||||
$pia_tab_setting = ''; $pia_tab_tool = ''; $pia_tab_backup = 'active';
|
||||
} else { $pia_tab_setting = 'active'; $pia_tab_tool = ''; $pia_tab_backup = '';}
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
@@ -230,10 +220,18 @@ if ($_REQUEST['tab'] == '1') {
|
||||
|
||||
<div class="nav-tabs-custom">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab_Settings" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Settings'];?></a></li>
|
||||
<li><a href="#tab_DBTools" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Tools'];?></a></li>
|
||||
<li><a href="#tab_BackupRestore" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_BackupRestore'];?></a></li>
|
||||
<li><a href="#tab_Logging" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Logging'];?></a></li>
|
||||
<li class="active">
|
||||
<a id="tab_Settings_id" href="#tab_Settings" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Settings'];?></a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="tab_DBTools_id" href="#tab_DBTools" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Tools'];?></a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="tab_BackupRestore_id" href="#tab_BackupRestore" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_BackupRestore'];?></a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="tab_Logging_id" href="#tab_Logging" data-toggle="tab"><?php echo $pia_lang['Maintenance_Tools_Tab_Logging'];?></a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="tab_Settings">
|
||||
@@ -378,46 +376,51 @@ if ($_REQUEST['tab'] == '1') {
|
||||
<div class="db_info_table">
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
pialert.log
|
||||
<div><label>pialert.log</label><span class="span-padding"><a href="./log/pialert.log"><i class="fa fa-download"></i> </a></span></div>
|
||||
<div><button class="btn btn-primary" onclick="logManage('pialert.log','cleanLog')"><?php echo $pia_lang['Gen_Purge'];?></button></div>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea id="pialert_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert.log" ); ?>
|
||||
<textarea id="pialert_log" class="logs" cols="70" rows="10" readonly ><?php echo file_get_contents( "./log/pialert.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
pialert_front.log
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
<div><label>pialert_front.log</label><span class="span-padding"><a href="./log/pialert_front.log"><i class="fa fa-download"></i> </a></span></div>
|
||||
<div><button class="btn btn-primary" onclick="logManage('pialert_front.log','cleanLog')"><?php echo $pia_lang['Gen_Purge'];?></button></div>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea id="pialert_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/pialert_front.log" ); ?>
|
||||
<textarea id="pialert_log" class="logs" cols="70" rows="10" readonly><?php echo file_get_contents( "./log/pialert_front.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
IP_changes.log
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
<div><label>IP_changes.log</label><span class="span-padding"><a href="./log/IP_changes.log"><i class="fa fa-download"></i> </a></span></div>
|
||||
<div><button class="btn btn-primary" onclick="logManage('IP_changes.log','cleanLog')"><?php echo $pia_lang['Gen_Purge'];?></button></div>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea id="IP_changes_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
|
||||
<textarea id="IP_changes_log" class="logs logs-small" cols="70" rows="10" readonly><?php echo file_get_contents( "./log/IP_changes.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
stdout.log
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
<div><label>stdout.log</label><span class="span-padding"><a href="./log/stdout.log"><i class="fa fa-download"></i> </a></span></div>
|
||||
<div><button class="btn btn-primary" onclick="logManage('stdout.log','cleanLog')"><?php echo $pia_lang['Gen_Purge'];?></button></div>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea id="stdout_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stdout.log" ); ?>
|
||||
<textarea id="stdout_log" class="logs logs-small" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/stdout.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="db_info_table_row">
|
||||
<div class="db_tools_table_cell_a" style="">
|
||||
stderr.log
|
||||
<div><label>stderr.log</label><span class="span-padding"><a href="./log/stderr.log"><i class="fa fa-download"></i> </a></span></div>
|
||||
<div><button class="btn btn-primary" onclick="logManage('stderr.log','cleanLog')"><?php echo $pia_lang['Gen_Purge'];?></button></div>
|
||||
</div>
|
||||
<div class="db_tools_table_cell_b">
|
||||
<textarea id="stderr_log" class="logs" cols="70" rows="10" ><?php echo file_get_contents( "./log/stderr.log" ); ?>
|
||||
<textarea id="stderr_log" class="logs logs-small" cols="70" rows="10" wrap='off' readonly><?php echo file_get_contents( "./log/stderr.log" ); ?>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
@@ -463,20 +466,10 @@ if ($_REQUEST['tab'] == '1') {
|
||||
|
||||
<script>
|
||||
|
||||
function scrollDown()
|
||||
{
|
||||
temp = $('#pialert_log');
|
||||
$temp.scrollTop($text[0].scrollHeight);
|
||||
var emptyArr = ['undefined', "", undefined, null];
|
||||
var selectedTab = 'tab_Settings_id';
|
||||
|
||||
temp = $('#IP_changes_log');
|
||||
$temp.scrollTop($text[0].scrollHeight);
|
||||
|
||||
temp = $('#stdout_log');
|
||||
$temp.scrollTop($text[0].scrollHeight);
|
||||
|
||||
temp = $('#stderr_log');
|
||||
$temp.scrollTop($text[0].scrollHeight);
|
||||
}
|
||||
initializeTabs();
|
||||
|
||||
// delete devices with emty macs
|
||||
function askDeleteDevicesWithEmptyMACs () {
|
||||
@@ -658,12 +651,97 @@ function PiaToggleArpScan()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Clean log file
|
||||
var targetLogFile = "";
|
||||
var logFileAction = "";
|
||||
|
||||
function logManage(callback) {
|
||||
targetLogFile = arguments[0]; // target
|
||||
logFileAction = arguments[1]; // action
|
||||
// Ask
|
||||
showModalWarning('<?php echo $pia_lang['Gen_Purge'];?>' + ' ' + arguments[1], '<?php echo $pia_lang['Gen_AreYouSure'];?>',
|
||||
'<?php echo $pia_lang['Gen_Cancel'];?>', '<?php echo $pia_lang['Gen_Okay'];?>', "performLogManage");
|
||||
}
|
||||
|
||||
function performLogManage() {
|
||||
// Execute
|
||||
console.log("targetLogFile:" + targetLogFile)
|
||||
console.log("logFileAction:" + logFileAction)
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "php/server/util.php",
|
||||
data: { function: logFileAction, settings: targetLogFile },
|
||||
success: function(data, textStatus) {
|
||||
showModalOk ('Result', data );
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function scrollDown()
|
||||
{
|
||||
var tempArea = $('#pialert_log');
|
||||
$(tempArea[0]).scrollTop(tempArea[0].scrollHeight);
|
||||
|
||||
tempArea = $('#IP_changes_log');
|
||||
$(tempArea[0]).scrollTop(tempArea[0].scrollHeight);
|
||||
|
||||
tempArea = $('#stdout_log');
|
||||
$(tempArea[0]).scrollTop(tempArea[0].scrollHeight);
|
||||
|
||||
tempArea = $('#stderr_log');
|
||||
$(tempArea[0]).scrollTop(tempArea[0].scrollHeight);
|
||||
|
||||
}
|
||||
|
||||
function initializeTabs () {
|
||||
// Activate panel
|
||||
if(!emptyArr.includes(getCache("activeMaintenanceTab")))
|
||||
{
|
||||
selectedTab = getCache("activeMaintenanceTab");
|
||||
}
|
||||
$('.nav-tabs a[id='+ selectedTab +']').tab('show');
|
||||
|
||||
// When changed save new current tab
|
||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||
setCache("activeMaintenanceTab", $(e.target).attr('id'))
|
||||
});
|
||||
|
||||
// events on tab change
|
||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||
var target = $(e.target).attr("href") // activated tab
|
||||
//alert(target);
|
||||
if(target == "#tab_Logging")
|
||||
{
|
||||
scrollDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getCache(key)
|
||||
{
|
||||
// check cache
|
||||
if(sessionStorage.getItem(key))
|
||||
{
|
||||
return sessionStorage.getItem(key);
|
||||
} else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function setCache(key, data)
|
||||
{
|
||||
sessionStorage.setItem(key, data);
|
||||
}
|
||||
|
||||
|
||||
// load footer asynchronously not to block the page load/other sections
|
||||
window.onload = function asyncFooter()
|
||||
{
|
||||
|
||||
// scrollDown();
|
||||
|
||||
$("#lastCommit").append('<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/jokob-sk/pi.alert/main?logo=github">');
|
||||
|
||||
$("#lastDockerUpdate").append(
|
||||
@@ -671,8 +749,6 @@ window.onload = function asyncFooter()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -70,8 +70,9 @@ require '/home/pi/pialert/front/php/templates/language/'.$pia_lang_selected.'.ph
|
||||
$FUNCTION = [];
|
||||
$SETTINGS = [];
|
||||
|
||||
// init request params
|
||||
if(array_key_exists('function', $_REQUEST) != FALSE)
|
||||
{echo 'here'.$timestamp ;
|
||||
{
|
||||
$FUNCTION = $_REQUEST['function'];
|
||||
}
|
||||
|
||||
@@ -80,8 +81,14 @@ if(array_key_exists('settings', $_REQUEST) != FALSE)
|
||||
$SETTINGS = $_REQUEST['settings'];
|
||||
}
|
||||
|
||||
if ($FUNCTION == 'savesettings') {
|
||||
// call functions based on requested params
|
||||
if ($FUNCTION == 'savesettings')
|
||||
{
|
||||
saveSettings();
|
||||
}
|
||||
elseif ($FUNCTION == 'cleanLog')
|
||||
{
|
||||
cleanLog($SETTINGS);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -157,6 +164,7 @@ function checkPermissions($files)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
function displayMessage($message, $logAlert = FALSE, $logConsole = TRUE, $logFile = TRUE, $logEcho = FALSE)
|
||||
{
|
||||
@@ -205,19 +213,39 @@ function displayMessage($message, $logAlert = FALSE, $logConsole = TRUE, $logFil
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
function cleanLog($logFile)
|
||||
{
|
||||
global $logFolderPath, $timestamp;
|
||||
|
||||
$path = "";
|
||||
|
||||
$allowedFiles = ['pialert.log', 'pialert_front.log', 'IP_changes.log', 'stdout.log', 'stderr.log'];
|
||||
|
||||
if(in_array($logFile, $allowedFiles))
|
||||
{
|
||||
$path = $logFolderPath.$logFile;
|
||||
}
|
||||
|
||||
if($path != "")
|
||||
{
|
||||
// purge content
|
||||
$file = fopen($path, "w") or die("Unable to open file!");
|
||||
fwrite($file, "[".$timestamp. "] Log file manually purged" .PHP_EOL."");
|
||||
fclose($file);
|
||||
displayMessage('File <code>'.$logFile.'</code> purged.', FALSE, TRUE, TRUE, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
function saveSettings()
|
||||
{
|
||||
global $SETTINGS, $FUNCTION, $config_file, $fullConfPath, $configFolderPath, $timestamp;
|
||||
|
||||
echo 'here'.$timestamp ;
|
||||
global $SETTINGS, $FUNCTION, $config_file, $fullConfPath, $configFolderPath, $timestamp;
|
||||
|
||||
// save in the file
|
||||
$new_name = $config_file.'_'.$timestamp.'.backup';
|
||||
$new_location = $configFolderPath.$new_name;
|
||||
|
||||
// chmod($fullConfPath, 0755);
|
||||
|
||||
if(file_exists( $fullConfPath) != 1)
|
||||
{
|
||||
displayMessage('File "'.$fullConfPath.'" not found or missing read permissions. Creating a new <code>'.$config_file.'</code> file.', FALSE, TRUE, TRUE, TRUE);
|
||||
@@ -298,8 +326,8 @@ function saveSettings()
|
||||
fwrite($newConfig, $txt);
|
||||
fclose($newConfig);
|
||||
|
||||
displayMessage("<br/>Settings saved to the <code>".$config_file."</code> file.
|
||||
Backup of ".$config_file." created: <code>".$new_name."</code>.<br/>
|
||||
displayMessage("<br/>Settings saved to the <code>".$config_file."</code> file.
|
||||
<br/><br/>Backup of the previous ".$config_file." created here: <br/><br/><code>".$new_name."</code><br/><br/>
|
||||
<b>Restart the container for the changes to take effect.</b>",
|
||||
FALSE, TRUE, TRUE, TRUE);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ $pia_lang['Gen_Purge'] = 'Aufräumen';
|
||||
$pia_lang['Gen_Backup'] = 'Sichern';
|
||||
$pia_lang['Gen_Restore'] = 'Wiederherstellen';
|
||||
$pia_lang['Gen_Switch'] = 'Umschalten';
|
||||
$pia_lang['Gen_AreYouSure'] = 'Sind Sie sich sicher?';
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Login Page - Update by @TeroRERO 03ago2022
|
||||
|
||||
@@ -16,6 +16,7 @@ $pia_lang['Gen_Purge'] = 'Purge';
|
||||
$pia_lang['Gen_Backup'] = 'Run Backup';
|
||||
$pia_lang['Gen_Restore'] = 'Run Restore';
|
||||
$pia_lang['Gen_Switch'] = 'Switch';
|
||||
$pia_lang['Gen_AreYouSure'] = 'Are you sure?';
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Login Page - Update by @TeroRERO 03ago2022
|
||||
|
||||
@@ -16,6 +16,7 @@ $pia_lang['Gen_Purge'] = 'Purgar';
|
||||
$pia_lang['Gen_Backup'] = 'Ejecutar copia de seguridad';
|
||||
$pia_lang['Gen_Restore'] = 'Ejecutar restauración';
|
||||
$pia_lang['Gen_Switch'] = 'Cambiar';
|
||||
$pia_lang['Gen_AreYouSure'] = '¿Estás seguro de';
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Login Page - Update by @TeroRERO 03ago2022
|
||||
|
||||
@@ -7,6 +7,26 @@
|
||||
# Puche 2021 pi.alert.application@gmail.com GNU GPLv3
|
||||
#--------------------------------------------------------------------------- -->
|
||||
|
||||
<!-- Modal Ok -->
|
||||
<div class="modal fade" id="modal-ok" style="display: none;">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header" >
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 id="modal-ok-title" class="modal-title"> Modal Default Title </h4>
|
||||
</div>
|
||||
|
||||
<div id="modal-ok-message" class="modal-body"> Modal Default message </div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button id="modal-ok-OK" type="button" class="btn btn-primary" style="min-width: 80px;" data-dismiss="modal"> OK </button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal-dialog -->
|
||||
</div>
|
||||
|
||||
<!-- Modal Default -->
|
||||
<div class="modal fade" id="modal-default" style="display: none;">
|
||||
|
||||
@@ -108,8 +108,6 @@ $db->close();
|
||||
|
||||
$html = $html.getString ($set['Code_Name'].'_description', $set['Description'], $pia_lang);
|
||||
|
||||
|
||||
|
||||
$html = $html.
|
||||
'</div>
|
||||
<div class="table_cell setting_input" >';
|
||||
@@ -254,7 +252,7 @@ $db->close();
|
||||
|
||||
if(ipMask == "" || ipInterface == "")
|
||||
{
|
||||
showModalDefault ('Validation error', 'Specify both, the network mask and the interface');
|
||||
modalDefaultOK ('Validation error', 'Specify both, the network mask and the interface');
|
||||
} else {
|
||||
$('#SCAN_SUBNETS').append($('<option disabled></option>').attr('value', full).text(full));
|
||||
|
||||
@@ -315,7 +313,7 @@ $db->close();
|
||||
success: function(data, textStatus) {
|
||||
// $("#result").html(data);
|
||||
// console.log(data);
|
||||
showModalDefault ('Result', data );
|
||||
showModalOk ('Result', data );
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user