Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask import Flask, flash, redirect, render_template, request, session, abort
- import os
- import pymysql.cursors
- app = Flask(__name__)
- import ipaddress
- @app.route('/ip')
- def get_ip():
- return request.remote_addr
- @app.route('/admin')
- def admin(key):
- sql = """
- select count(case type when 'http' then 1 else null end),
- count(case type when 'https' then 1 else null end),
- count(case type when 'socks4' then 1 else null end),
- count(case type when 'socks5' then 1 else null end),
- count(case glass when True then 1 else null end)-count(case when glass=True and type="https" then 1 else null end),
- count(case anonim when True then 1 else null end)-count(case when anonim=True and type="https" then 1 else null end),
- count(case elite when True then 1 else null end)-count(case when elite=True and type="https" then 1 else null end)
- FROM new_schema.prrrrrrrroxy;
- """
- try:
- connection = pymysql.connect(host='localhost',
- user='root',
- password='WINXKe#184Fjr',
- db='new_schema',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- ip_key = ''
- with connection.cursor() as cursor:
- cursor.execute(sql)
- data = ''
- for i in cursor.fetchall():
- data = str(i.values()).replace('dict_values(', '').replace(')', '')
- cursor.execute('SELECT count(*) FROM new_schema.prrrrrrrroxy where type!="https";')
- count_proxy = ''
- for i in cursor.fetchall():
- count_proxy = i['count(*)']
- cursor.execute('SELECT ip FROM new_schema.`keys` where key2="{}";'.format(key))
- for i in cursor.fetchall():
- ip_key = i['ip']
- sql='SELECT datediff(date, now()) FROM new_schema.`keys` Where key2="{}";'.format(key)
- cursor.execute(sql)
- for i in cursor.fetchall():
- day = i["datediff(date, now())"]
- if day == None:
- sql="UPDATE `new_schema`.`keys` SET `date` = DATE_ADD(NOW(), INTERVAL day2 DAY) WHERE (`key2` = '{}');".format(key)
- cursor.execute(sql)
- connection.commit()
- sql = 'SELECT datediff(date, now()) FROM new_schema.`keys` Where key2="{}";'.format(key)
- cursor.execute(sql)
- for i in cursor.fetchall():
- day = i["datediff(date, now())"]
- except:
- return "ERROR Reload Page please"
- finally:
- connection.close()
- return render_template('index2.html',day=day, data=data, count_proxy=count_proxy, key=key, ip=request.remote_addr, ip_key=ip_key)
- @app.route('/key-ip', methods=['POST'])
- def key_ip():
- new_ip = request.form["new-ip"]
- key = request.form["key"]
- try:
- ipaddress.ip_address(new_ip)
- except ValueError:
- return 'ERROR'
- try:
- connection = pymysql.connect(host='localhost',
- user='root',
- password='WINXKe#184Fjr',
- db='new_schema',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- sql = "UPDATE `new_schema`.`keys` SET `ip` = '{}' WHERE (`key2` = '{}');".format(new_ip, key)
- with connection.cursor() as cursor:
- cursor.execute(sql)
- connection.commit()
- return admin(key)
- except:
- return "ERROR Reload Page please"
- finally:
- connection.close()
- @app.route('/')
- def home():
- sql = """
- select count(case type when 'http' then 1 else null end),
- count(case type when 'https' then 1 else null end),
- count(case type when 'socks4' then 1 else null end),
- count(case type when 'socks5' then 1 else null end),
- count(case glass when True then 1 else null end)-count(case when glass=True and type="https" then 1 else null end),
- count(case anonim when True then 1 else null end)-count(case when anonim=True and type="https" then 1 else null end),
- count(case elite when True then 1 else null end)-count(case when elite=True and type="https" then 1 else null end)
- FROM new_schema.prrrrrrrroxy;
- """
- try:
- connection = pymysql.connect(host='localhost',
- user='root',
- password='WINXKe#184Fjr',
- db='new_schema',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- with connection.cursor() as cursor:
- cursor.execute(sql)
- data = ''
- for i in cursor.fetchall():
- data = str(i.values()).replace('dict_values(', '').replace(')', '')
- cursor.execute('SELECT count(*) FROM new_schema.prrrrrrrroxy where type!="https";')
- count_proxy = ''
- for i in cursor.fetchall():
- count_proxy = i['count(*)']
- except:
- return "ERROR Reload Page please"
- finally:
- connection.close()
- return render_template('index.html', data=data, count_proxy=count_proxy)
- @app.route('/login', methods=['POST'])
- def do_admin_login():
- key = request.form["key"]
- sql = 'SELECT count(*) FROM new_schema.`keys` where key2="{}";'.format(key)
- try:
- connection = pymysql.connect(host='localhost',
- user='root',
- password='WINXKe#184Fjr',
- db='new_schema',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- with connection.cursor() as cursor:
- cursor.execute(sql)
- for i in cursor.fetchall():
- if i["count(*)"] == 1:
- return admin(key)
- #return admin(key)
- except:
- return 'ERROR Please Try again'
- finally:
- connection.close()
- return home()
- #simple-proxies.com/api?&type=http,https,socks4,socks5&anonim=glass,anonim,elite&country=RU,EN&timeout=3000&limit=500
- @app.route('/api', methods=['GET'])
- def api():
- result = False
- user_key = request.args.get('key')
- try:
- if len(user_key) != 32:
- return 'ERROR Wrong Key'
- except:
- return 'ERROR Wrong Key'
- else:
- connection = pymysql.connect(host='localhost',
- user='root',
- password='WINXKe#184Fjr',
- db='new_schema',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- # 76d80224611fc919a5d54f0ff9fba425
- # SELECT count(*) FROM new_schema.`keys` WHERE new_schema.`keys`.key = "76d80224611fc919a5d54f0ff9fba425" LIMIT 1;
- try:
- with connection.cursor() as cursor:
- # SQL
- sql = 'SELECT *, datediff(date, now()) FROM new_schema.`keys` WHERE new_schema.`keys`.key2 = "{}" LIMIT 1;'.format(user_key)
- # Выполнить команду запроса (Execute Query).
- cursor.execute(sql)
- for i in cursor:
- if not i["datediff(date, now())"] == None:
- if i["key2"] == user_key and i['ip'] == request.remote_addr and i["datediff(date, now())"] >= 0:
- result = True
- finally:
- connection.close()
- try:
- if not result:
- return 'Wrong Key or Wrong IP'
- except:
- return 'Wrong Key or Wrong IP'
- if result:
- try:
- proxy_type = request.args.get('type')
- anonim_type = request.args.get('anonim')
- if proxy_type == None:
- proxy_type = "http,https,socks4,socks5"
- if anonim_type == None:
- anonim_type = "glass,anonim,elite"
- country = request.args.get('country')
- timeout = request.args.get('timeout')
- limit = request.args.get('limit')
- if proxy_type == "":
- proxy_type = "http,https,socks4,socks5"
- if anonim_type == "":
- anonim_type = "glass,anonim,elite"
- if validate_args(proxy_type, anonim_type, country, timeout, limit):
- response = ''
- if country == '':
- sql_country = 'True'
- else:
- sql_country = 'country="' + country.replace(',', '" OR country="') + '"'
- if limit == "0":
- sql_limit = 666666
- else:
- sql_limit = limit
- if timeout == "0":
- sql_timeout = 666666
- else:
- sql_timeout = timeout
- sql_type = 'type="' + proxy_type.replace(",", '" OR type="') + '"'
- sql_anon = anonim_type.replace(",", '=True OR ') + "=True"
- 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)
- try:
- connection = pymysql.connect(host='localhost',
- user='root',
- password='WINXKe#184Fjr',
- db='new_schema',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- with connection.cursor() as cursor:
- response = ''
- # Выполнить команду запроса (Execute Query).
- cursor.execute(sql_com)
- for i in cursor.fetchall():
- if not i["proxy"] in response:
- response = response + i["proxy"] + "\n"
- return response
- except:
- return 'SQL ERROR. Пожалуйста напишите в поддержку'
- finally:
- connection.close()
- else:
- return 'ERROR Please check api documentation'
- except:
- return 'ERROR Please check api documentation'
- def validate_args(proxy_type, anonim_type, country, timeout, limit):
- try:
- valid_types = ['http', 'https', 'socks4', 'socks5']#http,https,socks4,socks5
- valid_anonim = ["glass", "anonim", "elite"]#glass,anonim,elite
- if proxy_type == "":
- proxy_type = "http,https,socks4,socks5"
- if anonim_type == "":
- anonim_type = ["glass", "anonim", "elite"]
- for i in proxy_type.split(',', 4):
- if not i.replace(' ', '') in valid_types:
- return False
- for i in anonim_type.split(',', 3):
- if not i.replace(' ', '') in valid_anonim:
- return False
- try:
- int(timeout)
- int(limit)
- except:
- return False
- return True
- except:
- return 'ERROR Please check api documentation'
- if __name__ == "__main__":
- app.secret_key = os.urandom(12)
- app.run(host='0.0.0.0', port=80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement