Adding service settings to admin console
Этот коммит содержится в:
@@ -35,7 +35,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var lines []string
|
||||
|
||||
if utils.Cfg.LogSettings.FileEnable {
|
||||
if utils.Cfg.LogSettings.EnableFile {
|
||||
|
||||
file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation))
|
||||
if err != nil {
|
||||
@@ -82,7 +82,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(cfg.ServiceSettings.Port) == 0 {
|
||||
if len(cfg.ServiceSettings.ListenAddress) == 0 {
|
||||
c.SetInvalidParam("saveConfig", "config")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func Setup() {
|
||||
NewServer()
|
||||
StartServer()
|
||||
InitApi()
|
||||
Client = model.NewClient("http://localhost:" + utils.Cfg.ServiceSettings.Port)
|
||||
Client = model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -627,7 +627,7 @@ func TestGetChannelExtraInfo(t *testing.T) {
|
||||
currentEtag = cache_result.Etag
|
||||
}
|
||||
|
||||
Client2 := model.NewClient("http://localhost:" + utils.Cfg.ServiceSettings.Port)
|
||||
Client2 := model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
|
||||
|
||||
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "tester2@test.com", Nickname: "Tester 2", Password: "pwd"}
|
||||
user2 = Client2.Must(Client2.CreateUser(user2, "")).Data.(*model.User)
|
||||
|
||||
@@ -215,8 +215,8 @@ func joinCommand(c *Context, command *model.Command) bool {
|
||||
func loadTestCommand(c *Context, command *model.Command) bool {
|
||||
cmd := "/loadtest"
|
||||
|
||||
// This command is only available when AllowTesting is true
|
||||
if !utils.Cfg.ServiceSettings.AllowTesting {
|
||||
// This command is only available when EnableTesting is true
|
||||
if !utils.Cfg.ServiceSettings.EnableTesting {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -107,21 +107,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
isTokenFromQueryString = true
|
||||
}
|
||||
|
||||
protocol := "http"
|
||||
|
||||
// If the request came from the ELB then assume this is produciton
|
||||
// and redirect all http requests to https
|
||||
if utils.Cfg.ServiceSettings.UseSSL {
|
||||
forwardProto := r.Header.Get(model.HEADER_FORWARDED_PROTO)
|
||||
if forwardProto == "http" {
|
||||
l4g.Info("redirecting http request to https for %v", r.URL.Path)
|
||||
http.Redirect(w, r, "https://"+r.Host, http.StatusTemporaryRedirect)
|
||||
return
|
||||
} else {
|
||||
protocol = "https"
|
||||
}
|
||||
}
|
||||
|
||||
protocol := GetProtocol(r)
|
||||
c.setSiteURL(protocol + "://" + r.Host)
|
||||
|
||||
w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId)
|
||||
@@ -209,6 +195,14 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetProtocol(r *http.Request) string {
|
||||
if r.Header.Get(model.HEADER_FORWARDED_PROTO) == "https" {
|
||||
return "https"
|
||||
} else {
|
||||
return "http"
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) LogAudit(extraInfo string) {
|
||||
audit := &model.Audit{UserId: c.Session.UserId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
|
||||
if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
@@ -385,6 +379,11 @@ func (c *Context) GetSiteURL() string {
|
||||
|
||||
func GetIpAddress(r *http.Request) string {
|
||||
address := r.Header.Get(model.HEADER_FORWARDED)
|
||||
|
||||
if len(address) == 0 {
|
||||
address = r.Header.Get(model.HEADER_REAL_IP)
|
||||
}
|
||||
|
||||
if len(address) == 0 {
|
||||
address, _, _ = net.SplitHostPort(r.RemoteAddr)
|
||||
}
|
||||
@@ -458,14 +457,7 @@ func IsPrivateIpAddress(ipAddress string) bool {
|
||||
|
||||
func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
protocol := "http"
|
||||
if utils.Cfg.ServiceSettings.UseSSL {
|
||||
forwardProto := r.Header.Get(model.HEADER_FORWARDED_PROTO)
|
||||
if forwardProto != "http" {
|
||||
protocol = "https"
|
||||
}
|
||||
}
|
||||
|
||||
protocol := GetProtocol(r)
|
||||
SiteURL := protocol + "://" + r.Host
|
||||
|
||||
m := make(map[string]string)
|
||||
|
||||
@@ -399,7 +399,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
asyncGetFile(path, fileData)
|
||||
|
||||
if len(hash) > 0 && len(data) > 0 && len(teamId) == 26 {
|
||||
if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.PublicLinkSalt)) {
|
||||
if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt)) {
|
||||
c.Err = model.NewAppError("getFile", "The public link does not appear to be valid", "")
|
||||
return
|
||||
}
|
||||
@@ -477,7 +477,7 @@ func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
newProps["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(newProps)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.PublicLinkSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt))
|
||||
|
||||
url := fmt.Sprintf("%s/api/v1/files/get/%s/%s/%s?d=%s&h=%s&t=%s", c.GetSiteURL(), channelId, userId, filename, url.QueryEscape(data), url.QueryEscape(hash), c.Session.TeamId)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ func BenchmarkGetFile(b *testing.B) {
|
||||
newProps["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(newProps)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.PublicLinkSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt))
|
||||
|
||||
// wait a bit for files to ready
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
@@ -222,7 +222,7 @@ func TestGetFile(t *testing.T) {
|
||||
newProps["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(newProps)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.PublicLinkSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt))
|
||||
|
||||
Client.LoginByEmail(team2.Name, user2.Email, "pwd")
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ func NewServer() {
|
||||
|
||||
func StartServer() {
|
||||
l4g.Info("Starting Server...")
|
||||
l4g.Info("Server is listening on " + utils.Cfg.ServiceSettings.Port)
|
||||
l4g.Info("Server is listening on " + utils.Cfg.ServiceSettings.ListenAddress)
|
||||
|
||||
var handler http.Handler = Srv.Router
|
||||
|
||||
@@ -71,7 +71,7 @@ func StartServer() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := Srv.Server.ListenAndServe(":"+utils.Cfg.ServiceSettings.Port, handler)
|
||||
err := Srv.Server.ListenAndServe(utils.Cfg.ServiceSettings.ListenAddress, handler)
|
||||
if err != nil {
|
||||
l4g.Critical("Error starting server, err:%v", err)
|
||||
time.Sleep(time.Second)
|
||||
|
||||
21
api/team.go
21
api/team.go
@@ -38,7 +38,7 @@ func InitTeam(r *mux.Router) {
|
||||
}
|
||||
|
||||
func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !utils.Cfg.EmailSettings.AllowSignUpWithEmail {
|
||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
||||
c.Err = model.NewAppError("signupTeam", "Team sign-up with email is disabled.", "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
@@ -66,7 +66,7 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.InviteSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
|
||||
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_team_complete/?d=%s&h=%s", c.GetSiteURL(), url.QueryEscape(data), url.QueryEscape(hash))
|
||||
|
||||
@@ -85,7 +85,7 @@ func createTeamFromSSO(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
service := params["service"]
|
||||
|
||||
sso := utils.Cfg.GetSSOService(service)
|
||||
if sso != nil && !sso.Allow {
|
||||
if sso != nil && !sso.Enable {
|
||||
c.SetInvalidParam("createTeamFromSSO", "service")
|
||||
return
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func createTeamFromSSO(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !utils.Cfg.EmailSettings.AllowSignUpWithEmail {
|
||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
||||
c.Err = model.NewAppError("createTeamFromSignup", "Team sign-up with email is disabled.", "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
@@ -183,7 +183,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamSignup.User.TeamId = ""
|
||||
teamSignup.User.Password = password
|
||||
|
||||
if !model.ComparePassword(teamSignup.Hash, fmt.Sprintf("%v:%v", teamSignup.Data, utils.Cfg.ServiceSettings.InviteSalt)) {
|
||||
if !model.ComparePassword(teamSignup.Hash, fmt.Sprintf("%v:%v", teamSignup.Data, utils.Cfg.EmailSettings.InviteSalt)) {
|
||||
c.Err = model.NewAppError("createTeamFromSignup", "The signup link does not appear to be valid", "")
|
||||
return
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func CreateTeam(c *Context, team *model.Team) *model.Team {
|
||||
if !utils.Cfg.EmailSettings.AllowSignUpWithEmail {
|
||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
||||
c.Err = model.NewAppError("createTeam", "Team sign-up with email is disabled.", "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return nil
|
||||
@@ -258,11 +258,6 @@ func CreateTeam(c *Context, team *model.Team) *model.Team {
|
||||
return nil
|
||||
}
|
||||
|
||||
if utils.Cfg.ServiceSettings.Mode != utils.MODE_DEV {
|
||||
c.Err = model.NewAppError("CreateTeam", "The mode does not allow network creation without a valid invite", "")
|
||||
return nil
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Team().Save(team); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return nil
|
||||
@@ -488,10 +483,10 @@ func InviteMembers(c *Context, team *model.Team, user *model.User, invites []str
|
||||
props["name"] = team.Name
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.InviteSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&h=%s", c.GetSiteURL(), url.QueryEscape(data), url.QueryEscape(hash))
|
||||
|
||||
if utils.Cfg.ServiceSettings.Mode == utils.MODE_DEV {
|
||||
if !utils.Cfg.EmailSettings.SendEmailNotifications {
|
||||
l4g.Info("sending invitation to %v %v", invite, bodyPage.Props["Link"])
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestCreateFromSignupTeam(t *testing.T) {
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.InviteSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
user := model.User{Email: props["email"], Nickname: "Corey Hulen", Password: "hello"}
|
||||
|
||||
14
api/user.go
14
api/user.go
@@ -58,7 +58,7 @@ func InitUser(r *mux.Router) {
|
||||
}
|
||||
|
||||
func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !utils.Cfg.EmailSettings.AllowSignUpWithEmail {
|
||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
||||
c.Err = model.NewAppError("signupTeam", "User sign-up with email is disabled.", "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
@@ -90,7 +90,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
data := r.URL.Query().Get("d")
|
||||
props := model.MapFromJson(strings.NewReader(data))
|
||||
|
||||
if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.InviteSalt)) {
|
||||
if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt)) {
|
||||
c.Err = model.NewAppError("createUser", "The signup link does not appear to be valid", "")
|
||||
return
|
||||
}
|
||||
@@ -287,7 +287,7 @@ func LoginByEmail(c *Context, w http.ResponseWriter, r *http.Request, email, nam
|
||||
|
||||
func checkUserPassword(c *Context, user *model.User, password string) bool {
|
||||
|
||||
if user.FailedAttempts >= utils.Cfg.ServiceSettings.AllowedLoginAttempts {
|
||||
if user.FailedAttempts >= utils.Cfg.ServiceSettings.MaximumLoginAttempts {
|
||||
c.LogAuditWithUserId(user.Id, "fail")
|
||||
c.Err = model.NewAppError("checkUserPassword", "Your account is locked because of too many failed password attempts. Please reset your password.", "user_id="+user.Id)
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
@@ -1129,7 +1129,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
newProps["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(newProps)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.ResetSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.PasswordResetSalt))
|
||||
|
||||
link := fmt.Sprintf("%s/reset_password?d=%s&h=%s", c.GetTeamURLFromTeam(team), url.QueryEscape(data), url.QueryEscape(hash))
|
||||
|
||||
@@ -1208,7 +1208,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", props["data"], utils.Cfg.ServiceSettings.ResetSalt)) {
|
||||
if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", props["data"], utils.Cfg.EmailSettings.PasswordResetSalt)) {
|
||||
c.Err = model.NewAppError("resetPassword", "The reset password link does not appear to be valid", "")
|
||||
return
|
||||
}
|
||||
@@ -1357,7 +1357,7 @@ func getStatuses(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func GetAuthorizationCode(c *Context, w http.ResponseWriter, r *http.Request, teamName, service, redirectUri, loginHint string) {
|
||||
|
||||
sso := utils.Cfg.GetSSOService(service)
|
||||
if sso != nil && !sso.Allow {
|
||||
if sso != nil && !sso.Enable {
|
||||
c.Err = model.NewAppError("GetAuthorizationCode", "Unsupported OAuth service provider", "service="+service)
|
||||
c.Err.StatusCode = http.StatusBadRequest
|
||||
return
|
||||
@@ -1385,7 +1385,7 @@ func GetAuthorizationCode(c *Context, w http.ResponseWriter, r *http.Request, te
|
||||
|
||||
func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser, *model.Team, *model.AppError) {
|
||||
sso := utils.Cfg.GetSSOService(service)
|
||||
if sso != nil && !sso.Allow {
|
||||
if sso != nil && !sso.Enable {
|
||||
return nil, nil, model.NewAppError("AuthorizeOAuthUser", "Unsupported OAuth service provider", "service="+service)
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestLogin(t *testing.T) {
|
||||
props["display_name"] = rteam2.Data.(*model.Team).DisplayName
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.InviteSalt))
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
|
||||
ruser2, _ := Client.CreateUserFromSignup(&user2, data, hash)
|
||||
|
||||
@@ -814,7 +814,7 @@ func TestResetPassword(t *testing.T) {
|
||||
props["user_id"] = user.Id
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
data["data"] = model.MapToJson(props)
|
||||
data["hash"] = model.HashPassword(fmt.Sprintf("%v:%v", data["data"], utils.Cfg.ServiceSettings.ResetSalt))
|
||||
data["hash"] = model.HashPassword(fmt.Sprintf("%v:%v", data["data"], utils.Cfg.EmailSettings.PasswordResetSalt))
|
||||
data["name"] = team.Name
|
||||
|
||||
if _, err := Client.ResetPassword(data); err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func TestSocket(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
url := "ws://localhost:" + utils.Cfg.ServiceSettings.Port + "/api/v1/websocket"
|
||||
url := "ws://localhost" + utils.Cfg.ServiceSettings.ListenAddress + "/api/v1/websocket"
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user