Ready For 1.1

This commit is contained in:
nocci 2025-05-10 16:14:22 +02:00
parent c23f2f88e8
commit 7a221acb8e
11 changed files with 297 additions and 146 deletions

211
setup.sh
View file

@ -144,18 +144,18 @@ DEFAULT_LANGUAGE="en"
SUPPORTED_LANGUAGES="de,en"
# Timezone
TZ=Europe/Berlin
TZ="Europe/Berlin"
# Security
FORCE_HTTPS=False
SESSION_COOKIE_SECURE=auto
FORCE_HTTPS="False"
SESSION_COOKIE_SECURE="auto"
CSRF_ENABLED="True"
# Account registration
REGISTRATION_ENABLED="True"
# checking interval if keys have to be redeemed before a specific date
CHECK_EXPIRING_KEYS_INTERVAL_HOURS=6
CHECK_EXPIRING_KEYS_INTERVAL_HOURS="6"
# Want to check prices? Here you are!
ITAD_API_KEY="your-secret-key-here"
@ -170,7 +170,7 @@ APPRISE_URLS=""
#matrixs://TOKEN@matrix.org/!ROOM_ID"
# Redis URL
REDIS_URL=redis://redis:6379/0
REDIS_URL="redis://redis:6379/0"
# Enable Debug (e.g. for VS Code)
FLASK_DEBUG=1
@ -253,6 +253,7 @@ from sqlalchemy.engine import Engine
from sqlalchemy.exc import IntegrityError, LegacyAPIWarning
from sqlalchemy.orm import joinedload
from werkzeug.security import check_password_hash, generate_password_hash
from werkzeug.middleware.proxy_fix import ProxyFix
from wtforms import SelectField, StringField, TextAreaField, validators
# Config
@ -281,6 +282,11 @@ app.jinja_env.globals['getattr'] = getattr
def not_found_error(error):
return render_template('404.html'), 404
app.wsgi_app = ProxyFix(
app.wsgi_app,
x_proto=1, # Trust X-Forwarded-Proto Header
x_host=1 # Trust X-Forwarded-Host Header
)
# UNIX-Systems (Linux, Docker)
try:
@ -1162,7 +1168,7 @@ def generate_redeem(game_id):
)
db.session.add(new_token)
db.session.commit()
redeem_url = url_for('redeem', token=token, _external=True)
redeem_url = url_for('redeem', token=token, _external=True, _scheme='https')
message = translate(
'Redeem link generated: <a href="{url}" target="_blank">{url}</a>',
url=redeem_url
@ -1186,22 +1192,25 @@ def redeem_page(token):
redeem_token.used = True
db.session.commit()
# which Plattform
if game.platform == "steam" or game.steam_appid:
if game.platform == 'steam':
platform_link = 'https://store.steampowered.com/account/registerkey?key='
platform_label = "Steam"
elif game.platform == "gog":
platform_name = 'Steam'
elif game.platform == 'gog':
platform_link = 'https://www.gog.com/redeem/'
platform_label = "GOG"
elif game.platform == "xbox":
platform_name = 'GOG'
elif game.platform == 'xbox':
platform_link = 'https://redeem.microsoft.com/'
platform_label = "XBOX"
elif game.platform == "playstation":
platform_link = 'https://store.playstation.com/redeem'
platform_label = "PlayStation"
platform_name = 'Xbox'
elif game.platform == 'playstation':
platform_link = 'https://redeem.playstation.com/'
platform_name = 'PlayStation'
elif game.platform == 'switch':
platform_link = 'https://ec.nintendo.com/redeem/'
platform_name = 'Nintendo Switch'
else:
platform_link = '#'
platform_label = game.platform.capitalize() if game.platform else "Unknown"
# Fallback für benutzerdefinierte Keys
platform_link = ''
platform_name = 'Key'
return render_template(
'redeem.html',
@ -1209,9 +1218,10 @@ def redeem_page(token):
redeem_token=redeem_token,
expires_timestamp=int(expires_utc.timestamp() * 1000),
platform_link=platform_link,
platform_label=platform_label
platform_name=platform_name
)
@app.route('/admin/users')
@login_required
@admin_required
@ -1524,6 +1534,7 @@ cat <<HTML_END > templates/base.html
<meta name="theme-color" content="#212529">
<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
<title>{{ _('Game Key Manager') }}</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<!-- Preload Bootstrap CSS for better LCP -->
<link rel="preload" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"></noscript>
@ -1565,26 +1576,34 @@ cat <<HTML_END > templates/base.html
<input class="form-control me-2" type="search" name="q" id="searchInput" placeholder="{{ _('Search') }}" value="{{ search_query }}">
<button class="btn btn-outline-success" type="submit" aria-label="{{ _('Search') }}">🔍</button>
</form>
<ul class="navbar-nav ms-lg-3 mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="langDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<div class="dropdown ms-3">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{% if session.get('lang', 'en') == 'de' %} Deutsch {% elif session.get('lang', 'en') == 'en' %} English {% else %} Sprache {% endif %}
</a>
<ul class="dropdown-menu" aria-labelledby="langDropdown">
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item {% if session.get('lang', 'en') == 'de' %}active{% endif %}" href="{{ url_for('set_lang', lang='de') }}">Deutsch</a></li>
<li><a class="dropdown-item {% if session.get('lang', 'en') == 'en' %}active{% endif %}" href="{{ url_for('set_lang', lang='en') }}">English</a></li>
</ul>
</li>
{% if current_user.is_authenticated %}
{% if current_user.is_admin %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin_users') }}">⚙️ {{ _('Admin') }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin_audit_logs') }}">📜 {{ _('Audit Logs') }}</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('change_password') }}">🔒 {{ _('Password') }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('logout') }}">🚪 {{ _('Logout') }}</a></li>
{% endif %}
</ul>
</ul>
</div>
{% if current_user.is_authenticated %}
<div class="dropdown ms-3">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ _('Import/Export') }}
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="{{ url_for('export_games') }}">⬇️ {{ _('Export CSV') }}</a></li>
<li><a class="dropdown-item" href="{{ url_for('export_pdf') }}">⬇️ Export PDF (for sharing)</a></li>
<li><a class="dropdown-item" href="{{ url_for('import_games') }}">⬆️ {{ _('Import CSV') }}</a></li>
</ul>
</div>
{% if current_user.is_admin %}
<a class="btn btn-outline-secondary ms-3" href="{{ url_for('admin_users') }}">⚙️ {{ _('Admin') }}</a>
<a class="btn btn-outline-secondary ms-1" href="{{ url_for('admin_audit_logs') }}">📜 {{ _('Audit Logs') }}</a>
{% endif %}
<a class="btn btn-outline-secondary ms-3" href="{{ url_for('change_password') }}">🔒 {{ _('Password') }}</a>
<a class="btn btn-outline-danger ms-1" href="{{ url_for('logout') }}">🚪 {{ _('Logout') }}</a>
{% endif %}
</div>
</div>
</nav>
<div class="container mt-4">
@ -1652,16 +1671,7 @@ HTML_END
cat <<'HTML_END' > templates/index.html
{% extends "base.html" %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>{{ _('My Games') }}</h1>
<div>
<a href="{{ url_for('export_games') }}" class="btn btn-outline-secondary">⬇️ {{ _('Export CSV') }}</a>
<a href="{{ url_for('export_pdf') }}" class="btn btn-outline-secondary">⬇️ Export PDF (for sharing)</a>
<a href="{{ url_for('import_games') }}" class="btn btn-outline-secondary">⬆️ {{ _('Import CSV') }}</a>
<a href="{{ url_for('add_game') }}" class="btn btn-primary">+ {{ _('Add New Game') }}</a>
</div>
</div>
<button id="toggle-keys" class="btn btn-sm btn-outline-secondary mb-2">{{ _('Show/Hide Keys') }}</button>
{% if games %}
<div class="table-responsive">
<table class="table table-hover align-middle">
@ -1669,7 +1679,7 @@ cat <<'HTML_END' > templates/index.html
<tr>
<th>{{ _('Cover') }}</th>
<th>{{ _('Name') }}</th>
<th>{{ _('Key') }}</th>
<th class="key-col d-md-table-cell">{{ _('Key') }}</th>
<th>{{ _('Status') }}</th>
<th>{{ _('Created') }}</th>
<th>{{ _('Redeem by') }}</th>
@ -1685,15 +1695,15 @@ cat <<'HTML_END' > templates/index.html
<a href="{{ url_for('game_details', game_id=game.id) }}" title="{{ _('Details') }}">
{% if game.steam_appid %}
<img src="https://cdn.cloudflare.steamstatic.com/steam/apps/{{ game.steam_appid }}/header.jpg"
alt="Steam Header"
alt="Steam Header"
class="game-cover"
{% if loop.first %}fetchpriority="high"{% endif %}
width="368"
width="368"
height="172"
loading="lazy">
{% elif game.url and 'gog.com' in game.url %}
<img src="{{ url_for('static', filename='gog_logo.webp') }}"
alt="GOG Logo"
alt="GOG Logo"
class="game-cover"
width="368"
height="172"
@ -1702,7 +1712,7 @@ cat <<'HTML_END' > templates/index.html
</a>
</td>
<td>{{ game.name }}</td>
<td class="font-monospace">{{ game.steam_key }}</td>
<td class="font-monospace key-col d-none d-md-table-cell">{{ game.steam_key }}</td>
<td>
{% if game.status == 'nicht eingelöst' %}
<span class="badge bg-warning text-dark">{{ _('Not redeemed') }}</span>
@ -1752,8 +1762,8 @@ cat <<'HTML_END' > templates/index.html
</td>
<td class="text-nowrap">
{% if game.status == 'geschenkt' %}
<button type="button"
class="btn btn-sm btn-success generate-redeem"
<button type="button"
class="btn btn-sm btn-success generate-redeem"
data-game-id="{{ game.id }}"
title="{{ _('Generate redeem link') }}">
🔗
@ -1774,7 +1784,7 @@ cat <<'HTML_END' > templates/index.html
document.querySelectorAll('.generate-redeem').forEach(btn => {
btn.addEventListener('click', async function() {
const gameId = this.dataset.gameId;
const flashContainer = document.querySelector('.flash-container');
const flashContainer = document.querySelector('.flash-container')
try {
const response = await fetch(`/generate_redeem/${gameId}`, {
@ -1786,22 +1796,36 @@ document.querySelectorAll('.generate-redeem').forEach(btn => {
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || '{{ _("Unknown error") }}');
}
if (data.url) {
await navigator.clipboard.writeText(data.url);
// Erfolgsmeldung mit übersetztem Text
flashContainer.innerHTML = `
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ _("Link copied") }}: <a href="${data.url}" target="_blank">${data.url}</a>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
`;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(data.url)
.then(() => {
// Succcess ?? maybe
flashContainer.innerHTML = `
<div class="alert alert-success alert-dismissible fade show" role="alert">
{{ _("Link copied") }}: <a href="${data.url}" target="_blank">${data.url}</a>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
`;
})
.catch(err => {
flashContainer.innerHTML = `
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{ _("Clipboard error") }}: ${err.message}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
`;
});
} else {
alert("Clipboard API is not supported in your browser or context.");
}
}
} catch (error) {
// Fehlermeldung mit übersetztem Text
flashContainer.innerHTML = `
@ -1814,10 +1838,29 @@ document.querySelectorAll('.generate-redeem').forEach(btn => {
});
});
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
console.log("DOM ist geladen!"); // Überprüfe, ob DOMContentLoaded überhaupt ausgeführt wird
const toggleKeysButton = document.getElementById('toggle-keys');
if (toggleKeysButton) {
console.log("Button with ID 'toggle-keys' found!");
toggleKeysButton.addEventListener('click', function() {
console.log("Button clicked!");
const keyCols = document.querySelectorAll('.key-col');
keyCols.forEach(function(el) {
el.classList.toggle('hidden');
});
});
} else {
console.log("Button with ID 'toggle-keys' not found!");
}
});
</script>
{% else %}
<div class="alert alert-info">{{ _('No games yet') }}</div>
{% endif %}
{% endblock %}
HTML_END
# Login Template
@ -2287,11 +2330,17 @@ cat <<'HTML_END' > templates/redeem.html
<h4>{{ _('Your Key:') }}</h4>
<code class="fs-3">{{ game.steam_key }}</code>
</div>
{% if platform_link %}
<a href="{{ platform_link }}{{ game.steam_key }}"
class="btn btn-primary btn-lg mb-3"
target="_blank">
{{ _('Redeem now on') }} {{ platform_label }}
class="btn btn-primary btn-lg mb-3"
target="_blank">
{{ _('Redeem now on') }} {{ platform_name }}
</a>
{% else %}
<div class="alert alert-info">
{{ _('Your key:') }} <code class="fs-3">{{ game.steam_key }}</code>
</div>
{% endif %}
<div class="mt-4 text-muted">
<small>
{{ _('This page will expire in') }}
@ -2299,9 +2348,9 @@ cat <<'HTML_END' > templates/redeem.html
</small>
<div class="progress mt-2" style="height: 8px;">
<div id="expiry-bar"
class="progress-bar bg-danger"
role="progressbar"
style="width: 100%">
class="progress-bar bg-danger"
role="progressbar"
style="width: 100%">
</div>
</div>
</div>
@ -2554,6 +2603,7 @@ cat <<HTML_END > templates/admin_audit_logs.html
HTML_END
# Error Sites
# 403 Tempate
cat <<HTML_END > templates/403.html
{% extends "base.html" %}
{% block content %}
@ -2582,6 +2632,7 @@ cat <<HTML_END > templates/403.html
{% endblock %}
HTML_END
# 404 Template
cat <<HTML_END > templates/404.html
{% extends "base.html" %}
{% block content %}
@ -2778,6 +2829,28 @@ td.font-monospace {
overflow-wrap: break-word;
}
.key-col.hidden {
display: none !important;
}
@media (max-width: 768px) {
.key-col {
display: none;
}
}
.navbar .btn,
.navbar .dropdown-toggle,
.navbar .nav-link {
min-height: 40px;
line-height: 1.5 !important;
padding-top: 6px;
padding-bottom: 6px;
display: flex;
align-items: center;
font-size: 0.95em;
}
.alert-error { background-color: #f8d7da; border-color: #f5c6cb; color: #721c24; }
.alert-success { background-color: #d4edda; border-color: #c3e6cb; color: #155724; }
.alert-info { background: #d9edf7; color: #31708f; }