mirror of https://github.com/gophish/gophish
Fixed template validation to better support the all the possible template tags. Fixes #1189
parent
159ea126a0
commit
0c5925aeec
|
@ -36,31 +36,28 @@ func (t *Template) Validate() error {
|
||||||
}
|
}
|
||||||
// Test that the variables used in the template
|
// Test that the variables used in the template
|
||||||
// validate with no issues
|
// validate with no issues
|
||||||
td := struct {
|
vc := ValidationContext{
|
||||||
Result
|
FromAddress: "foo@bar.com",
|
||||||
URL string
|
BaseURL: "http://example.com",
|
||||||
TrackingURL string
|
}
|
||||||
Tracker string
|
td := Result{
|
||||||
From string
|
|
||||||
}{
|
|
||||||
Result{
|
|
||||||
BaseRecipient: BaseRecipient{
|
BaseRecipient: BaseRecipient{
|
||||||
Email: "foo@bar.com",
|
Email: "foo@bar.com",
|
||||||
FirstName: "Foo",
|
FirstName: "Foo",
|
||||||
LastName: "Bar",
|
LastName: "Bar",
|
||||||
Position: "Test",
|
Position: "Test",
|
||||||
},
|
},
|
||||||
},
|
RId: "123456",
|
||||||
"http://foo.bar",
|
|
||||||
"http://foo.bar/track",
|
|
||||||
"<img src='http://foo.bar/track",
|
|
||||||
"John Doe <foo@bar.com>",
|
|
||||||
}
|
}
|
||||||
_, err := ExecuteTemplate(t.HTML, td)
|
ptx, err := NewPhishingTemplateContext(vc, td.BaseRecipient, td.RId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = ExecuteTemplate(t.Text, td)
|
_, err = ExecuteTemplate(t.HTML, ptx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = ExecuteTemplate(t.Text, ptx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,20 @@ type TemplateContext interface {
|
||||||
getBaseURL() string
|
getBaseURL() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidationContext is used for validating templates and pages
|
||||||
|
type ValidationContext struct {
|
||||||
|
FromAddress string
|
||||||
|
BaseURL string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vc ValidationContext) getFromAddress() string {
|
||||||
|
return vc.FromAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vc ValidationContext) getBaseURL() string {
|
||||||
|
return vc.BaseURL
|
||||||
|
}
|
||||||
|
|
||||||
// PhishingTemplateContext is the context that is sent to any template, such
|
// PhishingTemplateContext is the context that is sent to any template, such
|
||||||
// as the email or landing page content.
|
// as the email or landing page content.
|
||||||
type PhishingTemplateContext struct {
|
type PhishingTemplateContext struct {
|
||||||
|
|
Loading…
Reference in New Issue