1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2025-01-07 17:00:11 +00:00

Compare commits

..

No commits in common. "94e3c13b3e9fa4f4b0a963f0debfda7434329baa" and "0bf8cd65cdc3b7cc1f89a0d66a6892649edd6776" have entirely different histories.

7 changed files with 10 additions and 42 deletions

View File

@ -154,8 +154,3 @@ See [CONTRIBUTING.md](https://github.com/hrfee/jfa-go/blob/main/CONTRIBUTING.md)
[![Translation status](https://weblate.jfa-go.com/widgets/jfa-go/-/multi-auto.svg)](https://weblate.jfa-go.com/engage/jfa-go/)
For translations, use the weblate instance [here](https://weblate.jfa-go.com/engage/jfa-go/). You can login with github.
#### Sponsors
Big thanks to those who sponsor me. You can see them below:
[<img src="https://sponsors-endpoint.hrfee.pw/sponsor/avatar/0" width="35">](https://sponsors-endpoint.hrfee.pw/sponsor/profile/0)

17
api.go
View File

@ -1715,22 +1715,11 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
"policy": map[string]string{},
"homescreen": map[string]string{},
}
/* Jellyfin doesn't seem to like too many of these requests sent in succession
and can crash and mess up its database. Issue #160 says this occurs when more
than 100 users are modified. A delay totalling 500ms between requests is used
if so. */
var shouldDelay bool = len(req.ApplyTo) >= 100
if shouldDelay {
app.debug.Println("Adding delay between requests for large batch")
}
for _, id := range req.ApplyTo {
status, err := app.jf.SetPolicy(id, policy)
if !(status == 200 || status == 204) || err != nil {
errors["policy"][id] = fmt.Sprintf("%d: %s", status, err)
}
if shouldDelay {
time.Sleep(250 * time.Millisecond)
}
if req.Homescreen {
status, err = app.jf.SetConfiguration(id, configuration)
errorString := ""
@ -1746,9 +1735,6 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
errors["homescreen"][id] = errorString
}
}
if shouldDelay {
time.Sleep(250 * time.Millisecond)
}
}
code := 200
if len(errors["policy"]) == len(req.ApplyTo) || len(errors["homescreen"]) == len(req.ApplyTo) {
@ -1945,8 +1931,6 @@ func (app *appContext) GetCustomEmails(gc *gin.Context) {
func (app *appContext) getCustomEmail(id string) *customEmail {
switch id {
case "Announcement":
return &customEmail{}
case "UserCreated":
return &app.storage.customEmails.UserCreated
case "InviteExpiry":
@ -2057,7 +2041,6 @@ func (app *appContext) GetCustomEmailTemplate(gc *gin.Context) {
emailAddress := app.storage.lang.Email[lang].Strings.get("emailAddress")
email := app.getCustomEmail(id)
if email == nil {
app.err.Printf("Failed to get custom email with ID \"%s\"", id)
respondBool(400, false, gc)
return
}

View File

@ -72,7 +72,6 @@ func (app *appContext) loadConfig() error {
app.MustSetValue("deletion", "email_text", "jfa-go:"+"deleted.txt")
app.MustSetValue("smtp", "hello_hostname", "localhost")
app.MustSetValue("smtp", "cert_validation", "true")
jfUrl := app.config.Section("jellyfin").Key("server").String()
if !(strings.HasPrefix(jfUrl, "http://") || strings.HasPrefix(jfUrl, "https://")) {

View File

@ -552,15 +552,6 @@
"type": "text",
"value": "",
"description": "Use if your SMTP server's SSL Certificate is not trusted by the system."
},
"cert_validation": {
"name": "Verify certificate",
"required": false,
"requires_restart": false,
"advanced": true,
"type": "bool",
"value": true,
"description": "Warning, disabling this makes you much more vulnerable to man-in-the-middle attacks"
}
}
},

View File

@ -84,7 +84,7 @@ func NewEmailer(app *appContext) *Emailer {
if username == "" && password != "" {
username = emailer.fromAddr
}
err := emailer.NewSMTP(app.config.Section("smtp").Key("server").String(), app.config.Section("smtp").Key("port").MustInt(465), username, password, sslTLS, app.config.Section("smtp").Key("ssl_cert").MustString(""), app.config.Section("smtp").Key("hello_hostname").String(), app.config.Section("smtp").Key("cert_validation").MustBool(true))
err := emailer.NewSMTP(app.config.Section("smtp").Key("server").String(), app.config.Section("smtp").Key("port").MustInt(465), username, password, sslTLS, app.config.Section("smtp").Key("ssl_cert").MustString(""), app.config.Section("smtp").Key("hello_hostname").String())
if err != nil {
app.err.Printf("Error while initiating SMTP mailer: %v", err)
}
@ -110,7 +110,7 @@ type SMTP struct {
}
// NewSMTP returns an SMTP emailClient.
func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string, helloHostname string, validateCertificate bool) (err error) {
func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string, helloHostname string) (err error) {
sender := &SMTP{}
sender.Client = sMail.NewSMTPClient()
if sslTLS {
@ -131,7 +131,7 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
// x509.SystemCertPool is unavailable on windows
if PLATFORM == "windows" {
sender.Client.TLSConfig = &tls.Config{
InsecureSkipVerify: !validateCertificate,
InsecureSkipVerify: false,
ServerName: server,
}
emailer.sender = sender
@ -149,7 +149,7 @@ func (emailer *Emailer) NewSMTP(server string, port int, username, password stri
}
}
sender.Client.TLSConfig = &tls.Config{
InsecureSkipVerify: !validateCertificate,
InsecureSkipVerify: false,
ServerName: server,
RootCAs: rootCAs,
}
@ -170,9 +170,11 @@ func (sm *SMTP) Send(fromName, fromAddr string, email *Message, address ...strin
e.SetFrom(from)
e.SetSubject(email.Subject)
e.AddTo(address...)
e.SetBody(sMail.TextPlain, email.Text)
if email.HTML != "" {
e.AddAlternative(sMail.TextHTML, email.HTML)
if email.HTML == "" {
e.SetBody(sMail.TextPlain, email.Text)
} else {
e.SetBody(sMail.TextHTML, email.HTML)
e.AddAlternative(sMail.TextPlain, email.Text)
}
err = e.Send(cli)
return err

2
go.mod
View File

@ -52,7 +52,7 @@ require (
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2
github.com/swaggo/gin-swagger v1.3.2
github.com/swaggo/swag v1.7.4 // indirect
github.com/swaggo/swag v1.7.3 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/tidwall/sjson v1.2.2 // indirect
github.com/ugorji/go v1.2.6 // indirect

2
go.sum
View File

@ -243,8 +243,6 @@ github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+t
github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc=
github.com/swaggo/swag v1.7.3 h1:ucB7irEdRrhjmW+Z1Ss4GjO68oPKQFjSgOR8BCAvcbU=
github.com/swaggo/swag v1.7.3/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI=
github.com/swaggo/swag v1.7.4 h1:up+ixy8yOqJKiFcuhMgkuYuF4xnevuhnFAXXF8OSfNg=
github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI=
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=