Implemented new methods + updates

This commit is contained in:
Valentino Orlandi 2022-07-21 21:44:27 +02:00
parent a7dc8e6a0b
commit 67d34c6295
Signed by: elB4RTO
GPG key ID: 1719E976DB2D4E71
2 changed files with 120 additions and 12 deletions

View file

@ -1,9 +1,67 @@
#include "crapview.h"
#include <iostream> // !!! REMOVE !!!
Crapview::Crapview()
{
count_ws = 11, count_type = 1, count_field = 10,
daytime_ws = 11, daytime_type = 1, daytime_field = 10,
relational_ws = 11, relational_field_1 = 10, relational_field_2 = 11,
speed_ws = 11;
}
const int Crapview::getDialogLevel()
{
return this->dialog_level;
}
void Crapview::setDialogLevel( const int new_level )
{
this->dialog_level = new_level;
}
void Crapview::setDbPath( const std::string& path )
{
this->dbQuery.setDbPath( path );
}
void Crapview::refreshDates()
{
auto result = this->dbQuery.refreshDates();
if ( std::get<0>(result) == true ) {
this->dates = std::get<1>(result);
}
}
const QStringList Crapview::getYears( const QString& web_server, const QString& logs_type )
{
QStringList years;
for ( const auto& [year, data] : this->dates.at( this->WebServer_s2i.value( web_server ) ).at( this->LogsType_s2i.value( logs_type ) ) ) {
years.push_back( QString::fromStdString( std::to_string( year ) ) );
}
return years;
}
const QStringList Crapview::getMonths( const QString& web_server, const QString& logs_type, const QString& year )
{
QStringList months;
for ( const auto& [month, data] : this->dates.at( this->WebServer_s2i.value( web_server ) ).at( this->LogsType_s2i.value( logs_type )).at( year.toInt() ) ) {
months.push_back( Months_i2s.value( month ) );
}
return months;
}
const QStringList Crapview::getDays( const QString& web_server, const QString& logs_type, const QString& year, const QString& month )
{
QStringList days;
for ( const int day : this->dates.at( this->WebServer_s2i.value( web_server ) ).at( this->LogsType_s2i.value( logs_type )).at( year.toInt() ).at( this->Months_s2i.value( month ) ) ) {
days.push_back( QString::fromStdString( std::to_string( day ) ) );
}
return days;
}
const QStringList Crapview::getFields( const QString& tab, const QString& logs_type )
{
return this->fields.value( tab ).value( logs_type );
}

View file

@ -1,6 +1,10 @@
#ifndef CRAPVIEW_H
#define CRAPVIEW_H
#include <QHash>
#include "tools/crapview/modules/query.h"
#include <string>
@ -9,19 +13,65 @@ class Crapview
public:
Crapview();
const int getDialogLevel();
void setDialogLevel( const int new_level );
void setDbPath( const std::string& path );
void refreshDates();
const QStringList getYears( const QString& web_server, const QString& logs_type );
const QStringList getMonths( const QString& web_server, const QString& logs_type, const QString& year );
const QStringList getDays( const QString& web_server, const QString& logs_type, const QString& year, const QString& month );
const QStringList getFields( const QString& tab, const QString& logs_type );
private:
// quantity of informational dialogs to display
int dialog_level = 2; // 0: essential, 1: usefull, 2: explanatory
bool daytime_period;
DbQuery dbQuery;
int count_ws, count_type, count_field,
daytime_ws, daytime_type, daytime_field,
relational_ws, relational_field_1, relational_field_2,
speed_ws;
// collection of available dates
// { web_server : { log_type : { year : { month_str : [ days ] } } } }
std::unordered_map<int, std::unordered_map<int, std::unordered_map<int, std::unordered_map<int, std::vector<int>>>>> dates;
std::string daytime_filter,
relational_field_1_filter, relational_field_2_filter,
speed_uri_filter;
// collection of available fields for tabs which needs them
// { tab : { log_type_str : [ fields ] } }
const QHash<QString, QHash<QString, QStringList>> fields = {
{"Daytime", {
{"Access", {"Protocol","Method","URI","Query","Response code","Referrer","Cookie","User-agent","Client"}},
{"Error", {"Level","Message","Source file","Client","Port"}} }},
{"Relational", {
{"Access", {"Protocol","Method","URI","Query","Response code","Time taken","Bytes sent","Bytes received","Referrer","Cookie","User-agent","Client"}},
{"Error", {"Level","Message","Source file","Client","Port"}} }}
};
// conversion between text and IDs
const QHash<QString, int>
WebServer_s2i = {
{"Apache2",11}, {"Nginx",12}, {"IIS",13} },
LogsType_s2i = {
{"Access",1}, {"Error",2} },
Months_s2i = {
{"January",1}, {"February",2}, {"March",3}, {"April",4}, {"May",5}, {"June",6},
{"July",7}, {"August",8}, {"September",9}, {"October",10}, {"November",11}, {"December",12} };
const QHash<int, QString>
/*WebServer_i2s = {
{11,"Apache2"}, {12,"Nginx"}, {13,"IIS"} },
LogsType_i2s = {
{1,"Access"}, {2,"Error"} },
LogField_i2s = {
{1,"year"}, {2,"month"}, {3,"day"}, {4,"hour"}, {5,"minute"}, {6,"second"},
{10,"protocol"}, {11,"method"}, {12,"request"}, {13,"query"}, {14,"response"},
{15,"time_taken"}, {16,"bytes_sent"}, {17,"bytes_received"}, {18,"referrer"},
{20,"client"}, {21,"user_agent"}, {22,"cookie"},
{30,"port"}, {31,"level"}, {32,"message"}, {33,"source_file"} },*/
Months_i2s = {
{1,"January"}, {2,"February"}, {3,"March"}, {4,"April"}, {5,"May"}, {6,"June"},
{7,"July"}, {8,"August"}, {9,"September"}, {10,"October"}, {11,"November"}, {12,"December"} };
};
#endif // CRAPVIEW_H