diff --git a/models/template_context.go b/models/template_context.go index 96e03f3e..af0cae91 100644 --- a/models/template_context.go +++ b/models/template_context.go @@ -6,6 +6,7 @@ import ( "net/url" "path" "text/template" + "time" ) // TemplateContext is an interface that allows both campaigns and email @@ -24,6 +25,7 @@ type PhishingTemplateContext struct { TrackingURL string RId string BaseURL string + Now time.Time BaseRecipient } @@ -66,6 +68,7 @@ func NewPhishingTemplateContext(ctx TemplateContext, r BaseRecipient, rid string Tracker: "", From: fn, RId: rid, + Now: time.Now(), }, nil } @@ -73,7 +76,12 @@ func NewPhishingTemplateContext(ctx TemplateContext, r BaseRecipient, rid string // template body and data. func ExecuteTemplate(text string, data interface{}) (string, error) { buff := bytes.Buffer{} - tmpl, err := template.New("template").Parse(text) + funcMap := template.FuncMap{ + "date": time.Parse, + "duration": time.ParseDuration, + "location": time.LoadLocation, + } + tmpl, err := template.New("template").Funcs(funcMap).Parse(text) if err != nil { return buff.String(), err } diff --git a/models/template_context_test.go b/models/template_context_test.go index 0b6ac4e1..018df601 100644 --- a/models/template_context_test.go +++ b/models/template_context_test.go @@ -43,5 +43,6 @@ func (s *ModelsSuite) TestNewTemplateContext(c *check.C) { expected.Tracker = "" got, err := NewPhishingTemplateContext(ctx, r.BaseRecipient, r.RId) c.Assert(err, check.Equals, nil) + expected.Now = got.Now c.Assert(got, check.DeepEquals, expected) }