diff options
author | Martin Kraft <martinkraft@gmail.com> | 2018-05-17 07:53:16 -0400 |
---|---|---|
committer | Martin Kraft <martinkraft@gmail.com> | 2018-05-17 07:53:16 -0400 |
commit | 6f31d90e2f31ae597b83b2f845d5db938af8e38c (patch) | |
tree | 81c59b83ffb033df92ff7fba5ffaf3ba5fe7a3cf /api/license.go | |
parent | 319d61123a0418ea9caa9510b8ad1e9a302c7b93 (diff) | |
parent | 1f6c271b3bedd6656ae7155714423b1b39a669c1 (diff) | |
download | chat-6f31d90e2f31ae597b83b2f845d5db938af8e38c.tar.gz chat-6f31d90e2f31ae597b83b2f845d5db938af8e38c.tar.bz2 chat-6f31d90e2f31ae597b83b2f845d5db938af8e38c.zip |
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'api/license.go')
-rw-r--r-- | api/license.go | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/api/license.go b/api/license.go deleted file mode 100644 index 432442ad6..000000000 --- a/api/license.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package api - -import ( - "bytes" - "io" - "net/http" - - "github.com/mattermost/mattermost-server/model" -) - -func (api *API) InitLicense() { - api.BaseRoutes.License.Handle("/add", api.ApiAdminSystemRequired(addLicense)).Methods("POST") - api.BaseRoutes.License.Handle("/remove", api.ApiAdminSystemRequired(removeLicense)).Methods("POST") - api.BaseRoutes.License.Handle("/client_config", api.ApiAppHandler(getClientLicenceConfig)).Methods("GET") -} - -func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { - c.LogAudit("attempt") - err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - m := r.MultipartForm - - fileArray, ok := m.File["license"] - if !ok { - c.Err = model.NewAppError("addLicense", "api.license.add_license.no_file.app_error", nil, "", http.StatusBadRequest) - return - } - - if len(fileArray) <= 0 { - c.Err = model.NewAppError("addLicense", "api.license.add_license.array.app_error", nil, "", http.StatusBadRequest) - return - } - - fileData := fileArray[0] - - file, err := fileData.Open() - if err != nil { - c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, err.Error(), http.StatusInternalServerError) - return - } - defer file.Close() - - buf := bytes.NewBuffer(nil) - io.Copy(buf, file) - - if license, err := c.App.SaveLicense(buf.Bytes()); err != nil { - if err.Id == model.EXPIRED_LICENSE_ERROR { - c.LogAudit("failed - expired or non-started license") - } else if err.Id == model.INVALID_LICENSE_ERROR { - c.LogAudit("failed - invalid license") - } else { - c.LogAudit("failed - unable to save license") - } - c.Err = err - return - } else { - c.LogAudit("success") - w.Write([]byte(license.ToJson())) - } -} - -func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { - c.LogAudit("") - - if err := c.App.RemoveLicense(); err != nil { - c.Err = err - return - } - - rdata := map[string]string{} - rdata["status"] = "ok" - w.Write([]byte(model.MapToJson(rdata))) -} - -func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request) { - useSanitizedLicense := !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) - - etag := c.App.GetClientLicenseEtag(useSanitizedLicense) - if c.HandleEtag(etag, "Get Client License Config", w, r) { - return - } - - var clientLicense map[string]string - - if useSanitizedLicense { - clientLicense = c.App.ClientLicense() - } else { - clientLicense = c.App.GetSanitizedClientLicense() - } - - w.Header().Set(model.HEADER_ETAG_SERVER, etag) - w.Write([]byte(model.MapToJson(clientLicense))) -} |