You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ff/panel.py

327 lines
11 KiB
Python

import glob
import wx
import wx.lib.buttons as buttons
import numpy as np
import pandas as pd
from util import sysid
from util import setup_child
from util import fprint
from util import find_data_file
BG_IMG = 'icon.png'
filename = sysid + "gendata.csv"
COLUMN_NAMES = np.flip(['Executable', 'Proto', 'Source IP', 'Destination IP', 'Status', 'PID'])
COLUMN_SIZES = np.flip([150, 50, 200, 200, 110, 65])
TEST_FILE = None
displaydata = None
settings = None
killme = False
class OtherFrame(wx.Frame):
"""
Class used for creating frames other than the main one
"""
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Server Panel', size=(600, 250))
panel = ServerPanel(self)
self.Show()
def on_edit(self, event):
fprint('in on_edit')
def on_window(self, event):
return
class HelpFrame(wx.Frame):
"""
Class used for creating frames other than the main one
"""
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Help', size=(600, 250))
panel = HelpPanel(self)
self.Show()
# Panel with all the login widgets
class LoginPanel(wx.Panel):
def __init__(self, parent):
super(LoginPanel, self).__init__(parent)
self.SetBackgroundColour((44, 51, 51))
basicLabel = wx.StaticText(self, -1, "Username")
basicLabel.SetForegroundColour((255,255,255))
global basicText
global pwdText
basicText = wx.TextCtrl(self, -1, "", size=(175, -1))
# basicText.SetInsertionPoint(0)
pwdLabel = wx.StaticText(self, -1, "Password")
pwdText = wx.TextCtrl(self, -1, "", size=(175, -1), style=wx.TE_PASSWORD)
#pwdText.Bind(wx.EVT_TEXT_ENTER, self.on_login) # press enter in password field to login
pwdLabel.SetForegroundColour((255, 255, 255))
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox.Add(basicLabel, 0, wx.ALIGN_CENTER | 100, 5)
vbox.Add(basicText, 0, wx.ALIGN_CENTER | 100, 5)
vbox.Add(pwdLabel, 0, wx.ALIGN_CENTER | 100, 5)
vbox.Add(pwdText, 0, wx.ALIGN_CENTER | 100, 5)
login_button = wx.Button(self, label='Login')
login_button.Bind(wx.EVT_BUTTON, self.on_login)
help_button = wx.Button(self, label='Help')
help_button.Bind(wx.EVT_BUTTON, self.on_help)
# signup_button = wx.Button(self, label='Sign Up')
hbox.Add(login_button, 0, wx.ALL | 200, 20)
# hbox.Add(signup_button, 0, wx.ALL | 200, 20)
hbox.Add(help_button, 0, wx.ALL | 200, 20)
vbox.Add(hbox, 0, wx.ALIGN_CENTER | 100, 5)
self.SetSizer(vbox)
def on_login(self, event):
# check for login verification
settings["username"] = basicText.GetValue()
settings["password"] = pwdText.GetValue()
settings["login"] = True
#OtherFrame()
def on_help(self, event):
HelpFrame()
# Panel with all the login widgets
class HelpPanel(wx.Panel):
def __init__(self, parent):
super(HelpPanel, self).__init__(parent)
self.SetBackgroundColour((44, 51, 51))
# basicLabel = wx.StaticText(self, -1, "Username")
# basicLabel.SetForegroundColour((255,255,255))
# basicText = wx.TextCtrl(self, -1, "", size=(175, -1))
#
# # basicText.SetInsertionPoint(0)
# pwdLabel = wx.StaticText(self, -1, "Password")
# pwdText = wx.TextCtrl(self, -1, "", size=(175, -1), style=wx.TE_PASSWORD)
# pwdLabel.SetForegroundColour((255, 255, 255))
# vbox = wx.BoxSizer(wx.VERTICAL)
# hbox = wx.BoxSizer(wx.HORIZONTAL)
# vbox.Add(basicLabel, 0, wx.ALIGN_CENTER | 100, 5)
# vbox.Add(basicText, 0, wx.ALIGN_CENTER | 100, 5)
# vbox.Add(pwdLabel, 0, wx.ALIGN_CENTER | 100, 5)
# vbox.Add(pwdText, 0, wx.ALIGN_CENTER | 100, 5)
# login_button = wx.Button(self, label='Login')
# login_button.Bind(wx.EVT_BUTTON, self.on_login)
# help_button = wx.Button(self, label='Help')
# # signup_button = wx.Button(self, label='Sign Up')
# hbox.Add(login_button, 0, wx.ALL | 200, 20)
# # hbox.Add(signup_button, 0, wx.ALL | 200, 20)
# hbox.Add(help_button, 0, wx.ALL | 200, 20)
# vbox.Add(hbox, 0, wx.ALIGN_CENTER | 100, 5)
# self.SetSizer(vbox)
class ServerPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent, size=(500, 500))
#self.SetBackgroundColour((44, 51, 51))
main_sizer = wx.BoxSizer(wx.VERTICAL)
secondary_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.row_obj_dict = {}
self.list_ctrl = wx.ListCtrl(
self, size=(-1, 200),
style=wx.LC_REPORT | wx.BORDER_SUNKEN
)
tb = wx.ToolBar( self, -1)
self.ToolBar = tb
tb.SetToolBitmapSize(wx.Size(30, 3))
tb.AddTool(wx.ID_ANY, '',wx.Bitmap(find_data_file("WXPython_30x30.png")),)
tb.AddTool(wx.ID_ANY, '',wx.Bitmap(find_data_file("settings_30x30.png")))
tb.Realize()
main_sizer.Add(tb)
#main_sizer.SetBackgroundColour((44, 51, 51))
# self.pnl1.SetBackgroundColour(wx.BLACK)
self.handle_columns()
global settings
for i in range(len(TEST_FILE)):
self.list_ctrl.InsertItem(i, TEST_FILE.iloc[i, 0])
#fprint(TEST_FILE.iloc[i, 5] + " in " + str(settings["badapps"]))
#if TEST_FILE.iloc[i, 5] in settings["badapps"]:
for pid in settings["badapps"]:
#fprint(pid)
if str(TEST_FILE.iloc[i, 5]) == str(pid):
#fprint("Got " + TEST_FILE.iloc[i, 5])
settings["killbox"].append(pid)
fprint(settings["killbox"])
self.list_ctrl.SetItemBackgroundColour(i, wx.Colour(200, 51, 51))
for j in range(1, 6):
self.list_ctrl.SetItem(i, j, str(TEST_FILE.iloc[i, j]))
#fprint(i, j, TEST_FILE.iloc[i, j])
main_sizer.Add(self.list_ctrl, 0, wx.ALL | wx.EXPAND, 20)
start_button = wx.Button(self, label='Start')
start_button.SetBackgroundColour((205, 215, 206))
start_button.Bind(wx.EVT_BUTTON, self.on_edit)
start_button.Bind(wx.EVT_ENTER_WINDOW, self.on_edit)
stop_button = wx.Button(self, label='Stop')
stop_button.SetBackgroundColour('#F08080')
secondary_frame_button = wx.Button(self, label='Window')
secondary_frame_button.Bind(wx.EVT_BUTTON, self.on_window)
# wx.BORDER(stop_button, wx.BORDER_NONE)
stop_button.Bind(wx.EVT_BUTTON, self.on_edit)
main_sizer.Add(start_button, 0, wx.CENTER | wx.ALL | 100, 5)
main_sizer.Add(stop_button, 0, wx.CENTER | wx.ALL | 100, 5)
main_sizer.Add(secondary_frame_button, 0, wx.CENTER | wx.ALL | 100, 5)
self.SetSizer(main_sizer)
def handle_columns(self):
for col in range(len(COLUMN_NAMES)):
self.list_ctrl.InsertColumn(0, COLUMN_NAMES[col], width=COLUMN_SIZES[col])
def on_edit(self, event):
fprint('in on_edit')
def on_window(self, event):
OtherFrame()
def ShowImage(self, imageFile):
if imageFile == "":
self.bitmap = wx.StaticBitmap(self, -1, size=(0, 0))
else:
bmp = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap = wx.StaticBitmap(self, -1, bmp, (0, 0))
class ServerFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None,
title='Server Dashboard')
self.panel = LoginPanel(self)
# image = wx.StaticBitmap(self, wx.ID_ANY)
# image.SetBitmap(wx.Bitmap('WXPython.png'))
self.Show()
def openwindow(data, sets, kill):
setup_child()
global killme
global settings
global displaydata
killme = kill
displaydata = data
settings = sets
if settings["loggedin"]:
fprint("Creating server panel")
global TEST_FILE
try:
TEST_FILE = pd.read_csv(find_data_file(filename), skiprows=1)
TEST_FILE = TEST_FILE.iloc[1:, :]
TEST_FILE.columns = ['Executable', 'Protocol', 'Source IP', 'Destination IP', 'Status', 'PID']
fprint(TEST_FILE)
fprint(len(TEST_FILE))
#fprint(TEST_FILE.iloc[1, 1])
except FileNotFoundError:
pass
app = wx.App(False)
frame = OtherFrame()
app.MainLoop()
else:
fprint("Creating login panel")
app = wx.App(False)
frame = ServerFrame()
app.MainLoop()
if __name__ == '__main__':
openwindow(list(), dict(), int())
"""class ServerPanel(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
secondary_sizer = wx.BoxSizer(wx.HORIZONTAL)
menubar = wx.MenuBar()
menu = wx.Menu()
menubar.Append(menu,"File")
self.SetMenuBar(menubar)
tb = wx.ToolBar( self, -1)
self.ToolBar = tb
#tb.AddTool( wx.ID_ANY, '', wx.Bitmap("IPPigeonLogo.png"))
tb.AddTool(wx.ID_ANY, '',wx.Bitmap("WXPython_30x30.png"),)
tb.AddTool(wx.ID_ANY, '',wx.Bitmap("settings_30x30.png"))
#tb.Bind(wx.EVT_TOOL, self.Onright)
#tb.Bind(wx.EVT_COMBOBOX,self.OnCombo)
#self.combo = wx.ComboBox( tb, 555, value = "Times", choices = ["Papyrus","Times","Comic Sans"])
#tb.AddControl(self.combo )
tb.Realize()
main_sizer.Add(tb)
self.Show(True)
self.row_obj_dict = {}
self.list_ctrl = wx.ListCtrl(
self, size=(-1, 100),
style=wx.LC_REPORT | wx.BORDER_SUNKEN
)
self.SetBackgroundColour(wx.BLACK)
self.list_ctrl.InsertColumn(0, 'Server name', width=140)
self.list_ctrl.InsertColumn(1, 'Port number', width=140)
self.list_ctrl.InsertColumn(2, 'Status', width=200)
main_sizer.Add(self.list_ctrl, 0, wx.ALL | wx.EXPAND, 5)
start_button = wx.Button(self, label='Start')
start_button.SetBackgroundColour((205, 215, 206))
start_button.Bind(wx.EVT_BUTTON, self.on_edit)
stop_button = wx.Button(self, label='Stop')
stop_button.SetBackgroundColour('#F08080')
# wx.BORDER(stop_button, wx.BORDER_NONE)
stop_button.Bind(wx.EVT_BUTTON, self.on_edit)
main_sizer.Add(start_button, 0, wx.CENTER | 100, 5)
main_sizer.Add(stop_button, 0, wx.CENTER | 100, 5)
# start_button.SetWindowStyleFlag(wx.SIMPLE_BORDER)
# stop_button.SetWindowStyleFlag(wx.SIMPLE_BORDER)
# wx.StaticBitmap(self, -1, png, (500, 300), (png.GetWidth(), png.GetHeight()))
self.SetSizer(main_sizer)
def OnQuit(self, e):
self.Close()
def on_edit(self, event):
print('in on_edit')
def update_mp3_listing(self, folder_path):
print(folder_path)
# def Onright(self, event):
# self.text.AppendText(str(event.GetId())+"\n")
# def OnCombo(self,event):
# self.text.AppendText( self.combo.GetValue()+"\n")
class ServerFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='Server Dashboard')
self.frame = ServerPanel(self)
# image = wx.StaticBitmap(self, wx.ID_ANY)
# image.SetBitmap(wx.Bitmap('WXPython.png'))
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = ServerFrame()
app.MainLoop()"""