4 changed files with 238 additions and 0 deletions
@ -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) |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,162 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
|
||||
|
<head> |
||||
|
<title>send file to server</title> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
|
<link rel="stylesheet" href="/static/static/css/bootstrap.css"> |
||||
|
<link rel="icon" type="image/x-icon" href="/favicon.ico?v=2"> |
||||
|
<script type="text/javascript" src="/static/static/js/jquery.min.js"></script> |
||||
|
<script type="text/javascript" src="/static/static/js/bootstrap.min.js"></script> |
||||
|
<style> |
||||
|
.list-group>.list-group-item { |
||||
|
padding: 20px; |
||||
|
} |
||||
|
|
||||
|
.optzone { |
||||
|
height: 60px; |
||||
|
} |
||||
|
.stabox{ |
||||
|
height: 260px; |
||||
|
overflow:scroll; |
||||
|
} |
||||
|
|
||||
|
.icon { |
||||
|
display: inline-block; |
||||
|
width: 24px; |
||||
|
height: 24px; |
||||
|
} |
||||
|
|
||||
|
.folder-icon { |
||||
|
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHhtbG5zOnhsaW5rPSdodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rJyAgcHJlc2VydmVBc3BlY3RSYXRpbz0neE1pZFlNaWQgbWVldCcgIHZpZXdCb3g9IjAgMCAyNCAyNCIgPjxwYXRoIGZpbGw9ImN1cnJlbnRDb2xvciIKZD0iTTEwIDRINEMyLjkgNCAyIDQuOSAyIDZWMThDMiAxOS4xIDIuOSAyMCA0IDIwSDIwQzIxLjEgMjAgMjIgMTkuMSAyMiAxOFY4QzIyIDYuOSAyMS4xIDYgMjAgNkgxMkwxMCA0WiIgLz48L3N2Zz4="); |
||||
|
background-repeat: no-repeat; |
||||
|
|
||||
|
} |
||||
|
.file-icon { |
||||
|
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHhtbG5zOnhsaW5rPSdodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rJyAgcHJlc2VydmVBc3BlY3RSYXRpbz0neE1pZFlNaWQgbWVldCcgIHZpZXdCb3g9IjAgMCAyNCAyNCIgPjxwYXRoIGQ9Ik0xNCAySDZDNC45IDIgNCAyLjkgNCA0VjIwQzQgMjEuMSA0LjkgMjIgNiAyMkgxOEMxOS4xIDIyIDIwIDIxLjEgMjAgMjBWOEwxNCAyTTEzIDlWMy41TDE4LjUgOUgxM1oiIC8+IDwvc3ZnPg=="); |
||||
|
background-repeat: no-repeat; |
||||
|
} |
||||
|
</style> |
||||
|
</head> |
||||
|
|
||||
|
<body> |
||||
|
|
||||
|
<div class="jumbotron"> |
||||
|
<div class="container"> |
||||
|
<p>文件更新控制台</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 输入服务器ip --> |
||||
|
<div class="container"> |
||||
|
<div class="col-md-12 no-padding"> |
||||
|
<div class="form-group col-md-10"> |
||||
|
<div class="input-group"> |
||||
|
<input type="hidden" class="form-control" name="bpath" value="" /> |
||||
|
</div> |
||||
|
|
||||
|
<div class="input-group"> |
||||
|
<input type="hidden" class="form-control" name="bfile" value="" /> |
||||
|
</div> |
||||
|
|
||||
|
<div class="input-group"> |
||||
|
<div class="input-group-addon">服务器ip</div> |
||||
|
<input type="text" class="form-control" name="sip" placeholder="eg:192.168.66.99"> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="form-group col-md-2"> |
||||
|
<button type="submit" class="btn btn-primary">Transfer</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
|
||||
|
<!-- 罗列文件的列表信息 --> |
||||
|
<div class="container"> |
||||
|
<!-- 源服务器 --> |
||||
|
<div class="col-md-6"> |
||||
|
<div class="panel panel-default"> |
||||
|
<!-- Default panel contents --> |
||||
|
<div class="panel-heading">源站({{.Loip}})</div> |
||||
|
<div class="panel-body"> |
||||
|
<p>监听目录:/www</p> |
||||
|
<p>相对目录: /app/common </p> |
||||
|
</div> |
||||
|
|
||||
|
<!-- List group --> |
||||
|
<ul class="list-group"> |
||||
|
{{ range .Files }} |
||||
|
<li class="list-group-item optzone"> |
||||
|
<div class="col-md-8"> |
||||
|
|
||||
|
{{ if .IsDir }} |
||||
|
|
||||
|
<span class="icon folder-icon"></span> |
||||
|
<a href="/up?p={{b64en $.UrlPath }}&f={{b64en .Name }}">{{ .Name }}</a> |
||||
|
{{ else }} |
||||
|
<span class="icon folder-icon"></span> |
||||
|
<a href="/up?p={{b64en $.UrlPath}}&f={{b64en .Name}}">{{ .Name }}</a> |
||||
|
|
||||
|
{{ end }} |
||||
|
|
||||
|
</div> |
||||
|
<div class="col-md-4"> |
||||
|
<a href="/up?p={{b64en $.UrlPath}}&f={{b64en .Name}}" title="更新{{ .Name }}" class="btn btn-primary btn-sm">同步</a> |
||||
|
<a href="#" class="btn btn-success btn-sm">复制</a></a> |
||||
|
</div> |
||||
|
</li> |
||||
|
{{ end }} |
||||
|
</ul> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 目标服务器 --> |
||||
|
<div class="col-md-6"> |
||||
|
<div class="panel panel-default"> |
||||
|
<!-- Default panel contents --> |
||||
|
<div class="panel-heading">目标站(220.44.660.44)</div> |
||||
|
<div class="panel-body"> |
||||
|
<p>监听目录:/www</p> |
||||
|
<p>相对目录: /app/common </p> |
||||
|
</div> |
||||
|
|
||||
|
<!-- List group --> |
||||
|
<ul class="list-group"> |
||||
|
<li class="list-group-item optzone"> |
||||
|
<div class="col-md-8">Cras justo odio</div> |
||||
|
<div class="col-md-4"> |
||||
|
<a href="#" class="btn btn-primary btn-sm">同步</a> |
||||
|
<a href="#" class="btn btn-success btn-sm">复制</a></a> |
||||
|
</div> |
||||
|
</li> |
||||
|
<li class="list-group-item">Dapibus ac facilisis in</li> |
||||
|
<li class="list-group-item">Morbi leo risus</li> |
||||
|
<li class="list-group-item">Porta ac consectetur ac</li> |
||||
|
<li class="list-group-item">Vestibulum at eros</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<!-- 状态信息 --> |
||||
|
<div class="container"> |
||||
|
<div class="col-md-12"> |
||||
|
<div class="panel"> |
||||
|
<div class="panel-heading">运行状态</div> |
||||
|
<div class="panel-body" > |
||||
|
<ul class="list-group"> |
||||
|
<li class="list-group-item">aa 复制完成</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<script type="text/javascript"> |
||||
|
$(function(){ |
||||
|
// |
||||
|
}); |
||||
|
</script> |
||||
|
</body> |
||||
|
|
||||
|
</html> |
||||
Loading…
Reference in new issue