Skip to content

Commit 319d034

Browse files
author
6nz
authored
Changed some lines
Removed unused module, added connection check and timeout, error handling, added requests session, changed a few lines
1 parent 05e3c6f commit 319d034

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

keyauth.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import win32security #get sid
1+
import win32security # get sid
22
import json as jsond # json
33

44
import time # sleep before exit
@@ -8,22 +8,31 @@
88
from uuid import uuid4 # gen random guid
99
import platform
1010
import os
11-
import requests # https requests
12-
from requests_toolbelt.adapters.fingerprint import FingerprintAdapter
11+
import requests # https requests
1312

1413
try:
1514
from Crypto.Cipher import AES
1615
from Crypto.Hash import SHA256
17-
from Crypto.Util.Padding import pad, unpad
16+
from Crypto.Util.Padding import pad, unpad
1817
except ModuleNotFoundError:
1918
print("Exception when importing modules")
2019
print("installing necessary modules....")
2120
os.system("pip install pycryptodome")
2221
print("Modules installed!")
2322
time.sleep(1.5)
24-
exit(0)
23+
os._exit(1)
24+
25+
try: # Connection check
26+
s = requests.Session() # Session
27+
s.get('https://google.com')
28+
except requests.exceptions.RequestException as e:
29+
print(e)
30+
time.sleep(3)
31+
os._exit(1)
32+
2533

2634
class api:
35+
2736
name = ownerid = secret = version = hash_to_check = ""
2837

2938
def __init__(self, name, ownerid, secret, version, hash_to_check):
@@ -45,7 +54,7 @@ def init(self):
4554
if self.sessionid != "":
4655
print("You've already initialized!")
4756
time.sleep(2)
48-
exit(0)
57+
os._exit(1)
4958
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
5059

5160
self.enckey = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
@@ -87,8 +96,6 @@ def init(self):
8796
self.initialized = True
8897
self.__load_app_data(json["appinfo"])
8998

90-
91-
9299
def register(self, user, password, license, hwid=None):
93100
self.checkinit()
94101
if hwid is None:
@@ -142,6 +149,7 @@ def upgrade(self, user, license):
142149
if json["success"]:
143150
print("successfully upgraded user")
144151
print("please restart program and login")
152+
time.sleep(2)
145153
os._exit(1)
146154
else:
147155
print(json["message"])
@@ -271,13 +279,13 @@ def setvar(self, var_name, var_data):
271279
response = self.__do_request(post_data)
272280
response = encryption.decrypt(response, self.enckey, init_iv)
273281
json = jsond.loads(response)
274-
282+
275283
if json["success"]:
276284
return True
277285
else:
278286
print(json["message"])
279287
time.sleep(5)
280-
os._exit(1)
288+
os._exit(1)
281289

282290
def ban(self):
283291
self.checkinit()
@@ -292,13 +300,13 @@ def ban(self):
292300
response = self.__do_request(post_data)
293301
response = encryption.decrypt(response, self.enckey, init_iv)
294302
json = jsond.loads(response)
295-
303+
296304
if json["success"]:
297305
return True
298306
else:
299307
print(json["message"])
300308
time.sleep(5)
301-
os._exit(1)
309+
os._exit(1)
302310

303311
def file(self, fileid):
304312
self.checkinit()
@@ -406,8 +414,8 @@ def log(self, message):
406414
}
407415

408416
self.__do_request(post_data)
409-
410-
def fetchOnline(self):
417+
418+
def fetchOnline(self):
411419
self.checkinit()
412420
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
413421

@@ -423,13 +431,13 @@ def fetchOnline(self):
423431
response = encryption.decrypt(response, self.enckey, init_iv)
424432

425433
json = jsond.loads(response)
426-
434+
427435
if json["success"]:
428436
if len(json["users"]) == 0:
429-
return None ## THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022 so it will return none if it is not an array.
430-
else:
437+
return None # THIS IS ISSUE ON KEYAUTH SERVER SIDE 6.8.2022, so it will return none if it is not an array.
438+
else:
431439
return json["users"]
432-
else:
440+
else:
433441
return None
434442

435443
def chatGet(self, channel):
@@ -455,7 +463,7 @@ def chatGet(self, channel):
455463
else:
456464
return None
457465

458-
def chatSend(self, message, channel):
466+
def chatSend(self, message, channel):
459467
self.checkinit()
460468
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
461469

@@ -482,19 +490,22 @@ def chatSend(self, message, channel):
482490
def checkinit(self):
483491
if not self.initialized:
484492
print("Initialize first, in order to use the functions")
493+
time.sleep(2)
485494
os._exit(1)
486495

487496
def __do_request(self, post_data):
488-
489-
rq_out = requests.post(
490-
"https://keyauth.win/api/1.0/", data=post_data
491-
)
492-
493-
return rq_out.text
497+
try:
498+
rq_out = s.post(
499+
"https://keyauth.win/api/1.0/", data=post_data, timeout=30
500+
)
501+
return rq_out.text
502+
except requests.exceptions.Timeout:
503+
print("Request timed out")
494504

495505
class application_data_class:
496506
numUsers = numKeys = app_ver = customer_panel = onlineUsers = ""
497507
# region user_data
508+
498509
class user_data_class:
499510
username = ip = hwid = expires = createdate = lastlogin = subscription = subscriptions = ""
500511

@@ -519,7 +530,6 @@ def __load_user_data(self, data):
519530
self.user_data.subscriptions = data["subscriptions"]
520531

521532

522-
523533
class others:
524534
@staticmethod
525535
def get_hwid():

0 commit comments

Comments
 (0)