Browse Source

Merge branch 'us52-gui-supports-ssl-file' into 'develop'

Resolve "US52: GUI supports SSL file"

Closes #101

See merge request tobias.wach/ccats!110
Serdyukov, Denys 4 years ago
parent
commit
11983014ba

+ 1 - 1
gui/include/climanager.h

@@ -9,7 +9,7 @@ namespace CliManager {
 void setQmlHandler(QMLHandler *q);
 extern bool loggedin;
 
-void init();
+void init(bool useSSL);
 void writeToCli(QString s);
 void readPipeLoop();
 void notificationsLoop();

+ 1 - 0
gui/include/cmdmanager.h

@@ -52,6 +52,7 @@ void handleExtendedStatus(Json::Value root);
 void handleKeyfile(Json::Value root);
 void handleClosekey(Json::Value root);
 void handleDisconnect(Json::Value root);
+void handleConnectionError(Json::Value root);
 } // namespace CmdManager
 
 #endif // CMDMANAGER_H

+ 1 - 3
gui/include/qmlhandler.h

@@ -9,9 +9,6 @@ extern bool _RESTART;
 class QMLHandler : public QObject {
 	Q_OBJECT
 
-private:
-	void fileExists(std::string name);
-
 public:
 	explicit QMLHandler(QObject *parent = 0);
 	void onExit();
@@ -19,6 +16,7 @@ public:
 	void loadSettingsToGUI();
 	QString getIP();
 	void setRestart(bool restart);
+	void setConfigExists(bool exists);
 
 	// C++ -> QML
 signals:

+ 2 - 2
gui/src/Forms/Main/FooterForm.ui.qml

@@ -11,7 +11,7 @@ Page {
     Connections {
         target: _qmlHandler
         onFooterSetStatus: {
-            footerStatusText.text = "Status: " + status
+            footerStatusText.text = status
         }
 
         onFooterSetError: {
@@ -52,7 +52,7 @@ Page {
 
     Timer {
         id: timer
-        interval: 3000
+        interval: 5000
         onTriggered: {
             footerErrorText.text = ""
         }

+ 1 - 1
gui/src/Forms/ServerFiles/ServerFilesFileTemplate.ui.qml

@@ -74,7 +74,7 @@ Item {
             horizontalAlignment: Text.AlignHCenter
             text: fileDecryptableText
             color: (fileDecryptableText
-                    == "decryptable") ? "#3fdf3f" : (fileDecryptableText
+                    == "decryptable") ? "#00ad11" : (fileDecryptableText
                                                      == "undecryptable") ? "#df3f3f" : "#000000"
         }
 

+ 1 - 1
gui/src/Forms/Settings/SettingsForm.ui.qml

@@ -25,7 +25,7 @@ Page {
         onKeyfileStatus: {
             if (success) {
                 settingsKeyStatus.text = "Keyfile: OK"
-                settingsKeyStatus.color = "#3fdf3f"
+                settingsKeyStatus.color = "#00ad11"
             } else {
                 settingsKeyStatus.text = "Keyfile: Error"
                 settingsKeyStatus.color = "#df3f3f"

+ 6 - 4
gui/src/climanager.cpp

@@ -57,8 +57,7 @@ void CliManager::onExit() {
 
 void CliManager::setQmlHandler(QMLHandler *q) { qmlHandler = q; }
 
-void CliManager::init() {
-	// TODO: Remove
+void CliManager::init(bool useSSL) {
 	qInfo() << QString::fromStdString(string("InitCLI with path ") + Config::getValue("CLI-Path"));
 	emit qmlHandler->log(QString::fromStdString(string("InitCLI with path ") + Config::getValue("CLI-Path")));
 	if (!Config::getValue("CLI-Path").size()) {
@@ -78,7 +77,11 @@ void CliManager::init() {
 		// ask kernel to deliver SIGTERM in case the parent dies
 		prctl(PR_SET_PDEATHSIG, SIGTERM);
 
-		execl(Config::getValue("CLI-Path").c_str(), "ccats-cli", "--machine", (char *)NULL);
+		if (useSSL) {
+			execl(Config::getValue("CLI-Path").c_str(), "ccats-cli", "--machine", "--usessl", Config::getValue("SSL-Path").c_str(), (char *)NULL);
+		} else {
+			execl(Config::getValue("CLI-Path").c_str(), "ccats-cli", "--machine", (char *)NULL);
+		}
 
 		exit(1);
 	}
@@ -144,7 +147,6 @@ void CliManager::readPipeLoop() {
 			pollCount = 0;
 			readOffset = 0;
 			if (waitpid(childpid, NULL, WNOHANG)) {
-				// TODO: Remove
 				qInfo() << "CLI has exited/did not launch";
 				emit qmlHandler->log("CLI has exited/did not launch");
 

+ 5 - 0
gui/src/cmdmanager.cpp

@@ -39,6 +39,7 @@ void CmdManager::init() {
 	cmdmap["keyfile"] = &CmdManager::handleKeyfile;
 	cmdmap["closekey"] = &CmdManager::handleClosekey;
 	cmdmap["disconnect"] = &CmdManager::handleDisconnect;
+	cmdmap["connectionerror"] = &CmdManager::handleConnectionError;
 
 	filemap.clear();
 }
@@ -340,3 +341,7 @@ void CmdManager::handleDisconnect(Json::Value root) {
 		CliManager::loggedin = false;
 	}
 }
+
+void CmdManager::handleConnectionError(Json::Value root) {
+	emit qmlHandler->footerSetError("Connection to the server lost. Use << File->Change Server... >> to connect again.");
+}

+ 6 - 2
gui/src/config.cpp

@@ -1,12 +1,11 @@
 #include "config.h"
-#include <QDebug>
 
 namespace Config {
 std::map<std::string, std::string> configuration;
 bool configValid = false;
 bool configInitialized = false;
 std::string configPath = "configGUI.txt";
-std::vector<std::string> configKeys = {"Autofill-IP", "Default-IP", "Autofill-Username", "Default-Username", "CLI-Path", "Keyfile-Path"};
+std::vector<std::string> configKeys = {"Autofill-IP", "Default-IP", "Autofill-Username", "Default-Username", "CLI-Path", "Keyfile-Path", "Use-SSL", "SSL-Path"};
 } // namespace Config
 
 void Config::setupDefaultConfig() {
@@ -17,6 +16,7 @@ void Config::setupDefaultConfig() {
 	setValue(configKeys[1], "0.0.0.0");
 	setValue(configKeys[2], "0");
 	setValue(configKeys[3], "user");
+	setValue(configKeys[6], "0");
 	configInitialized = true;
 	configValid = true;
 }
@@ -33,6 +33,10 @@ bool Config::checkConfig() {
 	if (autofill_user != "0" && autofill_user != "1")
 		return false;
 
+	std::string use_ssl = getValue("Use-SSL");
+	if (use_ssl != "0" && use_ssl != "1")
+		return false;
+
 	return true;
 }
 

+ 1 - 2
gui/src/jsonhandler.cpp

@@ -36,11 +36,10 @@ void JsonHandler::parseJSON(string buffer) {
 	if (cmd.compare("notifications") && cmd.compare("extendedlist") && cmd.compare("extendedstatus") && cmd.compare("status") && cmd.compare("putdata") &&
 	    cmd.compare("getdata")) {
 		emit qmlHandler->log(QString::fromStdString(buffer));
-		// TODO: Remove
 		qInfo() << QString::fromStdString(buffer);
 	}
 
-	if (err.compare("")) {
+	if (err.compare("") && cmd.compare("connectionerror")) {
 		emit qmlHandler->footerSetError(QString::fromStdString(err));
 	}
 

+ 2 - 0
gui/src/main.cpp

@@ -31,6 +31,8 @@ int main(int argc, char *argv[]) {
 	QQmlApplicationEngine engine;
 
 	QMLHandler qmlHandler;
+
+	qmlHandler.setConfigExists(Config::loadFile());
 	CmdManager::setQmlHandler(&qmlHandler);
 	CmdManager::init();
 	CliManager::setQmlHandler(&qmlHandler);

+ 17 - 4
gui/src/qmlhandler.cpp

@@ -24,6 +24,7 @@ using namespace std;
 
 QUrl sendFileUrl = QUrl("");
 bool _RESTART = false;
+bool configExists = false;
 
 QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 
@@ -44,8 +45,6 @@ void QMLHandler::loadSettingsToGUI() {
 
 // Main
 void QMLHandler::onStart(bool startWithCli) {
-	bool configExists = Config::loadFile();
-
 	if (configExists) {
 		// Config exists
 		if (Config::checkConfig()) {
@@ -62,8 +61,20 @@ void QMLHandler::onStart(bool startWithCli) {
 				// Invalid CLI Path
 				emit invalidCliPathPopupOpen();
 			} else if (startWithCli) {
-				// Everything OK, init CLI
-				CliManager::init();
+				// CLI exists, check for SSL
+				if (Config::getValue("Use-SSL") == "1") {
+					if (!ifstream(Config::getValue("SSL-Path"))) {
+						// SSL file does not exist
+						emit ipPopupSetStatus("Invalid SSL-Path. SSL has been disabled.");
+						CliManager::init(false);
+					} else {
+						// All good, start CLI with SSL
+						CliManager::init(true);
+					}
+				} else {
+					// All good, SSL is disabled, start CLI without SSL
+					CliManager::init(false);
+				}
 			}
 		} else {
 			// Config is invalid
@@ -237,3 +248,5 @@ void QMLHandler::onReceivingDequeueFileButton(QString fileName) {
 }
 
 void QMLHandler::setRestart(bool restart) { _RESTART = restart; }
+
+void QMLHandler::setConfigExists(bool exists) { configExists = exists; }