Compare commits

...
5 Commits
Author SHA1 Message Date
lejianwen 9d08c61390 fix: Normal user can not change the name of their own address book (#341) 2025-08-10 11:17:51 +08:00
Tao Chen 6f092472b1 feat: Optimize login workflow (#345)
* add "disable_pwd" and "auto_oidc" at /admin/login-options

* fix: build RedirectURL by host and scheme, not Origin
2025-07-31 10:46:11 +08:00
caicob 4876746f7a docs: README_EN.md (#340) 2025-07-31 10:42:56 +08:00
startgo 05d2d1642a feat: Update zh_TW.toml (#322)
Corrected translation to match Taiwanese Traditional Chinese usage
2025-07-19 21:08:40 +08:00
lejianwen 59fdd6424b feat(captcha): The captcha generates uppercase letter images, but it can only recognize them as lowercase (#319) 2025-07-14 20:36:33 +08:00
6 changed files with 88 additions and 62 deletions
+2 -3
View File
@@ -164,8 +164,7 @@ The table below does not list all configurations. Please refer to the configurat
| RUSTDESK_API_APP_DISABLE_PWD_LOGIN | disable password login | `false` | | RUSTDESK_API_APP_DISABLE_PWD_LOGIN | disable password login | `false` |
| RUSTDESK_API_APP_REGISTER_STATUS | register user default status ; 1 enabled , 2 disabled ; default 1 | `1` | | RUSTDESK_API_APP_REGISTER_STATUS | register user default status ; 1 enabled , 2 disabled ; default 1 | `1` |
| RUSTDESK_API_APP_CAPTCHA_THRESHOLD | captcha threshold; -1 disabled, 0 always enable, >0 threshold ;default `3` | `3` | | RUSTDESK_API_APP_CAPTCHA_THRESHOLD | captcha threshold; -1 disabled, 0 always enable, >0 threshold ;default `3` | `3` |
| RUSTDESK_API_APP_BAN_THRESHOLD | ban ip threshold; 0 disabled, >0 threshold ; default `0` | RUSTDESK_API_APP_BAN_THRESHOLD | ban ip threshold; 0 disabled, >0 threshold ; default `0` | `0` |
| `0` |
| ----- ADMIN Configuration----- | ---------- | ---------- | | ----- ADMIN Configuration----- | ---------- | ---------- |
| RUSTDESK_API_ADMIN_TITLE | Admin Title | `RustDesk Api Admin` | | RUSTDESK_API_ADMIN_TITLE | Admin Title | `RustDesk Api Admin` |
| RUSTDESK_API_ADMIN_HELLO | Admin welcome message, you can use `html` | | | RUSTDESK_API_ADMIN_HELLO | Admin welcome message, you can use `html` | |
@@ -325,4 +324,4 @@ Thanks to everyone who contributed!
<img src="https://contrib.rocks/image?repo=lejianwen/rustdesk-api" /> <img src="https://contrib.rocks/image?repo=lejianwen/rustdesk-api" />
</a> </a>
## Thanks for your support! If you find this project useful, please give it a ⭐️. Thank you! ## Thanks for your support! If you find this project useful, please give it a ⭐️. Thank you!
+2
View File
@@ -169,6 +169,8 @@ func (ct *Login) LoginOptions(c *gin.Context) {
"ops": ops, "ops": ops,
"register": global.Config.App.Register, "register": global.Config.App.Register,
"need_captcha": needCaptcha, "need_captcha": needCaptcha,
"disable_pwd": global.Config.App.DisablePwdLogin,
"auto_oidc": global.Config.App.DisablePwdLogin && len(ops) == 1,
}) })
} }
@@ -98,10 +98,10 @@ func (abc *AddressBookCollection) Update(c *gin.Context) {
return return
} }
u := service.AllService.UserService.CurUser(c) u := service.AllService.UserService.CurUser(c)
if f.UserId != u.Id { //if f.UserId != u.Id {
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess")) // response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
return // return
} //}
ex := service.AllService.AddressBookService.CollectionInfoById(f.Id) ex := service.AllService.AddressBookService.CollectionInfoById(f.Id)
if ex.Id == 0 { if ex.Id == 0 {
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
+56 -49
View File
@@ -5,8 +5,8 @@ other = "測試2 {{.P0}}"
[ParamsError] [ParamsError]
description = "Params validation failed." description = "Params validation failed."
one = "引數錯誤。" one = "參數驗證失敗。"
other = "引數錯誤。" other = "參數驗證失敗。"
[OperationFailed] [OperationFailed]
description = "OperationFailed." description = "OperationFailed."
@@ -20,18 +20,18 @@ other = "操作成功。"
[ItemExists] [ItemExists]
description = "Item already exists." description = "Item already exists."
one = "資料已存在。" one = "項目已存在。"
other = "資料已存在。" other = "項目已存在。"
[ItemNotFound] [ItemNotFound]
description = "Item not found." description = "Item not found."
one = "資料不存在。" one = "找不到項目。"
other = "資料不存在。" other = "找不到項目。"
[NoAccess] [NoAccess]
description = "No access." description = "No access."
one = "無許可權。" one = "無權限存取。"
other = "無許可權。" other = "無權限存取。"
[NeedLogin] [NeedLogin]
description = "Need login." description = "Need login."
@@ -50,24 +50,23 @@ other = "系統錯誤。"
[ConfigNotFound] [ConfigNotFound]
description = "Config not found." description = "Config not found."
one = "配置不存在。" one = "找不到設定。"
other = "配置不存在。" other = "找不到設定。"
#授權過期
[OauthExpired] [OauthExpired]
description = "Oauth expired." description = "Oauth expired."
one = "授權過期,請重新授權。" one = "OAuth 已過期,請重。"
other = "授權過期,請重新授權。" other = "OAuth 已過期,請重。"
[OauthFailed] [OauthFailed]
description = "Oauth failed." description = "Oauth failed."
one = "授權失敗。" one = "OAuth 失敗。"
other = "授權失敗。" other = "OAuth 失敗。"
[OauthHasBindOtherUser] [OauthHasBindOtherUser]
description = "Oauth has bind other user." description = "Oauth has bind other user."
one = "授權已繫結其他使用者。" one = "OAuth 已綁定其他使用者。"
other = "授權已繫結其他使用者。" other = "OAuth 已綁定其他使用者。"
[ParamIsEmpty] [ParamIsEmpty]
description = "Param is empty." description = "Param is empty."
@@ -76,56 +75,64 @@ other = "{{.P0}} 為空。"
[BindFail] [BindFail]
description = "Bind fail." description = "Bind fail."
one = "繫結失敗。" one = "綁定失敗。"
other = "繫結失敗。" other = "綁定失敗。"
[BindSuccess] [BindSuccess]
description = "Bind success." description = "Bind success."
one = "繫結成功。" one = "綁定成功。"
other = "繫結成功。" other = "綁定成功。"
[OauthHasBeenSuccess] [OauthHasBeenSuccess]
description = "Oauth has been success." description = "Oauth has been success."
one = "授權已成功。" one = "OAuth 已成功。"
other = "授權已成功。" other = "OAuth 已成功。"
[OauthSuccess] [OauthSuccess]
description = "Oauth success." description = "Oauth success."
one = "授權成功。" one = "OAuth 成功。"
other = "授權成功。" other = "OAuth 成功。"
[OauthRegisterSuccess] [OauthRegisterSuccess]
description = "Oauth register success." description = "Oauth register success."
one = "授權註冊成功。" one = "OAuth 註冊成功。"
other = "授權註冊成功。" other = "OAuth 註冊成功。"
[OauthRegisterFailed] [OauthRegisterFailed]
description = "Oauth register failed." description = "Oauth register failed."
one = "授權註冊失敗。" one = "OAuth 註冊失敗。"
other = "授權註冊失敗。" other = "OAuth 註冊失敗。"
[GetOauthTokenError] [GetOauthTokenError]
description = "Get oauth token error." description = "Get oauth token error."
one = "獲取授權token失敗。" one = "取得 OAuth 權杖錯誤。"
other = "獲取授權token失敗。" other = "取得 OAuth 權杖錯誤。"
[GetOauthUserInfoError] [GetOauthUserInfoError]
description = "Get oauth user info error." description = "Get oauth user info error."
one = "獲取授權使用者資訊失敗。" one = "取得 OAuth 使用者資訊錯誤。"
other = "獲取授權使用者資訊失敗。" other = "取得 OAuth 使用者資訊錯誤。"
[DecodeOauthUserInfoError] [DecodeOauthUserInfoError]
description = "Decode oauth user info error." description = "Decode oauth user info error."
one = "解析授權使用者資訊失敗。" one = "解析 OAuth 使用者資訊錯誤。"
other = "解析授權使用者資訊失敗。" other = "解析 OAuth 使用者資訊錯誤。"
[OldPasswordError] [OldPasswordError]
description = "Old password error." description = "Old password error."
one = "舊密碼錯誤。" one = "舊密碼錯誤。"
other = "舊密碼錯誤。" other = "舊密碼錯誤。"
[DefaultGroup] [DefaultGroup]
description = "Default group." description = "Default group."
one = "預設組" one = "預設組"
other = "預設組" other = "預設組"
[ShareGroup] [ShareGroup]
description = "Share group." description = "Share group."
one = "共享組" one = "共享組"
other = "共享組" other = "共享組"
[RegisterClosed] [RegisterClosed]
description = "Register closed." description = "Register closed."
one = "註冊已關閉。" one = "註冊已關閉。"
@@ -143,20 +150,20 @@ other = "驗證碼錯誤。"
[PwdLoginDisabled] [PwdLoginDisabled]
description = "Password login disabled." description = "Password login disabled."
one = "密碼登錄已禁用。" one = "密碼登入已停用。"
other = "密碼登錄已禁用。" other = "密碼登入已停用。"
[CannotShareToSelf] [CannotShareToSelf]
description = "Cannot share to self." description = "Cannot share to self."
one = "無法享給自己。" one = "無法享給自己。"
other = "無法享給自己。" other = "無法享給自己。"
[Banned] [Banned]
description = "Banned." description = "Banned."
one = "禁止使用。" one = "已被禁用。"
other = "禁止使用。" other = "已被禁用。"
[RegisterSuccessWaitAdminConfirm] [RegisterSuccessWaitAdminConfirm]
description = "Register success wait admin confirm." description = "Register success, wait admin confirm."
one = "註冊成功,等待管理員確認。" one = "註冊成功,等待管理員確認。"
other = "註冊成功,等待管理員確認。" other = "註冊成功,等待管理員確認。"
+22 -5
View File
@@ -180,14 +180,12 @@ func (os *OauthService) GetOauthConfig(c *gin.Context, op string) (err error, oa
if oauthInfo.Id == 0 || oauthInfo.ClientId == "" || oauthInfo.ClientSecret == "" { if oauthInfo.Id == 0 || oauthInfo.ClientId == "" || oauthInfo.ClientSecret == "" {
return errors.New("ConfigNotFound"), nil, nil, nil return errors.New("ConfigNotFound"), nil, nil, nil
} }
host := c.GetHeader("Origin") redirectUrl := os.buildRedirectURL(c)
if host == "" { Logger.Debug("Redirect URL: ", redirectUrl)
host = Config.Rustdesk.ApiServer
}
oauthConfig = &oauth2.Config{ oauthConfig = &oauth2.Config{
ClientID: oauthInfo.ClientId, ClientID: oauthInfo.ClientId,
ClientSecret: oauthInfo.ClientSecret, ClientSecret: oauthInfo.ClientSecret,
RedirectURL: host + "/api/oidc/callback", RedirectURL: redirectUrl,
} }
// Maybe should validate the oauthConfig here // Maybe should validate the oauthConfig here
@@ -529,3 +527,22 @@ func (os *OauthService) getGithubPrimaryEmail(client *http.Client, githubUser *m
return fmt.Errorf("no primary verified email found") return fmt.Errorf("no primary verified email found")
} }
func (os *OauthService) buildRedirectURL(c *gin.Context) string {
baseUrl := Config.Rustdesk.ApiServer
host := c.Request.Host
if host != "" {
scheme := c.GetHeader("X-Forwarded-Proto")
if scheme == "" {
if c.Request.TLS != nil {
scheme = "https"
} else {
scheme = "http"
}
}
baseUrl = fmt.Sprintf("%s://%s", scheme, host)
}
return fmt.Sprintf("%s/api/oidc/callback", baseUrl)
}
+2 -1
View File
@@ -5,7 +5,8 @@ import (
"time" "time"
) )
var capdString = base64Captcha.NewDriverString(50, 150, 0, 5, 4, "123456789abcdefghijklmnopqrstuvwxyz", nil, nil, nil) var capdString = base64Captcha.NewDriverString(50, 150, 0, 5, 4, "123456789abcdefghijklmnopqrstuvwxyz", nil, nil,
[]string{"3Dumb.ttf", "ApothecaryFont.ttf", "Comismsh.ttf", "Flim-Flam.ttf", "RitaSmith.ttf", "wqy-microhei.ttc"})
var capdMath = base64Captcha.NewDriverMath(50, 150, 3, 10, nil, nil, nil) var capdMath = base64Captcha.NewDriverMath(50, 150, 3, 10, nil, nil, nil)