Version upgrade 4.00 #45
4 changed files with 46 additions and 26 deletions
|
@ -2694,21 +2694,8 @@ void MainWindow::on_button_MakeStats_Start_clicked()
|
|||
{
|
||||
if ( this->dbUsable() ) {
|
||||
bool proceed{ true };
|
||||
// check that the format has been set
|
||||
const LogsFormat& lf{ this->craplog.getLogsFormat( this->craplog.getCurrentWSID() ) };
|
||||
if ( lf.string.empty() ) {
|
||||
// format string not set
|
||||
proceed &= false;
|
||||
DialogSec::errLogFormatNotSet( nullptr );
|
||||
} else if ( lf.fields.empty() ) {
|
||||
// no field, useless to parse
|
||||
proceed &= false;
|
||||
DialogSec::errLogFormatNoFields( nullptr );
|
||||
} else if ( lf.separators.size() < lf.fields.size()-1 ) {
|
||||
// missing at least a separator between two (or more) fields
|
||||
proceed &= false;
|
||||
DialogSec::errLogFormatNoSeparators( nullptr );
|
||||
}
|
||||
// check that the format has been set and is consistent
|
||||
proceed = craplog.checkCurrentLogsFormat();
|
||||
|
||||
if ( proceed ) {
|
||||
// take actions on Craplog's start
|
||||
|
@ -4677,7 +4664,7 @@ void MainWindow::on_inLine_ConfApache_Format_String_returnPressed()
|
|||
void MainWindow::on_button_ConfApache_Format_Save_clicked()
|
||||
{
|
||||
const bool success{ this->craplog.setApacheLogFormat(
|
||||
this->ui->inLine_ConfApache_Format_String->text().toStdString() ) };
|
||||
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 ) {
|
||||
|
@ -5048,7 +5035,7 @@ void MainWindow::on_inLine_ConfNginx_Format_String_returnPressed()
|
|||
void MainWindow::on_button_ConfNginx_Format_Save_clicked()
|
||||
{
|
||||
const bool success{ this->craplog.setNginxLogFormat(
|
||||
this->ui->inLine_ConfNginx_Format_String->text().toStdString() ) };
|
||||
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 ) {
|
||||
|
@ -5481,7 +5468,7 @@ void MainWindow::on_inLine_ConfIis_Format_String_returnPressed()
|
|||
void MainWindow::on_button_ConfIis_Format_Save_clicked()
|
||||
{
|
||||
const bool success{ this->craplog.setIisLogFormat(
|
||||
StringOps::strip( this->ui->inLine_ConfIis_Format_String->text().toStdString() ),
|
||||
this->ui->inLine_ConfIis_Format_String->text().trimmed().toStdString(),
|
||||
this->getIisLogsModule() ) };
|
||||
if ( success ) {
|
||||
this->ui->button_ConfIis_Format_Save->setEnabled( false );
|
||||
|
|
|
@ -35,23 +35,23 @@ Craplog::Craplog()
|
|||
////////////////////////
|
||||
// blacklists / whitelists
|
||||
for ( unsigned i{APACHE_ID}; i<=IIS_ID; i++ ) {
|
||||
this->warnlists.emplace( i, std::unordered_map<int, BWlist>{} );
|
||||
this->blacklists.emplace( i, std::unordered_map<int, BWlist>{} );
|
||||
this->warnlists.emplace( i, std::unordered_map<int, BWlist>(4) );
|
||||
this->blacklists.emplace( i, std::unordered_map<int, BWlist>(1) );
|
||||
// default data
|
||||
this->warnlists.at( i ).emplace( 11, BWlist{ .used=false, .list={"DELETE","HEAD","OPTIONS","PUT","PATCH"} } );
|
||||
this->warnlists.at( i ).emplace( 12, BWlist{ .used=true, .list={"/robots.txt","/../","/./","/.env","/.htaccess","/phpmyadmin","/wp-admin","/wp-content","/wp-config.php","/config.py","/views.py","/routes.py","/setup.cgi","/cgi-bin"} } );
|
||||
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=true, .list={} } );
|
||||
this->blacklists.at( i ).emplace( 20, BWlist{ .used=false, .list={} } );
|
||||
}
|
||||
|
||||
// default format strings
|
||||
this->logs_format_strings.emplace(
|
||||
APACHE_ID, "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" );
|
||||
APACHE_ID, "" );
|
||||
this->logs_format_strings.emplace(
|
||||
NGINX_ID, "$remote_addr - $remote_user [$time_local] \"$request\" $status $bytes_sent \"$http_referer\" \"$http_user_agent\"" );
|
||||
NGINX_ID, "" );
|
||||
this->logs_format_strings.emplace(
|
||||
IIS_ID, "date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken" );
|
||||
IIS_ID, "" );
|
||||
|
||||
// initialize formats
|
||||
this->logs_formats.emplace(
|
||||
|
@ -393,6 +393,24 @@ QString Craplog::getLogsFormatSample( const unsigned& web_server_id ) const
|
|||
}
|
||||
}
|
||||
|
||||
bool Craplog::checkCurrentLogsFormat() const
|
||||
{
|
||||
if ( this->current_LF.string.empty() ) {
|
||||
// format string not set
|
||||
DialogSec::errLogFormatNotSet( nullptr );
|
||||
return false;
|
||||
} else if ( this->current_LF.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 ) {
|
||||
// at least one separator is missing between two (or more) fields
|
||||
DialogSec::errLogFormatNoSeparators( nullptr );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// set the current Web Server
|
||||
void Craplog::setCurrentWSID( const unsigned web_server_id )
|
||||
|
|
|
@ -214,6 +214,9 @@ public:
|
|||
*/
|
||||
QString getLogsFormatSample( const unsigned& web_server_id ) const;
|
||||
|
||||
//! Checks whether the current Logs Format is valid or not
|
||||
bool checkCurrentLogsFormat() const;
|
||||
|
||||
|
||||
|
||||
//////////////////////
|
||||
|
|
|
@ -251,6 +251,10 @@ void checkIisString( std::string_view string )
|
|||
|
||||
LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) const
|
||||
{
|
||||
if ( f_str.empty() ) {
|
||||
return LogsFormat();
|
||||
}
|
||||
|
||||
const auto& f_map { this->APACHE_ALF };
|
||||
const auto& f_map_v { this->APACHE_ALF_V };
|
||||
|
||||
|
@ -582,6 +586,10 @@ QString FormatOps::getApacheLogSample( const LogsFormat& log_format ) const
|
|||
|
||||
LogsFormat FormatOps::processNginxFormatString( const std::string& f_str ) const
|
||||
{
|
||||
if ( f_str.empty() ) {
|
||||
return LogsFormat();
|
||||
}
|
||||
|
||||
const auto& f_map{ this->NGINX_ALF };
|
||||
|
||||
std::string initial, final;
|
||||
|
@ -678,6 +686,10 @@ QString FormatOps::getNginxLogSample( const LogsFormat& log_format ) const
|
|||
|
||||
LogsFormat FormatOps::processIisFormatString( const std::string& f_str, const int& l_mod ) const
|
||||
{
|
||||
if ( f_str.empty() ) {
|
||||
return LogsFormat();
|
||||
}
|
||||
|
||||
checkIisString( f_str );
|
||||
std::string initial, final;
|
||||
std::vector<std::string> separators, fields;
|
||||
|
|
Loading…
Reference in a new issue