Add login functionality (no hashing)

formac 1665470225
Cole Deck 2 years ago
parent 09836efcc4
commit 44166a2507

3
.gitignore vendored

@ -4,4 +4,5 @@ config.yaml
*.csv *.csv
admin-key.ppk admin-key.ppk
token.txt token.txt
*.zip *.zip
output.log

@ -0,0 +1,26 @@
import ssh
import csv
from util import fprint
from util import find_data_file
from time import sleep
def login(config, user, password, sysid):
fprint("Attempting to login as " + user)
filename = sysid + "login.csv"
with open(find_data_file(filename), "w", newline="") as f:
writer = csv.writer(f)
writer.writerows([[user,password,sysid],])
fprint("done creating csv")
ssh.sftp_send_data(config, filename, 'sendlogin')
command = "python3 login_service.py " + sysid
ssh.run_ssh(config, command, 'scripts')
sleep(1)
filename = sysid + "success.txt"
if ssh.check_for_file(config, filename, 'receivelogin') == False:
filename = sysid + "fail.txt"
if ssh.check_for_file(config, filename, 'receivelogin') == False:
raise ValueError("Unable to determine login status")
else:
return False
else:
return True

@ -5,8 +5,10 @@ sftp:
keyfile: keyfile-admin.pem keyfile: keyfile-admin.pem
filepath: filepath:
send: /home/ec2-user/Incoming/Incoming_Data send: /home/ec2-user/Incoming/Incoming_Data
login: /home/ec2-user/Incoming/Login sendlogin: /home/ec2-user/Incoming/Login
recieve: /home/ec2-user/Outgoing receive: /home/ec2-user/Outgoing/Outgoing_Data
receivelogin: /home/ec2-user/Outgoing/Login
scripts: /home/ec2-user/scripts
ui: ui:
darkmode: true darkmode: true

@ -12,6 +12,7 @@ import taskbartool
import util import util
import netstat import netstat
import ssh import ssh
import auth
displaydata = None displaydata = None
settings = None settings = None
@ -48,9 +49,14 @@ def netstat_done(res):
def process_done(res): def process_done(res):
fprint("uploading to sftp...") fprint("uploading to sftp...")
#ssh.sftp_send_data(res, config, datafile) #ssh.sftp_send_data(res, config, datafile)
procdata_res = pool.apply_async(ssh.sftp_send_data, (res, config, datafile)) procdata_res = pool.apply_async(ssh.sftp_send_data, (config, datafile, 'send'))
def login_done(res):
if not res:
fprint("Login failure")
settings["message"] = "Login failure"
else:
fprint("Login result in main: " + str(res))
def killall(): def killall():
@ -62,8 +68,8 @@ def killall():
def mainloop(pool): def mainloop(pool):
# worker pool: netstat, netstat cleanup, upload, download, ui tasks # worker pool: netstat, netstat cleanup, upload, download, ui tasks
fprint("start loop")
global counter
global netdata_res global netdata_res
global procdata_res global procdata_res
global rawdata global rawdata
@ -73,13 +79,25 @@ def mainloop(pool):
#print("killing") #print("killing")
killall() killall()
#print(res.get(timeout=1)) #print(res.get(timeout=1))
if netdata_res is None or netdata_res.ready(): if counter == 0: # runs every INTERVAL
#rawdata = netdata_res.get() fprint("start loop")
#procdata_res = pool.apply_async(process_netstat, (rawdata)) if netdata_res is None or netdata_res.ready():
fprint("netstat starting") #rawdata = netdata_res.get()
netdata_res = pool.apply_async(netstat.start, callback=netstat_done) #procdata_res = pool.apply_async(process_netstat, (rawdata))
#fprint(netdata_res.successful()) fprint("netstat starting")
sleep(interval) netdata_res = pool.apply_async(netstat.start, callback=netstat_done)
#fprint(netdata_res.successful())
# runs every 50ms
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
if counter == interval * 20:
counter = 0
class Logger(object): class Logger(object):
def __init__(self, filename="output.log"): def __init__(self, filename="output.log"):
@ -114,7 +132,9 @@ if __name__ == '__main__':
#print(config['sftp']['host']) #print(config['sftp']['host'])
interval = config['core']['interval'] interval = config['core']['interval']
displaydata = manager.list(range(2)) # data to be printed displaydata = manager.list(range(2)) # data to be printed
settings = manager.list(range(20)) # configuration settings = manager.dict() # configuration
settings["login"] = False
settings["loggedin"] = False
killme = manager.Value('d', 0) killme = manager.Value('d', 0)
#killme = False #killme = False
# launch background UI app as process # launch background UI app as process
@ -128,6 +148,7 @@ if __name__ == '__main__':
# launch loop - non-blocking! # launch loop - non-blocking!
counter = 0
while(keeprunning): while(keeprunning):
mainloop(pool) mainloop(pool)

