system.info.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package main
  2. import (
  3. "encoding/json"
  4. "log"
  5. "net/http"
  6. "runtime"
  7. "time"
  8. info "imuslab.com/arozos/mod/info/hardwareinfo"
  9. usage "imuslab.com/arozos/mod/info/usageinfo"
  10. prout "imuslab.com/arozos/mod/prouter"
  11. )
  12. //InitShowSysInformation xxx
  13. func SystemInfoInit() {
  14. log.Println("Operation System: " + runtime.GOOS)
  15. log.Println("System Architecture: " + runtime.GOARCH)
  16. if *allow_hardware_management {
  17. //Updates 5 Dec 2020, Added permission router
  18. router := prout.NewModuleRouter(prout.RouterOption{
  19. AdminOnly: false,
  20. UserHandler: userHandler,
  21. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  22. sendErrorResponse(w, "Permission Denied")
  23. },
  24. })
  25. //Create Info Server Object
  26. infoServer := info.NewInfoServer(info.ArOZInfo{
  27. BuildVersion: build_version + "." + internal_version,
  28. DeviceVendor: deviceVendor,
  29. DeviceModel: deviceModel,
  30. VendorIcon: "../../" + iconVendor,
  31. SN: deviceUUID,
  32. HostOS: runtime.GOOS,
  33. CPUArch: runtime.GOARCH,
  34. HostName: *host_name,
  35. })
  36. router.HandleFunc("/system/info/getCPUinfo", info.GetCPUInfo)
  37. router.HandleFunc("/system/info/ifconfig", info.Ifconfig)
  38. router.HandleFunc("/system/info/getDriveStat", info.GetDriveStat)
  39. router.HandleFunc("/system/info/usbPorts", info.GetUSB)
  40. router.HandleFunc("/system/info/getRAMinfo", info.GetRamInfo)
  41. router.HandleFunc("/system/info/getRuntimeInfo", InfoHandleGetRuntimeInfo)
  42. //ArOZ Info do not need permission router
  43. http.HandleFunc("/system/info/getArOZInfo", infoServer.GetArOZInfo)
  44. //Register as a system setting
  45. registerSetting(settingModule{
  46. Name: "Host Info",
  47. Desc: "System Information",
  48. IconPath: "SystemAO/info/img/small_icon.png",
  49. Group: "Info",
  50. StartDir: "SystemAO/info/index.html",
  51. })
  52. /*
  53. CPU and RAM usage interface
  54. */
  55. registerSetting(settingModule{
  56. Name: "Performance",
  57. Desc: "System CPU and RAM usage",
  58. IconPath: "SystemAO/info/img/small_icon.png",
  59. Group: "Info",
  60. StartDir: "SystemAO/info/taskManagerFrame.html",
  61. })
  62. router.HandleFunc("/system/info/getUsageInfo", InfoHandleTaskInfo)
  63. }
  64. }
  65. func InfoHandleGetRuntimeInfo(w http.ResponseWriter, r *http.Request) {
  66. type RuntimeInfo struct {
  67. StartupTime int64
  68. ContinuesRuntime int64
  69. }
  70. runtimeInfo := RuntimeInfo{
  71. StartupTime: startupTime,
  72. ContinuesRuntime: time.Now().Unix() - startupTime,
  73. }
  74. js, _ := json.Marshal(runtimeInfo)
  75. sendJSONResponse(w, string(js))
  76. }
  77. func InfoHandleTaskInfo(w http.ResponseWriter, r *http.Request) {
  78. type UsageInfo struct {
  79. CPU float64
  80. UsedRAM string
  81. TotalRam string
  82. RamUsage float64
  83. }
  84. cpuUsage := usage.GetCPUUsage()
  85. usedRam, totalRam, usagePercentage := usage.GetRAMUsage()
  86. info := UsageInfo{
  87. cpuUsage,
  88. usedRam,
  89. totalRam,
  90. usagePercentage,
  91. }
  92. js, _ := json.Marshal(info)
  93. sendJSONResponse(w, string(js))
  94. }