Skip to content

Commit

Permalink
Merge pull request #2 from Oneloutre/dev-add-proxy
Browse files Browse the repository at this point in the history
🔥 Fixing auth - adding proxy method - added requirements.txt - a…
  • Loading branch information
Oneloutre committed Apr 25, 2024
2 parents 8ace604 + 33b80fd commit 88d382f
Show file tree
Hide file tree
Showing 17 changed files with 313 additions and 53 deletions.
24 changes: 20 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import flask
from routes.auth.login import *
from routes.auth.register import *
from routes.misc.add_proxy import *
import os
from flask_jwt_extended import jwt_required, JWTManager, unset_jwt_cookies, get_jwt_identity, get_jwt
from flask_jwt_extended import jwt_required, JWTManager, unset_jwt_cookies, get_jwt_identity, get_jwt, verify_jwt_in_request
from datetime import timedelta, datetime, timezone


APP = flask.Flask(__name__)
jwt = JWTManager(APP)

Expand All @@ -24,18 +26,32 @@ def login():
@APP.route('/register', methods=['GET', 'POST'])
def register():
if os.path.exists('user_files/admin/admin.json'):
return 'You are already registered'
return redirect(url_for('index'), code=301)

return render_template('auth/already_registered.html')
else:
return register_user()


@APP.route('/', methods=['GET', 'POST'])
@jwt_required()
def index():
return render_template('index.html', code=200)
return redirect(url_for('dashboard'))


@APP.route('/dashboard', methods=['GET', 'POST'])
@jwt_required()
def dashboard():
return render_template('dashboard.html', code=200)


@APP.route('/add_proxy', methods=['GET', 'POST'])
def add_proxy():
if 'csrf_access_token' in request.cookies:
csrf_access_token = request.cookies['csrf_access_token']
return proxy_add_new(csrf_access_token)
else:
return redirect(url_for('login'))

@APP.route('/logout', methods=['POST'])
def logout():
resp = flask.make_response(flask.redirect(flask.url_for('login')))
Expand Down
18 changes: 18 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bcrypt==4.1.2
blinker==1.7.0
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
cloudscraper==1.2.71
Flask==3.0.3
Flask-JWT-Extended==4.6.0
idna==3.7
itsdangerous==2.2.0
Jinja2==3.1.3
MarkupSafe==2.1.5
PyJWT==2.8.0
pyparsing==3.1.2
requests==2.31.0
requests-toolbelt==1.0.0
urllib3==2.2.1
Werkzeug==3.0.2
4 changes: 2 additions & 2 deletions routes/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def log_in():
return response
else:
error = 'Invalid Credentials. Please try again.'
return render_template('login/login.html', error=error)
return render_template('login/login.html', error=error)
return render_template('auth/login/login.html', error=error)
return render_template('auth/login/login.html', error=error)


def load_encrypted_creds(file):
Expand Down
4 changes: 2 additions & 2 deletions routes/auth/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def register_user():
confirm_password = request.form['confirm_password']
if isFormEmpty(request.form):
error = 'Please fill all the fields'
return render_template('register/register.html', error=error)
return render_template('auth/register/register.html', error=error)

if password != confirm_password:
error = 'Passwords do not match'
Expand All @@ -21,7 +21,7 @@ def register_user():
with open('user_files/admin/admin.json', 'w') as file:
file.write('{\n "username": "' + crypted_username.decode('utf-8') + '",\n "email": "' + crypted_email.decode('utf-8') + '",\n "password": "' + crypted_password.decode('utf-8') + '"\n}')
return redirect(url_for('login'))
return render_template('register/register.html', error=error)
return render_template('auth/register/register.html', error=error)


def isFormEmpty(form):
Expand Down
54 changes: 54 additions & 0 deletions routes/misc/add_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import cloudscraper
from flask import render_template, request, redirect, url_for, make_response, jsonify, session

scraper = cloudscraper.create_scraper()

