This commit is contained in:
Valentino Orlandi 2024-01-22 00:14:26 +01:00
parent f5c276f6be
commit 6cba718598
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
11 changed files with 370 additions and 357 deletions

View File

@ -2,12 +2,15 @@
#define LOGDOCTOR__DEFINES__WEB_SERVERS_H
#include "lib.h"
//! ID of the Apache2 Web Server
#define APACHE_ID 11u
#define WS_APACHE WebServer::Apache
//! ID of the Nginx Web Server
#define NGINX_ID 12u
#define WS_NGINX WebServer::Nginx
//! ID of the IIS Web Server
#define IIS_ID 13u
#define WS_IIS WebServer::IIS
#endif // LOGDOCTOR__DEFINES__WEBSERVERS_H

View File

@ -165,24 +165,24 @@ MainWindow::MainWindow(QWidget *parent)
}
// set the default WS as the current one
switch ( this->default_ws ) {
case APACHE_ID:
switch ( this->default_web_server ) {
case WS_APACHE:
this->ui->button_LogFiles_Apache->setFlat( false );
this->ui->radio_ConfDefaults_Apache->setChecked( true );
break;
case NGINX_ID:
case WS_NGINX:
this->ui->button_LogFiles_Nginx->setFlat( false );
this->ui->radio_ConfDefaults_Nginx->setChecked( true );
break;
case IIS_ID:
case WS_IIS:
this->ui->button_LogFiles_Iis->setFlat( false );
this->ui->radio_ConfDefaults_Iis->setChecked( true );
break;
default:
// shouldn't be here
throw WebServerException( "Unexpected WebServer ID: "+std::to_string( this->default_ws ) );
throw WebServerException( "Unexpected WebServer: " + toString(this->default_web_server) );
}
this->craplog.setCurrentWSID( this->default_ws );
this->craplog.setCurrentWebServer( this->default_web_server );
// initialize the Configs
@ -221,30 +221,30 @@ MainWindow::MainWindow(QWidget *parent)
this->ui->checkBox_ConfControl_Size->setChecked( false );
}
// apache paths
this->ui->inLine_ConfApache_Path_String->setText( QString::fromStdString(this->craplog.getLogsPath( APACHE_ID )) );
this->ui->inLine_ConfApache_Path_String->setText( QString::fromStdString(this->craplog.getLogsPath( WS_APACHE )) );
this->ui->button_ConfApache_Path_Save->setEnabled( false );
// apache formats
this->ui->inLine_ConfApache_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( APACHE_ID ) ) );
this->ui->inLine_ConfApache_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( WS_APACHE ) ) );
this->ui->button_ConfApache_Format_Save->setEnabled( false );
// apache warnlists
this->on_box_ConfApache_Warnlist_Field_currentTextChanged( this->ui->box_ConfApache_Warnlist_Field->currentText() );
// apache blacklists
this->on_box_ConfApache_Blacklist_Field_currentTextChanged( this->ui->box_ConfApache_Blacklist_Field->currentText() );
// nginx paths
this->ui->inLine_ConfNginx_Path_String->setText( QString::fromStdString(this->craplog.getLogsPath( NGINX_ID )) );
this->ui->inLine_ConfNginx_Path_String->setText( QString::fromStdString(this->craplog.getLogsPath( WS_NGINX )) );
this->ui->button_ConfNginx_Path_Save->setEnabled( false );
// nginx formats
this->ui->inLine_ConfNginx_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( NGINX_ID ) ) );
this->ui->inLine_ConfNginx_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( WS_NGINX ) ) );
this->ui->button_ConfNginx_Format_Save->setEnabled( false );
// nginx warnlists
this->on_box_ConfNginx_Warnlist_Field_currentTextChanged( this->ui->box_ConfNginx_Warnlist_Field->currentText() );
// nginx blacklists
this->on_box_ConfNginx_Blacklist_Field_currentTextChanged( this->ui->box_ConfNginx_Blacklist_Field->currentText() );
// iis paths
this->ui->inLine_ConfIis_Path_String->setText( QString::fromStdString(this->craplog.getLogsPath( IIS_ID )) );
this->ui->inLine_ConfIis_Path_String->setText( QString::fromStdString(this->craplog.getLogsPath( WS_IIS )) );
this->ui->button_ConfIis_Path_Save->setEnabled( false );
// iis formats
this->ui->inLine_ConfIis_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( IIS_ID ) ) );
this->ui->inLine_ConfIis_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( WS_IIS ) ) );
this->ui->button_ConfIis_Format_Save->setEnabled( false );
// iis warnlists
this->on_box_ConfIis_Warnlist_Field_currentTextChanged( this->ui->box_ConfIis_Warnlist_Field->currentText() );
@ -382,7 +382,7 @@ void MainWindow::readConfigs()
std::vector<std::string> aux, configs;
try {
// reset the lists when a config file is found
for ( unsigned w=APACHE_ID; w<=IIS_ID; ++w ) {
for ( const WebServer& w : {WS_APACHE,WS_NGINX,WS_IIS} ) {
for ( const int& f : {11,12,20,21} ) {
this->craplog.setWarnlist( w, f, {} );
}
@ -442,7 +442,7 @@ void MainWindow::readConfigs()
this->dialogs_level = std::stoi( val );
} else if ( var == "DefaultWebServer" ) {
this->default_ws = std::stoi( val );
this->default_web_server = fromString( val );
} else if ( var == "DatabaseDataPath" ) {
this->db_data_path = this->resolvePath( val );
@ -475,7 +475,7 @@ void MainWindow::readConfigs()
this->craplog.setWarningSize( std::stoul( val ) );
} else if ( var == "ApacheLogsPath" ) {
this->craplog.setLogsPath( APACHE_ID, this->resolvePath( val ) );
this->craplog.setLogsPath( WS_APACHE, this->resolvePath( val ) );
} else if ( var == "ApacheLogsFormat" ) {
if ( ! this->craplog.setApacheLogFormat( val ) ) {
@ -485,45 +485,45 @@ void MainWindow::readConfigs()
} else if ( var == "ApacheWarnlistMethod" ) {
aux_err_msg = QString("Apache -> %1 (%2)")
.arg( TR::tr(FIELDS__METHOD.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( APACHE_ID, 11, this->string2list( val ) );
this->craplog.setWarnlist( WS_APACHE, 11, this->string2list( val ) );
} else if ( var == "ApacheWarnlistMethodUsed" ) {
this->craplog.setWarnlistUsed( APACHE_ID, 11, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_APACHE, 11, this->s2b.at( val ) );
} else if ( var == "ApacheWarnlistURI" ) {
aux_err_msg = QString("Apache -> %1 (%2)")
.arg( TR::tr(FIELDS__URI.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( APACHE_ID, 12, this->string2list( val ) );
this->craplog.setWarnlist( WS_APACHE, 12, this->string2list( val ) );
} else if ( var == "ApacheWarnlistURIUsed" ) {
this->craplog.setWarnlistUsed( APACHE_ID, 12, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_APACHE, 12, this->s2b.at( val ) );
} else if ( var == "ApacheWarnlistClient" ) {
aux_err_msg = QString("Apache -> %1 (%2)")
.arg( TR::tr(FIELDS__CLIENT.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( APACHE_ID, 20, this->string2list( val ) );
this->craplog.setWarnlist( WS_APACHE, 20, this->string2list( val ) );
} else if ( var == "ApacheWarnlistClientUsed" ) {
this->craplog.setWarnlistUsed( APACHE_ID, 20, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_APACHE, 20, this->s2b.at( val ) );
} else if ( var == "ApacheWarnlistUserAgent" ) {
aux_err_msg = QString("Apache -> %1 (%2)")
.arg( TR::tr(FIELDS__USER_AGENT.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( APACHE_ID, 21, this->string2list( val, true ) );
this->craplog.setWarnlist( WS_APACHE, 21, this->string2list( val, true ) );
} else if ( var == "ApacheWarnlistUserAgentUsed" ) {
this->craplog.setWarnlistUsed( APACHE_ID, 21, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_APACHE, 21, this->s2b.at( val ) );
} else if ( var == "ApacheBlacklistClient" ) {
aux_err_msg = QString("Apache -> %1 (%2)")
.arg( TR::tr(FIELDS__CLIENT.c_str()), MainWindow::tr("blacklist") );
this->craplog.setBlacklist( APACHE_ID, 20, this->string2list( val ) );
this->craplog.setBlacklist( WS_APACHE, 20, this->string2list( val ) );
} else if ( var == "ApacheBlacklistClientUsed" ) {
this->craplog.setBlacklistUsed( APACHE_ID, 20, this->s2b.at( val ) );
this->craplog.setBlacklistUsed( WS_APACHE, 20, this->s2b.at( val ) );
} else if ( var == "NginxLogsPath" ) {
this->craplog.setLogsPath( NGINX_ID, this->resolvePath( val ) );
this->craplog.setLogsPath( WS_NGINX, this->resolvePath( val ) );
} else if ( var == "NginxLogsFormat" ) {
if ( ! this->craplog.setNginxLogFormat( val ) ) {
@ -533,45 +533,45 @@ void MainWindow::readConfigs()
} else if ( var == "NginxWarnlistMethod" ) {
aux_err_msg = QString("Nginx -> %1 (%2)")
.arg( TR::tr(FIELDS__METHOD.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( NGINX_ID, 11, this->string2list( val ) );
this->craplog.setWarnlist( WS_NGINX, 11, this->string2list( val ) );
} else if ( var == "NginxWarnlistMethodUsed" ) {
this->craplog.setWarnlistUsed( NGINX_ID, 11, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_NGINX, 11, this->s2b.at( val ) );
} else if ( var == "NginxWarnlistURI" ) {
aux_err_msg = QString("Nginx -> %1 (%2)")
.arg( TR::tr(FIELDS__URI.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( NGINX_ID, 12, this->string2list( val ) );
this->craplog.setWarnlist( WS_NGINX, 12, this->string2list( val ) );
} else if ( var == "NginxWarnlistURIUsed" ) {
this->craplog.setWarnlistUsed( NGINX_ID, 12, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_NGINX, 12, this->s2b.at( val ) );
} else if ( var == "NginxWarnlistClient" ) {
aux_err_msg = QString("Nginx -> %1 (%2)")
.arg( TR::tr(FIELDS__CLIENT.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( NGINX_ID, 20, this->string2list( val ) );
this->craplog.setWarnlist( WS_NGINX, 20, this->string2list( val ) );
} else if ( var == "NginxWarnlistClientUsed" ) {
this->craplog.setWarnlistUsed( NGINX_ID, 20, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_NGINX, 20, this->s2b.at( val ) );
} else if ( var == "NginxWarnlistUserAgent" ) {
aux_err_msg = QString("Nginx -> %1 (%2)")
.arg( TR::tr(FIELDS__USER_AGENT.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( NGINX_ID, 21, this->string2list( val, true ) );
this->craplog.setWarnlist( WS_NGINX, 21, this->string2list( val, true ) );
} else if ( var == "NginxWarnlistUserAgentUsed" ) {
this->craplog.setWarnlistUsed( NGINX_ID, 21, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_NGINX, 21, this->s2b.at( val ) );
} else if ( var == "NginxBlacklistClient" ) {
aux_err_msg = QString("Nginx -> %1 (%2)")
.arg( TR::tr(FIELDS__CLIENT.c_str()), MainWindow::tr("blacklist") );
this->craplog.setBlacklist( NGINX_ID, 20, this->string2list( val ) );
this->craplog.setBlacklist( WS_NGINX, 20, this->string2list( val ) );
} else if ( var == "NginxBlacklistClientUsed" ) {
this->craplog.setBlacklistUsed( NGINX_ID, 20, this->s2b.at( val ) );
this->craplog.setBlacklistUsed( WS_NGINX, 20, this->s2b.at( val ) );
} else if ( var == "IisLogsPath" ) {
this->craplog.setLogsPath( IIS_ID, this->resolvePath( val ) );
this->craplog.setLogsPath( WS_IIS, this->resolvePath( val ) );
} else if ( var == "IisLogsModule" ) {
if ( val == "1" ) {
@ -594,42 +594,42 @@ void MainWindow::readConfigs()
} else if ( var == "IisWarnlistMethod" ) {
aux_err_msg = QString("IIS -> %1 (%2)")
.arg( TR::tr(FIELDS__METHOD.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( IIS_ID, 11, this->string2list( val ) );
this->craplog.setWarnlist( WS_IIS, 11, this->string2list( val ) );
} else if ( var == "IisWarnlistMethodUsed" ) {
this->craplog.setWarnlistUsed( IIS_ID, 11, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_IIS, 11, this->s2b.at( val ) );
} else if ( var == "IisWarnlistURI" ) {
aux_err_msg = QString("IIS -> %1 (%2)")
.arg( TR::tr(FIELDS__URI.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( IIS_ID, 12, this->string2list( val ) );
this->craplog.setWarnlist( WS_IIS, 12, this->string2list( val ) );
} else if ( var == "IisWarnlistURIUsed" ) {
this->craplog.setWarnlistUsed( IIS_ID, 12, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_IIS, 12, this->s2b.at( val ) );
} else if ( var == "IisWarnlistClient" ) {
aux_err_msg = QString("IIS -> %1 (%2)")
.arg( TR::tr(FIELDS__CLIENT.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( IIS_ID, 20, this->string2list( val ) );
this->craplog.setWarnlist( WS_IIS, 20, this->string2list( val ) );
} else if ( var == "IisWarnlistClientUsed" ) {
this->craplog.setWarnlistUsed( IIS_ID, 20, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_IIS, 20, this->s2b.at( val ) );
} else if ( var == "IisWarnlistUserAgent" ) {
aux_err_msg = QString("IIS -> %1 (%2)")
.arg( TR::tr(FIELDS__USER_AGENT.c_str()), MainWindow::tr("warnlist") );
this->craplog.setWarnlist( IIS_ID, 21, this->string2list( val, true ) );
this->craplog.setWarnlist( WS_IIS, 21, this->string2list( val, true ) );
} else if ( var == "IisWarnlistUserAgentUsed" ) {
this->craplog.setWarnlistUsed( IIS_ID, 21, this->s2b.at( val ) );
this->craplog.setWarnlistUsed( WS_IIS, 21, this->s2b.at( val ) );
} else if ( var == "IisBlacklistClient" ) {
aux_err_msg = QString("IIS -> %1 (%2)")
.arg( TR::tr(FIELDS__CLIENT.c_str()), MainWindow::tr("blacklist") );
this->craplog.setBlacklist( IIS_ID, 20, this->string2list( val ) );
this->craplog.setBlacklist( WS_IIS, 20, this->string2list( val ) );
} else if ( var == "IisBlacklistClientUsed" ) {
this->craplog.setBlacklistUsed( IIS_ID, 20, this->s2b.at( val ) );
this->craplog.setBlacklistUsed( WS_IIS, 20, this->s2b.at( val ) );
} else if ( var == "CrapviewDialogsLevel" ) {
this->crapview.setDialogsLevel( std::stoi( val ) );
@ -780,7 +780,7 @@ void MainWindow::writeConfigs()
configs += "\nIconsTheme=" + std::to_string( static_cast<themes_t>(GlobalConfigs::icons_theme) );
configs += "\nChartsTheme=" + std::to_string( static_cast<themes_t>(GlobalConfigs::charts_theme) );
configs += "\nMainDialogsLevel=" + std::to_string( this->dialogs_level );
configs += "\nDefaultWebServer=" + std::to_string( this->default_ws );
configs += "\nDefaultWebServer=" + toString( this->default_web_server );
configs += "\nDatabaseDataPath=" + this->db_data_path;
configs += "\nDatabaseHashesPath=" + this->db_hashes_path;
configs += "\nDatabaseDoBackup=" + this->b2s.at( this->db_do_backup );
@ -797,35 +797,35 @@ void MainWindow::writeConfigs()
configs += "\nWarningSize=" + std::to_string( this->craplog.getWarningSize() );
//// APACHE2 ////
configs += "\n\n[Apache2]";
configs += "\nApacheLogsPath=" + this->craplog.getLogsPath( APACHE_ID );
configs += "\nApacheLogsFormat=" + this->craplog.getLogsFormatString( APACHE_ID );
configs += "\nApacheWarnlistMethod=" + this->list2string( this->craplog.getWarnlist( APACHE_ID, 11 ) );
configs += "\nApacheWarnlistMethodUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( APACHE_ID, 11 ) );
configs += "\nApacheWarnlistURI=" + this->list2string( this->craplog.getWarnlist( APACHE_ID, 12 ) );
configs += "\nApacheWarnlistURIUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( APACHE_ID, 12 ) );
configs += "\nApacheWarnlistClient=" + this->list2string( this->craplog.getWarnlist( APACHE_ID, 20 ) );
configs += "\nApacheWarnlistClientUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( APACHE_ID, 20 ) );
configs += "\nApacheWarnlistUserAgent=" + this->list2string( this->craplog.getWarnlist( APACHE_ID, 21 ), true );
configs += "\nApacheWarnlistUserAgentUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( APACHE_ID, 21 ) );
configs += "\nApacheBlacklistClient=" + this->list2string( this->craplog.getBlacklist( APACHE_ID, 20 ) );
configs += "\nApacheBlacklistClientUsed=" + this->b2s.at( this->craplog.isBlacklistUsed( APACHE_ID, 20 ) );
configs += "\nApacheLogsPath=" + this->craplog.getLogsPath( WS_APACHE );
configs += "\nApacheLogsFormat=" + this->craplog.getLogsFormatString( WS_APACHE );
configs += "\nApacheWarnlistMethod=" + this->list2string( this->craplog.getWarnlist( WS_APACHE, 11 ) );
configs += "\nApacheWarnlistMethodUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_APACHE, 11 ) );
configs += "\nApacheWarnlistURI=" + this->list2string( this->craplog.getWarnlist( WS_APACHE, 12 ) );
configs += "\nApacheWarnlistURIUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_APACHE, 12 ) );
configs += "\nApacheWarnlistClient=" + this->list2string( this->craplog.getWarnlist( WS_APACHE, 20 ) );
configs += "\nApacheWarnlistClientUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_APACHE, 20 ) );
configs += "\nApacheWarnlistUserAgent=" + this->list2string( this->craplog.getWarnlist( WS_APACHE, 21 ), true );
configs += "\nApacheWarnlistUserAgentUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_APACHE, 21 ) );
configs += "\nApacheBlacklistClient=" + this->list2string( this->craplog.getBlacklist( WS_APACHE, 20 ) );
configs += "\nApacheBlacklistClientUsed=" + this->b2s.at( this->craplog.isBlacklistUsed( WS_APACHE, 20 ) );
//// NGINX ////
configs += "\n\n[Nginx]";
configs += "\nNginxLogsPath=" + this->craplog.getLogsPath( NGINX_ID );
configs += "\nNginxLogsFormat=" + this->craplog.getLogsFormatString( NGINX_ID );
configs += "\nNginxWarnlistMethod=" + this->list2string( this->craplog.getWarnlist( NGINX_ID, 11 ) );
configs += "\nNginxWarnlistMethodUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( NGINX_ID, 11 ) );
configs += "\nNginxWarnlistURI=" + this->list2string( this->craplog.getWarnlist( NGINX_ID, 12 ) );
configs += "\nNginxWarnlistURIUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( NGINX_ID, 12 ) );
configs += "\nNginxWarnlistClient=" + this->list2string( this->craplog.getWarnlist( NGINX_ID, 20 ) );
configs += "\nNginxWarnlistClientUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( NGINX_ID, 20 ) );
configs += "\nNginxWarnlistUserAgent=" + this->list2string( this->craplog.getWarnlist( NGINX_ID, 21 ), true );
configs += "\nNginxWarnlistUserAgentUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( NGINX_ID, 21 ) );
configs += "\nNginxBlacklistClient=" + this->list2string( this->craplog.getBlacklist( NGINX_ID, 20 ) );
configs += "\nNginxBlacklistClientUsed=" + this->b2s.at( this->craplog.isBlacklistUsed( NGINX_ID, 20 ) );
configs += "\nNginxLogsPath=" + this->craplog.getLogsPath( WS_NGINX );
configs += "\nNginxLogsFormat=" + this->craplog.getLogsFormatString( WS_NGINX );
configs += "\nNginxWarnlistMethod=" + this->list2string( this->craplog.getWarnlist( WS_NGINX, 11 ) );
configs += "\nNginxWarnlistMethodUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_NGINX, 11 ) );
configs += "\nNginxWarnlistURI=" + this->list2string( this->craplog.getWarnlist( WS_NGINX, 12 ) );
configs += "\nNginxWarnlistURIUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_NGINX, 12 ) );
configs += "\nNginxWarnlistClient=" + this->list2string( this->craplog.getWarnlist( WS_NGINX, 20 ) );
configs += "\nNginxWarnlistClientUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_NGINX, 20 ) );
configs += "\nNginxWarnlistUserAgent=" + this->list2string( this->craplog.getWarnlist( WS_NGINX, 21 ), true );
configs += "\nNginxWarnlistUserAgentUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_NGINX, 21 ) );
configs += "\nNginxBlacklistClient=" + this->list2string( this->craplog.getBlacklist( WS_NGINX, 20 ) );
configs += "\nNginxBlacklistClientUsed=" + this->b2s.at( this->craplog.isBlacklistUsed( WS_NGINX, 20 ) );
//// IIS ////
configs += "\n\n[IIS]";
configs += "\nIisLogsPath=" + this->craplog.getLogsPath( IIS_ID );
configs += "\nIisLogsPath=" + this->craplog.getLogsPath( WS_IIS );
std::string module{ "0" };
if ( this->ui->radio_ConfIis_Format_NCSA->isChecked() ) {
module = "1";
@ -833,17 +833,17 @@ void MainWindow::writeConfigs()
module = "2";
}
configs += "\nIisLogsModule=" + module;
configs += "\nIisLogsFormat=" + this->craplog.getLogsFormatString( IIS_ID );
configs += "\nIisWarnlistMethod=" + this->list2string( this->craplog.getWarnlist( IIS_ID, 11 ) );
configs += "\nIisWarnlistMethodUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( IIS_ID, 11 ) );
configs += "\nIisWarnlistURI=" + this->list2string( this->craplog.getWarnlist( IIS_ID, 12 ) );
configs += "\nIisWarnlistURIUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( IIS_ID, 12 ) );
configs += "\nIisWarnlistClient=" + this->list2string( this->craplog.getWarnlist( IIS_ID, 20 ) );
configs += "\nIisWarnlistClientUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( IIS_ID, 20 ) );
configs += "\nIisWarnlistUserAgent=" + this->list2string( this->craplog.getWarnlist( IIS_ID, 21 ), true );
configs += "\nIisWarnlistUserAgentUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( IIS_ID, 21 ) );
configs += "\nIisBlacklistClient=" + this->list2string( this->craplog.getBlacklist( IIS_ID, 20 ) );
configs += "\nIisBlacklistClientUsed=" + this->b2s.at( this->craplog.isBlacklistUsed( IIS_ID, 20 ) );
configs += "\nIisLogsFormat=" + this->craplog.getLogsFormatString( WS_IIS );
configs += "\nIisWarnlistMethod=" + this->list2string( this->craplog.getWarnlist( WS_IIS, 11 ) );
configs += "\nIisWarnlistMethodUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_IIS, 11 ) );
configs += "\nIisWarnlistURI=" + this->list2string( this->craplog.getWarnlist( WS_IIS, 12 ) );
configs += "\nIisWarnlistURIUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_IIS, 12 ) );
configs += "\nIisWarnlistClient=" + this->list2string( this->craplog.getWarnlist( WS_IIS, 20 ) );
configs += "\nIisWarnlistClientUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_IIS, 20 ) );
configs += "\nIisWarnlistUserAgent=" + this->list2string( this->craplog.getWarnlist( WS_IIS, 21 ), true );
configs += "\nIisWarnlistUserAgentUsed=" + this->b2s.at( this->craplog.isWarnlistUsed( WS_IIS, 21 ) );
configs += "\nIisBlacklistClient=" + this->list2string( this->craplog.getBlacklist( WS_IIS, 20 ) );
configs += "\nIisBlacklistClientUsed=" + this->b2s.at( this->craplog.isBlacklistUsed( WS_IIS, 20 ) );
//// CRAPVIEW ////
configs += "\n\n[Crapview]";
configs += "\nCrapviewDialogsLevel=" + std::to_string( this->crapview.getDialogsLevel() );
@ -1813,21 +1813,21 @@ void MainWindow::makeInitialChecks()
this->on_button_LogFiles_RefreshList_clicked();
// set the default WS as the current one
switch ( this->craplog.getCurrentWSID() ) {
case APACHE_ID:
case WS_APACHE:
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 );
break;
case NGINX_ID:
case WS_NGINX:
this->ui->box_StatsWarn_WebServer->setCurrentIndex( 1 );
this->ui->box_StatsCount_WebServer->setCurrentIndex( 1 );
this->ui->box_StatsSpeed_WebServer->setCurrentIndex( 1 );
this->ui->box_StatsDay_WebServer->setCurrentIndex( 1 );
this->ui->box_StatsRelat_WebServer->setCurrentIndex( 1 );
break;
case IIS_ID:
case WS_IIS:
this->ui->box_StatsWarn_WebServer->setCurrentIndex( 2 );
this->ui->box_StatsCount_WebServer->setCurrentIndex( 2 );
this->ui->box_StatsSpeed_WebServer->setCurrentIndex( 2 );
@ -1836,7 +1836,7 @@ void MainWindow::makeInitialChecks()
break;
default:
// shouldn't be here
throw WebServerException( "Unexpected WebServer ID: "+std::to_string( this->default_ws ) );
throw WebServerException( "Unexpected WebServer: " + toString(this->default_web_server) );
}
this->initiating &= false;
// effectively check if draw buttons can be enabled
@ -2399,13 +2399,13 @@ void MainWindow::checkMakeStats_Makable()
// switch to apache web server
void MainWindow::on_button_LogFiles_Apache_clicked()
{
if ( this->craplog.getCurrentWSID() != APACHE_ID ) {
if ( this->craplog.getCurrentWSID() != WS_APACHE ) {
// flat/unflat
this->ui->button_LogFiles_Apache->setFlat( false );
this->ui->button_LogFiles_Nginx->setFlat( true );
this->ui->button_LogFiles_Iis->setFlat( true );
// set the WebServer
this->craplog.setCurrentWSID( APACHE_ID );
this->craplog.setCurrentWebServer( WS_APACHE );
// reset the log files viewer
{
QString rich_text;
@ -2420,13 +2420,13 @@ void MainWindow::on_button_LogFiles_Apache_clicked()
// switch to nginx web server
void MainWindow::on_button_LogFiles_Nginx_clicked()
{
if ( this->craplog.getCurrentWSID() != NGINX_ID ) {
if ( this->craplog.getCurrentWSID() != WS_NGINX ) {
// flat/unflat
this->ui->button_LogFiles_Nginx->setFlat( false );
this->ui->button_LogFiles_Apache->setFlat( true );
this->ui->button_LogFiles_Iis->setFlat( true );
// set the WebServer
this->craplog.setCurrentWSID( NGINX_ID );
this->craplog.setCurrentWebServer( WS_NGINX );
// reset the log files viewer
{
QString rich_text;
@ -2441,13 +2441,13 @@ void MainWindow::on_button_LogFiles_Nginx_clicked()
// switch to iis web server
void MainWindow::on_button_LogFiles_Iis_clicked()
{
if ( this->craplog.getCurrentWSID() != IIS_ID ) {
if ( this->craplog.getCurrentWSID() != WS_IIS ) {
// flat/unflat
this->ui->button_LogFiles_Iis->setFlat( false );
this->ui->button_LogFiles_Apache->setFlat( true );
this->ui->button_LogFiles_Nginx->setFlat( true );
// set the WebServer
this->craplog.setCurrentWSID( IIS_ID );
this->craplog.setCurrentWebServer( WS_IIS );
// reset the log files viewer
{
QString rich_text;
@ -4563,17 +4563,17 @@ void MainWindow::on_spinBox_ConfDatabases_NumBackups_valueChanged(int arg1)
void MainWindow::on_radio_ConfDefaults_Apache_toggled(bool checked)
{
Q_UNUSED(checked)
this->default_ws = APACHE_ID;
this->default_web_server = WS_APACHE;
}
void MainWindow::on_radio_ConfDefaults_Nginx_toggled(bool checked)
{
Q_UNUSED(checked)
this->default_ws = NGINX_ID;
this->default_web_server = WS_NGINX;
}
void MainWindow::on_radio_ConfDefaults_Iis_toggled(bool checked)
{
Q_UNUSED(checked)
this->default_ws = IIS_ID;
this->default_web_server = WS_IIS;
}
/////////////////
@ -4636,7 +4636,7 @@ void MainWindow::on_button_ConfApache_Path_Save_clicked()
if ( ! IOutils::checkDir( path, true ) ) {
DialogSec::warnDirNotReadable( nullptr );
}
this->craplog.setLogsPath( APACHE_ID, path );
this->craplog.setLogsPath( WS_APACHE, path );
this->ui->inLine_ConfApache_Path_String->setText( QString::fromStdString( path ) );
}
this->ui->button_ConfApache_Path_Save->setEnabled( false );
@ -4664,7 +4664,7 @@ void MainWindow::on_button_ConfApache_Format_Save_clicked()
this->ui->inLine_ConfApache_Format_String->text().trimmed().toStdString() ) };
if ( success ) {
this->ui->button_ConfApache_Format_Save->setEnabled( false );
if ( this->craplog.getCurrentWSID() == APACHE_ID ) {
if ( this->craplog.getCurrentWSID() == WS_APACHE ) {
this->craplog.setCurrentLogFormat();
}
}
@ -4672,7 +4672,7 @@ void MainWindow::on_button_ConfApache_Format_Save_clicked()
void MainWindow::on_button_ConfApache_Format_Sample_clicked()
{
this->ui->preview_ConfApache_Format_Sample->setText(
this->craplog.getLogsFormatSample( APACHE_ID ) );
this->craplog.getLogsFormatSample( WS_APACHE ) );
}
void MainWindow::on_button_ConfApache_Format_Help_clicked()
{
@ -4687,13 +4687,13 @@ void MainWindow::on_box_ConfApache_Warnlist_Field_currentTextChanged(const QStri
this->ui->list_ConfApache_Warnlist_List->clear();
// update the list
const std::vector<std::string>& list{ this->craplog.getWarnlist(
APACHE_ID, this->crapview.getLogFieldID( arg1 ) ) };
WS_APACHE, this->crapview.getLogFieldID( arg1 ) ) };
for ( const std::string& item : list ) {
this->ui->list_ConfApache_Warnlist_List->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
const bool used{ this->craplog.isWarnlistUsed(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Field->currentText() ) ) };
this->ui->checkBox_ConfApache_Warnlist_Used->setChecked( used );
this->on_checkBox_ConfApache_Warnlist_Used_clicked( used );
@ -4702,7 +4702,7 @@ void MainWindow::on_box_ConfApache_Warnlist_Field_currentTextChanged(const QStri
void MainWindow::on_checkBox_ConfApache_Warnlist_Used_clicked(bool checked)
{
this->craplog.setWarnlistUsed(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Field->currentText() ),
checked );
if ( checked ) {
@ -4744,7 +4744,7 @@ void MainWindow::on_button_ConfApache_Warnlist_Add_clicked()
// not in the list yet, append
try {
this->craplog.warnlistAdd(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Field->currentText() ),
item.toStdString() );
this->ui->list_ConfApache_Warnlist_List->addItem( item );
@ -4792,7 +4792,7 @@ void MainWindow::on_button_ConfApache_Warnlist_Remove_clicked()
{
const auto item{ this->ui->list_ConfApache_Warnlist_List->selectedItems().at(0) };
this->craplog.warnlistRemove(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Field->currentText() ),
item->text().toStdString() );
// refresh the list
@ -4802,7 +4802,7 @@ void MainWindow::on_button_ConfApache_Warnlist_Up_clicked()
{
const auto item{ this->ui->list_ConfApache_Warnlist_List->selectedItems().at(0) };
const int i{ this->craplog.warnlistMoveUp(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -4815,7 +4815,7 @@ void MainWindow::on_button_ConfApache_Warnlist_Down_clicked()
{
const auto item{ this->ui->list_ConfApache_Warnlist_List->selectedItems().at(0) };
const int i{ this->craplog.warnlistMoveDown(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Warnlist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -4834,13 +4834,13 @@ void MainWindow::on_box_ConfApache_Blacklist_Field_currentTextChanged(const QStr
this->ui->list_ConfApache_Blacklist_List->clear();
// update the list
const std::vector<std::string>& list{ this->craplog.getBlacklist(
APACHE_ID, this->crapview.getLogFieldID( arg1 ) ) };
WS_APACHE, this->crapview.getLogFieldID( arg1 ) ) };
for ( const std::string& item : list ) {
this->ui->list_ConfApache_Blacklist_List->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
const bool used{ this->craplog.isBlacklistUsed(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Field->currentText() ) ) };
this->ui->checkBox_ConfApache_Blacklist_Used->setChecked( used );
this->on_checkBox_ConfApache_Blacklist_Used_clicked( used );
@ -4849,7 +4849,7 @@ void MainWindow::on_box_ConfApache_Blacklist_Field_currentTextChanged(const QStr
void MainWindow::on_checkBox_ConfApache_Blacklist_Used_clicked(bool checked)
{
this->craplog.setBlacklistUsed(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Field->currentText() ),
checked );
if ( checked ) {
@ -4891,7 +4891,7 @@ void MainWindow::on_button_ConfApache_Blacklist_Add_clicked()
// not in the list yet, append
try {
this->craplog.blacklistAdd(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Field->currentText() ),
item.toStdString() );
this->ui->list_ConfApache_Blacklist_List->addItem( item );
@ -4939,7 +4939,7 @@ void MainWindow::on_button_ConfApache_Blacklist_Remove_clicked()
{
const auto item{ this->ui->list_ConfApache_Blacklist_List->selectedItems().at(0) };
this->craplog.blacklistRemove(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Field->currentText() ),
item->text().toStdString() );
// refresh the list
@ -4949,7 +4949,7 @@ void MainWindow::on_button_ConfApache_Blacklist_Up_clicked()
{
const auto item{ this->ui->list_ConfApache_Blacklist_List->selectedItems().at(0) };
const int i{ this->craplog.blacklistMoveUp(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -4962,7 +4962,7 @@ void MainWindow::on_button_ConfApache_Blacklist_Down_clicked()
{
const auto item{ this->ui->list_ConfApache_Blacklist_List->selectedItems().at(0) };
const int i{ this->craplog.blacklistMoveDown(
APACHE_ID,
WS_APACHE,
this->crapview.getLogFieldID( this->ui->box_ConfApache_Blacklist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5007,7 +5007,7 @@ void MainWindow::on_button_ConfNginx_Path_Save_clicked()
if ( ! IOutils::checkDir( path, true ) ) {
DialogSec::warnDirNotReadable( nullptr );
}
this->craplog.setLogsPath( NGINX_ID, path );
this->craplog.setLogsPath( WS_NGINX, path );
this->ui->inLine_ConfNginx_Path_String->setText( QString::fromStdString( path ) );
}
this->ui->button_ConfNginx_Path_Save->setEnabled( false );
@ -5035,7 +5035,7 @@ void MainWindow::on_button_ConfNginx_Format_Save_clicked()
this->ui->inLine_ConfNginx_Format_String->text().trimmed().toStdString() ) };
if ( success ) {
this->ui->button_ConfNginx_Format_Save->setEnabled( false );
if ( this->craplog.getCurrentWSID() == NGINX_ID ) {
if ( this->craplog.getCurrentWSID() == WS_NGINX ) {
this->craplog.setCurrentLogFormat();
}
}
@ -5043,7 +5043,7 @@ void MainWindow::on_button_ConfNginx_Format_Save_clicked()
void MainWindow::on_button_ConfNginx_Format_Sample_clicked()
{
this->ui->preview_ConfNginx_Format_Sample->setText(
this->craplog.getLogsFormatSample( NGINX_ID ) );
this->craplog.getLogsFormatSample( WS_NGINX ) );
}
void MainWindow::on_button_ConfNginx_Format_Help_clicked()
{
@ -5058,13 +5058,13 @@ void MainWindow::on_box_ConfNginx_Warnlist_Field_currentTextChanged(const QStrin
this->ui->list_ConfNginx_Warnlist_List->clear();
// update the list
const std::vector<std::string>& list{ this->craplog.getWarnlist(
NGINX_ID, this->crapview.getLogFieldID( arg1 ) ) };
WS_NGINX, this->crapview.getLogFieldID( arg1 ) ) };
for ( const std::string& item : list ) {
this->ui->list_ConfNginx_Warnlist_List->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
const bool used{ this->craplog.isWarnlistUsed(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Warnlist_Field->currentText() ) ) };
this->ui->checkBox_ConfNginx_Warnlist_Used->setChecked( used );
this->on_checkBox_ConfNginx_Warnlist_Used_clicked( used );
@ -5073,7 +5073,7 @@ void MainWindow::on_box_ConfNginx_Warnlist_Field_currentTextChanged(const QStrin
void MainWindow::on_checkBox_ConfNginx_Warnlist_Used_clicked(bool checked)
{
this->craplog.setWarnlistUsed(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Warnlist_Field->currentText() ),
checked );
if ( checked ) {
@ -5115,7 +5115,7 @@ void MainWindow::on_button_ConfNginx_Warnlist_Add_clicked()
// not in the list yet, append
try {
this->craplog.warnlistAdd(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Warnlist_Field->currentText() ),
item.toStdString() );
this->ui->list_ConfNginx_Warnlist_List->addItem( item );
@ -5163,7 +5163,7 @@ void MainWindow::on_button_ConfNginx_Warnlist_Remove_clicked()
{
const auto item{ this->ui->list_ConfNginx_Warnlist_List->selectedItems().at(0) };
this->craplog.warnlistRemove(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Warnlist_Field->currentText() ),
item->text().toStdString() );
// refresh the list
@ -5173,7 +5173,7 @@ void MainWindow::on_button_ConfNginx_Warnlist_Up_clicked()
{
const auto item{ this->ui->list_ConfNginx_Warnlist_List->selectedItems().at(0) };
const int i{ this->craplog.warnlistMoveUp(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Warnlist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5186,7 +5186,7 @@ void MainWindow::on_button_ConfNginx_Warnlist_Down_clicked()
{
const auto item{ this->ui->list_ConfNginx_Warnlist_List->selectedItems().at(0) };
const int i{ this->craplog.warnlistMoveDown(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Warnlist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5205,13 +5205,13 @@ void MainWindow::on_box_ConfNginx_Blacklist_Field_currentTextChanged(const QStri
this->ui->list_ConfNginx_Blacklist_List->clear();
// update the list
const std::vector<std::string>& list{ this->craplog.getBlacklist(
NGINX_ID, this->crapview.getLogFieldID( arg1 ) ) };
WS_NGINX, this->crapview.getLogFieldID( arg1 ) ) };
for ( const std::string& item : list ) {
this->ui->list_ConfNginx_Blacklist_List->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
const bool used{ this->craplog.isBlacklistUsed(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Blacklist_Field->currentText() ) ) };
this->ui->checkBox_ConfNginx_Blacklist_Used->setChecked( used );
this->on_checkBox_ConfNginx_Blacklist_Used_clicked( used );
@ -5220,7 +5220,7 @@ void MainWindow::on_box_ConfNginx_Blacklist_Field_currentTextChanged(const QStri
void MainWindow::on_checkBox_ConfNginx_Blacklist_Used_clicked(bool checked)
{
this->craplog.setBlacklistUsed(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Blacklist_Field->currentText() ),
checked );
if ( checked ) {
@ -5262,7 +5262,7 @@ void MainWindow::on_button_ConfNginx_Blacklist_Add_clicked()
// not in the list yet, append
try {
this->craplog.blacklistAdd(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Blacklist_Field->currentText() ),
item.toStdString() );
this->ui->list_ConfNginx_Blacklist_List->addItem( item );
@ -5310,7 +5310,7 @@ void MainWindow::on_button_ConfNginx_Blacklist_Remove_clicked()
{
const auto item{ this->ui->list_ConfNginx_Blacklist_List->selectedItems().at(0) };
this->craplog.blacklistRemove(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Blacklist_Field->currentText() ),
item->text().toStdString() );
// refresh the list
@ -5320,7 +5320,7 @@ void MainWindow::on_button_ConfNginx_Blacklist_Up_clicked()
{
const auto item{ this->ui->list_ConfNginx_Blacklist_List->selectedItems().at(0) };
const int i{ this->craplog.blacklistMoveUp(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Blacklist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5333,7 +5333,7 @@ void MainWindow::on_button_ConfNginx_Blacklist_Down_clicked()
{
const auto item{ this->ui->list_ConfNginx_Blacklist_List->selectedItems().at(0) };
const int i{ this->craplog.blacklistMoveDown(
NGINX_ID,
WS_NGINX,
this->crapview.getLogFieldID( this->ui->box_ConfNginx_Blacklist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5378,7 +5378,7 @@ void MainWindow::on_button_ConfIis_Path_Save_clicked()
if ( ! IOutils::checkDir( path, true ) ) {
DialogSec::warnDirNotReadable( nullptr );
}
this->craplog.setLogsPath( IIS_ID, path );
this->craplog.setLogsPath( WS_IIS, path );
this->ui->inLine_ConfIis_Path_String->setText( QString::fromStdString( path ) );
}
this->ui->button_ConfIis_Path_Save->setEnabled( false );
@ -5403,7 +5403,7 @@ void MainWindow::on_radio_ConfIis_Format_W3C_toggled(bool checked)
this->ui->inLine_ConfIis_Format_String->clear();
this->ui->inLine_ConfIis_Format_String->setEnabled( true );
this->ui->inLine_ConfIis_Format_String->setFocus();
if ( this->craplog.getCurrentWSID() == IIS_ID ) {
if ( this->craplog.getCurrentWSID() == WS_IIS ) {
this->craplog.setCurrentLogFormat();
this->on_button_LogFiles_RefreshList_clicked();
}
@ -5418,10 +5418,10 @@ void MainWindow::on_radio_ConfIis_Format_NCSA_toggled(bool checked)
1 ) };
if ( success ) {
this->ui->inLine_ConfIis_Format_String->clear();
this->ui->inLine_ConfIis_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( IIS_ID ) ) );
this->ui->inLine_ConfIis_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( WS_IIS ) ) );
this->ui->inLine_ConfIis_Format_String->setEnabled( false );
this->ui->button_ConfIis_Format_Save->setEnabled( false );
if ( this->craplog.getCurrentWSID() == IIS_ID ) {
if ( this->craplog.getCurrentWSID() == WS_IIS ) {
this->craplog.setCurrentLogFormat();
this->on_button_LogFiles_RefreshList_clicked();
}
@ -5436,10 +5436,10 @@ void MainWindow::on_radio_ConfIis_Format_IIS_toggled(bool checked)
2 ) };
if ( success ) {
this->ui->inLine_ConfIis_Format_String->clear();
this->ui->inLine_ConfIis_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( IIS_ID ) ) );
this->ui->inLine_ConfIis_Format_String->setText( QString::fromStdString( this->craplog.getLogsFormatString( WS_IIS ) ) );
this->ui->inLine_ConfIis_Format_String->setEnabled( false );
this->ui->button_ConfIis_Format_Save->setEnabled( false );
if ( this->craplog.getCurrentWSID() == IIS_ID ) {
if ( this->craplog.getCurrentWSID() == WS_IIS ) {
this->craplog.setCurrentLogFormat();
this->on_button_LogFiles_RefreshList_clicked();
}
@ -5469,7 +5469,7 @@ void MainWindow::on_button_ConfIis_Format_Save_clicked()
this->getIisLogsModule() ) };
if ( success ) {
this->ui->button_ConfIis_Format_Save->setEnabled( false );
if ( this->craplog.getCurrentWSID() == IIS_ID ) {
if ( this->craplog.getCurrentWSID() == WS_IIS ) {
this->craplog.setCurrentLogFormat();
}
}
@ -5477,7 +5477,7 @@ void MainWindow::on_button_ConfIis_Format_Save_clicked()
void MainWindow::on_button_ConfIis_Format_Sample_clicked()
{
this->ui->preview_ConfIis_Format_Sample->setText(
this->craplog.getLogsFormatSample( IIS_ID ) );
this->craplog.getLogsFormatSample( WS_IIS ) );
}
void MainWindow::on_button_ConfIis_Format_Help_clicked()
{
@ -5492,13 +5492,13 @@ void MainWindow::on_box_ConfIis_Warnlist_Field_currentTextChanged(const QString&
this->ui->list_ConfIis_Warnlist_List->clear();
// update the list
const std::vector<std::string>& list{ this->craplog.getWarnlist(
IIS_ID, this->crapview.getLogFieldID( arg1 ) ) };
WS_IIS, this->crapview.getLogFieldID( arg1 ) ) };
for ( const std::string& item : list ) {
this->ui->list_ConfIis_Warnlist_List->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
const bool used{ this->craplog.isWarnlistUsed(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Warnlist_Field->currentText() ) ) };
this->ui->checkBox_ConfIis_Warnlist_Used->setChecked( used );
this->on_checkBox_ConfIis_Warnlist_Used_clicked( used );
@ -5507,7 +5507,7 @@ void MainWindow::on_box_ConfIis_Warnlist_Field_currentTextChanged(const QString&
void MainWindow::on_checkBox_ConfIis_Warnlist_Used_clicked(bool checked)
{
this->craplog.setWarnlistUsed(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Warnlist_Field->currentText() ),
checked );
if ( checked ) {
@ -5549,7 +5549,7 @@ void MainWindow::on_button_ConfIis_Warnlist_Add_clicked()
// not in the list yet, append
try {
this->craplog.warnlistAdd(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Warnlist_Field->currentText() ),
item.toStdString() );
this->ui->list_ConfIis_Warnlist_List->addItem( item );
@ -5597,7 +5597,7 @@ void MainWindow::on_button_ConfIis_Warnlist_Remove_clicked()
{
const auto item{ this->ui->list_ConfIis_Warnlist_List->selectedItems().at(0) };
this->craplog.warnlistRemove(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Warnlist_Field->currentText() ),
item->text().toStdString() );
// refresh the list
@ -5607,7 +5607,7 @@ void MainWindow::on_button_ConfIis_Warnlist_Up_clicked()
{
const auto item{ this->ui->list_ConfIis_Warnlist_List->selectedItems().at(0) };
const int i{ this->craplog.warnlistMoveUp(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Warnlist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5620,7 +5620,7 @@ void MainWindow::on_button_ConfIis_Warnlist_Down_clicked()
{
const auto item{ this->ui->list_ConfIis_Warnlist_List->selectedItems().at(0) };
const int i{ this->craplog.warnlistMoveDown(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Warnlist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5639,13 +5639,13 @@ void MainWindow::on_box_ConfIis_Blacklist_Field_currentTextChanged(const QString
this->ui->list_ConfIis_Blacklist_List->clear();
// update the list
const std::vector<std::string>& list{ this->craplog.getBlacklist(
IIS_ID, this->crapview.getLogFieldID( arg1 ) ) };
WS_IIS, this->crapview.getLogFieldID( arg1 ) ) };
for ( const std::string& item : list ) {
this->ui->list_ConfIis_Blacklist_List->addItem( QString::fromStdString( item ) );
}
// check/uncheck the usage option
const bool used{ this->craplog.isBlacklistUsed(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Blacklist_Field->currentText() ) ) };
this->ui->checkBox_ConfIis_Blacklist_Used->setChecked( used );
this->on_checkBox_ConfIis_Blacklist_Used_clicked( used );
@ -5654,7 +5654,7 @@ void MainWindow::on_box_ConfIis_Blacklist_Field_currentTextChanged(const QString
void MainWindow::on_checkBox_ConfIis_Blacklist_Used_clicked(bool checked)
{
this->craplog.setBlacklistUsed(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Blacklist_Field->currentText() ),
checked );
if ( checked ) {
@ -5696,7 +5696,7 @@ void MainWindow::on_button_ConfIis_Blacklist_Add_clicked()
// not in the list yet, append
try {
this->craplog.blacklistAdd(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Blacklist_Field->currentText() ),
item.toStdString() );
this->ui->list_ConfIis_Blacklist_List->addItem( item );
@ -5744,7 +5744,7 @@ void MainWindow::on_button_ConfIis_Blacklist_Remove_clicked()
{
const auto item{ this->ui->list_ConfIis_Blacklist_List->selectedItems().at(0) };
this->craplog.blacklistRemove(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Blacklist_Field->currentText() ),
item->text().toStdString() );
// refresh the list
@ -5754,7 +5754,7 @@ void MainWindow::on_button_ConfIis_Blacklist_Up_clicked()
{
const auto item{ this->ui->list_ConfIis_Blacklist_List->selectedItems().at(0) };
const int i{ this->craplog.blacklistMoveUp(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Blacklist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list
@ -5767,7 +5767,7 @@ void MainWindow::on_button_ConfIis_Blacklist_Down_clicked()
{
const auto item{ this->ui->list_ConfIis_Blacklist_List->selectedItems().at(0) };
const int i{ this->craplog.blacklistMoveDown(
IIS_ID,
WS_IIS,
this->crapview.getLogFieldID( this->ui->box_ConfIis_Blacklist_Field->currentText() ),
item->text().toStdString() ) };
// refresh the list

View File

@ -636,7 +636,7 @@ private:
int dialogs_level{ 2 }; // 0: essential, 1: usefull, 2: explanatory
// default web server
unsigned default_ws{ 11 };
WebServer default_web_server{ WS_APACHE };
//////////////////

View File

@ -33,52 +33,52 @@ Craplog::Craplog()
//// INITIALIZATION ////
////////////////////////
// blacklists / whitelists
for ( unsigned i{APACHE_ID}; i<=IIS_ID; ++i ) {
this->warnlists.emplace( i, std::unordered_map<int, BWlist>(4) );
this->blacklists.emplace( i, std::unordered_map<int, BWlist>(1) );
for ( const WebServer& w : {WS_APACHE,WS_NGINX,WS_IIS} ) {
this->warnlists.emplace( w, std::unordered_map<int, BWlist>(4) );
this->blacklists.emplace( w, std::unordered_map<int, BWlist>(1) );
// default data
this->warnlists.at( i ).emplace( 11, BWlist{ .used=false, .list={} } );
this->warnlists.at( i ).emplace( 12, BWlist{ .used=false, .list={} } );
this->warnlists.at( i ).emplace( 20, BWlist{ .used=false, .list={} } );
this->warnlists.at( i ).emplace( 21, BWlist{ .used=false, .list={} } );
this->blacklists.at( i ).emplace( 20, BWlist{ .used=false, .list={} } );
this->warnlists.at( w ).emplace( 11, BWlist{ .used=false, .list={} } );
this->warnlists.at( w ).emplace( 12, BWlist{ .used=false, .list={} } );
this->warnlists.at( w ).emplace( 20, BWlist{ .used=false, .list={} } );
this->warnlists.at( w ).emplace( 21, BWlist{ .used=false, .list={} } );
this->blacklists.at( w ).emplace( 20, BWlist{ .used=false, .list={} } );
}
// default format strings
this->logs_format_strings.emplace(
APACHE_ID, "" );
WS_APACHE, "" );
this->logs_format_strings.emplace(
NGINX_ID, "" );
WS_NGINX, "" );
this->logs_format_strings.emplace(
IIS_ID, "" );
WS_IIS, "" );
// initialize formats
this->logs_formats.emplace(
APACHE_ID, LogsFormat() );
WS_APACHE, LogsFormat() );
this->logs_formats.emplace(
NGINX_ID, LogsFormat() );
WS_NGINX, LogsFormat() );
this->logs_formats.emplace(
IIS_ID, LogsFormat() );
WS_IIS, LogsFormat() );
this->current_LF = this->logs_formats.at( APACHE_ID );
this->current_log_format = this->logs_formats.at( WS_APACHE );
// apache2 access/error logs location
this->logs_paths.emplace( APACHE_ID, "/var/log/apache2" );
this->logs_paths.emplace( WS_APACHE, "/var/log/apache2" );
// nginx access/error logs location
this->logs_paths.emplace( NGINX_ID, "/var/log/nginx" );
this->logs_paths.emplace( WS_NGINX, "/var/log/nginx" );
// iis access/error logs location
this->logs_paths.emplace( IIS_ID, "C:/inetpub/logs/LogFiles" );
this->logs_paths.emplace( WS_IIS, "C:/inetpub/logs/LogFiles" );
// apache2 access/error log files' names
this->logs_base_names.emplace( APACHE_ID, LogName{ .starts = "access.log.",
this->logs_base_names.emplace( WS_APACHE, LogName{ .starts = "access.log.",
.contains = "",
.ends = "" } );
// nginx access/error log files' names
this->logs_base_names.emplace( NGINX_ID, LogName{ .starts = "access.log.",
this->logs_base_names.emplace( WS_NGINX, LogName{ .starts = "access.log.",
.contains = "",
.ends = "" });
// iis access/error log files' names
this->logs_base_names.emplace( IIS_ID, LogName{ .starts = "",
this->logs_base_names.emplace( WS_IIS, LogName{ .starts = "",
.contains = "_ex",
.ends = ".log" });
}
@ -127,77 +127,77 @@ void Craplog::setWarningSize(const size_t new_size ) noexcept
////////////////////
//// WARN/BLACK ////
bool Craplog::isBlacklistUsed( const unsigned& web_server_id, const int& log_field_id ) const noexcept
bool Craplog::isBlacklistUsed( const WebServer& web_server, const int& log_field_id ) const noexcept
{
return this->blacklists.at( web_server_id ).at( log_field_id ).used;
return this->blacklists.at( web_server ).at( log_field_id ).used;
}
bool Craplog::isWarnlistUsed( const unsigned& web_server_id, const int& log_field_id ) const noexcept
bool Craplog::isWarnlistUsed( const WebServer& web_server, const int& log_field_id ) const noexcept
{
return this->warnlists.at( web_server_id ).at( log_field_id ).used;
return this->warnlists.at( web_server ).at( log_field_id ).used;
}
void Craplog::setBlacklistUsed( const unsigned& web_server_id, const int& log_field_id, const bool used ) noexcept
void Craplog::setBlacklistUsed( const WebServer& web_server, const int& log_field_id, const bool used ) noexcept
{
this->blacklists.at( web_server_id ).at( log_field_id ).used = used;
this->blacklists.at( web_server ).at( log_field_id ).used = used;
}
void Craplog::setWarnlistUsed( const unsigned& web_server_id, const int& log_field_id, const bool used ) noexcept
void Craplog::setWarnlistUsed( const WebServer& web_server, const int& log_field_id, const bool used ) noexcept
{
this->warnlists.at( web_server_id ).at( log_field_id ).used = used;
this->warnlists.at( web_server ).at( log_field_id ).used = used;
}
const std::vector<std::string>& Craplog::getBlacklist( const unsigned& web_server_id, const int& log_field_id ) const noexcept
const std::vector<std::string>& Craplog::getBlacklist( const WebServer& web_server, const int& log_field_id ) const noexcept
{
return this->blacklists.at( web_server_id ).at( log_field_id ).list;
return this->blacklists.at( web_server ).at( log_field_id ).list;
}
const std::vector<std::string>& Craplog::getWarnlist( const unsigned& web_server_id, const int& log_field_id ) const noexcept
const std::vector<std::string>& Craplog::getWarnlist( const WebServer& web_server, const int& log_field_id ) const noexcept
{
return this->warnlists.at( web_server_id ).at( log_field_id ).list;
return this->warnlists.at( web_server ).at( log_field_id ).list;
}
void Craplog::setBlacklist( const unsigned& web_server_id, const int& log_field_id, const std::vector<std::string>& new_list )
void Craplog::setBlacklist( const WebServer& web_server, const int& log_field_id, const std::vector<std::string>& new_list )
{
this->blacklists.at( web_server_id ).at( log_field_id ).list.clear();
this->blacklists.at( web_server ).at( log_field_id ).list.clear();
for ( const std::string& item : new_list ) {
this->blacklistAdd( web_server_id, log_field_id, item );
this->blacklistAdd( web_server, log_field_id, item );
}
}
void Craplog::setWarnlist( const unsigned& web_server_id, const int& log_field_id, const std::vector<std::string>& new_list )
void Craplog::setWarnlist( const WebServer& web_server, const int& log_field_id, const std::vector<std::string>& new_list )
{
this->warnlists.at( web_server_id ).at( log_field_id ).list.clear();
this->warnlists.at( web_server ).at( log_field_id ).list.clear();
for ( const std::string& item : new_list ) {
this->warnlistAdd( web_server_id, log_field_id, item );
this->warnlistAdd( web_server, log_field_id, item );
}
}
void Craplog::blacklistAdd( const unsigned& web_server_id, const int& log_field_id, const std::string& new_item )
void Craplog::blacklistAdd( const WebServer& web_server, const int& log_field_id, const std::string& new_item )
{
this->blacklists.at( web_server_id ).at( log_field_id ).list.push_back(
this->blacklists.at( web_server ).at( log_field_id ).list.push_back(
this->sanitizeBWitem( log_field_id, new_item ) );
}
void Craplog::warnlistAdd( const unsigned& web_server_id, const int& log_field_id, const std::string& new_item )
void Craplog::warnlistAdd( const WebServer& web_server, const int& log_field_id, const std::string& new_item )
{
this->warnlists.at( web_server_id ).at( log_field_id ).list.push_back(
this->warnlists.at( web_server ).at( log_field_id ).list.push_back(
this->sanitizeBWitem( log_field_id, new_item ) );
}
void Craplog::blacklistRemove( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept
void Craplog::blacklistRemove( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept
{
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
auto& list = this->blacklists.at( web_server ).at( log_field_id ).list;
if ( const auto it{ std::find( list.cbegin(), list.cend(), item ) }; it != list.cend() ) {
list.erase( it );
}
}
void Craplog::warnlistRemove( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept
void Craplog::warnlistRemove( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept
{
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
auto& list = this->warnlists.at( web_server ).at( log_field_id ).list;
if ( const auto it{ std::find( list.cbegin(), list.cend(), item ) }; it != list.cend() ) {
list.erase( it );
}
}
int Craplog::blacklistMoveUp( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept
int Craplog::blacklistMoveUp( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept
{
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
auto& list = this->blacklists.at( web_server ).at( log_field_id ).list;
if ( auto it{ std::find( std::next(list.begin()), list.end(), item ) }; it != list.cend() ) {
const int pos{ static_cast<int>( std::distance(list.begin(), it) ) - 1 };
std::swap( *it, *std::prev(it) );
@ -205,9 +205,9 @@ int Craplog::blacklistMoveUp( const unsigned& web_server_id, const int& log_fiel
}
return -1;
}
int Craplog::warnlistMoveUp( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept
int Craplog::warnlistMoveUp( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept
{
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
auto& list = this->warnlists.at( web_server ).at( log_field_id ).list;
if ( auto it{ std::find( std::next(list.begin()), list.end(), item ) }; it != list.cend() ) {
const int pos{ static_cast<int>( std::distance(list.begin(), it) ) - 1 };
std::swap( *it, *std::prev(it) );
@ -216,9 +216,9 @@ int Craplog::warnlistMoveUp( const unsigned& web_server_id, const int& log_field
return -1;
}
int Craplog::blacklistMoveDown( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept
int Craplog::blacklistMoveDown( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept
{
auto& list = this->blacklists.at( web_server_id ).at( log_field_id ).list;
auto& list = this->blacklists.at( web_server ).at( log_field_id ).list;
if ( auto it{ std::find( list.begin(), std::prev(list.end()), item ) }; it != list.cend() ) {
const int pos{ static_cast<int>( std::distance(list.begin(), it) ) + 1 };
std::swap( *it, *std::next(it) );
@ -226,9 +226,9 @@ int Craplog::blacklistMoveDown( const unsigned& web_server_id, const int& log_fi
}
return -1;
}
int Craplog::warnlistMoveDown( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept
int Craplog::warnlistMoveDown( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept
{
auto& list = this->warnlists.at( web_server_id ).at( log_field_id ).list;
auto& list = this->warnlists.at( web_server ).at( log_field_id ).list;
if ( auto it{ std::find( list.begin(), std::prev(list.end()), item ) }; it != list.cend() ) {
const int pos{ static_cast<int>( std::distance(list.begin(), it) ) + 1 };
std::swap( *it, *std::next(it) );
@ -280,15 +280,15 @@ std::string Craplog::sanitizeBWitem( const int& log_field_id, const std::string&
/////////////////
//// FORMATS ////
// get the logs format string
const std::string& Craplog::getLogsFormatString( const unsigned& web_server_id ) const noexcept
const std::string& Craplog::getLogsFormatString( const WebServer& web_server ) const noexcept
{
return this->logs_format_strings.at( web_server_id );
return this->logs_format_strings.at( web_server );
}
// get the logs format
const LogsFormat& Craplog::getLogsFormat(const unsigned& web_server_id ) const noexcept
const LogsFormat& Craplog::getLogsFormat(const WebServer& web_server ) const noexcept
{
return this->logs_formats.at( web_server_id );
return this->logs_formats.at( web_server );
}
// set the logs format
@ -297,9 +297,9 @@ bool Craplog::setApacheLogFormat( const std::string& format_string ) noexcept
// apache
bool success{ true };
try {
this->logs_formats.at( APACHE_ID ) =
this->logs_formats.at( WS_APACHE ) =
this->formatOps.processApacheFormatString( format_string );
this->logs_format_strings.at( APACHE_ID ) = format_string;
this->logs_format_strings.at( WS_APACHE ) = format_string;
} catch ( LogFormatException& e ) {
success &= false;
DialogSec::errInvalidLogFormatString( e.what() );
@ -314,9 +314,9 @@ bool Craplog::setNginxLogFormat( const std::string& format_string ) noexcept
// nginx
bool success{ true };
try {
this->logs_formats.at( NGINX_ID ) =
this->logs_formats.at( WS_NGINX ) =
this->formatOps.processNginxFormatString( format_string );
this->logs_format_strings.at( NGINX_ID ) = format_string;
this->logs_format_strings.at( WS_NGINX ) = format_string;
} catch ( LogFormatException& e ) {
success &= false;
DialogSec::errInvalidLogFormatString( e.what() );
@ -331,9 +331,9 @@ bool Craplog::setIisLogFormat( const std::string& format_string, const int log_m
// iis
bool success{ true };
try {
this->logs_formats.at( IIS_ID ) =
this->logs_formats.at( WS_IIS ) =
this->formatOps.processIisFormatString( format_string, log_module );
this->logs_format_strings.at( IIS_ID ) = format_string;
this->logs_format_strings.at( WS_IIS ) = format_string;
this->changeIisLogsBaseNames( log_module );
} catch ( LogFormatException& e ) {
success &= false;
@ -345,32 +345,31 @@ bool Craplog::setIisLogFormat( const std::string& format_string, const int log_m
return success;
}
QString Craplog::getLogsFormatSample( const unsigned& web_server_id ) const
QString Craplog::getLogsFormatSample( const WebServer& web_server ) const
{
switch ( web_server_id ) {
case APACHE_ID:
return this->formatOps.getApacheLogSample( this->logs_formats.at( web_server_id ) );
case NGINX_ID:
return this->formatOps.getNginxLogSample( this->logs_formats.at( web_server_id ) );
case IIS_ID:
return this->formatOps.getIisLogSample( this->logs_formats.at( web_server_id ) );
switch ( web_server ) {
case WS_APACHE:
return this->formatOps.getApacheLogSample( this->logs_formats.at( web_server ) );
case WS_NGINX:
return this->formatOps.getNginxLogSample( this->logs_formats.at( web_server ) );
case WS_IIS:
return this->formatOps.getIisLogSample( this->logs_formats.at( web_server ) );
default:
// unexpected WebServer
throw WebServerException( "Unexpected WebServerID: " + std::to_string( web_server_id ) );
throw WebServerException( "Unexpected WebServer: " + toString(web_server) );
}
}
bool Craplog::checkCurrentLogsFormat() const noexcept
{
if ( this->current_LF.string.empty() ) {
if ( this->current_log_format.string.empty() ) {
// format string not set
DialogSec::errLogFormatNotSet( nullptr );
return false;
} else if ( this->current_LF.fields.empty() ) {
} else if ( this->current_log_format.fields.empty() ) {
// no field, useless to parse
DialogSec::errLogFormatNoFields( nullptr );
return false;
} else if ( this->current_LF.separators.size() < this->current_LF.fields.size()-1 ) {
} else if ( this->current_log_format.separators.size() < this->current_log_format.fields.size()-1 ) {
// at least one separator is missing between two (or more) fields
DialogSec::errLogFormatNoSeparators( nullptr );
return false;
@ -380,37 +379,37 @@ bool Craplog::checkCurrentLogsFormat() const noexcept
// set the current Web Server
void Craplog::setCurrentWSID( const unsigned web_server_id ) noexcept
void Craplog::setCurrentWebServer( const WebServer web_server ) noexcept
{
this->current_WS = web_server_id;
this->current_web_server = web_server;
this->setCurrentLogFormat();
}
unsigned Craplog::getCurrentWSID() const noexcept
WebServer Craplog::getCurrentWSID() const noexcept
{
return this->current_WS;
return this->current_web_server;
}
// set the current access logs format
void Craplog::setCurrentLogFormat() noexcept
{
this->current_LF = this->logs_formats.at( this->current_WS );
this->current_log_format = this->logs_formats.at( this->current_web_server );
}
// get the current access logs format
const LogsFormat& Craplog::getCurrentLogFormat() const noexcept
{
return this->current_LF;
return this->current_log_format;
}
///////////////////
//// LOGS PATH ////
const std::string& Craplog::getLogsPath( const unsigned& web_server ) const noexcept
const std::string& Craplog::getLogsPath( const WebServer& web_server ) const noexcept
{
return this->logs_paths.at( web_server );
}
void Craplog::setLogsPath( const unsigned& web_server, const std::string& new_path ) noexcept
void Craplog::setLogsPath( const WebServer& web_server, const std::string& new_path ) noexcept
{
this->logs_paths.at( web_server ) = new_path;
}
@ -472,10 +471,10 @@ void Craplog::scanLogsDir()
this->logs_list.clear();
// hire the worker
CraplogLister* worker{ new CraplogLister(
this->current_WS,
this->current_web_server,
this->dialogs_level,
this->logs_paths.at( this->current_WS ),
this->logs_formats.at( this->current_WS ),
this->logs_paths.at( this->current_web_server ),
this->logs_formats.at( this->current_web_server ),
this->hashOps,
[this]( const std::string& file_name)
{ return this->isFileNameValid( file_name ); }
@ -523,11 +522,11 @@ void Craplog::changeIisLogsBaseNames( const int module_id )
{
switch ( module_id ) {
case 0: // W3C
this->logs_base_names.at( IIS_ID ).contains = "_ex"; break;
this->logs_base_names.at( WS_IIS ).contains = "_ex"; break;
case 1: // NCSA
this->logs_base_names.at( IIS_ID ).contains = "_nc"; break;
this->logs_base_names.at( WS_IIS ).contains = "_nc"; break;
case 2: // IIS
this->logs_base_names.at( IIS_ID ).contains = "_in"; break;
this->logs_base_names.at( WS_IIS ).contains = "_in"; break;
default: // shouldn't be reachable
throw GenericException( "Unexpected LogFormatModule ID: "+std::to_string( module_id ), true ); // leave un-catched
@ -537,28 +536,30 @@ void Craplog::changeIisLogsBaseNames( const int module_id )
bool Craplog::isFileNameValid( const std::string& name ) const
{
bool valid{ true };
if ( ! this->logs_base_names.at( this->current_WS ).starts.empty() ) {
if ( ! StringOps::startsWith( name, this->logs_base_names.at( this->current_WS ).starts ) ) {
if ( ! this->logs_base_names.at( this->current_web_server ).starts.empty() ) {
if ( ! StringOps::startsWith( name, this->logs_base_names.at( this->current_web_server ).starts ) ) {
return false;
}
}
if ( ! this->logs_base_names.at( this->current_WS ).contains.empty() ) {
if ( ! StringOps::contains( name.substr( this->logs_base_names.at( this->current_WS ).starts.size() ),
this->logs_base_names.at( this->current_WS ).contains ) ) {
if ( ! this->logs_base_names.at( this->current_web_server ).contains.empty() ) {
if ( ! StringOps::contains( name.substr( this->logs_base_names.at( this->current_web_server ).starts.size() ),
this->logs_base_names.at( this->current_web_server ).contains ) ) {
return false;
}
}
if ( ! this->logs_base_names.at( this->current_WS ).ends.empty() ) {
if ( ! StringOps::endsWith( name, this->logs_base_names.at( this->current_WS ).ends )
if ( ! this->logs_base_names.at( this->current_web_server ).ends.empty() ) {
if ( ! StringOps::endsWith( name, this->logs_base_names.at( this->current_web_server ).ends )
&& ! StringOps::endsWith( name, ".gz" ) ) {
return false;
}
}
switch ( this->current_WS ) {
size_t start, stop;
case APACHE_ID | NGINX_ID:
switch ( this->current_web_server ) {
case WS_APACHE:
[[fallthrough]];
case WS_NGINX: {
// further checks for apache / nginx
size_t start, stop;
start = name.rfind(".log." );
if ( start == std::string::npos ) {
valid &= false;
@ -576,11 +577,12 @@ bool Craplog::isFileNameValid( const std::string& name ) const
break;
}
}
break;
}break;
case IIS_ID:
case WS_IIS: {
// further checks for iis
start = name.find( this->logs_base_names.at( IIS_ID ).contains ) + 3ul;
size_t start, stop;
start = name.find( this->logs_base_names.at( WS_IIS ).contains ) + 3ul;
if ( start == std::string::npos ) {
valid &= false;
break;
@ -615,7 +617,10 @@ bool Craplog::isFileNameValid( const std::string& name ) const
}
}
}
break;
}break;
default:
throw WebServerException( "Unexpected WebServer: " + toString(this->current_web_server) );
}
return valid;
}
@ -830,13 +835,13 @@ void Craplog::startWorking()
void Craplog::hireWorker() const
{
CraplogParser* worker{ new CraplogParser(
this->current_WS,
this->current_web_server,
this->dialogs_level,
this->db_stats_path,
this->db_hashes_path,
this->logs_formats.at( this->current_WS ),
this->blacklists.at( this->current_WS ),
this->warnlists.at( this->current_WS ),
this->logs_formats.at( this->current_web_server ),
this->blacklists.at( this->current_web_server ),
this->warnlists.at( this->current_web_server ),
this->log_files_to_use
) };
QThread* worker_thread{ new QThread() };
@ -879,7 +884,7 @@ void Craplog::stopWorking( const bool successful )
this->db_edited = successful;
if ( successful ) {
// insert the hashes of the used files
this->hashOps.insertUsedHashes( this->db_hashes_path, this->used_files_hashes, this->current_WS );
this->hashOps.insertUsedHashes( this->db_hashes_path, this->used_files_hashes, this->current_web_server );
}
emit this->finishedWorking();
}

View File

@ -61,15 +61,15 @@ public:
//! Sets the currently used Web Server ID
/*!
\param web_server_id The new currently used Web Server
\param web_server The new currently used Web Server
*/
void setCurrentWSID( const unsigned web_server_id ) noexcept;
void setCurrentWebServer( const WebServer web_server ) noexcept;
//! Returns the currently used Web Server ID
/*!
\return The Web Server ID
*/
unsigned getCurrentWSID() const noexcept;
WebServer getCurrentWSID() const noexcept;
//! Uses the current Web Server to set the relative logs format
/*!
@ -90,17 +90,17 @@ public:
//! Returns the logs' path for the given web Server
/*!
\param web_server The ID of the Web Server
\param web_server The Web Server
\return The path of the logs' folder
*/
const std::string& getLogsPath( const unsigned& web_server ) const noexcept;
const std::string& getLogsPath( const WebServer& web_server ) const noexcept;
//! Sets a new path for the given Web Server to search the logs in
/*!
\param web_server The ID of the Web Server
\param web_server The Web Server
\param new_path The new path
*/
void setLogsPath( const unsigned& web_server, const std::string& new_path ) noexcept;
void setLogsPath( const WebServer& web_server, const std::string& new_path ) noexcept;
///////////////////
@ -189,28 +189,28 @@ public:
//! Returns the logs format string for the given Web Server
/*!
\param web_server_id ID of the Web Server
\param web_server ID of the Web Server
\return The format string
\see FormatOps::LogsFormat
*/
const std::string& getLogsFormatString( const unsigned& web_server_id ) const noexcept;
const std::string& getLogsFormatString( const WebServer& web_server ) const noexcept;
//! Returns the LogsFormat currently set for the given Web Server
/*!
\param web_server_id ID of the Web Server
\param web_server ID of the Web Server
\return The LogsFormat instance
\see LogsFormat
*/
const LogsFormat& getLogsFormat( const unsigned& web_server_id ) const noexcept;
const LogsFormat& getLogsFormat( const WebServer& web_server ) const noexcept;
//! Returns a sample log line for the given Web Server using the relative LogsFormat
/*!
\param web_server_id ID of the Web Server
\param web_server ID of the Web Server
\return The sample of a log line
\throw WebServerException
\see FormatOps::getApacheLogSample(), FormatOps::getNginxLogSample(), FormatOps::getIisLogSample()
*/
QString getLogsFormatSample( const unsigned& web_server_id ) const;
QString getLogsFormatSample( const WebServer& web_server ) const;
//! Checks whether the current Logs Format is valid or not
bool checkCurrentLogsFormat() const noexcept;
@ -238,147 +238,147 @@ public:
//! Returns whether the relative blacklist is set to be used or not
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\return Whether the list is used or not
\see BWlist
*/
bool isBlacklistUsed( const unsigned& web_server_id, const int& log_field_id ) const noexcept;
bool isBlacklistUsed( const WebServer& web_server, const int& log_field_id ) const noexcept;
//! Returns whether the relative warnlist is set to be used or not
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\return Whether the list is used or not
\see BWlist
*/
bool isWarnlistUsed( const unsigned& web_server_id, const int& log_field_id ) const noexcept;
bool isWarnlistUsed( const WebServer& web_server, const int& log_field_id ) const noexcept;
//! Sets the relative blacklist to be used or not
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param used Whether the list is to be used or not
\see BWlist
*/
void setBlacklistUsed( const unsigned& web_server_id, const int& log_field_id, const bool used ) noexcept;
void setBlacklistUsed( const WebServer& web_server, const int& log_field_id, const bool used ) noexcept;
//! Sets the relative warnlist to be used or not
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param used Whether the list is to be used or not
\see BWlist
*/
void setWarnlistUsed( const unsigned& web_server_id, const int& log_field_id, const bool used ) noexcept;
void setWarnlistUsed( const WebServer& web_server, const int& log_field_id, const bool used ) noexcept;
//! Returns the relative items list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\return The list of items in the given blacklist
\see BWlist
*/
const std::vector<std::string>& getBlacklist( const unsigned& web_server_id, const int& log_field_id ) const noexcept;
const std::vector<std::string>& getBlacklist( const WebServer& web_server, const int& log_field_id ) const noexcept;
//! Returns the relative items list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\return The list of items in the givenwarnlist
\see BWlist
*/
const std::vector<std::string>& getWarnlist( const unsigned& web_server_id, const int& log_field_id ) const noexcept;
const std::vector<std::string>& getWarnlist( const WebServer& web_server, const int& log_field_id ) const noexcept;
//! Sets the relative items list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param new_list The new items list
\see BWlist
*/
void setBlacklist( const unsigned& web_server_id, const int& log_field_id, const std::vector<std::string>& new_list );
void setBlacklist( const WebServer& web_server, const int& log_field_id, const std::vector<std::string>& new_list );
//! Sets the relative items list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param new_list The new items list
\see BWlist
*/
void setWarnlist( const unsigned& web_server_id, const int& log_field_id, const std::vector<std::string>& new_list );
void setWarnlist( const WebServer& web_server, const int& log_field_id, const std::vector<std::string>& new_list );
//! Adds an item to the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param new_list The new items list
\see BWlist
*/
void blacklistAdd( const unsigned& web_server_id, const int& log_field_id, const std::string& new_item );
void blacklistAdd( const WebServer& web_server, const int& log_field_id, const std::string& new_item );
//! Adds an item to the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param new_item The new item to add to the list
\see BWlist
*/
void warnlistAdd( const unsigned& web_server_id, const int& log_field_id, const std::string& new_item );
void warnlistAdd( const WebServer& web_server, const int& log_field_id, const std::string& new_item );
//! Removes an item from the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param item The item to remove from the list
\see BWlist
*/
void blacklistRemove( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept;
void blacklistRemove( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept;
//! Removes an item from the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param item The item to remove from the list
\see BWlist
*/
void warnlistRemove( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept;
void warnlistRemove( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept;
//! Moves an item one position up in the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param item The item to move
\see BWlist
*/
int blacklistMoveUp( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept;
int blacklistMoveUp( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept;
//! Moves an item one position up in the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param item The item to move
\see BWlist
*/
int warnlistMoveUp( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept;
int warnlistMoveUp( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept;
//! Moves an item one position down in the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param item The item to move
\see BWlist
*/
int blacklistMoveDown( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept;
int blacklistMoveDown( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept;
//! Moves an item one position down in the relative list
/*!
\param web_server_id The ID of the Web Server
\param web_server The Web Server
\param log_field_id The ID of the log field
\param item The item to move
\see BWlist
*/
int warnlistMoveDown( const unsigned& web_server_id, const int& log_field_id, const std::string& item ) noexcept;
int warnlistMoveDown( const WebServer& web_server, const int& log_field_id, const std::string& item ) noexcept;
//////////////
@ -520,9 +520,9 @@ private:
//////////////////////////////
//// BLACKLIST / WARNLIST ////
// { web_server_id : { log_field_id : BWlist } }
std::unordered_map<unsigned, std::unordered_map<int, BWlist>> blacklists;
std::unordered_map<unsigned, std::unordered_map<int, BWlist>> warnlists;
// { web_server : { log_field_id : BWlist } }
std::unordered_map<WebServer, std::unordered_map<int, BWlist>> blacklists;
std::unordered_map<WebServer, std::unordered_map<int, BWlist>> warnlists;
//! Sanitizes an item removing the unwanted elements
/*!
@ -540,9 +540,9 @@ private:
//// WEB SERVER ////
// currently used web server
unsigned current_WS{ APACHE_ID };
WebServer current_web_server{ WS_APACHE };
std::unordered_map<int, std::string> logs_paths;
std::unordered_map<WebServer, std::string> logs_paths;
//! Web Server specific file names criterions
/*!
@ -555,7 +555,7 @@ private:
std::string ends; //!< What should be the final part of the name
};
std::unordered_map<unsigned, LogName> logs_base_names;
std::unordered_map<WebServer, LogName> logs_base_names;
//! Changes the name criterions for IIS logs files names depending on the given module
/*!
@ -578,12 +578,12 @@ private:
FormatOps formatOps;
std::unordered_map<unsigned, std::string> logs_format_strings;
std::unordered_map<WebServer, std::string> logs_format_strings;
std::unordered_map<unsigned, LogsFormat> logs_formats;
std::unordered_map<WebServer, LogsFormat> logs_formats;
// currently used logs format
LogsFormat current_LF;
LogsFormat current_log_format;
};

View File

@ -136,9 +136,9 @@ void HashOps::digestFile( const std::string& file_path, std::string& hash )
// check if the given hash is from a file which has been used already
bool HashOps::hasBeenUsed( const std::string &file_hash, const unsigned& web_server_id) const noexcept
bool HashOps::hasBeenUsed( const std::string &file_hash, const WebServer& web_server) const noexcept
{
const auto& ws_hashes{ this->hashes.at( web_server_id ) };
const auto& ws_hashes{ this->hashes.at( web_server ) };
return std::any_of(
ws_hashes.cbegin(), ws_hashes.cend(),
[&file_hash]( const std::string& hash )
@ -147,15 +147,15 @@ bool HashOps::hasBeenUsed( const std::string &file_hash, const unsigned& web_ser
// insert the given hash/es in the relative list
bool HashOps::insertUsedHash( QSqlQuery& query, const QString& db_name, const std::string& hash, const unsigned& web_server_id ) noexcept
bool HashOps::insertUsedHash( QSqlQuery& query, const QString& db_name, const std::string& hash, const WebServer& web_server ) noexcept
{
bool successful{ true };
try {
if( ! VecOps::contains<std::string>( this->hashes.at( web_server_id ), hash ) ) {
this->hashes.at( web_server_id ).push_back( hash );
if( ! VecOps::contains<std::string>( this->hashes.at( web_server ), hash ) ) {
this->hashes.at( web_server ).push_back( hash );
// insert tnto the database
QString stmt = QString("INSERT INTO %1 ( hash ) VALUES ( '%2' );")
.arg( this->ws_names.at(web_server_id), QString::fromStdString(hash).replace("'","''") );
.arg( this->ws_names.at(web_server), QString::fromStdString(hash).replace("'","''") );
if ( ! query.exec( stmt ) ) {
// error opening database
successful &= false;
@ -180,7 +180,7 @@ bool HashOps::insertUsedHash( QSqlQuery& query, const QString& db_name, const st
}
bool HashOps::insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const unsigned& web_server_id )
bool HashOps::insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const WebServer& web_server )
{
bool successful{ true };
@ -218,7 +218,7 @@ bool HashOps::insertUsedHashes( const std::string& db_path, const std::vector<st
try {
for ( const std::string& hash : hashes ) {
successful = this->insertUsedHash( query, db_name, hash, web_server_id );
successful = this->insertUsedHash( query, db_name, hash, web_server );
if ( ! successful ) {
break;
}

View File

@ -9,6 +9,9 @@
#include <QString>
enum class WebServer;
class QSqlQuery;
@ -45,7 +48,7 @@ public:
\param web_server_id The ID of the Web Server which generated the file
\return Whether the hash is already in the list or not
*/
bool hasBeenUsed( const std::string& file_hash, const unsigned& web_server_id ) const noexcept;
bool hasBeenUsed( const std::string& file_hash, const WebServer& web_server ) const noexcept;
//! Inserts multiple hashes in the corresponding database table
/*!
@ -54,7 +57,7 @@ public:
\param web_server_id The ID of the Web Server which generated the file
\return Whether the operation has been successful or not
*/
bool insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const unsigned& web_server_id );
bool insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const WebServer& web_server );
private:
@ -62,24 +65,24 @@ private:
int dialog_level{ 2 };
// List of Web Servers names for database tables
const std::unordered_map<unsigned, QString> ws_names{
{APACHE_ID, "apache"},
{NGINX_ID, "nginx"},
{IIS_ID, "iis"}
const std::unordered_map<WebServer, QString> ws_names{
{WS_APACHE, "apache"},
{WS_NGINX, "nginx"},
{WS_IIS, "iis"}
};
// Lists of used files' hashes
// { web_server_id : { hashes } }
std::unordered_map<unsigned, std::vector<std::string>> hashes{
{APACHE_ID, {}},
{NGINX_ID, {}},
{IIS_ID, {}}
std::unordered_map<WebServer, std::vector<std::string>> hashes{
{WS_APACHE, {}},
{WS_NGINX, {}},
{WS_IIS, {}}
};
// Called by insertUsedHashes()
// Inserts a hash in the corresponding database table
bool insertUsedHash( QSqlQuery& query, const QString& db_name, const std::string& hash, const unsigned& web_server_id ) noexcept;
bool insertUsedHash( QSqlQuery& query, const QString& db_name, const std::string& hash, const WebServer& web_server ) noexcept;
};

View File

@ -13,9 +13,9 @@
#include "modules/craplog/modules/workers/lib.h"
CraplogLister::CraplogLister( const unsigned web_server_id, const unsigned dialogs_level, const std::string& logs_path, const LogsFormat& logs_format, const HashOps& hashOps, const std::function<bool(const std::string&)> check_filename, QObject* parent )
CraplogLister::CraplogLister( const WebServer web_server, const unsigned dialogs_level, const std::string& logs_path, const LogsFormat& logs_format, const HashOps& hashOps, const std::function<bool(const std::string&)> check_filename, QObject* parent )
: QObject { parent }
, wsID { web_server_id }
, web_server { web_server }
, dialogs_level { dialogs_level }
, logs_path { logs_path }
, logs_format { logs_format }
@ -120,7 +120,7 @@ void CraplogLister::work()
// push in the list
emit this->pushLogFile( LogFile{
false, this->hashOps.hasBeenUsed( hash, this->wsID ),
false, this->hashOps.hasBeenUsed( hash, this->web_server ),
size, name, hash, path } );
}
this->quit();

View File

@ -8,6 +8,7 @@ struct LogsFormat;
struct LogFile;
class HashOps;
enum class WebServer;
enum class WorkerDialog;
@ -18,7 +19,7 @@ class CraplogLister final : public QObject
public:
explicit CraplogLister(
const unsigned web_server_id,
const WebServer web_server,
const unsigned dialogs_level,
const std::string& logs_path,
const LogsFormat& logs_format,
@ -45,7 +46,7 @@ public slots:
private:
const unsigned wsID;
const WebServer web_server;
const unsigned dialogs_level;

View File

@ -19,9 +19,9 @@
#include <QSqlError>
CraplogParser::CraplogParser( const unsigned web_server_id, const unsigned dialogs_level, const std::string& db_data_path, const std::string& db_hashes_path, const LogsFormat& logs_format, const bw_lists_t& blacklists, const bw_lists_t& warnlists, const worker_files_t& log_files, QObject* parent )
CraplogParser::CraplogParser( const WebServer web_server, const unsigned dialogs_level, const std::string& db_data_path, const std::string& db_hashes_path, const LogsFormat& logs_format, const bw_lists_t& blacklists, const bw_lists_t& warnlists, const worker_files_t& log_files, QObject* parent )
: QObject { parent }
, wsID { web_server_id }
, web_server { web_server }
, dialogs_level { dialogs_level }
, db_data_path { db_data_path }
, db_hashes_path { db_hashes_path }
@ -152,7 +152,7 @@ void CraplogParser::joinLogLines()
this->total_lines += content.size();
this->total_size += aux.size();
if ( this->wsID == IIS_ID ) {
if ( this->web_server == WS_IIS ) {
cleanLines( content );
}
@ -357,7 +357,7 @@ void CraplogParser::storeLogLines()
#define APPEND_TO_QUERY_USER_AGENT(LOG_FIELD)\
query_stmt += QStringLiteral(", ");\
if ( LOG_FIELD ) {\
if ( this->wsID == IIS_ID ) {\
if ( this->web_server == WS_IIS ) {\
query_stmt += QString("'%1'").arg( QString::fromStdString( *LOG_FIELD ).replace("+"," ").replace("'","''") );\
} else {\
query_stmt += QString("'%1'").arg( QString::fromStdString( *LOG_FIELD ).replace("'","''") );\
@ -402,19 +402,19 @@ bool CraplogParser::storeData( QSqlDatabase& db )
// prepare the database related studd
QString table;
switch ( this->wsID ) {
case APACHE_ID:
switch ( this->web_server ) {
case WS_APACHE:
table += "apache";
break;
case NGINX_ID:
case WS_NGINX:
table += "nginx";
break;
case IIS_ID:
case WS_IIS:
table += "iis";
break;
default:
// wrong WebServerID, but should be unreachable because of the previous operations
throw WebServerException( "Unexpected WebServerID: " + std::to_string(this->wsID) );
throw WebServerException( "Unexpected WebServer: " + toString(this->web_server) );
}

View File

@ -12,6 +12,7 @@
struct BWlist;
struct LogLineData;
enum class WebServer;
enum class WorkerDialog;
class QSqlDatabase;
@ -28,7 +29,7 @@ class CraplogParser final : public QObject
public:
explicit CraplogParser(
const unsigned web_server_id,
const WebServer web_server,
const unsigned dialogs_level,
const std::string& db_data_path,
const std::string& db_hashes_path,
@ -73,7 +74,7 @@ public slots:
private:
const unsigned wsID;
const WebServer web_server;
const unsigned dialogs_level;