From 788487d1817d049c28892ab3aaff43016aab1066 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Tue, 29 Nov 2022 18:16:13 -0600 Subject: [PATCH] Add whitelist, tweak various code --- block.py | 25 ++++++++++- ippigeon.py | 39 ++++++++-------- music.mp3 | Bin 0 -> 24813 bytes netstat.py | 21 ++++----- notification.py | 19 ++++++++ panel.py | 116 +++++++++++++++++++++++++++++++++++++++++++----- setup.py | 2 +- ssh.py | 21 ++++----- taskbartool.py | 4 +- util.py | 39 ++++++++++------ 10 files changed, 218 insertions(+), 68 deletions(-) create mode 100644 music.mp3 create mode 100644 notification.py diff --git a/block.py b/block.py index ed241b0..a4ae02e 100644 --- a/block.py +++ b/block.py @@ -10,8 +10,10 @@ import time import csv import ssh -def get_blocklist(config, appendbad): +def get_blocklist(config, settings): setup_child() + appendbad = settings["appendbad"] + whitelist = settings["whitelist"] fprint("Downloading deny list from server") data = ssh.check_for_file(config, "BadIPs.csv", "receive") #fprint(data.stdout) @@ -24,7 +26,26 @@ def get_blocklist(config, appendbad): for line in appendbad: data2.append(line) - + for line in whitelist: + for line2 in data2: + if line[0] in line2 and line[1] in line2: + fprint("Whitelisting P1 " + line[0] + ":" + str(line[1])) + data2.remove(line2) + + if line[2] in settings["badapps"]: + tmp = settings["badapps"] + tmp.remove(line[2]) + settings["badapps"] = tmp + if line[0] in settings["badips"]: + tmp = settings["badips"] + tmp.remove(line[0]) + settings["badips"] = tmp + for line3 in settings["badlines"]: + if line[0] in line3 and line[1] in line3: + fprint("Whitelisting P2" + line[0] + ":" + str(line[1])) + tmp = settings["badlines"] + tmp.remove(line3) + settings["badlines"] = tmp fprint(data2) with open(find_data_file("blocklist.csv"), "w", newline="") as f: diff --git a/ippigeon.py b/ippigeon.py index 6b50c29..4d87ce3 100644 --- a/ippigeon.py +++ b/ippigeon.py @@ -60,13 +60,13 @@ if linux or macos: #fprint(hostname) def netstat_done(res): - fprint("netstat done, processing") + fprint("netstat done, processing", settings) procdata_res = pool.apply_async(netstat.process, (res,), callback=process_done) #netstat.process(res) def process_done(res): if settings["running"] == True: - fprint("uploading to sftp...") + fprint("uploading to sftp...", settings) #ssh.sftp_send_data(config, datafile, 'send') procdata_res = pool.apply_async(ssh.sftp_send_data, (config, datafile, 'send'), callback=upload_done) @@ -79,16 +79,16 @@ def upload_done(res): def login_done(res): if not res: - fprint("Login failure") + fprint("Login failure", settings) settings["message"] = "Login failure" else: - fprint("Login result in main: " + str(res)) + fprint("Login result in main: " + str(res), settings) settings["loggedin"] = res settings["continueui"] = True def blockdata_done(res): global settings - fprint("FINISHED downloading block data") + fprint("FINISHED downloading block data", settings) tmpkill = settings["kill"] settings["kill"] = False #block_res = pool.apply_async(block.block_conn, (config, datafile, res, settings)) @@ -105,42 +105,42 @@ def blockdata_done(res): tmplist = settings["badapps"] for x in block_pids: - fprint(x) + fprint(x, settings) if not x in tmplist: tmplist.append(x) settings["badapps"] = tmplist - fprint(settings["badapps"]) + fprint(settings["badapps"], settings) tmplist = settings["badips"] for x in block_ips: - fprint(x) + fprint(x, settings) if not x in tmplist: tmplist.append(x) settings["badips"] = tmplist - fprint(settings["badips"]) + fprint(settings["badips"], settings) settings["kill"] = tmpkill tmplist = settings["badlines"] for x in block_data: - fprint(x) + fprint(x, settings) if not x in tmplist: tmplist.append(x) settings["badlines"] = tmplist - fprint(settings["badlines"]) + fprint(settings["badlines"], settings) settings["newdata"] = True def readstat_done(res): settings["stats"] = res - fprint("Read stats!" + str(settings["stats"])) + fprint("Read stats!" + str(settings["stats"]), settings) def killall(): kids = active_children() for kid in kids: kid.kill() - fprint("Every child has been killed") + fprint("Every child has been killed", settings) os.kill(os.getpid(), 9) # dirty kill of self @@ -167,7 +167,7 @@ def mainloop(pool): if netdata_res is None or netdata_res.ready(): #rawdata = netdata_res.get() #procdata_res = pool.apply_async(process_netstat, (rawdata)) - fprint("netstat starting") + fprint("netstat starting", settings) netdata_res = pool.apply_async(netstat.start, callback=netstat_done) #fprint(netdata_res.successful()) @@ -193,8 +193,9 @@ def mainloop(pool): if settings["block"] == True and settings["running"] == True: - blockdata_res = pool.apply_async(block.get_blocklist, (config, settings["appendbad"]), callback=blockdata_done) - #block.get_blocklist(config) + #blockdata_res = pool.apply_async(block.get_blocklist, (config, settings), callback=blockdata_done) + res = block.get_blocklist(config, settings) + blockdata_done(res) settings["block"] = False if config["core"]["level"] == 0: @@ -233,7 +234,7 @@ def mainloop(pool): badport = line[5] if (badip, badport) not in history: - fprint("Firewalling " + badip + ":" + str(badport)) + fprint("Firewalling " + badip + ":" + str(badport), settings) send_notification("Firewalling " + badip + ":" + str(badport)) if win32: cmd = 'New-NetFirewallRule -DisplayName "IPPigeon Security Rule ' + badip + ':' + str(badport) + '" -Group "IPPigeon" -Direction Outbound -LocalPort Any -Protocol ' + badproto + ' -Action Block -RemoteAddress ' + badip + ' -RemotePort ' + str(badport) @@ -253,7 +254,7 @@ def mainloop(pool): with open(find_data_file('config.yml'), 'w') as filewrite: #global config yaml.dump(config, filewrite) - fprint("Config saved!") + fprint("Config saved!", settings) sleep(interval / (interval * config["core"]["clockspeed"])) counter += 1 @@ -312,6 +313,8 @@ if __name__ == '__main__': settings["running"] = config["core"]["autostart"] settings["newdata"] = False settings["appendbad"] = list() + settings["logMsg"] = list() + settings["whitelist"] = list() tmp = list() tmp.append(["N/A", "TCP", "N/A", "N/A", "20.112.52.29", "5000", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"]) tmp.append(["N/A", "TCP", "N/A", "N/A", "20.81.111.85", "80", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"]) diff --git a/music.mp3 b/music.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..a3cd9429dce6a48e5ea15b49183bc54c0e8348b7 GIT binary patch literal 24813 zcmeFY2UHYWyRKUufCieJnkYGkA_)jWlT(X;WC=~qS-^09XP*Nl8b?!otGI z$;T%mA|fRvFE6jGtgf!Bt9#+XrAyY<)(#G?uCCtRfq`LRVYhBYM8w6#-MN#QnVF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?8>2=I3Ym?-m8SFauLFs2r z|Fh)<8=GI&T{8Az3ufS&@45BJ9{x9u4E5`8_ArRm0F7Abbwx8$*84^7{=Yo00viM> zTteqxlhS%KWw4Du;~qa8;WGAIE*}iK7)33(E}UU5zPC7IvZ`z76od3?xxZrXnyl)9 zk$f45H~;@P=}23+q8KN~N#5nW%Q<;Ya-BJM<|N07XB+!E+MgUY=|{W&V+hB(=07JG>I-p>M47q>68a=PTAXynQJMKUL3^43C&pb0G}kL9Uy|GJnHGNDy-+5{*5FFR`@ z)wwSFcD#spI)AizV#@P0X9>TphZcHlm>+E~6Y%{M+ft^tVM`+XcZa!!nXR}j%2gW8 zbgM{9?#_bjz^z(W`X+yz+#m46%WSFB+_M&s+V?r%p2EE~N-^Pil*x_0wkx^?E9|eG zD_1d`%AXXVcQvbY%j2arsi5>TrSD@B`&#Bd7l3sac>Y~k_0R?V%!jb~uN1M$$lEd! zcQ?4!i_Q~PuC`8Y{_ayabwcEmlxtk@^h19BX3P|sl_#-HzKk)d%A%F=95<_)_nLc( zn(LQ%mxQ~pSh@W8sOnjmYsGrvzl_?!N%?Y)LGCOS8=I%h)bXgypG4 z%%n6gjYsDGi@16eP8kVxs2*Q=DBdSEQZJN@nq)AI8Sp(Qs?CvN`(^2V|&GmAN z%CU&qGLMqdxCISW7QeVI_PEE_&#}n*IA@D*`^6q}f5trLqetGzxCthyFVpztI3bkb zs|rWpCvWeKRjTS2?uGCN)wIlO+3{9i<)@a{#3!N_P7_nMoHO#?_(VfzqQVqUheX#Y z0Sh*{CUE}Ca$}rODv;2+*r`?RvW(fO8?xIcKFeP6= 0: - fprint("Not enough permissions") + fprint("Not enough permissions", settings) raise PermissionError("Unable to acquire netstat data without admin!") output2 = list() output2.append([util.sysid, util.userid, util.sysdom, util.time()]) # add metadata @@ -107,7 +108,7 @@ def process(data): with open(find_data_file(util.datafile), "w", newline="") as f: writer = csv.writer(f) writer.writerows(output2) - fprint("done creating csv") + fprint("done creating csv", settings) if macos: output = data.stdout.decode().split('\n') # split stdout into lines @@ -115,7 +116,7 @@ def process(data): #fprint("output data: " + str(output)) output = [i for i in output if i] if output[0].find("Not all processes could be identified") >= 0: - fprint("Not enough permissions") + fprint("Not enough permissions", settings) raise PermissionError("Unable to acquire netstat data without admin!") output2 = list() output2.append([util.sysid, util.userid, util.sysdom, util.time()]) # add metadata @@ -144,25 +145,25 @@ def process(data): with open(find_data_file(util.datafile), "w", newline="") as f: writer = csv.writer(f) writer.writerows(output2) - fprint("done creating csv") + fprint("done creating csv", settings) def start(): setup_child() - fprint("netstat started") + fprint("netstat started", settings) if win32: data = run_cmd("netstat -n -o -b") - fprint("data acquired") + fprint("data acquired", settings) return data if linux: data = run_cmd("netstat -atunpw") - fprint("data acquired") + fprint("data acquired", settings) return data if macos: data = run_cmd("netstat -anv") - fprint("data acquired") + fprint("data acquired", settings) return data diff --git a/notification.py b/notification.py new file mode 100644 index 0000000..3516685 --- /dev/null +++ b/notification.py @@ -0,0 +1,19 @@ +from plyer import notification #for getting notification on your PC +import sys +from playsound import playsound #pip install playsound==1.2.2 +from util import find_data_file +relative_path = (sys.path[0]) +sound = find_data_file('music.mp3') + +def send_notification(msg="Test notification"): + notification.notify( + title = "IP Pigeon", + message = msg, + app_name = "IPPigeon", + app_icon = find_data_file("icon.ico"), + timeout = 5 #number of seconds message is displayed + ) + playsound(sound) + +if __name__ == '__main__': + send_notification() diff --git a/panel.py b/panel.py index b4f223b..58c5a83 100644 --- a/panel.py +++ b/panel.py @@ -1,5 +1,7 @@ import glob import wx +import logging +import sys import wx.lib.buttons as buttons import numpy as np import pandas as pd @@ -47,7 +49,7 @@ class OtherFrame(wx.Frame): self.Show() def on_edit(self, event): - fprint('in on_edit') + fprint('in on_edit', settings) def on_window(self, event): return @@ -208,16 +210,30 @@ class ServerPanel(wx.Panel): self.blacklist_button = wx.Button(self, label='Add to blacklist') #self.login_button.SetBackgroundColour((205, 215, 206)) self.blacklist_button.Bind(wx.EVT_BUTTON, self.on_blacklist) + + self.whitelist_button = wx.Button(self, label='Add to whitelist') + #self.login_button.SetBackgroundColour((205, 215, 206)) + self.whitelist_button.Bind(wx.EVT_BUTTON, self.on_whitelist) + self.log_button = wx.Button(self, label='Logs') + self.log_button.Bind(wx.EVT_BUTTON, self.on_log) + + #self.log_window = wx.LogWindow(self, 'Log Window', True) + + #show_log_button = wx.Button(self, wx.NewId(), 'Show Log') + #show_log_button.Bind(wx.EVT_BUTTON, self._show_log) + self.sub_sizer_right.Add(self.statustext, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_right.Add(self.logintext, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_left.Add(self.start_button, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_left.Add(self.stop_button, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_left.Add(self.secondary_frame_button, 0, wx.CENTER | wx.ALL | 100, 5) + self.sub_sizer_left.Add(self.log_button, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_right.Add(self.login_button, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_right.Add(self.quit_button, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_stats.Add(self.stattext, 0, wx.CENTER | wx.ALL | 100, 5) self.sub_sizer_filter.Add(self.blacklist_button, 0, wx.CENTER | wx.ALL | 100, 5) + self.sub_sizer_filter.Add(self.whitelist_button, 0, wx.CENTER | wx.ALL | 100, 5) self.SetSizer(self.main_sizer) self.start_button.Enable(enable=settings["loggedin"]) self.stop_button.Enable(enable=settings["loggedin"]) @@ -238,8 +254,10 @@ class ServerPanel(wx.Panel): self.quit_button.Enable(enable=settings["loggedin"]) if self.list_ctrl.GetFirstSelected() < 0: self.blacklist_button.Enable(enable=False) + self.whitelist_button.Enable(enable=False) else: self.blacklist_button.Enable(enable=settings["loggedin"]) + self.whitelist_button.Enable(enable=settings["loggedin"]) def updatedata(self): global settings if settings["running"] == True: @@ -265,16 +283,16 @@ class ServerPanel(wx.Panel): else: wx.CallLater(100, self.updatedata) return - fprint("updatedata called") + fprint("updatedata called", settings) loaddata() list_total = self.list_ctrl.GetItemCount() list_top = self.list_ctrl.GetTopItem() list_pp = self.list_ctrl.GetCountPerPage() list_bottom = min(list_top + list_pp, list_total - 1) if self.list_ctrl.DeleteAllItems(): - fprint("Items deleted") + fprint("Items deleted", settings) else: - fprint("Unable to delete") + fprint("Unable to delete", settings) for i in range(len(TEST_FILE)): if str(TEST_FILE.iloc[i, 4]).find("TIME_WAIT") >= 0 or str(TEST_FILE.iloc[i, 4]).find("FIN_WAIT_2") >= 0: continue @@ -283,7 +301,7 @@ class ServerPanel(wx.Panel): #fprint(pid) idx = i if TEST_FILE.iloc[i, 5] == app: # "bad" pid, highlight in red at the top - fprint("BAD APP UI: " + str(app)) + fprint("BAD APP UI: " + str(app), settings) idx = self.list_ctrl.InsertItem(0, TEST_FILE.iloc[i, 0]) self.list_ctrl.SetItemBackgroundColour(idx, wx.Colour(200, 51, 51)) break @@ -305,21 +323,21 @@ class ServerPanel(wx.Panel): wx.CallLater(100, self.updatedata) def on_start(self, event): - fprint('in on_start') + fprint('in on_start', settings) settings["running"] = True def on_stop(self, event): - fprint('in on_stop') + fprint('in on_stop', settings) settings["running"] = False util.clear_fwll() def on_window(self, event): - fprint("open settings") + fprint("open settings", settings) dg = GetData(parent = None) dg.ShowModal() def on_login(self, event): - fprint("open login") + fprint("open login", settings) if settings["loggedin"] == True: settings["loggedin"] = False return @@ -341,10 +359,32 @@ class ServerPanel(wx.Panel): proto = self.list_ctrl.GetItem(idx, 1).GetText() dest = self.list_ctrl.GetItem(idx, 3).GetText() destip, destport = dest.split(":") - fprint([proto, destip, destport]) + fprint([proto, destip, destport], settings) tmp.append(["N/A", proto, "N/A", "N/A", destip, destport, "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"]) settings["appendbad"] = tmp + def on_whitelist(self, event): + global settings + tmp = settings["whitelist"] + idx = self.list_ctrl.GetFirstSelected() + if idx < 0: + return + proto = self.list_ctrl.GetItem(idx, 1).GetText() + dest = self.list_ctrl.GetItem(idx, 3).GetText() + pid = self.list_ctrl.GetItem(idx, 5).GetText() + destip, destport = dest.split(":") + fprint([proto, destip, destport], settings) + tmp.append([destip, destport, int(pid)]) + settings["whitelist"] = tmp + + def on_log(self, event): + fprint("open log", settings) + dg = logData(parent = None) + #fprint("attempting logLoop", settings) + logData.logLoop(dg) + #fprint("did logLoop work?", settings) + dg.ShowModal() + def ShowImage(self, imageFile): if imageFile == "": self.bitmap = wx.StaticBitmap(self, -1, size=(0, 0)) @@ -373,7 +413,7 @@ def openwindow(data, sets, kill): displaydata = data settings = sets #if settings["loggedin"]: - fprint("Creating server panel") + fprint("Creating server panel", settings) loaddata() app = wx.App(False) frame = OtherFrame() @@ -387,6 +427,58 @@ def openwindow(data, sets, kill): #frame.SetIcon(wx.Icon(find_data_file("icon.ico"), wx.BITMAP_TYPE_ICO)) #app.MainLoop() + + +class RedirectText(object): + def __init__(self,aWxTextCtrl): + self.out = aWxTextCtrl + + def write(self,string): + self.out.WriteText(string) + +class logData(wx.Dialog): + def __init__(self, parent): + wx.Dialog.__init__(self, parent, wx.ID_ANY, "Logs: ", size = (800,500)) + self.p = wx.Panel(self, wx.ID_ANY) + #self.logBox = wx.BoxSizer(wx.VERTICAL) + self.logsTitle = wx.StaticText(self.p, label="Logs", pos=(20,20)) + self.logs = wx.TextCtrl(self.p, pos=(20,40), size= (700, 400), style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL) + self.logs.WriteText("init\n") + #keepLoop = False + + def logLoop(self): + #self.logs.WriteText("before while loop\n") + i=0 + #self.logs.Clear() + tmp = settings["logMsg"] + if (tmp is not None): + while(i < len(settings["logMsg"])): + #for i in range(len(settings["logMsg"])): + #self.logs.WriteText("in while loop\n") + self.logs.WriteText(settings["logMsg"][i]) + self.logs.WriteText("\n") + tmp.remove(settings["logMsg"][i]) + i+=1 + else: + #self.logs.WriteText("settings is none :(") + tmp.add("init string for list") + logData.logLoop(self) + settings["logMsg"] = tmp + wx.CallLater(100, self.logLoop) + #self.logs.WriteText("after while loop\n") + + + + #redir = RedirectText(self.logs) + #sys.stdout = redir + #self.logs.WriteText(redir) + + #self.logs.LoadFile('output.log') + + #def doLogging(self): + #self.logs.WriteText("hi from doLogging\n") + #self.logs.WriteText(settings["logMsg"]) + class GetData(wx.Dialog): def __init__(self, parent): wx.Dialog.__init__(self, parent, wx.ID_ANY, "User Settings: ", size = (800,500)) @@ -434,7 +526,7 @@ class GetData(wx.Dialog): def OnQuit(self, event): # save changes - fprint("saving changes...") + fprint("saving changes...", settings) config = settings["config"] config["sftp"]["host"] = self.hostnametext.GetValue() config["sftp"]["user"] = self.usertext.GetValue() diff --git a/setup.py b/setup.py index d33e010..25e9fc0 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ debug = True debug = not debug # Dependencies are automatically detected, but it might need fine tuning. # "packages": ["os"] is used as example only -build_exe_options = {"packages": ["os"], "excludes": ["tkinter"], "include_msvcr": True, "include_files": ["icon.png", "config.yml", "keyfile-admin.pem", "WXPython.png", "WXPython_30x30.png", "settings.png", "settings_30x30.png", "icon.ico"], "optimize": 1} +build_exe_options = {"packages": ["os"], "excludes": ["tkinter"], "include_msvcr": True, "include_files": ["icon.png", "config.yml", "keyfile-admin.pem", "WXPython.png", "WXPython_30x30.png", "settings.png", "settings_30x30.png", "icon.ico", "music.mp3"], "optimize": 1} # base="Win32GUI" should be used only for Windows GUI app base = None diff --git a/ssh.py b/ssh.py index c8bc650..34fadcf 100644 --- a/ssh.py +++ b/ssh.py @@ -8,44 +8,45 @@ from invoke import exceptions import sys c = None +settings = None def sftp_send_data(config, filename, filetype): setup_child() if not macos: - fprint("Connecting over SSH to " + config['sftp']['host']) + fprint("Connecting over SSH to " + config['sftp']['host'], settings) global c if c is None: c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),}) - fprint("Sending data over SFTP: " + filename) - fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath'][filetype])) - fprint("Data sent over SFTP successfully") + fprint("Sending data over SFTP: " + filename, settings) + fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath'][filetype]), settings) + fprint("Data sent over SFTP successfully", settings) #command = 'ls ' + config['sftp']['filepath'][filetype] #fprint(c.run(command)) def check_for_file(config, filename, location): setup_child() - fprint("Connecting over SSH to " + config['sftp']['host']) + fprint("Connecting over SSH to " + config['sftp']['host'], settings) global c if c is None: c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),}) - fprint("Checking for existence of file " + config['sftp']['filepath'][location] + "/" + filename) + fprint("Checking for existence of file " + config['sftp']['filepath'][location] + "/" + filename, settings) try: res = c.run("ls -l " + config['sftp']['filepath'][location] + "/" + filename, hide=True) - fprint("File " + filename + " exists!") + fprint("File " + filename + " exists!", settings) return c.run("cat " + config['sftp']['filepath'][location] + "/" + filename, hide=True) except exceptions.UnexpectedExit: return False def run_ssh(config, command, location): setup_child() - fprint("Connecting over SSH to " + config['sftp']['host']) + fprint("Connecting over SSH to " + config['sftp']['host'], settings) global c if c is None: c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),}) - fprint("cd to " + config['sftp']['filepath'][location]) + fprint("cd to " + config['sftp']['filepath'][location], settings) with c.cd(config['sftp']['filepath'][location]): - fprint("Running ssh command: " + command) + fprint("Running ssh command: " + command, settings) res = c.run(command, hide=True, asynchronous=True) return res diff --git a/taskbartool.py b/taskbartool.py index 9ff5daf..050d0dc 100644 --- a/taskbartool.py +++ b/taskbartool.py @@ -42,7 +42,7 @@ class TaskBarIcon(wx.adv.TaskBarIcon): self.SetIcon(icon, TRAY_TOOLTIP) def on_left_down(self, event): - fprint ('Tray icon was left-clicked.') + fprint('Tray icon was left-clicked.', settings) def on_open(self, event): settings["showui"] = True @@ -81,7 +81,7 @@ def background(data, sets, kill): app = TaskbarApp(False) displaydata = data settings = sets - fprint("Creating taskbar icon") + fprint("Creating taskbar icon", settings) app.MainLoop() TRAY_ICON = find_data_file('icon.png') diff --git a/util.py b/util.py index db07554..15d23af 100644 --- a/util.py +++ b/util.py @@ -12,6 +12,10 @@ win32 = platform == "win32" linux = platform == "linux" or platform == "linux2" macos = platform == "darwin" datafile = "" +logMsg = "" +logCont = "" + +settings = None if win32: sysid = hex(uuid.getnode()) @@ -44,21 +48,28 @@ def time(): def kill(pid): setup_child() if pid > 0: - fprint("Killing PID " + str(pid)) + fprint("Killing PID " + str(pid), settings) os.kill(int(pid), 9) - fprint("Signal 9 sent to PID " + str(pid)) + fprint("Signal 9 sent to PID " + str(pid), settings) -def fprint(msg): +def fprint(msg, settings = None): #if not getattr(sys, "frozen", False): setup_child() try: frm = inspect.stack()[1] mod = inspect.getmodule(frm[0]) - print('[' + mod.__name__ + ":" + frm.function + ']:', str(msg)) + logMsg = '[' + mod.__name__ + ":" + frm.function + ']:' + str(msg) + + print(logMsg) + if (settings is not None): + tmpList = settings["logMsg"] + tmpList.append(logMsg) + settings["logMsg"] = tmpList except Exception as e: try: print('[????:' + frm.function + ']:', str(msg)) + print('[util:fprint]: ' + str(e)) except: print('[????]:', str(msg)) @@ -87,21 +98,23 @@ def run_cmd(cmd): #else: # print("alt") startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # , "-WindowStyle", "hidden" - fprint("running PS command: " + cmd) + fprint("running PS command: " + cmd, settings) completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo) - fprint("ran PS command successfully") + fprint("ran PS command successfully", settings) #completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo) return completed if linux or macos: - fprint("running sh command: " + cmd) + fprint("running sh command: " + cmd, settings) completed = subprocess.run(["sh", "-c", cmd], capture_output=True) - fprint("ran sh command successfully") + fprint("ran sh command successfully", settings) return completed -def setup_child(): +def setup_child(sets=None): if not getattr(sys, "frozen", False): sys.stdout = Logger(filename=find_data_file("output.log")) sys.stderr = Logger(filename=find_data_file("output.log")) + if sets is not None: + settings = sets class Logger(object): def __init__(self, filename="output.log"): @@ -128,7 +141,7 @@ def clear_fwll(): def write_stats(stats): - fprint("Writing stats") + fprint("Writing stats", settings) tmp = list() tmp.append(["connections blocked", "connections allowed", "data uploaded", "data recieved", "block ratio"]) tmp.append(stats) @@ -136,16 +149,16 @@ def write_stats(stats): with open(find_data_file("stats.csv"), "w", newline="") as f: writer = csv.writer(f) writer.writerows(tmp) - fprint("Done writing stats") + fprint("Done writing stats", settings) def read_stats(): with open(find_data_file("stats.csv"), newline='') as csvfile: csvreader = csv.reader(csvfile, delimiter=',', quotechar='|') header = True - fprint(csvreader) + fprint(csvreader, settings) data = list() for line in csvreader: - fprint(line) + fprint(line, settings) if header: header = False continue