feat: 通过传递客户端Cookie的方式使web终端兼容被Cloudflare Access保护的面板

This commit is contained in:
Akkia 2022-04-13 12:27:40 +08:00
parent 50a18daf05
commit 913c3da79b
No known key found for this signature in database
GPG Key ID: 464BA42A151C1E0F
3 changed files with 11 additions and 2 deletions

View File

@ -433,6 +433,12 @@ func handleTerminalTask(task *pb.Task) {
}
header := http.Header{}
header.Add("Secret", agentCliParam.ClientSecret)
// 目前只兼容Cloudflare验证
// 后续可能需要兼容更多的Cookie验证情况
if terminal.Cookie != "" {
cfCookie := fmt.Sprintf("CF_Authorization=%s", terminal.Cookie)
header.Add("Cookie", cfCookie)
}
conn, _, err := websocket.DefaultDialer.Dial(fmt.Sprintf("%s://%s/terminal/%s", protocol, terminal.Host, terminal.Session), header)
if err != nil {
println("Terminal 连接失败:", err)

View File

@ -275,13 +275,14 @@ func (cp *commonPage) terminal(c *gin.Context) {
}, true)
return
}
var cloudflareCookies string
cloudflareCookies, _ = c.Cookie("CF_Authorization")
terminalData, _ := utils.Json.Marshal(&model.TerminalTask{
Host: terminal.host,
UseSSL: terminal.useSSL,
Session: terminalID,
Cookie: cloudflareCookies,
})
if err := server.TaskStream.Send(&proto.Task{
Type: model.TaskTypeTerminal,
Data: string(terminalData),

View File

@ -27,6 +27,8 @@ type TerminalTask struct {
UseSSL bool `json:"use_ssl,omitempty"`
// 会话标识
Session string `json:"session,omitempty"`
// Agent在连接Server时需要的额外Cookie信息
Cookie string `json:"cookie,omitempty"`
}
const (