Эх сурвалжийг харах

7000新增爬虫维护限制,公共方法新增

maxiaoshan 2 жил өмнө
parent
commit
efd02336d5

+ 11 - 12
src/front/front.go

@@ -83,7 +83,6 @@ type Front struct {
 	getCity xweb.Mapper `xweb:"/center/getCity"` //获取城市
 }
 
-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)`)
@@ -127,9 +126,9 @@ func (f *Front) Login() error {
 		f.SetSession("platform", (*user)["s_platform"])
 		comeintime := time.Unix((*user)["l_comeintime"].(int64), 0).Format("2006-01-02")
 		f.SetSession("comeintime", comeintime)
-		if qu.IntAll((*user)["i_auth"]) > role_admin {
+		if qu.IntAll((*user)["i_auth"]) > u.Role_Admin {
 			return f.Redirect("/center/user.html")
-		} else if qu.IntAll((*user)["i_auth"]) == role_dev {
+		} else if qu.IntAll((*user)["i_auth"]) == u.Role_Dev {
 			return f.Redirect("/center/mytask")
 		} else {
 			return f.Redirect("/center")
@@ -146,7 +145,7 @@ func (f *Front) Login() error {
 func (f *Front) User() {
 	if f.Method() == "POST" {
 		auth := qu.IntAll(f.GetSession("auth"))
-		if auth > role_admin {
+		if auth > u.Role_Admin {
 			start, _ := f.GetInteger("start")
 			limit, _ := f.GetInteger("length")
 			draw, _ := f.GetInteger("draw")
@@ -183,7 +182,7 @@ func (f *Front) User() {
 func (f *Front) DelUser() {
 	userid := f.GetString("userid")
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth > role_admin {
+	if auth > u.Role_Admin {
 		query := map[string]interface{}{
 			"_id": mongodb.StringTOBsonId(userid),
 		}
@@ -403,14 +402,14 @@ func (f *Front) LoadIndex() {
 				map[string]interface{}{"param_common.1": map[string]interface{}{"$regex": search}},
 			}
 		}
-		if auth == role_examine { //审核员
+		if auth == u.Role_Examine { //审核员
 			if state > -1 {
 				query["state"] = state
 			} else {
 				query["state"] = Sp_state_1
 			}
 
-		} else if auth == role_dev { //开发员
+		} else if auth == u.Role_Dev { //开发员
 			if state > -1 {
 				query["state"] = state
 			}
@@ -484,7 +483,7 @@ func (f *Front) Checkrepeat() {
 //新建
 func (f *Front) Spidernew() error {
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth != role_admin {
+	if auth != u.Role_Admin {
 		return nil
 	}
 	copy := f.GetString("copy")
@@ -528,7 +527,7 @@ func (f *Front) Reg() {
 
 func (f *Front) ImportLua() {
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth != role_admin {
+	if auth != u.Role_Admin {
 		f.ServeJson("没有权限")
 		return
 	}
@@ -786,7 +785,7 @@ func saveLua(o map[string]interface{}) (bool, string) {
 
 func (f *Front) Importdata() {
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth == role_admin {
+	if auth == u.Role_Admin {
 		if f.Method() == "GET" {
 			f.Render("import.html")
 		} else {
@@ -869,7 +868,7 @@ func (f *Front) FindName() {
 //分配爬虫
 func (f *Front) Assign() {
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth != role_admin {
+	if auth != u.Role_Admin {
 		f.Write("n")
 		return
 	}
@@ -936,7 +935,7 @@ func (f *Front) DelRedis() {
 	hrefsarr := strings.Split(hrefs, ",")
 	auth := qu.IntAll(f.GetSession("auth"))
 	err := []string{}
-	if auth == role_admin { //权限控制
+	if auth == u.Role_Admin { //权限控制
 		if len(hrefsarr) > 0 {
 			for k1, h := range hrefsarr {
 				href := Reg.FindString(h)

+ 1 - 1
src/front/luamove.go

@@ -26,7 +26,7 @@ type LuaMove struct {
 func (lm *LuaMove) LuaMove() {
 	defer qu.Catch()
 	auth := qu.IntAll(lm.GetSession("auth"))
-	if auth == role_admin {
+	if auth == u.Role_Admin {
 		if lm.Method() == "GET" {
 			events := []string{}
 			for k, _ := range util.Config.Uploadevents {

+ 25 - 12
src/front/spider.go

@@ -94,7 +94,7 @@ func (f *Front) LoadSpider(codeTaskIdReState string) error {
 	} else if taskId == "restate=3" {
 		restate = 3
 	} else {
-		if auth == role_dev && qu.ObjToString(f.GetSession(taskId)) == "" {
+		if auth == u.Role_Dev && qu.ObjToString(f.GetSession(taskId)) == "" {
 			xgTime := time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05")
 			f.SetSession(taskId, xgTime)
 		}
@@ -108,6 +108,18 @@ func (f *Front) LoadSpider(codeTaskIdReState string) error {
 		auth := qu.IntAll(f.GetSession("auth"))
 		if qu.ObjToString((*lua)["createuserid"]) == f.GetSession("userid").(string) || auth >= 1 {
 			if len(*lua) > 0 {
+				if qu.IntAll((*lua)["event"]) == 7000 && qu.IntAll((*lua)["urgency"]) == 0 && qu.IntAll((*lua)["state"]) == 0 {
+					q := map[string]interface{}{
+						"event":        7000,
+						"state":        0,
+						"urgency":      1,
+						"modifyuserid": f.GetSession("userid"),
+					}
+					if u.MgoEB.Count("luaconfig", q) > 0 {
+						f.Write("名下还有7000节点待完成的紧急爬虫,暂无法处理该爬虫!")
+						return nil
+					}
+				}
 				if copy != "" {
 					//luacopy, _ := u.MgoE.FindOne("luaconfig", map[string]interface{}{"code": copy})
 					luacopy, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": copy})
@@ -277,7 +289,7 @@ func (f *Front) SaveStep() {
 			if len((*one)) > 0 {
 				comeintime = qu.Int64All((*one)["comeintime"])
 				ouserid := qu.ObjToString((*one)["createuserid"])
-				if ouserid != userid && auth == role_dev {
+				if ouserid != userid && auth == u.Role_Dev {
 					f.Write("权限不够,不能修改他人脚本")
 					return
 				} else {
@@ -286,14 +298,14 @@ func (f *Front) SaveStep() {
 					f.Base.SpiderName = ((*one)["param_common"].([]interface{}))[1].(string)
 				}
 			} else {
-				if auth != role_admin {
+				if auth != u.Role_Admin {
 					f.Write("不能新建爬虫,请联系管理员导入")
 					return
 				}
 			}
 			listcheck := f.GetString("listcheck")
 			contentcheck := f.GetString("contentcheck")
-			if auth == role_dev {
+			if auth == u.Role_Dev {
 				//f.Base.SpiderStoreToMsgEvent = 4002
 			}
 			common := []interface{}{
@@ -368,7 +380,7 @@ func (f *Front) SaveStep() {
 				param["code"] = (*one)["code"]
 				//开发员关联任务修改爬虫状态
 				state = qu.IntAll((*one)["state"])
-				if auth == role_dev && state >= Sp_state_3 && restate != 1 { //开发员修改,已经审核通过(不包含已上架),状态重置为待完成(restate!=1判断,重采修改保存爬虫时不修改爬虫状态)
+				if auth == u.Role_Dev && state >= Sp_state_3 && restate != 1 { //开发员修改,已经审核通过(不包含已上架),状态重置为待完成(restate!=1判断,重采修改保存爬虫时不修改爬虫状态)
 					param["state"] = 0
 				} else {
 					param["state"] = state
@@ -401,6 +413,7 @@ func (f *Front) SaveStep() {
 				} else if event := qu.IntAll((*one)["event"]); event != 7000 { //默认增量节点
 					param["incrementevent"] = event
 				}
+				param["urgency"] = 1 //保存到7000时,爬虫紧急度变为紧急(控制7000节点爬虫紧急未写完不能写普通)
 			} else if f.OtherBase.SpiderType == "increment" && err == nil { //增量
 				param["event"] = tmpEvent //开发人员切换增量节点
 			}
@@ -924,7 +937,7 @@ func (f *Front) DownSpider(code string) {
 	user := f.GetSession("loginuser")
 	success := false
 	script := ""
-	if auth > role_dev {
+	if auth > u.Role_Dev {
 		success = true
 		//one, _ := u.MgoE.FindOne("luaconfig", map[string]interface{}{"code": code})
 		one, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
@@ -984,7 +997,7 @@ func DelSpiderHeart(code string) bool {
 func (f *Front) Checktime() {
 	code := f.GetString("code")
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth != role_admin {
+	if auth != u.Role_Admin {
 		f.ServeJson(false)
 	} else {
 		//b := u.MgoE.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{
@@ -1424,7 +1437,7 @@ func UpTaskState(code []string, num int, reason string, startTime int64) {
 //更新节点
 func (f *Front) ChangeEvent() {
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth != role_admin {
+	if auth != u.Role_Admin {
 		f.ServeJson("没有权限")
 	}
 	code := f.GetString("code")
@@ -1478,15 +1491,15 @@ func (f *Front) ChangeEvent() {
 func IsHasUpState(auth, state int) bool {
 	rep := false
 	switch auth {
-	case role_dev:
+	case u.Role_Dev:
 		if state == Sp_state_1 || state == Sp_state_7 {
 			rep = true
 		}
-	case role_examine:
+	case u.Role_Examine:
 		if state == Sp_state_2 || state == Sp_state_3 {
 			rep = true
 		}
-	case role_admin:
+	case u.Role_Admin:
 		rep = true
 	default:
 	}
@@ -1498,7 +1511,7 @@ var list_fields = `{"_id":1,"code":1,"createuser":1,"modifyuser":1,"modifytime":
 //脚本管理,结合爬虫运行信息
 func (f *Front) LuaList() {
 	auth := qu.IntAll(f.GetSession("auth"))
-	if auth != role_admin {
+	if auth != u.Role_Admin {
 		f.ServeJson("没有权限!")
 		return
 	}

+ 39 - 27
src/spider/script.go

@@ -10,7 +10,6 @@ import (
 	codegrpc "analysiscode/client"
 	"bytes"
 	"compress/gzip"
-	"crypto/aes"
 	"encoding/base64"
 	"encoding/json"
 	"fmt"
@@ -499,19 +498,25 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 		key := S.ToString(-1)
 		bytekey := []byte(key)
 		byteorigData := []byte(origData)
-		cipher, _ := aes.NewCipher(generateKey([]byte(bytekey)))
-		length := (len(byteorigData) + aes.BlockSize) / aes.BlockSize
-		plain := make([]byte, length*aes.BlockSize)
-		copy(plain, byteorigData)
-		pad := byte(len(plain) - len(byteorigData))
-		for i := len(byteorigData); i < len(plain); i++ {
-			plain[i] = pad
-		}
-		encrypted := make([]byte, len(plain))
-		// 分组分块加密
-		for bs, be := 0, cipher.BlockSize(); bs <= len(byteorigData); bs, be = bs+cipher.BlockSize(), be+cipher.BlockSize() {
-			cipher.Encrypt(encrypted[bs:be], plain[bs:be])
-		}
+		encrypted := util.AesECBEncrypt(byteorigData, bytekey)
+		result := base64.StdEncoding.EncodeToString(encrypted)
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//aes ecb模式解密
+	s.L.SetGlobal("aesDecryptECB", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-2)
+		key := S.ToString(-1)
+		data, _ := base64.StdEncoding.DecodeString(origData)
+		result := util.AesECBDecrypter(data, []byte(key))
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//des ecb模式加密
+	s.L.SetGlobal("desEncryptECB", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-2)
+		key := S.ToString(-1)
+		encrypted := util.DesECBEncrypt([]byte(origData), []byte(key))
 		result := base64.StdEncoding.EncodeToString(encrypted)
 		S.Push(lua.LString(result))
 		return 1
@@ -520,8 +525,26 @@ func (s *Script) LoadScript(downloadnode, script string, isfile ...string) {
 	s.L.SetGlobal("desDecryptECB", s.L.NewFunction(func(S *lua.LState) int {
 		origData := S.ToString(-2)
 		key := S.ToString(-1)
-		b, _ := base64.StdEncoding.DecodeString(origData)
-		result := util.DesECBDecrypter(b, []byte(key))
+		data, _ := base64.StdEncoding.DecodeString(origData)
+		result := util.DesECBDecrypter(data, []byte(key))
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//rsa 公钥加密
+	s.L.SetGlobal("rsaEncrypt", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-2)
+		key := S.ToString(-1)
+		encrypted := util.EncryptWithPublicKey([]byte(origData), []byte(key))
+		result := base64.StdEncoding.EncodeToString(encrypted)
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//rsa 私钥解密
+	s.L.SetGlobal("rsaDecrypt", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-2)
+		key := S.ToString(-1)
+		data, _ := base64.StdEncoding.DecodeString(origData)
+		result := util.DecryptWithPrivateKey(data, []byte(key))
 		S.Push(lua.LString(result))
 		return 1
 	}))
@@ -822,14 +845,3 @@ func (s *Script) GetBoolVar(key string) bool {
 	}
 	return false
 }
-
-func generateKey(key []byte) (genKey []byte) {
-	genKey = make([]byte, 16)
-	copy(genKey, key)
-	for i := 16; i < len(key); {
-		for j := 0; j < 16 && i < len(key); j, i = j+1, i+1 {
-			genKey[j] ^= key[i]
-		}
-	}
-	return genKey
-}

+ 5 - 0
src/web/templates/index.html

@@ -245,6 +245,11 @@ $(function(){
 					});
 					$(cell).on("blur", ":input", function () {
 						var text = $(this).find("option:selected").text();
+						if (text == "紧急"){
+							text = 1;
+						}else {
+							text = 0;
+						}
 						ttable.cell(cell).data(text);
 						cellData = text;
 					});