diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0d6a42541eb84f45aafb8931b383488769efae18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# ignore everything +* + +# allow these: +# git stuff +!.gitignore + +# c/c++ stuff +!*.hpp +!*.cpp +!*.h +!*.c + +# qt stuff +!*.pro +!*.qrc + +# resources +!*.hqx +!*.ico +!*.gif +!*.svg +!*.html + +# apply to subdirectories +!*/ + +# but ignore bin +bin/ \ No newline at end of file diff --git a/include/NetCheckerWindow.hpp b/include/NetCheckerWindow.hpp index 422051ff40795756af34b15c01b9db0f3e69b538..393e46bc73f9aac7072057fb673047d4af1bcf3a 100644 --- a/include/NetCheckerWindow.hpp +++ b/include/NetCheckerWindow.hpp @@ -57,6 +57,7 @@ public slots: void incrementTime(); void finishAction(); void updateInfos(int, const QString); + void show(); private: void initStackedWindow(); void initWelcomePage(); diff --git a/include/Privileges.hpp b/include/Privileges.hpp index c341ea0e3db56969e604eb8bccd4e95732a5eb6d..1c6267be9725317a833af2a05dec069f7387034a 100644 --- a/include/Privileges.hpp +++ b/include/Privileges.hpp @@ -4,11 +4,12 @@ #ifndef PRIVILEGES_HPP #define PRIVILEGES_HPP -class Privileges { +namespace Privileges { -public: - static bool enoughPrivileges(const QString&, const QString&); - static bool isRoot(); -}; +bool Check(const QString&, const QString&); + +bool IsRoot(); + +} #endif // PRIVILEGES_HPP diff --git a/include/Translation.hpp b/include/Translation.hpp index 75df329265856272cb22accbefb4a33f2b5b68d3..e9badd5e5d4d96f909c529075fc1a123321d0f6f 100644 --- a/include/Translation.hpp +++ b/include/Translation.hpp @@ -15,7 +15,7 @@ extern QString TXT_LOG_GROUP[]; extern QString TXT_CLIPB_BTN[]; extern QString TXT_SAVE_BTN[]; extern QString TXT_SAVE_DIALOG[]; -extern QString TXT_ROOT_MSG_TITLE_WIN; -extern QString TXT_ROOT_MSG_WIN; +extern QString TXT_ROOT_MSG_TITLE_WIN[]; +extern QString TXT_ROOT_MSG_WIN[]; #endif diff --git a/main.cpp b/main.cpp index 6bcddce962e9c2ad6e9c15f5c5dfd0a600f16fa7..c760e1028f770206b41b1248b83c495bbb0cfe9d 100644 --- a/main.cpp +++ b/main.cpp @@ -1,16 +1,12 @@ #include <QApplication> #include <include/NetCheckerWindow.hpp> -#include <include/Privileges.hpp> -#include <include/Translation.hpp> int main(int argc, char *argv[]) { QApplication app(argc, argv); NetCheckerWindow ncw; - if (Privileges::enoughPrivileges(TXT_ROOT_MSG_TITLE_WIN, TXT_ROOT_MSG_WIN) == true){ - ncw.show(); - return app.exec(); - } - return 1; + + ncw.show(); + return app.exec(); } diff --git a/netchecker.pro.user b/netchecker.pro.user index 64adda700d410319307128524bf1376b02f35898..8e03a5b0b11a1e25fb0a16c5679567f66c9a4bc0 100644 --- a/netchecker.pro.user +++ b/netchecker.pro.user @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 3.4.2, 2015-09-21T17:36:13. --> +<!-- Written by QtCreator 3.6.0, 2016-02-07T15:29:27. --> <qtcreator> <data> <variable>EnvironmentId</variable> - <value type="QByteArray">{8a982672-9a47-4b9c-b231-1954ba5d7e5c}</value> + <value type="QByteArray">{1eb0af89-fa91-4fbf-8709-87fdc4066d8f}</value> </data> <data> <variable>ProjectExplorer.Project.ActiveTarget</variable> @@ -58,8 +58,8 @@ <data> <variable>ProjectExplorer.Project.Target.0</variable> <valuemap type="QVariantMap"> - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.5.0 MinGW 32bit</value> - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.5.0 MinGW 32bit</value> + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.5.1 MinGW 32bit</value> + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.5.1 MinGW 32bit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.55.win32_mingw492_kit</value> <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> @@ -73,7 +73,6 @@ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value> - <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value> <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value> <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value> @@ -128,7 +127,6 @@ <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value> - <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value> <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value> <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value> @@ -190,6 +188,10 @@ <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value> <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/> <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0"> + <value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value> + <value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value> + <value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value> + <value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value> <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/> <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value> <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value> @@ -227,8 +229,9 @@ <value type="int" key="PE.EnvironmentAspect.Base">2</value> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">netchecker</value> - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> - <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/bebe/Documents/QtProjects/NetChecker/netchecker.pro</value> + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">netchecker2</value> + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/BME/kszk/NetChecker/netchecker.pro</value> + <value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">netchecker.pro</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> diff --git a/src/Diagnostic.cpp b/src/Diagnostic.cpp index 8d4bd474d54610c24c4181a3488e5502075e0c7e..7740f0b898bc2eacbeec74224e001166dfb442a6 100644 --- a/src/Diagnostic.cpp +++ b/src/Diagnostic.cpp @@ -23,14 +23,16 @@ void Diagnostic::onStarted(){ } Diagnostic::Diagnostic() - : func_vec({ + : + func_vec({ &Diagnostic::getOsInfo, &Diagnostic::getInterfaceInfo, &Diagnostic::getRoutingInfo, &Diagnostic::getDGPingOutput, &Diagnostic::getODPingOutput, &Diagnostic::getDNSLookup - }), tab(2, ' ') + }), + tab(2, ' ') { INIT_GLOBALS(); } diff --git a/src/NetCheckerWindow.cpp b/src/NetCheckerWindow.cpp index 181c99d472532c4111475dcee764160dc3a717b4..5caaf4223d3e7bff1d941138fe0bb6abe2293dd2 100644 --- a/src/NetCheckerWindow.cpp +++ b/src/NetCheckerWindow.cpp @@ -246,7 +246,7 @@ void NetCheckerWindow::nextPage(){ /* thread start -> diagnostic start */ QObject::connect(diag_thread, SIGNAL(started()), diag_obj, SLOT(onStarted())); /* update -> window */ - QObject::connect(diag_obj, SIGNAL(Update(int,QString)), this, SLOT(updateInfos(int,QString))); + QObject::connect(diag_obj, SIGNAL(Update(int, QString)), this, SLOT(updateInfos(int, QString))); /* quit diagnostic -> quit thread */ QObject::connect(diag_obj, SIGNAL(Quit()), diag_thread, SLOT(quit())); /* thread finished -> window's finish action */ @@ -328,3 +328,9 @@ void NetCheckerWindow::incrementTime(){ } } } + +void NetCheckerWindow::show(){ + if (Privileges::Check(TXT_ROOT_MSG_TITLE_WIN[0], TXT_ROOT_MSG_WIN[0]) == true){ + QDialog::show(); + } +} diff --git a/src/Privileges.cpp b/src/Privileges.cpp index 02c9e514157ccf1aca2b8174c72a11bec32ece30..802a9cef7c84ea4c80c47f5ca119455802c64428 100644 --- a/src/Privileges.cpp +++ b/src/Privileges.cpp @@ -6,11 +6,8 @@ #include <include/ProcessHandler.hpp> #include <include/Privileges.hpp> -#ifndef PRIVILEGES_CPP -#define PRIVILEGES_CPP - -bool Privileges::enoughPrivileges(const QString &title, const QString &msg){ - if (Privileges::isRoot() == false){ +bool Privileges::Check(const QString &title, const QString &msg){ + if (Privileges::IsRoot() == false){ QMessageBox::critical(nullptr, title, msg, QMessageBox::Ok, QMessageBox::NoButton); return false; } @@ -18,32 +15,37 @@ bool Privileges::enoughPrivileges(const QString &title, const QString &msg){ } #if defined(Q_OS_WIN) - #include <windows.h> - #define WIN32_LEAN_AND_MEAN - #define WIN32_EXTRA_LEAN - bool Privileges::isRoot(){ - BOOL fRet = FALSE; - HANDLE hToken = NULL; - if( OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)){ - TOKEN_ELEVATION Elevation; - DWORD cbSize = sizeof(TOKEN_ELEVATION); - if(GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation),&cbSize)){ - fRet = Elevation.TokenIsElevated; - } - } - if(hToken){ - CloseHandle(hToken); - } - return fRet; - } + + #include <windows.h> + #define WIN32_LEAN_AND_MEAN + #define WIN32_EXTRA_LEAN + + bool Privileges::IsRoot(){ + BOOL fRet = FALSE; + HANDLE hToken = NULL; + if( OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)){ + TOKEN_ELEVATION Elevation; + DWORD cbSize = sizeof(TOKEN_ELEVATION); + if(GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation),&cbSize)){ + fRet = Elevation.TokenIsElevated; + } + } + if(hToken){ + CloseHandle(hToken); + } + return fRet; + } + #elif (defined(Q_OS_LINUX) || defined(Q_OS_OSX)) - #include <unistd.h> - bool Privileges::isRoot(){ - return !(getuid() && geteuid()); - } + + #include <unistd.h> + + bool Privileges::IsRoot(){ + return !(getuid() && geteuid()); + } + #else - #error "This OS is not supported yet!" -#endif -#endif // PRIVILEGES_CPP + #error "This OS is not supported yet!" +#endif diff --git a/src/ProcessHandler.cpp b/src/ProcessHandler.cpp index c7122ac298be32e8dfea3408eb252d166d5ae692..5adb0f8c2513c5670150f754e09a8a0d781631b6 100644 --- a/src/ProcessHandler.cpp +++ b/src/ProcessHandler.cpp @@ -11,13 +11,11 @@ ProcessHandler::ProcessHandler(QProcess::OpenMode mode): QProcess() { setOpenMode(mode); } QString ProcessHandler::exec(QString commands){ - start(commands); + start(commands); if (!waitForFinished()){ return tr("Error occured. Command was: %1\n").arg(commands); } - QByteArray ba = readAllStandardOutput(); - return ba; + return readAllStandardOutput(); } #endif - diff --git a/src/Translation.cpp b/src/Translation.cpp index c90820ac26622c856fcb6fd562a4644262185580..4ea85f0e442d40002336d8b87383efa75725f05c 100644 --- a/src/Translation.cpp +++ b/src/Translation.cpp @@ -1,18 +1,19 @@ #include <QString> #include <include/Translation.hpp> -QString TXT_APP_TITLE[] = { "NetChecker", "NetChecker" }; -QString README_URL[] = { ":/res/readme_en.html", ":/res/readme_hu.html" }; -QString TXT_NEXT_BTN[] = { "Next", "Tovább" }; -QString TXT_DIAG_GROUP[] = { "Running diagnostics", "Diagnosztika futtatása" }; -QString TXT_EST_TIME[] = { "Estimated time", "Várható befejezés" }; -QString TXT_ALMOST_END[] = { "Please be patient...", "Kérem várjon türelemmel..." }; -QString TXT_FINISHED[] = { "Finished.", "Művelet befejeződött." }; -QString TXT_LOG_GROUP[] = { "Log", "Napló" }; -QString TXT_CLIPB_BTN[] = { "Copy to clipboard", "Másolás vágólapra" }; -QString TXT_SAVE_BTN[] = { "Save to file...", "Mentés fájlba..." }; -QString TXT_SAVE_DIALOG[] = { "Save to...", "Mentés helye..." }; -QString TXT_ROOT_MSG_TITLE_WIN ={ "Error" }; -QString TXT_ROOT_MSG_WIN = { - "Az alkalmazás futtatásához Rendszergazdai jogosultság szükséges!\n\nYou must have Administrator privileges to use this tool!" +QString TXT_APP_TITLE[] = { "NetChecker", "NetChecker" }; +QString README_URL[] = { ":/res/readme_en.html", ":/res/readme_hu.html" }; +QString TXT_NEXT_BTN[] = { "Next", "Tovább" }; +QString TXT_DIAG_GROUP[] = { "Running diagnostics", "Diagnosztika futtatása" }; +QString TXT_EST_TIME[] = { "Estimated time", "Várható befejezés" }; +QString TXT_ALMOST_END[] = { "Please be patient...", "Kérem várjon türelemmel..." }; +QString TXT_FINISHED[] = { "Finished.", "Művelet befejeződött." }; +QString TXT_LOG_GROUP[] = { "Log", "Napló" }; +QString TXT_CLIPB_BTN[] = { "Copy to clipboard", "Másolás vágólapra" }; +QString TXT_SAVE_BTN[] = { "Save to file...", "Mentés fájlba..." }; +QString TXT_SAVE_DIALOG[] = { "Save to...", "Mentés helye..." }; +QString TXT_ROOT_MSG_TITLE_WIN[] = { "Error" }; +QString TXT_ROOT_MSG_WIN[] = { + "Az alkalmazás futtatásához Rendszergazdai jogosultság szükséges!" "\n\n" + "You must have Administrator privileges to use this tool!" };