Add UI import, add login to UI, etc

formac 1666032655
Cole Deck 2 years ago
parent 5c7cd9b0a5
commit 578eea1c1f

@ -20,6 +20,8 @@ def login(config, user, password, sysid):
if output == False:
filename = sysid + "fail.txt"
if ssh.check_for_file(config, filename, 'receivelogin') == False:
# ALERT: DIRTY HACK: SECURITY VULNERABILITY
#return True
raise ValueError("Unable to determine login status")
else:
return False

@ -1,138 +0,0 @@
import glob
import wx
import wx.adv
import os
from time import sleep
from multiprocessing import Process, Pipe
from sys import platform
TRAY_TOOLTIP = 'IP Pigeon'
TRAY_ICON = 'icon.png'
"""if platform == "linux" or platform == "linux2":
# linux
elif platform == "darwin":
# OS X
elif platform == "win32":
# Windows...
"""
displaydata = None
settings = None
class ServerPanel(wx.Panel):
def __init__(self, parent):
super().__init__(parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
self.row_obj_dict = {}
self.list_ctrl = wx.ListCtrl(
self, size=(-1, 100),
style=wx.LC_REPORT | wx.BORDER_SUNKEN
)
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.Bind(wx.EVT_BUTTON, self.on_edit)
stop_button = wx.Button(self, label='Stop')
stop_button.Bind(wx.EVT_BUTTON, self.on_edit)
main_sizer.Add(start_button, 0, wx.ALL | 100, 5)
main_sizer.Add(stop_button, 0, wx.ALL | 100, 5)
self.SetSizer(main_sizer)
def on_edit(self, event):
print('in on_edit')
def update_mp3_listing(self, folder_path):
print(folder_path)
class ServerFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None,
title='Server Dashboard')
self.panel = ServerPanel(self)
self.Show()
### Taskbar Icon
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.Append(item)
return item
class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
self.frame = frame
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Control Panel', self.on_open)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.Icon(path)
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
print ('Tray icon was left-clicked.')
def on_open(self, event):
foreground()
#self.close_popup()
def on_exit(self, event):
wx.CallAfter(self.Destroy)
self.close_popup()
def close_popup(self):
self.frame.Close()
class TaskbarApp(wx.App):
def OnInit(self):
frame=wx.Frame(None)
self.SetTopWindow(frame)
TaskBarIcon(frame)
return True
class FullApp(wx.App):
def OnInit(self):
fullframe=ServerFrame()
return True
def background():
app = TaskbarApp(False)
#with Manager() as manager:
app.MainLoop()
#displaydata = manager.list()
#settings = manager.list()
#rawdata = manager.list()
#logdata = manager.list()
#uploaddata = manager.list()
#downloaddata = manager.list()
def open_fg(outputdata, uisettings):
app = FullApp(False)
app.MainLoop()
def foreground():
# Open the foreground in a separate process so that UI acts independently of the taskbar icon
p = Process(target=open_fg, args=(displaydata, settings))
p.start()
#p.join()
print("Launched foreground")
if __name__ == '__main__':
background()

@ -13,12 +13,14 @@ import util
import netstat
import ssh
import auth
import panel
displaydata = None
settings = None
netdata_res = None
procdata_res = None
killme = None
ppanel = None
datafile = ""
#print(datafile)
config = None
@ -67,6 +69,8 @@ def login_done(res):
settings["message"] = "Login failure"
else:
fprint("Login result in main: " + str(res))
settings["loggedin"] = res
settings["continueui"] = True
def killall():
@ -84,6 +88,7 @@ def mainloop(pool):
global procdata_res
global rawdata
global killme
global ppanel
#print(killme)
if killme.value > 0:
#print("killing")
@ -99,10 +104,26 @@ def mainloop(pool):
#fprint(netdata_res.successful())
# runs every 50ms
if settings["continueui"] == True:
settings["continueui"] = False
if ppanel is not None:
# login panel is already open
ppanel.terminate()
ppanel = Process(target=panel.openwindow, args=(displaydata,settings,killme))
ppanel.start()
if settings["showui"] == True:
settings["showui"] = False
ppanel = Process(target=panel.openwindow, args=(displaydata,settings,killme))
ppanel.start()
if settings["login"] == True:
login_res = pool.apply_async(auth.login, (config, settings["username"], settings["password"], sysid), callback=login_done)
#fprint(auth.login(config, settings["username"], settings["password"], sysid))
settings["login"] = False
sleep(interval / (interval * 20.0))
counter += 1
@ -145,6 +166,8 @@ if __name__ == '__main__':
settings = manager.dict() # configuration
settings["login"] = False
settings["loggedin"] = False
settings["showui"] = False
settings["continueui"] = False
killme = manager.Value('d', 0)
#killme = False
# launch background UI app as process

File diff suppressed because it is too large Load Diff

@ -2,3 +2,4 @@ fabric
paramiko
wxpython
cx_Freeze
pandas

@ -45,8 +45,8 @@ class TaskBarIcon(wx.adv.TaskBarIcon):
fprint ('Tray icon was left-clicked.')
def on_open(self, event):
foreground()
#self.close_popup()
settings["showui"] = True
self.close_popup()
def on_login(self, event):
settings["username"] = "frontend"
@ -55,10 +55,11 @@ class TaskBarIcon(wx.adv.TaskBarIcon):
def on_exit(self, event):
wx.CallAfter(self.Destroy)
self.close_popup()
#print("kill cmd")
global killme
killme.value += 1
self.close_popup()
#print("kill cmd")
def close_popup(self):
self.frame.Close()

Loading…
Cancel
Save