summaryrefslogtreecommitdiffstats
path: root/mattermost.go
diff options
context:
space:
mode:
Diffstat (limited to 'mattermost.go')
-rw-r--r--mattermost.go219
1 files changed, 139 insertions, 80 deletions
diff --git a/mattermost.go b/mattermost.go
index 6073f37f4..44eed457d 100644
--- a/mattermost.go
+++ b/mattermost.go
@@ -4,6 +4,7 @@
package main
import (
+ "bufio"
"flag"
"fmt"
"html/template"
@@ -11,6 +12,7 @@ import (
"net/http"
"net/url"
"os"
+ "os/exec"
"os/signal"
"runtime"
"strconv"
@@ -44,6 +46,8 @@ var flagCmdCreateUser bool
var flagCmdAssignRole bool
var flagCmdJoinTeam bool
var flagCmdVersion bool
+var flagCmdRunWebClientTests bool
+var flagCmdRunJavascriptClientTests bool
var flagCmdResetPassword bool
var flagCmdResetMfa bool
var flagCmdPermanentDeleteUser bool
@@ -85,12 +89,12 @@ func main() {
}
pwd, _ := os.Getwd()
- l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash)
+ l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise)
l4g.Info(utils.T("mattermost.entreprise_enabled"), model.BuildEnterpriseReady)
l4g.Info(utils.T("mattermost.working_dir"), pwd)
l4g.Info(utils.T("mattermost.config_file"), utils.FindConfigFile(flagConfigFile))
- // Speical case for upgrading the db to 3.0
+ // Special case for upgrading the db to 3.0
// ADDED for 3.0 REMOVE for 3.4
cmdUpdateDb30()
@@ -118,7 +122,7 @@ func main() {
}
setDiagnosticId()
- runSecurityAndDiagnosticsJobAndForget()
+ go runSecurityAndDiagnosticsJob()
if einterfaces.GetComplianceInterface() != nil {
einterfaces.GetComplianceInterface().StartComplianceDailyJob()
@@ -149,96 +153,94 @@ func setDiagnosticId() {
}
}
-func runSecurityAndDiagnosticsJobAndForget() {
- go func() {
- for {
- if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
- if result := <-api.Srv.Store.System().Get(); result.Err == nil {
- props := result.Data.(model.StringMap)
- lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
- currentTime := model.GetMillis()
-
- if (currentTime - lastSecurityTime) > 1000*60*60*24*1 {
- l4g.Debug(utils.T("mattermost.security_checks.debug"))
-
- v := url.Values{}
-
- v.Set(utils.PROP_DIAGNOSTIC_ID, utils.CfgDiagnosticId)
- v.Set(utils.PROP_DIAGNOSTIC_BUILD, model.CurrentVersion+"."+model.BuildNumber)
- v.Set(utils.PROP_DIAGNOSTIC_ENTERPRISE_READY, model.BuildEnterpriseReady)
- v.Set(utils.PROP_DIAGNOSTIC_DATABASE, utils.Cfg.SqlSettings.DriverName)
- v.Set(utils.PROP_DIAGNOSTIC_OS, runtime.GOOS)
- v.Set(utils.PROP_DIAGNOSTIC_CATEGORY, utils.VAL_DIAGNOSTIC_CATEGORY_DEFAULT)
-
- if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
- v.Set(utils.PROP_DIAGNOSTIC_UNIT_TESTS, "1")
- } else {
- v.Set(utils.PROP_DIAGNOSTIC_UNIT_TESTS, "0")
- }
+func runSecurityAndDiagnosticsJob() {
+ for {
+ if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
+ if result := <-api.Srv.Store.System().Get(); result.Err == nil {
+ props := result.Data.(model.StringMap)
+ lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
+ currentTime := model.GetMillis()
+
+ if (currentTime - lastSecurityTime) > 1000*60*60*24*1 {
+ l4g.Debug(utils.T("mattermost.security_checks.debug"))
+
+ v := url.Values{}
+
+ v.Set(utils.PROP_DIAGNOSTIC_ID, utils.CfgDiagnosticId)
+ v.Set(utils.PROP_DIAGNOSTIC_BUILD, model.CurrentVersion+"."+model.BuildNumber)
+ v.Set(utils.PROP_DIAGNOSTIC_ENTERPRISE_READY, model.BuildEnterpriseReady)
+ v.Set(utils.PROP_DIAGNOSTIC_DATABASE, utils.Cfg.SqlSettings.DriverName)
+ v.Set(utils.PROP_DIAGNOSTIC_OS, runtime.GOOS)
+ v.Set(utils.PROP_DIAGNOSTIC_CATEGORY, utils.VAL_DIAGNOSTIC_CATEGORY_DEFAULT)
+
+ if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
+ v.Set(utils.PROP_DIAGNOSTIC_UNIT_TESTS, "1")
+ } else {
+ v.Set(utils.PROP_DIAGNOSTIC_UNIT_TESTS, "0")
+ }
- systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
- if lastSecurityTime == 0 {
- <-api.Srv.Store.System().Save(systemSecurityLastTime)
- } else {
- <-api.Srv.Store.System().Update(systemSecurityLastTime)
- }
+ systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
+ if lastSecurityTime == 0 {
+ <-api.Srv.Store.System().Save(systemSecurityLastTime)
+ } else {
+ <-api.Srv.Store.System().Update(systemSecurityLastTime)
+ }
- if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
- v.Set(utils.PROP_DIAGNOSTIC_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
- }
+ if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
+ v.Set(utils.PROP_DIAGNOSTIC_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
+ }
- if ucr := <-api.Srv.Store.User().GetTotalActiveUsersCount(); ucr.Err == nil {
- v.Set(utils.PROP_DIAGNOSTIC_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
- }
+ if ucr := <-api.Srv.Store.User().GetTotalActiveUsersCount(); ucr.Err == nil {
+ v.Set(utils.PROP_DIAGNOSTIC_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
+ }
- res, err := http.Get(utils.DIAGNOSTIC_URL + "/security?" + v.Encode())
- if err != nil {
- l4g.Error(utils.T("mattermost.security_info.error"))
- return
- }
+ res, err := http.Get(utils.DIAGNOSTIC_URL + "/security?" + v.Encode())
+ if err != nil {
+ l4g.Error(utils.T("mattermost.security_info.error"))
+ return
+ }
+
+ bulletins := model.SecurityBulletinsFromJson(res.Body)
- bulletins := model.SecurityBulletinsFromJson(res.Body)
+ for _, bulletin := range bulletins {
+ if bulletin.AppliesToVersion == model.CurrentVersion {
+ if props["SecurityBulletin_"+bulletin.Id] == "" {
+ if results := <-api.Srv.Store.User().GetSystemAdminProfiles(); results.Err != nil {
+ l4g.Error(utils.T("mattermost.system_admins.error"))
+ return
+ } else {
+ users := results.Data.(map[string]*model.User)
- for _, bulletin := range bulletins {
- if bulletin.AppliesToVersion == model.CurrentVersion {
- if props["SecurityBulletin_"+bulletin.Id] == "" {
- if results := <-api.Srv.Store.User().GetSystemAdminProfiles(); results.Err != nil {
- l4g.Error(utils.T("mattermost.system_admins.error"))
+ resBody, err := http.Get(utils.DIAGNOSTIC_URL + "/bulletins/" + bulletin.Id)
+ if err != nil {
+ l4g.Error(utils.T("mattermost.security_bulletin.error"))
return
- } else {
- users := results.Data.(map[string]*model.User)
-
- resBody, err := http.Get(utils.DIAGNOSTIC_URL + "/bulletins/" + bulletin.Id)
- if err != nil {
- l4g.Error(utils.T("mattermost.security_bulletin.error"))
- return
- }
-
- body, err := ioutil.ReadAll(resBody.Body)
- res.Body.Close()
- if err != nil || resBody.StatusCode != 200 {
- l4g.Error(utils.T("mattermost.security_bulletin_read.error"))
- return
- }
-
- for _, user := range users {
- l4g.Info(utils.T("mattermost.send_bulletin.info"), bulletin.Id, user.Email)
- utils.SendMail(user.Email, utils.T("mattermost.bulletin.subject"), string(body))
- }
}
- bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}
- <-api.Srv.Store.System().Save(bulletinSeen)
+ body, err := ioutil.ReadAll(resBody.Body)
+ res.Body.Close()
+ if err != nil || resBody.StatusCode != 200 {
+ l4g.Error(utils.T("mattermost.security_bulletin_read.error"))
+ return
+ }
+
+ for _, user := range users {
+ l4g.Info(utils.T("mattermost.send_bulletin.info"), bulletin.Id, user.Email)
+ utils.SendMail(user.Email, utils.T("mattermost.bulletin.subject"), string(body))
+ }
}
+
+ bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}
+ <-api.Srv.Store.System().Save(bulletinSeen)
}
}
}
}
}
-
- time.Sleep(time.Hour * 4)
}
- }()
+
+ time.Sleep(time.Hour * 4)
+ }
}
func parseCmds() {
@@ -260,6 +262,8 @@ func parseCmds() {
flag.BoolVar(&flagCmdAssignRole, "assign_role", false, "")
flag.BoolVar(&flagCmdJoinTeam, "join_team", false, "")
flag.BoolVar(&flagCmdVersion, "version", false, "")
+ flag.BoolVar(&flagCmdRunWebClientTests, "run_web_client_tests", false, "")
+ flag.BoolVar(&flagCmdRunJavascriptClientTests, "run_javascript_client_tests", false, "")
flag.BoolVar(&flagCmdResetPassword, "reset_password", false, "")
flag.BoolVar(&flagCmdResetMfa, "reset_mfa", false, "")
flag.BoolVar(&flagCmdPermanentDeleteUser, "permanent_delete_user", false, "")
@@ -277,6 +281,8 @@ func parseCmds() {
flagCmdResetPassword ||
flagCmdResetMfa ||
flagCmdVersion ||
+ flagCmdRunWebClientTests ||
+ flagCmdRunJavascriptClientTests ||
flagCmdPermanentDeleteUser ||
flagCmdPermanentDeleteTeam ||
flagCmdPermanentDeleteAllUsers ||
@@ -286,6 +292,7 @@ func parseCmds() {
func runCmds() {
cmdVersion()
+ cmdRunClientTests()
cmdCreateTeam()
cmdCreateUser()
cmdAssignRole()
@@ -304,6 +311,58 @@ type TeamForUpgrade struct {
Name string
}
+func setupClientTests() {
+ *utils.Cfg.TeamSettings.EnableOpenServer = true
+}
+
+func executeTestCommand(cmd *exec.Cmd) {
+ cmdOutPipe, err := cmd.StdoutPipe()
+ if err != nil {
+ l4g.Error("Failed to run tests")
+ os.Exit(1)
+ }
+
+ cmdOutReader := bufio.NewScanner(cmdOutPipe)
+ go func() {
+ for cmdOutReader.Scan() {
+ fmt.Println(cmdOutReader.Text())
+ }
+ }()
+
+ if err := cmd.Run(); err != nil {
+ l4g.Error("Client Tests failed")
+ os.Exit(1)
+ }
+}
+
+func runWebClientTests() {
+ os.Chdir("webapp")
+ cmd := exec.Command("npm", "test")
+ executeTestCommand(cmd)
+}
+
+func runJavascriptClientTests() {
+ os.Chdir("../mattermost-driver-javascript")
+ cmd := exec.Command("npm", "test")
+ executeTestCommand(cmd)
+}
+
+func cmdRunClientTests() {
+ if flagCmdRunWebClientTests {
+ api.StartServer()
+ setupClientTests()
+ runWebClientTests()
+ api.StopServer()
+ }
+
+ if flagCmdRunJavascriptClientTests {
+ api.StartServer()
+ setupClientTests()
+ runJavascriptClientTests()
+ api.StopServer()
+ }
+}
+
// ADDED for 3.0 REMOVE for 3.4
func cmdUpdateDb30() {
if flagCmdUpdateDb30 {
@@ -312,7 +371,7 @@ func cmdUpdateDb30() {
store := api.Srv.Store.(*store.SqlStore)
utils.InitHTML()
- l4g.Info("Attempting to run speical upgrade of the database schema to version 3.0 for user model changes")
+ l4g.Info("Attempting to run special upgrade of the database schema to version 3.0 for user model changes")
time.Sleep(time.Second)
if !store.DoesColumnExist("Users", "TeamId") {
@@ -367,7 +426,7 @@ func cmdUpdateDb30() {
flushLogAndExit(1)
}
- l4g.Info("Starting speical 3.0 database upgrade with performed_backup=YES team_name=%v", team.Name)
+ l4g.Info("Starting special 3.0 database upgrade with performed_backup=YES team_name=%v", team.Name)
l4g.Info("Primary team %v will be left unchanged", team.Name)
l4g.Info("Upgrading primary team %v", team.Name)
@@ -442,7 +501,7 @@ func cmdUpdateDb30() {
store.RemoveColumnIfExists("Users", "TeamId")
}
- l4g.Info("Finished running speical upgrade of the database schema to version 3.0 for user model changes")
+ l4g.Info("Finished running special upgrade of the database schema to version 3.0 for user model changes")
if result := <-store.System().Update(&model.System{Name: "Version", Value: model.CurrentVersion}); result.Err != nil {
l4g.Error("Failed to update system schema version details=%v", result.Err)