x
This commit is contained in:
@@ -0,0 +1,131 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"hash"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Crypto struct{}
|
||||||
|
|
||||||
|
type Hmac struct {
|
||||||
|
Algorithm string
|
||||||
|
hash hash.Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Hmac) Digest(class string) string {
|
||||||
|
value := h.hash.Sum(nil)
|
||||||
|
switch class {
|
||||||
|
case "hex":
|
||||||
|
return fmt.Sprintf("%x", value)
|
||||||
|
case "base64":
|
||||||
|
return base64.StdEncoding.EncodeToString(value)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Hmac) Update(data string) {
|
||||||
|
h.hash.Write([]byte(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Crypto) CreateHmac(algorithm, key string) *Hmac {
|
||||||
|
var hashFunc func() hash.Hash
|
||||||
|
switch algorithm {
|
||||||
|
case "md5":
|
||||||
|
hashFunc = md5.New
|
||||||
|
case "sha1":
|
||||||
|
hashFunc = sha1.New
|
||||||
|
case "sha256":
|
||||||
|
hashFunc = sha256.New
|
||||||
|
case "sha512":
|
||||||
|
hashFunc = sha512.New
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &Hmac{
|
||||||
|
hash: hmac.New(hashFunc, []byte(key)),
|
||||||
|
Algorithm: algorithm,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// func (c *Crypto) CreateCipheriv(algorithm, key, data string) *Hmac {
|
||||||
|
// switch algorithm {
|
||||||
|
// case "aes-256-cbc":
|
||||||
|
// block, err := aes.NewCipher([]byte(key))
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// ciphertext := make([]byte, aes.BlockSize+len(data))
|
||||||
|
// iv := ciphertext[:aes.BlockSize]
|
||||||
|
// if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// stream := cipher.NewCFBEncrypter(block, iv)
|
||||||
|
// stream.XORKeyStream(ciphertext[aes.BlockSize:], []byte(data))
|
||||||
|
// return base64.StdEncoding.EncodeToString(ciphertext), nil
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type Cipher struct{}
|
||||||
|
|
||||||
|
// func (c *Cipher) AesEncrypt(key, data string) (string, error) {
|
||||||
|
// block, err := aes.NewCipher([]byte(key))
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// ciphertext := make([]byte, aes.BlockSize+len(data))
|
||||||
|
// iv := ciphertext[:aes.BlockSize]
|
||||||
|
// if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// stream := cipher.NewCFBEncrypter(block, iv)
|
||||||
|
// stream.XORKeyStream(ciphertext[aes.BlockSize:], []byte(data))
|
||||||
|
// return base64.StdEncoding.EncodeToString(ciphertext), nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (c *Cipher) AesDecrypt(key, ciphertext string) (string, error) {
|
||||||
|
// block, err := aes.NewCipher([]byte(key))
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// data, err := base64.StdEncoding.DecodeString(ciphertext)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// if len(data) < aes.BlockSize {
|
||||||
|
// return "", fmt.Errorf("ciphertext too short")
|
||||||
|
// }
|
||||||
|
// iv := data[:aes.BlockSize]
|
||||||
|
// data = data[aes.BlockSize:]
|
||||||
|
// stream := cipher.NewCFBDecrypter(block, iv)
|
||||||
|
// stream.XORKeyStream(data, data)
|
||||||
|
// return string(data), nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (c *Cipher) Rc4Encrypt(key, data string) (string, error) {
|
||||||
|
// cipher, err := rc4.NewCipher([]byte(key))
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// ciphertext := make([]byte, len(data))
|
||||||
|
// cipher.XORKeyStream(ciphertext, []byte(data))
|
||||||
|
// return base64.StdEncoding.EncodeToString(ciphertext), nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (c *Cipher) Rc4Decrypt(key, ciphertext string) (string, error) {
|
||||||
|
// cipher, err := rc4.NewCipher([]byte(key))
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// data, err := base64.StdEncoding.DecodeString(ciphertext)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// cipher.XORKeyStream(data, data)
|
||||||
|
// return string(data), nil
|
||||||
|
// }
|
||||||
+1
-1
@@ -584,7 +584,7 @@ func initPlugin(data string, uuid string) (*common.Function, []func(), error) {
|
|||||||
}
|
}
|
||||||
_, err := vm.RunProgram(prg)
|
_, err := vm.RunProgram(prg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Error(strings.ReplaceAll(strings.ReplaceAll(err.Error(), "node_modules/", ""), "github.com/dop251/goja_nodejs/require", ""))
|
pluginConsole(uuid).Error(strings.ReplaceAll(strings.ReplaceAll(err.Error(), "node_modules/", ""), "github.com/dop251/goja_nodejs/require", ""))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package core
|
|
||||||
|
|
||||||
import "regexp"
|
|
||||||
|
|
||||||
func getPaterner(uuid, path string) {
|
|
||||||
var ss = regexp.MustCompile(`\S+`).FindAllString(path, -1)
|
|
||||||
path = ss[0]
|
|
||||||
var data []byte
|
|
||||||
var address = ""
|
|
||||||
ls := plugin_list
|
|
||||||
for _, f := range ls {
|
|
||||||
if f.UUID == uuid {
|
|
||||||
address = f.Address
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if address != "" {
|
|
||||||
for _, f := range ls {
|
|
||||||
if f.Address == address && (f.Title == path || f.UUID == path) {
|
|
||||||
data = plugins.GetBytes(f.UUID)
|
|
||||||
if data != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if data == nil {
|
|
||||||
for _, l := range ls {
|
|
||||||
if l.Address == address && (l.Title == path || l.UUID == path) {
|
|
||||||
data = fetchScript(l.Address, l.UUID)
|
|
||||||
if data == nil {
|
|
||||||
console.Warn("无法从订阅源获取 %s 的协作脚本 %s ", GetScriptNameByUUID(uuid), path)
|
|
||||||
} else {
|
|
||||||
console.Log("已从订阅源获取 %s 的协作脚本 %s", GetScriptNameByUUID(uuid), path)
|
|
||||||
plugins.Set(l.UUID, string(data))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if data == nil {
|
|
||||||
console.Warn("找不到 %s 的协作脚本 %s", GetScriptNameByUUID(uuid), path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import "regexp"
|
||||||
|
|
||||||
|
func getPaterner(uuid, path string) (string, string, bool) {
|
||||||
|
var ss = regexp.MustCompile(`\S+`).FindAllString(path, -1)
|
||||||
|
path = ss[0]
|
||||||
|
var data []byte
|
||||||
|
var address = ""
|
||||||
|
ls := plugin_list
|
||||||
|
for _, f := range ls {
|
||||||
|
if f.UUID == uuid {
|
||||||
|
address = f.Address
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range ls { //同源
|
||||||
|
if f.Address == address && (f.Title == path || f.UUID == path) {
|
||||||
|
data = plugins.GetBytes(f.UUID)
|
||||||
|
if data != nil {
|
||||||
|
return string(data), f.UUID, true //本地取
|
||||||
|
}
|
||||||
|
data = fetchScript(f.Address, f.UUID)
|
||||||
|
if data == nil {
|
||||||
|
console.Warn("无法从订阅源获取 %s 的协作脚本 %s ", GetScriptNameByUUID(uuid), path)
|
||||||
|
return "", f.UUID, false
|
||||||
|
} else {
|
||||||
|
console.Log("已从订阅源获取 %s 的协作脚本 %s", GetScriptNameByUUID(uuid), path)
|
||||||
|
plugins.Set(f.UUID, string(data))
|
||||||
|
return string(data), f.UUID, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range ls { //异源
|
||||||
|
if f.Address != address && (f.Title == path || f.UUID == path) {
|
||||||
|
data = plugins.GetBytes(f.UUID)
|
||||||
|
if data != nil {
|
||||||
|
return string(data), f.UUID, true //本地取
|
||||||
|
}
|
||||||
|
data = fetchScript(f.Address, f.UUID)
|
||||||
|
if data == nil {
|
||||||
|
console.Warn("无法从订阅源获取 %s 的协作脚本 %s ", GetScriptNameByUUID(uuid), path)
|
||||||
|
return "", f.UUID, false
|
||||||
|
} else {
|
||||||
|
console.Log("已从订阅源获取 %s 的协作脚本 %s", GetScriptNameByUUID(uuid), path)
|
||||||
|
plugins.Set(f.UUID, string(data))
|
||||||
|
return string(data), f.UUID, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", "", false
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ type RequestPluginResult struct {
|
|||||||
|
|
||||||
var plugin_list = []*common.Function{}
|
var plugin_list = []*common.Function{}
|
||||||
|
|
||||||
var cdle_sublink = "link://T4EywWN46ztYBhHNdOl6Tpz8QQsCZGj8JvdRJ5QKatJm0P+mI/G3ruO7AC04guqqKKa29VOvTGR7ATUJGYayRBpG2RFq+6ZPK3vcu6KCDGvRE3S43Gj42EXfvs04M6s4\nlink://T4EywWN46ztYBhHNdOl6Tpz8QQsCZGj8JvdRJ5QKatJYds3a/BticqD0hzidGsOysEx/RK/nKppChxMLb6QGczhWjGC/M2ETxWb+Jl+6q/x+LP4gy+ibeAEzatOYwdZMckI8nN/R6mY/HW2dyBtp0qH1ldICn6Wl+9YowLvvpLU="
|
var cdle_sublink = "link://T4EywWN46ztYBhHNdOl6Tpz8QQsCZGj8JvdRJ5QKatJm0P+mI/G3ruO7AC04guqqKKa29VOvTGR7ATUJGYayRBpG2RFq+6ZPK3vcu6KCDGvRE3S43Gj42EXfvs04M6s4\nlink://T4EywWN46ztYBhHNdOl6Tpz8QQsCZGj8JvdRJ5QKatJYds3a/BticqD0hzidGsOysEx/RK/nKppChxMLb6QGczhWjGC/M2ETxWb+Jl+6q/x+LP4gy+ibeAEzatOYwdZMckI8nN/R6mY/HW2dyBtp0qH1ldICn6Wl+9YowLvvpLU=\nlink://T4EywWN46ztYBhHNdOl6Tpz8QQsCZGj8JvdRJ5QKatL/GWakSkUWVNTd/jJS4YaqGXqvoJOxtEwVxbfBpmsMdTpKFr7K/+9MW/CJFpFsLFGM3yRxh2z8fVsDZUV6GoXei5QhOviIvo5ys7N5b6MRiEmbVATiiTEovz3IBg8nObQ="
|
||||||
|
|
||||||
func initPluginList() {
|
func initPluginList() {
|
||||||
list := []*common.Function{}
|
list := []*common.Function{}
|
||||||
|
|||||||
+10
-7
@@ -432,15 +432,18 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
|
|||||||
})
|
})
|
||||||
vm.Set("importJs", func(file string) error {
|
vm.Set("importJs", func(file string) error {
|
||||||
file = strings.Replace(file, ".js", "", -1)
|
file = strings.Replace(file, ".js", "", -1)
|
||||||
for _, f := range Functions {
|
s, id, ok := getPaterner(uuid, file)
|
||||||
if f.Title == file {
|
if !ok {
|
||||||
vm.RunString(plugins.GetString(f.UUID))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pluginConsole(uuid).Error("无法通过importJs导入" + file + ".js")
|
|
||||||
panic(Error(vm, "无法通过importJs导入"+file))
|
panic(Error(vm, "无法通过importJs导入"+file))
|
||||||
|
}
|
||||||
|
_, err := vm.RunString(s)
|
||||||
|
if err != nil {
|
||||||
|
pluginConsole(id).Error(err)
|
||||||
|
panic(Error(vm, "通过importJs导入"+file+"错误:"+err.Error()))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
|
vm.Set("crypto", &Crypto{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncryptPlugin(script string) string {
|
func EncryptPlugin(script string) string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -459,6 +460,10 @@ func GetPublicIP() (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !IsIPv4(ip) {
|
||||||
|
ip = ""
|
||||||
|
}
|
||||||
|
|
||||||
// 使用 ifconfig.co 获取公网IP地址
|
// 使用 ifconfig.co 获取公网IP地址
|
||||||
if ip == "" {
|
if ip == "" {
|
||||||
resp, err = http.Get("https://ifconfig.co/ip")
|
resp, err = http.Get("https://ifconfig.co/ip")
|
||||||
@@ -475,5 +480,14 @@ func GetPublicIP() (string, error) {
|
|||||||
return "", fmt.Errorf("获取IP地址失败")
|
return "", fmt.Errorf("获取IP地址失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !IsIPv4(ip) {
|
||||||
|
return "", fmt.Errorf("获取IP地址失败")
|
||||||
|
}
|
||||||
|
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsIPv4(ip string) bool {
|
||||||
|
parsedIP := net.ParseIP(ip)
|
||||||
|
return parsedIP != nil && parsedIP.To4() != nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user