Skip to content

Commit

Permalink
Merge pull request #118 from ubccr/update-deps
Browse files Browse the repository at this point in the history
Update deps minor bug fixes
  • Loading branch information
aebruno authored Feb 10, 2023
2 parents 53da4fa + 5fef342 commit 483b7bd
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ nfpms:
- src: ./scripts/nfpm/mokey.toml.default
dst: /etc/mokey/mokey.toml
type: "config|noreplace"
- src: ./scripts/nfpm/mokey.env
dst: /etc/default/mokey
type: "config|noreplace"
- src: ./scripts/nfpm/mokey.service
dst: /usr/lib/systemd/system/mokey.service
checksum:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ $ chmod 640 /etc/mokey/private/mokeyapp.keytab
$ chgrp mokey /etc/mokey/private/mokeyapp.keytab
```

Edit mokey configuration file and set path to keytab file, optionally set
secrets and any other site specific config options:
Edit mokey configuration file and set path to keytab file. The values for
`token_secret` and `csrf_secret` will be automatically generated for you if
left blank. Set these secret values if you'd like sessions to persist after a restart.
For other site specific config options [see here](https://github.com/ubccr/mokey/blob/main/mokey.toml.sample):

```
$ vim /etc/mokey/mokey.toml
Expand Down
23 changes: 13 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"io/ioutil"
golog "log"
"os"
Expand All @@ -15,9 +16,7 @@ import (
var (
cfgFile string
cfgFileUsed string
trace bool
debug bool
verbose bool
logLevel string

Root = &cobra.Command{
Use: "mokey",
Expand All @@ -37,25 +36,29 @@ func init() {
cobra.OnInitialize(initConfig)

Root.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
Root.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug messages")
Root.PersistentFlags().BoolVar(&trace, "trace", false, "Enable trace messages")
Root.PersistentFlags().BoolVar(&verbose, "verbose", false, "Enable verbose messages")
Root.PersistentFlags().StringVar(&logLevel, "loglevel", "info", "Set log level")

Root.PersistentPreRunE = func(command *cobra.Command, args []string) error {
return SetupLogging()
}
}

func SetupLogging() error {
if trace {
switch logLevel {
case "trace":
logrus.SetLevel(logrus.TraceLevel)
} else if debug {
case "debug":
logrus.SetLevel(logrus.DebugLevel)
} else if verbose {
case "info":
logrus.SetLevel(logrus.InfoLevel)
} else {
case "warn":
logrus.SetLevel(logrus.WarnLevel)
case "error":
logrus.SetLevel(logrus.ErrorLevel)
default:
return fmt.Errorf("Unknown log level: %s", logLevel)
}

golog.SetOutput(ioutil.Discard)

if cfgFileUsed != "" {
Expand Down
21 changes: 13 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,38 @@ module github.com/ubccr/mokey
require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/boombuler/barcode v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/dchest/captcha v1.0.0
github.com/dustin/go-humanize v1.0.0
github.com/essentialkaos/branca v1.3.2
github.com/gofiber/fiber/v2 v2.38.1
github.com/gofiber/storage/memory v0.0.0-20220921084501-87862b1ac6ad
github.com/gofiber/storage/redis v0.0.0-20220921084501-87862b1ac6ad
github.com/gofiber/storage/sqlite3 v0.0.0-20220921084501-87862b1ac6ad
github.com/gofiber/fiber/v2 v2.42.0
github.com/gofiber/storage/memory v0.0.0-20230208140745-b66e5d19eb84
github.com/gofiber/storage/redis v0.0.0-20230208140745-b66e5d19eb84
github.com/gofiber/storage/sqlite3 v0.0.0-20230208140745-b66e5d19eb84
github.com/gorilla/mux v1.8.0
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/klauspost/compress v1.15.11 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/mileusna/useragent v1.2.0
github.com/ory/hydra-client-go v1.9.2
github.com/ory/hydra-client-go v1.10.6
github.com/pkg/errors v0.9.1
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/pquerna/otp v1.3.0
github.com/prometheus/client_golang v1.11.1
github.com/rivo/uniseg v0.4.3 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/sirupsen/logrus v1.9.0
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
github.com/tinylib/msgp v1.1.8 // indirect
github.com/ubccr/goipa v0.0.6
github.com/urfave/negroni v1.0.0
github.com/valyala/fasthttp v1.40.0
golang.org/x/net v0.0.0-20220927171203-f486391704dc
github.com/valyala/fasthttp v1.44.0
golang.org/x/net v0.3.0
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
golang.org/x/sys v0.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)
Expand Down
129 changes: 94 additions & 35 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions scripts/nfpm/mokey.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MOKEY_ARGS="--config=/etc/mokey/mokey.toml --loglevel=info"

# --loglevel="info"
# Log level: trace,debug,info,warn,error
3 changes: 2 additions & 1 deletion scripts/nfpm/mokey.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ After=syslog.target network.target
Type=simple
User=mokey
Group=mokey
EnvironmentFile=/etc/default/mokey
WorkingDirectory=/var/lib/mokey
ExecStart=/usr/bin/mokey serve --debug -c /etc/mokey/mokey.toml
ExecStart=/usr/bin/mokey serve $MOKEY_ARGS
Restart=on-abort
StateDirectory=mokey
ConfigurationDirectory=mokey
Expand Down
39 changes: 27 additions & 12 deletions server/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"path/filepath"
"strings"
"time"

"github.com/dchest/captcha"
Expand All @@ -24,9 +25,19 @@ func (r *Router) AccountSettings(c *fiber.Ctx) error {
return c.Render("account.html", vars)
}

user.First = c.FormValue("first")
user.Last = c.FormValue("last")
user.Mobile = c.FormValue("phone")
user.First = strings.TrimSpace(c.FormValue("first"))
user.Last = strings.TrimSpace(c.FormValue("last"))
user.Mobile = strings.TrimSpace(c.FormValue("phone"))

if user.First == "" || user.Last == "" {
vars["message"] = "Please provide a first and last name"
return c.Render("account.html", vars)
}

if len(user.First) > 150 || len(user.Last) > 150 {
vars["message"] = "First or Last name is too long. Maximum of 150 chars allowed"
return c.Render("account.html", vars)
}

userUpdated, err := r.adminClient.UserMod(user)
if err != nil {
Expand Down Expand Up @@ -62,10 +73,10 @@ func (r *Router) AccountCreate(c *fiber.Ctx) error {
}

user := &ipa.User{}
user.Username = c.FormValue("username")
user.Email = c.FormValue("email")
user.First = c.FormValue("first")
user.Last = c.FormValue("last")
user.Username = strings.TrimSpace(c.FormValue("username"))
user.Email = strings.TrimSpace(c.FormValue("email"))
user.First = strings.TrimSpace(c.FormValue("first"))
user.Last = strings.TrimSpace(c.FormValue("last"))
password := c.FormValue("password")
passwordConfirm := c.FormValue("password2")
captchaID := c.FormValue("captcha_id")
Expand Down Expand Up @@ -111,12 +122,16 @@ func (r *Router) accountCreate(user *ipa.User, password, passwordConfirm, captch
return err
}

if user.First == "" || len(user.First) > 150 {
return errors.New("Please provide your first name")
if user.First == "" || user.Last == "" {
return errors.New("Please provide your first and last name")
}

if len(user.First) > 150 {
return errors.New("First name is too long. Maximum of 150 chars allowed")
}

if user.Last == "" || len(user.Last) > 150 {
return errors.New("Please provide your last name")
if len(user.Last) > 150 {
return errors.New("Last name is too long. Maximum of 150 chars allowed")
}

if err := validatePassword(password, passwordConfirm); err != nil {
Expand Down Expand Up @@ -155,7 +170,7 @@ func (r *Router) accountCreate(user *ipa.User, password, passwordConfirm, captch
"first": userRec.First,
"last": userRec.Last,
"homedir": userRec.HomeDir,
}).Warn("New user account created")
}).Debug("New user account created")

// Disable new users until they have verified their email address
err = r.adminClient.UserDisable(userRec.Username)
Expand Down
2 changes: 1 addition & 1 deletion server/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (e *Emailer) sendEmail(user *ipa.User, ctx *fiber.Ctx, subject, tmpl string
log.WithFields(log.Fields{
"email": user.Email,
"username": user.Username,
}).Info("Sending email to user")
}).Debug("Sending email to user")

if data == nil {
data = make(map[string]interface{})
Expand Down

0 comments on commit 483b7bd

Please sign in to comment.