Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gui/GUI_HELP_POPUP.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions gui/GUI_LOG_POPUP.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
15 changes: 8 additions & 7 deletions gui/GUI_MAIN_WINDOW.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions sk_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@
-k, --keys <keys> Set the target keywords (comma seperate)
-p, --points <points> Set the number of plot points

'''

FWD_HELP = '''\
USEAGE:
forward [options]

Options:
-h, --help Print this help message
-k, --keys <keys> Set the target keywords (comma seperate)
-p, --port <port> Set the forwarding port

'''
PLOT_TYPES_HELP = '''\
Plot Types (comma used as separator):
Expand Down
73 changes: 73 additions & 0 deletions sk_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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
########################################################################
#
Expand Down Expand Up @@ -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()
Expand Down
21 changes: 12 additions & 9 deletions ui_files/serial_killer_main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<property name="text">
<string>DEBUG TEXT HERE</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="3">
Expand Down Expand Up @@ -1181,8 +1184,8 @@ color: rgb(255, 255, 255);</string>
<rect>
<x>0</x>
<y>0</y>
<width>397</width>
<height>69</height>
<width>430</width>
<height>78</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -1256,8 +1259,8 @@ color: rgb(255, 255, 255);</string>
<rect>
<x>0</x>
<y>0</y>
<width>475</width>
<height>199</height>
<width>480</width>
<height>216</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -1539,8 +1542,8 @@ color: rgb(255, 255, 255);</string>
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>250</height>
<width>299</width>
<height>270</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -1709,8 +1712,8 @@ color: rgb(255, 255, 255);</string>
<rect>
<x>0</x>
<y>0</y>
<width>166</width>
<height>69</height>
<width>176</width>
<height>78</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -1789,7 +1792,7 @@ color: rgb(255, 255, 255);</string>
<x>0</x>
<y>0</y>
<width>526</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuLog">
Expand Down