|
@@ -12,12 +12,15 @@
|
|
|
#include <thread>
|
|
|
#include <unistd.h>
|
|
|
|
|
|
+#include "config.h"
|
|
|
#include "qmlhandler.h"
|
|
|
#include <boost/asio.hpp>
|
|
|
#include <boost/filesystem.hpp>
|
|
|
+#include <boost/lexical_cast.hpp>
|
|
|
#include <iostream>
|
|
|
#include <json/json.h>
|
|
|
|
|
|
+using boost::lexical_cast;
|
|
|
using boost::asio::buffer;
|
|
|
|
|
|
using namespace std;
|
|
@@ -38,6 +41,14 @@ QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
|
|
|
|
|
|
void QMLHandler::closeCLI() { _CLI_RUNNING = false; }
|
|
|
|
|
|
+void QMLHandler::loadSettingsToGUI() {
|
|
|
+ int covertMethod = lexical_cast<int>(Config::getValue("Covert-Channel-Method"));
|
|
|
+ bool saveIP = lexical_cast<bool>(Config::getValue("Autofill-IP"));
|
|
|
+ bool saveUsername = lexical_cast<bool>(Config::getValue("Autofill-Username"));
|
|
|
+ QString cliPath = QString::fromStdString(Config::getValue("CLI-Path"));
|
|
|
+ emit loadSettings(covertMethod, saveIP, saveUsername, cliPath);
|
|
|
+}
|
|
|
+
|
|
|
void QMLHandler::reopenCLI(QString ip) {
|
|
|
if (_CLI_RUNNING) {
|
|
|
waitpid(childpid, NULL, 0);
|
|
@@ -61,7 +72,8 @@ void QMLHandler::reopenCLI(QString ip) {
|
|
|
|
|
|
// Set the path to the CLI - pass argument h (help) for now
|
|
|
// TODO: Change hardcoded path
|
|
|
- execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(), "--machine", (char *)NULL);
|
|
|
+ // execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(), "--machine", (char *)NULL);
|
|
|
+ execl(Config::getValue("CLI-Path").c_str(), "ccats-cli", ip.toUtf8().constData(), "--machine", (char *)NULL);
|
|
|
|
|
|
exit(1);
|
|
|
}
|
|
@@ -157,6 +169,7 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
if (root["accept"] == true) {
|
|
|
emit loginSignupPopupClose();
|
|
|
write(outpipefd[1], "list\n", strlen("list\n"));
|
|
|
+ loadSettingsToGUI();
|
|
|
} else {
|
|
|
emit loginSetStatus(root["error"].asString().c_str());
|
|
|
reopenCLI(_IP);
|
|
@@ -192,7 +205,7 @@ void QMLHandler::handleJSON(string buffer) {
|
|
|
} else {
|
|
|
string fileName = root["file"].asString();
|
|
|
// TODO: Only do this in getdata when remaining is 0 (when the file is fully downloaded) - maybe set text to "downloading.." in between
|
|
|
- emit receivingDisableDownloadButton(QString::fromStdString(string(fileName)));
|
|
|
+ emit receivingDisableDownloadButton(QString::fromStdString(fileName));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -274,6 +287,60 @@ void QMLHandler::readPipeLoop() {
|
|
|
|
|
|
// ### QML Handlers ###
|
|
|
|
|
|
+void QMLHandler::onStart() {
|
|
|
+ bool configExists = Config::loadFile();
|
|
|
+
|
|
|
+ if (configExists == true) {
|
|
|
+ // Config exists
|
|
|
+ if (Config::checkConfig() == true) {
|
|
|
+ // Config is valid
|
|
|
+ if (!boost::filesystem::is_regular_file(Config::getValue("CLI-Path")) ||
|
|
|
+ boost::filesystem::path(Config::getValue("CLI-Path")).filename().compare("ccats-cli")) {
|
|
|
+ // Invalid CLI Path
|
|
|
+ emit invalidCliPathPopupOpen();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Config::getValue("Autofill-IP") == "1") {
|
|
|
+ emit ipPopupSetIP(QString::fromStdString(Config::getValue("Default-IP")));
|
|
|
+ emit ipPopupCheckSaveCheckbox();
|
|
|
+ }
|
|
|
+ if (Config::getValue("Autofill-Username") == "1") {
|
|
|
+ emit loginSetUsername(QString::fromStdString(Config::getValue("Default-Username")));
|
|
|
+ emit loginSignupCheckSaveCheckbox();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // Config is invalid
|
|
|
+ emit invalidConfigPopupOpen();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // Config doesn't exist
|
|
|
+ Config::setupDefaultConfig();
|
|
|
+ emit noConfigFoundPopupOpen();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// No Config Found Popup
|
|
|
+void QMLHandler::onNoConfigFoundPopupContinueButton(QString cli_path) {
|
|
|
+ Config::setValue("CLI-Path", cli_path.toUtf8().constData());
|
|
|
+ Config::saveFile();
|
|
|
+}
|
|
|
+
|
|
|
+// Invalid Cli Path Popup
|
|
|
+void QMLHandler::onInvalidCliPathPopupContinueButton(QString cli_path) {
|
|
|
+ Config::setValue("CLI-Path", cli_path.toUtf8().constData());
|
|
|
+ Config::saveFile();
|
|
|
+}
|
|
|
+
|
|
|
+void QMLHandler::onInvalidCliPathPopupQuitButton() { emit closeWindow(); }
|
|
|
+
|
|
|
+// Invalid Config Popup
|
|
|
+void QMLHandler::onInvalidConfigPopupQuitButton() { emit closeWindow(); }
|
|
|
+
|
|
|
+void QMLHandler::onInvalidConfigPopupCreateDefaultButton() {
|
|
|
+ Config::setupDefaultConfig();
|
|
|
+ emit noConfigFoundPopupOpen();
|
|
|
+}
|
|
|
+
|
|
|
// Sending
|
|
|
void QMLHandler::onSendingSelectFileButton(QUrl url) {
|
|
|
sendFileUrl = url.toLocalFile();
|
|
@@ -313,21 +380,53 @@ void QMLHandler::onMessagesSendButton(QString msg) { emit message(msg); }
|
|
|
// Settings
|
|
|
void QMLHandler::onSettingsDeleteMeButton() { write(outpipefd[1], "deleteme\n", strlen("deleteme\n")); }
|
|
|
|
|
|
+void QMLHandler::onSettingsRevertChangesButton() {
|
|
|
+ loadSettingsToGUI();
|
|
|
+ emit log("Settings changes reverted.");
|
|
|
+}
|
|
|
+
|
|
|
+void QMLHandler::onSettingsResetButton() {
|
|
|
+ string cli_path = Config::getValue("CLI-Path");
|
|
|
+ Config::setupDefaultConfig();
|
|
|
+ Config::setValue("CLI-Path", cli_path);
|
|
|
+ loadSettingsToGUI();
|
|
|
+ emit log("Settings resetted to default.");
|
|
|
+}
|
|
|
+
|
|
|
+void QMLHandler::onSettingsSaveButton(int covertMethod, bool saveIP, bool saveUsername, QString cliPath) {
|
|
|
+ Config::setValue("Covert-Channel-Method", lexical_cast<string>(covertMethod));
|
|
|
+ Config::setValue("Autofill-IP", lexical_cast<string>(saveIP));
|
|
|
+ Config::setValue("Autofill-Username", lexical_cast<string>(saveUsername));
|
|
|
+ Config::setValue("CLI-Path", cliPath.toUtf8().constData());
|
|
|
+ Config::saveFile();
|
|
|
+ emit log("Settings saved.");
|
|
|
+}
|
|
|
+
|
|
|
// Ip Popup
|
|
|
-void QMLHandler::onIpPopupConnectButton(QString ip) {
|
|
|
+void QMLHandler::onIpPopupConnectButton(QString ip, bool saveAsDefault) {
|
|
|
reopenCLI(ip);
|
|
|
emit ipPopupDisableConnectButton();
|
|
|
+ if (saveAsDefault) {
|
|
|
+ Config::setValue("Default-IP", ip.toUtf8().constData());
|
|
|
+ Config::setValue("Autofill-IP", "1");
|
|
|
+ Config::saveFile();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Login
|
|
|
-void QMLHandler::onLoginLoginButton(QString username, QString password) {
|
|
|
+void QMLHandler::onLoginLoginButton(QString username, QString password, bool saveAsDefault) {
|
|
|
QString command = "login " + username + " " + password + "\n";
|
|
|
write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
|
|
|
emit loginDisableLoginButton();
|
|
|
+ if (saveAsDefault) {
|
|
|
+ Config::setValue("Default-Username", username.toUtf8().constData());
|
|
|
+ Config::setValue("Autofill-Username", "1");
|
|
|
+ Config::saveFile();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Signup
|
|
|
-void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne, QString passwordTwo) {
|
|
|
+void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne, QString passwordTwo, bool saveAsDefault) {
|
|
|
if (QString::compare(passwordOne, passwordTwo, Qt::CaseSensitive)) {
|
|
|
emit signupSetStatus("Passwords don't match");
|
|
|
return;
|
|
@@ -335,6 +434,11 @@ void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne, Q
|
|
|
QString command = "signup " + username + " " + passwordOne + "\n";
|
|
|
write(outpipefd[1], command.toUtf8().constData(), strlen(command.toUtf8().constData()));
|
|
|
emit signupDisableRegisterButton();
|
|
|
+ if (saveAsDefault) {
|
|
|
+ Config::setValue("Default-Username", username.toUtf8().constData());
|
|
|
+ Config::setValue("Autofill-Username", "1");
|
|
|
+ Config::saveFile();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Footer
|