feat: initial commit for HookPilot

This commit is contained in:
吴璨
2026-09-27 20:09:10 +08:00
commit e998d4defc
73 changed files with 10782 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
# Caddy 反向代理示例:/etc/caddy/Caddyfile
# Caddy 会自动申请并续期 HTTPS 证书
hooks.example.com {
request_body {
max_size 2MB
}
reverse_proxy 127.0.0.1:8787 {
# 同步模式会等待脚本执行结束
transport http {
read_timeout 600s
write_timeout 600s
}
}
}
+38
View File
@@ -0,0 +1,38 @@
# HookPilot 环境配置,复制到 /etc/hookpilot/hookpilot.env 后按需修改
# 修改后执行:sudo systemctl restart hookpilot
# 监听地址。由反向代理对外提供 HTTPS,服务本身只监听本机
HOOKPILOT_HOST=127.0.0.1
HOOKPILOT_PORT=8787
# 数据目录:SQLite 数据库、脚本文件、任务临时目录、默认工作目录
HOOKPILOT_DATA_DIR=/var/lib/hookpilot
# 前端构建产物目录(默认为程序目录下的 web/dist)
# HOOKPILOT_WEB_DIR=/opt/hookpilot/web/dist
# 首次启动时创建的管理员。不设置密码时会随机生成并打印到日志(journalctl -u hookpilot)
HOOKPILOT_ADMIN_USER=admin
# HOOKPILOT_ADMIN_PASSWORD=请替换为强密码
# 信任的反向代理:loopback(默认,代理在本机)、true、false,或逗号分隔的 IP/网段
HOOKPILOT_TRUST_PROXY=loopback
# 登录 Cookie 是否带 Secure:auto(按请求协议判断)、true、false
HOOKPILOT_COOKIE_SECURE=auto
# 登录会话有效期(小时)
HOOKPILOT_SESSION_TTL_HOURS=168
# 请求体上限(字节),默认 1 MiB
HOOKPILOT_BODY_LIMIT=1048576
# 脚本执行使用的 Bash 与 PATH
HOOKPILOT_BASH=/bin/bash
HOOKPILOT_EXEC_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 日志级别:fatal / error / warn / info / debug
HOOKPILOT_LOG_LEVEL=info
# 脚本执行时区(可选)
# TZ=Asia/Shanghai
+26
View File
@@ -0,0 +1,26 @@
[Unit]
Description=HookPilot Webhook 脚本管理平台
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=hookpilot
Group=hookpilot
WorkingDirectory=/opt/hookpilot
EnvironmentFile=-/etc/hookpilot/hookpilot.env
ExecStart=/usr/bin/node /opt/hookpilot/server/dist/index.js
Restart=on-failure
RestartSec=3
# 停止时只向主进程发送 SIGTERM,由服务终止运行中的任务并标记为“中断”;
# 超过 TimeoutStopSec 仍未退出时,systemd 再清理整个 cgroup。
KillMode=mixed
TimeoutStopSec=15
# 脚本需要 sudo 提权时不能启用 NoNewPrivileges;如确定不需要提权,可取消下面的注释加固
# NoNewPrivileges=true
# ProtectSystem=full
[Install]
WantedBy=multi-user.target
+37
View File
@@ -0,0 +1,37 @@
# Nginx 反向代理示例:/etc/nginx/conf.d/hookpilot.conf
# 证书可使用 certbot 等工具申请,替换 hooks.example.com 与证书路径
server {
listen 80;
server_name hooks.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
http2 on;
server_name hooks.example.com;
ssl_certificate /etc/letsencrypt/live/hooks.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/hooks.example.com/privkey.pem;
# 与 HOOKPILOT_BODY_LIMIT 保持一致或略大
client_max_body_size 2m;
# 不在访问日志中记录 query(?token= 方式调用时避免 Token 落盘)
log_format hookpilot '$remote_addr - [$time_local] "$request_method $uri" $status $body_bytes_sent';
access_log /var/log/nginx/hookpilot.access.log hookpilot;
location / {
proxy_pass http://127.0.0.1:8787;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
# 同步模式会等待脚本执行结束,超时时间应大于最长的脚本超时 + 排队时间
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
}