Add FromAlias to the Mail service and some iriscontrol fixes

This commit is contained in:
Makis Maropoulos 2016-06-06 13:25:09 +03:00
parent 48aaca5bc0
commit 86694df84e
7 changed files with 38 additions and 11 deletions

View File

@ -10,6 +10,8 @@ type Mail struct {
Username string Username string
// Password is the auth password for the sender // Password is the auth password for the sender
Password string 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 // UseCommand enable it if you want to send e-mail with the mail command instead of smtp
// //
// Host,Port & Password will be ignored // Host,Port & Password will be ignored

View File

@ -93,13 +93,17 @@ func New(cfg ...config.Iris) *Iris {
c := config.Default().Merge(cfg) c := config.Default().Merge(cfg)
// create the Iris // create the Iris
s := &Iris{config: &c, plugins: &PluginContainer{}} s := &Iris{config: &c}
// create & set the router // create & set the router
s.router = newRouter(s) s.router = newRouter(s)
// set the Logger // set the Logger
s.logger = logger.New() s.logger = logger.New()
//set the plugin container
s.plugins = &PluginContainer{logger: s.logger}
// set the gzip writer pool // set the gzip writer pool
s.gzipWriterPool = sync.Pool{New: func() interface{} { return &gzip.Writer{} }} s.gzipWriterPool = sync.Pool{New: func() interface{} { return &gzip.Writer{} }}
return s return s
@ -123,6 +127,7 @@ func (s *Iris) initTemplates() {
return err.Error() return err.Error()
} }
}) })
s.templates = template.New(s.config.Render.Template) s.templates = template.New(s.config.Render.Template)
} }

View File

@ -33,10 +33,13 @@ type (
func New(cfg config.Mail) Service { func New(cfg config.Mail) Service {
m := &mailer{config: cfg} m := &mailer{config: cfg}
// not necessary if cfg.FromAlias == "" {
if !cfg.UseCommand && cfg.Username != "" && strings.Contains(cfg.Username, "@") { if !cfg.UseCommand && cfg.Username != "" && strings.Contains(cfg.Username, "@") {
m.fromAddr = mail.Address{cfg.Username[0:strings.IndexByte(cfg.Username, '@')], 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 return m
} }

View File

@ -1,8 +1,7 @@
package iris package iris
import ( import (
"fmt" "github.com/kataras/iris/logger"
"github.com/kataras/iris/utils" "github.com/kataras/iris/utils"
) )
@ -222,6 +221,7 @@ func (d *DownloadManager) Install(remoteFileZip string, targetDirectory string)
type PluginContainer struct { type PluginContainer struct {
activatedPlugins []IPlugin activatedPlugins []IPlugin
downloader *DownloadManager downloader *DownloadManager
logger *logger.Logger
} }
// Add activates the plugins and if succeed then adds it to the activated plugins list // 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 // 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... // maybe at the future I change it, instead of sync even-driven to async channels...
func (p *PluginContainer) Printf(format string, a ...interface{}) { 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 // PreHandle adds a PreHandle plugin-function to the plugin flow container

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/kataras/iris" "github.com/kataras/iris"
"github.com/kataras/iris/config"
"github.com/kataras/iris/plugin/routesinfo" "github.com/kataras/iris/plugin/routesinfo"
) )
@ -44,6 +45,7 @@ type DashboardPage struct {
ServerIsRunning bool ServerIsRunning bool
Routes []routesinfo.RouteInfo Routes []routesinfo.RouteInfo
Plugins []PluginInfo Plugins []PluginInfo
LastOperationDateStr string
} }
func (i *irisControlPlugin) setPluginsInfo() { func (i *irisControlPlugin) setPluginsInfo() {
@ -72,12 +74,18 @@ func (i *irisControlPlugin) setPanelRoutes() {
i.server.Use(i.authFunc) i.server.Use(i.authFunc)
i.server.Get("/", func(ctx *iris.Context) { 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 //the controls
i.server.Post("/start_server", func(ctx *iris.Context) { i.server.Post("/start_server", func(ctx *iris.Context) {
//println("server start") //println("server start")
i.lastOperationDate = time.Now()
old := i.stationServer old := i.stationServer
if !old.IsSecure() { if !old.IsSecure() {
i.station.Listen(old.Config.ListeningAddr) i.station.Listen(old.Config.ListeningAddr)

View File

@ -28,6 +28,8 @@ type irisControlPlugin struct {
//infos //infos
routes *routesinfo.Plugin routes *routesinfo.Plugin
plugins []PluginInfo plugins []PluginInfo
// last time the server was on
lastOperationDate time.Time
// //
authFunc iris.HandlerFunc authFunc iris.HandlerFunc
@ -88,6 +90,7 @@ func (i *irisControlPlugin) PostListen(s *iris.Iris) {
if i.station == nil { if i.station == nil {
i.station = s i.station = s
i.stationServer = i.station.Server() i.stationServer = i.station.Server()
i.lastOperationDate = time.Now()
i.startControlPanel() i.startControlPanel()
} }
@ -106,6 +109,7 @@ func (i *irisControlPlugin) Destroy() {
i.options = config.IrisControl{} i.options = config.IrisControl{}
i.routes = nil i.routes = nil
i.station = nil i.station = nil
i.lastOperationDate = config.CookieExpireNever
i.server.Close() i.server.Close()
i.pluginContainer = nil i.pluginContainer = nil
i.authFunc = nil i.authFunc = nil

View File

@ -157,6 +157,7 @@ func (s *Server) listenUnix() (err error) {
err = ErrServerRemoveUnix.Format(s.Config.ListeningAddr, errOs.Error()) err = ErrServerRemoveUnix.Format(s.Config.ListeningAddr, errOs.Error())
return return
} }
//
s.listener, err = net.Listen("unix", s.Config.ListeningAddr) s.listener, err = net.Listen("unix", s.Config.ListeningAddr)
if err != nil { if err != nil {
@ -201,6 +202,7 @@ func (s *Server) CloseServer() error {
} }
if s.listener != nil { if s.listener != nil {
s.started = false
return s.listener.Close() return s.listener.Close()
} }
return nil return nil