arsm.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package main
  2. /*
  3. ArOZ Remote Support and Management System
  4. author: tobychui
  5. This is a module for handling remote support and management of client
  6. devices from other side of the network (even behind NAT)
  7. This is a collection of submodules. Refer to the corrisponding submodules for more information
  8. */
  9. import (
  10. "log"
  11. "net/http"
  12. "imuslab.com/arozos/mod/arsm/aecron"
  13. module "imuslab.com/arozos/mod/modules"
  14. prout "imuslab.com/arozos/mod/prouter"
  15. )
  16. var (
  17. cronObject *aecron.Aecron
  18. )
  19. func ArsmInit() {
  20. /*
  21. System Scheudler
  22. The internal scheudler for arozos
  23. */
  24. //Create an user router and its module
  25. router := prout.NewModuleRouter(prout.RouterOption{
  26. ModuleName: "Tasks Scheduler",
  27. AdminOnly: false,
  28. UserHandler: userHandler,
  29. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  30. sendErrorResponse(w, "Permission Denied")
  31. },
  32. })
  33. //Register the module
  34. moduleHandler.RegisterModule(module.ModuleInfo{
  35. Name: "Tasks Scheduler",
  36. Group: "System Tools",
  37. IconPath: "SystemAO/arsm/img/scheduler.png",
  38. Version: "1.0",
  39. StartDir: "SystemAO/arsm/scheduler.html",
  40. SupportFW: true,
  41. InitFWSize: []int{1080, 580},
  42. LaunchFWDir: "SystemAO/arsm/scheduler.html",
  43. SupportEmb: false,
  44. })
  45. //Startup the ArOZ Emulated Crontab Service
  46. obj, err := aecron.NewArozEmulatedCrontab(userHandler, AGIGateway, "system/cron.json")
  47. if err != nil {
  48. log.Println("ArOZ Emulated Cron Startup Failed. Stopping all scheduled tasks.")
  49. }
  50. cronObject = obj
  51. //Register Endpoints
  52. http.HandleFunc("/system/arsm/aecron/list", func(w http.ResponseWriter, r *http.Request) {
  53. if authAgent.CheckAuth(r) {
  54. //User logged in
  55. obj.HandleListJobs(w, r)
  56. } else {
  57. //User not logged in
  58. http.NotFound(w, r)
  59. }
  60. })
  61. router.HandleFunc("/system/arsm/aecron/add", obj.HandleAddJob)
  62. router.HandleFunc("/system/arsm/aecron/remove", obj.HandleJobRemoval)
  63. router.HandleFunc("/system/arsm/aecron/listlog", obj.HandleShowLog)
  64. //Register settings
  65. registerSetting(settingModule{
  66. Name: "Tasks Scheduler",
  67. Desc: "System Tasks and Excution Scheduler",
  68. IconPath: "SystemAO/arsm/img/small_icon.png",
  69. Group: "Cluster",
  70. StartDir: "SystemAO/arsm/aecron.html",
  71. RequireAdmin: false,
  72. })
  73. }