Drink it cold: Terminplanung für Kühlanhänger
This commit is contained in:
commit
ec88c8ebac
55 changed files with 7091 additions and 0 deletions
7
tools/.htaccess
Normal file
7
tools/.htaccess
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<IfModule mod_authz_core.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</IfModule>
|
||||
251
tools/deploy.sh
Executable file
251
tools/deploy.sh
Executable file
|
|
@ -0,0 +1,251 @@
|
|||
#!/usr/bin/env bash
|
||||
# Deployt die Drink-it-cold-Terminplanung auf
|
||||
# drink-it-cold.programmschmiede.de.
|
||||
#
|
||||
# Aufruf:
|
||||
# ./tools/deploy.sh --check # Health, Login-Seite und Asset prüfen
|
||||
# ./tools/deploy.sh --sync # Code, Assets und Konfiguration hochladen
|
||||
# ./tools/deploy.sh --install # Schema + ersten Admin anlegen (einmalig)
|
||||
# ./tools/deploy.sh --all # sync + install + check
|
||||
#
|
||||
# Die Zugangsdaten kommen aus docs/credentials.txt (gitignored). Für die
|
||||
# Installation werden DIC_ADMIN_FIRST, DIC_ADMIN_LAST und DIC_ADMIN_PASSWORD
|
||||
# aus der Umgebung gelesen; fehlen sie, wird interaktiv gefragt.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
CREDENTIALS="$REPO_ROOT/docs/credentials.txt"
|
||||
REMOTE_DIR="drink-it-cold.programmschmiede.de"
|
||||
PUBLIC_URL="https://drink-it-cold.programmschmiede.de"
|
||||
|
||||
MODE="check"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--check) MODE="check" ;;
|
||||
--sync) MODE="sync" ;;
|
||||
--install) MODE="install" ;;
|
||||
--all) MODE="all" ;;
|
||||
-h|--help)
|
||||
sed -n '2,13p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
*) echo "Unbekannte Option: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[[ -f "$CREDENTIALS" ]] || { echo "Fehlt: $CREDENTIALS" >&2; exit 1; }
|
||||
|
||||
cred() {
|
||||
grep -m1 "^$1=" "$CREDENTIALS" | cut -d= -f2- | tr -d '\r' | sed 's/[[:space:]]*$//'
|
||||
}
|
||||
|
||||
FTP_URL="$(cred FTP_URL)"
|
||||
FTP_USER="$(cred FTP_USER)"
|
||||
FTP_PASSWORD="$(cred FTP_PASSWORD)"
|
||||
DB_HOST="$(cred DB_HOST)"
|
||||
DB_NAME="$(cred DB_NAME)"
|
||||
DB_USER="$(cred DB_USER)"
|
||||
DB_PASSWORD="$(cred DB_PASSWORD)"
|
||||
|
||||
HOST="${FTP_URL#ftp://}"
|
||||
HOST="${HOST#ftps://}"
|
||||
HOST="${HOST%%/*}"
|
||||
HOST="${HOST%%:*}"
|
||||
[[ -n "$HOST" && -n "$FTP_USER" ]] || { echo "FTP-Zugang unvollständig." >&2; exit 1; }
|
||||
|
||||
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/dic-deploy.XXXXXX")"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
|
||||
CURL=(curl --ssl-reqd --insecure --silent --show-error --connect-timeout 20 --max-time 900 --user "$FTP_USER:$FTP_PASSWORD")
|
||||
|
||||
ftp_url() {
|
||||
printf 'ftp://%s/%s/%s' "$HOST" "$REMOTE_DIR" "$1"
|
||||
}
|
||||
|
||||
ftp_put() {
|
||||
local local_path="$1" remote_path="$2"
|
||||
"${CURL[@]}" --ftp-create-dirs -T "$local_path" "$(ftp_url "$remote_path")"
|
||||
}
|
||||
|
||||
ftp_get() {
|
||||
local remote_path="$1" local_path="$2"
|
||||
"${CURL[@]}" -o "$local_path" "$(ftp_url "$remote_path")"
|
||||
}
|
||||
|
||||
ftp_chmod() {
|
||||
local mode="$1" remote_path="$2"
|
||||
"${CURL[@]}" "ftp://$HOST/" -Q "SITE CHMOD $mode $REMOTE_DIR/$remote_path" >/dev/null || true
|
||||
}
|
||||
|
||||
http_code() {
|
||||
curl -sS -o /dev/null -w '%{http_code}' --max-time 30 "$1" || true
|
||||
}
|
||||
|
||||
make_config() {
|
||||
local token="$1" cron_token="$2"
|
||||
DIC_INSTALL_TOKEN="$token" DIC_CRON_TOKEN="$cron_token" DIC_PUBLIC_URL="$PUBLIC_URL" \
|
||||
DIC_MAIL_ENABLED="${DIC_MAIL_ENABLED:-false}" \
|
||||
DIC_MAIL_FROM="${DIC_MAIL_FROM:-Drink it cold <noreply@drink-it-cold.programmschmiede.de>}" \
|
||||
DB_HOST="${DB_HOST:-localhost}" DB_NAME="$DB_NAME" DB_USER="$DB_USER" DB_PASSWORD="$DB_PASSWORD" \
|
||||
python3 - "$TMP_DIR/config.local.php" <<'PY'
|
||||
import os
|
||||
import sys
|
||||
|
||||
def php(value):
|
||||
return "'" + str(value).replace('\\', '\\\\').replace("'", "\\'") + "'"
|
||||
|
||||
target = sys.argv[1]
|
||||
mail_enabled = 'true' if os.environ.get('DIC_MAIL_ENABLED', '').strip().lower() in ('1', 'true', 'yes', 'on') else 'false'
|
||||
config = f"""<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
'db' => [
|
||||
'host' => {php(os.environ.get('DB_HOST') or 'localhost')},
|
||||
'port' => 3306,
|
||||
'name' => {php(os.environ['DB_NAME'])},
|
||||
'user' => {php(os.environ['DB_USER'])},
|
||||
'password' => {php(os.environ['DB_PASSWORD'])},
|
||||
'charset' => 'utf8mb4',
|
||||
],
|
||||
'app' => [
|
||||
'base_path' => '',
|
||||
'public_url' => {php(os.environ['DIC_PUBLIC_URL'])},
|
||||
'storage_path' => dirname(__DIR__) . '/storage',
|
||||
'install_token' => {php(os.environ['DIC_INSTALL_TOKEN'])},
|
||||
'session_idle_seconds' => 30 * 86400,
|
||||
'session_absolute_seconds' => 90 * 86400,
|
||||
'remember_seconds' => 90 * 86400,
|
||||
'login_window_seconds' => 900,
|
||||
'login_max_per_user' => 5,
|
||||
'login_max_per_ip' => 15,
|
||||
'mail_enabled' => {mail_enabled},
|
||||
'mail_from' => {php(os.environ['DIC_MAIL_FROM'])},
|
||||
|
||||
'cron_token' => {php(os.environ['DIC_CRON_TOKEN'])},
|
||||
],
|
||||
];
|
||||
"""
|
||||
with open(target, 'w', encoding='utf-8') as handle:
|
||||
handle.write(config)
|
||||
os.chmod(target, 0o600)
|
||||
PY
|
||||
}
|
||||
|
||||
upload_tree() {
|
||||
local source_root="$1" remote_prefix="$2"
|
||||
while IFS= read -r file; do
|
||||
local relative="${file#"$source_root"/}"
|
||||
case "$relative" in
|
||||
config.local.php|config.example.php|.DS_Store|*.swp) continue ;;
|
||||
esac
|
||||
ftp_put "$file" "$remote_prefix$relative"
|
||||
echo " $remote_prefix$relative"
|
||||
done < <(find "$source_root" -type f | sort)
|
||||
}
|
||||
|
||||
do_sync() {
|
||||
local token cron_token
|
||||
token="$(openssl rand -hex 24)"
|
||||
cron_token="$(openssl rand -hex 24)"
|
||||
make_config "$token" "$cron_token"
|
||||
|
||||
echo "Lade Anwendung hoch …"
|
||||
upload_tree "$REPO_ROOT/app" "app/"
|
||||
upload_tree "$REPO_ROOT/views" "views/"
|
||||
upload_tree "$REPO_ROOT/sql" "sql/"
|
||||
upload_tree "$REPO_ROOT/web" ""
|
||||
echo "Lade Cron-Skript und Konfiguration hoch …"
|
||||
ftp_put "$REPO_ROOT/tools/send_reminders.php" "tools/send_reminders.php"
|
||||
ftp_put "$REPO_ROOT/tools/.htaccess" "tools/.htaccess"
|
||||
ftp_put "$TMP_DIR/config.local.php" "app/config.local.php"
|
||||
ftp_chmod 600 "app/config.local.php"
|
||||
|
||||
# Leeres Log-Verzeichnis anlegen (FTP kann keine Ordner ohne Datei erstellen).
|
||||
printf '' > "$TMP_DIR/.gitkeep"
|
||||
ftp_put "$TMP_DIR/.gitkeep" "storage/logs/.gitkeep"
|
||||
ftp_put "$REPO_ROOT/storage/.htaccess" "storage/.htaccess"
|
||||
echo "Sync fertig. Install-Token liegt nur auf dem Server."
|
||||
}
|
||||
|
||||
install_if_needed() {
|
||||
local config_file="$TMP_DIR/remote-config.php"
|
||||
if ! ftp_get "app/config.local.php" "$config_file" 2>/dev/null; then
|
||||
echo "Konfiguration fehlt auf dem Server; zuerst --sync ausführen." >&2
|
||||
exit 1
|
||||
fi
|
||||
local token
|
||||
token="$(python3 - "$config_file" <<'PY'
|
||||
import re, sys
|
||||
text = open(sys.argv[1], encoding='utf-8').read()
|
||||
match = re.search(r"'install_token'\s*=>\s*'([^']+)'", text)
|
||||
print(match.group(1) if match else '')
|
||||
PY
|
||||
)"
|
||||
[[ -n "$token" ]] || { echo "Install-Token nicht gefunden." >&2; exit 1; }
|
||||
|
||||
local first="${DIC_ADMIN_FIRST:-$(cred DIC_ADMIN_FIRST)}"
|
||||
local last="${DIC_ADMIN_LAST:-$(cred DIC_ADMIN_LAST)}"
|
||||
local password="${DIC_ADMIN_PASSWORD:-$(cred DIC_ADMIN_PASSWORD)}"
|
||||
if [[ -z "$first" ]]; then
|
||||
read -r -p "Vorname des Administrators: " first
|
||||
fi
|
||||
if [[ -z "$last" ]]; then
|
||||
read -r -p "Nachname des Administrators: " last
|
||||
fi
|
||||
if [[ -z "$password" ]]; then
|
||||
read -r -s -p "Passwort (mind. 8 Zeichen): " password
|
||||
echo
|
||||
fi
|
||||
|
||||
echo "Lade Installer hoch …"
|
||||
ftp_put "$REPO_ROOT/install.php" "install.php"
|
||||
echo "Rufe Installer auf …"
|
||||
local response status
|
||||
response="$(curl -sS --max-time 300 -w '\n%{http_code}' \
|
||||
--data-urlencode "token=$token" \
|
||||
--data-urlencode "first_name=$first" \
|
||||
--data-urlencode "last_name=$last" \
|
||||
--data-urlencode "password=$password" \
|
||||
--data-urlencode "password_repeat=$password" \
|
||||
"$PUBLIC_URL/install.php" 2>&1)" || true
|
||||
status="${response##*$'\n'}"
|
||||
local body="${response%$'\n'*}"
|
||||
if [[ "$body" == *"bereits eingerichtet"* ]]; then
|
||||
echo "Anwendung ist bereits installiert; kein zweiter Admin angelegt."
|
||||
elif [[ "$status" == "200" && "$body" == *"Fertig."* ]]; then
|
||||
echo "Installation abgeschlossen."
|
||||
else
|
||||
echo "Installation fehlgeschlagen (HTTP $status)." >&2
|
||||
echo "$body" | sed -E 's/<[^>]+>/ /g' | tr -s ' \n' ' ' | head -c 1200 >&2
|
||||
echo >&2
|
||||
exit 1
|
||||
fi
|
||||
"${CURL[@]}" "ftp://$HOST/" -Q "-DELE $REMOTE_DIR/install.php" >/dev/null 2>&1 || true
|
||||
echo "install.php auf dem Server entfernt."
|
||||
}
|
||||
|
||||
do_check() {
|
||||
local health login title css
|
||||
health="$(curl -sS --max-time 30 "$PUBLIC_URL/health" || true)"
|
||||
if [[ "$health" != "ok" ]]; then
|
||||
echo "Health-Check fehlgeschlagen: $health" >&2
|
||||
exit 1
|
||||
fi
|
||||
login="$(http_code "$PUBLIC_URL/login")"
|
||||
css="$(http_code "$PUBLIC_URL/assets/app.css")"
|
||||
title="$(curl -sS --max-time 30 "$PUBLIC_URL/login" | grep -o '<title>[^<]*' | head -1 || true)"
|
||||
echo "Health: ok"
|
||||
echo "Login: HTTP $login"
|
||||
echo "Assets: HTTP $css"
|
||||
echo "Titel: ${title#<title>}"
|
||||
[[ "$login" == "200" && "$css" == "200" ]] || { echo "Check fehlgeschlagen." >&2; exit 1; }
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
sync) do_sync ;;
|
||||
install) install_if_needed ;;
|
||||
check) do_check ;;
|
||||
all) do_sync; install_if_needed; do_check ;;
|
||||
esac
|
||||
18
tools/router.php
Normal file
18
tools/router.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Router für den lokalen Entwicklungsserver:
|
||||
* php -S 127.0.0.1:8099 -t web tools/router.php
|
||||
*/
|
||||
|
||||
$path = (string) parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
|
||||
if ($path === '/install.php') {
|
||||
require __DIR__ . '/../install.php';
|
||||
return;
|
||||
}
|
||||
$file = __DIR__ . '/../web' . $path;
|
||||
if ($path !== '/' && is_file($file)) {
|
||||
return false;
|
||||
}
|
||||
require __DIR__ . '/../web/index.php';
|
||||
42
tools/send_reminders.php
Normal file
42
tools/send_reminders.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Täglicher Erinnerungs-Digest per E-Mail.
|
||||
*
|
||||
* Cron-Beispiel (täglich 07:00):
|
||||
* 0 7 * * * /usr/bin/php /pfad/zu/drink-it-cold/tools/send_reminders.php
|
||||
*
|
||||
* Voraussetzung: app.mail_enabled = true und Benutzer mit E-Mail-Adresse,
|
||||
* die mit einem Mitarbeiterkonto verknüpft sind. Die In-App-Erinnerungen
|
||||
* funktionieren unabhängig davon.
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../app/bootstrap.php';
|
||||
|
||||
$lookback = 7;
|
||||
foreach ($argv ?? [] as $arg) {
|
||||
if (preg_match('/^--lookback=(\d+)$/', $arg, $m)) {
|
||||
$lookback = max(1, min(60, (int) $m[1]));
|
||||
}
|
||||
}
|
||||
|
||||
$result = reminder_send_due($lookback);
|
||||
|
||||
if (!$result['enabled']) {
|
||||
fwrite(STDOUT, "E-Mail-Versand ist deaktiviert (app.mail_enabled = false).\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fwrite(STDOUT, sprintf(
|
||||
"Erinnerungen: %d versendet, %d übersprungen.\n",
|
||||
$result['sent'],
|
||||
$result['skipped']
|
||||
));
|
||||
foreach ($result['details'] as $detail) {
|
||||
fwrite(STDOUT, ' ' . $detail . "\n");
|
||||
}
|
||||
foreach ($result['errors'] as $error) {
|
||||
fwrite(STDERR, ' Fehler: ' . $error . "\n");
|
||||
}
|
||||
exit($result['errors'] ? 1 : 0);
|
||||
Loading…
Add table
Add a link
Reference in a new issue