This repository was archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauthenticate.py
More file actions
151 lines (134 loc) · 4.36 KB
/
authenticate.py
File metadata and controls
151 lines (134 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import requests, time, threading,_thread
import hashlib
from easygui import *
import easygui
import os, sys, socket, json, random, string, getpass
def my_ip():
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(('192.0.0.2',1027))
return s.getsockname()[0]
def basichttpserver(port,username,password):
server_command = "./Server "+server_user+" "+server_pass+" "+str(port)+" > server.log\""
output = os.system(server_command)
def downloader():
try:
hv_file = easygui.fileopenbox() #Does not return the full path
command = "python downloader.py "+ "\""+hv_file+"\""
os.system(command)
except TypeError as e:
return
def server_status():
try:
r = requests.get("http://"+server_user+":"+server_pass+"@localhost:"+str(port))
if r.status_code == 200:
status = 1
except requests.exceptions.RequestException as e:
status = 0
return status
def check_symlinks():
no_of_links = len(data)
i = 4
while i < no_of_links:
path_breakdown = data[i].strip("/")
symlink = path_breakdown[(len(path_breakdown)-1)]
if not os.path.islink(os.getcwd()+"/"+symlink):
#print(os.getcwd()+"/"+symlink)
data[i] = ""
i += 1
server_conf = open("sr.conf","w")
server_conf.writelines(data)
def select_choice():
while True:
if auth == 1:
if server_status() == 1:
print("1.Download\n2.Add Directory\n")
#choice = str(input("Enter 1 or 2 and exit to exit: "))
all_choices = ["Download", "Add Directory","Exit"]
choice = choicebox("You want to download or add a directory to be shared?","Choose",all_choices)
if choice == "Download":
downloader()
continue;
if choice == "Add Directory":
os.system("python3 symlink_adder.py")
send_directory()
continue
if choice == "Exit":
break;
else:
print("Invalid selection!")
else:
print("You seem to have exit the client server cmd prompt. Restarting the Server ...")
start_server()
else:
sys.exit(0)
def send_directory():
os.system("python3 new_lister.py")
file_dat = open("files.json","r")
all_files = file_dat.read()
dir_block = json.loads(all_files)
block = {}
block['username'] = username
block['ipaddr'] = ipaddr
block['server_user'] = server_user
block['server_pass'] = server_pass
block['port'] = port
dir_block["me"] = block
json_dirs = json.dumps(dir_block,separators=(',',':')) #Remove whitespaces
response = requests.post("http://"+localhost+"/direcctorylist.php", data = json_dirs)
def start_server():
server_thread = threading.Thread(target=basichttpserver,args=(port,server_user,server_pass,))
server_thread.setDaemon(True)
server_thread.start()
server_thread.join(5)
try:
server_conf = open("sr.conf","r")
data = server_conf.readlines()
server_user = data[0].strip('Username:').strip('\n')
server_pass = data[1].strip('Password:').strip('\n')
port = int(data[2].strip('Port:').strip('\n'))
localhost = data[3].strip('Localhost:').strip('\n')
server_conf.close()
status = 0 #Server is Offline
version = "1.0.0"
title = "Offline-Authentication"
msg = "Enter your Username and Password"
fields = ["Username","Password"]
check_symlinks()
try:
headers = {'content-type': 'application/json'}
if server_status() == 0:
start_server()
auth = 0
attempts = 5
#Authentication
while auth != 1 and attempts != 0:
username,password = multpasswordbox(msg,title,fields) #GUI
#password = getpass.getpass(prompt="Password: ", stream=None)
ipaddr = my_ip()
r = requests.post("http://"+localhost+"/auth.php", data = {'username':username, 'passw':password, 'ipaddr':ipaddr})
if r.text == '1':
print ("Authentication Successful!")
payload = {'username':username,'version':version}
notification = requests.get("http://"+localhost+"/notification.php",params = payload)
message = notification.text.split(":")
print(message[0])
stop = 0
if message[1] == "stop":
stop = 1
auth = 1
if stop == 0:
send_directory()
break;
elif attempts != 0:
if attempts != 1:
print("Authentication Failed! Try Again.")
attempts-=1
print("Attemps remaining "+str(attempts))
if stop == 1:
print("This client software will not work.")
sys.exit(0)
select_choice()
except requests.exceptions.RequestException as e:
print("Server is not live. Please try again later!")
except FileNotFoundError:
print("Sr.conf file not found. Make sure to download it and place it in the current directory.")