mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 08:44:14 +01:00
better (?) limit email formatting (#279)
This commit is contained in:
parent
2d16c87c3d
commit
5146ca8f24
@ -135,8 +135,11 @@
|
||||
<img src="https://zrok.io/wp-content/uploads/2023/03/warning.jpg" width="363px" height="500px" style="padding-bottom: 10px;"/>
|
||||
</div>
|
||||
<div class="cta" style="text-align: center;">
|
||||
<p style="text-align: center;">Your account is reaching a transfer limit, {{ .EmailAddress }}.</p>
|
||||
<p style="text-align: center;">{{ .Detail }}</p>
|
||||
<h3 style="text-align: center;">Your account is reaching a transfer limit, {{ .EmailAddress }}.</h3>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ .Detail }}
|
||||
</div>
|
||||
|
||||
<table border="0" cellpadding="0" cellspacing="0" align="center" class="about">
|
||||
|
@ -3,7 +3,7 @@ package emailUi
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/pkg/errors"
|
||||
"html/template"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type WarningEmail struct {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package limits
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/zrok/controller/emailUi"
|
||||
@ -36,9 +35,11 @@ func (a *accountWarningAction) HandleAccount(acct *store.Account, rxBytes, txByt
|
||||
if limit.Limit.Total != Unlimited {
|
||||
totalLimit = util.BytesToSize(limit.Limit.Total)
|
||||
}
|
||||
detail := fmt.Sprintf("Your account has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes)) +
|
||||
fmt.Sprintf(" This zrok instance only allows an account to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period) +
|
||||
fmt.Sprintf(" If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit)", limit.Period)
|
||||
|
||||
detail := newDetailMessage()
|
||||
detail = detail.append("Your account has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
|
||||
detail = detail.append("This zrok instance only allows an account to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period)
|
||||
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit)", limit.Period)
|
||||
|
||||
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
|
||||
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package limits
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/zrok/build"
|
||||
"github.com/openziti/zrok/controller/emailUi"
|
||||
"github.com/pkg/errors"
|
||||
@ -8,17 +9,48 @@ import (
|
||||
"github.com/wneessen/go-mail"
|
||||
)
|
||||
|
||||
func sendLimitWarningEmail(cfg *emailUi.Config, emailTo, detail string) error {
|
||||
type detailMessage struct {
|
||||
lines []string
|
||||
}
|
||||
|
||||
func newDetailMessage() *detailMessage {
|
||||
return &detailMessage{}
|
||||
}
|
||||
|
||||
func (m *detailMessage) append(msg string, args ...interface{}) *detailMessage {
|
||||
m.lines = append(m.lines, fmt.Sprintf(msg, args...))
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *detailMessage) html() string {
|
||||
out := ""
|
||||
for i := range m.lines {
|
||||
out += fmt.Sprintf("<p style=\"text-align: left;\">%s</p>\n", m.lines[i])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (m *detailMessage) plain() string {
|
||||
out := ""
|
||||
for i := range m.lines {
|
||||
out += fmt.Sprintf("%s\n\n", m.lines[i])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func sendLimitWarningEmail(cfg *emailUi.Config, emailTo string, d *detailMessage) error {
|
||||
emailData := &emailUi.WarningEmail{
|
||||
EmailAddress: emailTo,
|
||||
Detail: detail,
|
||||
Version: build.String(),
|
||||
}
|
||||
|
||||
emailData.Detail = d.plain()
|
||||
plainBody, err := emailData.MergeTemplate("limitWarning.gotext")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
emailData.Detail = d.html()
|
||||
htmlBody, err := emailData.MergeTemplate("limitWarning.gohtml")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1,7 +1,6 @@
|
||||
package limits
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/zrok/controller/emailUi"
|
||||
@ -42,9 +41,11 @@ func (a *environmentWarningAction) HandleEnvironment(env *store.Environment, rxB
|
||||
if limit.Limit.Total != Unlimited {
|
||||
totalLimit = util.BytesToSize(limit.Limit.Total)
|
||||
}
|
||||
detail := fmt.Sprintf("Your environment '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", env.Description, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes)) +
|
||||
fmt.Sprintf(" This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period) +
|
||||
fmt.Sprintf(" If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period)
|
||||
|
||||
detail := newDetailMessage()
|
||||
detail = detail.append("Your environment '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", env.Description, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
|
||||
detail = detail.append("This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period)
|
||||
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period)
|
||||
|
||||
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
|
||||
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package limits
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/zrok/controller/emailUi"
|
||||
@ -47,9 +46,11 @@ func (a *shareWarningAction) HandleShare(shr *store.Share, rxBytes, txBytes int6
|
||||
if limit.Limit.Total != Unlimited {
|
||||
totalLimit = util.BytesToSize(limit.Limit.Total)
|
||||
}
|
||||
detail := fmt.Sprintf("Your share '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", shr.Token, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes)) +
|
||||
fmt.Sprintf(" This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period) +
|
||||
fmt.Sprintf(" If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period)
|
||||
|
||||
detail := newDetailMessage()
|
||||
detail = detail.append("Your share '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", shr.Token, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
|
||||
detail = detail.append("This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period)
|
||||
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period)
|
||||
|
||||
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
|
||||
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
||||
|
Loading…
Reference in New Issue
Block a user