1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-23 07:09:43 +02:00

support for license keys

This commit is contained in:
Harvey Kandola 2017-02-22 20:03:40 -08:00
parent b0d70e2657
commit 3f87401d49
10 changed files with 252 additions and 35 deletions

View file

@ -16,13 +16,15 @@ import (
"io/ioutil"
"net/http"
"encoding/xml"
"fmt"
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/api/util"
)
// GetGlobalConfig returns installation-wide settings
func GetGlobalConfig(w http.ResponseWriter, r *http.Request) {
method := "GetGlobalConfig"
// GetSMTPConfig returns installation-wide SMTP settings
func GetSMTPConfig(w http.ResponseWriter, r *http.Request) {
method := "GetSMTPConfig"
p := request.GetPersister(r)
if !p.Context.Global {
@ -39,16 +41,16 @@ func GetGlobalConfig(w http.ResponseWriter, r *http.Request) {
json, err := json.Marshal(y)
if err != nil {
writeJSONMarshalError(w, method, "GetGlobalConfig", err)
writeJSONMarshalError(w, method, "SMTP", err)
return
}
util.WriteSuccessBytes(w, json)
}
// SaveGlobalConfig persists global configuration.
func SaveGlobalConfig(w http.ResponseWriter, r *http.Request) {
method := "SaveGlobalConfig"
// SaveSMTPConfig persists global SMTP configuration.
func SaveSMTPConfig(w http.ResponseWriter, r *http.Request) {
method := "SaveSMTPConfig"
p := request.GetPersister(r)
if !p.Context.Global {
@ -79,3 +81,110 @@ func SaveGlobalConfig(w http.ResponseWriter, r *http.Request) {
util.WriteSuccessEmptyJSON(w)
}
// GetLicense returns product license
func GetLicense(w http.ResponseWriter, r *http.Request) {
// method := "GetLicense"
p := request.GetPersister(r)
if !p.Context.Global {
writeForbiddenError(w)
return
}
// SMTP settings
config := request.ConfigString("EDITION-LICENSE", "")
if len(config) == 0 {
config = "{}"
}
x := &licenseXML{Key: "", Signature: ""}
lj := licenseJSON{}
err := json.Unmarshal([]byte(config), &lj)
if err == nil {
x.Key = lj.Key
x.Signature = lj.Signature
} else {
fmt.Println(err)
}
output, err := xml.MarshalIndent(x, " ", " ")
if err != nil {
fmt.Printf("error: %v\n", err)
}
w.WriteHeader(http.StatusOK)
w.Write(output)
// // marshal as JSON
// var y map[string]interface{}
// json.Unmarshal([]byte(config), &y)
// json, err := json.Marshal(y)
// if err != nil {
// writeJSONMarshalError(w, method, "EDITION-LICENSE", err)
// return
// }
// util.WriteSuccessBytes(w, json)
}
// SaveLicense persists product license
func SaveLicense(w http.ResponseWriter, r *http.Request) {
method := "SaveLicense"
p := request.GetPersister(r)
if !p.Context.Global {
writeForbiddenError(w)
return
}
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
if err != nil {
writePayloadError(w, method, err)
return
}
var config string
config = string(body)
lj := licenseJSON{}
x := licenseXML{Key: "", Signature: ""}
err = xml.Unmarshal([]byte(config), &x)
if err == nil {
lj.Key = x.Key
lj.Signature = x.Signature
} else {
fmt.Println(err)
}
j, err := json.Marshal(lj)
js := "{}"
if err == nil {
js = string(j)
}
request.ConfigSet("EDITION-LICENSE", js)
util.WriteSuccessEmptyJSON(w)
}
type licenseXML struct {
XMLName xml.Name `xml:"DocumizeLicense"`
Key string
Signature string
}
type licenseJSON struct {
Key string `json:"key"`
Signature string `json:"signature"`
}
/*
<DocumizeLicense>
<Key>some key</Key>
<Signature>some signature</Signature>
</DocumizeLicense>
*/