MCPcopy
hub / github.com/IceWhaleTech/CasaOS / GetDeviceInfo

Method GetDeviceInfo

service/system.go:72–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70type systemService struct{}
71
72func (c *systemService) GetDeviceInfo() model.DeviceInfo {
73 m := model.DeviceInfo{}
74 m.OS_Version = common.VERSION
75 err, portStr := MyService.Gateway().GetPort()
76 if err != nil {
77 m.Port = 80
78 } else {
79 port := gjson.Get(portStr, "data")
80 if len(port.Raw) == 0 {
81 m.Port = 80
82 } else {
83 p, err := strconv.Atoi(port.Raw)
84 if err != nil {
85 m.Port = 80
86 } else {
87 m.Port = p
88 }
89 }
90 }
91 allIpv4 := ip_helper.GetDeviceAllIPv4()
92 ip := []string{}
93 nets := MyService.System().GetNet(true)
94 for _, n := range nets {
95 if v, ok := allIpv4[n]; ok {
96 {
97 ip = append(ip, v)
98 }
99 }
100 }
101
102 m.LanIpv4 = ip
103 h, err := host.Info() /* */
104 if err == nil {
105 m.DeviceName = h.Hostname
106 }
107 mb := model.BaseInfo{}
108
109 err = json.Unmarshal(file.ReadFullFile(config.AppInfo.DBPath+"/baseinfo.conf"), &mb)
110 if err == nil {
111 m.Hash = mb.Hash
112 }
113
114 osRelease, _ := file.ReadOSRelease()
115 m.DeviceModel = osRelease["MODEL"]
116 m.DeviceSN = osRelease["SN"]
117 res := httper.Get("http://127.0.0.1:"+strconv.Itoa(m.Port)+"/v1/users/status", nil)
118 init := gjson.Get(res, "data.initialized")
119 m.Initialized, _ = strconv.ParseBool(init.Raw)
120
121 return m
122}
123
124func (c *systemService) GenreateSystemEntry() {
125 modelsPath := "/var/lib/casaos/www/modules"

Callers

nothing calls this directly

Calls 6

GetDeviceAllIPv4Function · 0.92
GetFunction · 0.92
InfoMethod · 0.80
GatewayMethod · 0.65
GetNetMethod · 0.65
SystemMethod · 0.65

Tested by

no test coverage detected