Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7131603c4 | |||
| 2f3a5a0a59 | |||
| c2468a7389 | |||
| b6ba3486d6 | |||
| f59e909d30 | |||
| 3bb47de45a | |||
| c71973850e | |||
| 65f062b860 | |||
| 7b502fed36 | |||
| fd6b15bdaf | |||
| f31bf24ec2 |
+14
-8
@@ -357,14 +357,18 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
//是否展示日志
|
//是否展示日志
|
||||||
if that.WebConnectLog != nil {
|
if that.WebConnectLog != nil {
|
||||||
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
|
||||||
//负载均衡优化
|
//负载均衡优化
|
||||||
if ipStr == "127.0.0.1" {
|
ipStr := ""
|
||||||
if req.Header.Get("X-Forwarded-For") != "" {
|
if req.Header.Get("X-Forwarded-For") != "" {
|
||||||
ipStr = req.Header.Get("X-Forwarded-For")
|
ipStr = req.Header.Get("X-Forwarded-For")
|
||||||
} else if req.Header.Get("X-Real-IP") != "" {
|
} else if req.Header.Get("X-Real-IP") != "" {
|
||||||
ipStr = req.Header.Get("X-Real-IP")
|
ipStr = req.Header.Get("X-Real-IP")
|
||||||
}
|
}
|
||||||
|
//负载均衡优化
|
||||||
|
if ipStr == "" {
|
||||||
|
//RemoteAddr := that.Req.RemoteAddr
|
||||||
|
ipStr = Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||||
}
|
}
|
||||||
|
|
||||||
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
||||||
@@ -679,7 +683,9 @@ func setMakeCodeListener(name string, appIns *Application) {
|
|||||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
|
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
|
||||||
return isFinished
|
return isFinished
|
||||||
}
|
}
|
||||||
|
if context.RouterString[1] == "hotime" && context.RouterString[2] == "wallpaper" {
|
||||||
|
return isFinished
|
||||||
|
}
|
||||||
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||||
context.Display(2, "你还没有登录")
|
context.Display(2, "你还没有登录")
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/360EntSecGroup-Skylar/excelize"
|
"github.com/360EntSecGroup-Skylar/excelize"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -907,6 +908,53 @@ var TptProject = Proj{
|
|||||||
|
|
||||||
that.Display(0, conf)
|
that.Display(0, conf)
|
||||||
},
|
},
|
||||||
|
//壁纸
|
||||||
|
"wallpaper": func(that *Context) {
|
||||||
|
random := ObjToCeilInt(that.Req.FormValue("random")) //壁纸随机,0为默认,1,为随机
|
||||||
|
|
||||||
|
tp := ObjToCeilInt(that.Req.FormValue("type")) //返回类型,0,json,1,302跳转到图片
|
||||||
|
|
||||||
|
images := that.Application.Cache("wallpaper").ToSlice()
|
||||||
|
if images == nil || len(images) == 0 {
|
||||||
|
|
||||||
|
url := "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=7&mkt=zh-CN"
|
||||||
|
res, e := http.Get(url)
|
||||||
|
if e != nil {
|
||||||
|
that.Display(4, "无法取得数据0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
b, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
that.Display(4, "无法取得数据1")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w := ObjToMap(string(b))
|
||||||
|
if len(w) == 0 {
|
||||||
|
that.Display(4, "无法取得数据2")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
images = w.GetSlice("images")
|
||||||
|
that.Application.Cache("wallpaper", images)
|
||||||
|
}
|
||||||
|
if random == 1 {
|
||||||
|
random = RandX(0, len(images)-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
img := images.GetMap(random)
|
||||||
|
if !strings.Contains(img.GetString("url"), "http") {
|
||||||
|
img["url"] = "https://cn.bing.com" + img.GetString("url")
|
||||||
|
}
|
||||||
|
if tp == 0 {
|
||||||
|
that.Display(0, img)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
that.Resp.Header().Set("Location", img.GetString("url"))
|
||||||
|
that.Resp.WriteHeader(302)
|
||||||
|
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-23
@@ -193,6 +193,12 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
|||||||
if indexNum > -1 {
|
if indexNum > -1 {
|
||||||
coloum["label"] = info.GetString("label")[:indexNum]
|
coloum["label"] = info.GetString("label")[:indexNum]
|
||||||
}
|
}
|
||||||
|
psStart := strings.Index(info.GetString("label"), "{")
|
||||||
|
psEnd := strings.Index(info.GetString("label"), "}")
|
||||||
|
if psStart != -1 && psEnd > psStart {
|
||||||
|
coloum["ps"] = info.GetString("label")[psStart+1 : psEnd]
|
||||||
|
}
|
||||||
|
|
||||||
//去除数据信息,是用:号分割的
|
//去除数据信息,是用:号分割的
|
||||||
indexNum = strings.Index(coloum.GetString("label"), ":")
|
indexNum = strings.Index(coloum.GetString("label"), ":")
|
||||||
if indexNum > -1 {
|
if indexNum > -1 {
|
||||||
@@ -1016,7 +1022,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
|
|
||||||
if keywordTableStr != "" {
|
if keywordTableStr != "" {
|
||||||
if keywordTableStr == v.GetString("name") {
|
if keywordTableStr == v.GetString("name") {
|
||||||
keyword[table+"."+keywordTableStr+"[~]"] = keywordStr
|
data[table+"."+keywordTableStr+"[~]"] = keywordStr
|
||||||
}
|
}
|
||||||
|
|
||||||
if keywordTableStr == v.GetString("value") {
|
if keywordTableStr == v.GetString("value") {
|
||||||
@@ -1026,7 +1032,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
childIds = append(childIds, cv.GetString("id"))
|
childIds = append(childIds, cv.GetString("id"))
|
||||||
}
|
}
|
||||||
if len(childIds) != 0 {
|
if len(childIds) != 0 {
|
||||||
keyword[v.GetString("link")+".id"] = childIds
|
data[v.GetString("link")+".id"] = childIds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@@ -1069,9 +1075,10 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
parentID = userData.GetCeilInt(table + "_id")
|
parentID = userData.GetCeilInt(table + "_id")
|
||||||
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
|
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
|
||||||
} else {
|
} else {
|
||||||
|
//是否展示全部子级
|
||||||
|
where := Map{}
|
||||||
|
if req.FormValue("showall") == "1" {
|
||||||
|
|
||||||
if req.FormValue("showself") != "" {
|
|
||||||
where := Map{}
|
|
||||||
for _, v := range reqValue {
|
for _, v := range reqValue {
|
||||||
if len(where) == 0 {
|
if len(where) == 0 {
|
||||||
where[table+"."+parent_idsStr] = "," + v + ","
|
where[table+"."+parent_idsStr] = "," + v + ","
|
||||||
@@ -1079,9 +1086,21 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
}
|
}
|
||||||
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
|
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
|
||||||
}
|
}
|
||||||
data["OR"] = Map{"OR": where, table + ".id": reqValue}
|
|
||||||
} else {
|
} else {
|
||||||
data[table+".parent_id"] = reqValue
|
where[table+".parent_id"] = reqValue
|
||||||
|
}
|
||||||
|
//是否展示自己
|
||||||
|
if req.FormValue("showself") == "1" {
|
||||||
|
if len(where) == 0 {
|
||||||
|
data["OR"] = Map{table + ".id": reqValue}
|
||||||
|
} else {
|
||||||
|
data["OR"] = Map{"OR": where, table + ".id": reqValue}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(where) != 0 {
|
||||||
|
data["OR"] = where
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1093,14 +1112,9 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
if parent_idsStr != "" {
|
if parent_idsStr != "" {
|
||||||
|
|
||||||
where := Map{}
|
where := Map{}
|
||||||
if len(reqValue) == 1 {
|
//是否全部展示
|
||||||
if len(where) == 0 {
|
if req.FormValue("showall") != "1" {
|
||||||
where[table+"."+searchItem.GetString("name")] = reqValue[0]
|
where[table+"."+searchItem.GetString("name")] = reqValue
|
||||||
|
|
||||||
} else {
|
|
||||||
where = Map{"OR": where, table + "." + searchItem.GetString("name"): reqValue[0]}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for _, v := range reqValue {
|
for _, v := range reqValue {
|
||||||
if len(where) == 0 {
|
if len(where) == 0 {
|
||||||
@@ -1110,6 +1124,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
|
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户
|
//用户
|
||||||
if userData[searchItem.GetString("name")] != nil {
|
if userData[searchItem.GetString("name")] != nil {
|
||||||
|
|
||||||
@@ -1143,17 +1158,12 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
data[k] = v
|
data[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(keyword) > 1 {
|
if len(keyword) > 1 {
|
||||||
|
if data["OR"] != nil {
|
||||||
if data["AND"] != nil {
|
data = Map{"AND": data, "OR": keyword}
|
||||||
and := data.GetMap("AND")
|
|
||||||
for k, v := range keyword {
|
|
||||||
and[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
//data = Map{"AND":Map{"OR": keyword} data, }
|
|
||||||
} else {
|
} else {
|
||||||
data["AND"] = keyword
|
data["OR"] = keyword
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//安全锁
|
//安全锁
|
||||||
@@ -36,6 +37,42 @@ func StrFirstToUpper(str string) string {
|
|||||||
return strings.ToUpper(first) + other
|
return strings.ToUpper(first) + other
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 时间转字符串,第二个参数支持1-5对应显示年月日时分秒
|
||||||
|
func Time2Str(t *time.Time, qu ...interface{}) string {
|
||||||
|
if t == nil || t.Unix() < 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
tp := 5
|
||||||
|
if len(qu) != 0 {
|
||||||
|
tp = (qu[0]).(int)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tp {
|
||||||
|
case 1:
|
||||||
|
return t.Format("2006-01")
|
||||||
|
case 2:
|
||||||
|
return t.Format("2006-01-02")
|
||||||
|
case 3:
|
||||||
|
return t.Format("2006-01-02 15")
|
||||||
|
case 4:
|
||||||
|
return t.Format("2006-01-02 15:04")
|
||||||
|
case 5:
|
||||||
|
return t.Format("2006-01-02 15:04:05")
|
||||||
|
case 12:
|
||||||
|
return t.Format("01-02")
|
||||||
|
case 14:
|
||||||
|
return t.Format("01-02 15:04")
|
||||||
|
case 15:
|
||||||
|
return t.Format("01-02 15:04:05")
|
||||||
|
case 34:
|
||||||
|
return t.Format("15:04")
|
||||||
|
case 35:
|
||||||
|
return t.Format("15:04:05")
|
||||||
|
}
|
||||||
|
return t.Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
||||||
func StrLd(s, t string, ignoreCase bool) int {
|
func StrLd(s, t string, ignoreCase bool) int {
|
||||||
if ignoreCase {
|
if ignoreCase {
|
||||||
|
|||||||
+10
-7
@@ -75,14 +75,17 @@ func (that *Context) View() {
|
|||||||
if that.Session("user_id").Data != nil {
|
if that.Session("user_id").Data != nil {
|
||||||
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
|
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
|
||||||
}
|
}
|
||||||
ipStr := Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
|
|
||||||
//负载均衡优化
|
//负载均衡优化
|
||||||
if ipStr == "127.0.0.1" {
|
ipStr := ""
|
||||||
if that.Req.Header.Get("X-Forwarded-For") != "" {
|
if that.Req.Header.Get("X-Forwarded-For") != "" {
|
||||||
ipStr = that.Req.Header.Get("X-Forwarded-For")
|
ipStr = that.Req.Header.Get("X-Forwarded-For")
|
||||||
} else if that.Req.Header.Get("X-Real-IP") != "" {
|
} else if that.Req.Header.Get("X-Real-IP") != "" {
|
||||||
ipStr = that.Req.Header.Get("X-Real-IP")
|
ipStr = that.Req.Header.Get("X-Real-IP")
|
||||||
}
|
}
|
||||||
|
//负载均衡优化
|
||||||
|
if ipStr == "" {
|
||||||
|
//RemoteAddr := that.Req.RemoteAddr
|
||||||
|
ipStr = Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
|
||||||
}
|
}
|
||||||
that.Log["ip"] = ipStr
|
that.Log["ip"] = ipStr
|
||||||
that.Db.Insert("logs", that.Log)
|
that.Db.Insert("logs", that.Log)
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ func Down(url, path, name string, e ...*Error) bool {
|
|||||||
}
|
}
|
||||||
out, err := os.Create(path + name)
|
out, err := os.Create(path + name)
|
||||||
|
|
||||||
if err != nil && e[0] != nil {
|
if err != nil && len(e) != 0 {
|
||||||
e[0].SetError(err)
|
e[0].SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil && e[0] != nil {
|
if err != nil && len(e) != 0 {
|
||||||
e[0].SetError(err)
|
e[0].SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func Down(url, path, name string, e ...*Error) bool {
|
|||||||
|
|
||||||
pix, err := ioutil.ReadAll(resp.Body)
|
pix, err := ioutil.ReadAll(resp.Body)
|
||||||
_, err = io.Copy(out, bytes.NewReader(pix))
|
_, err = io.Copy(out, bytes.NewReader(pix))
|
||||||
if err != nil && e[0] != nil {
|
if err != nil && len(e) != 0 {
|
||||||
e[0].SetError(err)
|
e[0].SetError(err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-9
@@ -8,7 +8,7 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mongoDb struct {
|
type MongoDb struct {
|
||||||
Client *mongo.Client
|
Client *mongo.Client
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
DataBase *mongo.Database
|
DataBase *mongo.Database
|
||||||
@@ -16,12 +16,12 @@ type mongoDb struct {
|
|||||||
LastErr error
|
LastErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(database, url string) (*mongoDb, error) {
|
func GetMongoDb(database, url string) (*MongoDb, error) {
|
||||||
db := mongoDb{}
|
db := MongoDb{}
|
||||||
clientOptions := options.Client().ApplyURI(url)
|
clientOptions := options.Client().ApplyURI(url)
|
||||||
|
|
||||||
db.Ctx = context.TODO()
|
db.Ctx = context.TODO()
|
||||||
// Connect to MongoDB
|
// Connect to MongoDb
|
||||||
var err error
|
var err error
|
||||||
db.Client, err = mongo.Connect(db.Ctx, clientOptions)
|
db.Client, err = mongo.Connect(db.Ctx, clientOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -32,7 +32,7 @@ func Init(database, url string) (*mongoDb, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Println("Connected to MongoDB!")
|
fmt.Println("Connected to MongoDb!")
|
||||||
//databases, err := db.Client.ListDatabaseNames(db.Ctx, bson.M{})
|
//databases, err := db.Client.ListDatabaseNames(db.Ctx, bson.M{})
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
@@ -43,7 +43,7 @@ func Init(database, url string) (*mongoDb, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *mongoDb) Insert(table string, data interface{}) string {
|
func (that *MongoDb) Insert(table string, data interface{}) string {
|
||||||
collection := that.DataBase.Collection(table)
|
collection := that.DataBase.Collection(table)
|
||||||
re, err := collection.InsertOne(that.Ctx, data)
|
re, err := collection.InsertOne(that.Ctx, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,7 +53,7 @@ func (that *mongoDb) Insert(table string, data interface{}) string {
|
|||||||
return ObjToStr(re.InsertedID)
|
return ObjToStr(re.InsertedID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *mongoDb) InsertMany(table string, data ...interface{}) Slice {
|
func (that *MongoDb) InsertMany(table string, data ...interface{}) Slice {
|
||||||
collection := that.DataBase.Collection(table)
|
collection := that.DataBase.Collection(table)
|
||||||
re, err := collection.InsertMany(that.Ctx, data)
|
re, err := collection.InsertMany(that.Ctx, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -65,7 +65,33 @@ func (that *mongoDb) InsertMany(table string, data ...interface{}) Slice {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *mongoDb) Get(table string, where Map) Map {
|
func (that *MongoDb) Update(table string, data Map, where Map) int64 {
|
||||||
|
collection := that.DataBase.Collection(table)
|
||||||
|
re, err := collection.UpdateMany(that.Ctx, where, data)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
that.LastErr = err
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return re.ModifiedCount
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *MongoDb) Delete(table string, where Map) int64 {
|
||||||
|
collection := that.DataBase.Collection(table)
|
||||||
|
re, err := collection.DeleteMany(that.Ctx, where)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
that.LastErr = err
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return re.DeletedCount
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (that *MongoDb) Get(table string, where Map) Map {
|
||||||
results := []Map{}
|
results := []Map{}
|
||||||
var cursor *mongo.Cursor
|
var cursor *mongo.Cursor
|
||||||
var err error
|
var err error
|
||||||
@@ -93,7 +119,7 @@ func (that *mongoDb) Get(table string, where Map) Map {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that mongoDb) Select(table string, where Map, page, pageRow int64) []Map {
|
func (that MongoDb) Select(table string, where Map, page, pageRow int64) []Map {
|
||||||
page = (page - 1) * pageRow
|
page = (page - 1) * pageRow
|
||||||
if page < 0 {
|
if page < 0 {
|
||||||
page = 0
|
page = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user