2014-04-16 22:29:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2015-05-27 17:08:44 +00:00
|
|
|
"fmt"
|
2014-10-29 16:59:59 +00:00
|
|
|
"os"
|
|
|
|
|
2015-04-19 17:06:05 +00:00
|
|
|
gohttp "net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/pat"
|
2014-06-23 18:21:20 +00:00
|
|
|
"github.com/ian-kent/go-log/log"
|
2014-12-24 16:52:53 +00:00
|
|
|
"github.com/mailhog/MailHog-Server/api"
|
2014-12-24 18:31:29 +00:00
|
|
|
cfgapi "github.com/mailhog/MailHog-Server/config"
|
2014-12-24 16:52:53 +00:00
|
|
|
"github.com/mailhog/MailHog-Server/smtp"
|
|
|
|
"github.com/mailhog/MailHog-UI/assets"
|
2014-12-24 18:31:29 +00:00
|
|
|
cfgui "github.com/mailhog/MailHog-UI/config"
|
2014-12-24 16:52:53 +00:00
|
|
|
"github.com/mailhog/MailHog-UI/web"
|
2015-05-27 17:08:44 +00:00
|
|
|
cfgcom "github.com/mailhog/MailHog/config"
|
2014-12-24 17:12:22 +00:00
|
|
|
"github.com/mailhog/http"
|
2015-05-26 21:58:57 +00:00
|
|
|
"github.com/mailhog/mhsendmail/cmd"
|
2015-05-27 17:08:44 +00:00
|
|
|
"golang.org/x/crypto/bcrypt"
|
2014-04-16 22:29:23 +00:00
|
|
|
)
|
|
|
|
|
2014-12-24 18:31:29 +00:00
|
|
|
var apiconf *cfgapi.Config
|
|
|
|
var uiconf *cfgui.Config
|
2015-05-27 17:08:44 +00:00
|
|
|
var comconf *cfgcom.Config
|
2014-04-20 14:35:59 +00:00
|
|
|
var exitCh chan int
|
2014-04-16 22:29:23 +00:00
|
|
|
|
2014-04-23 23:22:50 +00:00
|
|
|
func configure() {
|
2015-05-27 17:08:44 +00:00
|
|
|
cfgcom.RegisterFlags()
|
2014-12-24 18:31:29 +00:00
|
|
|
cfgapi.RegisterFlags()
|
|
|
|
cfgui.RegisterFlags()
|
2014-04-16 22:29:23 +00:00
|
|
|
flag.Parse()
|
2014-12-24 18:31:29 +00:00
|
|
|
apiconf = cfgapi.Configure()
|
|
|
|
uiconf = cfgui.Configure()
|
2015-05-27 17:08:44 +00:00
|
|
|
comconf = cfgcom.Configure()
|
2016-03-06 10:51:30 +00:00
|
|
|
|
|
|
|
apiconf.WebPath = comconf.WebPath
|
|
|
|
uiconf.WebPath = comconf.WebPath
|
2014-04-16 22:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2015-05-26 21:58:57 +00:00
|
|
|
if len(os.Args) > 1 && os.Args[1] == "sendmail" {
|
|
|
|
args := os.Args
|
|
|
|
os.Args = []string{args[0]}
|
|
|
|
if len(args) > 2 {
|
|
|
|
os.Args = append(os.Args, args[2:]...)
|
|
|
|
}
|
|
|
|
cmd.Go()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:08:44 +00:00
|
|
|
if len(os.Args) > 1 && os.Args[1] == "bcrypt" {
|
|
|
|
var pw string
|
|
|
|
if len(os.Args) > 2 {
|
|
|
|
pw = os.Args[2]
|
|
|
|
} else {
|
|
|
|
// TODO: read from stdin
|
|
|
|
}
|
|
|
|
b, err := bcrypt.GenerateFromPassword([]byte(pw), 4)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error bcrypting password: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
fmt.Println(string(b))
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2014-04-23 23:22:50 +00:00
|
|
|
configure()
|
2014-04-16 22:29:23 +00:00
|
|
|
|
2015-05-27 17:08:44 +00:00
|
|
|
if comconf.AuthFile != "" {
|
|
|
|
http.AuthFile(comconf.AuthFile)
|
|
|
|
}
|
|
|
|
|
2014-04-20 14:35:59 +00:00
|
|
|
exitCh = make(chan int)
|
2014-12-24 19:25:02 +00:00
|
|
|
if uiconf.UIBindAddr == apiconf.APIBindAddr {
|
2015-04-19 17:06:05 +00:00
|
|
|
cb := func(r gohttp.Handler) {
|
|
|
|
web.CreateWeb(uiconf, r.(*pat.Router), assets.Asset)
|
2016-04-22 13:58:05 +00:00
|
|
|
api.CreateAPI(apiconf, r.(*pat.Router))
|
2014-12-24 19:25:02 +00:00
|
|
|
}
|
|
|
|
go http.Listen(uiconf.UIBindAddr, assets.Asset, exitCh, cb)
|
|
|
|
} else {
|
2015-04-19 17:06:05 +00:00
|
|
|
cb1 := func(r gohttp.Handler) {
|
2016-04-22 13:58:05 +00:00
|
|
|
api.CreateAPI(apiconf, r.(*pat.Router))
|
2014-12-24 19:25:02 +00:00
|
|
|
}
|
2015-04-19 17:06:05 +00:00
|
|
|
cb2 := func(r gohttp.Handler) {
|
|
|
|
web.CreateWeb(uiconf, r.(*pat.Router), assets.Asset)
|
2014-12-24 19:25:02 +00:00
|
|
|
}
|
|
|
|
go http.Listen(apiconf.APIBindAddr, assets.Asset, exitCh, cb1)
|
|
|
|
go http.Listen(uiconf.UIBindAddr, assets.Asset, exitCh, cb2)
|
2014-11-23 15:05:11 +00:00
|
|
|
}
|
2014-12-24 18:31:29 +00:00
|
|
|
go smtp.Listen(apiconf, exitCh)
|
2014-04-20 14:35:59 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
2014-06-24 21:21:06 +00:00
|
|
|
case <-exitCh:
|
|
|
|
log.Printf("Received exit signal")
|
|
|
|
os.Exit(0)
|
2014-04-20 14:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-26 07:55:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Add some random content to the end of this file, hopefully tricking GitHub
|
|
|
|
into recognising this as a Go repo instead of Makefile.
|
|
|
|
|
|
|
|
A gopher, ASCII art style - borrowed from
|
|
|
|
https://gist.github.com/belbomemo/b5e7dad10fa567a5fe8a
|
|
|
|
|
|
|
|
,_---~~~~~----._
|
|
|
|
_,,_,*^____ _____``*g*\"*,
|
|
|
|
/ __/ /' ^. / \ ^@q f
|
|
|
|
[ @f | @)) | | @)) l 0 _/
|
|
|
|
\`/ \~____ / __ \_____/ \
|
|
|
|
| _l__l_ I
|
|
|
|
} [______] I
|
|
|
|
] | | | |
|
|
|
|
] ~ ~ |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
|
|
|
|
*/
|