逻辑调整

This commit is contained in:
刘河
2019-01-04 20:23:33 +08:00
parent 1fb1ea08bd
commit ade3bb0c71
8 changed files with 29 additions and 49 deletions

View File

@@ -3,7 +3,6 @@ package lib
import (
"errors"
"flag"
"github.com/astaxie/beego"
"log"
"reflect"
"strings"
@@ -27,7 +26,6 @@ var (
RunList map[string]interface{} //运行中的任务
bridge *Tunnel
CsvDb *Csv
//crypt = GetBoolNoErrFromConfig("crypt")
)
const cryptKey = "1234567812345678"
@@ -76,13 +74,6 @@ func InitFromCsv() {
}
func newMode(mode string, bridge *Tunnel, httpPort int, tunnelTarget string, u string, p string, enCompress int, deCompress int, vkey string, crypt string) interface{} {
if u == "" || p == "" { //如果web管理或者命令中设置了用户名和密码则覆盖配置文件
u = beego.AppConfig.String("auth.user")
p = beego.AppConfig.String("auth.password")
}
if crypt == "" { //如果web管理或者命令中设置了是否加密则覆盖配置文件
crypt = beego.AppConfig.String("crypt")
}
bCrypt := GetBoolByStr(crypt)
switch mode {
case "httpServer":

View File

@@ -195,8 +195,8 @@ func (s *TunnelModeServer) Start() error {
}
//权限认证
func (s *TunnelModeServer) auth(r *http.Request, c *Conn) error {
if s.basicUser != "" && s.basicPassword != "" && !checkAuth(r, s.basicUser, s.basicPassword) {
func (s *TunnelModeServer) auth(r *http.Request, c *Conn, u, p string) error {
if u != "" && p != "" && !checkAuth(r, u, p) {
c.Write([]byte(Unauthorized_BYTES))
c.Close()
return errors.New("401 Unauthorized")
@@ -237,7 +237,7 @@ func (s *TunnelModeServer) Close() error {
func ProcessTunnel(c *Conn, s *TunnelModeServer) error {
method, _, rb, err, r := c.GetHost()
if err == nil {
if err := s.auth(r, c); err != nil {
if err := s.auth(r, c, s.basicUser, s.basicPassword); err != nil {
return err
}
}
@@ -251,7 +251,7 @@ func ProcessHttp(c *Conn, s *TunnelModeServer) error {
c.Close()
return err
}
if err := s.auth(r, c); err != nil {
if err := s.auth(r, c, s.basicUser, s.basicPassword); err != nil {
return err
}
return s.dealClient(s.vKey, s.enCompress, s.deCompress, c, addr, method, rb)
@@ -264,10 +264,10 @@ func ProcessHost(c *Conn, s *TunnelModeServer) error {
c.Close()
return err
}
if err := s.auth(r, c); err != nil {
host, task, err := getKeyByHost(addr)
if err := s.auth(r, c, task.U, task.P); err != nil {
return err
}
host, task, err := getKeyByHost(addr)
if err != nil {
c.Close()
return err