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/auth.py

35 lines
1.2 KiB
Python

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"
output = ssh.check_for_file(config, filename, 'receivelogin')
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
else:
fprint(type(output))
if str(output).find("admin") >= 0 or str(output).find("Admin") >= 0:
fprint("Authorized as admin!")
return True
else:
fprint("Not admin")
return False