summaryrefslogtreecommitdiffstats
path: root/api/admin.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-17 21:00:59 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-17 21:00:59 -0700
commit44714dfcb18b9a393dc34be3c182b0c092eec28a (patch)
tree117bc8a3bc37f9112abf5498248c779081df514f /api/admin.go
parent82127341cacd4299f9a59e76b5f68d6d7222c45b (diff)
downloadchat-44714dfcb18b9a393dc34be3c182b0c092eec28a.tar.gz
chat-44714dfcb18b9a393dc34be3c182b0c092eec28a.tar.bz2
chat-44714dfcb18b9a393dc34be3c182b0c092eec28a.zip
PLT-11 Adding ability to save config file
Diffstat (limited to 'api/admin.go')
-rw-r--r--api/admin.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/api/admin.go b/api/admin.go
index 6d7a9028f..646597755 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -7,6 +7,7 @@ import (
"bufio"
"net/http"
"os"
+ "strings"
l4g "code.google.com/p/log4go"
"github.com/gorilla/mux"
@@ -20,6 +21,8 @@ func InitAdmin(r *mux.Router) {
sr := r.PathPrefix("/admin").Subrouter()
sr.Handle("/logs", ApiUserRequired(getLogs)).Methods("GET")
+ sr.Handle("/config", ApiUserRequired(getConfig)).Methods("GET")
+ sr.Handle("/save_config", ApiUserRequired(saveConfig)).Methods("POST")
sr.Handle("/client_props", ApiAppHandler(getClientProperties)).Methods("GET")
}
@@ -33,7 +36,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
if utils.Cfg.LogSettings.FileEnable {
- file, err := os.Open(utils.Cfg.LogSettings.FileLocation)
+ file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation))
if err != nil {
c.Err = model.NewAppError("getLogs", "Error reading log file", err.Error())
}
@@ -54,3 +57,44 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
func getClientProperties(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(model.MapToJson(utils.ClientProperties)))
}
+
+func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
+ if !c.HasSystemAdminPermissions("getConfig") {
+ return
+ }
+
+ json := utils.Cfg.ToJson()
+ cfg := model.ConfigFromJson(strings.NewReader(json))
+ json = cfg.ToJson()
+
+ w.Write([]byte(json))
+}
+
+func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
+ if !c.HasSystemAdminPermissions("getConfig") {
+ return
+ }
+
+ cfg := model.ConfigFromJson(r.Body)
+ if cfg == nil {
+ c.SetInvalidParam("saveConfig", "config")
+ return
+ }
+
+ if len(cfg.ServiceSettings.Port) == 0 {
+ c.SetInvalidParam("saveConfig", "config")
+ return
+ }
+
+ if cfg.TeamSettings.MaxUsersPerTeam == 0 {
+ c.SetInvalidParam("saveConfig", "config")
+ return
+ }
+
+ // TODO run some cleanup validators
+
+ utils.SaveConfig(utils.CfgFileName, cfg)
+ utils.LoadConfig(utils.CfgFileName)
+ json := utils.Cfg.ToJson()
+ w.Write([]byte(json))
+}