Merge a4b35ba0a6
into fdd7bf41c0
This commit is contained in:
commit
a563f4569d
@ -64,6 +64,7 @@ var SMTPPort = 587
|
|||||||
var SMTPAccount = ""
|
var SMTPAccount = ""
|
||||||
var SMTPFrom = ""
|
var SMTPFrom = ""
|
||||||
var SMTPToken = ""
|
var SMTPToken = ""
|
||||||
|
var SMTPAuthLoginEnabled = false
|
||||||
|
|
||||||
var GitHubClientId = ""
|
var GitHubClientId = ""
|
||||||
var GitHubClientSecret = ""
|
var GitHubClientSecret = ""
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/songquanpeng/one-api/common/config"
|
"github.com/songquanpeng/one-api/common/config"
|
||||||
"net"
|
"net"
|
||||||
@ -12,6 +13,32 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type loginAuth struct {
|
||||||
|
username, password string
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoginAuth(username, password string) smtp.Auth {
|
||||||
|
return &loginAuth{username, password}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *loginAuth) Start(_ *smtp.ServerInfo) (string, []byte, error) {
|
||||||
|
return "LOGIN", []byte(a.username), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
||||||
|
if more {
|
||||||
|
switch string(fromServer) {
|
||||||
|
case "Username:":
|
||||||
|
return []byte(a.username), nil
|
||||||
|
case "Password:":
|
||||||
|
return []byte(a.password), nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("unknown command from server during login auth")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func shouldAuth() bool {
|
func shouldAuth() bool {
|
||||||
return config.SMTPAccount != "" || config.SMTPToken != ""
|
return config.SMTPAccount != "" || config.SMTPToken != ""
|
||||||
}
|
}
|
||||||
@ -47,7 +74,13 @@ func SendEmail(subject string, receiver string, content string) error {
|
|||||||
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
|
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
|
||||||
receiver, config.SystemName, config.SMTPFrom, encodedSubject, messageId, time.Now().Format(time.RFC1123Z), content))
|
receiver, config.SystemName, config.SMTPFrom, encodedSubject, messageId, time.Now().Format(time.RFC1123Z), content))
|
||||||
|
|
||||||
auth := smtp.PlainAuth("", config.SMTPAccount, config.SMTPToken, config.SMTPServer)
|
var auth smtp.Auth
|
||||||
|
if config.SMTPAuthLoginEnabled {
|
||||||
|
auth = LoginAuth(config.SMTPAccount, config.SMTPToken)
|
||||||
|
} else {
|
||||||
|
auth = smtp.PlainAuth("", config.SMTPAccount, config.SMTPToken, config.SMTPServer)
|
||||||
|
}
|
||||||
|
|
||||||
addr := fmt.Sprintf("%s:%d", config.SMTPServer, config.SMTPPort)
|
addr := fmt.Sprintf("%s:%d", config.SMTPServer, config.SMTPPort)
|
||||||
to := strings.Split(receiver, ";")
|
to := strings.Split(receiver, ";")
|
||||||
|
|
||||||
|
@ -330,6 +330,7 @@
|
|||||||
"通常和邮箱地址保持一致": "Usually consistent with the email address",
|
"通常和邮箱地址保持一致": "Usually consistent with the email address",
|
||||||
"SMTP 访问凭证": "SMTP Access Credential",
|
"SMTP 访问凭证": "SMTP Access Credential",
|
||||||
"敏感信息不会发送到前端显示": "Sensitive information will not be displayed in the frontend",
|
"敏感信息不会发送到前端显示": "Sensitive information will not be displayed in the frontend",
|
||||||
|
"使用 SMTP LOGIN 认证方式": "Use LOGIN as SMTP authentication method",
|
||||||
"保存 SMTP 设置": "Save SMTP Settings",
|
"保存 SMTP 设置": "Save SMTP Settings",
|
||||||
"配置 GitHub OAuth App": "Configure GitHub OAuth App",
|
"配置 GitHub OAuth App": "Configure GitHub OAuth App",
|
||||||
"用以支持通过 GitHub 进行登录注册": "To support login & registration via GitHub",
|
"用以支持通过 GitHub 进行登录注册": "To support login & registration via GitHub",
|
||||||
|
@ -46,6 +46,7 @@ func InitOptionMap() {
|
|||||||
config.OptionMap["SMTPPort"] = strconv.Itoa(config.SMTPPort)
|
config.OptionMap["SMTPPort"] = strconv.Itoa(config.SMTPPort)
|
||||||
config.OptionMap["SMTPAccount"] = ""
|
config.OptionMap["SMTPAccount"] = ""
|
||||||
config.OptionMap["SMTPToken"] = ""
|
config.OptionMap["SMTPToken"] = ""
|
||||||
|
config.OptionMap["SMTPAuthLoginEnabled"] = strconv.FormatBool(config.SMTPAuthLoginEnabled)
|
||||||
config.OptionMap["Notice"] = ""
|
config.OptionMap["Notice"] = ""
|
||||||
config.OptionMap["About"] = ""
|
config.OptionMap["About"] = ""
|
||||||
config.OptionMap["HomePageContent"] = ""
|
config.OptionMap["HomePageContent"] = ""
|
||||||
@ -153,6 +154,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
config.DisplayInCurrencyEnabled = boolValue
|
config.DisplayInCurrencyEnabled = boolValue
|
||||||
case "DisplayTokenStatEnabled":
|
case "DisplayTokenStatEnabled":
|
||||||
config.DisplayTokenStatEnabled = boolValue
|
config.DisplayTokenStatEnabled = boolValue
|
||||||
|
case "SMTPAuthLoginEnabled":
|
||||||
|
config.SMTPAuthLoginEnabled = boolValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch key {
|
switch key {
|
||||||
|
@ -18,6 +18,7 @@ const SystemSetting = () => {
|
|||||||
SMTPAccount: '',
|
SMTPAccount: '',
|
||||||
SMTPFrom: '',
|
SMTPFrom: '',
|
||||||
SMTPToken: '',
|
SMTPToken: '',
|
||||||
|
SMTPAuthLoginEnabled: '',
|
||||||
ServerAddress: '',
|
ServerAddress: '',
|
||||||
Footer: '',
|
Footer: '',
|
||||||
WeChatAuthEnabled: '',
|
WeChatAuthEnabled: '',
|
||||||
@ -76,6 +77,7 @@ const SystemSetting = () => {
|
|||||||
case 'TurnstileCheckEnabled':
|
case 'TurnstileCheckEnabled':
|
||||||
case 'EmailDomainRestrictionEnabled':
|
case 'EmailDomainRestrictionEnabled':
|
||||||
case 'RegisterEnabled':
|
case 'RegisterEnabled':
|
||||||
|
case 'SMTPAuthLoginEnabled':
|
||||||
value = inputs[key] === 'true' ? 'false' : 'true';
|
value = inputs[key] === 'true' ? 'false' : 'true';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -107,7 +109,7 @@ const SystemSetting = () => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
name === 'Notice' ||
|
name === 'Notice' ||
|
||||||
name.startsWith('SMTP') ||
|
(name.startsWith('SMTP') && !name.endsWith('Enabled')) ||
|
||||||
name === 'ServerAddress' ||
|
name === 'ServerAddress' ||
|
||||||
name === 'GitHubClientId' ||
|
name === 'GitHubClientId' ||
|
||||||
name === 'GitHubClientSecret' ||
|
name === 'GitHubClientSecret' ||
|
||||||
@ -444,6 +446,12 @@ const SystemSetting = () => {
|
|||||||
checked={inputs.RegisterEnabled === 'true'}
|
checked={inputs.RegisterEnabled === 'true'}
|
||||||
placeholder='敏感信息不会发送到前端显示'
|
placeholder='敏感信息不会发送到前端显示'
|
||||||
/>
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.SMTPAuthLoginEnabled === 'true'}
|
||||||
|
label='使用 SMTP LOGIN 认证方式'
|
||||||
|
name='SMTPAuthLoginEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
|
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
Loading…
Reference in New Issue
Block a user