-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
354 lines (322 loc) · 13.8 KB
/
run.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import sys, os
import subprocess
from tkinter import Tk, filedialog
from tkinter import *
import json
from cryptography.fernet import Fernet
from threading import Thread
from hurry.filesize import size
from functools import partial
import requests
import time
import extract
from tqdm import tqdm
import os
import sys
from pathlib import Path
import requests
import webbrowser
# This example script downloads python program for mac.
# Home directory of Mac, pathlib.Path module make this easy.
#home_path = Path.home()
# This is the sub directory under home directory.
#sub_path = "tmp"
# The download link of python.
#url = "https://www.python.org/ftp/python/3.8.5/python-3.8.5-macosx10.9.pkg"
# The header of the dl link has a Content-Length which is in bytes.
# The bytes is in string hence has to convert to integer.
#filesize = int(requests.head(url).headers["Content-Length"])
# os.path.basename returns python-3.8.5-macosx10.9.pkg,
# without this module I will have to manually split the url by "/"
# then get the last index with -1.
# Example:
# url.split("/")[-1]
#filename = os.path.basename(url)
# make the sub directory, exists_ok=True will not have exception if the sub dir does not exists.
# the dir will be created if not exists.
#os.makedirs(os.path.join(home_path, sub_path), exist_ok=True)
# The absolute path to download the python program to.
#dl_path = os.path.join(home_path, sub_path, filename)
#chunk_size = 1024
# Use the requests.get with stream enable, with iter_content by chunk size,
# the contents will be written to the dl_path.
# tqdm tracks the progress by progress.update(datasize)
#with requests.get(url, stream=True) as r, open(dl_path, "wb") as f, tqdm(
# unit="B", # unit string to be displayed.
# unit_scale=True, # let tqdm to determine the scale in kilo, mega..etc.
# unit_divisor=1024, # is used when unit_scale is true
# total=filesize, # the total iteration.
# file=sys.stdout, # default goes to stderr, this is the display on console.
# desc=filename # prefix to be displayed on progress bar.
#) as progress:
# for chunk in r.iter_content(chunk_size=chunk_size):
# # download the file chunk by chunk
# datasize = f.write(chunk)
# # on each chunk update the progress bar.
# progress.update(datasize)
def checks():
print('Performing Checks...')
fs = fileSystem()
fs.cf('data')
fs.cf('data/cache')
fs.cf('data/user')
fs.cf('data/logs')
def extractFiles():
key = Fernet(b'')
for f in extract.files:
try:
data = json.loads(f)
for p in data['Config']:
with open(p['filename'], 'wb') as outf:
outf.write(key.decrypt(p['content'].encode()))
except Exception as e:
print(e)
class fileSystem:
def __init__(self):
pass
def cf(self, folder):
if os.path.isdir(folder):
print(folder + ' Exists')
else:
try:
os.mkdir(folder)
print('Created ' + folder)
except:
pass
class Error:
def __init__(self, title, content):
self.error = Tk()
self.error.title(title)
Label(self.error, text=content).pack()
Button(self.error, text='Close', command=self.destroy)
def destroy(self):
self.error.destroy()
class Auth:
"""
Auths the user (Used for logging in / Performing actions)
"""
def __init__(self):
pass
def validateLogin(self, username, password, msg, log):
key = Fernet(b'')
data = {}
data['Config'] = []
data['Config'].append({
'email': str(username.get()),
'password': str(password.get())
})
try:
x = requests.post('http://vnodehost.com/api/login', data=key.encrypt(json.dumps(data).encode()))
except Exception as e:
print(e)
print(x.text)
if x.text == '-':
msg.get('Email or password incorrect!')
else:
try:
data = json.loads(x.text)
for p in data['Config']:
#print('User: {}\n'
# 'Status: {}\n'
# 'Password: {}'.format(p['user'], p['status'], p['pw']))
if p['term'] == True:
print('Account was terminated, visit discord to find out why.')
m = Error(title='Account was terminated', content='Your account was terminated, please visit our discord for more info')
dta = {}
dta['Config'] = []
dta['Config'].append({
'user': p['user'],
'email': p['email'],
'pw': p['pw'],
'acc': p['acc'],
'type': p['type'],
})
with open('data/user/data.data', 'wb') as jsf:
jsf.write(key.encrypt(json.dumps(dta).encode()))
try:
log.destroy()
except:
pass
Main().dashboard()
# Encrypt data file
# Create Dashboard
# Create more API (Dashboard, Uploads, Server)
# Termination Message
except Exception as e:
print('oop ' + e)
#print(username.get(), password.get())
class Get:
def __init__(self):
pass
def text(self, api):
try:
x = request.get('http://vnodehost.com/api/{}'.format(api))
return x.text
except:
return False
class Main:
"""
Main application
"""
def __init__(self):
self.open = True
def UploadAction(self, dash, uploadStatus, email, pw):
key = Fernet(b'')
filename = filedialog.askopenfilenames()
total_size = 0
filec = 0
bfc = 0
for f in filename:
try:
bfc += os.path.getsize(f)
except:
pass
start = time.time()
for fp in tqdm(filename, unit='file'):
if not os.path.islink(fp):
uploadStatus.set('Uploading {}... ({})({} Seconds)'.format(fp, size(os.path.getsize(fp)), round(time.time()-start)))
total_size += os.path.getsize(fp)
#print('{}: {} ({})'.format(fp, size(os.path.getsize(fp)), os.path.getsize(fp)))
filec += 1
#print('{} / {} ({} / {})'.format(filec, len(list(filename)), size(total_size), total_size), end='\r')
try:
x = requests.post('http://vnodehost.com/api/storage/upload', json={'email': email, 'pw': pw, 'filename': fp, 'content': key.encrypt(open(fp, 'r').read().encode()).decode()})
if x.text == '+':
print('\n[Upload] Uploaded {} ({})\n'.format(fp, size(os.path.getsize(fp))))
#print(x.text)
except:
try:
x = requests.post('http://vnodehost.com/api/storage/upload', json={'email': email, 'pw': pw, 'filename': fp, 'content': key.encrypt(open(fp, 'rb').read()).decode()})
print('\n[Upload] Uploaded {} ({})\n'.format(fp, size(os.path.getsize(fp))))
#print(x.text)
except Exception as e:
print('\nUnable to upload {} | {}\n'.format(fp, e))
print('Uploaded:', size(total_size), total_size)
uploadStatus.set('Uploaded! ({} in {} seconds)'.format(size(total_size), round(time.time()-start)))
def logout(self, dash):
try:
if os.path.isfile('data/user/data.data'):
os.remove('data/user/data.data')
else:
print('Unable to logout!')
except Exception as e:
print(e)
def getFiles(self, storageFiles, user, email, pw):
time.sleep(2)
while True:
if self.open == False:
sys.exit()
try:
print(storageFiles.get(storageFiles.curselection()))
except Exception as e:
print(e)
try:
x = requests.post('http://vnodehost.com/api/storage/files', json={'user': user, 'email': email, 'pw': pw})
if x.text == '-':
storageFiles.insert(END, 'Error Getting Storage')
else:
try:
storageFiles.delete(0,END)
except Exception as e:
print(e)
try:
for f in x.text.split(','):
storageFiles.insert(END, f.replace('[', '').replace(']', '').replace("'", ""))
#storageFiles.insert(END, x.text)
except:
storageFiles.insert(END, 'Error Getting Storage')
except Exception as e:
storageFiles.insert(END, 'Error Getting Storage | {}'.format(e))
time.sleep(20)
def getStorage(self, user, storageleft):
time.sleep(2)
while True:
if self.open == False:
sys.exit()
try:
x = requests.post('http://vnodehost.com/api/storage/get', json={'user': user})
if x.text == '-':
storageleft.set('Error Getting Storage')
else:
try:
data = json.loads(x.text)
#print(x.text)
for p in data['Config']:
storageleft.set('{} / {}'.format(p['left'], p['amt']))
except:
storageleft.set('Error Getting Storage')
except:
storageleft.set('No internet connection!')
time.sleep(10)
def uploadGo(self, dash, uploadStatus, email, pw):
Thread(target=lambda:Main().UploadAction(dash, uploadStatus, email, pw)).start()
def Cur(self, storageFiles):
try:
print(storageFiles.get(storageFiles.curselection()))
except Exception as e:
print(e)
def minecraft(self, dash, user):
dash.title('Minecraft Dashboard - VNode')
Label(dash, text='Dashboard | Minecraft').pack()
def storage(self, dash, user, email, pw):
dash.title('Storage Dashboard - VNode')
Label(dash, text='Dashboard | Storage | {}'.format(email)).pack()
storageleft = StringVar()
storageleft.set('0B / 0B')
uploadStatus = StringVar()
Label(dash, textvariable=uploadStatus).pack()
Label(dash, textvariable=storageleft).pack()
Thread(target=lambda:Main().getStorage(user, storageleft)).start()
Button(dash, text='Open', command=lambda:self.uploadGo(dash, uploadStatus, email, pw)).pack()
storageFiles = Listbox(dash, height = 20, width = 40)
storageFiles.bind('<<ListboxSelect>>',self.Cur(storageFiles))
storageFiles.pack()
Thread(target=lambda:Main().getFiles(storageFiles, user, email, pw)).start()
Label(textvariable=storageFiles).pack()
def login(self):
log = Tk()
log.title('VNode - Login')
log.iconbitmap('icon.ico')
msg = StringVar()
#stat = Label(log, textvariable=msg)
#stat.pack()
usernameLabel = Label(log, text="Email").grid(row=0, column=0)
username = StringVar()
usernameEntry = Entry(log, textvariable=username).grid(row=0, column=1)
passwordLabel = Label(log,text="Password").grid(row=1, column=0)
password = StringVar()
passwordEntry = Entry(log, textvariable=password, show='*').grid(row=1, column=1)
validateLogin = partial(Auth().validateLogin, username, password, msg, log)
loginButton = Button(log, text="Login", command=validateLogin).grid(row=4, column=0)
log.mainloop()
def dashboard(self):
key = Fernet(b'')
if os.path.isfile('data/user/data.data'):
with open('data/user/data.data', 'rb') as jsf:
p = key.decrypt(jsf.read())
data = json.loads(p.decode())
for f in data['Config']:
print(data)
dash = Tk()
dash.title('Dashboard - VNode')
dash.geometry("500x500")
dash.iconbitmap('icon.ico')
#logo = Button(dash, text='Logout', comamnd=Main().logout(dash)).pack()
#[WinError 32] The process cannot access the file because it is being used by another process: 'data/user/data.data'
webs = Button(dash, text='VNode', command=lambda:webbrowser.open('https://vnodehost.com')).pack()
#if f['acc'] == 'mc':
# self.minecraft(dash, f['user'])
if f['acc'] == 'storage':
self.storage(dash, f['user'], f['email'], f['pw'])
#self.storage(dash, f['user'], f['email'], p['pw'])
else:
e = Error('Not currently supported!', '{} is not currently supported'.format(f['acc']))
dash.mainloop()
print('Loop has ended')
self.open = False
else:
self.login()
extractFiles()
checks()
m = Main()
m.dashboard()