Skip to content

Commit

Permalink
Merge pull request #6 from Oneloutre/developement
Browse files Browse the repository at this point in the history
Developement
  • Loading branch information
Oneloutre authored Apr 26, 2024
2 parents d923cd8 + b5a0b17 commit 3f03d07
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 15 deletions.
8 changes: 7 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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 datetime import timedelta, datetime, timezone
from jwt.exceptions import ExpiredSignatureError
from routes.misc.add_proxy import *


APP = flask.Flask(__name__)
Expand Down Expand Up @@ -54,13 +54,19 @@ def add_proxy():
return redirect(url_for('login'))


@APP.route('/please_wait', methods=['GET', 'POST'])
def please_wait():
return render_template('misc/please_wait.html')


@APP.route('/logout', methods=['POST'])
def logout():
resp = flask.make_response(flask.redirect(flask.url_for('login')))
unset_jwt_cookies(resp)
return resp



@jwt.unauthorized_loader
def my_invalid_token_callback():
return redirect(url_for('login'))
Expand Down
43 changes: 37 additions & 6 deletions routes/misc/add_proxy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os.path

import cloudscraper
from flask import render_template, request, jsonify
from flask import render_template, request, jsonify, redirect, url_for
from bs4 import BeautifulSoup
import json

scraper = cloudscraper.create_scraper()

Expand Down Expand Up @@ -98,15 +101,16 @@ def authenticate_user_in_nginx(url, user, password, csrf_access_token, csrf_sent
return render_template('misc/add_proxy.html', error=jsonified['error']['message'])
else:
token = jsonified['token']

headers = {
'Authorization': f'Bearer {token}',
'accept': 'application/json'
}
hosts = scraper.get(url+'/api/nginx/proxy-hosts', headers=headers)
print(hosts.json()[1])
return render_template('misc/add_proxy.html', success='Successfully authenticated !')
#return redirect(url_for('dashboard'))
try:
hosts = scraper.get(url+'/api/nginx/proxy-hosts', headers=headers)
get_hosts(hosts)
except Exception as e:
return render_template('misc/add_proxy.html', error='Error fetching the hosts')
return redirect(url_for('please_wait'))
except Exception as e:
print(e)

Expand All @@ -116,3 +120,30 @@ def verify_credentials_validity(url, user, password):
return False
else:
return True


def get_hosts(hosts):
json_dumped = json.dumps(hosts.json(), indent=4)
with open('user_files/hosts.json', 'w') as file:
file.write(json_dumped)


def register_instance(url, user, password, token):
new_instance = {
"instances": {
"url": url,
"credentials": {
"username": user,
"password": password,
"token": token
}
}
}
if not os.path.exists('user_files/instances.json'):
with open('user_files/hosts.json', 'r') as f:
json.dump(new_instance, f, indent=4)
else:
with open('user_files/hosts.json', 'r') as f:
data = json.load(f)
data['instances']['instance2'] = new_instance
json.dump(data, f, indent=4)
6 changes: 6 additions & 0 deletions routes/misc/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os


def display_dashboard():
if os.path.exists('user_files/admin/instances.json'):

21 changes: 14 additions & 7 deletions static/already_registered.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
body {
background-color: #1e2124;
}

.container {
background-color: #282b30;
border-radius: 10px;
width: 10%;
margin: auto;
margin-top: 20vh;
padding: 20px;
margin-top: 50px;
text-align: center;
}

.text-white {
.loading-content {
color: white;
}

.logo-container img {
max-width: 200px;
}

.text-container p {
margin-top: 20px;
font-size: 20px;
}
2 changes: 1 addition & 1 deletion static/dashboard/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
body {
background-color: #1e2124;
color: #ffffff; /* Text color */
color: #ffffff;
}

.container {
Expand Down
27 changes: 27 additions & 0 deletions static/misc/please_wait.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.page-wrapper {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #1e2124;
}

.container {
background-color: #282b30;
width: 50%;
padding: 100px;
text-align: center;
}

.loading-content {
color: white;
}

.logo-container img {
max-width: 200px;
}

.text-container p {
margin-top: 20px;
font-size: 20px;
}
25 changes: 25 additions & 0 deletions templates/misc/please_wait.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="/static/Assets/favicon.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/misc/please_wait.css">
</head>
<body>
<div class="page-wrapper">
<div class="container">
<div class="loading-content">
<div class="logo-container">
<img src="/static/Assets/loading.gif" alt="Loading Logo">
</div>
<div class="text-container">
<p>Please wait while we process your new instance...</p>
</div>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 3f03d07

Please sign in to comment.