2022-06-28 20:51:28 +02:00
|
|
|
|
2022-06-21 21:07:06 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "./ui_mainwindow.h"
|
2022-06-20 21:44:58 +02:00
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
#include "qtimer.h"
|
|
|
|
|
2022-06-24 19:56:34 +02:00
|
|
|
#include <iostream>
|
2022-06-30 20:47:05 +02:00
|
|
|
#include <chrono>
|
2022-06-24 19:56:34 +02:00
|
|
|
|
2022-06-28 20:51:28 +02:00
|
|
|
|
2022-07-04 21:08:23 +02:00
|
|
|
MainWindow::MainWindow( QWidget *parent )
|
2022-06-20 21:44:58 +02:00
|
|
|
: QMainWindow(parent)
|
2022-06-21 21:07:06 +02:00
|
|
|
, ui(new Ui::MainWindow)
|
2022-06-20 21:44:58 +02:00
|
|
|
{
|
2022-06-27 19:49:09 +02:00
|
|
|
//////////////////
|
|
|
|
//// GRAPHICS ////
|
2022-06-22 21:37:35 +02:00
|
|
|
this->ui->setupUi(this);
|
2022-06-24 01:26:00 +02:00
|
|
|
|
2022-06-27 21:55:14 +02:00
|
|
|
// initialize the color-schemes map
|
|
|
|
this->TB_COLOR_SCHEMES = ColorSec::getColorSchemes();
|
2022-06-22 21:37:35 +02:00
|
|
|
// initialize the colors map
|
2022-06-27 21:55:14 +02:00
|
|
|
this->COLORS = ColorSec::getColors();
|
2022-06-27 19:49:09 +02:00
|
|
|
|
2022-06-22 21:37:35 +02:00
|
|
|
// load the main font
|
2022-06-25 18:48:08 +02:00
|
|
|
this->main_font_family = QFontDatabase::applicationFontFamilies(
|
2022-06-22 21:37:35 +02:00
|
|
|
QFontDatabase::addApplicationFont(":/fonts/Metropolis")).at(0);
|
|
|
|
// load the script font
|
2022-06-25 18:48:08 +02:00
|
|
|
this->script_font_family = QFontDatabase::applicationFontFamilies(
|
2022-06-22 21:37:35 +02:00
|
|
|
QFontDatabase::addApplicationFont(":/fonts/3270")).at(0);
|
|
|
|
// initialize the fonts map
|
2022-06-25 18:48:08 +02:00
|
|
|
this->FONTS["main"] = QFont(
|
|
|
|
this->main_font_family,
|
|
|
|
this->font_size );
|
|
|
|
this->FONTS["main_italic"] = QFont(
|
|
|
|
this->main_font_family,
|
|
|
|
this->font_size,
|
|
|
|
-1, true );
|
|
|
|
this->FONTS["main_bold"] = QFont(
|
|
|
|
this->main_font_family,
|
|
|
|
this->font_size,
|
|
|
|
1 );
|
|
|
|
this->FONTS["main_big"] = QFont(
|
|
|
|
this->main_font_family,
|
|
|
|
this->font_size_big );
|
|
|
|
this->FONTS["main_small"] = QFont(
|
|
|
|
this->main_font_family,
|
|
|
|
this->font_size_small );
|
|
|
|
this->FONTS["script"] = QFont(
|
|
|
|
this->script_font_family,
|
|
|
|
this->font_size );
|
|
|
|
|
2022-06-25 21:17:40 +02:00
|
|
|
// parent font for every tab
|
|
|
|
this->ui->CrapTabs->setFont( this->FONTS["main_big"] );
|
|
|
|
|
2022-06-25 18:48:08 +02:00
|
|
|
// TreeView for the LogFiles
|
2022-06-25 21:17:40 +02:00
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setFont( this->FONTS["main_small"] );
|
2022-06-25 18:48:08 +02:00
|
|
|
this->ui->listLogFiles->setFont( this->FONTS["main"] );
|
2022-06-25 21:17:40 +02:00
|
|
|
// TextBrowser for the LogFiles
|
2022-06-29 21:47:20 +02:00
|
|
|
this->TB.setColorScheme( 1, this->TB_COLOR_SCHEMES[1] );
|
2022-06-27 21:55:14 +02:00
|
|
|
this->TB.setFontFamily( this->main_font_family );
|
|
|
|
this->TB.setFont( QFont(
|
|
|
|
this->main_font_family,
|
|
|
|
this->font_size ));
|
|
|
|
this->ui->textLogFiles->setFont( this->TB.getFont() );
|
2022-06-27 19:49:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
//// INITIALIZATION ////
|
2022-07-06 21:03:58 +02:00
|
|
|
// sqlite databases paths
|
2022-07-08 21:40:58 +02:00
|
|
|
this->db_stats_path = "test.db";//"~/.craplog/db"; !!! RESTORE
|
2022-06-27 19:49:09 +02:00
|
|
|
// WebServers for the LogsList
|
|
|
|
this->allowed_web_servers[11] = true; // apache2
|
|
|
|
this->allowed_web_servers[12] = true; // nginx
|
|
|
|
this->allowed_web_servers[13] = true; // iis
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
//// CONFIGS ////
|
2022-07-08 21:40:58 +02:00
|
|
|
this->craplog.setDialogLevel( 2 ); // !!! DELETE ME WHEN DONE TESTING !!!
|
2022-06-27 19:49:09 +02:00
|
|
|
|
|
|
|
|
2022-07-06 21:03:58 +02:00
|
|
|
//////////////////////////
|
|
|
|
//// INTEGRITY CHECKS ////
|
2022-07-08 21:40:58 +02:00
|
|
|
// check that the sqlite plugin is available
|
|
|
|
/*if ( CheckSec::checkSQLitePlugin() ) {
|
|
|
|
// checks failed, abort
|
|
|
|
this->close();
|
|
|
|
}*/
|
2022-07-06 21:03:58 +02:00
|
|
|
// statistics' database
|
|
|
|
if ( CheckSec::checkStatsDatabase( this->db_stats_path ) ) {
|
|
|
|
// checks failed, abort
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
this->craplog.setStatsDatabasePath( this->db_stats_path );
|
|
|
|
// used-files' hashes' database
|
|
|
|
if ( CheckSec::checkHashesDatabase( this->db_hashes_path ) ) {
|
|
|
|
// checks failed, abort
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
this->craplog.setHashesDatabasePath( this->db_hashes_path );
|
|
|
|
// craplog variables
|
|
|
|
if ( CheckSec::checkCraplog( this->craplog ) ) {
|
|
|
|
// checks failed, abort
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-27 19:49:09 +02:00
|
|
|
///////////////////
|
|
|
|
//// POLISHING ////
|
|
|
|
// disable the unallowed WebServers
|
|
|
|
int ws = 14;
|
|
|
|
for ( int id=11; id<14; id++ ) {
|
|
|
|
if ( this->allowed_web_servers[ id ] == true ) {
|
|
|
|
ws = ( id < ws ) ? id : ws;
|
|
|
|
} else {
|
|
|
|
switch (id) {
|
|
|
|
case 11: this->ui->button_LogFiles_Apache->setEnabled( false ); break;
|
|
|
|
case 12: this->ui->button_LogFiles_Nginx->setEnabled( false ); break;
|
|
|
|
case 13: this->ui->button_LogFiles_Iis->setEnabled( false ); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( ws == 14 ) {
|
|
|
|
// no WS is allowed (???), fallback to the default one
|
|
|
|
ws = 11;
|
|
|
|
this->craplog.setCurrentWSID( 11 );
|
|
|
|
this->allowed_web_servers[ 11 ] = true;
|
|
|
|
this->on_button_LogFiles_Apache_clicked();
|
|
|
|
this->ui->button_LogFiles_Apache->setEnabled( true );
|
|
|
|
}
|
|
|
|
// set the LogList to the current WebServer
|
|
|
|
if ( this->allowed_web_servers[ this->craplog.getCurrentWSID() ] == false ) {
|
|
|
|
// the current WS is not allowed, fallback to the default one
|
|
|
|
this->craplog.setCurrentWSID( ws );
|
|
|
|
}
|
|
|
|
// set the current WS for the LogList
|
|
|
|
switch ( this->craplog.getCurrentWSID() ) {
|
|
|
|
case 11:
|
|
|
|
this->ui->button_LogFiles_Apache->setFlat( false );
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
this->ui->button_LogFiles_Nginx->setFlat( false );
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
this->ui->button_LogFiles_Iis->setFlat( false );
|
|
|
|
break;
|
|
|
|
}
|
2022-06-25 21:17:40 +02:00
|
|
|
// get a fresh list of LogFiles
|
2022-06-22 21:37:35 +02:00
|
|
|
this->ui->listLogFiles->header()->resizeSection(0,200);
|
|
|
|
this->ui->listLogFiles->header()->resizeSection(1,100);
|
2022-07-03 19:12:42 +02:00
|
|
|
QTimer::singleShot(500, this, SLOT(on_button_LogFiles_RefreshList_clicked()));
|
2022-06-20 21:44:58 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:07:06 +02:00
|
|
|
MainWindow::~MainWindow()
|
2022-06-20 21:44:58 +02:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-06-24 01:26:00 +02:00
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
/////////////////////
|
|
|
|
//// GENERAL USE ////
|
|
|
|
/////////////////////
|
|
|
|
// printable size with suffix and limited decimals
|
2022-07-04 21:08:23 +02:00
|
|
|
QString MainWindow::printableSize( const int bytes )
|
2022-06-30 20:47:05 +02:00
|
|
|
{
|
|
|
|
std::string size_str, size_sfx=" B";
|
|
|
|
float size = (float)bytes;
|
|
|
|
if (size > 1024) {
|
|
|
|
size /= 1024;
|
|
|
|
size_sfx = " KiB";
|
|
|
|
if (size > 1024) {
|
|
|
|
size /= 1024;
|
|
|
|
size_sfx = " MiB";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cut decimals depending on how big the floor is
|
|
|
|
size_str = std::to_string( size );
|
|
|
|
int cut_index = size_str.find('.')+1;
|
|
|
|
if ( cut_index == 0 ) {
|
|
|
|
cut_index = size_str.find(',')+1;
|
|
|
|
}
|
|
|
|
int n_decimals = 3;
|
|
|
|
if ( size >= 100 ) {
|
|
|
|
n_decimals = 2;
|
|
|
|
if ( size >= 1000 ) {
|
|
|
|
n_decimals = 1;
|
|
|
|
if ( size >= 10000 ) {
|
|
|
|
n_decimals = 0;
|
|
|
|
cut_index --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( cut_index >= 1 ) {
|
|
|
|
cut_index += n_decimals;
|
|
|
|
if ( cut_index > size_str.size()-1 ) {
|
|
|
|
cut_index = size_str.size()-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString::fromStdString( size_str.substr(0, cut_index ) + size_sfx );
|
|
|
|
}
|
|
|
|
|
|
|
|
// printable speed with suffix and limited decimals
|
2022-07-04 21:08:23 +02:00
|
|
|
QString MainWindow::printableSpeed( const int bytes, const int secs_ )
|
2022-06-30 20:47:05 +02:00
|
|
|
{
|
|
|
|
std::string speed_str, speed_sfx=" B/s";
|
2022-07-04 21:08:23 +02:00
|
|
|
int secs = secs_;
|
|
|
|
if ( secs == 0 ) {
|
|
|
|
secs = 1;
|
|
|
|
}
|
|
|
|
float speed = (float)bytes / (float)secs;
|
|
|
|
if (speed > 1024) {
|
|
|
|
speed /= 1024;
|
2022-06-30 20:47:05 +02:00
|
|
|
speed_sfx = " KiB/s";
|
2022-07-04 21:08:23 +02:00
|
|
|
if (speed > 1024) {
|
|
|
|
speed /= 1024;
|
2022-06-30 20:47:05 +02:00
|
|
|
speed_sfx = " MiB/s";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cut decimals depending on how big the floor is
|
2022-07-04 21:08:23 +02:00
|
|
|
speed_str = std::to_string( speed );
|
2022-06-30 20:47:05 +02:00
|
|
|
int cut_index = speed_str.find('.')+1;
|
|
|
|
if ( cut_index == 0 ) {
|
|
|
|
cut_index = speed_str.find(',')+1;
|
|
|
|
}
|
|
|
|
int n_decimals = 3;
|
2022-07-04 21:08:23 +02:00
|
|
|
if ( speed >= 100 ) {
|
2022-06-30 20:47:05 +02:00
|
|
|
n_decimals = 2;
|
2022-07-04 21:08:23 +02:00
|
|
|
if ( speed >= 1000 ) {
|
2022-06-30 20:47:05 +02:00
|
|
|
n_decimals = 1;
|
2022-07-04 21:08:23 +02:00
|
|
|
if ( speed >= 10000 ) {
|
2022-06-30 20:47:05 +02:00
|
|
|
n_decimals = 0;
|
|
|
|
cut_index --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( cut_index >= 1 ) {
|
|
|
|
cut_index += n_decimals;
|
|
|
|
if ( cut_index > speed_str.size()-1 ) {
|
|
|
|
cut_index = speed_str.size()-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString::fromStdString( speed_str.substr(0, cut_index ) + speed_sfx );
|
|
|
|
}
|
|
|
|
|
2022-07-04 21:08:23 +02:00
|
|
|
QString MainWindow::printableTime( const int secs_ )
|
2022-06-30 20:47:05 +02:00
|
|
|
{
|
2022-07-04 21:08:23 +02:00
|
|
|
int secs = secs_;
|
2022-06-30 20:47:05 +02:00
|
|
|
int mins = secs / 60;
|
|
|
|
secs = secs - (mins*60);
|
|
|
|
std::string mins_str = (mins<10) ? "0"+std::to_string(mins) : std::to_string(mins);
|
|
|
|
std::string secs_str = (secs<10) ? "0"+std::to_string(secs) : std::to_string(secs);
|
|
|
|
return QString::fromStdString( mins_str +":"+ secs_str );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 21:07:06 +02:00
|
|
|
//////////////
|
|
|
|
//// LOGS ////
|
|
|
|
//////////////
|
2022-06-27 19:49:09 +02:00
|
|
|
// switch to apache web server
|
2022-06-26 23:12:57 +02:00
|
|
|
void MainWindow::on_button_LogFiles_Apache_clicked()
|
|
|
|
{
|
2022-06-27 19:49:09 +02:00
|
|
|
if ( this->craplog.getCurrentWSID() != 11
|
2022-07-03 19:12:42 +02:00
|
|
|
&& this->allowed_web_servers.at( 11 ) == true ) {
|
2022-06-27 19:49:09 +02:00
|
|
|
// enable the enables
|
2022-06-26 23:12:57 +02:00
|
|
|
this->ui->button_LogFiles_Apache->setFlat( false );
|
|
|
|
this->ui->button_LogFiles_Nginx->setFlat( true );
|
|
|
|
this->ui->button_LogFiles_Iis->setFlat( true );
|
2022-06-27 19:49:09 +02:00
|
|
|
// load the list
|
|
|
|
this->craplog.setCurrentWSID( 11 );
|
2022-06-30 20:47:05 +02:00
|
|
|
this->on_button_LogFiles_RefreshList_clicked();
|
2022-07-01 21:30:15 +02:00
|
|
|
this->ui->textLogFiles->setText( RichText::richLogsDefault() );
|
|
|
|
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
|
2022-06-26 23:12:57 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-27 19:49:09 +02:00
|
|
|
// switch to nginx web server
|
2022-06-26 23:12:57 +02:00
|
|
|
void MainWindow::on_button_LogFiles_Nginx_clicked()
|
|
|
|
{
|
2022-06-27 19:49:09 +02:00
|
|
|
if ( this->craplog.getCurrentWSID() != 12
|
2022-07-03 19:12:42 +02:00
|
|
|
&& this->allowed_web_servers.at( 12 ) == true) {
|
2022-06-27 19:49:09 +02:00
|
|
|
// enable the enables
|
2022-06-26 23:12:57 +02:00
|
|
|
this->ui->button_LogFiles_Nginx->setFlat( false );
|
|
|
|
this->ui->button_LogFiles_Apache->setFlat( true );
|
|
|
|
this->ui->button_LogFiles_Iis->setFlat( true );
|
2022-06-27 19:49:09 +02:00
|
|
|
// load the list
|
|
|
|
this->craplog.setCurrentWSID( 12 );
|
2022-06-30 20:47:05 +02:00
|
|
|
this->on_button_LogFiles_RefreshList_clicked();
|
2022-07-01 21:30:15 +02:00
|
|
|
this->ui->textLogFiles->setText( RichText::richLogsDefault() );
|
|
|
|
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
|
2022-06-26 23:12:57 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-27 19:49:09 +02:00
|
|
|
// switch to iis web server
|
2022-06-26 23:12:57 +02:00
|
|
|
void MainWindow::on_button_LogFiles_Iis_clicked()
|
|
|
|
{
|
2022-06-27 19:49:09 +02:00
|
|
|
if ( this->craplog.getCurrentWSID() != 13
|
2022-07-03 19:12:42 +02:00
|
|
|
&& this->allowed_web_servers.at( 13 ) == true ) {
|
2022-06-27 19:49:09 +02:00
|
|
|
// load the list
|
2022-06-26 23:12:57 +02:00
|
|
|
this->ui->button_LogFiles_Iis->setFlat( false );
|
|
|
|
this->ui->button_LogFiles_Apache->setFlat( true );
|
|
|
|
this->ui->button_LogFiles_Nginx->setFlat( true );
|
2022-06-27 19:49:09 +02:00
|
|
|
// load the list
|
|
|
|
this->craplog.setCurrentWSID( 13 );
|
2022-06-30 20:47:05 +02:00
|
|
|
this->on_button_LogFiles_RefreshList_clicked();
|
2022-07-01 21:30:15 +02:00
|
|
|
this->ui->textLogFiles->setText( RichText::richLogsDefault() );
|
|
|
|
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
|
2022-06-26 23:12:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 21:07:06 +02:00
|
|
|
// refresh the log files list
|
2022-06-30 20:47:05 +02:00
|
|
|
void MainWindow::on_button_LogFiles_RefreshList_clicked()
|
2022-06-21 21:07:06 +02:00
|
|
|
{
|
2022-06-27 19:49:09 +02:00
|
|
|
std::string col;
|
2022-06-21 21:07:06 +02:00
|
|
|
// clear the current tree
|
|
|
|
this->ui->listLogFiles->clear();
|
2022-06-27 19:49:09 +02:00
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setCheckState( Qt::CheckState::Unchecked );
|
2022-06-21 21:07:06 +02:00
|
|
|
// iterate over elements of list
|
2022-06-23 04:00:37 +02:00
|
|
|
for ( const Craplog::LogFile& log_file : this->craplog.getLogsList(true) ) {
|
2022-06-21 21:07:06 +02:00
|
|
|
// new entry for the tree widget
|
|
|
|
QTreeWidgetItem * item = new QTreeWidgetItem();
|
2022-07-01 21:30:15 +02:00
|
|
|
|
|
|
|
// preliminary check for file-type display
|
|
|
|
if ( this->display_access_logs == false && log_file.type == LogOps::LogType::Access ) {
|
|
|
|
// do not display
|
|
|
|
delete item; // possible memory leak, says cppcheck
|
|
|
|
continue;
|
|
|
|
} else if ( this->display_error_logs == false && log_file.type == LogOps::LogType::Error ) {
|
|
|
|
// do not display
|
|
|
|
delete item; // possible memory leak, says cppcheck
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// preliminary check for file usage display
|
|
|
|
if ( log_file.used_already == true ) {
|
2022-06-27 19:49:09 +02:00
|
|
|
if ( this->display_used_files == false ) {
|
|
|
|
// do not display
|
2022-07-01 21:30:15 +02:00
|
|
|
delete item; // possible memory leak, says cppcheck
|
2022-06-27 19:49:09 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-01 21:30:15 +02:00
|
|
|
// display with red foreground
|
2022-07-03 19:12:42 +02:00
|
|
|
item->setForeground( 0, this->COLORS.at( "red" ) );
|
2022-06-27 19:49:09 +02:00
|
|
|
}
|
2022-07-01 21:30:15 +02:00
|
|
|
|
|
|
|
// preliminary check on file size
|
2022-06-27 19:49:09 +02:00
|
|
|
col = "grey";
|
|
|
|
if ( log_file.size > this->craplog.getWarningSize() ) {
|
|
|
|
if ( this->display_warnsize_files == false ) {
|
|
|
|
// do not display
|
2022-07-01 21:30:15 +02:00
|
|
|
delete item; // possible memory leak, says cppcheck
|
2022-06-27 19:49:09 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
col = "orange";
|
|
|
|
}
|
2022-07-03 19:12:42 +02:00
|
|
|
item->setForeground( 1, this->COLORS.at( col ) );
|
2022-07-01 21:30:15 +02:00
|
|
|
|
|
|
|
// set the name
|
|
|
|
item->setText( 0, log_file.name );
|
|
|
|
// set the size
|
|
|
|
item->setText( 1, this->printableSize( log_file.size ) );
|
2022-07-03 19:12:42 +02:00
|
|
|
item->setFont( 1, this->FONTS.at("main_italic") );
|
2022-06-21 21:07:06 +02:00
|
|
|
// append the item (on top, forced)
|
2022-06-27 19:49:09 +02:00
|
|
|
item->setCheckState(0, Qt::CheckState::Unchecked );
|
2022-06-21 21:07:06 +02:00
|
|
|
this->ui->listLogFiles->addTopLevelItem( item );
|
|
|
|
}
|
2022-06-27 19:49:09 +02:00
|
|
|
if ( this->craplog.getLogsListSize() > 0 ) {
|
|
|
|
// sort the list alphabetically
|
|
|
|
this->ui->listLogFiles->sortByColumn(0, Qt::SortOrder::AscendingOrder );
|
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setEnabled( true );
|
|
|
|
} else {
|
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setCheckState( Qt::CheckState::Unchecked );
|
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setEnabled( false );
|
|
|
|
}
|
2022-06-21 21:07:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-25 21:17:40 +02:00
|
|
|
void MainWindow::on_checkBox_LogFiles_CheckAll_stateChanged(int arg1)
|
2022-06-21 21:07:06 +02:00
|
|
|
{
|
2022-06-22 21:37:35 +02:00
|
|
|
Qt::CheckState new_state;
|
2022-06-25 21:17:40 +02:00
|
|
|
if ( this->ui->checkBox_LogFiles_CheckAll->checkState() == Qt::CheckState::Checked ) {
|
2022-06-22 21:37:35 +02:00
|
|
|
// check all
|
|
|
|
new_state = Qt::CheckState::Checked;
|
2022-06-30 20:47:05 +02:00
|
|
|
this->ui->button_MakeStats_Start->setEnabled(true);
|
2022-06-25 21:17:40 +02:00
|
|
|
} else if ( this->ui->checkBox_LogFiles_CheckAll->checkState() == Qt::CheckState::Unchecked ) {
|
2022-06-22 21:37:35 +02:00
|
|
|
// un-check all
|
|
|
|
new_state = Qt::CheckState::Unchecked;
|
2022-06-30 20:47:05 +02:00
|
|
|
this->ui->button_MakeStats_Start->setEnabled(false);
|
2022-06-22 21:37:35 +02:00
|
|
|
} else {
|
|
|
|
// do nothing
|
2022-06-30 20:47:05 +02:00
|
|
|
this->ui->button_MakeStats_Start->setEnabled(true);
|
2022-06-22 21:37:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-06-21 21:07:06 +02:00
|
|
|
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
|
|
|
while ( *i ) {
|
2022-06-22 21:37:35 +02:00
|
|
|
(*i)->setCheckState( 0, new_state );
|
|
|
|
++i;
|
2022-06-21 21:07:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
void MainWindow::on_button_LogFiles_ViewFile_clicked()
|
2022-06-21 21:07:06 +02:00
|
|
|
{
|
2022-06-25 18:48:08 +02:00
|
|
|
if ( this->ui->listLogFiles->selectedItems().size() > 0 ) {
|
2022-07-01 21:30:15 +02:00
|
|
|
bool proceed = true;
|
2022-06-25 18:48:08 +02:00
|
|
|
// display the selected item
|
|
|
|
Craplog::LogFile item = this->craplog.getLogFileItem(
|
|
|
|
this->ui->listLogFiles->selectedItems().takeFirst()->text(0) );
|
2022-06-26 22:31:45 +02:00
|
|
|
FormatOps::LogsFormat format;
|
2022-06-26 23:28:54 +02:00
|
|
|
if ( item.type == LogOps::LogType::Access ) {
|
2022-06-26 22:31:45 +02:00
|
|
|
format = this->craplog.getCurrentALF();
|
2022-06-26 23:28:54 +02:00
|
|
|
} else if ( item.type == LogOps::LogType::Error ) {
|
2022-06-26 22:31:45 +02:00
|
|
|
format = this->craplog.getCurrentELF();
|
2022-06-25 18:48:08 +02:00
|
|
|
} else {
|
2022-07-01 21:30:15 +02:00
|
|
|
// this shouldn't be reached, but...
|
|
|
|
proceed = false;
|
2022-07-03 19:12:42 +02:00
|
|
|
DialogSec::errUndefinedLogType( nullptr, item.name );
|
2022-07-01 21:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( proceed == true ) {
|
|
|
|
std::string content;
|
|
|
|
try {
|
|
|
|
content = IOutils::readFile( item.path );
|
|
|
|
} catch (const std::ios_base::failure& err) {
|
|
|
|
// failed reading
|
|
|
|
proceed = false;
|
|
|
|
// >> err.what() << //
|
2022-07-03 19:12:42 +02:00
|
|
|
DialogSec::errFailedReadFile( nullptr, item.name );
|
2022-07-01 21:30:15 +02:00
|
|
|
} catch (...) {
|
|
|
|
// failed somehow
|
|
|
|
proceed = false;
|
2022-07-03 19:12:42 +02:00
|
|
|
DialogSec::errFailedReadFile( nullptr, item.name );
|
2022-07-01 21:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( proceed == true ) {
|
|
|
|
// succesfully read, now enriched and display
|
|
|
|
this->ui->textLogFiles->setText(
|
|
|
|
RichText::enrichLogs(
|
|
|
|
content,
|
|
|
|
format,
|
|
|
|
this->TB ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( proceed == false ) {
|
|
|
|
// failed to read
|
|
|
|
this->ui->textLogFiles->setText( RichText::richLogsFailure() );
|
|
|
|
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
|
2022-06-25 18:48:08 +02:00
|
|
|
}
|
2022-06-24 19:56:34 +02:00
|
|
|
}
|
2022-06-21 21:07:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
2022-06-30 20:47:05 +02:00
|
|
|
this->on_button_LogFiles_ViewFile_clicked();
|
2022-06-22 21:37:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_listLogFiles_itemChanged(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
|
|
|
// control checked
|
|
|
|
int n_checked = 0;
|
|
|
|
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
|
|
|
while ( *i ) {
|
|
|
|
if ( (*i)->checkState(0) == Qt::CheckState::Checked ) {
|
|
|
|
n_checked++;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if ( n_checked == 0 ) {
|
2022-06-25 21:17:40 +02:00
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::Unchecked);
|
2022-06-22 21:37:35 +02:00
|
|
|
} else if ( n_checked == this->craplog.getLogsListSize() ) {
|
2022-06-25 21:17:40 +02:00
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::Checked);
|
2022-06-22 21:37:35 +02:00
|
|
|
} else {
|
2022-06-25 21:17:40 +02:00
|
|
|
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::PartiallyChecked);
|
2022-06-22 21:37:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
void MainWindow::on_button_MakeStats_Start_clicked()
|
2022-06-22 21:37:35 +02:00
|
|
|
{
|
2022-06-30 20:47:05 +02:00
|
|
|
// take actions on Craplog's start
|
|
|
|
this->craplogStarted();
|
|
|
|
|
|
|
|
// feed craplog with the checked files
|
2022-06-22 21:37:35 +02:00
|
|
|
bool proceed = true;
|
|
|
|
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
|
|
|
while ( *i ) {
|
|
|
|
if ( (*i)->checkState(0) == Qt::CheckState::Checked ) {
|
|
|
|
// tell Craplog to set this file as selected
|
2022-06-27 19:49:09 +02:00
|
|
|
if ( this->craplog.setLogFileSelected( (*i)->text(0) ) == false ) {
|
2022-06-22 21:37:35 +02:00
|
|
|
// this shouldn't be, but...
|
2022-07-01 21:30:15 +02:00
|
|
|
if ( DialogSec::choiceSelectedFileNotFound( nullptr, (*i)->text(0) ) == false ) {
|
2022-06-30 20:47:05 +02:00
|
|
|
proceed = false;
|
2022-06-22 21:37:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2022-06-30 20:47:05 +02:00
|
|
|
|
2022-07-08 21:40:58 +02:00
|
|
|
if ( proceed == true ) {
|
|
|
|
// check files to be used before to start
|
|
|
|
proceed = this->craplog.checkFiles();
|
|
|
|
} else {
|
|
|
|
this->craplogFinished();
|
|
|
|
}
|
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
if ( proceed == true ) {
|
2022-07-01 21:30:15 +02:00
|
|
|
// periodically update perfs
|
2022-06-30 20:47:05 +02:00
|
|
|
this->craplog_timer = new QTimer(this);
|
2022-07-04 21:08:23 +02:00
|
|
|
connect(this->craplog_timer, SIGNAL(timeout()), this, SLOT(update_Craplog_PerfData()));
|
2022-06-30 20:47:05 +02:00
|
|
|
this->craplog_timer->start(250);
|
2022-07-01 21:30:15 +02:00
|
|
|
// run craplog as thread
|
|
|
|
this->craplog_timer_start = std::chrono::system_clock::now();
|
2022-06-30 20:47:05 +02:00
|
|
|
this->craplog_thread = std::thread( &Craplog::run, &this->craplog );
|
|
|
|
} else {
|
|
|
|
this->craplogFinished();
|
2022-06-22 21:37:35 +02:00
|
|
|
}
|
2022-06-30 20:47:05 +02:00
|
|
|
}
|
2022-06-24 01:26:00 +02:00
|
|
|
|
2022-07-01 21:30:15 +02:00
|
|
|
void MainWindow::reset_MakeStats_labels()
|
|
|
|
{
|
|
|
|
// reset to default
|
|
|
|
this->ui->label_MakeStats_Size->setText( "0 B" );
|
|
|
|
this->ui->label_MakeStats_Lines->setText( "0" );
|
|
|
|
// time and speed
|
|
|
|
this->ui->label_MakeStats_Time->setText( "00:00" );
|
|
|
|
this->ui->label_MakeStats_Speed->setText( "0 B/s" );
|
|
|
|
}
|
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
void MainWindow::update_MakeStats_labels()
|
|
|
|
{
|
|
|
|
// update values
|
2022-07-04 21:08:23 +02:00
|
|
|
int size, secs;
|
2022-06-30 20:47:05 +02:00
|
|
|
// size and lines
|
2022-07-05 21:50:51 +02:00
|
|
|
if ( this->craplog.isParsing() == true ) {
|
|
|
|
this->craplog.collectPerfData();
|
|
|
|
}
|
2022-06-30 20:47:05 +02:00
|
|
|
size = this->craplog.getParsedSize();
|
|
|
|
this->ui->label_MakeStats_Size->setText( this->printableSize( size ) );
|
|
|
|
this->ui->label_MakeStats_Lines->setText( QString::fromStdString(std::to_string(this->craplog.getParsedLines())) );
|
|
|
|
// time and speed
|
|
|
|
this->craplog_timer_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
2022-07-08 21:40:58 +02:00
|
|
|
this->craplog_timer_start - std::chrono::system_clock::now()
|
2022-06-30 20:47:05 +02:00
|
|
|
);
|
2022-07-05 21:50:51 +02:00
|
|
|
size = this->craplog.getPerfSize();
|
2022-06-30 20:47:05 +02:00
|
|
|
secs = this->craplog_timer_elapsed.count() / -1000000000;
|
|
|
|
this->ui->label_MakeStats_Time->setText( this->printableTime( secs ));
|
|
|
|
this->ui->label_MakeStats_Speed->setText( this->printableSpeed( size, secs ));
|
2022-07-04 21:08:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::update_Craplog_PerfData()
|
|
|
|
{
|
|
|
|
// craplog is running as thread, update the values meanwhile
|
|
|
|
this->update_MakeStats_labels();
|
|
|
|
// check if Craplog has finished working
|
2022-06-30 20:47:05 +02:00
|
|
|
if ( this->craplog.isWorking() == false ) {
|
|
|
|
this->craplog_timer->stop();
|
|
|
|
this->craplog_thread.join();
|
|
|
|
this->craplogFinished();
|
|
|
|
}
|
|
|
|
}
|
2022-06-24 01:26:00 +02:00
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
void MainWindow::craplogStarted()
|
|
|
|
{
|
2022-07-04 21:08:23 +02:00
|
|
|
// reset perfs
|
|
|
|
this->reset_MakeStats_labels();
|
|
|
|
this->craplog.logOps.resetPerfData();
|
2022-06-30 20:47:05 +02:00
|
|
|
// disable the LogFiles section
|
|
|
|
this->ui->LogBoxFiles->setEnabled(false);
|
|
|
|
// disable the start button
|
|
|
|
this->ui->button_MakeStats_Start->setEnabled(false);
|
|
|
|
// enable all labels (needed only the first time)
|
|
|
|
this->ui->icon_MakeStats_Size->setEnabled(false);
|
|
|
|
this->ui->label_MakeStats_Size->setEnabled(true);
|
|
|
|
this->ui->icon_MakeStats_Lines->setEnabled(false);
|
|
|
|
this->ui->label_MakeStats_Lines->setEnabled(true);
|
|
|
|
this->ui->icon_MakeStats_Time->setEnabled(false);
|
|
|
|
this->ui->label_MakeStats_Time->setEnabled(true);
|
|
|
|
this->ui->icon_MakeStats_Speed->setEnabled(false);
|
|
|
|
this->ui->label_MakeStats_Speed->setEnabled(true);
|
2022-07-05 21:50:51 +02:00
|
|
|
// disable the settings tab
|
|
|
|
this->ui->Set->setEnabled(false);
|
2022-06-30 20:47:05 +02:00
|
|
|
}
|
2022-06-24 01:26:00 +02:00
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
void MainWindow::craplogFinished()
|
|
|
|
{
|
2022-07-04 21:08:23 +02:00
|
|
|
// update the perf data one last time, just in case
|
|
|
|
this->update_MakeStats_labels();
|
|
|
|
// clean up temp vars
|
|
|
|
this->craplog.logOps.resetPerfData();
|
|
|
|
|
2022-06-30 20:47:05 +02:00
|
|
|
// refresh the logs list
|
|
|
|
this->on_button_LogFiles_RefreshList_clicked();
|
|
|
|
// enable the LogFiles section
|
|
|
|
this->ui->LogBoxFiles->setEnabled(true);
|
2022-07-05 21:50:51 +02:00
|
|
|
// enable all labels (needed only the first time each session)
|
2022-06-30 20:47:05 +02:00
|
|
|
this->ui->icon_MakeStats_Size->setEnabled(true);
|
|
|
|
this->ui->icon_MakeStats_Lines->setEnabled(true);
|
|
|
|
this->ui->icon_MakeStats_Time->setEnabled(true);
|
|
|
|
this->ui->icon_MakeStats_Speed->setEnabled(true);
|
2022-07-05 21:50:51 +02:00
|
|
|
// enable the settings tab
|
|
|
|
this->ui->Set->setEnabled(true);
|
2022-06-21 21:07:06 +02:00
|
|
|
}
|
|
|
|
|