From 86694df84e564188967373c84481de455543f209 Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Mon, 6 Jun 2016 13:25:09 +0300 Subject: [PATCH] Add FromAlias to the Mail service and some iriscontrol fixes --- config/mail.go | 2 ++ iris.go | 7 ++++++- mail/service.go | 9 ++++++--- plugin.go | 9 ++++++--- plugin/iriscontrol/control_panel.go | 16 ++++++++++++---- plugin/iriscontrol/iriscontrol.go | 4 ++++ server/server.go | 2 ++ 7 files changed, 38 insertions(+), 11 deletions(-) diff --git a/config/mail.go b/config/mail.go index c0e6bb66..0514a6c8 100644 --- a/config/mail.go +++ b/config/mail.go @@ -10,6 +10,8 @@ type Mail struct { Username string // Password is the auth password for the sender Password string + // FromAlias is the from part, if empty this is the first part before @ from the Username field + FromAlias string // UseCommand enable it if you want to send e-mail with the mail command instead of smtp // // Host,Port & Password will be ignored diff --git a/iris.go b/iris.go index c9794766..98fd7276 100644 --- a/iris.go +++ b/iris.go @@ -93,13 +93,17 @@ func New(cfg ...config.Iris) *Iris { c := config.Default().Merge(cfg) // create the Iris - s := &Iris{config: &c, plugins: &PluginContainer{}} + s := &Iris{config: &c} + // create & set the router s.router = newRouter(s) // set the Logger s.logger = logger.New() + //set the plugin container + s.plugins = &PluginContainer{logger: s.logger} + // set the gzip writer pool s.gzipWriterPool = sync.Pool{New: func() interface{} { return &gzip.Writer{} }} return s @@ -123,6 +127,7 @@ func (s *Iris) initTemplates() { return err.Error() } }) + s.templates = template.New(s.config.Render.Template) } diff --git a/mail/service.go b/mail/service.go index 22431553..6cdbada1 100644 --- a/mail/service.go +++ b/mail/service.go @@ -33,9 +33,12 @@ type ( func New(cfg config.Mail) Service { m := &mailer{config: cfg} - // not necessary - if !cfg.UseCommand && cfg.Username != "" && strings.Contains(cfg.Username, "@") { - m.fromAddr = mail.Address{cfg.Username[0:strings.IndexByte(cfg.Username, '@')], cfg.Username} + if cfg.FromAlias == "" { + if !cfg.UseCommand && cfg.Username != "" && strings.Contains(cfg.Username, "@") { + m.fromAddr = mail.Address{cfg.Username[0:strings.IndexByte(cfg.Username, '@')], cfg.Username} + } + } else { + m.fromAddr = mail.Address{cfg.FromAlias, cfg.Username} } return m diff --git a/plugin.go b/plugin.go index 93940395..7b0c82ed 100644 --- a/plugin.go +++ b/plugin.go @@ -1,8 +1,7 @@ package iris import ( - "fmt" - + "github.com/kataras/iris/logger" "github.com/kataras/iris/utils" ) @@ -222,6 +221,7 @@ func (d *DownloadManager) Install(remoteFileZip string, targetDirectory string) type PluginContainer struct { activatedPlugins []IPlugin downloader *DownloadManager + logger *logger.Logger } // Add activates the plugins and if succeed then adds it to the activated plugins list @@ -327,7 +327,10 @@ func (p *PluginContainer) GetDownloader() IDownloadManager { // Printf sends plain text to any registed logger (future), some plugins maybe want use this method // maybe at the future I change it, instead of sync even-driven to async channels... func (p *PluginContainer) Printf(format string, a ...interface{}) { - fmt.Printf(format, a...) //for now just this. + if p.logger != nil { + p.logger.Printf(format, a...) //for now just this. + } + } // PreHandle adds a PreHandle plugin-function to the plugin flow container diff --git a/plugin/iriscontrol/control_panel.go b/plugin/iriscontrol/control_panel.go index ac8c2092..bb33c005 100644 --- a/plugin/iriscontrol/control_panel.go +++ b/plugin/iriscontrol/control_panel.go @@ -6,6 +6,7 @@ import ( "time" "github.com/kataras/iris" + "github.com/kataras/iris/config" "github.com/kataras/iris/plugin/routesinfo" ) @@ -41,9 +42,10 @@ func (i *irisControlPlugin) startControlPanel() { // DashboardPage is the main data struct for the index // contains a boolean if server is running, the routes and the plugins type DashboardPage struct { - ServerIsRunning bool - Routes []routesinfo.RouteInfo - Plugins []PluginInfo + ServerIsRunning bool + Routes []routesinfo.RouteInfo + Plugins []PluginInfo + LastOperationDateStr string } func (i *irisControlPlugin) setPluginsInfo() { @@ -72,12 +74,18 @@ func (i *irisControlPlugin) setPanelRoutes() { i.server.Use(i.authFunc) i.server.Get("/", func(ctx *iris.Context) { - ctx.Render("index.html", DashboardPage{ServerIsRunning: i.station.Server().IsListening(), Routes: i.routes.All(), Plugins: i.plugins}) + ctx.Render("index.html", DashboardPage{ + ServerIsRunning: i.station.Server().IsListening(), + Routes: i.routes.All(), + Plugins: i.plugins, + LastOperationDateStr: i.lastOperationDate.Format(config.TimeFormat), + }) }) //the controls i.server.Post("/start_server", func(ctx *iris.Context) { //println("server start") + i.lastOperationDate = time.Now() old := i.stationServer if !old.IsSecure() { i.station.Listen(old.Config.ListeningAddr) diff --git a/plugin/iriscontrol/iriscontrol.go b/plugin/iriscontrol/iriscontrol.go index e25771a8..1cabb579 100644 --- a/plugin/iriscontrol/iriscontrol.go +++ b/plugin/iriscontrol/iriscontrol.go @@ -28,6 +28,8 @@ type irisControlPlugin struct { //infos routes *routesinfo.Plugin plugins []PluginInfo + // last time the server was on + lastOperationDate time.Time // authFunc iris.HandlerFunc @@ -88,6 +90,7 @@ func (i *irisControlPlugin) PostListen(s *iris.Iris) { if i.station == nil { i.station = s i.stationServer = i.station.Server() + i.lastOperationDate = time.Now() i.startControlPanel() } @@ -106,6 +109,7 @@ func (i *irisControlPlugin) Destroy() { i.options = config.IrisControl{} i.routes = nil i.station = nil + i.lastOperationDate = config.CookieExpireNever i.server.Close() i.pluginContainer = nil i.authFunc = nil diff --git a/server/server.go b/server/server.go index db58fdf2..8bf2e8c4 100644 --- a/server/server.go +++ b/server/server.go @@ -157,6 +157,7 @@ func (s *Server) listenUnix() (err error) { err = ErrServerRemoveUnix.Format(s.Config.ListeningAddr, errOs.Error()) return } + // s.listener, err = net.Listen("unix", s.Config.ListeningAddr) if err != nil { @@ -201,6 +202,7 @@ func (s *Server) CloseServer() error { } if s.listener != nil { + s.started = false return s.listener.Close() } return nil