def proxy_add_new(csrf_access_token):
error = None
if request.method == 'POST':
if csrf_access_token != request.form['csrf_token']:
return jsonify({'error': 'Invalid CSRF token'}), 400
else:
url_form = request.form['target']
url = url_form.strip()
if not url:
error = 'URL is required.'
return render_template('misc/add_proxy.html', error=error)
else:
if validate(url):
pass
else:
url = 'http://' + url
try:
response = timeout_checker(url)
if response == "Host seems up and running !":
return render_template('misc/add_proxy.html', success='Host seems up and running.')
elif response == "Timeout Error":
error = 'Timeout Error'
else:
error = 'Error fetching the URL'
except:
error = ''
return render_template('misc/add_proxy.html', error=error)

def validate(url):
if not (url.startswith('http://') or url.startswith('https://')):
return False
else:
return True


#def check_proxy_validity(url, timeout=5):


def timeout_checker(url, timeout=5):
try:
response = scraper.get(url, timeout=timeout)
response.raise_for_status()
return 'Host seems up and running !'
except Exception as e:
print(e)
if "Read timed out" in str(e):
return 'Timeout Error'
else:
return 'Error'
Binary file added static/Assets/pm2xNginx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions static/already_registered.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
background-color: #1e2124;
}

.container {
background-color: #282b30;
border-radius: 10px;
padding: 20px;
margin-top: 50px;
}

.text-white {
color: white;
}
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions static/dashboard/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
background-color: #1e2124;
color: #ffffff; /* Text color */
}

.container {
background-color: #282b30;
padding: 20px;
border-radius: 10px;
margin-top: 20px;
}
54 changes: 54 additions & 0 deletions static/misc/add_proxy.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body {
background-color: #1e2124;
}

.img-fluid{
margin-top: 60px;
margin-left: -2px;
max-width: 100px;
max-height: 400px;
}

.card {
background-color: #282b30;
color: #ffffff;
border-radius: 5px;
width: 600px;
margin-top: 50px;
}

.card-header {
background-color: #282b30;
text-align: center;
border-bottom: 1px solid #ffffff;
}

.btn-primary {
background-color: #007bff;
border-color: #007bff;
}

.btn-primary:hover {
background-color: #007bff;
border-color: #007bff;
}

.btn-success {
background-color: #007bff;
border-color: #007bff;
}

.btn-success:hover {
background-color: #007bff;
border-color: #007bff;
}

.error {
color: red;
font-size: 15px;
}

.success {
color: green;
font-size: 15px;
}
26 changes: 26 additions & 0 deletions templates/auth/already_registered.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Already Registered</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/static/already_registered.css">
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="banner">
<img src="static/Assets/BannerNginxPM2.png" class="img-fluid banner-img" alt="Bannière">
</div>
<h1 class="text-center text-white mt-5">Already Registered !</h1>
<p class="text-center text-white mt-3">You are already registered. Please login, or head up to the dashboard.</p>
<div class="text-center mt-4">
<a href="/dashboard" class="btn btn-primary">Go to Dashboard</a>
</div>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link href="static/login/style.css" rel="stylesheet">
<link href="static/auth/login/style.css" rel="stylesheet">
</head>
<body>
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register Page</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link href="static/register/style.css" rel="stylesheet">
<link href="static/auth/register/style.css" rel="stylesheet">
</head>
<body>
<div class="container">
Expand Down
51 changes: 51 additions & 0 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<!-- Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="static/dashboard/style.css" rel="stylesheet">
</head>
<body>

<div class="container">
<h1>Dashboard</h1>
<div class="row">
<div class="col-md-4">
<div class="card bg-dark text-white">
<div class="card-body">
<h5 class="card-title">Card 1</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card bg-dark text-white">
<div class="card-body">
<h5 class="card-title">Card 2</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card bg-dark text-white">
<div class="card-body">
<h5 class="card-title">Card 3</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>

</div>
</div>

<!-- Bootstrap JS and dependencies (not required for styling) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

</body>
</html>
43 changes: 0 additions & 43 deletions templates/index.html

This file was deleted.

Loading

0 comments on commit 88d382f

Please sign in to comment.