mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-10 23:53:29 +08:00
修改日志写入文件内
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user