This commit is contained in:
cdle
2023-07-08 12:57:11 +08:00
parent 4bf46badb4
commit 87e6f98876
11 changed files with 133 additions and 71 deletions
+1 -1
View File
@@ -683,7 +683,7 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
if one != nil {
message_id := ""
one.Handle(&Faker{
Type: "*",
Type: "message",
}, func(vm *goja.Runtime) {
obj := vm.NewObject()
for k, v := range msg {
+19
View File
@@ -199,3 +199,22 @@ func SetBucketKeyValue(bucket storage.Bucket, key interface{}, value interface{}
}
return bucket.Set(key, new)
}
func SetBucketKeyValue2(bucket storage.Bucket, key interface{}, value interface{}) (string, error) {
new := ""
switch value := value.(type) {
case int, int64, int32, uint:
new = fmt.Sprintf("d:%d", value)
case float32, float64:
new = fmt.Sprintf("f:%f", value)
case string, []byte:
new = fmt.Sprintf("%s", value)
case bool:
new = fmt.Sprintf("b:%t", value)
case nil:
new = ""
default:
new = fmt.Sprintf("o:%s", utils.JsonMarshal(value))
}
return bucket.Set2(key, new)
}
+4
View File
@@ -21,6 +21,10 @@ func init() {
{
Admin: true,
Rules: []string{"identify sublink [地址] [组织]"},
ImType: &common.Filter{
BlackMode: true,
Items: []string{"pgm"},
},
Handle: func(s common.Sender, _ func(vm *goja.Runtime)) interface{} {
address := s.Get(0)
organization := s.Get(1)
+3 -2
View File
@@ -130,7 +130,9 @@ func Init() {
Message: fmt.Sprintf("当前版本 %s 已是最新,无需升级", compiled_at),
}
}
client = &http.Client{}
client = &http.Client{
Timeout: 30 * time.Second,
}
if transport != nil {
client.Transport = transport
}
@@ -151,7 +153,6 @@ func Init() {
defer resp.Body.Close()
body = resp.Body
goto CREATE
PROXY:
//使用免费代理下载
proxy = true
+26
View File
@@ -25,6 +25,13 @@ func MakeBucketObject(vm *goja.Runtime, uuid string, on_start bool, bucket stora
}
return msg
})
obj.Set("set2", func(key, value interface{}) interface{} {
msg, err := SetBucketKeyValue2(bucket, key, value)
if err != nil {
panic(Error(vm, err))
}
return msg
})
obj.Set("delete", func(key interface{}) error {
_, err := bucket.Set(key, "")
return err
@@ -94,3 +101,22 @@ func JsBucket(vm *goja.Runtime, name string, uuid string, on_start bool) goja.Pr
},
})
}
func JsBucket2(vm *goja.Runtime, name string, uuid string, on_start bool) goja.Proxy {
return vm.NewProxy(MakeBucketObject(vm, uuid, on_start, MakeBucket(name)), &goja.ProxyTrapConfig{
Get: func(target *goja.Object, property string, receiver goja.Value) (value goja.Value) {
obj := target.Get(property)
if obj != nil {
return obj
}
result := target.Get("get").Export().(func(...interface{}) interface{})(property)
return vm.ToValue(result)
},
Set: func(target *goja.Object, property string, value, receiver goja.Value) (success bool) {
target.Get("set2").Export().(func(interface{}, interface{}) interface{})(
property, value.Export(),
)
return true
},
})
}
+2 -3
View File
@@ -114,7 +114,8 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
return JsBucket(vm, name, uuid, on_start)
})
registry := require.NewRegistry(require.WithLoader(mapFileSystemSourceLoader(uuid)))
registry.RegisterNativeModule("crypto", cryptoModule)
registry.RegisterNativeModule("buffer", bufferModule)
if on_start {
var ids = &[]cron.EntryID{}
crons.Store(uuid, ids)
@@ -157,8 +158,6 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
return o
})
registry.RegisterNativeModule("crypto", cryptoModule)
registry.RegisterNativeModule("buffer", bufferModule)
vm.Set("gofor", func(running func() bool, handle func()) {
go func() {
for {
+63 -48
View File
@@ -5,10 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"reflect"
"strings"
"sync"
"time"
"github.com/Dreamacro/clash/adapter"
C "github.com/Dreamacro/clash/constant"
@@ -21,6 +23,7 @@ import (
// }
type ProxyConfig struct {
ID string `json:"id"`
Type string `json:"type"`
Server string `json:"server"`
Port int `json:"port"`
@@ -47,7 +50,7 @@ type ProxyConfig struct {
// Enable bool `json:"enable,omitempty"`
// ExcludeIPs []string `json:"exclude-ip,omitempty"`
// ProxyGroups []string `json:"proxy-groups,omitempty"`
Google []int `json:"google"`
}
var Proxies sync.Map
@@ -124,6 +127,7 @@ func GetProxyTransport(rawURL string, uuid string, params map[string]interface{}
func init() {
proxies.Foreach(func(b1, b2 []byte) error {
key := string(b1)
new := string(b2)
var ncfg = ProxyConfig{}
var params = map[string]interface{}{}
@@ -144,7 +148,7 @@ func init() {
// fmt.Println("===", string(utils.JsonMarshal(ncfg)))
// fmt.Println(ncfg.RuleMatcher.Match("106.52.87.206"))
// fmt.Println(ncfg.RuleMatcher.Match("api.telegram.org"))
Proxies.Store(string(b1), &ncfg)
Proxies.Store(key, &ncfg)
}
return nil
})
@@ -215,49 +219,60 @@ func init() {
})
}
func structToMap(s interface{}) map[string]interface{} {
result := make(map[string]interface{})
d, _ := json.Marshal(s)
json.Unmarshal(d, &result)
return result
}
func IsDifferent(a, b interface{}, ignoreFields []string) bool {
aVal := reflect.ValueOf(a)
bVal := reflect.ValueOf(b)
if aVal.Kind() != reflect.Struct || bVal.Kind() != reflect.Struct {
// 如果不是 struct 类型,则返回 true(不同)
return true
}
// 获取 struct 的字段数
numFields := aVal.NumField()
// 遍历 struct 的所有字段,检查是否有不同
for i := 0; i < numFields; i++ {
aField := aVal.Field(i)
bField := bVal.Field(i)
// 获取字段名
fieldName := aVal.Type().Field(i).Name
// 如果字段名在 ignoreFields 中,则跳过比较
if Contains(ignoreFields, fieldName) {
continue
}
// 如果字段类型不同,则返回 true(不同)
if aField.Type() != bField.Type() {
return true
}
// 如果字段值不同,则返回 true(不同)
if !reflect.DeepEqual(aField.Interface(), bField.Interface()) {
return true
}
}
// 如果所有字段都相同,则返回 false(相同)
return false
func checkProxy() {
proxies.Foreach(func(b1, b2 []byte) error {
go func(b1, b2 []byte) {
key := string(b1)
new := string(b2)
var ncfg = ProxyConfig{}
var params = map[string]interface{}{}
if strings.HasPrefix(new, "o:") {
var data = []byte(strings.Replace(new, "o:", "", 1))
err := json.Unmarshal(data, &ncfg)
json.Unmarshal(data, &params)
if err != nil {
return
}
var check = map[string]int64{}
for _, site := range []string{"https://google.com", "https://github.com"} {
func(site string) {
instance, err := GetProxyTransport(site, "", params)
if err != nil {
return
}
defer instance.Close()
var client = &http.Client{
Transport: &http.Transport{
Dial: func(string, string) (net.Conn, error) {
return instance, nil
},
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}
req, err := http.NewRequest("GET", site, strings.NewReader(""))
if err != nil {
return
}
startTime := time.Now().UnixMilli()
resp, err := client.Do(req)
if err != nil {
return
}
endTime := time.Now().UnixMilli()
resp.Body.Close()
spend := endTime - startTime
check[site] = spend
console.Log(site, "resp.StatusCode", resp.StatusCode, "time", spend)
}(site)
}
params["check"] = check
proxies.Set2(key, "o:"+string(utils.JsonMarshal(params)))
}
}(b1, b2)
return nil
})
}
+5 -1
View File
@@ -244,6 +244,7 @@ func parseReply2(str string) string {
})
}
// rule 专用
func parseReply3(str string, f func(string, string)) string {
ks := map[string]bool{}
re := regexp.MustCompile(`\$\{\s*([^{}]+)\s*\}`)
@@ -259,8 +260,11 @@ func parseReply3(str string, f func(string, string)) string {
return fmt.Sprintf(`Bucket("%s")["%s"]`, parts[0], parts[1])
})
vm := goja.New()
// vm.Set("Bucket", func(name string) interface{} {
// return JsBucket(vm, name, "", false)
// })
vm.Set("Bucket", func(name string) interface{} {
return JsBucket(vm, name, "", false)
return JsBucket2(vm, name, "", false)
})
v, err := vm.RunString(script)
if err == nil {
+1 -1
View File
@@ -141,7 +141,7 @@ func initWeb() {
if c.Request.URL.Path == path && c.Request.Method == method {
req.handled = true
function.Handle(&Faker{
Type: "*",
Type: "http",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("req", req)
+3 -3
View File
@@ -36,7 +36,7 @@ func handleWebsocket(c *gin.Context) {
}
req._event = "connect"
function.Handle(&Faker{
Type: "*",
Type: "websocket",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("req", req)
@@ -63,7 +63,7 @@ func handleWebsocket(c *gin.Context) {
}
}
function.Handle(&Faker{
Type: "*",
Type: "websocket",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("req", req)
@@ -79,7 +79,7 @@ func handleWebsocket(c *gin.Context) {
}
}
function.Handle(&Faker{
Type: "*",
Type: "websocket",
}, func(vm *goja.Runtime) {
vm.Set("res", res)
vm.Set("req", req)
+6 -12
View File
@@ -1,4 +1,4 @@
n="sillyplus"
n="sillyGirl"
s="/usr/local/$n"
a=arm64
if [[ $(uname -a | grep "x86_64") != "" ]]; then
@@ -9,21 +9,15 @@ if [ ! -d $s ]; then
fi ;
cd $s;
rm -rf $n;
v=`curl https://gitlab.com/cdle/$a/-/raw/main/compile_time.go --silent | tr -cd "[0-9]"`
d=""
v=`curl https://raw.githubusercontent.com/cdle/binary/main/compile_time.go --silent | tr -cd "[0-9]"`
if [ ${#v} == 13 ]; then
d="https://gitlab.com/cdle/${a}/-/raw/main/sillyplus_linux_${a}_${v}"
d="https://raw.githubusercontent.com/cdle/binary/main/sillyGirl_linux_${a}_${v}"
else
v=`curl https://raw.githubusercontent.com/cdle/binary/main/compile_time.go --silent | tr -cd "[0-9]"`
if [ ${#v} == 13 ]; then
d="https://raw.githubusercontent.com/cdle/binary/main/sillyplus_linux_${a}_${v}"
else
echo "Sorry,你网不好!"
exit
fi
echo "Sorry,你网不好,请使用其他方式下载!"
exit
fi
echo "检测到版本 $v"
echo "正在从 $d 下载..."
curl -o $n $d && chmod 777 $n
echo "傻妞已安装到 $s"
echo "请手动运行 $s/$n -t"
echo "请手动运行 $s/$n 带 -t 进入交互模式"