restructure for docker

This commit is contained in:
Ville Rantanen
2023-07-24 20:02:49 +03:00
parent 58abf04d2c
commit a0c0d69c5e
8 changed files with 213 additions and 146 deletions

View File

@@ -1,11 +1,3 @@
# Security Policy # Security Policy
## Supported Versions Use at your own risk.
Only the latest version is supported.
## Reporting a Vulnerability
Please send a mail to agreper+security@demindiro.com
PGP key: [7897 2A80 BC74 A394 1C50 F060 A915 6EA5 E4B6 44FF](https://www.demindiro.com/pubkey.pgp.asc)

View File

@@ -1,4 +1,4 @@
VERSION = "agreper-v0.1.1q1" from version import VERSION
# TODO put in config table # TODO put in config table
THREADS_PER_PAGE = 50 THREADS_PER_PAGE = 50

View File

@@ -73,8 +73,6 @@ td > input[type=text], td > input[type=password] {
.logo { .logo {
margin: 0; margin: 0;
padding: 5px;
padding-left: 15px;
font-size: 3em; font-size: 3em;
font-weight: bold; font-weight: bold;
} }
@@ -138,3 +136,81 @@ table.form > * > tr > td, th {
opacity: 1; opacity: 1;
color: white; color: white;
} }
/* Dropdown menu */
.navbar {
overflow: hidden;
background-color: #333;
font-family: inherit;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 0px 0px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
.button_image {
height: 50px;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: black;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #444;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: #F9F6EE;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #555;
}
.dropdown-content a:visited {
color: #F9F6EE;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Admin */
.admin_h2 {
background-color: rgba(0,0,0,0.15);
}

View File

@@ -4,38 +4,15 @@
<title>{{ title }}</title> <title>{{ title }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="utf-8" http-equiv="encoding"> <meta content="utf-8" http-equiv="encoding">
<style> <link rel=stylesheet href="{{ url_for('static', filename='theme.css') }}">
body { {%- if config.server_name -%}
font-family: sans-serif; <link rel=stylesheet href="{{ url_for('static', filename='user.css') }}">
} {%- endif -%}
.flash.success {
background-color: lightgreen;
border-radius: 5px;
padding: 8px;
}
.flash.error {
background-color: #ff4646;
border-radius: 5px;
padding: 8px;
}
table {
border-collapse: collapse;
width: 80%;
}
th, td {
border: 1px solid;
padding: 5px;
text-align: left;
}
textarea {
width: 95%;
}
</style>
</head> </head>
<body> <body>
<h1>{{ title }}</h1> <h1>{{ title }}</h1>
<p> <p>
<a href="{{ url_for('admin') }}">Admin panel</a> <a href="{{ url_for('admin') }}">Admin panel</a><span> | </span>
<a href="{{ url_for('index') }}">Home page</a> <a href="{{ url_for('index') }}">Home page</a>
</p> </p>
{%- for category, msg in get_flashed_messages(True) -%} {%- for category, msg in get_flashed_messages(True) -%}

View File

@@ -1,84 +1,7 @@
{% extends 'admin/base.html' -%} {% extends 'admin/base.html' -%}
{% block content -%} {% block content -%}
<h2>Query</h2> <!-- -->
<p>&#9888; Only use queries if you know what you're doing &#9888;</p> <h2 class=admin_h2>Users</h2>
<form action=query/ method=post>
<input type=text name=q placeholder="SELECT * from users">
<input type=submit value=Submit>
</form>
<h2>Configuration</h2>
<form action=config/edit/ method=post>
<table>
<tr>
<td>Server name</td>
<td><input type=text name=server_name value="{{ config.server_name }}"></td>
</tr>
<tr>
<td>Server description</td>
<td><textarea name=server_description>{{ config.server_description }}</textarea></td>
</tr>
<tr>
<td>Registration enabled</td>
<td><input name=registration_enabled type=checkbox {{ 'checked' if config.registration_enabled else '' }}></td>
</tr>
<tr>
<td>Login required</td>
<td><input name=login_required type=checkbox {{ 'checked' if config.login_required else '' }}></td>
</tr>
</table>
<input type=submit value=Update>
</form>
<p>
<form action=config/new_secrets/ method=post>
<input type=submit value="Generate new secrets">
</form>
</p>
<p>
<form action=restart/ method=post>
<input type=submit value="Restart">
</form>
</p>
<h2>Forums</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Actions</th>
</tr>
{% for id, name, description, _, _, _ in forums %}
<tr>
<td>{{ id }}</td>
<td>
<form method=post action="forum/{{ id }}/edit/name/">
<input type=text name=name value="{{ name }}"</input>
<input type=submit value="Set name">
</form>
<td>
<form method=post action="forum/{{ id }}/edit/description/">
<textarea name=description>{{ description }}</textarea>
<input type=submit value="Set description">
</form>
</td>
<td><a href="#">Remove</a></td>
</tr>
{% endfor %}
</table>
<h3>Add forum</h3>
<form method=post action="forum/new/">
<table>
<tr>
<td>Name</td>
<td><input type=text name=name></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name=description></textarea></td>
</tr>
</table>
<input type=submit value="Add forum">
</form>
<h2>Users</h2>
<table> <table>
<tr> <tr>
<th>ID</th> <th>ID</th>
@@ -126,4 +49,93 @@
</table> </table>
<input type=submit value="Add user"> <input type=submit value="Add user">
</form> </form>
<!-- -->
<h2 class=admin_h2>Forums</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Actions</th>
</tr>
{% for id, name, description, _, _, _ in forums %}
<tr>
<td>{{ id }}</td>
<td>
<form method=post action="forum/{{ id }}/edit/name/">
<input type=text name=name value="{{ name }}"</input>
<input type=submit value="Set name">
</form>
<td>
<form method=post action="forum/{{ id }}/edit/description/">
<textarea name=description>{{ description }}</textarea>
<input type=submit value="Set description">
</form>
</td>
<td><a href="#">Remove</a></td>
</tr>
{% endfor %}
</table>
<h3>Add forum</h3>
<form method=post action="forum/new/">
<table>
<tr>
<td>Name</td>
<td><input type=text name=name></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name=description></textarea></td>
</tr>
</table>
<input type=submit value="Add forum">
</form>
<!-- -->
<h2 class=admin_h2>Configuration</h2>
<form action=config/edit/ method=post>
<table>
<tr>
<td>Server name</td>
<td><input type=text name=server_name value="{{ config.server_name }}"></td>
</tr>
<tr>
<td>Server description</td>
<td><textarea name=server_description>{{ config.server_description }}</textarea></td>
</tr>
<tr>
<td>Registration enabled</td>
<td><input name=registration_enabled type=checkbox {{ 'checked' if config.registration_enabled else '' }}></td>
</tr>
<tr>
<td>Login required</td>
<td><input name=login_required type=checkbox {{ 'checked' if config.login_required else '' }}></td>
</tr>
</table>
<input type=submit value=Update>
</form>
<p>
<form action=config/new_secrets/ method=post>
<input type=submit value="Generate new secrets">
</form>
</p>
<p>
<form action=restart/ method=post>
<input type=submit value="Restart">
</form>
</p>
<!-- -->
<h2 class=admin_h2>Query</h2>
<p>&#9888; Only use queries if you know what you're doing &#9888;</p>
<form action=query/ method=post>
<input type=text name=q placeholder="SELECT * from users">
<input type=submit value=Submit>
</form>
{%- endblock %} {%- endblock %}

View File

@@ -11,7 +11,8 @@
</head> </head>
<body> <body>
<nav> <nav>
<a class=logo href="{{ url_for('index') }}">A</a> <!--
<a class=logo href="{{ url_for('index') }}">⛤</a>
<div style="margin:auto"></div> <div style="margin:auto"></div>
{%- if user is not none -%} {%- if user is not none -%}
<a href="{{ url_for('user_edit') }}"> <a href="{{ url_for('user_edit') }}">
@@ -31,8 +32,36 @@
{%- endif -%} {%- endif -%}
<a href="{{ url_for('login') }}">Login</a> <a href="{{ url_for('login') }}">Login</a>
{%- endif -%} {%- endif -%}
<span> | </span> <a href="https://www.markdownguide.org/cheat-sheet/" target=_blank>Syntax help</a>
<a href="{{ url_for('help') }}">Help</a> -->
<div class="navbar">
<div class="dropdown">
<button class="dropbtn"><img class="button_image" src={{ url_for('static', filename='button.png') }}>
<!--i class="fa fa-caret-down"></i-->
</button>
<div class="dropdown-content">
<a href="{{ url_for('index') }}">Home</a>
{%- if user is not none -%}
<a href="{{ url_for('user_edit') }}">
Profile
{%- if user.is_banned() %} (banned for {{ format_until(user.banned_until) }}){% endif -%}
</a>
{%- if user.is_admin() -%}
<a href="{{ url_for('admin') }}">Admin panel</a>
{%- endif -%}
<a href="{{ url_for('logout') }}">Logout</a>
{%- else -%}
{%- if config.registration_enabled -%}
<a href="{{ url_for('register') }}">Register</a>
{%- endif -%}
<a href="{{ url_for('login') }}">Login</a>
{%- endif -%}
{%- if user is not none -%}
<a href="https://www.markdownguide.org/cheat-sheet/" target=_blank>Syntax help</a>
{%- endif -%}
</div>
</div>
</div>
</nav> </nav>
<main> <main>
<h1>{{ title }}</h1> <h1>{{ title }}</h1>

View File

@@ -23,6 +23,9 @@ cmd = arg(1, f"usage: {proc} <command> [...]")
if cmd == "password": if cmd == "password":
pwd = arg_last(2, "usage: {proc} password <pwd>") pwd = arg_last(2, "usage: {proc} password <pwd>")
print(password.hash(pwd)) print(password.hash(pwd))
elif cmd == "version":
from version import VERSION
print(VERSION)
else: else:
print("unknown command ", cmd) print("unknown command ", cmd)
sys.exit(1) sys.exit(1)

View File

@@ -1,27 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
docker-compose up -d -t 0 --build forum
if [ -z "$SERVER" ] docker-compose logs -f
then
echo "SERVER is not set" >&2
exit 1
fi
case "$SERVER" in
dev)
touch main.py
;;
gunicorn)
if [ -z "$PID" ]
then
echo "PID is not set" >&2
exit 1
fi
kill -hup $(cat "$PID")
;;
*)
echo "Unsupported $SERVER" >&2
exit 1
;;
esac