maxiaoshan 3 жил өмнө
parent
commit
df6a04d4a6

+ 1 - 0
src/front/front.go

@@ -83,6 +83,7 @@ type Front struct {
 const role_admin, role_examine, role_dev = 3, 2, 1                                                                            //管理员,审核员,开发员
 const Sp_state_0, Sp_state_1, Sp_state_2, Sp_state_3, Sp_state_4, Sp_state_5, Sp_state_6, Sp_state_7 = 0, 1, 2, 3, 4, 5, 6, 7 //0待完成,1待审核,2打回,3发布,4作废,5已上架,6已下架,7其他
 
+var LuaReg = regexp.MustCompile(`(:(find|match)|string\.|com\.getPureContent)`)
 var spinfos sync.Map = sync.Map{}
 var SessMap map[string]*httpsession.Session
 var AutoTpl map[string]interface{}

+ 19 - 8
src/front/spider.go

@@ -377,17 +377,22 @@ func (f *Front) SaveStep() {
 			//三级页复制
 			param["str_recontent"] = f.StepRe3.Expert
 			param["iscopycontent"] = f.StepRe3.Checked
-			issave := spider.SaveSpider(code, param) //保存脚本
-			if issave {
-				for k, v := range one {
-					if k != "_id" && param[k] == nil {
-						param[k] = v
+			matchLua := LuaTextCheck(f.Step2.Expert, f.Step3.Expert)
+			if !matchLua {
+				issave := spider.SaveSpider(code, param) //保存脚本
+				if issave {
+					for k, v := range one {
+						if k != "_id" && param[k] == nil {
+							param[k] = v
+						}
 					}
+					Wlog(f.Base.SpiderName, f.Base.SpiderCode, f.GetSession("username").(string), f.GetSession("userid").(string), "修改", param)
+					rep["msg"] = "保存成功"
+				} else {
+					rep["msg"] = "保存失败"
 				}
-				Wlog(f.Base.SpiderName, f.Base.SpiderCode, f.GetSession("username").(string), f.GetSession("userid").(string), "修改", param)
-				rep["msg"] = "保存成功"
 			} else {
-				rep["msg"] = "保存失败"
+				rep["msg"] = "保存失败,代码中含有禁用方法"
 			}
 			rep["code"] = util.Se.Encode2Hex(code)
 			f.ServeJson(rep)
@@ -395,6 +400,12 @@ func (f *Front) SaveStep() {
 	}
 }
 
+//检查列表页和三级页代码中是否含lua原生方法
+func LuaTextCheck(list, detail string) bool {
+	defer qu.Catch()
+	return LuaReg.MatchString(list) || LuaReg.MatchString(detail)
+}
+
 func (f *Front) Assort() {
 	state, _ := f.GetInteger("state")
 	code := f.GetString("code")

+ 30 - 0
src/spider/script.go

@@ -455,6 +455,36 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 		S.Push(lua.LBool(isMatch))
 		return 2
 	}))
+	//截取
+	s.L.SetGlobal("stringSub", s.L.NewFunction(func(S *lua.LState) int {
+		text := S.ToString(-3)
+		start := S.ToInt(-2)
+		end := S.ToInt(-1)
+		result := ""
+		if len(text) > 0 {
+			textRune := []rune(text)
+			textLen := len(textRune)
+			if end == -1 {
+				if start >= 1 { //正向截取到结尾
+					result = string(textRune[start-1:])
+				} else if start < 0 && textLen+start >= 0 { //反向截取后缀
+					result = string(textRune[textLen+start:])
+				}
+			} else if start >= 1 && end <= textLen { //从第start个截取到第end个
+				result = string(textRune[start-1 : end])
+			}
+		}
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//长度
+	s.L.SetGlobal("stringLen", s.L.NewFunction(func(S *lua.LState) int {
+		text := S.ToString(-1)
+		textLen := len([]rune(text))
+		S.Push(lua.LNumber(textLen))
+		return 1
+	}))
+
 	//去除特殊标签中间内容
 	s.L.SetGlobal("getPureContent", s.L.NewFunction(func(S *lua.LState) int {
 		con := S.ToString(-1)

+ 1 - 1
src/web/staticres/js/common.js

@@ -415,7 +415,7 @@ common.spider.save_unnew=function(){
 				}
 				$(window).unbind('beforeunload');
 			}else{
-				showMsg(r,function(){});
+				showMsg(r["msg"],function(){});
 			}
 		}
 	})