修改profile.xml自动获取hash

This commit is contained in:
bjdgyc
2021-12-31 16:35:33 +08:00
parent e780afe18c
commit 6c5969c5ea
7 changed files with 31 additions and 45 deletions

View File

@@ -14,6 +14,8 @@ import (
"github.com/bjdgyc/anylink/sessdata"
)
var profileHash = ""
func LinkAuth(w http.ResponseWriter, r *http.Request) {
// 判断anyconnect客户端
userAgent := strings.ToLower(r.UserAgent())
@@ -89,7 +91,7 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) {
other := &dbdata.SettingOther{}
_ = dbdata.SettingGet(other)
rd := RequestData{SessionId: sess.Sid, SessionToken: sess.Sid + "@" + sess.Token,
Banner: other.Banner}
Banner: other.Banner, ProfileHash: profileHash}
w.WriteHeader(http.StatusOK)
tplRequest(tpl_complete, w, rd)
base.Debug("login", cr.Auth.Username)
@@ -125,6 +127,7 @@ type RequestData struct {
SessionId string
SessionToken string
Banner string
ProfileHash string
}
var auth_request = `<?xml version="1.0" encoding="UTF-8"?>
@@ -176,8 +179,8 @@ var auth_complete = `<?xml version="1.0" encoding="UTF-8"?>
<vpn-profile-manifest>
<vpn rev="1.0">
<file type="profile" service-type="user">
<uri>/files/profile.xml</uri>
<hash type="sha1">A8B0B07FBA93D06E8501E40AB807AEE2464E73B7</hash>
<uri>/profile.xml</uri>
<hash type="sha1">{{.ProfileHash}}</hash>
</file>
</vpn>
</vpn-profile-manifest>

View File

@@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
"os"
"time"
"github.com/bjdgyc/anylink/base"
@@ -26,14 +27,14 @@ func startTls() {
)
// 判断证书文件
//_, err = os.Stat(certFile)
//if errors.Is(err, os.ErrNotExist) {
// _, err = os.Stat(certFile)
// if errors.Is(err, os.ErrNotExist) {
// // 自动生成证书
// certs[0], err = selfsign.GenerateSelfSignedWithDNS("vpn.anylink")
//} else {
// } else {
// // 使用自定义证书
// certs[0], err = tls.LoadX509KeyPair(certFile, keyFile)
//}
// }
certs[0], err = tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
@@ -77,9 +78,10 @@ func initRoute() http.Handler {
r.HandleFunc("/", LinkAuth).Methods(http.MethodPost)
r.HandleFunc("/CSCOSSLC/tunnel", LinkTunnel).Methods(http.MethodConnect)
r.HandleFunc("/otp_qr", LinkOtpQr).Methods(http.MethodGet)
// r.HandleFunc("/profile.xml", func(w http.ResponseWriter, r *http.Request) {
// w.Write([]byte(auth_profile))
// }).Methods(http.MethodGet)
r.HandleFunc("/profile.xml", func(w http.ResponseWriter, r *http.Request) {
b, _ := os.ReadFile(base.Cfg.Profile)
w.Write(b)
}).Methods(http.MethodGet)
r.PathPrefix("/files/").Handler(
http.StripPrefix("/files/",
http.FileServer(http.Dir(base.Cfg.FilesPath)),

View File

@@ -1,6 +1,10 @@
package handler
import (
"crypto/sha1"
"encoding/hex"
"os"
"github.com/bjdgyc/anylink/admin"
"github.com/bjdgyc/anylink/base"
"github.com/bjdgyc/anylink/dbdata"
@@ -22,6 +26,14 @@ func Start() {
base.Fatal("LinkMode is err")
}
// 计算profile.xml的hash
b, err := os.ReadFile(base.Cfg.Profile)
if err != nil {
panic(err)
}
ha := sha1.Sum(b)
profileHash = hex.EncodeToString(ha[:])
go admin.StartAdmin()
go startTls()
go startDtls()