mirror of
https://github.com/openziti/zrok.git
synced 2025-08-19 12:24:37 +02:00
better (?) limit email formatting (#279)
This commit is contained in:
@@ -135,8 +135,11 @@
|
|||||||
<img src="https://zrok.io/wp-content/uploads/2023/03/warning.jpg" width="363px" height="500px" style="padding-bottom: 10px;"/>
|
<img src="https://zrok.io/wp-content/uploads/2023/03/warning.jpg" width="363px" height="500px" style="padding-bottom: 10px;"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="cta" style="text-align: center;">
|
<div class="cta" style="text-align: center;">
|
||||||
<p style="text-align: center;">Your account is reaching a transfer limit, {{ .EmailAddress }}.</p>
|
<h3 style="text-align: center;">Your account is reaching a transfer limit, {{ .EmailAddress }}.</h3>
|
||||||
<p style="text-align: center;">{{ .Detail }}</p>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{ .Detail }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table border="0" cellpadding="0" cellspacing="0" align="center" class="about">
|
<table border="0" cellpadding="0" cellspacing="0" align="center" class="about">
|
||||||
|
@@ -3,7 +3,7 @@ package emailUi
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"html/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WarningEmail struct {
|
type WarningEmail struct {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package limits
|
package limits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/openziti/edge/rest_management_api_client"
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
"github.com/openziti/zrok/controller/emailUi"
|
"github.com/openziti/zrok/controller/emailUi"
|
||||||
@@ -36,9 +35,11 @@ func (a *accountWarningAction) HandleAccount(acct *store.Account, rxBytes, txByt
|
|||||||
if limit.Limit.Total != Unlimited {
|
if limit.Limit.Total != Unlimited {
|
||||||
totalLimit = util.BytesToSize(limit.Limit.Total)
|
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) +
|
detail := newDetailMessage()
|
||||||
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 = 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 {
|
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
|
||||||
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package limits
|
package limits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/openziti/zrok/build"
|
"github.com/openziti/zrok/build"
|
||||||
"github.com/openziti/zrok/controller/emailUi"
|
"github.com/openziti/zrok/controller/emailUi"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -8,17 +9,48 @@ import (
|
|||||||
"github.com/wneessen/go-mail"
|
"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{
|
emailData := &emailUi.WarningEmail{
|
||||||
EmailAddress: emailTo,
|
EmailAddress: emailTo,
|
||||||
Detail: detail,
|
|
||||||
Version: build.String(),
|
Version: build.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emailData.Detail = d.plain()
|
||||||
plainBody, err := emailData.MergeTemplate("limitWarning.gotext")
|
plainBody, err := emailData.MergeTemplate("limitWarning.gotext")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emailData.Detail = d.html()
|
||||||
htmlBody, err := emailData.MergeTemplate("limitWarning.gohtml")
|
htmlBody, err := emailData.MergeTemplate("limitWarning.gohtml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package limits
|
package limits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/openziti/edge/rest_management_api_client"
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
"github.com/openziti/zrok/controller/emailUi"
|
"github.com/openziti/zrok/controller/emailUi"
|
||||||
@@ -42,9 +41,11 @@ func (a *environmentWarningAction) HandleEnvironment(env *store.Environment, rxB
|
|||||||
if limit.Limit.Total != Unlimited {
|
if limit.Limit.Total != Unlimited {
|
||||||
totalLimit = util.BytesToSize(limit.Limit.Total)
|
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) +
|
detail := newDetailMessage()
|
||||||
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 = 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 {
|
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
|
||||||
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package limits
|
package limits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/openziti/edge/rest_management_api_client"
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
"github.com/openziti/zrok/controller/emailUi"
|
"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 {
|
if limit.Limit.Total != Unlimited {
|
||||||
totalLimit = util.BytesToSize(limit.Limit.Total)
|
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) +
|
detail := newDetailMessage()
|
||||||
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 = 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 {
|
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
|
||||||
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
|
||||||
|
Reference in New Issue
Block a user