mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-10-23 19:49:14 +09:00
Introduce fallback audit logging and enrich audit tooling; add builtin extension discovery/install; and update default launcher ports and related docs/config. Key changes: - New middleware app.middleware.audit registers an after-request fallback that records authenticated mutating API requests when routes don't emit explicit audit logs. - Audit model/action constants extended and AuditService enhanced (request context handling, redaction for sensitive settings, optional commit flag, sets g.audit_logged, emits events). - Routes/services updated to create explicit audit entries for marketplace and plugin operations (create/update/publish/install/uninstall/enable/disable) and SSO/settings flows switched to use AuditService. - Added tests for audit logging behavior and redaction (backend/tests/test_audit_log.py). - Plugin service: added BUILTIN_EXTENSIONS_DIR, list_builtin_extensions and install_builtin_extension; plugin API endpoints to list/install builtin extensions. - Contribution system extended to support layouts and route layout metadata; frontend wiring updated to surface standalone/custom layouts and extension routes. - Launcher port defaults changed (backend -> 47927, frontend -> 41921). Updated backend .env.example, config CORS defaults, Dockerfiles and docker-compose to use SERVERKIT_BACKEND_PORT, and many docs/README files and frontend envs to reflect new ports. - Minor frontend cleanups and new builtin extension example (serverkit-git) plus associated manifest and frontend re-export. These changes improve observability/security for mutating APIs, enable opt-in builtin plugins, and align local dev/run ports with the launcher defaults.
110 lines
3.3 KiB
Bash
Executable File
110 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# ServerKit WSL Development Setup
|
|
# Run: ./scripts/dev/setup-wsl.sh
|
|
|
|
set -e
|
|
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
cd "$PROJECT_ROOT"
|
|
|
|
echo "============================================"
|
|
echo " ServerKit Dev Setup"
|
|
echo "============================================"
|
|
echo ""
|
|
|
|
echo -e "${YELLOW}[1/6] Installing base dependencies...${NC}"
|
|
sudo apt update
|
|
sudo apt install -y python3.11 python3.11-venv python3-pip nginx docker.io docker-compose git curl lsof ca-certificates gnupg
|
|
sudo usermod -aG docker $USER 2>/dev/null || true
|
|
echo -e "${GREEN}Done!${NC}"
|
|
|
|
echo -e "${YELLOW}[2/6] Installing Node.js 20...${NC}"
|
|
# Install Node.js 20 from NodeSource (Ubuntu default is too old)
|
|
if ! node --version 2>/dev/null | grep -q "v20\|v21\|v22"; then
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|
sudo apt install -y nodejs
|
|
fi
|
|
echo "Node.js $(node --version)"
|
|
echo -e "${GREEN}Done!${NC}"
|
|
|
|
echo -e "${YELLOW}[3/6] Enabling systemd...${NC}"
|
|
if ! grep -q "systemd=true" /etc/wsl.conf 2>/dev/null; then
|
|
echo -e "[boot]\nsystemd=true" | sudo tee /etc/wsl.conf > /dev/null
|
|
echo -e "${YELLOW}Note: Run 'wsl --shutdown' after setup for systemd.${NC}"
|
|
fi
|
|
echo -e "${GREEN}Done!${NC}"
|
|
|
|
echo -e "${YELLOW}[4/6] Setting up backend...${NC}"
|
|
cd "$PROJECT_ROOT/backend"
|
|
python3.11 -m venv venv
|
|
source venv/bin/activate
|
|
pip install --upgrade pip -q
|
|
pip install -r requirements.txt -q
|
|
|
|
# Create instance directory
|
|
mkdir -p instance
|
|
|
|
# Create .env if it doesn't exist (don't overwrite existing config)
|
|
if [ ! -f .env ]; then
|
|
cat > .env << EOF
|
|
FLASK_ENV=development
|
|
FLASK_DEBUG=1
|
|
SECRET_KEY=dev-secret-key-change-in-production
|
|
JWT_SECRET_KEY=jwt-secret-key-change-in-production
|
|
DATABASE_URL=sqlite:///instance/serverkit.db
|
|
PORT=47927
|
|
CORS_ORIGINS=http://localhost:41921,http://127.0.0.1:41921,http://localhost:47927,http://127.0.0.1:47927
|
|
EOF
|
|
fi
|
|
echo -e "${GREEN}Done!${NC}"
|
|
|
|
echo -e "${YELLOW}[5/6] Setting up frontend...${NC}"
|
|
cd "$PROJECT_ROOT/frontend"
|
|
npm install
|
|
[ ! -f .env.development ] && echo "VITE_API_URL=http://localhost:47927/api/v1" > .env.development
|
|
echo -e "${GREEN}Done!${NC}"
|
|
|
|
echo -e "${YELLOW}[6/6] Creating admin user...${NC}"
|
|
cd "$PROJECT_ROOT/backend"
|
|
source venv/bin/activate
|
|
python3 << 'PYTHON'
|
|
import sys, os
|
|
sys.path.insert(0, os.getcwd())
|
|
try:
|
|
from app import create_app, db
|
|
from app.models.user import User
|
|
app = create_app()
|
|
with app.app_context():
|
|
db.create_all()
|
|
admin = User.query.filter_by(username='admin').first()
|
|
if admin:
|
|
admin.set_password('admin')
|
|
else:
|
|
admin = User(username='admin', email='admin@localhost', role='admin', is_active=True)
|
|
admin.set_password('admin')
|
|
db.session.add(admin)
|
|
db.session.commit()
|
|
print("Admin user ready!")
|
|
except Exception as e:
|
|
print(f"Could not create admin: {e}")
|
|
PYTHON
|
|
echo -e "${GREEN}Done!${NC}"
|
|
|
|
echo ""
|
|
echo "============================================"
|
|
echo -e "${GREEN} Ready!${NC}"
|
|
echo "============================================"
|
|
echo ""
|
|
echo " Login: admin / admin"
|
|
echo " DB: ~/.serverkit/serverkit.db"
|
|
echo ""
|
|
echo " Start: ./dev.sh"
|
|
echo ""
|
|
echo " Open: http://localhost:41921"
|
|
echo ""
|