|
@@ -38,7 +38,7 @@ const (
|
|
|
|
|
|
var TimeSleepChan = make(chan bool, 1)
|
|
|
|
|
|
-//脚本
|
|
|
+// 脚本
|
|
|
type Script struct {
|
|
|
SCode, ScriptFile string
|
|
|
Encoding string
|
|
@@ -57,7 +57,7 @@ type Script struct {
|
|
|
}
|
|
|
|
|
|
var ErrFid = "a6879f0a8570256aa21fb978e6dabb50429a30dfacff697cf0b898abbc5c262e" //限制访问的附件
|
|
|
-//加载文件
|
|
|
+// 加载文件
|
|
|
func (s *Script) LoadScript(site, channel, user *string, code, script_file string) string {
|
|
|
defer mu.Catch()
|
|
|
s.SCode = code
|
|
@@ -793,6 +793,32 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
S.Push(lua.LString(result))
|
|
|
return 1
|
|
|
}))
|
|
|
+ //aes cbc模式加密
|
|
|
+ s.L.SetGlobal("aesEncryptCBC", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-3)
|
|
|
+ key := S.ToString(-2)
|
|
|
+ iv := S.ToString(-1)
|
|
|
+ bytekey := []byte(key)
|
|
|
+ byteorigData := []byte(origData)
|
|
|
+ byteiv := []byte(iv)
|
|
|
+ encrypted := util.AesCBCEncrypt(byteorigData, bytekey, byteiv)
|
|
|
+ // 将加密后的数据和初始向量进行Base64编码
|
|
|
+ result := base64.StdEncoding.EncodeToString(encrypted)
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //aes cbc模式解密
|
|
|
+ s.L.SetGlobal("aesDecryptCBC", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-3)
|
|
|
+ key := S.ToString(-2)
|
|
|
+ iv := S.ToString(-1)
|
|
|
+ bytekey := []byte(key)
|
|
|
+ byteiv := []byte(iv)
|
|
|
+ data, _ := base64.StdEncoding.DecodeString(origData)
|
|
|
+ result := util.AesCBCDecrypter(data, bytekey, byteiv)
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
//aes ecb模式加密
|
|
|
s.L.SetGlobal("aesEncryptECB", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
origData := S.ToString(-2)
|
|
@@ -831,6 +857,31 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
S.Push(lua.LString(result))
|
|
|
return 1
|
|
|
}))
|
|
|
+ //des cbc模式加密
|
|
|
+ s.L.SetGlobal("desEncryptCBC", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-3)
|
|
|
+ key := S.ToString(-2)
|
|
|
+ iv := S.ToString(-1)
|
|
|
+ bytekey := []byte(key)
|
|
|
+ byteorigData := []byte(origData)
|
|
|
+ byteiv := []byte(iv)
|
|
|
+ encrypted := util.DesCBCEncrypt(byteorigData, bytekey, byteiv)
|
|
|
+ result := base64.StdEncoding.EncodeToString(encrypted)
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //des cbc模式解密
|
|
|
+ s.L.SetGlobal("desDecryptCBC", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-3)
|
|
|
+ key := S.ToString(-2)
|
|
|
+ iv := S.ToString(-1)
|
|
|
+ bytekey := []byte(key)
|
|
|
+ byteiv := []byte(iv)
|
|
|
+ data, _ := base64.StdEncoding.DecodeString(origData)
|
|
|
+ result := util.DesCBCDecrypter(data, bytekey, byteiv)
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
//rsa 公钥加密
|
|
|
s.L.SetGlobal("rsaEncrypt", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
origData := S.ToString(-2)
|
|
@@ -938,6 +989,7 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
head := S.ToTable(-2)
|
|
|
stype := S.ToString(-3)
|
|
|
path := S.ToString(-4)
|
|
|
+ proxy := S.ToBool(-5)
|
|
|
headMap := util.GetTable(head)
|
|
|
//qu.Debug("cookie----------", cookie)
|
|
|
//qu.Debug("headMap----------", headMap)
|
|
@@ -946,7 +998,7 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
if err == nil {
|
|
|
headJsonStr = string(headByte)
|
|
|
}
|
|
|
- code, respHead, respCookie := codegrpc.GetCodeByPath(path, stype, headJsonStr, cookie)
|
|
|
+ code, respHead, respCookie := codegrpc.GetCodeByPath(path, stype, headJsonStr, cookie, proxy)
|
|
|
//qu.Debug("code====", code)
|
|
|
//qu.Debug("respHead====", respHead)
|
|
|
//qu.Debug("respCookie====", respCookie)
|
|
@@ -1012,6 +1064,43 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
S.Push(lua.LString(contentHtml))
|
|
|
return 1
|
|
|
}))
|
|
|
+ //chromedp下载
|
|
|
+ s.L.SetGlobal("downloadByChrome", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ timeout := S.ToInt64(-2)
|
|
|
+ taskStr := S.ToString(-1)
|
|
|
+ cam := util.ChromeActionMap{}
|
|
|
+ if json.Unmarshal([]byte(taskStr), &cam) == nil {
|
|
|
+ if len(cam.BaseActions) > 0 {
|
|
|
+ if len(cam.RangeActions) > 0 && cam.RangeTimes > 0 {
|
|
|
+ for times := 1; times <= cam.RangeTimes; times++ {
|
|
|
+ cam.BaseActions = append(cam.BaseActions, cam.RangeActions...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ chromeTask := util.ChromeTask{
|
|
|
+ TimeOut: timeout,
|
|
|
+ Actions: cam.BaseActions,
|
|
|
+ }
|
|
|
+ ret := DownloadByChrome(s.SCode, s.Downloader, chromeTask, s.Timeout)
|
|
|
+ S.Push(util.MapToTable(S, ret))
|
|
|
+ } else {
|
|
|
+ S.Push(S.NewTable())
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ S.Push(S.NewTable())
|
|
|
+ }
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //针对中国招标投标公共服务平台三级页瑞数加密下载方法
|
|
|
+ s.L.SetGlobal("downloadByDataIntercept", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ url := S.ToString(-4)
|
|
|
+ url_regex := S.ToString(-3)
|
|
|
+ timeout := S.ToInt(-2)
|
|
|
+ proxy := S.ToBool(-1)
|
|
|
+ headers := util.DownloadByDataIntercept(url, url_regex, timeout, proxy)
|
|
|
+ table := util.MapToLuaTable(S, headers)
|
|
|
+ S.Push(table)
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
return ""
|
|
|
}
|
|
|
|
|
@@ -1058,7 +1147,7 @@ func getChildrenLen(sq *gq.Selection) (ret int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//unicode转码
|
|
|
+// unicode转码
|
|
|
func transUnic(str string) string {
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
i, j := 0, len(str)
|
|
@@ -1086,7 +1175,7 @@ func transUnic(str string) string {
|
|
|
return buf.String()
|
|
|
}
|
|
|
|
|
|
-//取得变量
|
|
|
+// 取得变量
|
|
|
func (s *Script) GetVar(key string) string {
|
|
|
return s.L.GetGlobal(key).String()
|
|
|
}
|
|
@@ -1107,7 +1196,7 @@ func (s *Script) GetBoolVar(key string) bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-//设置睡眠时间
|
|
|
+// 设置睡眠时间
|
|
|
func SleepTime(basetime int, times []time.Duration) {
|
|
|
st := 0 //记录最后睡眠时长
|
|
|
base := float64(basetime * 60)
|