diff --git a/apps/leafwiki/0.15.0/.env.sample b/apps/leafwiki/0.15.0/.env.sample new file mode 100644 index 000000000..5535efdf0 --- /dev/null +++ b/apps/leafwiki/0.15.0/.env.sample @@ -0,0 +1,7 @@ +PANEL_APP_PORT_HTTP=8080 +LEAFWIKI_ADMIN_USERNAME=admin +LEAFWIKI_ADMIN_EMAIL=admin@localhost +LEAFWIKI_ADMIN_PASSWORD=LeafWiki_Admin +LEAFWIKI_ALLOW_INSECURE=false +APP_DATA_DIR=./data +CONTAINER_NAME= diff --git a/apps/leafwiki/0.15.0/data.yml b/apps/leafwiki/0.15.0/data.yml new file mode 100644 index 000000000..3d927fa71 --- /dev/null +++ b/apps/leafwiki/0.15.0/data.yml @@ -0,0 +1,107 @@ +additionalProperties: + formFields: + - default: 8080 + edit: true + envKey: PANEL_APP_PORT_HTTP + labelEn: Port + labelZh: 端口 + label: + en: Port + zh: 端口 + zh-Hant: 埠 + ja: ポート + ko: 포트 + ru: Порт + ms: Port + pt-br: Porta + required: true + rule: paramPort + type: number + - default: admin + edit: true + envKey: LEAFWIKI_ADMIN_USERNAME + labelEn: Initial Admin Username + labelZh: 初始管理员用户名 + label: + en: Initial Admin Username + zh: 初始管理员用户名 + zh-Hant: 初始管理員使用者名稱 + ja: 初期管理者ユーザー名 + ko: 초기 관리자 사용자 이름 + ru: Имя начального администратора + ms: Nama Pengguna Pentadbir Awal + pt-br: Nome do Administrador Inicial + required: true + rule: paramCommon + type: text + - default: admin@localhost + edit: true + envKey: LEAFWIKI_ADMIN_EMAIL + labelEn: Initial Admin Email + labelZh: 初始管理员邮箱 + label: + en: Initial Admin Email + zh: 初始管理员邮箱 + zh-Hant: 初始管理員電子郵件 + ja: 初期管理者メール + ko: 초기 관리자 이메일 + ru: Email начального администратора + ms: E-mel Pentadbir Awal + pt-br: E-mail do Administrador Inicial + required: true + type: text + - default: LeafWiki_Admin + edit: true + envKey: LEAFWIKI_ADMIN_PASSWORD + labelEn: Initial Admin Password + labelZh: 初始管理员密码 + label: + en: Initial Admin Password + zh: 初始管理员密码 + zh-Hant: 初始管理員密碼 + ja: 初期管理者パスワード + ko: 초기 관리자 비밀번호 + ru: Пароль начального администратора + ms: Kata Laluan Pentadbir Awal + pt-br: Senha do Administrador Inicial + random: true + required: true + rule: paramComplexity + type: password + - default: "false" + edit: true + envKey: LEAFWIKI_ALLOW_INSECURE + labelEn: Allow Plain HTTP Login (Insecure, Trusted LAN Only) + labelZh: 允许明文 HTTP 登录(不安全,仅限可信局域网) + label: + en: Allow Plain HTTP Login (Insecure, Trusted LAN Only) + zh: 允许明文 HTTP 登录(不安全,仅限可信局域网) + zh-Hant: 允許明文 HTTP 登入(不安全,僅限可信區域網路) + ja: 平文 HTTP ログインを許可(非推奨) + ko: 일반 HTTP 로그인 허용(안전하지 않음) + ru: Разрешить вход по HTTP без шифрования (небезопасно) + ms: Benarkan Log Masuk HTTP Biasa (Tidak Selamat) + pt-br: Permitir Login HTTP sem Criptografia (Inseguro) + required: true + type: select + values: + - label: "true" + value: "true" + - label: "false" + value: "false" + - default: ./data + edit: true + envKey: APP_DATA_DIR + labelEn: Data Directory + labelZh: 数据目录 + label: + en: Data Directory + zh: 数据目录 + zh-Hant: 資料目錄 + ja: データディレクトリ + ko: 데이터 디렉터리 + ru: Каталог данных + ms: Direktori data + pt-br: Diretório de Dados + required: true + type: text diff --git a/apps/leafwiki/0.15.0/data/.gitkeep b/apps/leafwiki/0.15.0/data/.gitkeep new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/apps/leafwiki/0.15.0/data/.gitkeep @@ -0,0 +1 @@ + diff --git a/apps/leafwiki/0.15.0/docker-compose.yml b/apps/leafwiki/0.15.0/docker-compose.yml new file mode 100644 index 000000000..571313db0 --- /dev/null +++ b/apps/leafwiki/0.15.0/docker-compose.yml @@ -0,0 +1,43 @@ +services: + leafwiki: + image: "ghcr.io/perber/leafwiki:v0.15.0@sha256:bacd15c0fb12c53d034d80c3cb1828f1eb6177fcac362fe90077d1f7f32e307c" + container_name: ${CONTAINER_NAME} + restart: unless-stopped + init: true + user: "1000:1000" + networks: + - 1panel-network + ports: + - "${PANEL_APP_PORT_HTTP}:8080" + env_file: + - path: "${APP_DATA_DIR}/.leafwiki-secrets.env" + required: false + environment: + - LEAFWIKI_DATA_DIR=/app/data + - LEAFWIKI_ADMIN_PASSWORD=${LEAFWIKI_ADMIN_PASSWORD} + - LEAFWIKI_ADMIN_USERNAME=${LEAFWIKI_ADMIN_USERNAME} + - LEAFWIKI_ADMIN_EMAIL=${LEAFWIKI_ADMIN_EMAIL} + - LEAFWIKI_ALLOW_INSECURE=${LEAFWIKI_ALLOW_INSECURE} + - LEAFWIKI_DISABLE_AUTH=false + - LEAFWIKI_PUBLIC_ACCESS=false + read_only: true + tmpfs: + - /tmp:size=32m,mode=1777 + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/api/health"] + interval: 30s + timeout: 5s + start_period: 10s + retries: 3 + volumes: + - "${APP_DATA_DIR}:/app/data" + labels: + createdBy: "Apps" + +networks: + 1panel-network: + external: true diff --git a/apps/leafwiki/0.15.0/scripts/init.sh b/apps/leafwiki/0.15.0/scripts/init.sh new file mode 100755 index 000000000..4f1aa1352 --- /dev/null +++ b/apps/leafwiki/0.15.0/scripts/init.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" +ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}" + +read_env_value() { + local key="$1" + [[ -f "$ENV_FILE" ]] || return 0 + local value + value="$(sed -n "s/^${key}=//p" "$ENV_FILE" | tail -n 1)" + case "$value" in + \"*\") value="${value#\"}"; value="${value%\"}" ;; + \'*\') value="${value#\'}"; value="${value%\'}" ;; + esac + printf '%s\n' "$value" +} + +configured_value() { + local key="$1" + local default_value="$2" + local value="${!key:-}" + if [[ -z "$value" ]]; then + value="$(read_env_value "$key")" + fi + printf '%s\n' "${value:-$default_value}" +} + +prepare_data_dir() { + local raw path secrets_file temp_file jwt_secret totp_key + raw="$(configured_value APP_DATA_DIR ./data)" + + [[ -n "$raw" ]] || { + printf '%s\n' 'APP_DATA_DIR must not be empty' >&2 + exit 1 + } + if [[ "$raw" = /* ]]; then + printf '%s\n' 'APP_DATA_DIR must be relative to the application version directory' >&2 + exit 1 + fi + + path="$(realpath -m -- "$ROOT_DIR/${raw#./}")" + case "$path" in + "$ROOT_DIR"/*) ;; + *) + printf '%s\n' 'APP_DATA_DIR must remain inside the application version directory' >&2 + exit 1 + ;; + esac + + install -d -m 0750 "$path" + path="$(realpath -e -- "$path")" + case "$path" in + "$ROOT_DIR"/*) ;; + *) + printf '%s\n' 'APP_DATA_DIR resolves outside the application version directory' >&2 + exit 1 + ;; + esac + chmod 0750 "$path" + chown -R --no-dereference 1000:1000 "$path" + + secrets_file="$path/.leafwiki-secrets.env" + if [[ -L "$secrets_file" ]]; then + printf '%s\n' 'LeafWiki secrets file must not be a symbolic link' >&2 + exit 1 + fi + if [[ ! -e "$secrets_file" ]]; then + umask 077 + jwt_secret="$(od -An -N32 -tx1 /dev/urandom | tr -d ' \n')" + totp_key="$(od -An -N32 -tx1 /dev/urandom | tr -d ' \n')" + [[ ${#jwt_secret} -eq 64 && ${#totp_key} -eq 64 ]] || { + printf '%s\n' 'Failed to generate LeafWiki secrets' >&2 + exit 1 + } + temp_file="$(mktemp "$path/.leafwiki-secrets.env.tmp.XXXXXX")" + trap 'rm -f -- "${temp_file:-}"' EXIT + printf 'LEAFWIKI_JWT_SECRET=%s\nLEAFWIKI_TOTP_ENCRYPTION_KEY=%s\n' \ + "$jwt_secret" "$totp_key" >"$temp_file" + chmod 0600 "$temp_file" + chown 1000:1000 "$temp_file" + mv -f -- "$temp_file" "$secrets_file" + trap - EXIT + fi + [[ -f "$secrets_file" ]] || { + printf '%s\n' 'LeafWiki secrets path must be a regular file' >&2 + exit 1 + } + [[ "$(grep -c '^LEAFWIKI_JWT_SECRET=' "$secrets_file")" -eq 1 ]] || { + printf '%s\n' 'LeafWiki secrets file must contain exactly one JWT secret' >&2 + exit 1 + } + [[ "$(grep -c '^LEAFWIKI_TOTP_ENCRYPTION_KEY=' "$secrets_file")" -eq 1 ]] || { + printf '%s\n' 'LeafWiki secrets file must contain exactly one TOTP encryption key' >&2 + exit 1 + } + jwt_secret="$(sed -n 's/^LEAFWIKI_JWT_SECRET=//p' "$secrets_file")" + totp_key="$(sed -n 's/^LEAFWIKI_TOTP_ENCRYPTION_KEY=//p' "$secrets_file")" + [[ "$jwt_secret" =~ ^[0-9a-f]{64}$ ]] || { + printf '%s\n' 'LeafWiki JWT secret must be a 256-bit hexadecimal value' >&2 + exit 1 + } + [[ "$totp_key" =~ ^[0-9a-f]{64}$ ]] || { + printf '%s\n' 'LeafWiki TOTP encryption key must be a 256-bit hexadecimal value' >&2 + exit 1 + } + [[ "$(stat -c '%a' -- "$secrets_file")" = 600 ]] || { + printf '%s\n' 'LeafWiki secrets file permissions must be 0600' >&2 + exit 1 + } +} + +prepare_data_dir diff --git a/apps/leafwiki/0.15.0/scripts/uninstall.sh b/apps/leafwiki/0.15.0/scripts/uninstall.sh new file mode 100755 index 000000000..ab8a8d674 --- /dev/null +++ b/apps/leafwiki/0.15.0/scripts/uninstall.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose down --volumes diff --git a/apps/leafwiki/0.15.0/scripts/upgrade.sh b/apps/leafwiki/0.15.0/scripts/upgrade.sh new file mode 100755 index 000000000..692e341e2 --- /dev/null +++ b/apps/leafwiki/0.15.0/scripts/upgrade.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail + +"$(dirname "$0")/init.sh"