mirror of https://github.com/bjdgyc/anylink.git
修改日志写入文件内
This commit is contained in:
parent
665732fc03
commit
0baab68bb2
12
README.md
12
README.md
|
@ -20,7 +20,7 @@ AnyLink 基于 [ietf-openconnect](https://tools.ietf.org/html/draft-mavrogiannop
|
|||
|
||||
AnyLink 使用TLS/DTLS进行数据加密,因此需要RSA或ECC证书,可以通过 Let's Encrypt 和 TrustAsia 申请免费的SSL证书。
|
||||
|
||||
AnyLink 服务端仅在CentOS7测试通过,如需要安装在其他系统,需要服务端支持tun/tap功能、ip设置命令。
|
||||
AnyLink 服务端仅在CentOS7、Ubuntu测试通过,如需要安装在其他系统,需要服务端支持tun/tap功能、ip设置命令。
|
||||
|
||||
## Screenshot
|
||||
|
||||
|
@ -36,9 +36,12 @@ git clone https://github.com/bjdgyc/anylink.git
|
|||
cd anylink
|
||||
sh deploy.sh
|
||||
|
||||
#注意使用root权限运行
|
||||
# 注意使用root权限运行
|
||||
cd anylink-deploy
|
||||
sudo ./anylink -conf="conf/server.toml"
|
||||
|
||||
# 默认管理后台访问地址
|
||||
# http://host:8800
|
||||
```
|
||||
|
||||
## Feature
|
||||
|
@ -155,8 +158,9 @@ sh bridge-init.sh
|
|||
本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 LICENSE 文件中。
|
||||
|
||||
|
||||
|
||||
|
||||
## Thank
|
||||
|
||||
[](https://www.jetbrains.com)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,26 +10,26 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// 登陆接口
|
||||
// Login 登陆接口
|
||||
func Login(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO 调试信息输出
|
||||
// hd, _ := httputil.DumpRequest(r, true)
|
||||
// fmt.Println("DumpRequest: ", string(hd))
|
||||
|
||||
_ = r.ParseForm()
|
||||
admin_user := r.PostFormValue("admin_user")
|
||||
admin_pass := r.PostFormValue("admin_pass")
|
||||
adminUser := r.PostFormValue("admin_user")
|
||||
adminPass := r.PostFormValue("admin_pass")
|
||||
|
||||
// 认证错误
|
||||
if !(admin_user == base.Cfg.AdminUser &&
|
||||
utils.PasswordVerify(admin_pass, base.Cfg.AdminPass)) {
|
||||
if !(adminUser == base.Cfg.AdminUser &&
|
||||
utils.PasswordVerify(adminPass, base.Cfg.AdminPass)) {
|
||||
RespError(w, RespUserOrPassErr)
|
||||
return
|
||||
}
|
||||
|
||||
// token有效期
|
||||
expiresAt := time.Now().Unix() + 3600*3
|
||||
jwtData := map[string]interface{}{"admin_user": admin_user}
|
||||
jwtData := map[string]interface{}{"admin_user": adminUser}
|
||||
tokenString, err := SetJwtData(jwtData, expiresAt)
|
||||
if err != nil {
|
||||
RespError(w, 1, err)
|
||||
|
@ -38,7 +38,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
data := make(map[string]interface{})
|
||||
data["token"] = tokenString
|
||||
data["admin_user"] = admin_user
|
||||
data["admin_user"] = adminUser
|
||||
data["expires_at"] = expiresAt
|
||||
|
||||
RespSucess(w, data)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestJwtData(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
base.Cfg.JwtSecret = "dsfasfdfsadfasdfasd3sdaf"
|
||||
data := map[string]interface{}{
|
||||
"key": "value",
|
||||
}
|
||||
expiresAt := time.Now().Add(time.Minute).Unix()
|
||||
token, err := SetJwtData(data, expiresAt)
|
||||
assert.Nil(err)
|
||||
dataN, err := GetJwtData(token)
|
||||
assert.Nil(err)
|
||||
assert.Equal(dataN["key"], "value")
|
||||
}
|
|
@ -40,7 +40,8 @@ type ServerConfig struct {
|
|||
CertFile string `toml:"cert_file" info:"证书文件"`
|
||||
CertKey string `toml:"cert_key" info:"证书密钥"`
|
||||
UiPath string `toml:"ui_path" info:"ui文件路径"`
|
||||
DownFilesPath string `toml:"down_files_path" info:"外部下载文件路径"`
|
||||
FilesPath string `toml:"files_path" info:"外部下载文件路径"`
|
||||
LogPath string `toml:"log_path" info:"日志文件路径"`
|
||||
LogLevel string `toml:"log_level" info:"日志等级"`
|
||||
Issuer string `toml:"issuer" info:"系统名称"`
|
||||
AdminUser string `toml:"admin_user" info:"管理用户名"`
|
||||
|
@ -83,7 +84,8 @@ func initServerCfg() {
|
|||
Cfg.CertFile = getAbsPath(base, Cfg.CertFile)
|
||||
Cfg.CertKey = getAbsPath(base, Cfg.CertKey)
|
||||
Cfg.UiPath = getAbsPath(base, Cfg.UiPath)
|
||||
Cfg.DownFilesPath = getAbsPath(base, Cfg.DownFilesPath)
|
||||
Cfg.FilesPath = getAbsPath(base, Cfg.FilesPath)
|
||||
Cfg.LogPath = getAbsPath(base, Cfg.LogPath)
|
||||
|
||||
if len(Cfg.JwtSecret) < 20 {
|
||||
fmt.Println("请设置 jwt_secret 长度20位以上")
|
||||
|
@ -94,6 +96,10 @@ func initServerCfg() {
|
|||
}
|
||||
|
||||
func getAbsPath(base, cfile string) string {
|
||||
if cfile == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
abs := filepath.IsAbs(cfile)
|
||||
if abs {
|
||||
return cfile
|
||||
|
|
|
@ -26,7 +26,7 @@ var (
|
|||
)
|
||||
|
||||
func initFlag() {
|
||||
flag.StringVar(&serverFile, "conf", "./conf/server.toml", "server config file path")
|
||||
flag.StringVar(&serverFile, "conf", "./conf/server.toml", "server config files path")
|
||||
flag.StringVar(&passwd, "passwd", "", "convert the password plaintext")
|
||||
flag.BoolVar(&secret, "secret", false, "generate a random jwt secret")
|
||||
flag.BoolVar(&rev, "rev", false, "display version info")
|
||||
|
|
58
base/log.go
58
base/log.go
|
@ -4,7 +4,9 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -19,11 +21,65 @@ var (
|
|||
baseLog *log.Logger
|
||||
baseLevel int
|
||||
levels map[int]string
|
||||
|
||||
dateFormat = "2006-01-02"
|
||||
logName = "anylink.log"
|
||||
)
|
||||
|
||||
// 实现 os.Writer 接口
|
||||
type logWriter struct {
|
||||
UseStdout bool
|
||||
FileName string
|
||||
File *os.File
|
||||
NowDate string
|
||||
}
|
||||
|
||||
// 实现日志文件的切割
|
||||
func (lw *logWriter) Write(p []byte) (n int, err error) {
|
||||
if !lw.UseStdout {
|
||||
return lw.File.Write(p)
|
||||
}
|
||||
|
||||
date := time.Now().Format(dateFormat)
|
||||
if lw.NowDate != date {
|
||||
_ = lw.File.Close()
|
||||
_ = os.Rename(lw.FileName, lw.FileName+"."+lw.NowDate)
|
||||
lw.NowDate = date
|
||||
lw.newFile()
|
||||
}
|
||||
return lw.File.Write(p)
|
||||
}
|
||||
|
||||
// 创建新文件
|
||||
func (lw *logWriter) newFile() {
|
||||
if lw.UseStdout {
|
||||
lw.File = os.Stdout
|
||||
return
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(lw.FileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
lw.File = f
|
||||
}
|
||||
|
||||
func initLog() {
|
||||
baseLog = log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile)
|
||||
// 初始化 baseLog
|
||||
baseLw := &logWriter{
|
||||
UseStdout: Cfg.LogPath == "",
|
||||
FileName: path.Join(Cfg.LogPath, logName),
|
||||
NowDate: time.Now().Format(dateFormat),
|
||||
}
|
||||
|
||||
baseLw.newFile()
|
||||
baseLevel = logLevel2Int(Cfg.LogLevel)
|
||||
baseLog = log.New(baseLw, "", log.LstdFlags|log.Lshortfile)
|
||||
}
|
||||
|
||||
// 获取 log.Logger
|
||||
func GetBaseLog() *log.Logger {
|
||||
return baseLog
|
||||
}
|
||||
|
||||
func logLevel2Int(l string) int {
|
||||
|
|
|
@ -9,8 +9,9 @@ db_file = "./data.db"
|
|||
cert_file = "./vpn_cert.pem"
|
||||
cert_key = "./vpn_cert.key"
|
||||
ui_path = "../ui"
|
||||
down_files_path = "../down_files"
|
||||
|
||||
files_path = "../files"
|
||||
#日志目录,为空写入标准输出
|
||||
log_path = "../log"
|
||||
log_level = "info"
|
||||
|
||||
#系统名称
|
||||
|
|
|
@ -16,6 +16,7 @@ cd ../
|
|||
|
||||
#整理部署文件
|
||||
mkdir anylink-deploy
|
||||
mkdir anylink-deploy/log
|
||||
|
||||
cp -r anylink anylink-deploy
|
||||
cp -r anylink-web/ui anylink-deploy
|
||||
|
|
15
go.mod
15
go.mod
|
@ -6,21 +6,20 @@ require (
|
|||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||
github.com/asdine/storm/v3 v3.2.1
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||
github.com/google/gopacket v1.1.19
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/mojocn/base64Captcha v1.3.1
|
||||
github.com/pelletier/go-toml v1.8.1
|
||||
github.com/shirou/gopsutil v3.20.11+incompatible
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091
|
||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
||||
github.com/stretchr/testify v1.6.1
|
||||
github.com/xhit/go-simple-mail/v2 v2.6.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/xhit/go-simple-mail/v2 v2.8.0
|
||||
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119
|
||||
go.etcd.io/bbolt v1.3.5
|
||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
|
||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
|
||||
)
|
||||
|
|
40
go.sum
40
go.sum
|
@ -4,17 +4,18 @@ github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863 h1:BRrxwOZBolJN4gIwv
|
|||
github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/asdine/storm v1.1.0 h1:lwDLqMMPhokfYk8EuU1RRHTi54T68EI+QnCqK5t4TCM=
|
||||
github.com/asdine/storm v2.1.2+incompatible h1:dczuIkyqwY2LrtXPz8ixMrU/OFgZp71kbKTHGrXYt/Q=
|
||||
github.com/asdine/storm/v3 v3.2.1 h1:I5AqhkPK6nBZ/qJXySdI7ot5BlXSZ7qvDY1zAn5ZJac=
|
||||
github.com/asdine/storm/v3 v3.2.1/go.mod h1:LEpXwGt4pIqrE/XcTvCnZHT5MgZCV6Ub9q7yQzOFWr0=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
|
@ -29,14 +30,12 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
|||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mojocn/base64Captcha v1.3.1 h1:2Wbkt8Oc8qjmNJ5GyOfSo4tgVQPsbKMftqASnq8GlT0=
|
||||
github.com/mojocn/base64Captcha v1.3.1/go.mod h1:wAQCKEc5bDujxKRmbT6/vTnTt5CjStQ8bRfPWUuz/iY=
|
||||
github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM=
|
||||
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto=
|
||||
github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible h1:2LwXWdbjXwyDgq26Yy/OT4xozlpmssQfy/rtfhWb0bY=
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 h1:1zN6ImoqhSJhN8hGXFaJlSC8msLmIbX8bFqOfWLKw0w=
|
||||
|
@ -45,12 +44,14 @@ github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D
|
|||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
|
||||
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
|
||||
github.com/xhit/go-simple-mail/v2 v2.6.0 h1:pvPmpDUUWy07cnTgwxwEe5fjdyYtETnxcvdGPQxtv/k=
|
||||
github.com/xhit/go-simple-mail/v2 v2.6.0/go.mod h1:kA1XbQfCI4JxQ9ccSN6VFyIEkkugOm7YiPkA5hKiQn4=
|
||||
github.com/xhit/go-simple-mail v1.0.0 h1:sLvCv2srAOeKnEPY3pzACtcjOjHHwwPdMcdMNRnMkRA=
|
||||
github.com/xhit/go-simple-mail v2.2.2+incompatible h1:Hm2VGfLqiQJ/NnC8SYsrPOPyVYIlvP2kmnotP4RIV74=
|
||||
github.com/xhit/go-simple-mail/v2 v2.8.0 h1:w6ZDXvRk0EO+r78LRlQl14ngP2tiRDRRHhr9UaVJ0p4=
|
||||
github.com/xhit/go-simple-mail/v2 v2.8.0/go.mod h1:kA1XbQfCI4JxQ9ccSN6VFyIEkkugOm7YiPkA5hKiQn4=
|
||||
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 h1:YyPWX3jLOtYKulBR6AScGIs74lLrJcgeKRwcbAuQOG4=
|
||||
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119/go.mod h1:/nuTSlK+okRfR/vnIPqR89fFKonnWPiZymN5ydRJkX8=
|
||||
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
|
@ -58,21 +59,20 @@ go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
|||
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604=
|
||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 h1:TbGuee8sSq15Iguxu4deQ7+Bqq/d2rsQejGcEtADAMQ=
|
||||
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 h1:lwlPPsmjDKK0J6eG6xDWd5XPehI0R024zxjDnw3esPA=
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d h1:1aflnvSoWWLI2k/dMUAl5lvU1YO4Mb4hz0gh+1rjcxU=
|
||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
|
@ -82,8 +82,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
|
|||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba h1:O8mE0/t419eoIwhTFpKVkHiTs/Igowgfkj25AcZrtiE=
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
|
@ -67,7 +67,7 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) {
|
|||
// TODO 用户密码校验
|
||||
err = dbdata.CheckUser(cr.Auth.Username, cr.Auth.Password, cr.GroupSelect)
|
||||
if err != nil {
|
||||
base.Info(err)
|
||||
base.Warn(err)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
data := RequestData{Group: cr.GroupSelect, Groups: dbdata.GetGroupNames(), Error: "用户名或密码错误"}
|
||||
tplRequest(tpl_request, w, data)
|
||||
|
@ -92,6 +92,7 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) {
|
|||
Banner: other.Banner}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
tplRequest(tpl_complete, w, rd)
|
||||
base.Debug("login", cr.Auth.Username)
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
|
||||
func LinkCstp(conn net.Conn, cSess *sessdata.ConnSession) {
|
||||
defer func() {
|
||||
// log.Println("LinkCstp return")
|
||||
conn.Close()
|
||||
base.Debug("LinkCstp return", cSess.IpAddr)
|
||||
_ = conn.Close()
|
||||
cSess.Close()
|
||||
}()
|
||||
|
||||
|
@ -72,8 +72,8 @@ func LinkCstp(conn net.Conn, cSess *sessdata.ConnSession) {
|
|||
|
||||
func cstpWrite(conn net.Conn, cSess *sessdata.ConnSession) {
|
||||
defer func() {
|
||||
// log.Println("cstpWrite return")
|
||||
conn.Close()
|
||||
base.Debug("cstpWrite return", cSess.IpAddr)
|
||||
_ = conn.Close()
|
||||
cSess.Close()
|
||||
}()
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ func LinkTap(cSess *sessdata.ConnSession) error {
|
|||
err = execCmd(cmdStrs)
|
||||
if err != nil {
|
||||
base.Error(err)
|
||||
ifce.Close()
|
||||
_ = ifce.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -81,9 +81,9 @@ func LinkTap(cSess *sessdata.ConnSession) error {
|
|||
|
||||
func tapWrite(ifce *water.Interface, cSess *sessdata.ConnSession) {
|
||||
defer func() {
|
||||
// log.Println("LinkTap return")
|
||||
base.Debug("LinkTap return", cSess.IpAddr)
|
||||
cSess.Close()
|
||||
ifce.Close()
|
||||
_ = ifce.Close()
|
||||
}()
|
||||
|
||||
var (
|
||||
|
@ -153,8 +153,8 @@ func tapWrite(ifce *water.Interface, cSess *sessdata.ConnSession) {
|
|||
|
||||
func tapRead(ifce *water.Interface, cSess *sessdata.ConnSession) {
|
||||
defer func() {
|
||||
// log.Println("tapRead return")
|
||||
ifce.Close()
|
||||
base.Debug("tapRead return", cSess.IpAddr)
|
||||
_ = ifce.Close()
|
||||
}()
|
||||
|
||||
var (
|
||||
|
|
|
@ -51,7 +51,7 @@ func LinkTun(cSess *sessdata.ConnSession) error {
|
|||
err = execCmd(cmdStrs)
|
||||
if err != nil {
|
||||
base.Error(err)
|
||||
ifce.Close()
|
||||
_ = ifce.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -62,9 +62,9 @@ func LinkTun(cSess *sessdata.ConnSession) error {
|
|||
|
||||
func tunWrite(ifce *water.Interface, cSess *sessdata.ConnSession) {
|
||||
defer func() {
|
||||
// log.Println("LinkTun return")
|
||||
base.Debug("LinkTun return", cSess.IpAddr)
|
||||
cSess.Close()
|
||||
ifce.Close()
|
||||
_ = ifce.Close()
|
||||
}()
|
||||
|
||||
var (
|
||||
|
@ -89,8 +89,8 @@ func tunWrite(ifce *water.Interface, cSess *sessdata.ConnSession) {
|
|||
|
||||
func tunRead(ifce *water.Interface, cSess *sessdata.ConnSession) {
|
||||
defer func() {
|
||||
// log.Println("tunRead return")
|
||||
ifce.Close()
|
||||
base.Debug("tunRead return", cSess.IpAddr)
|
||||
_ = ifce.Close()
|
||||
}()
|
||||
var (
|
||||
err error
|
||||
|
|
|
@ -140,6 +140,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
|||
hj := w.(http.Hijacker)
|
||||
conn, _, err := hj.Hijack()
|
||||
if err != nil {
|
||||
base.Error(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
|
@ -14,22 +13,28 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func GetCertificate(*tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||
cert, err := tls.LoadX509KeyPair(base.Cfg.CertFile, base.Cfg.CertKey)
|
||||
return &cert, err
|
||||
}
|
||||
|
||||
func startTls() {
|
||||
addr := base.Cfg.ServerAddr
|
||||
certFile := base.Cfg.CertFile
|
||||
keyFile := base.Cfg.CertKey
|
||||
|
||||
logger := log.New(os.Stdout, "[SERVER]", log.Lshortfile|log.Ldate)
|
||||
// 设置tls信息
|
||||
tlsConfig := &tls.Config{
|
||||
NextProtos: []string{"http/1.1"},
|
||||
MinVersion: tls.VersionTLS12,
|
||||
NextProtos: []string{"http/1.1"},
|
||||
MinVersion: tls.VersionTLS12,
|
||||
InsecureSkipVerify: true,
|
||||
GetCertificate: GetCertificate,
|
||||
}
|
||||
srv := &http.Server{
|
||||
Addr: addr,
|
||||
Handler: initRoute(),
|
||||
TLSConfig: tlsConfig,
|
||||
ErrorLog: logger,
|
||||
ErrorLog: base.GetBaseLog(),
|
||||
}
|
||||
|
||||
var ln net.Listener
|
||||
|
@ -57,9 +62,9 @@ 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.PathPrefix("/down_files/").Handler(
|
||||
http.StripPrefix("/down_files/",
|
||||
http.FileServer(http.Dir(base.Cfg.DownFilesPath)),
|
||||
r.PathPrefix("/files/").Handler(
|
||||
http.StripPrefix("/files/",
|
||||
http.FileServer(http.Dir(base.Cfg.FilesPath)),
|
||||
),
|
||||
)
|
||||
r.NotFoundHandler = http.HandlerFunc(notFound)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
|
@ -3,7 +3,6 @@ package sessdata
|
|||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
|
@ -191,7 +190,7 @@ func (s *Session) NewConn() *ConnSession {
|
|||
|
||||
func (cs *ConnSession) Close() {
|
||||
cs.closeOnce.Do(func() {
|
||||
log.Println("closeOnce:", cs.IpAddr)
|
||||
base.Info("closeOnce:", cs.IpAddr)
|
||||
cs.Sess.mux.Lock()
|
||||
defer cs.Sess.mux.Unlock()
|
||||
|
||||
|
|
Loading…
Reference in New Issue