LogDoctor/logdoctor/mainwindow.h

660 lines
18 KiB
C
Raw Normal View History

2022-06-21 21:07:06 +02:00
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
2022-06-20 21:44:58 +02:00
#include "ui_mainwindow.h"
2022-07-26 20:44:47 +02:00
#include <QMainWindow>
#include <QCloseEvent>
2022-06-20 21:44:58 +02:00
#include <QTranslator>
2022-07-26 20:44:47 +02:00
#include <QFontDatabase>
#include <QMessageBox>
#include <QTreeWidget>
#include <QChartView>
2022-06-21 21:07:06 +02:00
#include <thread>
#include "utilities/colors.h"
#include "utilities/io.h"
#include "utilities/rtf.h"
#include "utilities/strings.h"
#include "utilities/vectors.h"
#include "modules/checks.h"
#include "modules/dialogs.h"
#include "modules/tb.h"
#include "tools/shared.h"
2022-06-26 22:31:45 +02:00
#include "tools/craplog/craplog.h"
2022-07-21 21:45:52 +02:00
#include "tools/crapview/crapview.h"
#include "tools/craphelp/craphelp.h"
#include "tools/crapup/crapup.h"
#include "tools/crapnote/crapnote.h"
#include "tools/crapinfo/crapinfo.h"
2022-06-23 04:00:37 +02:00
2022-06-20 21:44:58 +02:00
QT_BEGIN_NAMESPACE
2022-06-21 21:07:06 +02:00
namespace Ui { class MainWindow; }
2022-06-20 21:44:58 +02:00
QT_END_NAMESPACE
2022-06-21 21:07:06 +02:00
class MainWindow : public QMainWindow
2022-06-20 21:44:58 +02:00
{
Q_OBJECT
2022-06-20 21:44:58 +02:00
public:
MainWindow(QWidget *parent=nullptr);
2022-06-21 21:07:06 +02:00
~MainWindow();
2022-07-26 20:44:47 +02:00
void closeEvent( QCloseEvent *event );
//void operator()( int a );
2022-06-21 21:07:06 +02:00
private slots:
2022-07-21 21:45:52 +02:00
// custom
void wait_ActiveWindow();
void update_Craplog_PerfData();
void check_CraplogLLT_Finished();
2022-07-21 21:45:52 +02:00
// Qt's
/////////////////
//// CRAPLOG ////
void on_button_LogFiles_ViewFile_clicked();
2022-06-25 21:17:40 +02:00
void on_checkBox_LogFiles_CheckAll_stateChanged(int arg1);
void on_button_LogFiles_RefreshList_clicked();
2022-06-21 21:07:06 +02:00
void on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column);
void on_listLogFiles_itemChanged(QTreeWidgetItem *item, int column);
2022-06-26 23:12:57 +02:00
void on_button_LogFiles_Apache_clicked();
void on_button_LogFiles_Nginx_clicked();
void on_button_LogFiles_Iis_clicked();
void on_button_MakeStats_Start_clicked();
//////////////////
//// CRAPVIEW ////
void drawStatsWarn();
void drawStatsSpeed();
void drawStatsCount();
void drawStatsDay();
void drawStatsRelat();
void makeStatsGlobals();
//// WARNINGS ////
void on_box_StatsWarn_WebServer_currentIndexChanged(int index);
void on_box_StatsWarn_Year_currentIndexChanged(int index);
void on_box_StatsWarn_Month_currentIndexChanged(int index);
void on_box_StatsWarn_Day_currentIndexChanged(int index);
void on_checkBox_StatsWarn_Hour_stateChanged(int state);
void on_box_StatsWarn_Hour_currentIndexChanged(int index);
void on_button_StatsWarn_Draw_clicked();
2022-07-28 22:45:38 +02:00
void on_button_StatsWarn_Update_clicked();
//// SPEED ////
2022-07-21 21:45:52 +02:00
void on_box_StatsSpeed_WebServer_currentIndexChanged(int index);
2022-07-09 18:16:09 +02:00
2022-07-21 21:45:52 +02:00
void on_box_StatsSpeed_Year_currentIndexChanged(int index);
void on_box_StatsSpeed_Month_currentIndexChanged(int index);
void on_box_StatsSpeed_Day_currentIndexChanged(int index);
2022-07-21 21:45:52 +02:00
void on_button_StatsSpeed_Draw_clicked();
//// COUNTS ////
void on_box_StatsCount_WebServer_currentIndexChanged(int index);
void on_box_StatsCount_Year_currentIndexChanged(int index);
void on_box_StatsCount_Month_currentIndexChanged(int index);
void on_box_StatsCount_Day_currentIndexChanged(int index);
void on_button_StatsCount_Protocol_clicked();
void on_button_StatsCount_Method_clicked();
void on_button_StatsCount_Uri_clicked();
void on_button_StatsCount_Query_clicked();
void on_button_StatsCount_Response_clicked();
void on_button_StatsCount_Referrer_clicked();
void on_button_StatsCount_Cookie_clicked();
void on_button_StatsCount_UserAgent_clicked();
void on_button_StatsCount_Client_clicked();
//// DAY-TIME ////
void on_box_StatsDay_WebServer_currentIndexChanged(int index);
void on_box_StatsDay_LogsField_currentIndexChanged(int index);
void on_box_StatsDay_FromYear_currentIndexChanged(int index);
void on_box_StatsDay_FromMonth_currentIndexChanged(int index);
void on_box_StatsDay_FromDay_currentIndexChanged(int index);
void on_checkBox_StatsDay_Period_stateChanged(int state);
void on_box_StatsDay_ToYear_currentIndexChanged(int index);
void on_box_StatsDay_ToMonth_currentIndexChanged(int index);
void on_box_StatsDay_ToDay_currentIndexChanged(int index);
void on_button_StatsDay_Draw_clicked();
//// RELATIONAL ////
void on_box_StatsRelat_WebServer_currentIndexChanged(int index);
void on_box_StatsRelat_LogsField_1_currentIndexChanged(int index);
void on_box_StatsRelat_LogsField_2_currentIndexChanged(int index);
void on_box_StatsRelat_FromYear_currentIndexChanged(int index);
void on_box_StatsRelat_FromMonth_currentIndexChanged(int index);
void on_box_StatsRelat_FromDay_currentIndexChanged(int index);
void on_box_StatsRelat_ToYear_currentIndexChanged(int index);
void on_box_StatsRelat_ToMonth_currentIndexChanged(int index);
void on_box_StatsRelat_ToDay_currentIndexChanged(int index);
void on_button_StatsRelat_Draw_clicked();
void on_button_StatsGlob_Apache_clicked();
void on_button_StatsGlob_Nginx_clicked();
void on_button_StatsGlob_Iis_clicked();
/////////////////
//// CRAPSET ////
//// WINDOW ////
void on_checkBox_ConfWindow_Geometry_clicked(bool checked);
void on_box_ConfWindow_Theme_currentIndexChanged(int index);
//// DIALOGS ////
void on_slider_ConfDialogs_General_sliderReleased();
void on_slider_ConfDialogs_Logs_sliderReleased();
void on_slider_ConfDialogs_Stats_sliderReleased();
//// TEXT BROWSER ////
void on_box_ConfTextBrowser_Font_currentIndexChanged(int index);
void on_checkBox_ConfTextBrowser_WideLines_clicked(bool checked);
void on_box_ConfTextBrowser_ColorScheme_currentIndexChanged(int index);
//// CHARTS ////
void on_box_ConfCharts_Theme_currentIndexChanged(int index);
//// DATABASES ////
void on_inLine_ConfDatabases_Data_Path_textChanged(const QString &arg1);
void on_inLine_ConfDatabases_Data_Path_returnPressed();
void on_button_ConfDatabases_Data_Save_clicked();
void on_inLine_ConfDatabases_Hashes_Path_textChanged(const QString &arg1);
void on_inLine_ConfDatabases_Hashes_Path_returnPressed();
void on_button_ConfDatabases_Hashes_Save_clicked();
void on_checkBox_ConfDatabases_DoBackup_clicked(bool checked);
void on_spinBox_ConfDatabases_NumBackups_valueChanged(int arg1);
//// LOGS DEFAULTS ////
void on_radio_ConfDefaults_Apache_toggled(bool checked);
void on_radio_ConfDefaults_Nginx_toggled(bool checked);
void on_radio_ConfDefaults_Iis_toggled(bool checked);
//// LOGS CONTROL ////
void on_checkBox_ConfControl_Usage_clicked(bool checked);
void on_checkBox_ConfControl_Size_clicked(bool checked);
void on_spinBox_ConfControl_Size_editingFinished();
//// APACHE ////
void on_inLine_ConfApache_Path_String_textChanged(const QString &arg1);
void on_inLine_ConfApache_Path_String_returnPressed();
void on_button_ConfApache_Path_Save_clicked();
void on_inLine_ConfApache_Format_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfApache_Format_String_returnPressed();
void on_button_ConfApache_Format_Save_clicked();
void on_button_ConfApache_Format_Sample_clicked();
void on_button_ConfApache_Format_Help_clicked();
void on_box_ConfApache_Warnlist_Field_currentTextChanged(const QString &arg1);
void on_checkBox_ConfApache_Warnlist_Used_clicked(bool checked);
void on_inLine_ConfApache_Warnlist_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfApache_Warnlist_String_returnPressed();
void on_button_ConfApache_Warnlist_Add_clicked();
void on_list_ConfApache_Warnlist_List_itemSelectionChanged();
void on_button_ConfApache_Warnlist_Remove_clicked();
void on_button_ConfApache_Warnlist_Up_clicked();
void on_button_ConfApache_Warnlist_Down_clicked();
void on_box_ConfApache_Blacklist_Field_currentTextChanged(const QString &arg1);
void on_checkBox_ConfApache_Blacklist_Used_clicked(bool checked);
void on_inLine_ConfApache_Blacklist_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfApache_Blacklist_String_returnPressed();
void on_button_ConfApache_Blacklist_Add_clicked();
void on_list_ConfApache_Blacklist_List_itemSelectionChanged();
void on_button_ConfApache_Blacklist_Remove_clicked();
void on_button_ConfApache_Blacklist_Up_clicked();
void on_button_ConfApache_Blacklist_Down_clicked();
//// NGINX ////
void on_inLine_ConfNginx_Path_String_textChanged(const QString &arg1);
void on_inLine_ConfNginx_Path_String_returnPressed();
void on_button_ConfNginx_Path_Save_clicked();
void on_inLine_ConfNginx_Format_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfNginx_Format_String_returnPressed();
void on_button_ConfNginx_Format_Save_clicked();
void on_button_ConfNginx_Format_Sample_clicked();
void on_button_ConfNginx_Format_Help_clicked();
void on_box_ConfNginx_Warnlist_Field_currentTextChanged(const QString &arg1);
void on_checkBox_ConfNginx_Warnlist_Used_clicked(bool checked);
void on_inLine_ConfNginx_Warnlist_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfNginx_Warnlist_String_returnPressed();
void on_button_ConfNginx_Warnlist_Add_clicked();
void on_list_ConfNginx_Warnlist_List_itemSelectionChanged();
void on_button_ConfNginx_Warnlist_Remove_clicked();
void on_button_ConfNginx_Warnlist_Up_clicked();
void on_button_ConfNginx_Warnlist_Down_clicked();
void on_box_ConfNginx_Blacklist_Field_currentTextChanged(const QString &arg1);
void on_checkBox_ConfNginx_Blacklist_Used_clicked(bool checked);
void on_inLine_ConfNginx_Blacklist_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfNginx_Blacklist_String_returnPressed();
void on_button_ConfNginx_Blacklist_Add_clicked();
void on_list_ConfNginx_Blacklist_List_itemSelectionChanged();
void on_button_ConfNginx_Blacklist_Remove_clicked();
void on_button_ConfNginx_Blacklist_Up_clicked();
void on_button_ConfNginx_Blacklist_Down_clicked();
//// IIS ////
void on_inLine_ConfIis_Path_String_textChanged(const QString &arg1);
void on_inLine_ConfIis_Path_String_returnPressed();
void on_button_ConfIis_Path_Save_clicked();
void on_radio_ConfIis_Format_W3C_toggled(bool checked);
void on_radio_ConfIis_Format_NCSA_toggled(bool checked);
void on_radio_ConfIis_Format_IIS_toggled(bool checked);
void on_inLine_ConfIis_Format_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfIis_Format_String_returnPressed();
void on_button_ConfIis_Format_Save_clicked();
void on_button_ConfIis_Format_Sample_clicked();
void on_button_ConfIis_Format_Help_clicked();
void on_box_ConfIis_Warnlist_Field_currentTextChanged(const QString &arg1);
void on_checkBox_ConfIis_Warnlist_Used_clicked(bool checked);
void on_inLine_ConfIis_Warnlist_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfIis_Warnlist_String_returnPressed();
void on_button_ConfIis_Warnlist_Add_clicked();
void on_list_ConfIis_Warnlist_List_itemSelectionChanged();
void on_button_ConfIis_Warnlist_Remove_clicked();
void on_button_ConfIis_Warnlist_Up_clicked();
void on_button_ConfIis_Warnlist_Down_clicked();
void on_box_ConfIis_Blacklist_Field_currentTextChanged(const QString &arg1);
void on_checkBox_ConfIis_Blacklist_Used_clicked(bool checked);
void on_inLine_ConfIis_Blacklist_String_cursorPositionChanged(int arg1, int arg2);
void on_inLine_ConfIis_Blacklist_String_returnPressed();
void on_button_ConfIis_Blacklist_Add_clicked();
void on_list_ConfIis_Blacklist_List_itemSelectionChanged();
void on_button_ConfIis_Blacklist_Remove_clicked();
void on_button_ConfIis_Blacklist_Up_clicked();
void on_button_ConfIis_Blacklist_Down_clicked();
///////////////
//// MENU ////
//// LANGUAGE ////
void menu_actionEnglish_triggered();
void menu_actionEspanol_triggered();
void menu_actionFrancais_triggered();
void menu_actionItaliano_triggered();
//// TOOLS ////
void menu_actionBlockNote_triggered();
//// UTILITIES ////
void menu_actionInfos_triggered();
void menu_actionCheckUpdates_triggered();
2022-06-20 21:44:58 +02:00
private:
2022-06-21 21:07:06 +02:00
Ui::MainWindow *ui;
// current version of LogDoctor
const float version = 1.0;
// web servers ID constants
const unsigned int APACHE_ID=11, NGINX_ID=12, IIS_ID=13;
// operating system
// 1: linux, 2:windows, 3:mac
#if defined( Q_OS_UNIX )
// Unix-like systems: Linux, BSD and SysV
const unsigned int OS = 1;
#elif defined( Q_OS_WIN )
// Microsoft Windows systems
const unsigned int this->OS = 2;
#elif defined( Q_OS_DARWIN )
// Darwin-based systems: macOS, macOS, iOS, watchOS and tvOS.
const unsigned int this->OS = 3;
#else
#error "System not supported"
#endif
void defineOSspec();
std::string logdoc_path;
////////////////////////
//// CONFIGURATIONS ////
////////////////////////
std::string configs_path;
void readConfigs();
void writeConfigs();
// string to bool and vice versa
const std::unordered_map<std::string, bool> s2b = { {"true",true}, {"false",false} };
const std::unordered_map<bool, std::string> b2s = { {true,"true"}, {false,"false"} };
// language
QTranslator translator;
std::string language = "en";
void updateUiLanguage();
// window geometry
const std::string geometryToString();
void geometryFromString( const std::string& geometry );
// quantoty of informational dialogs to display
int dialogs_level = 2; // 0: essential, 1: usefull, 2: explanatory
// default web server
int default_ws = 11;
// list to string and vice versa
const std::string list2string( const std::vector<std::string>& list, const bool& user_agent=false );
const std::vector<std::string> string2list( const std::string& string, const bool& user_agent=false );
////////////////
//// CHECKS ////
bool initiating = true,
db_ok = true;
2022-07-09 18:16:09 +02:00
void makeInitialChecks();
const bool& checkDataDB();
2022-07-09 18:16:09 +02:00
2022-07-06 21:03:58 +02:00
//////////////////
//// GRAPHICS ////
//////////////////
// remember window position and sizes
bool remember_window = true;
// themes
int window_theme_id = 0,
charts_theme_id = 0;
void updateUiTheme();
const std::vector<QChart::ChartTheme> CHARTS_THEMES = {
QChart::ChartTheme::ChartThemeLight,
QChart::ChartTheme::ChartThemeDark,
QChart::ChartTheme::ChartThemeBrownSand,
QChart::ChartTheme::ChartThemeBlueCerulean
};
// color schemes
2022-06-27 21:55:14 +02:00
std::unordered_map<int, std::unordered_map<std::string, QString>> TB_COLOR_SCHEMES;
std::unordered_map<std::string, QColor> COLORS;
// fonts
2022-06-25 18:48:08 +02:00
std::unordered_map<std::string, QFont> FONTS;
int font_size = 13,
font_size_big = 16,
font_size_small = 10;
// base font families, to build fonts from
QString main_font_family,
alternative_font_family,
script_font_family;
2022-07-06 21:03:58 +02:00
/////////////////////
//// GENERAL USE ////
2022-07-06 21:03:58 +02:00
/////////////////////
// get a printable size, from Bytes to the best fit
const QString printableSize( const int& bytes ),
printableSpeed( const int& bytes, const int& secs ),
printableTime( const int& seconds );
2022-08-12 22:15:14 +02:00
// resolve a path
const std::string resolvePath( const std::string& path );
const std::string basePath( const std::string& path );
2022-06-25 18:48:08 +02:00
///////////////////
//// DATABASES ////
///////////////////
bool db_edited = false;
bool db_do_backup = true;
2022-08-23 00:58:17 +02:00
unsigned db_backups_number = 3;
void backupDatabase();
std::string db_data_path,
2022-07-06 21:03:58 +02:00
db_hashes_path;
// actions when working on a db
bool db_working = false;
void setDbWorkingState( const bool& state );
2022-07-06 21:03:58 +02:00
/////////////////
//// CRAPLOG ////
/////////////////
Craplog craplog;
std::thread craplog_thread;
QTimer *craplog_timer;
2022-07-08 21:40:58 +02:00
std::chrono::system_clock::time_point craplog_timer_start;
2022-07-06 21:03:58 +02:00
std::chrono::system_clock::duration craplog_timer_elapsed;
void craplogStarted();
void craplogFinished();
void checkMakeStats_Makable();
2022-07-06 21:03:58 +02:00
//////////////
//// LOGS ////
// web servers related
bool loading_LogsList = false;
void disableAllButtons_LogFiles_WS(),
enableAllButtons_LogFiles_WS();
// logs list related
bool hide_used_files = false;
bool refreshing_list = false;
void refreshLogsList();
2022-06-25 18:48:08 +02:00
// text browser related
2022-06-27 21:55:14 +02:00
TextBrowser TB;
2022-07-01 21:30:15 +02:00
//////////////////////////
//// LOGS PERFORMANCE ////
void update_MakeStats_labels(),
2022-07-10 18:14:00 +02:00
update_MakeStats_graphs(),
reset_MakeStats_labels();
2022-07-01 21:30:15 +02:00
2022-07-21 21:45:52 +02:00
//////////////////
//// CRAPVIEW ////
//////////////////
Crapview crapview;
/*std::thread crapview_thread;*/
QTimer *crapview_timer = new QTimer();
2022-07-21 21:45:52 +02:00
// refresh dates: query a new collection from the db and apply to the tabs
void refreshStatsDates();
// check if drawing conditions are met
void checkStatsWarnDrawable();
void checkStatsSpeedDrawable();
void checkStatsCountDrawable();
void checkStatsDayDrawable();
void checkStatsRelatDrawable();
// count
QString count_fld;
2022-08-21 21:55:15 +02:00
void startCountDrawing();
void resetStatsCountButtons();
// globals
QString glob_ws;
2022-08-21 21:55:15 +02:00
void globalsButtonClicked();
void resetStatsGlobals();
2022-07-21 21:45:52 +02:00
/////////////////
//// CRAPSET ////
/////////////////
void refreshTextBrowserPreview();
void refreshChartsPreview();
const int getIisLogsModule();
//////////////////
//// CRAPHELP ////
//////////////////
Craphelp* craphelp = new Craphelp();
void showHelp( const std::string& file_name );
////////////////
//// CRAPUP ////
////////////////
Crapup crapup;
//////////////////
//// CRAPNOTE ////
//////////////////
Crapnote* crapnote = new Crapnote();
//////////////////
//// CRAPINFO ////
//////////////////
Crapinfo* crapinfo = new Crapinfo("","","","");
2022-06-20 21:44:58 +02:00
};
2022-06-21 21:07:06 +02:00
#endif // MAINWINDOW_H