Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket update #1159

Merged
merged 5 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func init() {

route.InitFunction()
go SendToSocket(service.MyService.System().GetDeviceInfo())
service.MyService.System().GenreateSystemEntry()
//service.MyService.System().GenreateSystemEntry()
///
//service.MountLists = make(map[string]*mountlib.MountPoint)
//configfile.Install()
Expand Down Expand Up @@ -260,14 +260,14 @@ func Special(myservice service.Repository) {

func SendToSocket(m model2.DeviceInfo) {
if len(m.DeviceSN) == 0 {
//TODO:需要更换socket地址,需要放开sn的判断
//TODO:需要放开sn的判断
//return
}
by, _ := json.Marshal(m)
base64Str := base64.StdEncoding.EncodeToString(by)
var count int = 1
for i := 0; i < 10; i++ {
wsURL := fmt.Sprintf("ws://%s/server/zima%s", "52.193.63.104:3060", "?device="+base64Str)
wsURL := fmt.Sprintf("wss://%s/server/zima%s", "www.findzima.com/ws", "?device="+base64Str)
ws, err := websocket.Dial(wsURL, "", "http://localhost")
if err != nil {
logger.Error("connect websocket err"+strconv.Itoa(i), zap.Any("error", err))
Expand Down
4 changes: 2 additions & 2 deletions route/v2/zerotier.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *CasaOS) SetZerotierNetworkStatus(ctx echo.Context, networkId string) er
ctx.Bind(&m)
status := m["status"]
if status == "online" {
ip = `,"via":""`
ip = ``
}
body := `{
"routes": [
Expand Down Expand Up @@ -62,7 +62,7 @@ func (s *CasaOS) GetZerotierInfo(ctx echo.Context) error {
via := gjson.GetBytes(res, "routes.0.via").Str
info.Id = utils.Ptr(gjson.GetBytes(res, "id").Str)
info.Name = &name
if len(via) != 0 {
if len(via) == 0 {
info.Status = utils.Ptr("online")
} else {
info.Status = utils.Ptr("offline")
Expand Down
25 changes: 19 additions & 6 deletions service/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,30 @@ func (c *systemService) GenreateSystemEntry() {

}
func (c *systemService) GetSystemEntry() string {
entryFilePath := filepath.Join(config.AppInfo.DBPath, "db", "entry.json")
_, err := os.Open(entryFilePath)
if os.IsNotExist(err) {

modelsPath := "/var/lib/casaos/www/modules"
entryFileName := "entry.json"
dir, err := os.ReadDir(modelsPath)
if err != nil {
logger.Error("read dir error", zap.Error(err))
return ""
}
by, err := os.ReadFile(entryFilePath)
json := "["
for _, v := range dir {
data, err := os.ReadFile(filepath.Join(modelsPath, v.Name(), entryFileName))
if err != nil {
logger.Error("read entry file error", zap.Error(err))
continue
}
json += string(data) + ","
}
json = strings.TrimRight(json, ",")
json += "]"
if err != nil {
logger.Error("read entry file error", zap.Error(err))
logger.Error("write entry file error", zap.Error(err))
return ""
}
return string(by)
return json
}
func (c *systemService) GetMacAddress() (string, error) {
interfaces, err := net.Interfaces()
Expand Down