system.info.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. router.HandleFunc("/system/info/getCPUinfo", info.GetCPUInfo)
  36. router.HandleFunc("/system/info/ifconfig", info.Ifconfig)
  37. router.HandleFunc("/system/info/getDriveStat", info.GetDriveStat)
  38. router.HandleFunc("/system/info/usbPorts", info.GetUSB)
  39. router.HandleFunc("/system/info/getRAMinfo", info.GetRamInfo)
  40. //ArOZ Info do not need permission router
  41. http.HandleFunc("/system/info/getArOZInfo", infoServer.GetArOZInfo)
  42. //Register as a system setting
  43. registerSetting(settingModule{
  44. Name: "Host Info",
  45. Desc: "System Information",
  46. IconPath: "SystemAO/info/img/small_icon.png",
  47. Group: "Info",
  48. StartDir: "SystemAO/info/index.html",
  49. })
  50. /*
  51. CPU and RAM usage interface
  52. */
  53. registerSetting(settingModule{
  54. Name: "Performance",
  55. Desc: "System CPU and RAM usage",
  56. IconPath: "SystemAO/info/img/small_icon.png",
  57. Group: "Info",
  58. StartDir: "SystemAO/info/taskManagerFrame.html",
  59. })
  60. router.HandleFunc("/system/info/getUsageInfo", InfoHandleTaskInfo)
  61. }
  62. }
  63. func InfoHandleTaskInfo(w http.ResponseWriter, r *http.Request) {
  64. type UsageInfo struct {
  65. CPU float64
  66. UsedRAM string
  67. TotalRam string
  68. RamUsage float64
  69. }
  70. cpuUsage := usage.GetCPUUsage()
  71. usedRam, totalRam, usagePercentage := usage.GetRAMUsage()
  72. info := UsageInfo{
  73. cpuUsage,
  74. usedRam,
  75. totalRam,
  76. usagePercentage,
  77. }
  78. js, _ := json.Marshal(info)
  79. sendJSONResponse(w, string(js))
  80. }