Compare commits

...

3 Commits

Author SHA1 Message Date
augustin64 37e8f6f61b Fix fake_popen 2024-04-12 16:20:25 +02:00
augustin64 db6fa9b6b0 Add env variables arguments to flask app
- NO_SUBPROCESS to fake subprocesses calls
- APP_ROOT to use the app outside of Docker
2024-04-12 15:55:14 +02:00
augustin64 d6988c03b4 Oops.. fixed nginx config 2024-04-12 15:51:20 +02:00
5 changed files with 62 additions and 43 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
**/.venv
user_data/*

6
.gitignore vendored
View File

@ -3,18 +3,16 @@ geckodriver.log
.vscode/
.idea
venv
**/.venv
/Git
page.html
screenshot.png
login.csv
data
**/__pycache__
user_data/*
install.sh
nohup.out
points.csv
file.png
user_data/configs.json
*.ts
LICENSE
README.md
README.md

View File

@ -13,11 +13,27 @@ import re
from requests import get
import redis
APP_ROOT = os.getenv("APP_ROOT")
if APP_ROOT is None:
APP_ROOT = "/app/MsRewards-Reborn/"
NO_SUBPROCESS = os.getenv("NO_SUBPROCESS")
if NO_SUBPROCESS is not None:
def fake_popen(*args, **kwargs):
print("Calling subprocess.Popen with", args, kwargs)
subprocess.Popen = fake_popen
print("Faking subprocess calls")
# redis part for live update
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.Redis(connection_pool=pool)
def get_path(path):
return os.path.join(APP_ROOT, path)
def generate_output():
pubsub = r.pubsub()
pubsub.subscribe('console')
@ -32,7 +48,7 @@ def generate_output():
# the end
global password
with open("/app/MsRewards-Reborn/user_data/flask.json", "r") as inFile:
with open(get_path("user_data/flask.json"), "r") as inFile:
data = json.load(inFile)
password = data["password"]
@ -40,7 +56,7 @@ secret = data["secret"]
if secret == "":
import secrets
secret = secrets.token_hex()
with open("/app/MsRewards-Reborn/user_data/flask.json", "w") as inFile:
with open(get_path("user_data/flask.json"), "w") as inFile:
data = {
"password": password,
"secret": secret
@ -70,14 +86,14 @@ scheduler.add_job( # on relance le job
def start_ms(i):
print("\033[32m" + f"Starting config {i}" + "\033[0m")
log = open(f"/app/MsRewards-Reborn/Flask/static/logs/{i}.txt", 'a') # so that data written to it will be appended
subprocess.Popen([f"python3 -u /app/MsRewards-Reborn/V6.py -c {i}"], stdout=log, stderr=log, shell=True)
log = open(get_path(f"Flask/static/logs/{i}.txt"), 'a') # so that data written to it will be appended
subprocess.Popen([f"python3 -u {get_path('V6.py')} -c {i}"], stdout=log, stderr=log, shell=True)
log.close()
TriggerDict = {}
def update_jobs():
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
for i in configs:
try :
@ -120,7 +136,7 @@ app = Flask(__name__)
@app.context_processor
def inject_default_variables():
with open("/app/MsRewards-Reborn/version", "r") as f:
with open(get_path("version"), "r") as f:
version = f.readline().replace("\n", '')
return dict(version=version)
"""
@ -175,7 +191,7 @@ def change_password():
if request.method == 'POST':
password = request.form["password"]
subprocess.Popen(["grafana-cli", "admin", "reset-admin-password", password])
with open("/app/MsRewards-Reborn/user_data/flask.json", "w") as inFile:
with open(get_path("user_data/flask.json"), "w") as inFile:
data = {
"password": password,
"secret": secret
@ -201,21 +217,21 @@ def load_user(userid):
@app.route("/")
def main():
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
return(render_template("schedule.html", data=configs))
@app.route("/discord/")
def discord_get():
with open("/app/MsRewards-Reborn/user_data/discord.json", "r") as inFile:
with open(get_path("user_data/discord.json"), "r") as inFile:
data = json.load(inFile)
return(render_template("discord.html", data=data, len=maxi(data)))
@app.route("/discord/", methods=["post"])
def discord_post():
with open("/app/MsRewards-Reborn/user_data/discord.json", "r") as inFile:
with open(get_path("user_data/discord.json"), "r") as inFile:
data = json.load(inFile)
action = request.form
if action['DISCORD'] == "delete" :
@ -237,7 +253,7 @@ def discord_post():
name = action["name"] if action["name"] else f"unnamed{action['select']}"
data[config] = {"errorsL" : errorsL, "errorsT": errorsT, "successT": successT, "successL": successL, "name": name}
with open("/app/MsRewards-Reborn/user_data/discord.json", "w") as outFile:
with open(get_path("user_data/discord.json"), "w") as outFile:
json.dump(data, outFile)
return(render_template("discord.html", data=data, len=maxi(data)))
@ -249,7 +265,7 @@ def dev2():
@app.route("/settings/")
def settings_get():
with open("/app/MsRewards-Reborn/user_data/settings.json", "r") as inFile:
with open(get_path("user_data/settings.json"), "r") as inFile:
settings = json.load(inFile)
return(render_template("settings.html", data=settings))
@ -259,21 +275,21 @@ def settings_post():
settings = {}
action = request.form
settings['avatarlink'] = action["avatarlink"]
with open("/app/MsRewards-Reborn/user_data/settings.json", "w") as inFile:
with open(get_path("user_data/settings.json"), "w") as inFile:
json.dump(settings, inFile)
return(render_template("settings.html", data=settings))
@app.route("/proxy/")
def proxy_get():
with open("/app/MsRewards-Reborn/user_data/proxy.json", "r") as inFile:
with open(get_path("user_data/proxy.json"), "r") as inFile:
j = json.load(inFile)
return(render_template("proxy.html", data=j, len=maxi(j)))
@app.route("/proxy/", methods=["post"])
def proxy_post():
with open("/app/MsRewards-Reborn/user_data/proxy.json", "r") as inFile:
with open(get_path("user_data/proxy.json"), "r") as inFile:
data = json.load(inFile)
action = request.form
print(action)
@ -290,21 +306,21 @@ def proxy_post():
except :
print("error : probably bad config")
with open("/app/MsRewards-Reborn/user_data/proxy.json", "w") as outFile:
with open(get_path("user_data/proxy.json"), "w") as outFile:
json.dump(data, outFile)
return(render_template("proxy.html", data=data, len=maxi(data)))
@app.route("/schedule/")
def schedule_get():
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
return(render_template("schedule.html", data=configs))
@app.route("/schedule/", methods=["post"])
def schedule_post():
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
data = dict(request.form)
@ -318,7 +334,7 @@ def schedule_post():
configs[i]["time"] = data[f"time{i}"]
configs[i]["enabled"] = data[f"switch{i}"] == "on"
with open("/app/MsRewards-Reborn/user_data/configs.json", "w") as inFile:
with open(get_path("user_data/configs.json"), "w") as inFile:
json.dump(configs, inFile)
update_jobs()
return(render_template("schedule.html", data=configs))
@ -326,11 +342,11 @@ def schedule_post():
@app.route("/config/")
def config_get():
with open("/app/MsRewards-Reborn/user_data/proxy.json", "r") as inFile:
with open(get_path("user_data/proxy.json"), "r") as inFile:
proxys = json.load(inFile)
with open("/app/MsRewards-Reborn/user_data/discord.json", "r") as inFile:
with open(get_path("user_data/discord.json"), "r") as inFile:
discords = json.load(inFile)
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
return(render_template("config.html", data=configs, discords=discords, proxys=proxys, configs=configs, len=maxi(configs)))
@ -338,11 +354,11 @@ def config_get():
@app.route("/config/", methods=["POST"])
def config_post():
action = request.form
with open("/app/MsRewards-Reborn/user_data/proxy.json", "r") as inFile:
with open(get_path("user_data/proxy.json"), "r") as inFile:
proxys = json.load(inFile)
with open("/app/MsRewards-Reborn/user_data/discord.json", "r") as inFile:
with open(get_path("user_data/discord.json"), "r") as inFile:
discords = json.load(inFile)
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
if action["data"] == "delete":
@ -365,18 +381,18 @@ def config_post():
"enabled":"False",
"accounts": comptes
}
with open("/app/MsRewards-Reborn/user_data/configs.json", "w") as outFile:
with open(get_path("user_data/configs.json"), "w") as outFile:
json.dump(configs, outFile)
return(render_template("config.html", data=configs, discords=discords, proxys=proxys, configs=configs, len=maxi(configs)))
@app.route("/logs/", methods=["GET", "POST"])
def logs():
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
files = [(configs[i]["name"], i) for i in configs]
config_files = [i[1] for i in files]
for f in os.listdir("/app/MsRewards-Reborn/Flask/static/logs"):
for f in os.listdir(get_path("Flask/static/logs")):
fid = ".".join(f.split(".")[:-1]) # filename without .txt
if f != ".gitignore" and fid not in config_files:
files.append((f, fid))
@ -395,21 +411,21 @@ def stats():
@app.route("/override/", methods=["POST"])
def override_post():
json = request.form.to_dict(flat=False)
log = open(f"/app/MsRewards-Reborn/Flask/static/logs/custom.txt", 'w') # so that data written to it will be appended
subprocess.Popen([f"python3 -u /app/MsRewards-Reborn/V6.py -c {json['config'][0]} --json \"{json}\""], stdout=log, stderr=log, shell=True)
log = open(get_path("Flask/static/logs/custom.txt"), 'w') # so that data written to it will be appended
subprocess.Popen([f"python3 -u {get_path('V6.py')} -c {json['config'][0]} --json \"{json}\""], stdout=log, stderr=log, shell=True)
log.close()
return(render_template("vnc_post.html"))
@app.route("/override/", methods=["GET"])
def override_get():
with open("/app/MsRewards-Reborn/user_data/configs.json", "r") as inFile:
with open(get_path("user_data/configs.json"), "r") as inFile:
configs = json.load(inFile)
return(render_template("vnc_get.html", configs=configs))
@app.route('/download/<path:filename>', methods=['GET', 'POST'])
@login_required
def download(filename):
return send_from_directory(directory='/app/MsRewards-Reborn/user_data/', path=filename, as_attachment=True)
return send_from_directory(directory=get_path("user_data/"), path=filename, as_attachment=True)
def allowed_file(filename):
@ -430,8 +446,8 @@ def upload_file():
elif file and allowed_file(file.filename):
filename = secure_filename(file.filename)
print(os.path.join('/app/MsRewards-Reborn/user_data/', filename))
file.save(os.path.join('/app/MsRewards-Reborn/user_data/', filename))
print(os.path.join(get_path("user_data/"), filename))
file.save(os.path.join(get_path("user_data/"), filename))
i += 1
print(i)
@ -449,4 +465,7 @@ def maxi(dict):
update_jobs()
subprocess.Popen(["bash",'/app/MsRewards-Reborn/config/request.sh'])
subprocess.Popen(["bash", get_path("config/request.sh")])
if __name__ == "__main__":
app.run()

View File

@ -46,7 +46,7 @@ server {
proxy_pass "http://127.0.0.1:6666";
chunked_transfer_encoding off;
proxy_buffering off;
set_header X-Accel-Buffering no;
add_header X-Accel-Buffering no;
}
}

View File

@ -11,11 +11,11 @@ class Driver:
self.mobile_driver = mobile_driver
def switch_to_driver(self, driver: str):
match driver:
case "pc" | "PC" | "Pc":
match driver.lower():
case "pc":
self.driver = self.pc_driver
case "mobile" | "Mobile":
case "mobile":
self.driver = self.mobile_driver
case _: