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