You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
package core
|
|
|
|
import (
|
|
"aufs/db"
|
|
"aufs/util"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type Brespone struct {
|
|
Status string `json:"status"`
|
|
Data []db.StFileInfo `json:"data"` //目录下的文件
|
|
}
|
|
|
|
// 输出数据库中的基础文件的结构和hash
|
|
func BfsInfo(w http.ResponseWriter, r *http.Request) {
|
|
// 监听的目录通过?p=的方式传入
|
|
urlpath := r.URL.Query().Get("p")
|
|
fmt.Printf("your params:%s\n", urlpath)
|
|
// 防止逃逸,造成漏洞
|
|
if strings.Contains(urlpath, "../") {
|
|
// urlpath = "Lg=="
|
|
urlpath = util.Bas64end(".")
|
|
}
|
|
|
|
// dsrpath := util.Base64dec(urlpath)
|
|
// 如果根目录
|
|
if urlpath == "" || urlpath == "." || urlpath == "Lg==" {
|
|
urlpath = util.Bas64end(".")
|
|
// urlpath = "Lg=="
|
|
}
|
|
|
|
fmt.Printf("after chk:%s\n", urlpath)
|
|
|
|
// 链接数据库
|
|
db.Init()
|
|
// 获取请求的信息
|
|
flists := db.Fquery(urlpath)
|
|
// fmt.Printf("stfile :%v\n", flist)
|
|
//
|
|
bfslist := make([]db.StFileInfo, 0)
|
|
//
|
|
for _, v := range flists {
|
|
bfslist = append(bfslist, v)
|
|
}
|
|
|
|
// fmt.Fprintf(w, "%s:sqlite query ...", r.Host)
|
|
response := Brespone{
|
|
Status: "success",
|
|
Data: bfslist,
|
|
}
|
|
|
|
// 开启跨域
|
|
uCorsHadler(w, r)
|
|
json.NewEncoder(w).Encode(response)
|
|
}
|
|
|