mirror of
https://github.com/donl/gPanel.git
synced 2026-05-26 06:12:20 -06:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package settings
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"log"
|
|
"github.com/Ennovar/gPanel/pkg/database"
|
|
"encoding/json"
|
|
)
|
|
|
|
func GetAdmin(res http.ResponseWriter, req *http.Request, logger *log.Logger, dir string) bool {
|
|
if req.Method != "GET" {
|
|
logger.Println(req.URL.Path + "::" + req.Method + "::" + strconv.Itoa(http.StatusMethodNotAllowed) + "::" + http.StatusText(http.StatusMethodNotAllowed))
|
|
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
|
return false
|
|
}
|
|
|
|
ds, err := database.Open(dir + database.DB_SETTINGS)
|
|
if err != nil || ds == nil {
|
|
logger.Println(req.URL.Path + "::" + err.Error())
|
|
http.Error(res, err.Error(), http.StatusInternalServerError)
|
|
return false
|
|
}
|
|
defer ds.Close()
|
|
|
|
var adminSettings database.Struct_Admin
|
|
|
|
err = ds.Get(database.BUCKET_GENERAL, []byte("admin"), &adminSettings)
|
|
if err != nil {
|
|
logger.Println(req.URL.Path + "::" + err.Error())
|
|
http.Error(res, err.Error(), http.StatusInternalServerError)
|
|
return false
|
|
}
|
|
|
|
b, err := json.Marshal(adminSettings)
|
|
if err != nil {
|
|
logger.Println(req.URL.Path + "::" + err.Error())
|
|
http.Error(res, err.Error(), http.StatusInternalServerError)
|
|
return false
|
|
}
|
|
|
|
res.WriteHeader(http.StatusOK)
|
|
res.Write(b)
|
|
return true
|
|
}
|