· 6 years ago · Sep 15, 2019, 07:20 PM
1from flask import Flask
2from flask import Flask, flash, redirect, render_template, request, session, abort
3import os
4import pymysql.cursors
5app = Flask(__name__)
6import ipaddress
7
8@app.route('/ip')
9def get_ip():
10 return request.remote_addr
11
12@app.route('/admin')
13def admin(key):
14 sql = """
15 select count(case type when 'http' then 1 else null end),
16 count(case type when 'https' then 1 else null end),
17 count(case type when 'socks4' then 1 else null end),
18 count(case type when 'socks5' then 1 else null end),
19 count(case glass when True then 1 else null end)-count(case when glass=True and type="https" then 1 else null end),
20 count(case anonim when True then 1 else null end)-count(case when anonim=True and type="https" then 1 else null end),
21 count(case elite when True then 1 else null end)-count(case when elite=True and type="https" then 1 else null end)
22 FROM new_schema.prrrrrrrroxy;
23 """
24 try:
25 connection = pymysql.connect(host='localhost',
26 user='root',
27 password='WINXKe#184Fjr',
28 db='new_schema',
29 charset='utf8mb4',
30 cursorclass=pymysql.cursors.DictCursor)
31 ip_key = ''
32 with connection.cursor() as cursor:
33 cursor.execute(sql)
34 data = ''
35 for i in cursor.fetchall():
36 data = str(i.values()).replace('dict_values(', '').replace(')', '')
37 cursor.execute('SELECT count(*) FROM new_schema.prrrrrrrroxy where type!="https";')
38 count_proxy = ''
39 for i in cursor.fetchall():
40 count_proxy = i['count(*)']
41 cursor.execute('SELECT ip FROM new_schema.`keys` where key2="{}";'.format(key))
42 for i in cursor.fetchall():
43 ip_key = i['ip']
44 sql='SELECT datediff(date, now()) FROM new_schema.`keys` Where key2="{}";'.format(key)
45 cursor.execute(sql)
46 for i in cursor.fetchall():
47 day = i["datediff(date, now())"]
48 if day == None:
49 sql="UPDATE `new_schema`.`keys` SET `date` = DATE_ADD(NOW(), INTERVAL day2 DAY) WHERE (`key2` = '{}');".format(key)
50 cursor.execute(sql)
51 connection.commit()
52 sql = 'SELECT datediff(date, now()) FROM new_schema.`keys` Where key2="{}";'.format(key)
53 cursor.execute(sql)
54 for i in cursor.fetchall():
55 day = i["datediff(date, now())"]
56 except:
57 return "ERROR Reload Page please"
58 finally:
59 connection.close()
60 return render_template('index2.html',day=day, data=data, count_proxy=count_proxy, key=key, ip=request.remote_addr, ip_key=ip_key)
61
62@app.route('/key-ip', methods=['POST'])
63def key_ip():
64 new_ip = request.form["new-ip"]
65 key = request.form["key"]
66 try:
67 ipaddress.ip_address(new_ip)
68 except ValueError:
69 return 'ERROR'
70 try:
71 connection = pymysql.connect(host='localhost',
72 user='root',
73 password='WINXKe#184Fjr',
74 db='new_schema',
75 charset='utf8mb4',
76 cursorclass=pymysql.cursors.DictCursor)
77 sql = "UPDATE `new_schema`.`keys` SET `ip` = '{}' WHERE (`key2` = '{}');".format(new_ip, key)
78 with connection.cursor() as cursor:
79 cursor.execute(sql)
80 connection.commit()
81 return admin(key)
82 except:
83 return "ERROR Reload Page please"
84 finally:
85 connection.close()
86
87@app.route('/')
88def home():
89 sql = """
90 select count(case type when 'http' then 1 else null end),
91 count(case type when 'https' then 1 else null end),
92 count(case type when 'socks4' then 1 else null end),
93 count(case type when 'socks5' then 1 else null end),
94 count(case glass when True then 1 else null end)-count(case when glass=True and type="https" then 1 else null end),
95 count(case anonim when True then 1 else null end)-count(case when anonim=True and type="https" then 1 else null end),
96 count(case elite when True then 1 else null end)-count(case when elite=True and type="https" then 1 else null end)
97 FROM new_schema.prrrrrrrroxy;
98 """
99 try:
100 connection = pymysql.connect(host='localhost',
101 user='root',
102 password='WINXKe#184Fjr',
103 db='new_schema',
104 charset='utf8mb4',
105 cursorclass=pymysql.cursors.DictCursor)
106 with connection.cursor() as cursor:
107 cursor.execute(sql)
108 data = ''
109 for i in cursor.fetchall():
110 data = str(i.values()).replace('dict_values(', '').replace(')', '')
111 cursor.execute('SELECT count(*) FROM new_schema.prrrrrrrroxy where type!="https";')
112 count_proxy = ''
113 for i in cursor.fetchall():
114 count_proxy = i['count(*)']
115 except:
116 return "ERROR Reload Page please"
117 finally:
118 connection.close()
119 return render_template('index.html', data=data, count_proxy=count_proxy)
120
121@app.route('/login', methods=['POST'])
122def do_admin_login():
123 key = request.form["key"]
124 sql = 'SELECT count(*) FROM new_schema.`keys` where key2="{}";'.format(key)
125 try:
126 connection = pymysql.connect(host='localhost',
127 user='root',
128 password='WINXKe#184Fjr',
129 db='new_schema',
130 charset='utf8mb4',
131 cursorclass=pymysql.cursors.DictCursor)
132 with connection.cursor() as cursor:
133 cursor.execute(sql)
134 for i in cursor.fetchall():
135 if i["count(*)"] == 1:
136 return admin(key)
137 #return admin(key)
138 except:
139 return 'ERROR Please Try again'
140 finally:
141 connection.close()
142 return home()
143#simple-proxies.com/api?&type=http,https,socks4,socks5&anonim=glass,anonim,elite&country=RU,EN&timeout=3000&limit=500
144@app.route('/api', methods=['GET'])
145def api():
146 result = False
147 user_key = request.args.get('key')
148 try:
149 if len(user_key) != 32:
150 return 'ERROR Wrong Key'
151 except:
152 return 'ERROR Wrong Key'
153 else:
154 connection = pymysql.connect(host='localhost',
155 user='root',
156 password='WINXKe#184Fjr',
157 db='new_schema',
158 charset='utf8mb4',
159 cursorclass=pymysql.cursors.DictCursor)
160 # 76d80224611fc919a5d54f0ff9fba425
161 # SELECT count(*) FROM new_schema.`keys` WHERE new_schema.`keys`.key = "76d80224611fc919a5d54f0ff9fba425" LIMIT 1;
162 try:
163 with connection.cursor() as cursor:
164 # SQL
165 sql = 'SELECT *, datediff(date, now()) FROM new_schema.`keys` WHERE new_schema.`keys`.key2 = "{}" LIMIT 1;'.format(user_key)
166 # Выполнить команду запроса (Execute Query).
167 cursor.execute(sql)
168 for i in cursor:
169 if not i["datediff(date, now())"] == None:
170 if i["key2"] == user_key and i['ip'] == request.remote_addr and i["datediff(date, now())"] >= 0:
171 result = True
172 finally:
173 connection.close()
174 try:
175 if not result:
176 return 'Wrong Key or Wrong IP'
177 except:
178 return 'Wrong Key or Wrong IP'
179 if result:
180 try:
181 proxy_type = request.args.get('type')
182 anonim_type = request.args.get('anonim')
183 if proxy_type == None:
184 proxy_type = "http,https,socks4,socks5"
185 if anonim_type == None:
186 anonim_type = "glass,anonim,elite"
187 country = request.args.get('country')
188 timeout = request.args.get('timeout')
189 limit = request.args.get('limit')
190 if proxy_type == "":
191 proxy_type = "http,https,socks4,socks5"
192 if anonim_type == "":
193 anonim_type = "glass,anonim,elite"
194 if validate_args(proxy_type, anonim_type, country, timeout, limit):
195 response = ''
196 if country == '':
197 sql_country = 'True'
198 else:
199 sql_country = 'country="' + country.replace(',', '" OR country="') + '"'
200 if limit == "0":
201 sql_limit = 666666
202 else:
203 sql_limit = limit
204 if timeout == "0":
205 sql_timeout = 666666
206 else:
207 sql_timeout = timeout
208 sql_type = 'type="' + proxy_type.replace(",", '" OR type="') + '"'
209 sql_anon = anonim_type.replace(",", '=True OR ') + "=True"
210 sql_com = "SELECT proxy FROM new_schema.prrrrrrrroxy where (" + sql_type + ") AND (" + sql_anon + ") AND (timeout<=" + str(sql_timeout) + ") AND (" + sql_country + ") LIMIT " + str(sql_limit)
211 try:
212 connection = pymysql.connect(host='localhost',
213 user='root',
214 password='WINXKe#184Fjr',
215 db='new_schema',
216 charset='utf8mb4',
217 cursorclass=pymysql.cursors.DictCursor)
218 with connection.cursor() as cursor:
219 response = ''
220 # Выполнить команду запроса (Execute Query).
221 cursor.execute(sql_com)
222 for i in cursor.fetchall():
223 if not i["proxy"] in response:
224 response = response + i["proxy"] + "\n"
225 return response
226 except:
227 return 'SQL ERROR. Пожалуйста напишите в поддержку'
228 finally:
229 connection.close()
230 else:
231 return 'ERROR Please check api documentation'
232 except:
233 return 'ERROR Please check api documentation'
234
235def validate_args(proxy_type, anonim_type, country, timeout, limit):
236 try:
237 valid_types = ['http', 'https', 'socks4', 'socks5']#http,https,socks4,socks5
238 valid_anonim = ["glass", "anonim", "elite"]#glass,anonim,elite
239 if proxy_type == "":
240 proxy_type = "http,https,socks4,socks5"
241 if anonim_type == "":
242 anonim_type = ["glass", "anonim", "elite"]
243 for i in proxy_type.split(',', 4):
244 if not i.replace(' ', '') in valid_types:
245 return False
246 for i in anonim_type.split(',', 3):
247 if not i.replace(' ', '') in valid_anonim:
248 return False
249 try:
250 int(timeout)
251 int(limit)
252 except:
253 return False
254 return True
255 except:
256 return 'ERROR Please check api documentation'
257
258if __name__ == "__main__":
259 app.secret_key = os.urandom(12)
260 app.run(host='0.0.0.0', port=80)