-
Notifications
You must be signed in to change notification settings - Fork 8
/
Https.py
155 lines (110 loc) · 3.85 KB
/
Https.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
import hashlib
import os
from random import randint
import sqlite3
import twisted.web.http
from twisted.internet import reactor
from twisted.web import resource, server
import Utils.DataClass as DataClass
import Utils.Globals as Globals
from Utils import Globals as Globals
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
urlPath = request.path.split('/')
#print request
#print request.args
#print request.content.read()
#print request.content.getvalue()
#print request.getAllHeaders()
#print "===================="
#print(str(request.path))
cwd = os.getcwd()
path = cwd+"\\Data\\"
if(urlPath[1] == "api"):
if(urlPath[4] == "battledash"):
if(urlPath[6] == "widgetdata"):
return open(path+'battledash.json').read()
if(urlPath[4] == "persona"):
if(urlPath[7] == "ingame_metadata"):
return '{"clubRank": "", "personaId": "'+urlPath[6]+'", "emblemUrl": "", "clubName": "", "countryCode": "US"}'
elif(urlPath[1] == "bf4"):
if(urlPath[2] == "battledash"):
request.setHeader("Access-Control-Allow-Origin", "*")
#request.setHeader("Origin", "http://battlelog.battlefield.com")
return open(path+'battledash.html').read()
serverXML = open(path+'server.xml')
request.setHeader("content-type", "text/xml")
return serverXML.read()
def getFreePort(self):
port = randint(50000,58000)
for auth in Globals.authClients:
if auth.Port == port:
return getFreePort()
return port
def render_POST(self, request):
urlPath = request.path.split('/')
#print request
#print request.args
#print request.content.read()
#print request.content.getvalue()
#print list(request.headers)
#print urlPath
#print "===================="
#Error ints
# 1 = No User found
# 2 = Password error, check password.txt file or make one
if(urlPath[1] == "login"):
args = request.content.getvalue().split("&")
name = ""
password = ""
if (args[0].split("=")[0] == "username"):
name = args[0].split("=")[1]
if(len(args) > 1):
if (args[1].split("=")[0] == "password"):
password = args[1].split("=")[1]
#cwd = os.getcwd()
#path = cwd+"\\Users\\"+name+"\\"
print "[SQLite] User logging in, username: " + name + " password: " + password
mysqlCheckRes = self.checkUserMySql(name, password)
if mysqlCheckRes == False:
print "[SQLite] User login fail!"
return str(1)
else:
for auth in Globals.authClients:
if auth.Name == name:
return str(auth.Port)
port = self.getFreePort()
authClient = DataClass.AuthClient()
authClient.Name = name
authClient.Port = port
Globals.authClients.append(authClient)
print "[SQLite] Added " + name + ":" + str(authClient.Port) + " To Authentication List"
return str(authClient.Port)
'''
if name == "" or os.path.exists(path) == False:
return str(1)
if (Globals.userPasswords):
if(len(args) < 2):
return str(2)
if os.path.isfile(path+"password.txt") == False:
return str(2)
passwordFile = open(path+"password.txt")
userPassword = str(passwordFile.readline())
passwordFile.close()
if(userPassword != password):
return str(2)
'''
return '"528591967549a51344692b9e18294e4c8240b7b7"'
def checkUserMySql(self, username, password):
db = sqlite3.connect(Globals.dbDatabase)
cursor = db.cursor()
password_md5=hashlib.md5(password).hexdigest()
#print(username+password_md5)
cursor.execute ("SELECT * FROM `users` WHERE username = '" + username + "' OR password = '" + password_md5 + "'")
if not cursor.rowcount:
return False
else:
return True
cursor.close()
db.close()