Skip to content

Commit 5f47d31

Browse files
authored
Merge pull request #57 from Pitastic/docker-deployment
Deployment und kleine Fixes
2 parents a8bb32b + bf978d0 commit 5f47d31

22 files changed

Lines changed: 278 additions & 76 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ RUN ln -sf /dev/stdout /var/log/apache2/access.log && \
2121

2222
EXPOSE 80
2323

24-
ENTRYPOINT ["/app/docker/entrypoint.sh"]
24+
ENTRYPOINT ["apachectl", "-D", "FOREGROUND"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ docker compose build
2626
docker compose down && docker compose up -d
2727
```
2828

29+
**Ändere `AUTH_PASSWORD` in der `docker-compose.yaml` !**
30+
31+
2932
### Standalone non-Docker Setup
3033

3134
```
@@ -36,6 +39,8 @@ pip install -r requirements.txt
3639
.venv/bin/python3.12 app/server.py
3740
```
3841

42+
**Ändere das Login Passwort in der `app/config.py` !**
43+
3944
### Start
4045

4146
- Importiere Kontoumsätze über CSV Listen oder PDF Kontoauszüge deiner Bank ([unterstützte Banken](#unterstützte-banken))

app/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#!/usr/bin/python3
22
"""App Settings zum Zeitpunkt der Initalisierung von PynanceParser"""
33

4+
import os
5+
46
# Logging (will also log in webserver logs if used via wsgi)
57
LOG_ACCESS_FILE = '/tmp/pynance_access.log'
68
LOG_ERROR_FILE = '/tmp/pynance_error.log'
79

810
# Options:
9-
DATABASE_BACKEND = 'tiny' # or 'mongo'
11+
12+
# - Login Password (overwrite to not use the system env variable)
13+
PASSWORD = os.getenv('AUTH_PASSWORD', 'change_this_password')
14+
15+
# - Database Backend ('tiny' or 'mongo')
16+
DATABASE_BACKEND = 'tiny'
1017

1118
# For tiny: Path to the Folder (/path/to)
1219
# For mongo: MongoDB URI

app/routes.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import os
55
from datetime import datetime
66
from flask import request, current_app, render_template, redirect, \
7-
make_response, send_from_directory
7+
make_response, send_from_directory, session
8+
import secrets
89

910

1011
class Routes:
@@ -37,6 +38,59 @@ def version_string():
3738
'version': current_app.config.get('VERSION', 'unknown')
3839
}
3940

41+
@current_app.before_request
42+
def require_login():
43+
"""
44+
Before Request Handler, der sicherstellt, dass der User eingeloggt ist.
45+
Falls nicht, wird dieser immer zur Login Seite umeleitet-
46+
"""
47+
# Allow PyTest Client
48+
if current_app.config.get('TESTING', False):
49+
return
50+
51+
# Allow access to login route
52+
if request.endpoint == "login":
53+
return
54+
55+
# Allow access to CSS files
56+
if request.endpoint == "static" and request.path.endswith(".css"):
57+
return
58+
59+
# Allow access to JS files
60+
if request.endpoint == "static" and request.path.endswith(".js"):
61+
return
62+
63+
# Block everything else unless logged in
64+
if not session.get("logged_in"):
65+
return redirect('/login')
66+
67+
@current_app.route("/login", methods=["GET", "POST"])
68+
def login():
69+
"""
70+
Login Seite, die ohne gültiges Cookie immer aufgerufen wird.
71+
Args (form):
72+
password, str: Passwort für den Login
73+
Returns:
74+
html: Login Formular
75+
"""
76+
error = None
77+
78+
if request.method == "POST":
79+
password = request.form.get("password", "")
80+
if secrets.compare_digest(password, current_app.config['PASSWORD']):
81+
session["logged_in"] = True
82+
return redirect('/')
83+
84+
error = "Invalid password"
85+
86+
return render_template('login.html', error=error)
87+
88+
@current_app.route("/logout")
89+
def logout():
90+
"""Logout Seite, welche das Cookie löscht und zur Loin Seite weiterleitet."""
91+
session.clear()
92+
return redirect('/login')
93+
4094
@current_app.route('/', methods=['GET'])
4195
def welcome() -> str:
4296
"""
@@ -215,16 +269,6 @@ def show_stats(iban) -> str:
215269
return render_template('stats.html', sums=sums, IBAN=iban,
216270
filters=frontend_filters)
217271

218-
@current_app.route('/logout', methods=['GET'])
219-
def logout():
220-
"""
221-
Loggt den User aus der Session aus und leitet zur Startseite weiter.
222-
223-
Returns:
224-
redirect: Weiterleitung zur Startseite
225-
"""
226-
return redirect('/')
227-
228272
@current_app.route('/sw.js')
229273
def sw():
230274
response = make_response(

app/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def create_app(config_path: str) -> Flask:
3939
template_folder=os.path.join(parent_dir, 'app', 'templates'),
4040
static_folder=os.path.join(parent_dir, 'app', 'static')
4141
)
42+
app.secret_key = os.urandom(24).hex()
4243

4344
# Global Config
4445
app.config.from_pyfile(config_path)

app/static/css/style.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ main {
1515
flex: 1;
1616
}
1717

18-
.container.hero {
19-
margin-top: 10%;
18+
.container.hero {margin-top: 10%;}
19+
main.container.hero {margin-top: 5%;}
20+
21+
.margin-top{
22+
margin-top: 2em;
2023
}
2124

2225
/* Pico Tooltip Feature with newlines*/
@@ -38,6 +41,10 @@ main {
3841
@media (max-width: 1023px) {.hide-m {display:none !important;}}
3942

4043
/* Color classes */
44+
.error {
45+
color: var(--pico-color-red-600);
46+
font-weight: bold;
47+
}
4148
.delete {
4249
color: white;
4350
border-color: var(--pico-color-red-600);

app/templates/iban.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h3>
2626
&#128202; <a href="/{{IBAN}}/stats?{{ request.query_string.decode('utf-8')|safe }}" title="Statistiken">Statistik</a>
2727
</li>
2828
<li>
29-
&#128682; <a href="/logout" title="Logout">Logout</a>
29+
&#128218; <a href="/" title="Konten">Konten</a>
3030
</li>
3131
</ul>
3232
</nav>

app/templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<header>
66
<hgroup class="container hero">
77
<h1>Pynance Parser</h1>
8-
<p>Manage Bankaccounts like a Boss !</p>
8+
<p>Manage Bankaccounts like a Boss !</p>
99
</hgroup>
1010
</header>
1111

@@ -55,6 +55,7 @@ <h1>Pynance Parser</h1>
5555

5656
<section>
5757
<p>Das Konto wird bei einem Import automatisch erstellt.</p>
58+
<p><a href="/logout" role="button" class="secondary margin-top">Logout</a></p>
5859
</section>
5960

6061
</main>

app/templates/login.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{% extends 'layout.html' %}
2+
3+
{% block content %}
4+
5+
<header>
6+
<hgroup class="container hero">
7+
<h1>Pynance Parser</h1>
8+
<p>Manage Bankaccounts like a Boss !</p>
9+
</hgroup>
10+
</header>
11+
12+
<main class="container hero">
13+
14+
<section class="grid m-6-6 margin">
15+
16+
<form method="post" action="/login">
17+
<div role="group">
18+
<input type="password" name="password" value=""
19+
placeholder="Passwort"
20+
{% if error %}aria-invalid="true"{%endif%}
21+
>
22+
<input type="submit" value="🔒" role="button">
23+
</div>
24+
</form>
25+
26+
</section>
27+
28+
{% if error %}
29+
<section>
30+
<p class="error">{{ error }}</p>
31+
</section>
32+
{% endif %}
33+
34+
</main>
35+
36+
37+
{% endblock %}

docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ services:
77
volumes:
88
- ./settings:/app/settings
99
environment:
10-
- AUTH_USER=username
1110
- AUTH_PASSWORD=yourpasswordhere
1211

1312
mongo:

0 commit comments

Comments
 (0)