diff --git a/cmd/admin/handlers-post.go b/cmd/admin/handlers-post.go index 8f17d6ad..ebbaa508 100644 --- a/cmd/admin/handlers-post.go +++ b/cmd/admin/handlers-post.go @@ -1229,7 +1229,7 @@ func usersPOSTHandler(w http.ResponseWriter, r *http.Request) { log.Printf("DebugService: %s %v", responseMessage, err) } } else { - newUser, err := adminUsers.New(u.Username, u.Password, u.Fullname, u.Admin) + newUser, err := adminUsers.New(u.Username, u.Password, u.Email, u.Fullname, u.Admin) if err != nil { responseMessage = "error with new user" responseCode = http.StatusInternalServerError diff --git a/cmd/admin/static/js/users.js b/cmd/admin/static/js/users.js index 8fa00d80..585de855 100644 --- a/cmd/admin/static/js/users.js +++ b/cmd/admin/static/js/users.js @@ -1,5 +1,6 @@ function addUser() { $("#user_username").val(''); + $("#user_email").val(''); $("#user_fullname").val(''); $("#user_password").val(''); $("#addUserModal").modal(); @@ -11,6 +12,7 @@ function confirmAddUser() { var _url = window.location.pathname; var _username = $("#user_username").val(); + var _email = $("#user_email").val(); var _fullname = $("#user_fullname").val(); var _password = $("#user_password").val(); @@ -18,9 +20,10 @@ function confirmAddUser() { csrftoken: _csrftoken, action: 'add', username: _username, + email: _email, fullname: _fullname, password: _password, - admin: true + admin: false }; sendPostRequest(data, _url, _url, false); } diff --git a/cmd/admin/templates/users.html b/cmd/admin/templates/users.html index 3cb35c2d..dfc06d40 100644 --- a/cmd/admin/templates/users.html +++ b/cmd/admin/templates/users.html @@ -41,8 +41,9 @@ Username - Fullname - Last IP + Email + Fullname + Last IP Last UserAgent Admin Last Session @@ -53,6 +54,7 @@ {{range $i, $e := $.CurrentUsers}} {{ $e.Username }} + {{ $e.Email }} {{ $e.Fullname }} {{ $e.LastIPAddress }} {{ $e.LastUserAgent }} @@ -97,6 +99,10 @@
+ +
+ +
diff --git a/cmd/admin/types-requests.go b/cmd/admin/types-requests.go index 130dda60..c6ecea28 100644 --- a/cmd/admin/types-requests.go +++ b/cmd/admin/types-requests.go @@ -107,6 +107,7 @@ type UsersRequest struct { CSRFToken string `json:"csrftoken"` Action string `json:"action"` Username string `json:"username"` + Email string `json:"email"` Fullname string `json:"fullname"` Password string `json:"password"` Admin bool `json:"admin"` diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 799f4f7f..ea8aab3e 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -83,6 +83,10 @@ func init() { Hidden: false, Usage: "Make this user an admin", }, + cli.StringFlag{ + Name: "email, e", + Usage: "Email for the new user", + }, cli.StringFlag{ Name: "fullname, n", Usage: "Full name for the new user", @@ -103,6 +107,10 @@ func init() { Name: "password, p", Usage: "New password to be used", }, + cli.StringFlag{ + Name: "email, e", + Usage: "Email to be used", + }, cli.StringFlag{ Name: "fullname, n", Usage: "Full name to be used", diff --git a/cmd/cli/user.go b/cmd/cli/user.go index 9a49b56a..035028f6 100644 --- a/cmd/cli/user.go +++ b/cmd/cli/user.go @@ -21,9 +21,10 @@ func addUser(c *cli.Context) error { os.Exit(1) } password := c.String("password") + email := c.String("email") fullname := c.String("fullname") admin := c.Bool("admin") - user, err := adminUsers.New(username, password, fullname, admin) + user, err := adminUsers.New(username, password, email, fullname, admin) if err != nil { return err } @@ -46,6 +47,12 @@ func editUser(c *cli.Context) error { return err } } + email := c.String("email") + if email != "" { + if err := adminUsers.ChangeEmail(username, email); err != nil { + return err + } + } fullname := c.String("fullname") if fullname != "" { if err := adminUsers.ChangeFullname(username, fullname); err != nil { diff --git a/go.mod b/go.mod index f0dc1610..e2a77368 100644 --- a/go.mod +++ b/go.mod @@ -10,19 +10,19 @@ require ( github.com/gorilla/securecookie v1.1.1 github.com/gorilla/sessions v1.1.3 github.com/jinzhu/gorm v1.9.10 - github.com/jmpsec/osctrl/pkg/carves v0.1.7 - github.com/jmpsec/osctrl/pkg/environments v0.1.7 - github.com/jmpsec/osctrl/pkg/metrics v0.1.7 - github.com/jmpsec/osctrl/pkg/nodes v0.1.7 - github.com/jmpsec/osctrl/pkg/queries v0.1.7 - github.com/jmpsec/osctrl/pkg/settings v0.1.7 - github.com/jmpsec/osctrl/pkg/types v0.1.7 - github.com/jmpsec/osctrl/pkg/users v0.1.7 - github.com/jmpsec/osctrl/pkg/utils v0.1.7 - github.com/jmpsec/osctrl/plugins/db_logging v0.1.7 // indirect - github.com/jmpsec/osctrl/plugins/graylog_logging v0.1.7 // indirect - github.com/jmpsec/osctrl/plugins/logging_dispatcher v0.1.7 // indirect - github.com/jmpsec/osctrl/plugins/splunk_logging v0.1.7 // indirect + github.com/jmpsec/osctrl/pkg/carves v0.1.8 + github.com/jmpsec/osctrl/pkg/environments v0.1.8 + github.com/jmpsec/osctrl/pkg/metrics v0.1.8 + github.com/jmpsec/osctrl/pkg/nodes v0.1.8 + github.com/jmpsec/osctrl/pkg/queries v0.1.8 + github.com/jmpsec/osctrl/pkg/settings v0.1.8 + github.com/jmpsec/osctrl/pkg/types v0.1.8 + github.com/jmpsec/osctrl/pkg/users v0.1.8 + github.com/jmpsec/osctrl/pkg/utils v0.1.8 + github.com/jmpsec/osctrl/plugins/db_logging v0.1.8 // indirect + github.com/jmpsec/osctrl/plugins/graylog_logging v0.1.8 // indirect + github.com/jmpsec/osctrl/plugins/logging_dispatcher v0.1.8 // indirect + github.com/jmpsec/osctrl/plugins/splunk_logging v0.1.8 // indirect github.com/mattn/go-runewidth v0.0.4 // indirect github.com/olekukonko/tablewriter v0.0.1 github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 // indirect diff --git a/pkg/queries/go.mod b/pkg/queries/go.mod index 5e0a697a..4351d772 100644 --- a/pkg/queries/go.mod +++ b/pkg/queries/go.mod @@ -3,6 +3,6 @@ module github.com/jmpsec/osctrl/pkg/queries go 1.12 require ( - github.com/jmpsec/osctrl/pkg/nodes v0.1.7 + github.com/jmpsec/osctrl/pkg/nodes v0.1.8 github.com/jinzhu/gorm v1.9.8 ) diff --git a/pkg/types/go.mod b/pkg/types/go.mod index e2d9be67..4cd7634b 100644 --- a/pkg/types/go.mod +++ b/pkg/types/go.mod @@ -2,4 +2,4 @@ module github.com/jmpsec/osctrl/pkg/types go 1.12 -require github.com/jmpsec/osctrl/pkg/queries v0.1.7 +require github.com/jmpsec/osctrl/pkg/queries v0.1.8 diff --git a/pkg/users/users.go b/pkg/users/users.go index 49a41be8..269aa928 100644 --- a/pkg/users/users.go +++ b/pkg/users/users.go @@ -13,6 +13,7 @@ import ( type AdminUser struct { gorm.Model Username string `gorm:"index"` + Email string Fullname string PassHash string Admin bool @@ -87,7 +88,7 @@ func (m *UserManager) Create(user AdminUser) error { } // New empty user -func (m *UserManager) New(username, password, fullname string, admin bool) (AdminUser, error) { +func (m *UserManager) New(username, password, email, fullname string, admin bool) (AdminUser, error) { if !m.Exists(username) { passhash, err := m.HashPasswordWithSalt(password) if err != nil { @@ -97,6 +98,7 @@ func (m *UserManager) New(username, password, fullname string, admin bool) (Admi Username: username, PassHash: passhash, Admin: admin, + Email: email, Fullname: fullname, }, nil } @@ -170,6 +172,20 @@ func (m *UserManager) ChangePassword(username, password string) error { return nil } +// ChangeEmail for user by username +func (m *UserManager) ChangeEmail(username, email string) error { + user, err := m.Get(username) + if err != nil { + return fmt.Errorf("error getting user %v", err) + } + if email != user.Email { + if err := m.DB.Model(&user).Update("email", email).Error; err != nil { + return fmt.Errorf("Update %v", err) + } + } + return nil +} + // ChangeFullname for user by username func (m *UserManager) ChangeFullname(username, fullname string) error { user, err := m.Get(username) diff --git a/plugins/db_logging/go.mod b/plugins/db_logging/go.mod index 5c6dd1e4..7636cbf5 100644 --- a/plugins/db_logging/go.mod +++ b/plugins/db_logging/go.mod @@ -3,6 +3,6 @@ module github.com/jmpsec/osctrl/plugins/db_logging go 1.12 require ( - github.com/jmpsec/osctrl/pkg/types v0.1.7 + github.com/jmpsec/osctrl/pkg/types v0.1.8 github.com/jinzhu/gorm v1.9.10 ) diff --git a/plugins/graylog_logging/go.mod b/plugins/graylog_logging/go.mod index 46a15128..5237f306 100644 --- a/plugins/graylog_logging/go.mod +++ b/plugins/graylog_logging/go.mod @@ -2,4 +2,4 @@ module github.com/jmpsec/osctrl/plugins/graylog_logging go 1.12 -require github.com/jmpsec/osctrl/pkg/utils v0.1.7 +require github.com/jmpsec/osctrl/pkg/utils v0.1.8 diff --git a/plugins/logging_dispatcher/go.mod b/plugins/logging_dispatcher/go.mod index 651d7b24..b6c19c96 100644 --- a/plugins/logging_dispatcher/go.mod +++ b/plugins/logging_dispatcher/go.mod @@ -3,8 +3,8 @@ module github.com/jmpsec/osctrl/plugins/logging_dispatcher go 1.12 require ( - github.com/jmpsec/osctrl/pkg/settings v0.1.7 - github.com/jmpsec/osctrl/pkg/types v0.1.7 + github.com/jmpsec/osctrl/pkg/settings v0.1.8 + github.com/jmpsec/osctrl/pkg/types v0.1.8 github.com/jinzhu/gorm v1.9.8 github.com/spf13/viper v1.4.0 ) diff --git a/plugins/splunk_logging/go.mod b/plugins/splunk_logging/go.mod index 75a63122..c00e6c56 100644 --- a/plugins/splunk_logging/go.mod +++ b/plugins/splunk_logging/go.mod @@ -3,6 +3,6 @@ module github.com/jmpsec/osctrl/plugins/splunk_logging go 1.12 require ( - github.com/jmpsec/osctrl/pkg/types v0.1.7 - github.com/jmpsec/osctrl/pkg/utils v0.1.7 + github.com/jmpsec/osctrl/pkg/types v0.1.8 + github.com/jmpsec/osctrl/pkg/utils v0.1.8 )