-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.go
103 lines (94 loc) · 2.01 KB
/
page.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package send
import (
_ "embed"
"html/template"
"net/http"
"github.com/mikhailche/spammer/pages/base"
)
//go:embed index.html
var install_html string
var senderTemplate *template.Template
type FormField struct {
ID string
Name string
Value string
}
func (f FormField) String() string {
return f.Value
}
type SendForm struct {
SMTP struct {
Host string
Port string
SSL string
Login string
Password string
}
Sender struct {
Name string
Email string
}
Recipient struct {
Email string
}
Message struct {
Subject string
Text string
}
}
type TemplateData struct {
Body SendForm
}
func init() {
var err error
senderTemplate, err = base.Page(install_html)
if err != nil {
panic(err)
}
}
func Page(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(100 * 1024 * 1024) // 100 MB
defer r.Body.Close()
err := senderTemplate.ExecuteTemplate(w, "base", struct {
PageTitle string
Body SendForm
}{
Body: SendForm{
SMTP: struct {
Host string
Port string
SSL string
Login string
Password string
}{
Host: r.FormValue("app-config-smtp-host-name"),
Port: r.FormValue("app-config-smtp-port-name"),
SSL: r.FormValue("app-config-smtp-ssl-name"),
Login: r.FormValue("app-config-smtp-login-name"),
Password: r.FormValue("app-config-smtp-password-name"),
},
Sender: struct {
Name string
Email string
}{
Name: r.FormValue("app-config-sender-name-name"),
Email: r.FormValue("app-config-sender-email-name"),
},
Recipient: struct {
Email string
}{
Email: r.FormValue("app-config-recipient-email-name"),
},
Message: struct {
Subject string
Text string
}{
Subject: r.FormValue("app-config-message-subject-name"),
Text: r.FormValue("app-config-message-text-name"),
},
},
})
if err != nil {
http.Error(w, err.Error(), 500)
}
}