MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / handleSettings

Function handleSettings

cmd/dash.go:1132–1382  ·  view source on GitHub ↗

handleSettings handles GET and POST requests for settings

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1130
1131// handleSettings handles GET and POST requests for settings
1132func handleSettings(w http.ResponseWriter, r *http.Request) {
1133 w.Header().Set("Content-Type", "application/json")
1134
1135 switch r.Method {
1136 case "GET":
1137 // Read the current config file
1138 configPath := configFilePath()
1139 data, err := ioutil.ReadFile(configPath)
1140 if err != nil {
1141 // If file doesn't exist, return empty config
1142 data = []byte("{}")
1143 }
1144
1145 var configData ConfigFile
1146 if err := json.Unmarshal(data, &configData); err != nil {
1147 http.Error(w, "Failed to parse config file", http.StatusInternalServerError)
1148 return
1149 }
1150
1151 // Get list of timezones
1152 timezones := []string{}
1153
1154 // Get the system's timezone first
1155 systemTZ := effectiveTimezoneLocationName().Name
1156
1157 // Try to read from system timezone database
1158 zoneDirs := []string{
1159 "/usr/share/zoneinfo",
1160 "/usr/lib/zoneinfo",
1161 "/usr/share/lib/zoneinfo",
1162 "/etc/zoneinfo",
1163 "/var/db/timezone/zoneinfo", // macOS location
1164 }
1165
1166 var zoneDir string
1167 for _, dir := range zoneDirs {
1168 if _, err := os.Stat(dir); err == nil {
1169 // Follow symlinks to get the actual directory
1170 realPath, err := filepath.EvalSymlinks(dir)
1171 if err == nil {
1172 zoneDir = realPath
1173 break
1174 }
1175 }
1176 }
1177
1178 if zoneDir != "" {
1179 err := filepath.Walk(zoneDir, func(path string, info os.FileInfo, err error) error {
1180 if err != nil {
1181 return nil
1182 }
1183 // Skip the root directory itself
1184 if path == zoneDir {
1185 return nil
1186 }
1187 if !info.IsDir() {
1188 // Convert path to timezone name by removing the zoneDir prefix
1189 tz := strings.TrimPrefix(path, zoneDir+"/")

Callers

nothing calls this directly

Calls 11

configFilePathFunction · 0.85
checkForUpdateFunction · 0.85
effectiveHostnameFunction · 0.85
getClientIPFunction · 0.85
logFunction · 0.85
ErrorMethod · 0.80
LoadAllowedIPsMethod · 0.80
LoadAllowedOriginsMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected