From 09a7466b00c11cb836a648c3b825d4abaf51eda1 Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Fri, 29 Oct 2021 08:55:20 +0800 Subject: [PATCH] update --- core/otto.go | 18 +++++++++++++----- go.mod | 1 + go.sum | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/otto.go b/core/otto.go index b4acbe6..0785274 100644 --- a/core/otto.go +++ b/core/otto.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "log" "os" "regexp" "strings" @@ -12,6 +13,7 @@ import ( "github.com/beego/beego/v2/adapter/httplib" "github.com/beego/beego/v2/adapter/logs" + "github.com/denisbrodbeck/machineid" "github.com/robertkrimen/otto" ) @@ -35,12 +37,18 @@ func init() { var OttoFuncs = map[string]func(string) string{ "machineId": func(_ string) string { - data, _ := os.ReadFile("/var/lib/dbus/machine-id") - id := regexp.MustCompile(`\w+`).FindString(string(data)) - if id == "" { - data, _ = os.ReadFile("/etc/machine-id") - id = regexp.MustCompile(`\w+`).FindString(string(data)) + // data, _ := os.ReadFile("/var/lib/dbus/machine-id") + // id := regexp.MustCompile(`\w+`).FindString(string(data)) + // if id == "" { + // data, _ = os.ReadFile("/etc/machine-id") + // id = regexp.MustCompile(`\w+`).FindString(string(data)) + // } + id, err := machineid.ProtectedID("sillyGirl") + if err != nil { + log.Fatal(err) } + fmt.Println(id) + return id }, "uuid": func(_ string) string { diff --git a/go.mod b/go.mod index 912fa1c..38a486f 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/beego/beego/v2 v2.0.1 github.com/boltdb/bolt v1.3.1 github.com/buger/jsonparser v1.1.1 + github.com/denisbrodbeck/machineid v1.0.1 github.com/gin-gonic/gin v1.7.0 github.com/google/uuid v1.1.1 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 577a246..81d07cd 100644 --- a/go.sum +++ b/go.sum @@ -54,6 +54,8 @@ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGii github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=