-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
126 lines (105 loc) · 4.18 KB
/
app.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
import datetime
from flask import Flask, render_template,jsonify, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from Server import functesturl, updatedb, basicproxytest
e = create_engine('sqlite:///database.db') # loads db into memory
# Resource
app = Flask(__name__, template_folder="templates")
api = Api(app) # api is a collection of objects, where each object contains a specific functionality (GET, POST, etc)
@app.route('/')
def home():
"""
This function just responds to the browser ULR
localhost:5000/
:return: the rendered template 'home.html'
"""
return render_template('home.html')
@app.route('/proxies')
def proxies():
return render_template('proxylistview.html')
class index(Resource):
def get(self):
conn = e.connect()
try:
query = conn.execute("select * from proxyprovider")
rows = query.cursor.fetchall()
query_testurl = conn.execute("select * from proxytest")
rows_testurl = query_testurl.cursor.fetchall()
return jsonify({'tasks': rows, 'testtasks': rows_testurl})
except:
return {'msg': 'Error occurred ! '}, 400
conn.close()
def post(self):
json = request.get_json()
urlTest = json['url']
conn = e.connect()
query = conn.execute("select * from proxylists")
rows = query.cursor.fetchall()
if not rows:
return {'message': 'No Proxies Are Available in the Database !'}, 400
proxyList = []
for i in rows:
line = i[0]+':'+ str(i[1])
proxyList.append(line)
conn.close()
functesturl(proxyList, urlTest)
return { 'message': 'Proxy test with certain url is completed, find the details in Test URLS Division!' }, 201
class proxiesretrive(Resource):
def get(self):
conn = e.connect()
try:
query = conn.execute("select * from proxylists")
rows = query.cursor.fetchall()
return jsonify({'tasks': rows})
except:
return {'msg': 'Error occurred ! '}, 400
conn.close()
def post(self):
json_data = request.get_json()
if not json_data:
return {'message': 'No input data provided'}, 400
conn = e.connect()
query = conn.execute("select * from proxylists where IP = ? ", (json_data['IP']))
row = query.cursor.fetchall()
if not row:
updatedb(json_data)
return { 'message': 'IP Entry Has Been Added Successfully ' }, 201
else:
return { 'message': 'IP is already exists, please enter new IP address !' }, 400
conn.close()
def put(self):
json_data = request.get_json()
proxy_list = []
if not json_data:
return {'message': 'No input data provided'}, 400
conn = e.connect()
query = conn.execute("select * from proxylists where IP = ? ", (json_data['oldIP']))
row = query.cursor.fetchall()
if not row:
return {'message': 'IP does not exist'}, 400
else:
date = str(datetime.datetime.now())
dataformat = date[0:10] + ',' + date[11:19]
conn.execute("UPDATE proxylists SET IP = ?, Port = ?, insertdate = ?, lastupdate = ? WHERE IP = ?",
(json_data['newIP'],json_data['newPort'], dataformat, dataformat, json_data['oldIP']))
dict_line = {'IP': json_data['newIP'], 'Port': json_data['newPort']}
proxy_list.append(dict_line)
basicproxytest(proxy_list, dataformat)
return {'message': 'IP Entry Has Been Updated Successfully '}, 201
conn.close()
def delete(self):
json_data = request.get_json(force=True)
if json_data == 1:
print('deleted')
conn = e.connect()
conn.execute("DELETE from proxylists")
conn.close()
return {"status": 'success'}, 201
else:
return {'message': 'No input data provided'}, 400
#resource route
api.add_resource(proxiesretrive, '/proxiestest')
api.add_resource(index, '/indexpage')
if __name__ == '__main__':
app.run(debug=True)