File diff suppressed because it is too large Load Diff

@ -1,14 +1,39 @@
#from __future__ import with_statement
from fabric import Connection from fabric import Connection
from util import find_data_file from util import find_data_file
from util import setup_child from util import setup_child
from util import fprint from util import fprint
from invoke import exceptions
import sys
def sftp_send_data(res, config, filename): def sftp_send_data(config, filename, filetype):
setup_child() setup_child()
fprint("Connecting over SSH to " + config['sftp']['host']) fprint("Connecting over SSH to " + config['sftp']['host'])
c = Connection(host=config['sftp']['host'], user=config['sftp']['user'], port=config['sftp']['port'], connect_kwargs={"key_filename": find_data_file(config['sftp']['keyfile']),}) 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("Sending data over SFTP: " + filename)
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath']['send'])) fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath'][filetype]))
fprint("Data sent over SFTP sucessfully") fprint("Data sent over SFTP successfully")
#command = 'ls ' + config['sftp']['filepath']['send'] #command = 'ls ' + config['sftp']['filepath'][filetype]
#fprint(c.run(command)) #fprint(c.run(command))
def check_for_file(config, filename, location):
setup_child()
fprint("Connecting over SSH to " + config['sftp']['host'])
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)
try:
res = c.run("ls -l " + config['sftp']['filepath'][location] + "/" + filename, hide=True)
fprint("File " + filename + " exists!")
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'])
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])
with c.cd(config['sftp']['filepath'][location]):
fprint("Running ssh command: " + command)
res = c.run(command, hide=True, asynchronous=True)
return res

@ -31,6 +31,7 @@ class TaskBarIcon(wx.adv.TaskBarIcon):
def CreatePopupMenu(self): def CreatePopupMenu(self):
menu = wx.Menu() menu = wx.Menu()
create_menu_item(menu, 'Control Panel', self.on_open) create_menu_item(menu, 'Control Panel', self.on_open)
create_menu_item(menu, 'Login test', self.on_login)
menu.AppendSeparator() menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit) create_menu_item(menu, 'Exit', self.on_exit)
return menu return menu
@ -46,6 +47,11 @@ class TaskBarIcon(wx.adv.TaskBarIcon):
foreground() foreground()
#self.close_popup() #self.close_popup()
def on_login(self, event):
settings["username"] = "Cole"
settings["password"] = "12345"
settings["login"] = True
def on_exit(self, event): def on_exit(self, event):
wx.CallAfter(self.Destroy) wx.CallAfter(self.Destroy)
self.close_popup() self.close_popup()
@ -65,6 +71,8 @@ class TaskbarApp(wx.App):
def background(data, sets, kill): def background(data, sets, kill):
global killme global killme
global settings
global displaydata
killme = kill killme = kill
app = TaskbarApp(False) app = TaskbarApp(False)
displaydata = data displaydata = data

@ -70,7 +70,7 @@ def run_ps(cmd):
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # , "-WindowStyle", "hidden" startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # , "-WindowStyle", "hidden"
fprint("running PS command: " + cmd) fprint("running PS command: " + cmd)
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo) completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
fprint("ran PS command sucessfully") fprint("ran PS command successfully")
#completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo) #completed = subprocess.run(["powershell", "-WindowStyle", "hidden", "-Command", cmd], capture_output=True, startupinfo=startupinfo)
return completed return completed

Loading…
Cancel
Save