Browse Source

调整代码

master
453530270@qq.com 2 years ago
parent
commit
e1997e769a
  1. 10
      fss/core/baseinfo.go
  2. 2
      fss/db/sqliteDb.go
  3. BIN
      fss/ups.db
  4. 81
      fss/www/index.html
  5. BIN
      fssc/ups.db
  6. BIN
      fstool/fshash
  7. 16
      fstool/util/fsutil.go

10
fss/core/baseinfo.go

@ -2,6 +2,7 @@ package core
import ( import (
"encoding/json" "encoding/json"
"fmt"
"fss/db" "fss/db"
"fss/util" "fss/util"
"net/http" "net/http"
@ -17,17 +18,22 @@ type Brespone struct {
func BfsInfo(w http.ResponseWriter, r *http.Request) { func BfsInfo(w http.ResponseWriter, r *http.Request) {
// 监听的目录通过?p=的方式传入 // 监听的目录通过?p=的方式传入
urlpath := r.URL.Query().Get("p") urlpath := r.URL.Query().Get("p")
fmt.Printf("your params:%s\n", urlpath)
// 防止逃逸,造成漏洞 // 防止逃逸,造成漏洞
if strings.Contains(urlpath, "../") { if strings.Contains(urlpath, "../") {
// urlpath = "Lg==" // urlpath = "Lg=="
urlpath = "." urlpath = util.Bas64end(".")
} }
// dsrpath := util.Base64dec(urlpath)
// 如果根目录 // 如果根目录
if urlpath == "" || urlpath == "." { if urlpath == "" || urlpath == "." || urlpath == "Lg==" {
urlpath = util.Bas64end(".") urlpath = util.Bas64end(".")
// urlpath = "Lg=="
} }
fmt.Printf("after chk:%s\n", urlpath)
// 链接数据库 // 链接数据库
db.Init() db.Init()
// 获取请求的信息 // 获取请求的信息

2
fss/db/sqliteDb.go

@ -12,7 +12,7 @@ var db *sqlx.DB
var err error var err error
func Init() { func Init() {
fmt.Printf("hey,I am initilize function in SqliteDb\n") // fmt.Printf("hey,I am initilize function in SqliteDb\n")s
// //
// Open() 函数指定驱动名称和数据源名称 // Open() 函数指定驱动名称和数据源名称
db, err = sqlx.Open("sqlite", "ups.db") db, err = sqlx.Open("sqlite", "ups.db")

BIN
fss/ups.db

Binary file not shown.

81
fss/www/index.html

@ -43,7 +43,7 @@
margin-left: 16px; margin-left: 16px;
} }
.hschange{ .hschange {
background-color: #da1616; background-color: #da1616;
} }
@ -177,13 +177,13 @@
var chknum = 0; var chknum = 0;
var scip = ""; //目标服务器ip var scip = ""; //目标服务器ip
var urlpath = ".";// 当前的操作目录 var urlpath = ".";// 当前的操作目录
var bfsarr= new Array; // base file infomation array //var bfsarr = new Array; // base file infomation array
$(function () { $(function () {
// read sessionStorage // read sessionStorage
var oscip = sessionStorage.getItem("scip"); var oscip = sessionStorage.getItem("scip");
var otip = sessionStorage.getItem("tscip"); var otip = sessionStorage.getItem("tscip");
if (oscip != "" || otip!='') { if (oscip != "" || otip != '') {
$("input[name='sip']").val(oscip); $("input[name='sip']").val(oscip);
$("input[name='tsip']").val(otip); $("input[name='tsip']").val(otip);
} }
@ -192,7 +192,7 @@
scfs(); scfs();
}) })
// 目标服务器的文件信息 // 目标服务器的文件信息
var scfs = function () { var scfs = function () {
// //
@ -202,15 +202,16 @@
//监视目录 //监视目录
var jsdir = $("input[name='sdir']").val(); var jsdir = $("input[name='sdir']").val();
if (jsdir != '') { if (jsdir != '') {
urlpath = encodeURIComponent(btoa(jsdir)); urlpath = bsrqst(jsdir)
//urlpath = encodeURIComponent(btoa(jsdir));
} }
// //
var html = "<li class=\"list-group-item\">输入源服务器" + scip + "</li>"; var html = "<li class=\"list-group-item\">输入源服务器" + scip + "</li>";
$("#mbip").text("源站(" + scip + ")"); $("#mbip").text("源站(" + scip + ")");
// 获取信息 // 获取信息
gescinfo("#scsc",scip,urlpath); gescinfo("#scsc", scip, urlpath);
// 获取基础结构信息
bsfinfo(urlpath);
// //
$("#rstatus").append(html); $("#rstatus").append(html);
} }
@ -235,37 +236,51 @@
// 目标站 // 目标站
$("#mbip").text("目标站(" + tsip + ")"); $("#mbip").text("目标站(" + tsip + ")");
// 获取信息 // 获取信息
gescinfo("#tgsc",tsip,urlpath); gescinfo("#tgsc", tsip, urlpath);
// //
$("#rstatus").append(html); $("#rstatus").append(html);
} }
// 获取目标服务器的信息 // 获取目标服务器的信息
var gescinfo = function (elemnt,scip,upath) { var gescinfo = function (elemnt, scip, upath) {
upath = upath.replace("/\\/g", "\/");
// 获取基础结构信息
var bfsarr = new Array;
bfsarr = bsfinfo(upath);
// console.log("in gsc", bfsarr)
// 客户端的状态地址 // 客户端的状态地址
var url = "http://" + scip + ":9099/sc?p=" + upath.replace("/\\/g", "\/"); var url = "http://" + scip + ":9099/sc?p=" + upath;
// //
var html = ""; var html = "";
$.getJSON(url, function (res) { $.getJSON(url, function (res) {
// //
var chgflag;
// res.curdir // res.curdir
$.each(res.data.list, function (k, v) { $.each(res.data.list, function (k, v) {
// console.log("kn",btoa(v.fname))
// console.log("kkkk "+k,bfsarr[btoa(v.fname)])
// 处理后的base64
var bsfn="";
// 判读是否存在 变化 // 判读是否存在 变化
if(!v.dirflag){ if (!v.dirflag) {
var chgflag=bfsarr[v.fname] == v.hash?" nochage":" hschange"; bsfn=btoa(v.fname)
chgflag = bfsarr[bsfn] == v.hash ? " nochage" : " hschange";
// chgflag = bfsarr["'" + v.fname + "'"] == v.hash ? " nochage" : " hschange";
} }
// //
html += "<li class=\"list-group-item optzone "+chgflag+"\"><div class=\"col-md-10\">"; html += "<li class=\"list-group-item optzone " + chgflag + "\"><div class=\"col-md-10\">";
html+="<input type=\"checkbox\" name=\"sfiles\" value="+v.fname+" />"; html += "<input type=\"checkbox\" name=\"sfiles\" value=" + v.fname + " />";
if (v.dirflag) { if (v.dirflag) {
html += "<span class=\"icon folder-icon\"></span>" + v.fname + "</div>"; html += "<span class=\"icon folder-icon\"></span>" + v.fname + "</div>";
} else { } else {
html += "<span class=\"icon file-icon\"></span>" + html += "<span class=\"icon file-icon\"></span>" +
"<a href=\"javascript:void(0);\" hsval='"+v.hash+"' bhasval='"+bfsarr[v.fname]+"'>"+v.fname + "</a></div>"; "<a href=\"javascript:void(0);\" hsval='" + v.hash + "' bhasval='" + bfsarr[bsfn] + "'>" + v.fname + "</a></div>";
} }
if (v.isbackup == 1) { if (v.isbackup == 1) {
@ -352,26 +367,28 @@
} }
//解码base64 //解码base64
var dbsresp = function (bsStr) { var dbsresp = function (bsStr) {
console.log("respone base64 string ",bsStr) // console.log("respone base64 string ", bsStr)
if(bsStr=="."){ if (bsStr == ".") {
return "." return "."
}else{ } else {
return decodeURIComponent(atob(bsStr)) return decodeURIComponent(atob(bsStr))
} }
} }
// 获取基础结构,存入数组 // 获取基础结构,存入数组
var bsfinfo = function(upath){ // upath 的方式存入 session storage
console.log("get basic file infomation ",upath) var bsfinfo = function (upath) {
bfsarr.splice() var barr= new Array;
$.getJSON("/bs",{p:upath},function(ret){ $.getJSON("/bs?p="+upath, function (ret) {
// 遍历存入数组 // 遍历存入数组
$.each(ret.data,function(k,v){ $.each(ret.data, function (k, v) {
bfsarr[v.fname] = v.fhash var kn = btoa(v.fname)
barr[kn] = v.fhash
}); });
// console.log(ttarr["UkVBRE1FLm1k"])
}) })
// console.log(barr[0])
console.log (bfsarr) return barr;
} }
// 另外的base64的解码 // 另外的base64的解码

BIN
fssc/ups.db

Binary file not shown.

BIN
fstool/fshash

Binary file not shown.

16
fstool/util/fsutil.go

@ -17,11 +17,6 @@ func GetDirFilePaths(dirPath string, relativeOnly bool) ([]string, error) {
if err != nil { if err != nil {
return err return err
} }
// 排除软连接
if info.Mode()&os.ModeSymlink == 0 {
return nil
}
//
if !info.IsDir() { if !info.IsDir() {
if relativeOnly { if relativeOnly {
fileName := filepath.Base(path) fileName := filepath.Base(path)
@ -41,6 +36,17 @@ func GetDirFilePaths(dirPath string, relativeOnly bool) ([]string, error) {
// 计算文件的hash // 计算文件的hash
func CalacHash(rfile string) string { func CalacHash(rfile string) string {
// 排除软连接的情况
// Lstat 用于获取文件的状态,而不是文件的属性
finfo, err := os.Lstat(rfile)
if err != nil {
return ""
}
// 排除软连接
if finfo.Mode()&os.ModeSymlink != 0 {
fmt.Printf("file:%s,mode:%v\n", rfile, finfo.Mode())
return ""
}
// 获取到真实地址 // 获取到真实地址
// rpath := filepath.Join(config.G.FilePath, rfile) // rpath := filepath.Join(config.G.FilePath, rfile)
// //

Loading…
Cancel
Save