latest working sample
This commit is contained in:
parent
0ef3916ae7
commit
445cdc834a
@ -4,11 +4,11 @@ import time
|
||||
from requests_tor import RequestsTor
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from ktvmanager.lib.get_urls import generate_urls_for_user
|
||||
from get_urls import generate_urls_for_user
|
||||
import json
|
||||
load_dotenv()
|
||||
|
||||
rt = RequestsTor(tor_ports=(9001, 9002, 9003, 9004, 9005), tor_cport=9051, password=os.getenv('TORSPWD'), autochange_id=3)
|
||||
rt = RequestsTor(tor_host=os.getenv('TORSSRV'), tor_ports=(9001, 9002, 9003, 9004, 9005), tor_cport=9051, password=os.getenv('TORSPWD'), autochange_id=3)
|
||||
|
||||
def get_status(url):
|
||||
try:
|
||||
|
@ -1 +1,2 @@
|
||||
http://sarahgraphite.awardvpn.xyz
|
||||
http://sarahgraphite.liveme.vip
|
@ -19,7 +19,10 @@ def get_latest_urls_from_dns():
|
||||
|
||||
for url in lines:
|
||||
data = requests.get(url)
|
||||
content = json.loads(data.text)
|
||||
try:
|
||||
content = json.loads(data.text)
|
||||
except Exception:
|
||||
pass
|
||||
list_of_urls = content['su'].split(',')
|
||||
for url in list_of_urls:
|
||||
complete_list_of_urls.append(url)
|
||||
|
@ -0,0 +1,35 @@
|
||||
from flask import Flask
|
||||
from routes.index import index_blueprint
|
||||
from routes.get_user_accounts import get_user_accounts_blueprint
|
||||
from routes.single_check import single_check_blueprint
|
||||
from routes.add_account import add_account_blueprint
|
||||
from routes.delete_account import delete_account_blueprint
|
||||
from routes.login import login_blueprint
|
||||
from auth import requires_auth
|
||||
from lib.get_users import get_users
|
||||
|
||||
app = Flask(__name__)
|
||||
users = get_users()
|
||||
|
||||
# Routes without auth
|
||||
app.register_blueprint(index_blueprint)
|
||||
|
||||
# Routes with basic auth
|
||||
app.register_blueprint(login_blueprint, url_prefix="/login")
|
||||
app.register_blueprint(get_user_accounts_blueprint, url_prefix="/getUserAccounts")
|
||||
app.register_blueprint(single_check_blueprint, url_prefix="/singleCheck")
|
||||
app.register_blueprint(add_account_blueprint, url_prefix="/addAccount")
|
||||
app.register_blueprint(delete_account_blueprint, url_prefix="/deleteAccount")
|
||||
|
||||
# 404 handler
|
||||
@app.errorhandler(404)
|
||||
def not_found(error):
|
||||
return {"error": "Not found"}, 404
|
||||
|
||||
# 500 error handler
|
||||
@app.errorhandler(500)
|
||||
def server_error(error):
|
||||
return {"error": "Server error"}, 500
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
90
ktvmanager_backend/lib/get_user.py
Normal file
90
ktvmanager_backend/lib/get_user.py
Normal file
@ -0,0 +1,90 @@
|
||||
import mysql.connector
|
||||
|
||||
def get_connection():
|
||||
return mysql.connector.connect(
|
||||
host='localhost',
|
||||
user='your_mysql_user',
|
||||
password='your_mysql_password',
|
||||
database='your_database'
|
||||
)
|
||||
|
||||
def get_user_accounts(user_id):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
userAccounts.username,
|
||||
userAccounts.stream,
|
||||
userAccounts.streamURL,
|
||||
userAccounts.expiaryDate,
|
||||
userAccounts.password
|
||||
FROM users
|
||||
INNER JOIN userAccounts ON users.id = userAccounts.userID
|
||||
WHERE users.id = %s
|
||||
""", (user_id,))
|
||||
data = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return data if data else 'User Not Found'
|
||||
|
||||
def get_user_accounts_check(user_id):
|
||||
return get_user_accounts(user_id)
|
||||
|
||||
def get_all_user_accounts():
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
userAccounts.username,
|
||||
userAccounts.password,
|
||||
userAccounts.expiaryDate,
|
||||
userAccounts.stream
|
||||
FROM userAccounts
|
||||
WHERE userAccounts.expiaryDate != '0'
|
||||
ORDER BY userAccounts.id DESC
|
||||
""")
|
||||
data = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return data if data else 'User Not Found'
|
||||
|
||||
def get_all_unique_accounts():
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("""
|
||||
SELECT DISTINCT userAccounts.stream, userAccounts.username,
|
||||
userAccounts.password, userAccounts.stream
|
||||
FROM userAccounts
|
||||
WHERE userAccounts.expiaryDate != '0'
|
||||
GROUP BY userAccounts.stream
|
||||
""")
|
||||
data = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return data if data else 'User Not Found'
|
||||
|
||||
def get_user_unique_accounts(user_id):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("""
|
||||
SELECT DISTINCT userAccounts.streamURL, userAccounts.username,
|
||||
userAccounts.password, userAccounts.stream, userAccounts.streamURL
|
||||
FROM userAccounts
|
||||
WHERE userAccounts.expiaryDate != '0'
|
||||
AND userAccounts.userId = %s
|
||||
GROUP BY userAccounts.stream
|
||||
ORDER BY userAccounts.stream ASC
|
||||
""", (user_id,))
|
||||
data = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return data if data else 'User Not Found'
|
||||
|
||||
def get_user_id(username):
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT id FROM users WHERE userName = %s", (username,))
|
||||
result = cursor.fetchone()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return result["id"] if result else 'User Not Found'
|
16
requirements.txt
Normal file
16
requirements.txt
Normal file
@ -0,0 +1,16 @@
|
||||
Brotli==1.1.0
|
||||
certifi==2025.4.26
|
||||
cffi==1.17.1
|
||||
charset-normalizer==3.4.2
|
||||
cryptography==44.0.3
|
||||
idna==3.10
|
||||
mysql-connector-python==9.3.0
|
||||
pycparser==2.22
|
||||
pyeasyencrypt==0.1.0
|
||||
pyodbc==5.2.0
|
||||
PySocks==1.7.1
|
||||
python-dotenv==1.1.0
|
||||
requests==2.32.3
|
||||
requests-tor @ git+https://github.com/karl0ss/requests_tor.git@ae1e85abb3bb2c25f431bd031c6d881986c626f6
|
||||
stem==1.8.2
|
||||
urllib3==2.4.0
|
24
routes/auth.py
Normal file
24
routes/auth.py
Normal file
@ -0,0 +1,24 @@
|
||||
from functools import wraps
|
||||
from flask import request, Response
|
||||
from lib.get_users import get_users
|
||||
|
||||
users = get_users()
|
||||
|
||||
def check_auth(username, password):
|
||||
return users.get(username) == password
|
||||
|
||||
def authenticate():
|
||||
return Response(
|
||||
'Could not verify your access.\n',
|
||||
401,
|
||||
{'WWW-Authenticate': 'Basic realm="Login Required"'}
|
||||
)
|
||||
|
||||
def requires_auth(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
auth = request.authorization
|
||||
if not auth or not check_auth(auth.username, auth.password):
|
||||
return authenticate()
|
||||
return f(*args, **kwargs)
|
||||
return decorated
|
Loading…
x
Reference in New Issue
Block a user