forked from KeyAuth/KeyAuth-Python-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
279 lines (229 loc) · 10 KB
/
main.py
File metadata and controls
279 lines (229 loc) · 10 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
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
import sys
from keyauth import api
import time
import os
import hashlib
from time import sleep
from datetime import datetime
# import json as jsond
# ^^ only for auto login/json writing/reading
# watch setup video if you need help https://www.youtube.com/watch?v=L2eAQOmuUiA
os.system("cls & title Python Example")
print("Initializing")
def getchecksum():
md5_hash = hashlib.md5()
file = open(''.join(sys.argv), "rb")
md5_hash.update(file.read())
digest = md5_hash.hexdigest()
return digest
keyauthapp = api(
name = "", #App name (Manage Applications --> Application name)
ownerid = "", #Owner ID (Account-Settings --> OwnerID)
secret = "", #App secret(Manage Applications --> App credentials code)
version = "1.0",
hash_to_check = getchecksum()
)
print(f"""1
App data:
Number of users: {keyauthapp.app_data.numUsers}
Number of online users: {keyauthapp.app_data.onlineUsers}
Number of keys: {keyauthapp.app_data.numKeys}
Application Version: {keyauthapp.app_data.app_ver}
Customer panel link: {keyauthapp.app_data.customer_panel}
""")
print(f"Current Session Validation Status: {keyauthapp.check()}")
print(f"Blacklisted? : {keyauthapp.checkblacklist()}") # check if blacklisted, you can edit this and make it exit the program if blacklisted
def answer():
try:
print("""
1.Login
2.Register
3.Upgrade
4.License Key Only
""")
ans = input("Select Option: ")
if ans == "1":
user = input('Provide username: ')
password = input('Provide password: ')
keyauthapp.login(user, password)
elif ans == "2":
user = input('Provide username: ')
password = input('Provide password: ')
license = input('Provide License: ')
keyauthapp.register(user, password, license)
elif ans == "3":
user = input('Provide username: ')
license = input('Provide License: ')
keyauthapp.upgrade(user, license)
elif ans == "4":
key = input('Enter your license: ')
keyauthapp.license(key)
else:
print("\nNot Valid Option")
time.sleep(1)
os.system('cls')
answer()
except KeyboardInterrupt:
os._exit(1)
answer()
# region Extra Functions
# * Download Files form the server to your computer using the download function in the api class
# bytes = keyauthapp.download("FILEID")
# f = open("example.exe", "wb")
# f.write(bytes)
# f.close()
# * Set up user variable
# keyauthapp.setvar("varName", "varValue")
# * Get user variable and print it
# data = keyauthapp.getvar("varName")
# print(data)
# * Get normal variable and print it
# data = keyauthapp.var("varName")
# print(data)
# * Log message to the server and then to your webhook what is set on app settings
# keyauthapp.log("Message")
# * Get if the user pc have been blacklisted
# print(f"Blacklisted? : {keyauthapp.checkblacklist()}")
# * See if the current session is validated
# print(f"Session Validated?: {keyauthapp.check()}")
# * example to send normal request with no POST data
# data = keyauthapp.webhook("WebhookID", "?type=resetuser&user=username")
# * example to send form data
# data = keyauthapp.webhook("WebhookID", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded")
# * example to send JSON
# data = keyauthapp.webhook("WebhookID", "", "{\"content\": \"webhook message here\",\"embeds\": null}", "application/json")
# * Get chat messages
# messages = keyauthapp.chatGet("CHANNEL")
# Messages = ""
# for i in range(len(messages)):
# Messages += datetime.utcfromtimestamp(int(messages[i]["timestamp"])).strftime('%Y-%m-%d %H:%M:%S') + " - " + messages[i]["author"] + ": " + messages[i]["message"] + "\n"
# print("\n\n" + Messages)
# * Send chat message
# keyauthapp.chatSend("MESSAGE", "CHANNEL")
# * Auto-Login Example (THIS IS JUST AN EXAMPLE --> YOU WILL HAVE TO EDIT THE CODE PROBABLY)
# 1. Checking and Reading JSON
#### Note: Remove the ''' on line 140 and 199
'''try:
if os.path.isfile('auth.json'): #Checking if the auth file exist
if jsond.load(open("auth.json"))["authusername"] == "": #Checks if the authusername is empty or not
print("""
1. Login
2. Register
""")
ans=input("Select Option: ") #Skipping auto-login bc auth file is empty
if ans=="1":
user = input('Provide username: ')
password = input('Provide password: ')
keyauthapp.login(user,password)
elif ans=="2":
user = input('Provide username: ')
password = input('Provide password: ')
license = input('Provide License: ')
keyauthapp.register(user,password,license)
else:
print("\nNot Valid Option")
os._exit(1)
else:
try: #2. Auto login
with open('auth.json', 'r') as f:
authfile = jsond.load(f)
authuser = authfile.get('authusername')
authpass = authfile.get('authpassword')
keyauthapp.login(authuser,authpass)
except Exception as e: #Error stuff
print(e)
else: #Creating auth file bc its missing
try:
f = open("auth.json", "a") #Writing content
f.write("""{
"authusername": "",
"authpassword": ""
}""")
f.close()
print ("""
1. Login
2. Register
""")#Again skipping auto-login bc the file is empty/missing
ans=input("Select Option: ")
if ans=="1":
user = input('Provide username: ')
password = input('Provide password: ')
keyauthapp.login(user,password)
elif ans=="2":
user = input('Provide username: ')
password = input('Provide password: ')
license = input('Provide License: ')
keyauthapp.register(user,password,license)
else:
print("\nNot Valid Option")
os._exit(1)
except Exception as e: #Error stuff
print(e)
os._exit(1)
except Exception as e: #Error stuff
print(e)
os._exit(1)'''
# Writing user data on login:
# Check Keyauth.py file --> Line 158
# Replace the whole login function with this login function (This has auto user data dumping, so the user only have to log in once), don't forget to remove the ''' on line 206,243
# Note: The auto login function above is needed for this bc it creates the auth file, if the auth file is missing this won't work
'''def login(self, user, password, hwid=None):
self.checkinit()
if hwid is None:
hwid = others.get_hwid()
init_iv = SHA256.new(str(uuid4())[:8].encode()).hexdigest()
post_data = {
"type": binascii.hexlify(("login").encode()),
"username": encryption.encrypt(user, self.enckey, init_iv),
"pass": encryption.encrypt(password, self.enckey, init_iv),
"hwid": encryption.encrypt(hwid, self.enckey, init_iv),
"sessionid": binascii.hexlify(self.sessionid.encode()),
"name": binascii.hexlify(self.name.encode()),
"ownerid": binascii.hexlify(self.ownerid.encode()),
"init_iv": init_iv
}
response = self.__do_request(post_data)
response = encryption.decrypt(response, self.enckey, init_iv)
json = jsond.loads(response)
if json["success"]:
self.__load_user_data(json["info"])
if jsond.load(open("auth.json"))["authusername"] == "": #Check if the authusername is empty so it can write the user data
authfile = jsond.load(open("Files/auth.json"))
authfile["authusername"] = user #login(self, user)
jsond.dump(authfile, open('Files/auth.json', 'w'), sort_keys=False, indent=4) #Dumping username to auth file/You can change the indent
authfile["authpassword"] = password #login(self, password)
jsond.dump(authfile, open('Files/auth.json', 'w'), sort_keys=False, indent=4) #Dumping password to auth file/You can change the indent
else: #Auth file is filled with data so it skips the user data dumping
pass
print("successfully logged in")
else:
print(json["message"])
os._exit(1)'''
# endregion
print("\nUser data: ")
print("Username: " + keyauthapp.user_data.username)
print("IP address: " + keyauthapp.user_data.ip)
print("Hardware-Id: " + keyauthapp.user_data.hwid)
# print("Subcription: " + keyauthapp.user_data.subscription) ## Print Subscription "ONE" name
subs = keyauthapp.user_data.subscriptions # Get all Subscription names, expiry, and timeleft
for i in range(len(subs)):
sub = subs[i]["subscription"] # Subscription from every Sub
expiry = datetime.utcfromtimestamp(int(subs[i]["expiry"])).strftime(
'%Y-%m-%d %H:%M:%S') # Expiry date from every Sub
timeleft = subs[i]["timeleft"] # Timeleft from every Sub
print(f"[{i + 1} / {len(subs)}] | Subscription: {sub} - Expiry: {expiry} - Timeleft: {timeleft}")
onlineUsers = keyauthapp.fetchOnline()
OU = "" # KEEP THIS EMPTY FOR NOW, THIS WILL BE USED TO CREATE ONLINE USER STRING.
if onlineUsers is None:
OU = "No online users"
else:
for i in range(len(onlineUsers)):
OU += onlineUsers[i]["credential"] + " "
print("\n" + OU + "\n")
print("Created at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.createdate)).strftime('%Y-%m-%d %H:%M:%S'))
print("Last login at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.lastlogin)).strftime('%Y-%m-%d %H:%M:%S'))
print("Expires at: " + datetime.utcfromtimestamp(int(keyauthapp.user_data.expires)).strftime('%Y-%m-%d %H:%M:%S'))
print(f"Current Session Validation Status: {keyauthapp.check()}")
print("Exiting in 10 secs....")
sleep(10)
os._exit(1)