ソースを参照

Merge branch 'gui' into 'master'

US03: Base GUI

See merge request tobias.wach/ccats!3
Pflanzer, Jonas 5 年 前
コミット
1c0bd11f89
6 ファイル変更172 行追加0 行削除
  1. 17 0
      gui/CMakeLists.txt
  2. 73 0
      gui/src/main.cpp
  3. 40 0
      gui/src/main.qml
  4. 5 0
      gui/src/qml.qrc
  5. 17 0
      gui/src/qmlhandler.cpp
  6. 20 0
      gui/src/qmlhandler.h

+ 17 - 0
gui/CMakeLists.txt

@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+project(CCats-GUI LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+
+find_package(Threads)
+find_package(Boost 1.67 REQUIRED COMPONENTS system)
+find_package(Qt5 COMPONENTS Core Quick REQUIRED)
+
+add_executable(${PROJECT_NAME} src/main.cpp src/qmlhandler.cpp src/qml.qrc)
+
+target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} Qt5::Core Qt5::Quick)
+
+

+ 73 - 0
gui/src/main.cpp

@@ -0,0 +1,73 @@
+#include <QGuiApplication>
+#include <QObject>
+#include <QQmlApplicationEngine>
+#include <csignal>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "qmlhandler.h"
+
+using namespace std;
+int inpipefd[2];
+int outpipefd[2];
+char buf[1024];
+
+int main(int argc, char *argv[]) {
+  pid_t pid = 0;
+  char msg[256];
+  int status;
+
+  pipe(inpipefd);
+  pipe(outpipefd);
+  pid = fork();
+  if (pid == 0) {
+    // Child
+    dup2(outpipefd[0], STDIN_FILENO);
+    dup2(inpipefd[1], STDOUT_FILENO);
+    dup2(inpipefd[1], STDERR_FILENO);
+
+    // ask kernel to deliver SIGTERM in case the parent dies
+    prctl(PR_SET_PDEATHSIG, SIGTERM);
+
+    // Set the path to the CLI - pass argument h (help) for now
+    // TODO: Change hardcoded path
+    execl("../../cli/build/ccats-cli", "ccats-cli", "c", "127.0.0.1",
+          (char *)NULL);
+
+    exit(1);
+  }
+
+  close(outpipefd[0]);
+  close(inpipefd[1]);
+
+  // ########## GUI CODE ##########
+
+  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+
+  QGuiApplication app(argc, argv);
+
+  QQmlApplicationEngine engine;
+  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+
+  if (engine.rootObjects().isEmpty())
+    return -1;
+
+  QMLHandler qmlHandler;
+
+  QObject *statusButton =
+      engine.rootObjects().first()->findChild<QObject *>("getstatusbutton");
+
+  QObject::connect(statusButton, SIGNAL(clicked()), &qmlHandler,
+                   SLOT(onGetStatusClick()));
+
+  QObject::connect(&qmlHandler, SIGNAL(setStatusMessage(QVariant)),
+                   engine.rootObjects().first(),
+                   SLOT(setStatusMessage(QVariant)));
+
+  return app.exec();
+}

+ 40 - 0
gui/src/main.qml

@@ -0,0 +1,40 @@
+import QtQuick 2.9
+import QtQuick.Window 2.2
+import QtQuick.Controls 1.5
+
+Window {
+    visible: true
+    width: 1280
+    height: 720
+    color: "#191919"
+    title: qsTr("Covert Channel | Control Panel")
+
+    function setStatusMessage(text) {
+        statusmessage.text = text
+    }
+
+    Text {
+        id: statusmessage
+        objectName: "statusmessage"
+        x: 210
+        y: 583
+        width: 861
+        height: 109
+        color: "#ffffff"
+        text: qsTr("")
+        font.family: "Courier"
+        horizontalAlignment: Text.AlignHCenter
+        fontSizeMode: Text.FixedSize
+        font.pixelSize: 59
+    }
+
+    Button {
+        id: getstatusbutton
+        objectName: "getstatusbutton"
+        x: 504
+        y: 183
+        width: 273
+        height: 73
+        text: qsTr("Get Daemon Status")
+    }
+}

+ 5 - 0
gui/src/qml.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>main.qml</file>
+    </qresource>
+</RCC>

+ 17 - 0
gui/src/qmlhandler.cpp

@@ -0,0 +1,17 @@
+#include "qmlhandler.h"
+
+#include <unistd.h>
+
+extern int inpipefd[2];
+extern int outpipefd[2];
+extern char buf[1024];
+
+QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
+
+void QMLHandler::onGetStatusClick() {
+  read(inpipefd[0], buf, 1024);
+  buf[1023] = 0;
+  buf[strlen(buf)] = 0;
+  qInfo() << buf;
+  emit setStatusMessage("Check Terminal plz");
+}

+ 20 - 0
gui/src/qmlhandler.h

@@ -0,0 +1,20 @@
+#ifndef CCATS_GUI_QMLHANDLER_H
+#define CCATS_GUI_QMLHANDLER_H
+
+#include <QDebug>
+#include <QObject>
+
+class QMLHandler : public QObject {
+  Q_OBJECT
+
+public:
+  explicit QMLHandler(QObject *parent = 0);
+
+signals:
+  void setStatusMessage(QVariant text);
+
+public slots:
+  void onGetStatusClick();
+};
+
+#endif // CCATS_GUI_QMLHANDLER_H