add admin panel
This commit is contained in:
parent
ea3c737c04
commit
a5d02f3efd
5 changed files with 49 additions and 3 deletions
|
@ -4,6 +4,9 @@ db_password=""
|
||||||
db_host=postgres.hackclub.app
|
db_host=postgres.hackclub.app
|
||||||
db_port=5432
|
db_port=5432
|
||||||
|
|
||||||
|
BASIC_AUTH_USERNAME="admin"
|
||||||
|
BASIC_AUTH_PASSWORD="veryverylongpasswordthatshouldbesafe"
|
||||||
|
|
||||||
SYNC_SERVER_URL="sync.example.com"
|
SYNC_SERVER_URL="sync.example.com"
|
||||||
HOST="0.0.0.0"
|
HOST="0.0.0.0"
|
||||||
PORT=80
|
PORT=80
|
12
main.py
12
main.py
|
@ -1,4 +1,5 @@
|
||||||
from flask import Flask, request, make_response, render_template
|
from flask import Flask, request, make_response, render_template
|
||||||
|
from flask_basicauth import BasicAuth
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask_sock import Sock
|
from flask_sock import Sock
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
@ -9,6 +10,10 @@ import os
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
sock = Sock(app)
|
sock = Sock(app)
|
||||||
|
basic_auth = BasicAuth(app)
|
||||||
|
|
||||||
|
app.config['BASIC_AUTH_USERNAME'] = os.getenv("AUTH_USERNAME")
|
||||||
|
app.config['BASIC_AUTH_PASSWORD'] = os.getenv("AUTH_PASSWORD")
|
||||||
|
|
||||||
def make_resp(data=''):
|
def make_resp(data=''):
|
||||||
response = make_response(data)
|
response = make_response(data)
|
||||||
|
@ -136,6 +141,13 @@ def websocket(ws):
|
||||||
if operation == "usernames": # TODO
|
if operation == "usernames": # TODO
|
||||||
ws.send(json.dumps({"1": "Mathias"}))
|
ws.send(json.dumps({"1": "Mathias"}))
|
||||||
|
|
||||||
|
@app.route("/admin")
|
||||||
|
@basic_auth.required
|
||||||
|
def admin_panel():
|
||||||
|
users = database.db.execute_query("SELECT name, email FROM users;")
|
||||||
|
vaults = database.db.execute_query("SELECT name, (SELECT name FROM users WHERE uid=owner) FROM vaults;")
|
||||||
|
return render_template("admin.html", users=users, vaults=vaults)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index_page():
|
def index_page():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
psycopg2
|
psycopg2
|
||||||
python-dotenv
|
python-dotenv
|
||||||
flask
|
Flask
|
||||||
flask-sock
|
flask-sock
|
||||||
|
Flask-BasicAuth
|
30
templates/admin.html
Normal file
30
templates/admin.html
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Obsidian Sync server</title>
|
||||||
|
<link rel="icon" href="https://obsidian.md/favicon.ico" sizes="32x32">
|
||||||
|
<link rel="icon" href="https://obsidian.md/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
|
<link rel="apple-touch-icon" href="https://obsidian.md/apple-touch-icon.png">
|
||||||
|
<style>
|
||||||
|
body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- Copy of nginx homepage -->
|
||||||
|
<h1>Obsidian Sync / Admin Panel</h1>
|
||||||
|
Users:
|
||||||
|
<ul>
|
||||||
|
{% for user in users %}
|
||||||
|
<li>{{ user[0] }} ({{ user[1] }})</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
Vaults:
|
||||||
|
<ul>
|
||||||
|
{% for vault in vaults %}
|
||||||
|
<li>{{ vault[0] }} ({{ vault[1] }})</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -13,7 +13,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- Copy of nginx homepage -->
|
<!-- Copy of nginx homepage -->
|
||||||
<h1>Obsidian Sync server</h1>
|
<h1>Obsidian Sync</h1>
|
||||||
<p>If you see this page, your Obsidian Sync server server is successfully installed and working.</p>
|
<p>If you see this page, your Obsidian Sync server server is successfully installed and working.</p>
|
||||||
<p>Available at <a href="https://git.hackclub.app/mathias/obsidian_freesync">mathias/obsidian_freesync</a></p>
|
<p>Available at <a href="https://git.hackclub.app/mathias/obsidian_freesync">mathias/obsidian_freesync</a></p>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue