Cosmos-Server/src/configapi/get.go

53 lines
1.2 KiB
Go
Raw Permalink Normal View History

2023-03-16 18:56:36 +00:00
package configapi
2023-03-10 20:59:56 +00:00
import (
"net/http"
"encoding/json"
2023-05-27 17:11:33 +00:00
"os"
2023-03-25 20:15:00 +00:00
"github.com/azukaar/cosmos-server/src/utils"
2023-03-10 20:59:56 +00:00
)
func ConfigApiGet(w http.ResponseWriter, req *http.Request) {
2023-05-01 11:59:46 +00:00
if utils.LoggedInOnly(w, req) != nil {
2023-03-10 20:59:56 +00:00
return
2023-05-01 11:59:46 +00:00
}
isAdmin := utils.IsAdmin(req)
2023-03-10 20:59:56 +00:00
if(req.Method == "GET") {
2023-04-27 18:29:26 +00:00
config := utils.ReadConfigFromFile()
2023-03-10 20:59:56 +00:00
// delete AuthPrivateKey and TLSKey
2023-03-16 18:56:36 +00:00
config.HTTPConfig.AuthPrivateKey = ""
config.HTTPConfig.TLSKey = ""
2023-03-10 20:59:56 +00:00
2023-05-01 11:59:46 +00:00
if !isAdmin {
config.MongoDB = "***"
config.EmailConfig.Password = "***"
config.EmailConfig.Username = "***"
config.EmailConfig.Host = "***"
// filter admin only routes
filteredRoutes := make([]utils.ProxyRouteConfig, 0)
for _, route := range config.HTTPConfig.ProxyConfig.Routes {
if !route.AdminOnly {
filteredRoutes = append(filteredRoutes, route)
}
}
config.HTTPConfig.ProxyConfig.Routes = filteredRoutes
}
2023-03-10 20:59:56 +00:00
json.NewEncoder(w).Encode(map[string]interface{}{
"status": "OK",
"data": config,
2023-05-15 19:23:06 +00:00
"updates": utils.UpdateAvailable,
2023-05-27 17:11:33 +00:00
"hostname": os.Getenv("HOSTNAME"),
2023-08-20 10:36:52 +00:00
"isAdmin": isAdmin,
2023-03-10 20:59:56 +00:00
})
} else {
utils.Error("SettingGet: Method not allowed" + req.Method, nil)
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
return
}
}