system.info.go 3.2 KB

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