LogDoctor/logdoctor/mainwindow.cpp

2235 lines
83 KiB
C++
Raw Normal View History

2022-06-21 21:07:06 +02:00
#include "mainwindow.h"
#include "./ui_mainwindow.h"
2022-06-20 21:44:58 +02:00
#include "qtimer.h"
#include <chrono>
2022-07-21 21:45:52 +02:00
#include <iostream> // !!! REMOVE !!!
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
{
//////////////////
//// GRAPHICS ////
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();
// initialize the colors map
2022-06-27 21:55:14 +02:00
this->COLORS = ColorSec::getColors();
// load the main font
2022-06-25 18:48:08 +02:00
this->main_font_family = QFontDatabase::applicationFontFamilies(
QFontDatabase::addApplicationFont(":/fonts/Metropolis")).at(0);
// load the script font
2022-06-25 18:48:08 +02:00
this->script_font_family = QFontDatabase::applicationFontFamilies(
QFontDatabase::addApplicationFont(":/fonts/3270")).at(0);
// initialize the fonts map
this->FONTS.emplace( "main", QFont(
2022-06-25 18:48:08 +02:00
this->main_font_family,
this->font_size ) );
this->FONTS.emplace( "main_italic", QFont(
2022-06-25 18:48:08 +02:00
this->main_font_family,
this->font_size,
-1, true ) );
this->FONTS.emplace( "main_bold", QFont(
2022-06-25 18:48:08 +02:00
this->main_font_family,
this->font_size,
1 ) );
this->FONTS.emplace( "main_big", QFont(
2022-06-25 18:48:08 +02:00
this->main_font_family,
this->font_size_big ) );
this->FONTS.emplace( "main_small", QFont(
2022-06-25 18:48:08 +02:00
this->main_font_family,
this->font_size_small ) );
this->FONTS.emplace( "script", QFont(
2022-06-25 18:48:08 +02:00
this->script_font_family,
this->font_size ) );
2022-06-25 18:48:08 +02:00
2022-06-25 21:17:40 +02:00
// parent font for every tab
this->ui->CrapTabs->setFont( this->FONTS.at( "main_big" ) );
2022-06-25 21:17:40 +02:00
2022-07-20 21:43:38 +02:00
// WebServers buttons for the LogFiles
this->ui->button_LogFiles_Apache->setFont( this->FONTS.at( "main" ) );
this->ui->button_LogFiles_Nginx->setFont( this->FONTS.at( "main" ) );
this->ui->button_LogFiles_Iis->setFont( this->FONTS.at( "main" ) );
2022-06-25 18:48:08 +02:00
// TreeView for the LogFiles
this->ui->checkBox_LogFiles_CheckAll->setFont( this->FONTS.at( "main_small" ) );
this->ui->listLogFiles->setFont( this->FONTS.at( "main" ) );
2022-06-25 21:17:40 +02:00
// TextBrowser for the LogFiles
this->TB.setColorScheme( 1, this->TB_COLOR_SCHEMES.at( 1 ) );
2022-06-27 21:55:14 +02:00
this->TB.setFontFamily( this->main_font_family );
this->TB.setFont( this->FONTS.at( "main" ) );
2022-06-27 21:55:14 +02:00
this->ui->textLogFiles->setFont( this->TB.getFont() );
2022-07-10 18:14:00 +02:00
// MakeStats labels
this->ui->label_MakeStats_Size->setFont( this->FONTS.at( "main" ) );
this->ui->label_MakeStats_Lines->setFont( this->FONTS.at( "main" ) );
this->ui->label_MakeStats_Time->setFont( this->FONTS.at( "main" ) );
this->ui->label_MakeStats_Speed->setFont( this->FONTS.at( "main" ) );
2022-07-21 21:45:52 +02:00
// StatsSpeed table
this->ui->table_StatsSpeed->setFont( this->FONTS.at("main") );
2022-07-21 21:45:52 +02:00
// adjust LogsList headers width
this->ui->listLogFiles->header()->resizeSection(0,200);
this->ui->listLogFiles->header()->resizeSection(1,100);
////////////////////////
//// INITIALIZATION ////
2022-07-06 21:03:58 +02:00
// sqlite databases paths
2022-07-09 18:16:09 +02:00
this->db_stats_path = "collection.db";//"~/.craplog/collection.db"; !!! RESTORE
this->db_hashes_path = "hashes.db";//"~/.craplog/hashes.db"; !!! RESTORE
2022-07-21 21:45:52 +02:00
this->crapview.setDbPath( this->db_stats_path );
// WebServers for the LogsList
this->allowed_web_servers.emplace( this->APACHE_ID, true );
this->allowed_web_servers.emplace( this->NGINX_ID, true );
this->allowed_web_servers.emplace( this->IIS_ID, true );
/////////////////
//// CONFIGS ////
2022-07-09 18:16:09 +02:00
this->craplog.setDialogLevel( 1 ); // !!! REPLACE WITH CONFIGURATION VALUE !!!
2022-07-06 21:03:58 +02:00
2022-07-26 20:44:47 +02:00
// set user-definet tabs indexes => this->ui->StatsTabs->widget( 0 );
2022-07-06 21:03:58 +02:00
///////////////////
//// POLISHING ////
// disable the unallowed WebServers
int ws = 14;
2022-07-21 21:45:52 +02:00
for ( int id=13; id>10; id-- ) {
2022-07-20 21:43:38 +02:00
if ( this->allowed_web_servers.at( id ) == true ) {
ws = ( id < ws ) ? id : ws; // to be used later on
} else {
switch (id) {
2022-07-21 21:45:52 +02:00
case 11:
this->ui->button_LogFiles_Apache->setEnabled( false );
this->ui->box_StatsWarn_WebServer->removeItem( 0 );
2022-07-21 21:45:52 +02:00
this->ui->box_StatsCount_WebServer->removeItem( 0 );
this->ui->box_StatsSpeed_WebServer->removeItem( 0 );
this->ui->box_StatsDay_WebServer->removeItem( 0 );
this->ui->box_StatsRelat_WebServer->removeItem( 0 );
this->ui->button_StatsGlob_Apache->setEnabled( false );
2022-07-21 21:45:52 +02:00
break;
case 12:
this->ui->button_LogFiles_Nginx->setEnabled( false );
this->ui->box_StatsWarn_WebServer->removeItem( 1 );
2022-07-21 21:45:52 +02:00
this->ui->box_StatsCount_WebServer->removeItem( 1 );
this->ui->box_StatsSpeed_WebServer->removeItem( 1 );
this->ui->box_StatsDay_WebServer->removeItem( 1 );
this->ui->box_StatsRelat_WebServer->removeItem( 1 );
this->ui->button_StatsGlob_Nginx->setEnabled( false );
2022-07-21 21:45:52 +02:00
break;
case 13:
this->ui->button_LogFiles_Iis->setEnabled( false );
this->ui->box_StatsWarn_WebServer->removeItem( 2 );
2022-07-21 21:45:52 +02:00
this->ui->box_StatsCount_WebServer->removeItem( 2 );
this->ui->box_StatsSpeed_WebServer->removeItem( 2 );
this->ui->box_StatsDay_WebServer->removeItem( 2 );
this->ui->box_StatsRelat_WebServer->removeItem( 2 );
this->ui->button_StatsGlob_Iis->setEnabled( false );
2022-07-21 21:45:52 +02:00
break;
}
}
}
if ( ws == 14 ) {
// no WS is allowed (???), fallback to the default one
ws = 11;
2022-07-21 21:45:52 +02:00
this->craplog.setCurrentWSID( ws );
this->allowed_web_servers.at( ws ) = true;
this->on_button_LogFiles_Apache_clicked();
this->ui->button_LogFiles_Apache->setEnabled( true );
this->ui->box_StatsWarn_WebServer->addItem( "Apache2" );
2022-07-21 21:45:52 +02:00
this->ui->box_StatsCount_WebServer->addItem( "Apache2" );
this->ui->box_StatsSpeed_WebServer->addItem( "Apache2" );
this->ui->box_StatsDay_WebServer->addItem( "Apache2" );
this->ui->box_StatsRelat_WebServer->addItem( "Apache2" );
this->ui->button_StatsGlob_Apache->setEnabled( true );
}
// set the LogList to the current WebServer
2022-07-21 21:45:52 +02:00
if ( this->allowed_web_servers.at( this->craplog.getCurrentWSID() ) == false ) {
// the current craplog's 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-07-21 21:45:52 +02:00
default:
// shouldn't be here
throw( &"Unexpected WebServer ID for Craplog: "[this->craplog.getCurrentWSID()] );
}
// set the current WS for the ViewStats and make them initialize
2022-07-21 21:45:52 +02:00
switch ( ws ) {
case 11:
// already set to index 0 by default
this->ui->box_StatsWarn_WebServer->setCurrentIndex( 0 );
this->ui->box_StatsCount_WebServer->setCurrentIndex( 0 );
this->ui->box_StatsSpeed_WebServer->setCurrentIndex( 0 );
this->ui->box_StatsDay_WebServer->setCurrentIndex( 0 );
this->ui->box_StatsRelat_WebServer->setCurrentIndex( 0 );
2022-07-21 21:45:52 +02:00
break;
case 12:
for ( int i=0; i<this->ui->box_StatsCount_WebServer->count(); i++ ) {
if ( this->ui->box_StatsCount_WebServer->itemText( i ) == "Nginx" ) {
this->ui->box_StatsWarn_WebServer->setCurrentIndex( i );
2022-07-21 21:45:52 +02:00
this->ui->box_StatsCount_WebServer->setCurrentIndex( i );
this->ui->box_StatsSpeed_WebServer->setCurrentIndex( i );
this->ui->box_StatsDay_WebServer->setCurrentIndex( i );
this->ui->box_StatsRelat_WebServer->setCurrentIndex( i );
break;
}
}
break;
case 13:
for ( int i=0; i<this->ui->box_StatsCount_WebServer->count(); i++ ) {
if ( this->ui->box_StatsCount_WebServer->itemText( i ) == "IIS" ) {
this->ui->box_StatsWarn_WebServer->setCurrentIndex( i );
2022-07-21 21:45:52 +02:00
this->ui->box_StatsCount_WebServer->setCurrentIndex( i );
this->ui->box_StatsSpeed_WebServer->setCurrentIndex( i );
this->ui->box_StatsDay_WebServer->setCurrentIndex( i );
this->ui->box_StatsRelat_WebServer->setCurrentIndex( i );
break;
}
}
break;
default:
// shouldn't be here
throw( &"Unexpected WebServer ID: "[ws] );
}
2022-07-21 21:45:52 +02:00
// make the Configs initialize
this->ui->checkBox_ConfWindow_Geometry->setChecked( this->remember_window );
this->ui->box_ConfWindow_Theme->setCurrentIndex( this->window_theme );
this->ui->slider_ConfDialogs_General->setValue( this->dialogs_Level );
this->ui->slider_ConfDialogs_Logs->setValue( this->craplog.getDialogsLevel() );
this->ui->slider_ConfDialogs_Stats->setValue( this->crapview.getDialogsLevel() );
this->ui->box_ConfTextBrowser_ColorScheme->setCurrentIndex( this->TB.getColorSchemeID() );
this->ui->box_ConfCharts_Theme->setCurrentIndex( this->charts_theme );
2022-06-25 21:17:40 +02:00
// get a fresh list of LogFiles
2022-07-09 18:16:09 +02:00
this->craplog_timer = new QTimer(this);
connect(this->craplog_timer, SIGNAL(timeout()), this, SLOT(wait_ActiveWindow()));
this->craplog_timer->start(250);
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-07-26 20:44:47 +02:00
void MainWindow::closeEvent (QCloseEvent *event)
{
// save actual configurations
// save tabs positions => this->ui->CrapTabs->tabText( 0 );
// => this->ui->CrapTabs->tabText( 0 );
this->ui->StatsTabs->move( 0,1 );
// save splitters sizes => this->ui->splitter_StatsCount->sizes();
}
2022-06-24 01:26:00 +02:00
2022-07-09 18:16:09 +02:00
//////////////////////////
//// INTEGRITY CHECKS ////
void MainWindow::wait_ActiveWindow()
{
if ( this->isActiveWindow() == false ) {
std::this_thread::sleep_for( std::chrono::milliseconds(250) );
} else {
this->craplog_timer->stop();
this->makeInitialChecks();
}
}
void MainWindow::makeInitialChecks()
{
bool ok = true;
// check that the sqlite plugin is available
if ( QSqlDatabase::drivers().contains("QSQLITE") == false ) {
// checks failed, abort
DialogSec::errSqlDriverNotFound( nullptr, "QSQLITE" );
ok = false;
}
if ( ok == true ) {
// statistics' database
if ( CheckSec::checkStatsDatabase( this->db_stats_path ) == false ) {
// checks failed, abort
ok = false;
} else {
this->craplog.setStatsDatabasePath( this->db_stats_path );
// used-files' hashes' database
if ( CheckSec::checkHashesDatabase( this->db_hashes_path ) == false ) {
// checks failed, abort
ok = false;
} else {
this->craplog.setHashesDatabasePath( this->db_hashes_path );
if ( this->craplog.hashOps.loadUsedHashesLists( this->db_hashes_path ) == false ) {
// failed to load the list, abort
ok = false;
} else {
// craplog variables
if ( CheckSec::checkCraplog( this->craplog ) == false ) {
// checks failed, abort
ok = false;
}
}
}
}
}
if ( ok == false ) {
this->close();
//QCoreApplication::exit(0);
//this->destroy();
} else {
2022-07-21 21:45:52 +02:00
// get available stats dates
this->refreshStatsDates();
// initialize logs fields boxes
this->on_box_StatsDay_LogsType_currentIndexChanged(0);
this->on_box_StatsRelat_LogsType_currentIndexChanged(0);
2022-07-21 21:45:52 +02:00
// get a fresh list of log files
2022-07-09 18:16:09 +02:00
this->on_button_LogFiles_RefreshList_clicked();
}
}
/////////////////////
//// GENERAL USE ////
/////////////////////
// printable size with suffix and limited decimals
QString MainWindow::printableSize( const int bytes )
{
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
QString MainWindow::printableSpeed( const int bytes, const int secs_ )
{
std::string speed_str, speed_sfx=" B/s";
int secs = secs_;
if ( secs == 0 ) {
secs = 1;
}
float speed = (float)bytes / (float)secs;
if (speed > 1024) {
speed /= 1024;
speed_sfx = " KiB/s";
if (speed > 1024) {
speed /= 1024;
speed_sfx = " MiB/s";
}
}
// cut decimals depending on how big the floor is
speed_str = std::to_string( speed );
int cut_index = speed_str.find('.')+1;
if ( cut_index == 0 ) {
cut_index = speed_str.find(',')+1;
}
int n_decimals = 3;
if ( speed >= 100 ) {
n_decimals = 2;
if ( speed >= 1000 ) {
n_decimals = 1;
if ( speed >= 10000 ) {
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 );
}
QString MainWindow::printableTime( const int secs_ )
{
int secs = secs_;
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 ////
//////////////
// switch to apache web server
2022-06-26 23:12:57 +02:00
void MainWindow::on_button_LogFiles_Apache_clicked()
{
if ( this->craplog.getCurrentWSID() != 11
2022-07-03 19:12:42 +02:00
&& this->allowed_web_servers.at( 11 ) == true ) {
// 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 );
// load the list
this->craplog.setCurrentWSID( 11 );
this->on_button_LogFiles_RefreshList_clicked();
2022-07-23 22:16:34 +02:00
QString rich_text;
RichText::richLogsDefault( rich_text );
this->ui->textLogFiles->setText( rich_text );
2022-07-01 21:30:15 +02:00
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
2022-07-23 22:16:34 +02:00
rich_text.clear();
2022-06-26 23:12:57 +02:00
}
}
// switch to nginx web server
2022-06-26 23:12:57 +02:00
void MainWindow::on_button_LogFiles_Nginx_clicked()
{
if ( this->craplog.getCurrentWSID() != 12
2022-07-03 19:12:42 +02:00
&& this->allowed_web_servers.at( 12 ) == true) {
// 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 );
// load the list
this->craplog.setCurrentWSID( 12 );
this->on_button_LogFiles_RefreshList_clicked();
2022-07-23 22:16:34 +02:00
QString rich_text;
RichText::richLogsDefault( rich_text );
this->ui->textLogFiles->setText( rich_text );
2022-07-01 21:30:15 +02:00
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
2022-07-23 22:16:34 +02:00
rich_text.clear();
2022-06-26 23:12:57 +02:00
}
}
// switch to iis web server
2022-06-26 23:12:57 +02:00
void MainWindow::on_button_LogFiles_Iis_clicked()
{
if ( this->craplog.getCurrentWSID() != 13
2022-07-03 19:12:42 +02:00
&& this->allowed_web_servers.at( 13 ) == true ) {
// 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 );
// load the list
this->craplog.setCurrentWSID( 13 );
this->on_button_LogFiles_RefreshList_clicked();
2022-07-23 22:16:34 +02:00
QString rich_text;
RichText::richLogsDefault( rich_text );
this->ui->textLogFiles->setText( rich_text );
2022-07-01 21:30:15 +02:00
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
2022-07-23 22:16:34 +02:00
rich_text.clear();
2022-06-26 23:12:57 +02:00
}
}
2022-06-21 21:07:06 +02:00
// refresh the log files list
void MainWindow::on_button_LogFiles_RefreshList_clicked()
2022-06-21 21:07:06 +02:00
{
std::string col;
2022-06-21 21:07:06 +02:00
// clear the current tree
this->ui->listLogFiles->clear();
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
2022-08-02 21:07:21 +02:00
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 ) {
if ( this->display_used_files == false ) {
// do not display
2022-07-01 21:30:15 +02:00
delete item; // possible memory leak, says cppcheck
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-07-01 21:30:15 +02:00
// preliminary check on file size
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
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)
item->setCheckState(0, Qt::CheckState::Unchecked );
2022-06-21 21:07:06 +02:00
this->ui->listLogFiles->addTopLevelItem( item );
}
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
{
Qt::CheckState new_state;
2022-06-25 21:17:40 +02:00
if ( this->ui->checkBox_LogFiles_CheckAll->checkState() == Qt::CheckState::Checked ) {
// check all
new_state = Qt::CheckState::Checked;
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 ) {
// un-check all
new_state = Qt::CheckState::Unchecked;
this->ui->button_MakeStats_Start->setEnabled(false);
} else {
// do nothing
this->ui->button_MakeStats_Start->setEnabled(true);
return;
}
2022-06-21 21:07:06 +02:00
QTreeWidgetItemIterator i(this->ui->listLogFiles);
while ( *i ) {
(*i)->setCheckState( 0, new_state );
++i;
2022-06-21 21:07:06 +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
2022-07-23 22:16:34 +02:00
QString rich_content;
RichText::enrichLogs(
rich_content, content,
format, this->TB );
this->ui->textLogFiles->setText( rich_content );
rich_content.clear();
2022-07-01 21:30:15 +02:00
}
2022-07-23 22:16:34 +02:00
content.clear();
2022-07-01 21:30:15 +02:00
}
if ( proceed == false ) {
// failed to read
2022-07-23 22:16:34 +02:00
QString rich_text;
RichText::richLogsFailure( rich_text );
this->ui->textLogFiles->setText( rich_text );
2022-07-01 21:30:15 +02:00
this->ui->textLogFiles->setAlignment( Qt::AlignHCenter );
2022-06-25 18:48:08 +02:00
}
}
2022-06-21 21:07:06 +02:00
}
void MainWindow::on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
this->on_button_LogFiles_ViewFile_clicked();
}
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);
} else if ( n_checked == this->craplog.getLogsListSize() ) {
2022-06-25 21:17:40 +02:00
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::Checked);
} else {
2022-06-25 21:17:40 +02:00
this->ui->checkBox_LogFiles_CheckAll->setCheckState(Qt::CheckState::PartiallyChecked);
}
}
void MainWindow::on_button_MakeStats_Start_clicked()
{
// take actions on Craplog's start
this->craplogStarted();
// feed craplog with the checked files
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
if ( this->craplog.setLogFileSelected( (*i)->text(0) ) == false ) {
// this shouldn't be, but...
2022-07-01 21:30:15 +02:00
if ( DialogSec::choiceSelectedFileNotFound( nullptr, (*i)->text(0) ) == false ) {
proceed = false;
break;
}
}
}
++i;
}
2022-07-08 21:40:58 +02:00
if ( proceed == true ) {
// check files to be used before to start
2022-07-09 18:16:09 +02:00
proceed = this->craplog.checkStuff();
2022-07-08 21:40:58 +02:00
} else {
this->craplogFinished();
}
if ( proceed == true ) {
2022-07-01 21:30:15 +02:00
// periodically update perfs
this->craplog_timer = new QTimer(this);
connect(this->craplog_timer, SIGNAL(timeout()), this, SLOT(update_Craplog_PerfData()));
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();
this->craplog_thread = std::thread( &Craplog::run, &this->craplog );
} else {
this->craplogFinished();
}
}
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" );
}
void MainWindow::update_MakeStats_labels()
{
// update values
int size, secs;
// size and lines
2022-07-05 21:50:51 +02:00
if ( this->craplog.isParsing() == true ) {
this->craplog.collectPerfData();
}
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-07-05 21:50:51 +02:00
size = this->craplog.getPerfSize();
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 ));
}
void MainWindow::update_Craplog_PerfData()
{
// craplog is running as thread, update the values meanwhile
this->update_MakeStats_labels();
// check if Craplog has finished working
if ( this->craplog.isWorking() == false ) {
this->craplog_timer->stop();
this->craplog_thread.join();
this->craplogFinished();
}
}
2022-06-24 01:26:00 +02:00
void MainWindow::craplogStarted()
{
// reset perfs
this->reset_MakeStats_labels();
this->craplog.logOps.resetPerfData();
// 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-21 21:45:52 +02:00
// disable the stats/settings tab
this->ui->View->setEnabled(false);
2022-07-05 21:50:51 +02:00
this->ui->Set->setEnabled(false);
}
2022-06-24 01:26:00 +02:00
void MainWindow::craplogFinished()
{
// update the perf data one last time, just in case
this->update_MakeStats_labels();
this->craplog.makeGraphs( this->FONTS, this->ui->chart_MakeStats_Access, this->ui->chart_MakeStats_Error, this->ui->chart_MakeStats_Traffic );
// clean up temp vars
2022-07-10 18:14:00 +02:00
this->craplog.clearDataCollection();
this->craplog.logOps.resetPerfData();
// 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)
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-21 21:45:52 +02:00
// enable back the stats/settings tab
this->ui->View->setEnabled(true);
2022-07-05 21:50:51 +02:00
this->ui->Set->setEnabled(true);
2022-07-21 21:45:52 +02:00
// get a fresh collection of available stats dates
this->refreshStatsDates();
}
///////////////
//// STATS ////
///////////////
// refresh all the dates boxes
void MainWindow::refreshStatsDates()
{
this->crapview.refreshDates();
this->on_box_StatsWarn_WebServer_currentIndexChanged(0);
this->on_box_StatsSpeed_WebServer_currentIndexChanged(0);
this->on_box_StatsCount_WebServer_currentIndexChanged(0);
this->on_box_StatsDay_WebServer_currentIndexChanged(0);
this->on_box_StatsRelat_WebServer_currentIndexChanged(0);
2022-07-21 21:45:52 +02:00
}
//////////////
//// WARN ////
void MainWindow::checkStatsWarnDrawable()
{
if ( this->ui->box_StatsWarn_Year->currentIndex() >= 0
&& this->ui->box_StatsWarn_Month->currentIndex() >= 0
&& this->ui->box_StatsWarn_Day->currentIndex() >= 0 ) {
// enable the draw buttpn
this->ui->button_StatsWarn_Draw->setEnabled( true );
} else {
// disable the draw button
this->ui->button_StatsWarn_Draw->setEnabled( false );
}
}
void MainWindow::on_box_StatsWarn_WebServer_currentIndexChanged(int index)
{
this->ui->box_StatsWarn_LogsType->setCurrentIndex( 0 );
this->checkStatsWarnDrawable();
}
void MainWindow::on_box_StatsWarn_LogsType_currentIndexChanged(int index)
{
this->ui->box_StatsWarn_Year->clear();
if ( index != -1 ) {
this->ui->box_StatsWarn_Year->addItems(
this->crapview.getYears(
this->ui->box_StatsWarn_WebServer->currentText(),
this->ui->box_StatsWarn_LogsType->currentText() ));
this->ui->box_StatsWarn_Year->setCurrentIndex( 0 );
}
this->checkStatsWarnDrawable();
}
void MainWindow::on_box_StatsWarn_Year_currentIndexChanged(int index)
{
this->ui->box_StatsWarn_Month->clear();
if ( index != -1 ) {
this->ui->box_StatsWarn_Month->addItems(
this->crapview.getMonths(
this->ui->box_StatsWarn_WebServer->currentText(),
this->ui->box_StatsWarn_LogsType->currentText(),
this->ui->box_StatsWarn_Year->currentText() ) );
this->ui->box_StatsWarn_Month->setCurrentIndex( 0 );
}
this->checkStatsWarnDrawable();
}
void MainWindow::on_box_StatsWarn_Month_currentIndexChanged(int index)
{
this->ui->box_StatsWarn_Day->clear();
if ( index != -1 ) {
this->ui->box_StatsWarn_Day->addItems(
this->crapview.getDays(
this->ui->box_StatsWarn_WebServer->currentText(),
this->ui->box_StatsWarn_LogsType->currentText(),
this->ui->box_StatsWarn_Year->currentText(),
this->ui->box_StatsWarn_Month->currentText() ) );
this->ui->box_StatsWarn_Day->setCurrentIndex( 0 );
}
this->checkStatsWarnDrawable();
}
void MainWindow::on_box_StatsWarn_Day_currentIndexChanged(int index)
{
if ( this->ui->checkBox_StatsWarn_Hour->isChecked() == true ) {
this->ui->box_StatsWarn_Hour->clear();
if ( index != -1 ) {
2022-07-28 22:45:38 +02:00
this->ui->box_StatsWarn_Hour->addItems( this->crapview.getHours() );
this->ui->box_StatsWarn_Hour->setCurrentIndex( 0 );
}
}
this->checkStatsWarnDrawable();
}
void MainWindow::on_checkBox_StatsWarn_Hour_stateChanged(int state)
{
if ( state == Qt::CheckState::Checked ) {
this->ui->box_StatsWarn_Hour->setEnabled( true );
// add available dates
this->on_box_StatsWarn_Day_currentIndexChanged( 0 );
} else {
this->ui->box_StatsWarn_Hour->clear();
this->ui->box_StatsWarn_Hour->setEnabled( false );
}
}
void MainWindow::on_box_StatsWarn_Hour_currentIndexChanged(int index)
{
this->checkStatsWarnDrawable();
}
void MainWindow::on_button_StatsWarn_Draw_clicked()
{
2022-07-28 22:45:38 +02:00
this->ui->table_StatsWarn->setRowCount(0);
this->crapview.drawWarn(
this->ui->table_StatsWarn, this->ui->chart_StatsWarn,
this->FONTS,
this->ui->box_StatsWarn_WebServer->currentText(),
this->ui->box_StatsWarn_LogsType->currentText(),
this->ui->box_StatsWarn_Year->currentText(),
this->ui->box_StatsWarn_Month->currentText(),
this->ui->box_StatsWarn_Day->currentText(),
(this->ui->checkBox_StatsWarn_Hour->isChecked()) ? this->ui->box_StatsWarn_Hour->currentText() : "" );
this->ui->button_StatsWarn_Update->setEnabled( true );
}
2022-07-28 22:45:38 +02:00
void MainWindow::on_button_StatsWarn_Update_clicked()
{
this->crapview.updateWarn(
this->ui->table_StatsWarn,
this->ui->box_StatsWarn_WebServer->currentText(),
this->ui->box_StatsWarn_LogsType->currentText() );
this->on_button_StatsWarn_Draw_clicked();
}
2022-07-21 21:45:52 +02:00
///////////////
//// SPEED ////
void MainWindow::checkStatsSpeedDrawable()
{
if ( this->ui->box_StatsSpeed_Year->currentIndex() >= 0
&& this->ui->box_StatsSpeed_Month->currentIndex() >= 0
&& this->ui->box_StatsSpeed_Day->currentIndex() >= 0 ) {
// enable the draw buttpn
this->ui->button_StatsSpeed_Draw->setEnabled( true );
} else {
// disable the draw button
this->ui->button_StatsSpeed_Draw->setEnabled( false );
}
}
void MainWindow::on_box_StatsSpeed_WebServer_currentIndexChanged(int index)
2022-07-21 21:45:52 +02:00
{
this->ui->box_StatsSpeed_Year->clear();
this->ui->box_StatsSpeed_Year->addItems(
this->crapview.getYears(
this->ui->box_StatsSpeed_WebServer->currentText(),
"Access" ) );
this->ui->box_StatsSpeed_Year->setCurrentIndex( 0 );
this->checkStatsSpeedDrawable();
2022-07-21 21:45:52 +02:00
}
void MainWindow::on_box_StatsSpeed_Year_currentIndexChanged(int index)
{
this->ui->box_StatsSpeed_Month->clear();
if ( index != -1 ) {
this->ui->box_StatsSpeed_Month->addItems(
this->crapview.getMonths(
this->ui->box_StatsSpeed_WebServer->currentText(),
"Access",
this->ui->box_StatsSpeed_Year->currentText() ) );
this->ui->box_StatsSpeed_Month->setCurrentIndex( 0 );
}
this->checkStatsSpeedDrawable();
2022-07-21 21:45:52 +02:00
}
void MainWindow::on_box_StatsSpeed_Month_currentIndexChanged(int index)
{
this->ui->box_StatsSpeed_Day->clear();
if ( index != -1 ) {
this->ui->box_StatsSpeed_Day->addItems(
this->crapview.getDays(
this->ui->box_StatsSpeed_WebServer->currentText(),
"Access",
this->ui->box_StatsSpeed_Year->currentText(),
this->ui->box_StatsSpeed_Month->currentText() ) );
this->ui->box_StatsSpeed_Day->setCurrentIndex( 0 );
}
this->checkStatsSpeedDrawable();
}
void MainWindow::on_box_StatsSpeed_Day_currentIndexChanged(int index)
{
this->checkStatsSpeedDrawable();
2022-07-21 21:45:52 +02:00
}
void MainWindow::on_button_StatsSpeed_Draw_clicked()
{
//this->ui->table_StatsSpeed->clear();
this->ui->table_StatsSpeed->setRowCount(0);
this->crapview.drawSpeed(
this->ui->table_StatsSpeed,
this->ui->chart_SatsSpeed,
this->FONTS,
this->ui->box_StatsSpeed_WebServer->currentText(),
this->ui->box_StatsSpeed_Year->currentText(),
this->ui->box_StatsSpeed_Month->currentText(),
this->ui->box_StatsSpeed_Day->currentText(),
2022-07-28 22:45:38 +02:00
this->crapview.parseTextualFilter( this->ui->inLine_StatsSpeed_Protocol->text() ),
this->crapview.parseTextualFilter( this->ui->inLine_StatsSpeed_Method->text() ),
this->crapview.parseTextualFilter( this->ui->inLine_StatsSpeed_Uri->text() ),
this->crapview.parseTextualFilter( this->ui->inLine_StatsSpeed_Query->text() ),
this->crapview.parseNumericFilter( this->ui->inLine_StatsSpeed_Response->text() ) );
2022-06-21 21:07:06 +02:00
}
2022-07-21 21:45:52 +02:00
///////////////
//// COUNT ////
void MainWindow::checkStatsCountDrawable()
{
if ( this->ui->box_StatsCount_Year->currentIndex() >= 0
&& this->ui->box_StatsCount_Month->currentIndex() >= 0
&& this->ui->box_StatsCount_Day->currentIndex() >= 0 ) {
// enable the draw buttpn
this->ui->scrollArea_StatsCount_Access->setEnabled( true );
this->ui->scrollArea_StatsCount_Error->setEnabled( true );
} else {
// disable the draw button
this->ui->scrollArea_StatsCount_Access->setEnabled( false );
this->ui->scrollArea_StatsCount_Error->setEnabled( false );
}
}
void MainWindow::on_box_StatsCount_WebServer_currentIndexChanged(int index)
{
this->ui->box_StatsCount_Year->clear();
this->ui->box_StatsCount_Year->addItems(
this->crapview.getYears(
this->ui->box_StatsCount_WebServer->currentText(),
this->ui->tabs_StatsCount_AccErr->tabText( this->ui->tabs_StatsCount_AccErr->currentIndex() )));
this->ui->box_StatsCount_Year->setCurrentIndex( 0 );
this->resetStatsCountAccButtons();
this->resetStatsCountErrButtons();
this->checkStatsCountDrawable();
}
void MainWindow::on_tabs_StatsCount_AccErr_currentChanged(int index)
{
this->ui->box_StatsCount_Year->clear();
this->ui->box_StatsCount_Year->addItems(
this->crapview.getYears(
this->ui->box_StatsCount_WebServer->currentText(),
this->ui->tabs_StatsCount_AccErr->tabText( index ) ));
this->ui->box_StatsCount_Year->setCurrentIndex( 0 );
this->checkStatsCountDrawable();
}
void MainWindow::on_box_StatsCount_Year_currentIndexChanged(int index)
{
this->ui->box_StatsCount_Month->clear();
if ( index != -1 ) {
this->ui->box_StatsCount_Month->addItems(
this->crapview.getMonths(
this->ui->box_StatsCount_WebServer->currentText(),
this->ui->tabs_StatsCount_AccErr->tabText( this->ui->tabs_StatsCount_AccErr->currentIndex() ),
this->ui->box_StatsCount_Year->currentText() ) );
this->ui->box_StatsCount_Month->setCurrentIndex( 0 );
}
this->checkStatsCountDrawable();
}
void MainWindow::on_box_StatsCount_Month_currentIndexChanged(int index)
{
this->ui->box_StatsCount_Day->clear();
if ( index != -1 ) {
this->ui->box_StatsCount_Day->addItems(
this->crapview.getDays(
this->ui->box_StatsCount_WebServer->currentText(),
this->ui->tabs_StatsCount_AccErr->tabText( this->ui->tabs_StatsCount_AccErr->currentIndex() ),
this->ui->box_StatsCount_Year->currentText(),
this->ui->box_StatsCount_Month->currentText() ) );
this->ui->box_StatsCount_Day->setCurrentIndex( 0 );
}
this->checkStatsCountDrawable();
}
void MainWindow::on_box_StatsCount_Day_currentIndexChanged(int index)
{
this->checkStatsCountDrawable();
}
void MainWindow::resetStatsCountAccButtons()
{
2022-07-26 20:44:47 +02:00
if ( this->ui->button_StatsCount_Protocol->isFlat() == false ) {
this->ui->button_StatsCount_Protocol->setFlat( true );
}
if ( this->ui->button_StatsCount_Method->isFlat() == false ) {
this->ui->button_StatsCount_Method->setFlat( true );
}
if ( this->ui->button_StatsCount_Request->isFlat() == false ) {
this->ui->button_StatsCount_Request->setFlat( true );
}
if ( this->ui->button_StatsCount_Query->isFlat() == false ) {
this->ui->button_StatsCount_Query->setFlat( true );
}
if ( this->ui->button_StatsCount_Response->isFlat() == false ) {
this->ui->button_StatsCount_Response->setFlat( true );
}
if ( this->ui->button_StatsCount_Referrer->isFlat() == false ) {
this->ui->button_StatsCount_Referrer->setFlat( true );
}
if ( this->ui->button_StatsCount_Cookie->isFlat() == false ) {
this->ui->button_StatsCount_Cookie->setFlat( true );
}
if ( this->ui->button_StatsCount_UserAgent->isFlat() == false ) {
this->ui->button_StatsCount_UserAgent->setFlat( true );
}
if ( this->ui->button_StatsCount_AccClient->isFlat() == false ) {
this->ui->button_StatsCount_AccClient->setFlat( true );
}
}
void MainWindow::resetStatsCountErrButtons()
{
2022-07-26 20:44:47 +02:00
if ( this->ui->button_StatsCount_Level->isFlat() == false ) {
this->ui->button_StatsCount_Level->setFlat( true );
}
if ( this->ui->button_StatsCount_Message->isFlat() == false ) {
this->ui->button_StatsCount_Message->setFlat( true );
}
if ( this->ui->button_StatsCount_Source->isFlat() == false ) {
this->ui->button_StatsCount_Source->setFlat( true );
}
if ( this->ui->button_StatsCount_Port->isFlat() == false ) {
this->ui->button_StatsCount_Port->setFlat( true );
}
if ( this->ui->button_StatsCount_ErrClient->isFlat() == false ) {
this->ui->button_StatsCount_ErrClient->setFlat( true );
}
}
void MainWindow::on_button_StatsCount_Protocol_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Protocol->text() );
this->ui->button_StatsCount_Protocol->setFlat( false );
}
void MainWindow::on_button_StatsCount_Method_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Method->text() );
this->ui->button_StatsCount_Method->setFlat( false );
}
void MainWindow::on_button_StatsCount_Request_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Request->text() );
this->ui->button_StatsCount_Request->setFlat( false );
}
void MainWindow::on_button_StatsCount_Query_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Query->text() );
this->ui->button_StatsCount_Query->setFlat( false );
}
void MainWindow::on_button_StatsCount_Response_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Response->text() );
this->ui->button_StatsCount_Response->setFlat( false );
}
void MainWindow::on_button_StatsCount_Referrer_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Referrer->text() );
this->ui->button_StatsCount_Referrer->setFlat( false );
}
void MainWindow::on_button_StatsCount_Cookie_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Cookie->text() );
this->ui->button_StatsCount_Cookie->setFlat( false );
}
void MainWindow::on_button_StatsCount_UserAgent_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_UserAgent->text() );
this->ui->button_StatsCount_UserAgent->setFlat( false );
}
void MainWindow::on_button_StatsCount_AccClient_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_AccClient->text() );
this->ui->button_StatsCount_AccClient->setFlat( false );
}
void MainWindow::on_button_StatsCount_Level_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Level->text() );
this->ui->button_StatsCount_Level->setFlat( false );
}
void MainWindow::on_button_StatsCount_Message_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Message->text() );
this->ui->button_StatsCount_Message->setFlat( false );
}
void MainWindow::on_button_StatsCount_Source_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Source->text() );
this->ui->button_StatsCount_Source->setFlat( false );
}
void MainWindow::on_button_StatsCount_Port_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_Port->text() );
this->ui->button_StatsCount_Port->setFlat( false );
}
void MainWindow::on_button_StatsCount_ErrClient_clicked()
{
2022-07-26 20:44:47 +02:00
this->drawStatsCount( this->ui->button_StatsCount_ErrClient->text() );
this->ui->button_StatsCount_ErrClient->setFlat( false );
}
void MainWindow::drawStatsCount( const QString& field )
{
this->ui->table_StatsCount->setRowCount(0);
this->crapview.drawCount(
2022-07-26 20:44:47 +02:00
this->ui->table_StatsCount, this->ui->chart_StatsCount, this->FONTS,
this->ui->box_StatsCount_WebServer->currentText(), this->ui->tabs_StatsCount_AccErr->tabText( this->ui->tabs_StatsCount_AccErr->currentIndex() ),
this->ui->box_StatsCount_Year->currentText(), this->ui->box_StatsCount_Month->currentText(), this->ui->box_StatsCount_Day->currentText(),
2022-07-26 20:44:47 +02:00
field );
this->resetStatsCountAccButtons();
this->resetStatsCountErrButtons();
}
/////////////
//// DAY ////
void MainWindow::checkStatsDayDrawable()
{
bool aux = true;
// secondary date (period)
if ( this->ui->checkBox_StatsDay_Period->isChecked() == true ) {
if ( this->ui->box_StatsDay_ToYear->currentIndex() < 0
&& this->ui->box_StatsDay_ToMonth->currentIndex() < 0
&& this->ui->box_StatsDay_ToDay->currentIndex() < 0 ) {
aux = false;
} else {
int a,b;
a = this->ui->box_StatsDay_ToYear->currentText().toInt();
b = this->ui->box_StatsDay_FromYear->currentText().toInt();
if ( a < b ) {
// year 'to' is less than 'from'
aux = false;
} else if ( a == b ) {
a = this->crapview.getMonthNumber( this->ui->box_StatsDay_ToMonth->currentText() );
b = this->crapview.getMonthNumber( this->ui->box_StatsDay_FromMonth->currentText() );
if ( a < b ) {
// month 'to' is less than 'from'
aux = false;
} else if ( a == b ) {
a = this->ui->box_StatsDay_ToDay->currentText().toInt();
b = this->ui->box_StatsDay_FromDay->currentText().toInt();
if ( a < b ) {
// day 'to' is less than 'from'
aux = false;
}
}
}
}
}
// primary date
if ( this->ui->box_StatsDay_FromYear->currentIndex() < 0
&& this->ui->box_StatsDay_FromMonth->currentIndex() < 0
&& this->ui->box_StatsDay_FromDay->currentIndex() < 0 ) {
aux = false;
}
// check log field validity
if ( this->ui->box_StatsDay_LogsField->currentIndex() < 0 ) {
aux = false;
}
this->ui->button_StatsDay_Draw->setEnabled( aux);
}
void MainWindow::on_box_StatsDay_WebServer_currentIndexChanged(int index)
{
this->ui->box_StatsDay_LogsType->setCurrentIndex( 0 );
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_LogsType_currentIndexChanged(int index)
{
this->ui->box_StatsDay_LogsField->clear();
if ( index != -1 ) {
// refresh fields
this->ui->box_StatsDay_LogsField->addItems(
this->crapview.getFields(
"Daytime",
this->ui->box_StatsDay_LogsType->currentText() ));
this->ui->box_StatsDay_LogsField->setCurrentIndex( 0 );
// refresh dates
QStringList years = this->crapview.getYears(
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText() );
this->ui->box_StatsDay_FromYear->clear();
this->ui->box_StatsDay_FromYear->addItems( years );
this->ui->box_StatsDay_FromYear->setCurrentIndex( 0 );
if ( this->ui->checkBox_StatsDay_Period->isChecked() == true ) {
this->ui->box_StatsDay_ToYear->clear();
this->ui->box_StatsDay_ToYear->addItems( years );
this->ui->box_StatsDay_ToYear->setCurrentIndex( 0 );
}
years.clear();
}
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_LogsField_currentIndexChanged(int index)
{
this->ui->inLine_StatsDay_Filter->clear();
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_FromYear_currentIndexChanged(int index)
{
this->ui->box_StatsDay_FromMonth->clear();
if ( index != -1 ) {
this->ui->box_StatsDay_FromMonth->addItems(
this->crapview.getMonths(
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText(),
this->ui->box_StatsDay_FromYear->currentText() ) );
this->ui->box_StatsDay_FromMonth->setCurrentIndex( 0 );
}
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_FromMonth_currentIndexChanged(int index)
{
this->ui->box_StatsDay_FromDay->clear();
if ( index != -1 ) {
this->ui->box_StatsDay_FromDay->addItems(
this->crapview.getDays(
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText(),
this->ui->box_StatsDay_FromYear->currentText(),
this->ui->box_StatsDay_FromMonth->currentText() ) );
this->ui->box_StatsDay_FromDay->setCurrentIndex( 0 );
}
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_FromDay_currentIndexChanged(int index)
{
this->checkStatsDayDrawable();
}
void MainWindow::on_checkBox_StatsDay_Period_stateChanged(int state)
{
if ( state == Qt::CheckState::Checked ) {
this->ui->box_StatsDay_ToYear->setEnabled( true );
this->ui->box_StatsDay_ToMonth->setEnabled( true );
this->ui->box_StatsDay_ToDay->setEnabled( true );
// add available dates
this->ui->box_StatsDay_ToYear->addItems( this->crapview.getYears(
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText() ) );
this->ui->box_StatsDay_ToYear->setCurrentIndex( 0 );
} else {
this->ui->box_StatsDay_ToYear->clear();
this->ui->box_StatsDay_ToYear->setEnabled( false );
this->ui->box_StatsDay_ToMonth->clear();
this->ui->box_StatsDay_ToMonth->setEnabled( false );
this->ui->box_StatsDay_ToDay->clear();
this->ui->box_StatsDay_ToDay->setEnabled( false );
}
}
void MainWindow::on_box_StatsDay_ToYear_currentIndexChanged(int index)
{
this->ui->box_StatsDay_ToMonth->clear();
if ( index != -1 ) {
this->ui->box_StatsDay_ToMonth->addItems(
this->crapview.getMonths(
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText(),
this->ui->box_StatsDay_ToYear->currentText() ) );
this->ui->box_StatsDay_ToMonth->setCurrentIndex( 0 );
}
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_ToMonth_currentIndexChanged(int index)
{
this->ui->box_StatsDay_ToDay->clear();
if ( index != -1 ) {
this->ui->box_StatsDay_ToDay->addItems(
this->crapview.getDays(
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText(),
this->ui->box_StatsDay_ToYear->currentText(),
this->ui->box_StatsDay_ToMonth->currentText() ) );
this->ui->box_StatsDay_ToDay->setCurrentIndex( 0 );
}
this->checkStatsDayDrawable();
}
void MainWindow::on_box_StatsDay_ToDay_currentIndexChanged(int index)
{
this->checkStatsDayDrawable();
}
void MainWindow::on_button_StatsDay_Draw_clicked()
{
2022-07-28 22:45:38 +02:00
QString filter;
if ( this->ui->box_StatsDay_LogsField->currentIndex() == 0 ) {
filter = this->crapview.parseBooleanFilter( this->ui->inLine_StatsDay_Filter->text() );
} else if ( this->ui->box_StatsDay_LogsType->currentIndex() == 0
&& this->ui->box_StatsDay_LogsField->currentIndex() == 5 ) {
filter = this->crapview.parseNumericFilter( this->ui->inLine_StatsDay_Filter->text() );
} else {
filter = this->crapview.parseTextualFilter( this->ui->inLine_StatsDay_Filter->text() );
}
this->crapview.drawDay(
this->ui->chart_StatsDay,
this->FONTS,
this->ui->box_StatsDay_WebServer->currentText(),
this->ui->box_StatsDay_LogsType->currentText(),
this->ui->box_StatsDay_FromYear->currentText(),
this->ui->box_StatsDay_FromMonth->currentText(),
this->ui->box_StatsDay_FromDay->currentText(),
( this->ui->checkBox_StatsDay_Period->isChecked() ) ? this->ui->box_StatsDay_ToYear->currentText() : "",
( this->ui->checkBox_StatsDay_Period->isChecked() ) ? this->ui->box_StatsDay_ToMonth->currentText() : "",
( this->ui->checkBox_StatsDay_Period->isChecked() ) ? this->ui->box_StatsDay_ToDay->currentText() : "",
this->ui->box_StatsDay_LogsField->currentText(),
2022-07-28 22:45:38 +02:00
filter );
}
////////////////////
//// RELATIONAL ////
void MainWindow::checkStatsRelatDrawable()
{
bool aux = true;
if ( this->ui->box_StatsRelat_FromYear->currentIndex() >= 0
&& this->ui->box_StatsRelat_FromMonth->currentIndex() >= 0
&& this->ui->box_StatsRelat_FromDay->currentIndex() >= 0
&& this->ui->box_StatsRelat_ToYear->currentIndex() >= 0
&& this->ui->box_StatsRelat_ToMonth->currentIndex() >= 0
&& this->ui->box_StatsRelat_ToDay->currentIndex() >= 0 ) {
// check period validity
int a,b;
a = this->ui->box_StatsRelat_ToYear->currentText().toInt();
b = this->ui->box_StatsRelat_FromYear->currentText().toInt();
if ( a < b ) {
// year 'to' is less than 'from'
aux = false;
} else if ( a == b ) {
a = this->crapview.getMonthNumber( this->ui->box_StatsRelat_ToMonth->currentText() );
b = this->crapview.getMonthNumber( this->ui->box_StatsRelat_FromMonth->currentText() );
if ( a < b ) {
// month 'to' is less than 'from'
aux = false;
} else if ( a == b ) {
a = this->ui->box_StatsRelat_ToDay->currentText().toInt();
b = this->ui->box_StatsRelat_FromDay->currentText().toInt();
if ( a < b ) {
// day 'to' is less than 'from'
aux = false;
}
}
}
} else {
// disable the draw button
aux = false;
}
// check log field validity
if ( this->ui->box_StatsRelat_LogsField_1->currentIndex() < 0
|| this->ui->box_StatsRelat_LogsField_2->currentIndex() < 0 ) {
aux = false;
}
this->ui->button_StatsRelat_Draw->setEnabled( aux );
}
void MainWindow::on_box_StatsRelat_WebServer_currentIndexChanged(int index)
{
this->ui->box_StatsRelat_LogsType->setCurrentIndex( 0 );
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_LogsType_currentIndexChanged(int index)
{
this->ui->box_StatsRelat_LogsField_1->clear();
this->ui->box_StatsRelat_LogsField_2->clear();
if ( index != -1 ) {
// refresh fields
QStringList fields = this->crapview.getFields(
"Relational",
this->ui->box_StatsRelat_LogsType->currentText() );
this->ui->box_StatsRelat_LogsField_1->addItems( fields );
this->ui->box_StatsRelat_LogsField_2->addItems( fields );
this->ui->box_StatsRelat_LogsField_1->setCurrentIndex( 0 );
this->ui->box_StatsRelat_LogsField_2->setCurrentIndex( 0 );
// refresh dates
QStringList years = this->crapview.getYears(
this->ui->box_StatsRelat_WebServer->currentText(),
this->ui->box_StatsRelat_LogsType->currentText() );
// from
this->ui->box_StatsRelat_FromYear->clear();
this->ui->box_StatsRelat_FromYear->addItems( years );
this->ui->box_StatsRelat_FromYear->setCurrentIndex( 0 );
// to
this->ui->box_StatsRelat_ToYear->clear();
this->ui->box_StatsRelat_ToYear->addItems( years );
this->ui->box_StatsRelat_ToYear->setCurrentIndex( 0 );
years.clear();
}
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_LogsField_1_currentIndexChanged(int index)
{
this->ui->inLine_StatsRelat_Filter_1->clear();
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_LogsField_2_currentIndexChanged(int index)
{
this->ui->inLine_StatsRelat_Filter_2->clear();
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_FromYear_currentIndexChanged(int index)
{
this->ui->box_StatsRelat_FromMonth->clear();
if ( index != -1 ) {
this->ui->box_StatsRelat_FromMonth->addItems(
this->crapview.getMonths(
this->ui->box_StatsRelat_WebServer->currentText(),
this->ui->box_StatsRelat_LogsType->currentText(),
this->ui->box_StatsRelat_FromYear->currentText() ) );
this->ui->box_StatsRelat_FromMonth->setCurrentIndex( 0 );
}
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_FromMonth_currentIndexChanged(int index)
{
this->ui->box_StatsRelat_FromDay->clear();
if ( index != -1 ) {
this->ui->box_StatsRelat_FromDay->addItems(
this->crapview.getDays(
this->ui->box_StatsRelat_WebServer->currentText(),
this->ui->box_StatsRelat_LogsType->currentText(),
this->ui->box_StatsRelat_FromYear->currentText(),
this->ui->box_StatsRelat_FromMonth->currentText() ) );
this->ui->box_StatsRelat_FromDay->setCurrentIndex( 0 );
}
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_FromDay_currentIndexChanged(int index)
{
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_ToYear_currentIndexChanged(int index)
{
this->ui->box_StatsRelat_ToMonth->clear();
if ( index != -1 ) {
this->ui->box_StatsRelat_ToMonth->addItems(
this->crapview.getMonths(
this->ui->box_StatsRelat_WebServer->currentText(),
this->ui->box_StatsRelat_LogsType->currentText(),
2022-07-24 21:03:40 +02:00
this->ui->box_StatsRelat_ToYear->currentText() ) );
this->ui->box_StatsRelat_ToMonth->setCurrentIndex( 0 );
}
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_ToMonth_currentIndexChanged(int index)
{
this->ui->box_StatsRelat_ToDay->clear();
if ( index != -1 ) {
this->ui->box_StatsRelat_ToDay->addItems(
this->crapview.getDays(
this->ui->box_StatsRelat_WebServer->currentText(),
this->ui->box_StatsRelat_LogsType->currentText(),
2022-07-24 21:03:40 +02:00
this->ui->box_StatsRelat_ToYear->currentText(),
this->ui->box_StatsRelat_ToMonth->currentText() ) );
this->ui->box_StatsRelat_ToDay->setCurrentIndex( 0 );
}
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_box_StatsRelat_ToDay_currentIndexChanged(int index)
{
2022-07-23 22:16:34 +02:00
this->checkStatsRelatDrawable();
}
void MainWindow::on_button_StatsRelat_Draw_clicked()
{
2022-07-28 22:45:38 +02:00
QString filter1, filter2;
if ( this->ui->box_StatsRelat_LogsType->currentIndex() == 0 ) {
2022-08-02 21:07:21 +02:00
int aux;
2022-07-28 22:45:38 +02:00
aux = this->ui->box_StatsRelat_LogsField_1->currentIndex();
if ( aux == 0 ) {
filter1 = this->crapview.parseBooleanFilter( this->ui->inLine_StatsRelat_Filter_1->text() );
} else if ( aux >= 5 && aux <= 8 ) {
filter1 = this->crapview.parseNumericFilter( this->ui->inLine_StatsRelat_Filter_1->text() );
} else {
filter1 = this->ui->inLine_StatsRelat_Filter_1->text();
}
aux = this->ui->box_StatsRelat_LogsField_2->currentIndex();
if ( aux == 0 ) {
filter2 = this->crapview.parseBooleanFilter( this->ui->inLine_StatsRelat_Filter_2->text() );
} else if ( aux >= 5 && aux <= 8 ) {
filter2 = this->crapview.parseNumericFilter( this->ui->inLine_StatsRelat_Filter_2->text() );
} else {
filter2 = this->crapview.parseTextualFilter( this->ui->inLine_StatsRelat_Filter_2->text() );
}
} else {
if ( this->ui->box_StatsRelat_LogsField_1->currentIndex() == 0 ) {
filter1 = this->crapview.parseBooleanFilter( this->ui->inLine_StatsRelat_Filter_1->text() );
} else {
filter1 = this->ui->inLine_StatsRelat_Filter_1->text();
}
if ( this->ui->box_StatsRelat_LogsField_2->currentIndex() == 0 ) {
filter2 = this->crapview.parseBooleanFilter( this->ui->inLine_StatsRelat_Filter_2->text() );
} else {
filter2 = this->crapview.parseTextualFilter( this->ui->inLine_StatsRelat_Filter_2->text() );
}
}
this->crapview.drawRelat(
this->ui->chart_StatsRelat,
this->FONTS,
this->ui->box_StatsRelat_WebServer->currentText(),
this->ui->box_StatsRelat_LogsType->currentText(),
this->ui->box_StatsRelat_FromYear->currentText(),
this->ui->box_StatsRelat_FromMonth->currentText(),
this->ui->box_StatsRelat_FromDay->currentText(),
this->ui->box_StatsRelat_ToYear->currentText(),
this->ui->box_StatsRelat_ToMonth->currentText(),
this->ui->box_StatsRelat_ToDay->currentText(),
2022-07-28 22:45:38 +02:00
this->ui->box_StatsRelat_LogsField_1->currentText(), filter1,
this->ui->box_StatsRelat_LogsField_2->currentText(), filter2 );
}
////////////////
//// GLOBAL ////
void MainWindow::on_button_StatsGlob_Apache_clicked()
{
2022-07-30 20:58:23 +02:00
this->crapview.calcGlobals(
this->FONTS,
this->ui->button_StatsGlob_Apache->text(),
"Access" );
if ( this->ui->button_StatsGlob_Apache->isFlat() == true ) {
// un-flat
this->ui->button_StatsGlob_Apache->setFlat( false );
this->ui->button_StatsGlob_Nginx->setFlat( true );
this->ui->button_StatsGlob_Iis->setFlat( true );
}
}
void MainWindow::on_button_StatsGlob_Nginx_clicked()
{
}
void MainWindow::on_button_StatsGlob_Iis_clicked()
{
}
/////////////////
//// CONFIGS ////
/////////////////
/////////////////
//// GENERAL ////
////////////////
//// WINDOW ////
// window geometry
void MainWindow::on_checkBox_ConfGeneral_Window_clicked(bool checked)
{
this->remember_window = checked;
}
// dialogs levels
void MainWindow::on_slider_ConfGeneral_General_sliderReleased()
{
this->dialogs_Level = this->ui->slider_ConfDialogs_General->value();
}
void MainWindow::on_slider_ConfGeneral_Logs_sliderReleased()
{
this->craplog.setDialogLevel( this->ui->slider_ConfDialogs_Logs->value() );
}
void MainWindow::on_slider_ConfGeneral_Stats_sliderReleased()
{
this->crapview.setDialogLevel( this->ui->slider_ConfDialogs_Stats->value() );
}
// themes
void MainWindow::on_box_ConfGeneral_Theme_Window_currentIndexChanged(int index)
{
}
void MainWindow::on_box_ConfGeneral_Theme_TextBrowser_currentIndexChanged(int index)
{
}
void MainWindow::on_box_ConfGeneral_Theme_Charts_currentIndexChanged(int index)
{
}
//////////////
//// LOGS ////
/////////////////
//// CONTROL ////
// usage control
void MainWindow::on_checkBox_ConfControl_Usage_clicked(bool checked)
{
this->display_used_files = checked;
}
// size warning
void MainWindow::on_checkBox_ConfControl_Size_clicked(bool checked)
{
if ( checked == false ) {
// disable size warning
this->ui->spinBox_ConfControl_Size->setEnabled( false );
this->craplog.setWarningSize( 0 );
} else {
// enable warning
this->ui->spinBox_ConfControl_Size->setEnabled( true );
this->craplog.setWarningSize( this->ui->spinBox_ConfControl_Size->value() );
}
}
void MainWindow::on_spinBox_ConfControl_Size_editingFinished()
{
this->craplog.setWarningSize( this->ui->spinBox_ConfControl_Size->value() );
}
////////////////
//// APACHE ////
// paths
void MainWindow::on_checkBox_ConfApache_Paths_Different_clicked(bool checked)
{
if ( checked == true ) {
// enable the error logs path line
this->ui->label_ConfApache_Paths_Access->setEnabled( true );
this->ui->label_ConfApache_Paths_Error->setEnabled( true );
this->ui->inLine_ConfApache_Paths_ErrPath->setEnabled( true );
this->ui->inLine_ConfApache_Paths_ErrPath->setText( QString::fromStdString(
this->craplog.getLogsPath( this->APACHE_ID, this->ERROR_LOGS ) ) );
this->on_inLine_ConfApache_Paths_ErrPath_textChanged(
this->ui->inLine_ConfApache_Paths_ErrPath->text() );
} else {
// disable the error logs path line
this->ui->label_ConfApache_Paths_Access->setEnabled( false );
this->ui->label_ConfApache_Paths_Error->setEnabled( false );
this->ui->inLine_ConfApache_Paths_ErrPath->setEnabled( false );
this->ui->icon_ConfApache_Paths_ErrWrong->setVisible( false );
// set the error logs path equals to the access logs path
this->craplog.setLogsPath( this->APACHE_ID, this->ERROR_LOGS,
this->craplog.getLogsPath( this->APACHE_ID, this->ACCESS_LOGS ) );
}
}
void MainWindow::on_inLine_ConfApache_Paths_AccPath_textChanged(const QString &arg1)
{
if ( IOutils::checkDir( arg1.toStdString() ) == true ) {
this->ui->icon_ConfApache_Paths_AccWrong->setVisible( false );
if ( this->ui->icon_ConfApache_Paths_ErrWrong->isVisible() == false ) {
this->ui->button_ConfApache_Paths_SavePaths->setEnabled( true );
} else {
this->ui->button_ConfApache_Paths_SavePaths->setEnabled( false );
}
}
}
void MainWindow::on_inLine_ConfApache_Paths_ErrPath_textChanged(const QString &arg1)
{
if ( IOutils::checkDir( arg1.toStdString() ) == true ) {
this->ui->icon_ConfApache_Paths_ErrWrong->setVisible( false );
if ( this->ui->icon_ConfApache_Paths_AccWrong->isVisible() == false ) {
this->ui->button_ConfApache_Paths_SavePaths->setEnabled( true );
} else {
this->ui->button_ConfApache_Paths_SavePaths->setEnabled( false );
}
}
}
void MainWindow::on_button_ConfApache_Paths_SavePaths_clicked()
{
if ( this->ui->icon_ConfApache_Paths_ErrWrong->isVisible() == false
&& this->ui->icon_ConfApache_Paths_AccWrong->isVisible() == false ) {
// set the paths
this->craplog.setLogsPath( this->APACHE_ID, this->ACCESS_LOGS,
this->ui->inLine_ConfApache_Paths_AccPath->text().toStdString() );
if ( this->ui->checkBox_ConfApache_Paths_Different->isChecked() == true ) {
this->craplog.setLogsPath( this->APACHE_ID, this->ERROR_LOGS,
this->ui->inLine_ConfApache_Paths_ErrPath->text().toStdString() );
}
}
}
// formats
void MainWindow::on_inLine_ConfApache_Formats_AccString_cursorPositionChanged(int arg1, int arg2)
{
if ( arg2 > 0 ) {
this->ui->button_ConfApache_Format_AccSave->setEnabled( true );
} else {
this->ui->button_ConfApache_Format_AccSave->setEnabled( false );
}
}
void MainWindow::on_button_ConfApache_Format_AccSave_clicked()
{
this->craplog.setApacheALF( this->ui->inLine_ConfApache_Formats_AccString->text().toStdString() );
}
void MainWindow::on_button_ConfApache_Formats_AccSample_clicked()
{
this->ui->label_ConfApache_Formats_AccString->setText(
this->craplog.getLogsFormatSample( this->APACHE_ID, this->ACCESS_LOGS ) );
}
void MainWindow::on_button_ConfApache_Formats_AccHelp_clicked()
{
// !!! 2 COMPLETE !!!
}
void MainWindow::on_inLine_ConfApache_Formats_ErrString_cursorPositionChanged(int arg1, int arg2)
{
if ( arg2 > 0 ) {
this->ui->button_ConfApache_Format_ErrSave->setEnabled( true );
} else {
this->ui->button_ConfApache_Format_ErrSave->setEnabled( false );
}
}
void MainWindow::on_button_ConfApache_Format_ErrSave_clicked()
{
this->craplog.setApacheELF( this->ui->inLine_ConfApache_Formats_ErrString->text().toStdString() );
}
void MainWindow::on_button_ConfApache_Formats_ErrSample_clicked()
{
this->ui->label_ConfApache_Formats_ErrString->setText(
this->craplog.getLogsFormatSample( this->APACHE_ID, this->ERROR_LOGS ) );
}
void MainWindow::on_button_ConfApache_Formats_ErrHelp_clicked()
{
// !!! 2 COMPLETE !!!
}
// warnlists
void MainWindow::on_box_ConfApache_Warnlist_Acc_currentTextChanged(const QString &arg1)
{
this->ui->inLine_ConfApache_Warnlist_Acc->clear();
this->ui->list_ConfApache_Warnlist_Acc->clear();
// update the list
const std::vector<std::string>& list = this->craplog.getWarnlist(
this->APACHE_ID, this->ACCESS_LOGS, this->crapview.getLogFieldID( arg1 ) );
for ( const std::string& item : list ) {
this->ui->list_ConfApache_Warnlist_Acc->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
bool used = this->craplog.isWarnlistUsed(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Acc->currentText() ) );
this->ui->checkBox_ConfApache_Warnlist_AccUsed->setChecked( used );
this->on_checkBox_ConfApache_Warnlist_AccUsed_clicked( used );
}
void MainWindow::on_checkBox_ConfApache_Warnlist_AccUsed_clicked(bool checked)
{
this->craplog.setWarnlistUsed(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Acc->currentText() ),
checked );
if ( this->ui->checkBox_ConfApache_Warnlist_AccUsed->isChecked() == true ) {
this->ui->inLine_ConfApache_Warnlist_Acc->setEnabled( true );
this->ui->list_ConfApache_Warnlist_Acc->setEnabled( true );
} else {
this->ui->inLine_ConfApache_Warnlist_Acc->clear();
this->ui->inLine_ConfApache_Warnlist_Acc->setEnabled( false );
this->ui->list_ConfApache_Warnlist_Acc->clearSelection();
this->ui->list_ConfApache_Warnlist_Acc->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Warnlist_Acc_cursorPositionChanged(int arg1, int arg2)
{
if ( arg2 > 0 ) {
this->ui->button_ConfApache_Warnlist_AccAdd->setEnabled( true );
} else {
this->ui->button_ConfApache_Warnlist_AccAdd->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Warnlist_Acc_returnPressed()
{
this->on_button_ConfApache_Warnlist_AccAdd_clicked();
}
void MainWindow::on_button_ConfApache_Warnlist_AccAdd_clicked()
{
const QString& item = this->ui->inLine_ConfApache_Warnlist_Acc->text();
this->ui->list_ConfApache_Warnlist_Acc->addItem( item );
this->craplog.warnlistAdd(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Acc->currentText() ),
item.toStdString() );
this->ui->inLine_ConfApache_Warnlist_Acc->clear();
}
void MainWindow::on_list_ConfApache_Warnlist_Acc_itemSelectionChanged()
{
if ( this->ui->list_ConfApache_Warnlist_Acc->selectedItems().size() > 0 ) {
this->ui->button_ConfApache_Warnlist_AccRemove->setEnabled( true );
this->ui->button_ConfApache_Warnlist_AccUp->setEnabled( true );
this->ui->button_ConfApache_Warnlist_AccDown->setEnabled( true );
} else {
this->ui->button_ConfApache_Warnlist_AccRemove->setEnabled( false );
this->ui->button_ConfApache_Warnlist_AccUp->setEnabled( false );
this->ui->button_ConfApache_Warnlist_AccDown->setEnabled( false );
}
}
void MainWindow::on_button_ConfApache_Warnlist_AccRemove_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Warnlist_Acc->selectedItems() ) {
this->craplog.warnlistRemove(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Acc->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Warnlist_AccUp_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Warnlist_Acc->selectedItems() ) {
this->craplog.warnlistMoveUp(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Acc->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Warnlist_AccDown_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Warnlist_Acc->selectedItems() ) {
this->craplog.warnlistMoveDown(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Acc->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_box_ConfApache_Warnlist_Err_currentTextChanged(const QString &arg1)
{
this->ui->inLine_ConfApache_Warnlist_Err->clear();
this->ui->list_ConfApache_Warnlist_Err->clear();
// update the list
const std::vector<std::string>& list = this->craplog.getWarnlist(
this->APACHE_ID, this->ERROR_LOGS, this->crapview.getLogFieldID( arg1 ) );
for ( const std::string& item : list ) {
this->ui->list_ConfApache_Warnlist_Err->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
bool used = this->craplog.isWarnlistUsed(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Err->currentText() ) );
this->ui->checkBox_ConfApache_Warnlist_ErrUsed->setChecked( used );
this->on_checkBox_ConfApache_Warnlist_ErrUsed_clicked( used );
}
void MainWindow::on_checkBox_ConfApache_Warnlist_ErrUsed_clicked(bool checked)
{
this->craplog.setWarnlistUsed(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Err->currentText() ),
checked );
if ( this->ui->checkBox_ConfApache_Warnlist_ErrUsed->isChecked() == true ) {
this->ui->inLine_ConfApache_Warnlist_Err->setEnabled( true );
this->ui->list_ConfApache_Warnlist_Err->setEnabled( true );
} else {
this->ui->inLine_ConfApache_Warnlist_Err->clear();
this->ui->inLine_ConfApache_Warnlist_Err->setEnabled( false );
this->ui->list_ConfApache_Warnlist_Err->clearSelection();
this->ui->list_ConfApache_Warnlist_Err->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Warnlist_Err_cursorPositionChanged(int arg1, int arg2)
{
if ( arg2 > 0 ) {
this->ui->button_ConfApache_Warnlist_ErrAdd->setEnabled( true );
} else {
this->ui->button_ConfApache_Warnlist_ErrAdd->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Warnlist_Err_returnPressed()
{
this->on_button_ConfApache_Warnlist_ErrAdd_clicked();
}
void MainWindow::on_button_ConfApache_Warnlist_ErrAdd_clicked()
{
const QString& item = this->ui->inLine_ConfApache_Warnlist_Err->text();
this->ui->list_ConfApache_Warnlist_Err->addItem( item );
this->craplog.warnlistAdd(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Err->currentText() ),
item.toStdString() );
this->ui->inLine_ConfApache_Warnlist_Err->clear();
}
void MainWindow::on_list_ConfApache_Warnlist_Err_itemSelectionChanged()
{
if ( this->ui->list_ConfApache_Warnlist_Err->selectedItems().size() > 0 ) {
this->ui->button_ConfApache_Warnlist_ErrRemove->setEnabled( true );
this->ui->button_ConfApache_Warnlist_ErrUp->setEnabled( true );
this->ui->button_ConfApache_Warnlist_ErrDown->setEnabled( true );
} else {
this->ui->button_ConfApache_Warnlist_ErrRemove->setEnabled( false );
this->ui->button_ConfApache_Warnlist_ErrUp->setEnabled( false );
this->ui->button_ConfApache_Warnlist_ErrDown->setEnabled( false );
}
}
void MainWindow::on_button_ConfApache_Warnlist_ErrRemove_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Warnlist_Err->selectedItems() ) {
this->craplog.warnlistRemove(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Err->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Warnlist_ErrUp_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Warnlist_Err->selectedItems() ) {
this->craplog.warnlistMoveUp(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Err->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Warnlist_ErrDown_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Warnlist_Err->selectedItems() ) {
this->craplog.warnlistMoveDown(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Err->currentText() ),
item->text().toStdString() );
}
}
// blacklist
void MainWindow::on_box_ConfApache_Blacklist_Acc_currentTextChanged(const QString &arg1)
{
this->ui->inLine_ConfApache_Blacklist_Acc->clear();
this->ui->list_ConfApache_Blacklist_Acc->clear();
// update the list
const std::vector<std::string>& list = this->craplog.getBlacklist(
this->APACHE_ID, this->ACCESS_LOGS, this->crapview.getLogFieldID( arg1 ) );
for ( const std::string& item : list ) {
this->ui->list_ConfApache_Blacklist_Acc->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
bool used = this->craplog.isBlacklistUsed(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Acc->currentText() ) );
this->ui->checkBox_ConfApache_Blacklist_AccUsed->setChecked( used );
this->on_checkBox_ConfApache_Blacklist_AccUsed_clicked( used );
}
void MainWindow::on_checkBox_ConfApache_Blacklist_AccUsed_clicked(bool checked)
{
this->craplog.setBlacklistUsed(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Acc->currentText() ),
checked );
if ( this->ui->checkBox_ConfApache_Blacklist_AccUsed->isChecked() == true ) {
this->ui->inLine_ConfApache_Blacklist_Acc->setEnabled( true );
this->ui->list_ConfApache_Blacklist_Acc->setEnabled( true );
} else {
this->ui->inLine_ConfApache_Blacklist_Acc->clear();
this->ui->inLine_ConfApache_Blacklist_Acc->setEnabled( false );
this->ui->list_ConfApache_Blacklist_Acc->clearSelection();
this->ui->list_ConfApache_Blacklist_Acc->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Blacklist_Acc_cursorPositionChanged(int arg1, int arg2)
{
if ( arg2 > 0 ) {
this->ui->button_ConfApache_Blacklist_AccAdd->setEnabled( true );
} else {
this->ui->button_ConfApache_Blacklist_AccAdd->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Blacklist_Acc_returnPressed()
{
this->on_button_ConfApache_Blacklist_AccAdd_clicked();
}
void MainWindow::on_button_ConfApache_Blacklist_AccAdd_clicked()
{
const QString& item = this->ui->inLine_ConfApache_Blacklist_Acc->text();
this->ui->list_ConfApache_Blacklist_Acc->addItem( item );
this->craplog.blacklistAdd(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Acc->currentText() ),
item.toStdString() );
this->ui->inLine_ConfApache_Blacklist_Acc->clear();
}
void MainWindow::on_list_ConfApache_Blacklist_Acc_itemSelectionChanged()
{
if ( this->ui->list_ConfApache_Blacklist_Acc->selectedItems().size() > 0 ) {
this->ui->button_ConfApache_Blacklist_AccRemove->setEnabled( true );
this->ui->button_ConfApache_Blacklist_AccUp->setEnabled( true );
this->ui->button_ConfApache_Blacklist_AccDown->setEnabled( true );
} else {
this->ui->button_ConfApache_Blacklist_AccRemove->setEnabled( false );
this->ui->button_ConfApache_Blacklist_AccUp->setEnabled( false );
this->ui->button_ConfApache_Blacklist_AccDown->setEnabled( false );
}
}
void MainWindow::on_button_ConfApache_Blacklist_AccRemove_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Blacklist_Acc->selectedItems() ) {
this->craplog.blacklistRemove(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Acc->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Blacklist_AccUp_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Blacklist_Acc->selectedItems() ) {
this->craplog.blacklistMoveUp(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Acc->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Blacklist_AccDown_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Blacklist_Acc->selectedItems() ) {
this->craplog.blacklistMoveDown(
this->APACHE_ID, this->ACCESS_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Acc->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_box_ConfApache_Blacklist_Err_currentTextChanged(const QString &arg1)
{
this->ui->inLine_ConfApache_Blacklist_Err->clear();
this->ui->list_ConfApache_Blacklist_Err->clear();
// update the list
const std::vector<std::string>& list = this->craplog.getBlacklist(
this->APACHE_ID, this->ERROR_LOGS, this->crapview.getLogFieldID( arg1 ) );
for ( const std::string& item : list ) {
this->ui->list_ConfApache_Blacklist_Err->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
bool used = this->craplog.isBlacklistUsed(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Err->currentText() ) );
this->ui->checkBox_ConfApache_Blacklist_ErrUsed->setChecked( used );
this->on_checkBox_ConfApache_Blacklist_ErrUsed_clicked( used );
}
void MainWindow::on_checkBox_ConfApache_Blacklist_ErrUsed_clicked(bool checked)
{
this->craplog.setBlacklistUsed(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Err->currentText() ),
checked );
if ( this->ui->checkBox_ConfApache_Blacklist_ErrUsed->isChecked() == true ) {
this->ui->inLine_ConfApache_Blacklist_Err->setEnabled( true );
this->ui->list_ConfApache_Blacklist_Err->setEnabled( true );
} else {
this->ui->inLine_ConfApache_Blacklist_Err->clear();
this->ui->inLine_ConfApache_Blacklist_Err->setEnabled( false );
this->ui->list_ConfApache_Blacklist_Err->clearSelection();
this->ui->list_ConfApache_Blacklist_Err->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Blacklist_Err_cursorPositionChanged(int arg1, int arg2)
{
if ( arg2 > 0 ) {
this->ui->button_ConfApache_Blacklist_ErrAdd->setEnabled( true );
} else {
this->ui->button_ConfApache_Blacklist_ErrAdd->setEnabled( false );
}
}
void MainWindow::on_inLine_ConfApache_Blacklist_Err_returnPressed()
{
this->on_button_ConfApache_Blacklist_ErrAdd_clicked();
}
void MainWindow::on_button_ConfApache_Blacklist_ErrAdd_clicked()
{
const QString& item = this->ui->inLine_ConfApache_Blacklist_Err->text();
this->ui->list_ConfApache_Blacklist_Err->addItem( item );
this->craplog.blacklistAdd(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Err->currentText() ),
item.toStdString() );
this->ui->inLine_ConfApache_Blacklist_Err->clear();
}
void MainWindow::on_list_ConfApache_Blacklist_Err_itemSelectionChanged()
{
if ( this->ui->list_ConfApache_Blacklist_Err->selectedItems().size() > 0 ) {
this->ui->button_ConfApache_Blacklist_ErrRemove->setEnabled( true );
this->ui->button_ConfApache_Blacklist_ErrUp->setEnabled( true );
this->ui->button_ConfApache_Blacklist_ErrDown->setEnabled( true );
} else {
this->ui->button_ConfApache_Blacklist_ErrRemove->setEnabled( false );
this->ui->button_ConfApache_Blacklist_ErrUp->setEnabled( false );
this->ui->button_ConfApache_Blacklist_ErrDown->setEnabled( false );
}
}
void MainWindow::on_button_ConfApache_Blacklist_ErrRemove_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Blacklist_Err->selectedItems() ) {
this->craplog.blacklistRemove(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Err->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Blacklist_ErrUp_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Blacklist_Err->selectedItems() ) {
this->craplog.blacklistMoveUp(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Err->currentText() ),
item->text().toStdString() );
}
}
void MainWindow::on_button_ConfApache_Blacklist_ErrDown_clicked()
{
for ( auto& item : this->ui->list_ConfApache_Blacklist_Err->selectedItems() ) {
this->craplog.blacklistMoveDown(
this->APACHE_ID, this->ERROR_LOGS,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Err->currentText() ),
item->text().toStdString() );
}
}