diff --git a/fssc/internal/handler/webconsole.go b/fssc/internal/handler/webconsole.go new file mode 100644 index 0000000..fb2d400 --- /dev/null +++ b/fssc/internal/handler/webconsole.go @@ -0,0 +1,71 @@ +package handler + +import ( + "fssc/config" + "fssc/internal/util" + "fssc/web" + "html/template" + "net/http" + "os" + "path/filepath" + "strings" +) + +// web 控制台 +func WebConsole(w http.ResponseWriter, r *http.Request) { + urlpath := r.URL.Query().Get("p") + upath := strings.TrimSuffix(urlpath, "console") + + // serve download page for send + realFilePath := filepath.Join(config.G.FilePath, upath) + downloadPath := filepath.Join(filepath.Base(config.G.FilePath), r.URL.Path[1:]) + fileInfo, err := os.Stat(realFilePath) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + data := struct { + DeviceName string + Loip string + Rundir string + IsDir bool + FileName string + DownloadPath string + UrlPath string + Files []os.DirEntry + }{ + DeviceName: config.G.DeviceName, + Loip: config.G.LocalIP, + Rundir: config.G.FilePath, + DownloadPath: downloadPath, + UrlPath: strings.TrimSuffix(r.URL.Path, "/"), + // UrlPath: r.URL.Path, + } + + if fileInfo.IsDir() { + data.IsDir = true + // 遍历目录 + files, err := os.ReadDir(realFilePath) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + data.Files = files + } else { + data.FileName = filepath.Base(realFilePath) + } + // add self template function + fmap := template.FuncMap{"b64en": util.Bas64end} + // 文件列表模板 + tmpl, err := template.New("console").Funcs(fmap).Parse(web.WbConsole) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + err = tmpl.Execute(w, data) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + +} diff --git a/fssc/main.go b/fssc/main.go index 55ee613..9a87e3f 100644 --- a/fssc/main.go +++ b/fssc/main.go @@ -52,6 +52,8 @@ func sendClient() error { http.HandleFunc("/sendZip", handler.SendZip) // 监视目标的fs json http.HandleFunc("/nf", handler.NfTest) + // web console + http.HandleFunc("/console", handler.WebConsole) fmt.Println("send file to server...") diff --git a/fssc/web/embed.go b/fssc/web/embed.go index d8276d2..74e3b36 100644 --- a/fssc/web/embed.go +++ b/fssc/web/embed.go @@ -15,3 +15,6 @@ var UpPage string // go:embed favicon.ico var WbIco string + +//go:embed wbconsole.tmpl +var WbConsole string diff --git a/fssc/web/wbconsole.tmpl b/fssc/web/wbconsole.tmpl new file mode 100644 index 0000000..80a9662 --- /dev/null +++ b/fssc/web/wbconsole.tmpl @@ -0,0 +1,162 @@ + + + + + send file to server + + + + + + + + + + +
+
+

文件更新控制台

+
+
+ + +
+
+
+
+ +
+ +
+ +
+ +
+
服务器ip
+ +
+
+
+ +
+
+
+ + + +
+ +
+
+ +
源站({{.Loip}})
+
+

监听目录:/www

+

相对目录: /app/common

+
+ + + +
+
+ + +
+
+ +
目标站(220.44.660.44)
+
+

监听目录:/www

+

相对目录: /app/common

+
+ + +
    +
  • +
    Cras justo odio
    +
    + 同步 + 复制 +
    +
  • +
  • Dapibus ac facilisis in
  • +
  • Morbi leo risus
  • +
  • Porta ac consectetur ac
  • +
  • Vestibulum at eros
  • +
+
+
+
+ + +
+
+
+
运行状态
+
+
    +
  • aa 复制完成
  • +
+
+
+
+
+ + + + + \ No newline at end of file