diff --git a/gui/GUI_HELP_POPUP.py b/gui/GUI_HELP_POPUP.py index 5f49633..8b74ea0 100644 --- a/gui/GUI_HELP_POPUP.py +++ b/gui/GUI_HELP_POPUP.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'C:/Users/admin/Documents/GitHub/SerialKiller/ui_files/serial_killer_help_popup.ui' +# Form implementation generated from reading ui file '/home/patrick/careweather/serialkiller//ui_files/serial_killer_help_popup.ui' # -# Created by: PyQt5 UI code generator 5.15.6 +# Created by: PyQt5 UI code generator 5.15.10 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. diff --git a/gui/GUI_LOG_POPUP.py b/gui/GUI_LOG_POPUP.py index 355bcf9..af16107 100644 --- a/gui/GUI_LOG_POPUP.py +++ b/gui/GUI_LOG_POPUP.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'C:/Users/admin/Documents/GitHub/SerialKiller/ui_files/serial_killer_log_popup.ui' +# Form implementation generated from reading ui file '/home/patrick/careweather/serialkiller//ui_files/serial_killer_log_popup.ui' # -# Created by: PyQt5 UI code generator 5.15.6 +# Created by: PyQt5 UI code generator 5.15.10 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. diff --git a/gui/GUI_MAIN_WINDOW.py b/gui/GUI_MAIN_WINDOW.py index 27345d1..a165169 100644 --- a/gui/GUI_MAIN_WINDOW.py +++ b/gui/GUI_MAIN_WINDOW.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'C:/Users/admin/Documents/GitHub/SerialKiller/ui_files/serial_killer_main_window.ui' +# Form implementation generated from reading ui file '/home/patrick/careweather/serialkiller//ui_files/serial_killer_main_window.ui' # -# Created by: PyQt5 UI code generator 5.15.6 +# Created by: PyQt5 UI code generator 5.15.10 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. @@ -54,6 +54,7 @@ def setupUi(self, MainWindow): font.setPointSize(10) font.setBold(True) self.label_debug.setFont(font) + self.label_debug.setWordWrap(True) self.label_debug.setObjectName("label_debug") self.gridLayout.addWidget(self.label_debug, 2, 0, 1, 2) self.label_5 = QtWidgets.QLabel(self.groupBox_output) @@ -472,7 +473,7 @@ def setupUi(self, MainWindow): self.toolBox = QtWidgets.QToolBox(self.settings) self.toolBox.setObjectName("toolBox") self.page_send_settings = QtWidgets.QWidget() - self.page_send_settings.setGeometry(QtCore.QRect(0, 0, 397, 69)) + self.page_send_settings.setGeometry(QtCore.QRect(0, 0, 430, 78)) self.page_send_settings.setObjectName("page_send_settings") self.gridLayout_13 = QtWidgets.QGridLayout(self.page_send_settings) self.gridLayout_13.setObjectName("gridLayout_13") @@ -496,7 +497,7 @@ def setupUi(self, MainWindow): self.gridLayout_13.addItem(spacerItem7, 2, 0, 1, 1) self.toolBox.addItem(self.page_send_settings, "") self.page_terminal_settings = QtWidgets.QWidget() - self.page_terminal_settings.setGeometry(QtCore.QRect(0, 0, 475, 199)) + self.page_terminal_settings.setGeometry(QtCore.QRect(0, 0, 480, 216)) self.page_terminal_settings.setObjectName("page_terminal_settings") self.gridLayout_6 = QtWidgets.QGridLayout(self.page_terminal_settings) self.gridLayout_6.setObjectName("gridLayout_6") @@ -594,7 +595,7 @@ def setupUi(self, MainWindow): self.gridLayout_6.addWidget(self.label_12, 10, 0, 1, 6) self.toolBox.addItem(self.page_terminal_settings, "") self.page_log_settings = QtWidgets.QWidget() - self.page_log_settings.setGeometry(QtCore.QRect(0, 0, 276, 250)) + self.page_log_settings.setGeometry(QtCore.QRect(0, 0, 299, 270)) self.page_log_settings.setObjectName("page_log_settings") self.gridLayout_11 = QtWidgets.QGridLayout(self.page_log_settings) self.gridLayout_11.setObjectName("gridLayout_11") @@ -668,7 +669,7 @@ def setupUi(self, MainWindow): self.gridLayout_11.addWidget(self.lineEdit_log_name, 3, 1, 1, 2) self.toolBox.addItem(self.page_log_settings, "") self.page_command_settings = QtWidgets.QWidget() - self.page_command_settings.setGeometry(QtCore.QRect(0, 0, 166, 69)) + self.page_command_settings.setGeometry(QtCore.QRect(0, 0, 176, 78)) self.page_command_settings.setObjectName("page_command_settings") self.gridLayout_10 = QtWidgets.QGridLayout(self.page_command_settings) self.gridLayout_10.setObjectName("gridLayout_10") @@ -693,7 +694,7 @@ def setupUi(self, MainWindow): self.gridLayout_3.addWidget(self.tabWidget, 2, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) - self.menubar.setGeometry(QtCore.QRect(0, 0, 526, 21)) + self.menubar.setGeometry(QtCore.QRect(0, 0, 526, 22)) self.menubar.setObjectName("menubar") self.menuLog = QtWidgets.QMenu(self.menubar) self.menuLog.setObjectName("menuLog") diff --git a/sk_help.py b/sk_help.py index 7102ae8..1b31d89 100644 --- a/sk_help.py +++ b/sk_help.py @@ -93,6 +93,17 @@ -k, --keys Set the target keywords (comma seperate) -p, --points Set the number of plot points +''' + +FWD_HELP = '''\ +USEAGE: + forward [options] + +Options: + -h, --help Print this help message + -k, --keys Set the target keywords (comma seperate) + -p, --port Set the forwarding port + ''' PLOT_TYPES_HELP = '''\ Plot Types (comma used as separator): diff --git a/sk_main_window.py b/sk_main_window.py index b9f6ad0..4858165 100644 --- a/sk_main_window.py +++ b/sk_main_window.py @@ -3,6 +3,8 @@ import os import time from datetime import datetime +import socket +import json from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import QThread, QTimer @@ -106,6 +108,7 @@ class MainWindow(QtWidgets.QMainWindow): timestamp_format: str = '[%I:%M:%S.%f] ' open_time = datetime.now() preference_port: str = None + fwd_buffer = "" def __init__(self, parent: QtWidgets.QApplication, open_cmd=[], * args, **kwargs) -> None: super().__init__(*args, **kwargs) @@ -151,6 +154,49 @@ def __init__(self, parent: QtWidgets.QApplication, open_cmd=[], * args, **kwargs + self.forwarder = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.forwarder.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + def initForwarder(self, host, port, targets): + self.forwarder.connect((host, port)) + self.forwarding_targets = targets.split(',') + + def isForwarding(self): + try: + remote_address = self.forwarder.getpeername() + return True + except socket.error: + return False + + def forward(self, input: str, wait_for_newline=True): + self.fwd_buffer += input + if '\n' not in self.fwd_buffer and wait_for_newline: + return + + lines = self.fwd_buffer.split("\n") + if len(lines) > 1: + self.fwd_buffer = lines.pop(-1) # Last part did not have a newline + else: + self.fwd_buffer = "" + + for line in lines: + line = line.replace("\r", '') + if not line: continue + + if line.startswith('|') and line.endswith('|'): + continue + + # clean_line = re.sub(r"\s+", '', line) + + # data = {token.split(':')[0]:token.split(':')[1] for token in clean_line.split('\\s+')} + + # self.forwarder.sendall(json.dumps(data).encode()) + + self.forwarder.sendall(line.encode()) + + def close_forwarder(self): + self.forwarder.close() + def keyPressEvent(self, event: QtGui.QKeyEvent) -> None: key = event.key() modifier = event.modifiers() @@ -315,6 +361,8 @@ def add_text(self, *args, type: int = TYPE_RX): self.log.write(text) if self.plot_started: self.ui.widget_plot.update(text) + if self.isForwarding(): + self.forward(text) text = text.replace("\r", '') if self.ui.checkBox_timestamp.isChecked(): if self.needs_timestamp: @@ -992,6 +1040,13 @@ def create_commands(self): self.cmd_list.append(cmd_plot) + cmd_fwd = Command("forward", self.handle_fwd_command, 1) + cmd_fwd.add_option(("-h", "--help")) + cmd_fwd.add_option(("-k", "--keys")) + cmd_fwd.add_option(("-p", "--port")) + + self.cmd_list.append(cmd_fwd) + cmd_keys = Command("key", self.handle_key_cmd, 3) cmd_keys.add_option(("-h", "--help")) @@ -1268,6 +1323,7 @@ def end_script(self): self.script_worker.stop() self.script_worker = None self.debug_text("SCRIPT ENDED", color=COLOR_GREEN) + self.close_forwarder() return ######################################################################## # @@ -1434,6 +1490,23 @@ def handle_plot_command(self, *args, **kwargs): self.ui.comboBox_plot_type.setCurrentText(plot_type) self.start_plot() + def handle_fwd_command(self, **kwargs): + HOST = '127.0.0.1' # Local host + PORT = 65432 # Default sk port + targets = None + + if '-h' in kwargs: + self.add_text(FWD_HELP, type=TYPE_HELP) + return + elif '-k' in kwargs: + targets = kwargs['-k'] + self.ui.lineEdit_target_keys.setText(targets) + + elif '-p' in kwargs: + PORT = kwargs['-p'] + + self.initForwarder(HOST, PORT, targets) + def start_plot(self): if self.plot_started: self.end_plot() diff --git a/ui_files/serial_killer_main_window.ui b/ui_files/serial_killer_main_window.ui index ea7b036..429416a 100644 --- a/ui_files/serial_killer_main_window.ui +++ b/ui_files/serial_killer_main_window.ui @@ -109,6 +109,9 @@ DEBUG TEXT HERE + + true + @@ -1181,8 +1184,8 @@ color: rgb(255, 255, 255); 0 0 - 397 - 69 + 430 + 78 @@ -1256,8 +1259,8 @@ color: rgb(255, 255, 255); 0 0 - 475 - 199 + 480 + 216 @@ -1539,8 +1542,8 @@ color: rgb(255, 255, 255); 0 0 - 276 - 250 + 299 + 270 @@ -1709,8 +1712,8 @@ color: rgb(255, 255, 255); 0 0 - 166 - 69 + 176 + 78 @@ -1789,7 +1792,7 @@ color: rgb(255, 255, 255); 0 0 526 - 21 + 22