Skip to content

Commit

Permalink
add XL_PREVENT_UPDATE envkey and --prevent_update flag that set to pr…
Browse files Browse the repository at this point in the history
…event xl update
  • Loading branch information
cnk3x committed May 23, 2024
1 parent a2a3cb9 commit 2f07716
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 62 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ ENV \
XL_DASHBOARD_PORT=2345 \
XL_DASHBOARD_USERNAME= \
XL_DASHBOARD_PASSWORD= \
XL_DEBUG=0 \
XL_CHROOT=/xunlei
XL_DEBUG=false \
XL_CHROOT=/xunlei \
XL_PREVENT_UPDATE=true

EXPOSE 2345
VOLUME [ "/xunlei/data", "/xunlei/downloads" ]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ XL_DIR_DATA #程序数据保存文件夹,默认 /xunlei/data
XL_DEBUG #调试模式, 可选值 true/false, 1/0
XL_UID #运行迅雷的用户ID
XL_GID #运行迅雷的用户组ID
XL_PREVENT_UPDATE #是否阻止更新,默认 true, 可选值 true/false, 1/0
```

#### 在容器中运行
Expand Down
46 changes: 0 additions & 46 deletions ubuntu.Dockerfile

This file was deleted.

23 changes: 14 additions & 9 deletions xlp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
ENV_XL_GID = "XL_GID" //运行迅雷的用户组ID
ENV_XL_DEBUG = "XL_DEBUG" //是否开启调试日志
ENV_CHROOT = "XL_CHROOT" //CHROOT模式运行,用于在容器内。
ENV_PREVENT_UPDATE = "XL_PREVENT_UPDATE" //阻止更新

ENV_WEB_ADDRESS = "XL_WEB_ADDRESS" //旧的环境变量,标记过期: 网页访问的地址
ENV_BA_USER = "XL_BA_USER" //旧的环境变量,标记过期: 网页访问的用户名
Expand All @@ -31,10 +32,11 @@ type Config struct {
DashboardPassword string `json:"dashboard_password,omitempty"` //网页访问的密码
DirDownload string `json:"dir_download,omitempty"` //下载保存文件夹,此文件夹链接到主文件夹的`下载`
DirData string `json:"dir_data,omitempty"` //程序数据保存文件夹,此文件夹链接到主文件夹的`.drive,存储了登录的账号,下载进度等信息
Debug bool `json:"debug,omitempty"`
UID string `json:"uid,omitempty"`
GID string `json:"gid,omitempty"`
Chroot string `json:"chroot,omitempty"`
Debug bool `json:"debug,omitempty"` //是否开启调试日志
UID string `json:"uid,omitempty"` //运行迅雷的用户ID
GID string `json:"gid,omitempty"` //运行迅雷的用户组ID
PreventUpdate bool `json:"prevent_update,omitempty"` //阻止更新
Chroot string `json:"chroot,omitempty"` //CHROOT模式运行,用于在容器内。
}

// 绑定环境变量,参数来源和优先级: 命令行参数 > 环境变量 > 预设
Expand All @@ -48,6 +50,7 @@ func (cfg *Config) Init() {
bindEnv(&cfg.UID, ENV_XL_UID, ENV_OLD_UID)
bindEnv(&cfg.GID, ENV_XL_GID, ENV_OLD_GID)
bindEnv(&cfg.Chroot, ENV_CHROOT)
bindEnv(&cfg.PreventUpdate, ENV_PREVENT_UPDATE)
}

