123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #include <QDebug>
- #include <QGuiApplication>
- #include <csignal>
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <poll.h>
- #include <string>
- #include <sys/prctl.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #include <thread>
- #include <unistd.h>
- #include "../include/climanager.h"
- #include "../include/config.h"
- #include "../include/jsonhandler.h"
- #include "../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;
- QUrl sendFileUrl = QUrl("");
- bool _RESTART = false;
- QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
- 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);
- }
- // ### 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();
- }
- CliManager::init();
- }
- // 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();
- emit log("File Selected: " + sendFileUrl.toString());
- emit sendingSetFileUrlText("Selected File: " + sendFileUrl.toString());
- emit sendingEnableSendButton();
- }
- void QMLHandler::onSendingSendFileButton() {
- QString command = "put " + sendFileUrl.toString();
- CliManager::writeToCli(command);
- }
- void QMLHandler::onSendingClearSelectionButton() {
- sendFileUrl = QUrl("");
- emit log("Cleared Selection");
- emit sendingSetFileUrlText("Selected File: None");
- emit sendingDisableSendButton();
- }
- // Receiving
- void QMLHandler::onReceivingListFilesButton() { CliManager::writeToCli("extendedlist"); }
- void QMLHandler::onReceivingDownloadFileButton(QString fileName) {
- QString command = "get " + fileName;
- CliManager::writeToCli(command);
- }
- void QMLHandler::onReceivingConfirmDeleteFileButton(QString fileName) {
- QString command = "deletefile " + fileName;
- CliManager::writeToCli(command);
- }
- // Messages
- void QMLHandler::onMessagesSendButton(QString msg) { emit message(msg); }
- // Settings
- void QMLHandler::onSettingsDeleteMeButton(QString password) {
- QString command = "deleteme " + password;
- CliManager::writeToCli(command);
- }
- 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, bool saveAsDefault) {
- QString command = "connect " + ip;
- CliManager::writeToCli(command);
- 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, bool saveAsDefault) {
- QString command = "login " + username + " " + password;
- CliManager::writeToCli(command);
- 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, bool saveAsDefault) {
- if (QString::compare(passwordOne, passwordTwo, Qt::CaseSensitive)) {
- emit signupSetStatus("Passwords don't match");
- return;
- }
- QString command = "signup " + username + " " + passwordOne;
- CliManager::writeToCli(command);
- emit signupDisableRegisterButton();
- if (saveAsDefault) {
- Config::setValue("Default-Username", username.toUtf8().constData());
- Config::setValue("Autofill-Username", "1");
- Config::saveFile();
- }
- }
- // Footer
- void QMLHandler::onFooterGetStatusButton() { CliManager::writeToCli("status"); }
- // Notifications
- void QMLHandler::onDismissNotificationButton(int index) { emit dismissNotification(index); }
- // Queueing
- void QMLHandler::onReceivingQueueFileButton(QString fileName) {
- QString command = "queue " + fileName;
- CliManager::writeToCli(command);
- }
- void QMLHandler::onReceivingDequeueFileButton(QString fileName) {
- QString command = "dequeue " + fileName;
- CliManager::writeToCli(command);
- }
- void QMLHandler::setRestart(bool restart) { _RESTART = restart; }
|