-
Notifications
You must be signed in to change notification settings - Fork 1
/
keep_alive.py
95 lines (87 loc) · 2.3 KB
/
keep_alive.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
#websocket for uptimerobot to ping, keeps bot online
from flask import Flask, render_template, request
from flask_wtf import FlaskForm
#from flask_ipban import IpBan
from wtforms import RadioField
from threading import Thread
import random
from json import loads, dumps
import os
import asyncio
import lists
app = Flask(__name__)
seckey = os.urandom(32)
app.config.update(
#TESTING=True,
TEMPLATES_AUTO_RELOAD=True,
SECRET_KEY=seckey
)
#ip_ban=IpBan(app)
#ip_ban = IpBan(ban_seconds=200)
class SimpleForm(FlaskForm):
def setchoices():
opts=[]
data=lists.readdataE()
for x in data:
if x=="ban" or x=="banguilds":
continue
else:
#print(x)
name=str(data[x]["name"])
pingchan=str(x)
obj=tuple((pingchan,name))
opts.append(obj)
#print(opts)
return opts
clan = RadioField('btn', choices=setchoices(),default=1, coerce=int)
@app.route('/')
def home():
form = SimpleForm()
return render_template('index.html',form=form)
filename=""
@app.route('/datafiles/<string:file>/<string:passkey>')
def jsondat(file,passkey=0):
if passkey=="1498657841136236":
base_path = '/Backups'
#GOOD -- Verify with normalised version of path
fullpath = os.path.normpath(os.path.join(base_path, filename))
if not fullpath.startswith(base_path):
raise Exception("not allowed")
data = loads(open(fullpath, 'rb').read())
return data
#return loads(open(f'{file}.json', 'r').read())
else:
return "Access to NEW LIGHT DATA FILES is restricted."
@app.route("/", methods=["POST"])
def get_provider():
#print(form.clan.data)
rf = request.form['btn']
if rf =="index":
dp = request.form["provider"]
dpb = request.form["clan"]
#dp_lower_case #= dp.lower()
#print(f'{dp}')
data = lists.readother()
format=[dpb,dp]
#print(data)
data["pinglinks"].append(format)
#print(data)
lists.setother(data)
return render_template('submit.html')
elif rf=="submit":
form = SimpleForm()
return render_template('index.html',form=form)
else:
form = SimpleForm()
return render_template('index.html',form=form)
def run():
app.run(
host='0.0.0.0',
port=8080
)
def keep_alives():
'''
Creates and starts new thread that runs the function run.
'''
t = Thread(target=run)
t.start()