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

43 lines
1.5 KiB
Python

import ssh
import csv
from util import fprint
from util import find_data_file
from time import sleep
import bcrypt
def login(config, user, password, sysid):
fprint("Attempting to login as " + user)
filename = sysid + "login.csv"
#return True
#hashpasswd = bcrypt.hashpw(password.encode('utf-8'), user).decode()
with open(find_data_file(filename), "w", newline="") as f:
writer = csv.writer(f)
writer.writerows([[user,password,sysid],])
fprint("done creating csv")
#return True
ssh.sftp_send_data(config, filename, 'sendlogin')
command = "python3 login_service.py " + sysid
ssh.run_ssh(config, command, 'scripts')
filename = sysid + "success.txt"
count = 0
while count < 20:
output = ssh.check_for_file(config, filename, 'receivelogin')
if output == False:
filename = sysid + "fail.txt"
if ssh.check_for_file(config, filename, 'receivelogin') == False:
# try again
count += 1
sleep(0.1)
filename = sysid + "success.txt"
#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
return False