func (cfg *Config) MarshalEnv() (env []string) {
Expand All @@ -59,20 +62,22 @@ func (cfg *Config) MarshalEnv() (env []string) {
env = append(env, fmt.Sprintf("%s=%t", ENV_XL_DEBUG, cfg.Debug))
env = append(env, fmt.Sprintf("%s=%s", ENV_XL_UID, cfg.UID))
env = append(env, fmt.Sprintf("%s=%s", ENV_XL_GID, cfg.GID))
env = append(env, fmt.Sprintf("%s=%t", ENV_PREVENT_UPDATE, cfg.PreventUpdate))
return
}

// 绑定命令行参数,参数来源和优先级: 命令行参数 > 环境变量 > 预设
func (cfg *Config) BindFlag(fs flagSet, parse bool) {
fs.IntVar(&cfg.DashboardPort, "dashboard-port", cfg.DashboardPort, "网页控制台访问端口")
fs.StringVar(&cfg.DashboardUsername, "dashboard-username", cfg.DashboardUsername, "网页控制台访问用户名")
fs.StringVar(&cfg.DashboardPassword, "dashboard-password", cfg.DashboardPassword, "网页控制台访问密码")
fs.StringVar(&cfg.DirDownload, "dir-download", cfg.DirDownload, "默认下载保存文件夹")
fs.StringVar(&cfg.DirData, "dir-data", cfg.DirData, "迅雷程序数据保存文件夹")
fs.IntVar(&cfg.DashboardPort, "dashboard_port", cfg.DashboardPort, "网页控制台访问端口")
fs.StringVar(&cfg.DashboardUsername, "dashboard_username", cfg.DashboardUsername, "网页控制台访问用户名")
fs.StringVar(&cfg.DashboardPassword, "dashboard_password", cfg.DashboardPassword, "网页控制台访问密码")
fs.StringVar(&cfg.DirDownload, "dir_download", cfg.DirDownload, "默认下载保存文件夹")
fs.StringVar(&cfg.DirData, "dir_data", cfg.DirData, "迅雷程序数据保存文件夹")
fs.StringVar(&cfg.UID, "uid", cfg.UID, "运行迅雷的 UID")
fs.StringVar(&cfg.GID, "gid", cfg.GID, "运行迅雷的 GID")
fs.BoolVar(&cfg.Debug, "debug", cfg.Debug, "开启调试模式")
fs.StringVar(&cfg.Chroot, "chroot", cfg.Chroot, "CHROOT模式运行,用于在容器内。")
fs.BoolVar(&cfg.PreventUpdate, "prevent_update", cfg.PreventUpdate, "CHROOT模式运行,用于在容器内。")

if parse {
fs.Parse(os.Args[1:])
Expand Down
24 changes: 19 additions & 5 deletions xlp/xlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
PATH_SYNO_INFO_CONF = "/etc/synoinfo.conf" //synoinfo.conf 文件路径
PATH_SYNO_AUTHENTICATE_CGI = "/usr/syno/synoman/webman/modules/authenticate.cgi" //syno...authenticate.cgi 文件路径
SYNO_AUTHENTICATE_CGI_SCRIPT = "#!/bin/sh\necho Content-Type: text/plain\necho;\necho admin\n" //syno...authenticate.cgi 文件内容
UPDATE_URL = "/webman/3rdparty/" + SYNOPKG_PKGNAME + "/version"
)

var (
Expand Down Expand Up @@ -224,14 +225,18 @@ func (d *Daemon) run(ctx context.Context) (err error) {
return
}

c := exec.CommandContext(
ctx,
PAN_XUNLEI_CLI,
"-launcher_listen", "unix://"+LAUNCHER_LISTEN_PATH,
var args = []string{
"-launcher_listen", "unix://" + LAUNCHER_LISTEN_PATH,
"-pid", PID_FILE,
"-logfile", LOG_LAUNCHER,
"-logsize", "1MB",
)
}

if d.cfg.PreventUpdate {
args = append(args, "-update_url", fmt.Sprintf("http://127.0.0.1:%d%s", d.cfg.DashboardPort, UPDATE_URL))
}

c := exec.CommandContext(ctx, PAN_XUNLEI_CLI, args...)

setupProcAttr(c, uid, gid)

Expand Down Expand Up @@ -294,6 +299,9 @@ func (d *Daemon) mockHandler(environs []string) http.Handler {
router := chi.NewMux()
router.Use(middleware.Recoverer)
router.Handle("/webman/login.cgi", Respond(fmt.Sprintf(`{"SynoToken":"syno_%s"}`, randText(24)), "application/json", http.StatusOK))
if d.cfg.PreventUpdate {
router.Handle("GET "+UPDATE_URL, preventUpdate())
}

router.Group(func(r chi.Router) {
index := fmt.Sprintf("/webman/3rdparty/%s/index.cgi/", SYNOPKG_PKGNAME)
Expand Down Expand Up @@ -342,3 +350,9 @@ func walkFiles(root string, do func(cur string), r bool) {
do(root)
}
}

func preventUpdate() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Respond(fmt.Sprintf("arch: %s\nversion: \"0.0.1\"\naccept: [\"9.9.9\"]", runtime.GOARCH), `text/vnd.yaml`, 200)
}
}

0 comments on commit 2f07716

Please sign in to comment.