From 55a1677fb4f7f98b9544d3445c5c6884055856a0 Mon Sep 17 00:00:00 2001 From: piair Date: Thu, 24 Aug 2023 13:28:49 +0200 Subject: [PATCH] c'est bon ? --- Dockerfile | 8 +- Flask/app.py | 19 +--- .../Stats-dashbord.json | 0 config/config.sh | 50 ++++++++++ {grafana-config => config}/grafana.ini | 0 config.sh => config/request.sh | 55 +---------- database.py | 92 ------------------- grafana-config/aa | 1 - requirements.txt | 1 - 9 files changed, 59 insertions(+), 167 deletions(-) rename {grafana-config => config}/Stats-dashbord.json (100%) create mode 100644 config/config.sh rename {grafana-config => config}/grafana.ini (100%) rename config.sh => config/request.sh (68%) delete mode 100644 database.py delete mode 100644 grafana-config/aa diff --git a/Dockerfile b/Dockerfile index 6bfcb4b..e52e529 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,11 @@ RUN curl -sSLO https://piair.xyz/download/chrome.deb \ && ln -fs /usr/share/zoneinfo/Europe/Paris /etc/localtime \ && git clone https://gitea.augustin64.fr/piair/MsRewards-Reborn \ && python3 -m pip install -r MsRewards-Reborn/requirements.txt \ - && apt update \ - && apt install xvfb nginx nano tzdata sqlite3 apt-transport-https software-properties-common wget wfrench tigervnc-standalone-server libasound2 libatk-bridge2.0-0 libnss3 libnspr4 xvfb libgbm1 libatk1.0-0 libu2f-udev libatspi2.0-0 libcups2 libxkbcommon0 libxrandr2 libdbus-1-3 xdg-utils fonts-liberation libdrm2 -y \ - && wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key \ && echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | tee -a /etc/apt/sources.list.d/grafana.list \ && apt update \ - && apt install grafana \ - && bash MsRewards-Reborn/config.sh \ + && apt install grafana xvfb nginx nano tzdata sqlite3 apt-transport-https software-properties-common wget wfrench tigervnc-standalone-server libasound2 libatk-bridge2.0-0 libnss3 libnspr4 xvfb libgbm1 libatk1.0-0 libu2f-udev libatspi2.0-0 libcups2 libxkbcommon0 libxrandr2 libdbus-1-3 xdg-utils fonts-liberation libdrm2 -y \ + && wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key \ + && bash MsRewards-Reborn/config/config.sh \ && dpkg -i chrome.deb ENV TZ="Europe/Paris" diff --git a/Flask/app.py b/Flask/app.py index 6cd37c4..3a6d7f4 100644 --- a/Flask/app.py +++ b/Flask/app.py @@ -8,7 +8,7 @@ from flask_login import LoginManager, UserMixin, login_required, login_user, log from werkzeug.utils import secure_filename import json import re - +from requests import get global password with open("/app/MsRewards-Reborn/user_data/flask.json", "r") as inFile: @@ -455,21 +455,12 @@ def maxi(dict): m = int(i) return(m+1) - - -from flask import Flask -from requests import get - -SITE_NAME = 'http://localhost:3000' - -@app.route('/proxytest', defaults={'path': ''}) -@app.route('/proxytest') -def proxy(): - return get(f'{SITE_NAME}').content - - +def setup_grafana(): + if requests.get("http://localhost:3000/api/datasources").text == "[]" : + subprocess.Popen(["bash",'/app/MsRewards-Reborn/config/request.sh']) if __name__ == '__main__': update_jobs() edit_version() + setup_grafana() app.run(host='0.0.0.0', port=1234, debug=True) diff --git a/grafana-config/Stats-dashbord.json b/config/Stats-dashbord.json similarity index 100% rename from grafana-config/Stats-dashbord.json rename to config/Stats-dashbord.json diff --git a/config/config.sh b/config/config.sh new file mode 100644 index 0000000..88de766 --- /dev/null +++ b/config/config.sh @@ -0,0 +1,50 @@ +printf "\nsetting up NGINX\n" + +rm /etc/nginx/sites-available/default +echo " +map \$http_upgrade \$connection_upgrade { + default upgrade; + '' close; +} + +upstream grafana { +server localhost:3000; +} + +server { + listen 1234; + server_name localhost; + location /grafana { + proxy_pass http://localhost:3000; + rewrite ^/grafana/(.*) /\$1 break; + proxy_set_header Host \$host; + } + location /grafana/api/live/ { + proxy_http_version 1.1; + proxy_set_header Upgrade \$http_upgrade; + proxy_set_header Connection \$connection_upgrade; + proxy_set_header Host \$http_host; + proxy_pass http://grafana; + rewrite ^/grafana/(.*) /\$1 break; + } + location / { + proxy_set_header X-Forwarded-For \$remote_addr; + proxy_set_header Host \$http_host; + proxy_pass "http://127.0.0.1:6666"; + } + +} +" >> /etc/nginx/sites-available/default +printf "\nNGINX configuration successfull\n" + +printf "\ncreating sqlite databases\n" +sqlite3 /app/MsRewards-Reborn/MsRewards.db "CREATE TABLE daily (id INTEGER PRIMARY KEY,compte TEXT,points int,date TEXT);" +sqlite3 /app/MsRewards-Reborn/MsRewards.db "CREATE TABLE comptes (id INTEGER PRIMARY KEY,compte TEXT,last_pts int, banned int);" + +printf "\nconfigurating grafana\n" + +cp /app/MsRewards-Reborn/config/grafana.ini /etc/grafana/ +grafana-cli plugins install frser-sqlite-datasource + +printf "setting up default dashboard" +cp /app/MsRewards-Reborn/config/Stats-dashbord.json /usr/share/grafana/public/dashboards/home.json \ No newline at end of file diff --git a/grafana-config/grafana.ini b/config/grafana.ini similarity index 100% rename from grafana-config/grafana.ini rename to config/grafana.ini diff --git a/config.sh b/config/request.sh similarity index 68% rename from config.sh rename to config/request.sh index 0862baf..c4a69f2 100644 --- a/config.sh +++ b/config/request.sh @@ -1,59 +1,9 @@ -printf "\n\nsetting up NGINX\n\n" - -rm /etc/nginx/sites-available/default -echo " -map \$http_upgrade \$connection_upgrade { - default upgrade; - '' close; -} - -upstream grafana { -server localhost:3000; -} - -server { - listen 1234; - server_name localhost; - location /grafana { - proxy_pass http://localhost:3000; - rewrite ^/grafana/(.*) /\$1 break; - proxy_set_header Host \$host; - } - location /grafana/api/live/ { - proxy_http_version 1.1; - proxy_set_header Upgrade \$http_upgrade; - proxy_set_header Connection \$connection_upgrade; - proxy_set_header Host \$http_host; - proxy_pass http://grafana; - rewrite ^/grafana/(.*) /\$1 break; - } - location / { - proxy_set_header X-Forwarded-For \$remote_addr; - proxy_set_header Host \$http_host; - proxy_pass "http://127.0.0.1:6666"; - } - -} -" >> /etc/nginx/sites-available/default -printf "\n\nNGINX configuration successfull\n\n" -service nginx restart - -printf "\n\ncreating sqlite databases\n\n" -sqlite3 /app/MsRewards-Reborn/MsRewards.db "CREATE TABLE daily (id INTEGER PRIMARY KEY,compte TEXT,points int,date TEXT);" -sqlite3 /app/MsRewards-Reborn/MsRewards.db "CREATE TABLE comptes (id INTEGER PRIMARY KEY,compte TEXT,last_pts int, banned int);" - -printf "\n\nconfigurating grafana\n\n" - -cp /app/MsRewards-Reborn/grafana-config/grafana.ini /etc/grafana/ -grafana-cli plugins install frser-sqlite-datasource -service grafana-server stop -service grafana-server start curl -X "POST" "http://localhost:3000/api/datasources" \ -H "Content-Type: application/json" \ --user admin:admin \ --data-raw $'{"id":1,"uid":"bed26262-6b98-4dfc-a95d-f8bd39b5d09c","orgId":1,"name":"SQLite","type":"frser-sqlite-datasource","typeName":"SQLite","typeLogoUrl":"public/plugins/frser-sqlite-datasource/img/logo.svg","access":"proxy","url":"","user":"","database":"","basicAuth":false,"isDefault":true,"jsonData":{"attachLimit":0,"path":"/app/MsRewards-Reborn/MsRewards.db","pathPefix":"file:"},"readOnly":false}' -curl 'http://192.168.1.32:5555/grafana/api/dashboards/import' \ +curl 'http://localhost:1234/grafana/api/dashboards/import' \ -H 'content-type: application/json' \ -H 'x-grafana-org-id: 1' \ --user admin:admin \ @@ -61,6 +11,3 @@ curl 'http://192.168.1.32:5555/grafana/api/dashboards/import' \ --compressed \ --insecure - -printf "setting up default dashboard" -cp /app/MsRewards-Reborn/grafana-config/Stats-dashbord.json /usr/share/grafana/public/dashboards/home.json \ No newline at end of file diff --git a/database.py b/database.py deleted file mode 100644 index a5a0477..0000000 --- a/database.py +++ /dev/null @@ -1,92 +0,0 @@ -import mysql.connector -import configparser -from os import path -import argparse - -parser = argparse.ArgumentParser() -parser.add_argument( - "-f", - "--file", - help="Choose a file", - type=argparse.FileType('r') -) -parser.add_argument( - "-m", - "--manual", - help="add point manually do database", - dest="manual", - action="store_true" -) - -args = parser.parse_args() -MANUAL = args.manual - -config_path = "./user_data/config.cfg" -config = configparser.ConfigParser() -config.read(config_path) - -sql_usr = config["SQL"]["usr"] -sql_pwd = config["SQL"]["pwd"] -sql_host = config["SQL"]["host"] -sql_database = config["SQL"]["database"] - - -mydb = mysql.connector.connect( - host=sql_host, - user=sql_usr, - password=sql_pwd, - database = sql_database -) -mycursor = mydb.cursor() - -def add_account(name: str, endroit: str, proprio: str): - command = f'INSERT INTO comptes (compte, proprio, endroit, last_pts) VALUES ("{name}", "{proprio}", "{endroit}",0);' - mycursor.execute(command) - - -def ban_account(name: str, pts = 0): - - command1 = f"INSERT INTO banned (nom, total) VALUES ('{name}', {pts});" - command2 = f'DELETE FROM comptes WHERE compte = "{name}";' - mycursor.execute(command1) - mycursor.execute(command2) - -def update_pts(name: str, pts = 0): - pass - -if not MANUAL : - print("ajouter un compte : 1\nban un compte : 2") - i = input() - if i == "1": - if args.file : - l =[x.split(",")[0].split("@")[0] for x in args.file.readlines()] - endroit = input("ou est le bot ? ") - proprio = input("qui est le proprio ? ") - for name in l : - add_account(name, endroit, proprio) - else : - name = input("quel est le nom ? ").split("@")[0] - endroit = input("ou est le bot ? ") - proprio = input("qui est le proprio ? ") - add_account(name, endroit, proprio) - elif i == '2': - name = input("quel est le compte qui a été ban ? ") - pts = input("il avait combien de points ? ") - ban_account(name, pts) - - mydb.commit() - mycursor.close() - mydb.close() -else : - import modules.db as datab - config_path = f"{path.abspath(path.dirname(path.dirname( __file__ )))}/MsRewards/user_data/config.cfg" - print(config_path) - config = configparser.ConfigParser() - config.read(config_path) - sql_usr = config["SQL"]["usr"] - sql_pwd = config["SQL"]["pwd"] - sql_host = config["SQL"]["host"] - sql_database = config["SQL"]["database"] - account_name = input("compte ? ") - points = int(input("points ? ")) - datab.add_to_database(account_name, points, sql_host, sql_usr, sql_pwd, sql_database) \ No newline at end of file diff --git a/grafana-config/aa b/grafana-config/aa deleted file mode 100644 index 144766b..0000000 --- a/grafana-config/aa +++ /dev/null @@ -1 +0,0 @@ -{"id":1,"uid":"bed26262-6b98-4dfc-a95d-f8bd39b5d09c","orgId":1,"name":"SQLite","type":"frser-sqlite-datasource","typeName":"SQLite","typeLogoUrl":"public/plugins/frser-sqlite-datasource/img/logo.svg","access":"proxy","url":"","user":"","database":"","basicAuth":false,"isDefault":true,"jsonData":{"attachLimit":0,"path":"/app/MsRewards-Reborn/MsRewards.db","pathPefix":"file:"},"readOnly":false} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7cfca33..904f4b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,6 @@ pyvirtualdisplay undetected_chromedriver requests flask -mysql-connector-python enquiries EasyProcess pyotp