Browse Source

Implemented US21.3 + Fixed GUI Offset Bug

Cyamond 5 years ago
parent
commit
4421a6d6e5
7 changed files with 46 additions and 27 deletions
  1. 1 1
      cli/src/cmdman.cpp
  2. 0 1
      gui/src/LoginForm.ui.qml
  3. 12 3
      gui/src/SettingsForm.ui.qml
  4. 10 0
      gui/src/main.cpp
  5. 0 7
      gui/src/main.qml
  6. 19 13
      gui/src/qmlhandler.cpp
  7. 4 2
      gui/src/qmlhandler.h

+ 1 - 1
cli/src/cmdman.cpp

@@ -571,7 +571,7 @@ CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
       output["names"] = arr;
       fileman.closeList();
     } else {
-      retval.type = print | send;
+      retval.type = send;
       retval.nextcommand = "listdata";
     }
   }

+ 0 - 1
gui/src/LoginForm.ui.qml

@@ -44,7 +44,6 @@ Page {
             Layout.alignment: Qt.AlignCenter
             id: loginPasswordInput
             selectByMouse: true
-            focus: true
             text: qsTr("")
             placeholderText: "Password"
             horizontalAlignment: Text.AlignHCenter

+ 12 - 3
gui/src/SettingsForm.ui.qml

@@ -4,9 +4,17 @@ import QtQuick.Controls 2.5
 Page {
     width: 1280
     height: 470
+    id: page
 
     font.capitalization: Font.MixedCase
 
+    Connections {
+        target: _qmlHandler
+        onCloseWindow: {
+            window.close()
+        }
+    }
+
     ComboBox {
         id: settingsCovertMethodPicker
         x: 328
@@ -37,17 +45,18 @@ Page {
     }
 
     Button {
-        id: settingsSwitchServerButton
+        id: settingsDeleteMeButton
         x: 549
         y: 343
         width: 182
         height: 71
-        text: qsTr("Switch Server")
+        text: qsTr("Delete Me")
         font.pointSize: 15
         // @disable-check M223
         onClicked: {
             // @disable-check M222
-            _qmlHandler.onSettingsSwitchServerButton()
+            _qmlHandler.onSettingsDeleteMeButton()
+
         }
     }
 

+ 10 - 0
gui/src/main.cpp

@@ -47,5 +47,15 @@ int main(int argc, char *argv[]) {
   // server now
   qmlHandler.onExit();
 
+  if (_RESTART) {
+    // DO SHIT
+    pid_t pid = 0;
+    pid = fork();
+    if (pid == 0) {
+      execl("./CCats-GUI", "CCats-GUI", (char *)NULL);
+      exit(1);
+    }
+  }
+
   return ret;
 }

+ 0 - 7
gui/src/main.qml

@@ -8,13 +8,6 @@ ApplicationWindow {
     height: 720
     title: qsTr("Covert Channel - Control Panel")
 
-    Connections {
-        target: _qmlHandler
-        onSettingsOpenSwitchServerPopup: {
-            switchDialog.open()
-        }
-    }
-
     SwipeView {
         id: swipeView
         anchors.fill: parent

+ 19 - 13
gui/src/qmlhandler.cpp

@@ -24,6 +24,7 @@ char buf[1025];
 QUrl sendFileUrl = QUrl("");
 QString _IP = "";
 bool _CLI_RUNNING = false;
+bool _RESTART = false;
 
 bool programActive = true;
 
@@ -197,6 +198,13 @@ void QMLHandler::handleJSON(string buffer) {
   else if (!cmd.compare("getdata")) {
     // TODO: Show speed and handle Error
   }
+
+  else if (!cmd.compare("deleteme")) {
+    if (root["accept"] == true) {
+      _RESTART = true;
+      emit closeWindow();
+    }
+  }
 }
 
 // This method is a loop which runs in a seperate thread.
@@ -209,10 +217,11 @@ void QMLHandler::readPipeLoop() {
   struct pollfd inPipeStatus;
   inPipeStatus.fd = inpipefd[0];
   inPipeStatus.events = POLLIN;
-  std::vector<std::string> inputs;
+  vector<string> inputs;
+  string pipeInput;
 
   while (programActive) {
-    inputs = std::vector<std::string>();
+    inputs = vector<string>();
     poll(&inPipeStatus, 1, 100);
 
     if (inPipeStatus.revents & POLLIN) {
@@ -223,26 +232,23 @@ void QMLHandler::readPipeLoop() {
       pollCount++;
     }
 
-    if (pollCount > 9 && buf[0]) {
-      buf[1024] = 0;
-      buf[strlen(buf)] = 0;
-      inputs = tokenizeByNewlines(string(buf));
+    if (pollCount > 9 && (readOffset || pipeInput.size())) {
+      pipeInput.append(buf);
+      inputs = tokenizeByNewlines(pipeInput);
       for (string s : inputs) {
-        //~ string cleanBuffer = buf + strcspn(buf, "\n") + 1;
-        //~ string receivedData = cleanBuffer.substr(0, cleanBuffer.size() - 1);
-
         emit log(QString::fromStdString(s));
         qInfo() << QString::fromStdString(s);
         handleJSON(s);
       }
-      memset(buf, 0, 1024);
+      pipeInput = string();
+      memset(buf, 0, 1025);
       pollCount = 0;
       readOffset = 0;
     }
 
     // Fixme
     if (readOffset >= 1024) {
-      qInfo() << "Fixme: QMLHandler::readPipeLoop() readOffset too high!!!";
+      pipeInput.append(buf);
       readOffset = 0;
       pollCount = 0;
       memset(buf, 0, 1025);
@@ -288,8 +294,8 @@ void QMLHandler::onReceivingGetFileButton(QString fileName) {
 void QMLHandler::onMessagesSendButton(QString msg) { emit message(msg); }
 
 // Settings
-void QMLHandler::onSettingsSwitchServerButton() {
-  emit settingsOpenSwitchServerPopup();
+void QMLHandler::onSettingsDeleteMeButton() {
+  write(outpipefd[1], "deleteme\n", strlen("deleteme\n"));
 }
 
 // Ip Popup

+ 4 - 2
gui/src/qmlhandler.h

@@ -7,6 +7,8 @@
 #include <QUrl>
 #include <string>
 
+extern bool _RESTART;
+
 class QMLHandler : public QObject {
   Q_OBJECT
 
@@ -36,7 +38,7 @@ signals:
   void message(QString msg);
 
   // Settings
-  void settingsOpenSwitchServerPopup();
+  void closeWindow();
 
   // Ip Popup
   void ipPopupSetStatus(QString status);
@@ -73,7 +75,7 @@ public slots:
   void onMessagesSendButton(QString msg);
 
   // Settings
-  void onSettingsSwitchServerButton();
+  void onSettingsDeleteMeButton();
 
   // Ip Popup
   void onIpPopupConnectButton(QString ip);