Final updates
Этот коммит содержится в:
2
.gitignore
поставляемый
2
.gitignore
поставляемый
@@ -9,6 +9,8 @@ web/static/js/bundle*.js
|
|||||||
web/static/js/bundle*.js.map
|
web/static/js/bundle*.js.map
|
||||||
web/static/js/libs*.js
|
web/static/js/libs*.js
|
||||||
|
|
||||||
|
config/active.dat
|
||||||
|
|
||||||
# Build Targets
|
# Build Targets
|
||||||
.prepare
|
.prepare
|
||||||
.prepare-go
|
.prepare-go
|
||||||
|
|||||||
@@ -69,14 +69,15 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
if err := writeFileLocally(data, utils.LicenseLocation()); err != nil {
|
||||||
if err := writeFileLocally(data, utils.LICENSE_FILE_LOC); err != nil {
|
c.LogAudit("failed - could not save license file")
|
||||||
l4g.Error("Could not save license file")
|
c.Err = model.NewAppError("addLicense", "License did not save properly.", "path="+utils.LicenseLocation())
|
||||||
}
|
utils.RemoveLicense()
|
||||||
}()
|
return
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c.LogAudit("failed - invalid license")
|
c.LogAudit("failed - invalid license")
|
||||||
c.Err = model.NewAppError("addLicense", "Invalid license file", "")
|
c.Err = model.NewAppError("addLicense", "Invalid license file.", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +88,11 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
c.LogAudit("")
|
c.LogAudit("")
|
||||||
|
|
||||||
utils.RemoveLicense()
|
if ok := utils.RemoveLicense(); !ok {
|
||||||
|
c.LogAudit("failed - could not remove license file")
|
||||||
|
c.Err = model.NewAppError("removeLicense", "License did not remove properly.", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rdata := map[string]string{}
|
rdata := map[string]string{}
|
||||||
rdata["status"] = "ok"
|
rdata["status"] = "ok"
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CheckUserDomain(user *model.User, domains string) bool {
|
func CheckUserDomain(user *model.User, domains string) bool {
|
||||||
|
if len(domains) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
domainArray := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(domains, "@", " ", -1), ",", " ", -1))))
|
domainArray := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(domains, "@", " ", -1), ",", " ", -1))))
|
||||||
|
|
||||||
matched := false
|
matched := false
|
||||||
|
|||||||
@@ -107,5 +107,28 @@
|
|||||||
"AuthEndpoint": "",
|
"AuthEndpoint": "",
|
||||||
"TokenEndpoint": "",
|
"TokenEndpoint": "",
|
||||||
"UserApiEndpoint": ""
|
"UserApiEndpoint": ""
|
||||||
|
},
|
||||||
|
"GoogleSettings": {
|
||||||
|
"Enable": false,
|
||||||
|
"Secret": "",
|
||||||
|
"Id": "",
|
||||||
|
"Scope": "",
|
||||||
|
"AuthEndpoint": "",
|
||||||
|
"TokenEndpoint": "",
|
||||||
|
"UserApiEndpoint": ""
|
||||||
|
},
|
||||||
|
"LdapSettings": {
|
||||||
|
"Enable": false,
|
||||||
|
"LdapServer": null,
|
||||||
|
"LdapPort": 389,
|
||||||
|
"BaseDN": null,
|
||||||
|
"BindUsername": null,
|
||||||
|
"BindPassword": null,
|
||||||
|
"FirstNameAttribute": null,
|
||||||
|
"LastNameAttribute": null,
|
||||||
|
"EmailAttribute": null,
|
||||||
|
"UsernameAttribute": null,
|
||||||
|
"IdAttribute": null,
|
||||||
|
"QueryTimeout": 60
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,10 @@ import (
|
|||||||
_ "github.com/go-ldap/ldap"
|
_ "github.com/go-ldap/ldap"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ENTERPRISE_IMPORTS
|
import (
|
||||||
|
_ "github.com/mattermost/enterprise/oauth/google"
|
||||||
|
_ "github.com/mattermost/enterprise/ldap"
|
||||||
|
)
|
||||||
|
|
||||||
var flagCmdCreateTeam bool
|
var flagCmdCreateTeam bool
|
||||||
var flagCmdCreateUser bool
|
var flagCmdCreateUser bool
|
||||||
|
|||||||
@@ -26,9 +26,26 @@ type Customer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Features struct {
|
type Features struct {
|
||||||
Users int `json:"users"`
|
Users *int `json:"users"`
|
||||||
LDAP bool `json:"ldap"`
|
LDAP *bool `json:"ldap"`
|
||||||
GoogleSSO bool `json:"google_sso"`
|
GoogleSSO *bool `json:"google_sso"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Features) SetDefaults() {
|
||||||
|
if f.Users == nil {
|
||||||
|
f.Users = new(int)
|
||||||
|
*f.Users = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.LDAP == nil {
|
||||||
|
f.LDAP = new(bool)
|
||||||
|
*f.LDAP = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.GoogleSSO == nil {
|
||||||
|
f.GoogleSSO = new(bool)
|
||||||
|
*f.GoogleSSO = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *License) IsExpired() bool {
|
func (l *License) IsExpired() bool {
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha256"
|
"crypto/sha512"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LICENSE_FILE_LOC = "./data/active.dat"
|
LICENSE_FILENAME = "active.dat"
|
||||||
)
|
)
|
||||||
|
|
||||||
var IsLicensed bool = false
|
var IsLicensed bool = false
|
||||||
@@ -41,7 +42,7 @@ NxpC+5KFhU+xSeeklNqwCgnlOyZ7qSTxmdJHb+60SwuYnnGIYzLJhY4LYDr4J+KR
|
|||||||
-----END PUBLIC KEY-----`)
|
-----END PUBLIC KEY-----`)
|
||||||
|
|
||||||
func LoadLicense() {
|
func LoadLicense() {
|
||||||
file, err := os.Open(LICENSE_FILE_LOC)
|
file, err := os.Open(LicenseLocation())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l4g.Warn("Unable to open/find license file")
|
l4g.Warn("Unable to open/find license file")
|
||||||
return
|
return
|
||||||
@@ -53,18 +54,15 @@ func LoadLicense() {
|
|||||||
|
|
||||||
if success, licenseStr := ValidateLicense(buf.Bytes()); success {
|
if success, licenseStr := ValidateLicense(buf.Bytes()); success {
|
||||||
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
license := model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||||
if !license.IsExpired() && license.IsStarted() && license.StartsAt > License.StartsAt {
|
SetLicense(license)
|
||||||
License = license
|
|
||||||
IsLicensed = true
|
|
||||||
ClientLicense = getClientLicense(license)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l4g.Warn("No valid enterprise license found")
|
l4g.Warn("No valid enterprise license found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetLicense(license *model.License) bool {
|
func SetLicense(license *model.License) bool {
|
||||||
|
license.Features.SetDefaults()
|
||||||
|
|
||||||
if !license.IsExpired() && license.IsStarted() {
|
if !license.IsExpired() && license.IsStarted() {
|
||||||
License = license
|
License = license
|
||||||
IsLicensed = true
|
IsLicensed = true
|
||||||
@@ -75,14 +73,21 @@ func SetLicense(license *model.License) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveLicense() {
|
func LicenseLocation() string {
|
||||||
|
return filepath.Dir(CfgFileName) + "/" + LICENSE_FILENAME
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveLicense() bool {
|
||||||
License = &model.License{}
|
License = &model.License{}
|
||||||
IsLicensed = false
|
IsLicensed = false
|
||||||
ClientLicense = getClientLicense(License)
|
ClientLicense = getClientLicense(License)
|
||||||
|
|
||||||
if err := os.Remove(LICENSE_FILE_LOC); err != nil {
|
if err := os.Remove(LicenseLocation()); err != nil {
|
||||||
l4g.Error("Unable to remove license file, err=%v", err.Error())
|
l4g.Error("Unable to remove license file, err=%v", err.Error())
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateLicense(signed []byte) (bool, string) {
|
func ValidateLicense(signed []byte) (bool, string) {
|
||||||
@@ -117,11 +122,11 @@ func ValidateLicense(signed []byte) (bool, string) {
|
|||||||
|
|
||||||
rsaPublic := public.(*rsa.PublicKey)
|
rsaPublic := public.(*rsa.PublicKey)
|
||||||
|
|
||||||
h := sha256.New()
|
h := sha512.New()
|
||||||
h.Write(plaintext)
|
h.Write(plaintext)
|
||||||
d := h.Sum(nil)
|
d := h.Sum(nil)
|
||||||
|
|
||||||
err = rsa.VerifyPKCS1v15(rsaPublic, crypto.SHA256, d, signature)
|
err = rsa.VerifyPKCS1v15(rsaPublic, crypto.SHA512, d, signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l4g.Error("Invalid signature, err=%v", err.Error())
|
l4g.Error("Invalid signature, err=%v", err.Error())
|
||||||
return false, ""
|
return false, ""
|
||||||
@@ -136,9 +141,9 @@ func getClientLicense(l *model.License) map[string]string {
|
|||||||
props["IsLicensed"] = strconv.FormatBool(IsLicensed)
|
props["IsLicensed"] = strconv.FormatBool(IsLicensed)
|
||||||
|
|
||||||
if IsLicensed {
|
if IsLicensed {
|
||||||
props["Users"] = strconv.Itoa(l.Features.Users)
|
props["Users"] = strconv.Itoa(*l.Features.Users)
|
||||||
props["LDAP"] = strconv.FormatBool(l.Features.LDAP)
|
props["LDAP"] = strconv.FormatBool(*l.Features.LDAP)
|
||||||
props["GoogleSSO"] = strconv.FormatBool(l.Features.GoogleSSO)
|
props["GoogleSSO"] = strconv.FormatBool(*l.Features.GoogleSSO)
|
||||||
props["IssuedAt"] = strconv.FormatInt(l.IssuedAt, 10)
|
props["IssuedAt"] = strconv.FormatInt(l.IssuedAt, 10)
|
||||||
props["StartsAt"] = strconv.FormatInt(l.StartsAt, 10)
|
props["StartsAt"] = strconv.FormatInt(l.StartsAt, 10)
|
||||||
props["ExpiresAt"] = strconv.FormatInt(l.ExpiresAt, 10)
|
props["ExpiresAt"] = strconv.FormatInt(l.ExpiresAt, 10)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user