Add login functionality (no hashing)
This commit is contained in:
parent
09836efcc4
commit
44166a2507
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ config.yaml
|
||||
admin-key.ppk
|
||||
token.txt
|
||||
*.zip
|
||||
output.log
|
||||
|
26
auth.py
Normal file
26
auth.py
Normal file
@ -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
|
||||
filepath:
|
||||
send: /home/ec2-user/Incoming/Incoming_Data
|
||||
login: /home/ec2-user/Incoming/Login
|
||||
recieve: /home/ec2-user/Outgoing
|
||||
sendlogin: /home/ec2-user/Incoming/Login
|
||||
receive: /home/ec2-user/Outgoing/Outgoing_Data
|
||||
receivelogin: /home/ec2-user/Outgoing/Login
|
||||
scripts: /home/ec2-user/scripts
|
||||
|
||||
ui:
|
||||
darkmode: true
|
||||
|
31
ippigeon.py
31
ippigeon.py
@ -12,6 +12,7 @@ import taskbartool
|
||||
import util
|
||||
import netstat
|
||||
import ssh
|
||||
import auth
|
||||
|
||||
displaydata = None
|
||||
settings = None
|
||||
@ -48,9 +49,14 @@ def netstat_done(res):
|
||||
def process_done(res):
|
||||
fprint("uploading to sftp...")
|
||||
#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():
|
||||
@ -62,8 +68,8 @@ def killall():
|
||||
|
||||
def mainloop(pool):
|
||||
# worker pool: netstat, netstat cleanup, upload, download, ui tasks
|
||||
fprint("start loop")
|
||||
|
||||
global counter
|
||||
global netdata_res
|
||||
global procdata_res
|
||||
global rawdata
|
||||
@ -73,13 +79,25 @@ def mainloop(pool):
|
||||
#print("killing")
|
||||
killall()
|
||||
#print(res.get(timeout=1))
|
||||
if counter == 0: # runs every INTERVAL
|
||||
fprint("start loop")
|
||||
if netdata_res is None or netdata_res.ready():
|
||||
#rawdata = netdata_res.get()
|
||||
#procdata_res = pool.apply_async(process_netstat, (rawdata))
|
||||
fprint("netstat starting")
|
||||
netdata_res = pool.apply_async(netstat.start, callback=netstat_done)
|
||||
#fprint(netdata_res.successful())
|
||||
sleep(interval)
|
||||
|
||||
# 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):
|
||||
def __init__(self, filename="output.log"):
|
||||
@ -114,7 +132,9 @@ if __name__ == '__main__':
|
||||
#print(config['sftp']['host'])
|
||||
interval = config['core']['interval']
|
||||
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 = False
|
||||
# launch background UI app as process
|
||||
@ -128,6 +148,7 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
# launch loop - non-blocking!
|
||||
counter = 0
|
||||
while(keeprunning):
|
||||
mainloop(pool)
|
||||
|
||||
|
45258
output.log
45258
output.log
File diff suppressed because it is too large
Load Diff
33
ssh.py
33
ssh.py
@ -1,14 +1,39 @@
|
||||
#from __future__ import with_statement
|
||||
from fabric import Connection
|
||||
from util import find_data_file
|
||||
from util import setup_child
|
||||
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()
|
||||
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("Sending data over SFTP: " + filename)
|
||||
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath']['send']))
|
||||
fprint("Data sent over SFTP sucessfully")
|
||||
#command = 'ls ' + config['sftp']['filepath']['send']
|
||||
fprint(c.put(find_data_file(filename), remote=config['sftp']['filepath'][filetype]))
|
||||
fprint("Data sent over SFTP successfully")
|
||||
#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'])
|
||||
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):
|
||||
menu = wx.Menu()
|
||||
create_menu_item(menu, 'Control Panel', self.on_open)
|
||||
create_menu_item(menu, 'Login test', self.on_login)
|
||||
menu.AppendSeparator()
|
||||
create_menu_item(menu, 'Exit', self.on_exit)
|
||||
return menu
|
||||
@ -46,6 +47,11 @@ class TaskBarIcon(wx.adv.TaskBarIcon):
|
||||
foreground()
|
||||
#self.close_popup()
|
||||
|
||||
def on_login(self, event):
|
||||
settings["username"] = "Cole"
|
||||
settings["password"] = "12345"
|
||||
settings["login"] = True
|
||||
|
||||
def on_exit(self, event):
|
||||
wx.CallAfter(self.Destroy)
|
||||
self.close_popup()
|
||||
@ -65,6 +71,8 @@ class TaskbarApp(wx.App):
|
||||
|
||||
def background(data, sets, kill):
|
||||
global killme
|
||||
global settings
|
||||
global displaydata
|
||||
killme = kill
|
||||
app = TaskbarApp(False)
|
||||
displaydata = data
|
||||
|
2
util.py
2
util.py
@ -70,7 +70,7 @@ def run_ps(cmd):
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # , "-WindowStyle", "hidden"
|
||||
fprint("running PS command: " + cmd)
|
||||
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)
|
||||
|
||||
return completed
|
||||
|
Loading…
x
Reference in New Issue
Block a user