dockerfiles/anylink/server/handler/link_home.go

47 lines
1.2 KiB
Go
Raw Normal View History

2021-06-08 20:45:26 +08:00
package handler
import (
"fmt"
"net/http"
"strings"
"github.com/bjdgyc/anylink/admin"
2022-11-10 15:53:48 +08:00
"github.com/bjdgyc/anylink/dbdata"
2021-06-08 20:45:26 +08:00
)
func LinkHome(w http.ResponseWriter, r *http.Request) {
// fmt.Println(r.RemoteAddr)
// hu, _ := httputil.DumpRequest(r, true)
// fmt.Println("DumpHome: ", string(hu))
2023-04-26 22:17:10 +08:00
w.Header().Set("Server", "AnyLinkOpenSource")
2021-06-08 20:45:26 +08:00
connection := strings.ToLower(r.Header.Get("Connection"))
userAgent := strings.ToLower(r.UserAgent())
2021-12-29 11:43:26 +08:00
if connection == "close" && (strings.Contains(userAgent, "anyconnect") || strings.Contains(userAgent, "openconnect")) {
2021-06-08 20:45:26 +08:00
w.Header().Set("Connection", "close")
w.WriteHeader(http.StatusBadRequest)
return
}
2022-11-10 15:53:48 +08:00
index := &dbdata.SettingOther{}
2023-04-26 22:17:10 +08:00
if err := dbdata.SettingGet(index); err != nil {
return
}
2021-06-08 20:45:26 +08:00
w.WriteHeader(http.StatusOK)
2022-11-10 15:53:48 +08:00
if index.Homeindex == "" {
index.Homeindex = "AnyLink 是一个企业级远程办公 SSL VPN 软件,可以支持多人同时在线使用。"
2023-04-26 22:17:10 +08:00
}
2022-11-10 15:53:48 +08:00
fmt.Fprintln(w, index.Homeindex)
2021-06-08 20:45:26 +08:00
}
func LinkOtpQr(w http.ResponseWriter, r *http.Request) {
_ = r.ParseForm()
idS := r.FormValue("id")
jwtToken := r.FormValue("jwt")
data, err := admin.GetJwtData(jwtToken)
if err != nil || idS != fmt.Sprint(data["id"]) {
w.WriteHeader(http.StatusForbidden)
return
}
admin.UserOtpQr(w, r)
}