-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetting.go
165 lines (149 loc) · 4.44 KB
/
setting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"encoding/json"
"net/http"
module "imuslab.com/arozos/mod/modules"
"imuslab.com/arozos/mod/utils"
)
type settingModule struct {
Name string //Name of the setting module.
Desc string //Description of the setting module
IconPath string //Icon path for the setting module
Group string //Accept {}
StartDir string //Startup Directory / path
RequireAdmin bool //If the setting require admin access.
//^ Enable this to hide this setting from non-admin users, but for API call, module has to handle admin check themselves.
}
type settingGroup struct {
Name string
Group string
IconPath string
Desc string
}
var (
settingModules []settingModule
)
func SystemSettingInit() {
http.HandleFunc("/system/setting/list", system_setting_handleListing)
//Register the module
moduleHandler.RegisterModule(module.ModuleInfo{
Name: "System Setting",
Desc: "Cutomize your systems to fit your needs",
Group: "System Settings",
IconPath: "SystemAO/system_setting/img/small_icon.png",
Version: "1.0",
StartDir: "SystemAO/system_setting/index.html",
SupportFW: true,
InitFWSize: []int{1080, 580},
LaunchFWDir: "SystemAO/system_setting/index.html",
SupportEmb: false,
})
}
//Setting group defination. Your setting module defination must match the group in-order to be shown
func system_setting_getSettingGroups() []settingGroup {
return []settingGroup{
{
Name: "Host Information",
Group: "Info",
IconPath: "SystemAO/system_setting/img/server.svg",
Desc: "Config and info about the Server Host",
},
{
Name: "Devices & IoT",
Group: "Device",
IconPath: "SystemAO/system_setting/img/device.svg",
Desc: "Connected clients and IoT devices",
},
{
Name: "Module Management",
Group: "Module",
IconPath: "SystemAO/system_setting/img/module.svg",
Desc: "List of modules loaded in the system",
},
{
Name: "Disk & Storage",
Group: "Disk",
IconPath: "SystemAO/system_setting/img/drive.svg",
Desc: "Manage Storage Devices and Disks",
},
{
Name: "Network & Connection",
Group: "Network",
IconPath: "SystemAO/system_setting/img/network.svg",
Desc: "Manage Host Network and Connections",
},
{
Name: "Users & Groups",
Group: "Users",
IconPath: "SystemAO/system_setting/img/users.svg",
Desc: "Add, removed or edit users and groups",
},
{
Name: "Clusters & Scheduling",
Group: "Cluster",
IconPath: "SystemAO/system_setting/img/cluster.svg",
Desc: "Cluster, Network Scanning and Task Scheduling",
},
{
Name: "Security & Auth",
Group: "Security",
IconPath: "SystemAO/system_setting/img/security.svg",
Desc: "System Security and Auth Credentials",
},
{
Name: "Developer Options",
Group: "Advance",
IconPath: "SystemAO/system_setting/img/code.svg",
Desc: "Advance configs for developers",
},
{
Name: "About ArOZ",
Group: "About",
IconPath: "SystemAO/system_setting/img/info.svg",
Desc: "Information of the current running ArOZ Online System",
},
}
}
func registerSetting(thismodule settingModule) {
settingModules = append(settingModules, thismodule)
}
//List all the setting modules and output it as JSON
func system_setting_handleListing(w http.ResponseWriter, r *http.Request) {
userinfo, err := userHandler.GetUserInfoFromRequest(w, r)
if err != nil {
utils.SendErrorResponse(w, "User not logged in")
return
}
allSettingGroups := system_setting_getSettingGroups()
listGroup, _ := utils.GetPara(r, "listGroup")
if len(listGroup) > 0 {
//List the given group
var results []settingModule
for _, setMod := range settingModules {
if setMod.Group == listGroup {
//Check if the module is admin only.
if setMod.RequireAdmin && userinfo.IsAdmin() {
//Admin module and user is admin. Append to list
results = append(results, setMod)
} else if setMod.RequireAdmin == false {
//Normal module. Append to list
results = append(results, setMod)
}
}
}
if len(results) > 0 {
jsonString, _ := json.Marshal(results)
utils.SendJSONResponse(w, string(jsonString))
return
} else {
//This group not found,
utils.SendErrorResponse(w, "Group not found")
return
}
} else {
//List all root groups
jsonString, _ := json.Marshal(allSettingGroups)
utils.SendJSONResponse(w, string(jsonString))
return
}
}