diff --git a/core/plugin_core.go b/core/plugin_core.go index 3c09264..5a59eb8 100644 --- a/core/plugin_core.go +++ b/core/plugin_core.go @@ -535,12 +535,12 @@ func initPlugin(data string, uuid string) (*common.Function, []func(), error) { return false }) vm.Set("s", ss) - vm.Set("InitAdapter", func(plt, botid string) *Factory { + vm.Set("InitAdapter", func(plt, botid string, params map[string]interface{}) *Factory { f := &Factory{ uuid: uuid, vm: vm, } - f.Init(plt, botid, nil) + f.Init(plt, botid, params) return f }) vm.Set("initAdapter", func(plt, botid string) *Factory { diff --git a/core/web.go b/core/web.go index 8c9fee1..1ec3726 100644 --- a/core/web.go +++ b/core/web.go @@ -360,10 +360,15 @@ func initWeb() { }) // logs.Info("Http服务(%s)开始运行", port) + logs.Info("管理员面板:") - logs.Info(" > 本机: http://localhost:%s", port) + logs.Info(" > 本机: http://localhost:%s/admin", port) local_ip := getLocalIP() - logs.Info(" > 局域网: http://%s:%s", local_ip, port) + logs.Info(" > 局域网: http://%s:%s/admin", local_ip, port) + ip := sillyGirl.GetString("ip") + if ip != "" { + logs.Info(" > 广域网: http://%s:%s/admin", ip, port) + } sillyGirl.Set("local_ip", local_ip) go func() { if err := srvs[0].ListenAndServe(); err != nil && err != http.ErrServerClosed { diff --git a/main.go b/main.go index 9064449..d655e69 100644 --- a/main.go +++ b/main.go @@ -15,11 +15,17 @@ import ( "github.com/cdle/sillyplus/utils" ) -var sillyplus = core.MakeBucket("sillyplus") +var app = core.MakeBucket("app") func main() { + go func() { + ip, err := utils.GetPublicIP() + if err == nil { + app.Set("ip", ip) + } + }() core.Init() - if sillyplus.GetBool("anti_kasi") { + if app.GetBool("anti_kasi") { go utils.MonitorGoroutine() } d := false diff --git a/utils/init.go b/utils/init.go index db490b0..6995257 100644 --- a/utils/init.go +++ b/utils/init.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "os" "os/exec" "path/filepath" @@ -444,3 +445,35 @@ func Itoa(i interface{}) string { return fmt.Sprint(i) } } + +func GetPublicIP() (string, error) { + var ip string + + // 使用 ipapi.co 获取公网IP地址 + resp, err := http.Get("https://ipapi.co/ip/") + if err == nil { + defer resp.Body.Close() + ipBytes, err := ioutil.ReadAll(resp.Body) + if err == nil { + ip = string(ipBytes) + } + } + + // 使用 ifconfig.co 获取公网IP地址 + if ip == "" { + resp, err = http.Get("https://ifconfig.co/ip") + if err == nil { + defer resp.Body.Close() + ipBytes, err := ioutil.ReadAll(resp.Body) + if err == nil { + ip = string(ipBytes) + } + } + } + + if ip == "" { + return "", fmt.Errorf("获取IP地址失败") + } + + return ip, nil +}