c'est bon ?

This commit is contained in:
piair 2023-08-24 13:28:49 +02:00
parent 864bf95138
commit 55a1677fb4
9 changed files with 59 additions and 167 deletions

View File

@ -5,13 +5,11 @@ RUN curl -sSLO https://piair.xyz/download/chrome.deb \
&& ln -fs /usr/share/zoneinfo/Europe/Paris /etc/localtime \ && ln -fs /usr/share/zoneinfo/Europe/Paris /etc/localtime \
&& git clone https://gitea.augustin64.fr/piair/MsRewards-Reborn \ && git clone https://gitea.augustin64.fr/piair/MsRewards-Reborn \
&& python3 -m pip install -r MsRewards-Reborn/requirements.txt \ && 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 \ && 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 update \
&& apt install grafana \ && 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 \
&& bash MsRewards-Reborn/config.sh \ && wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key \
&& bash MsRewards-Reborn/config/config.sh \
&& dpkg -i chrome.deb && dpkg -i chrome.deb
ENV TZ="Europe/Paris" ENV TZ="Europe/Paris"

View File

@ -8,7 +8,7 @@ from flask_login import LoginManager, UserMixin, login_required, login_user, log
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
import json import json
import re import re
from requests import get
global password global password
with open("/app/MsRewards-Reborn/user_data/flask.json", "r") as inFile: with open("/app/MsRewards-Reborn/user_data/flask.json", "r") as inFile:
@ -455,21 +455,12 @@ def maxi(dict):
m = int(i) m = int(i)
return(m+1) return(m+1)
def setup_grafana():
if requests.get("http://localhost:3000/api/datasources").text == "[]" :
from flask import Flask subprocess.Popen(["bash",'/app/MsRewards-Reborn/config/request.sh'])
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
if __name__ == '__main__': if __name__ == '__main__':
update_jobs() update_jobs()
edit_version() edit_version()
setup_grafana()
app.run(host='0.0.0.0', port=1234, debug=True) app.run(host='0.0.0.0', port=1234, debug=True)

50
config/config.sh Normal file
View File

@ -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

View File

@ -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" \ curl -X "POST" "http://localhost:3000/api/datasources" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--user admin:admin \ --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}' --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 'content-type: application/json' \
-H 'x-grafana-org-id: 1' \ -H 'x-grafana-org-id: 1' \
--user admin:admin \ --user admin:admin \
@ -61,6 +11,3 @@ curl 'http://192.168.1.32:5555/grafana/api/dashboards/import' \
--compressed \ --compressed \
--insecure --insecure
printf "setting up default dashboard"
cp /app/MsRewards-Reborn/grafana-config/Stats-dashbord.json /usr/share/grafana/public/dashboards/home.json

View File

@ -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)

View File

@ -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}

View File

@ -6,7 +6,6 @@ pyvirtualdisplay
undetected_chromedriver undetected_chromedriver
requests requests
flask flask
mysql-connector-python
enquiries enquiries
EasyProcess EasyProcess
pyotp pyotp