mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-02 04:00:42 +00:00
Code optimization
This commit is contained in:
parent
4b0aebd6a5
commit
cc6d053b6d
@ -92,12 +92,12 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
|||||||
} else if !status { //the status is true , return target to the targetArr
|
} else if !status { //the status is true , return target to the targetArr
|
||||||
file.GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Tunnel)
|
v := value.(*file.Tunnel)
|
||||||
if v.Client.Id == id && v.Mode == "tcp" && strings.Contains(v.Target, info) {
|
if v.Client.Id == id && v.Mode == "tcp" && strings.Contains(v.Target.TargetStr, info) {
|
||||||
v.Lock()
|
v.Lock()
|
||||||
if v.TargetArr == nil || (len(v.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
if v.Target.TargetArr == nil || (len(v.Target.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
||||||
v.TargetArr = common.TrimArr(strings.Split(v.Target, "\n"))
|
v.Target.TargetArr = common.TrimArr(strings.Split(v.Target.TargetStr, "\n"))
|
||||||
}
|
}
|
||||||
v.TargetArr = common.RemoveArrVal(v.TargetArr, info)
|
v.Target.TargetArr = common.RemoveArrVal(v.Target.TargetArr, info)
|
||||||
if v.HealthRemoveArr == nil {
|
if v.HealthRemoveArr == nil {
|
||||||
v.HealthRemoveArr = make([]string, 0)
|
v.HealthRemoveArr = make([]string, 0)
|
||||||
}
|
}
|
||||||
@ -108,12 +108,12 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
|||||||
})
|
})
|
||||||
file.GetCsvDb().Hosts.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Hosts.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Host)
|
v := value.(*file.Host)
|
||||||
if v.Client.Id == id && strings.Contains(v.Target, info) {
|
if v.Client.Id == id && strings.Contains(v.Target.TargetStr, info) {
|
||||||
v.Lock()
|
v.Lock()
|
||||||
if v.TargetArr == nil || (len(v.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
if v.Target.TargetArr == nil || (len(v.Target.TargetArr) == 0 && len(v.HealthRemoveArr) == 0) {
|
||||||
v.TargetArr = common.TrimArr(strings.Split(v.Target, "\n"))
|
v.Target.TargetArr = common.TrimArr(strings.Split(v.Target.TargetStr, "\n"))
|
||||||
}
|
}
|
||||||
v.TargetArr = common.RemoveArrVal(v.TargetArr, info)
|
v.Target.TargetArr = common.RemoveArrVal(v.Target.TargetArr, info)
|
||||||
if v.HealthRemoveArr == nil {
|
if v.HealthRemoveArr == nil {
|
||||||
v.HealthRemoveArr = make([]string, 0)
|
v.HealthRemoveArr = make([]string, 0)
|
||||||
}
|
}
|
||||||
@ -125,9 +125,9 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
|||||||
} else { //the status is false,remove target from the targetArr
|
} else { //the status is false,remove target from the targetArr
|
||||||
file.GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Tunnel)
|
v := value.(*file.Tunnel)
|
||||||
if v.Client.Id == id && v.Mode == "tcp" && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.TargetArr, info) {
|
if v.Client.Id == id && v.Mode == "tcp" && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.Target.TargetArr, info) {
|
||||||
v.Lock()
|
v.Lock()
|
||||||
v.TargetArr = append(v.TargetArr, info)
|
v.Target.TargetArr = append(v.Target.TargetArr, info)
|
||||||
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
||||||
v.Unlock()
|
v.Unlock()
|
||||||
}
|
}
|
||||||
@ -136,9 +136,9 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
|
|||||||
|
|
||||||
file.GetCsvDb().Hosts.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Hosts.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Host)
|
v := value.(*file.Host)
|
||||||
if v.Client.Id == id && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.TargetArr, info) {
|
if v.Client.Id == id && common.IsArrContains(v.HealthRemoveArr, info) && !common.IsArrContains(v.Target.TargetArr, info) {
|
||||||
v.Lock()
|
v.Lock()
|
||||||
v.TargetArr = append(v.TargetArr, info)
|
v.Target.TargetArr = append(v.Target.TargetArr, info)
|
||||||
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
v.HealthRemoveArr = common.RemoveArrVal(v.HealthRemoveArr, info)
|
||||||
v.Unlock()
|
v.Unlock()
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ func (s *Bridge) DelClient(id int) {
|
|||||||
if file.GetCsvDb().IsPubClient(id) {
|
if file.GetCsvDb().IsPubClient(id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c, err := file.GetCsvDb().GetClient(id); err == nil && c.NoStore {
|
if c, err := file.GetCsvDb().GetClient(id); err == nil {
|
||||||
s.CloseClient <- c.Id
|
s.CloseClient <- c.Id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,7 +320,6 @@ func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, linkAddr string, t
|
|||||||
if t != nil && t.Mode == "file" {
|
if t != nil && t.Mode == "file" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = conn.NewConn(target).SendLinkInfo(link); err != nil {
|
if _, err = conn.NewConn(target).SendLinkInfo(link); err != nil {
|
||||||
logs.Info("new connect error ,the target %s refuse to connect", link.Host)
|
logs.Info("new connect error ,the target %s refuse to connect", link.Host)
|
||||||
return
|
return
|
||||||
@ -441,7 +440,7 @@ loop:
|
|||||||
break loop
|
break loop
|
||||||
} else {
|
} else {
|
||||||
ports := common.GetPorts(t.Ports)
|
ports := common.GetPorts(t.Ports)
|
||||||
targets := common.GetPorts(t.Target)
|
targets := common.GetPorts(t.Target.TargetStr)
|
||||||
if len(ports) > 1 && (t.Mode == "tcp" || t.Mode == "udp") && (len(ports) != len(targets)) {
|
if len(ports) > 1 && (t.Mode == "tcp" || t.Mode == "udp") && (len(ports) != len(targets)) {
|
||||||
fail = true
|
fail = true
|
||||||
c.WriteAddFail()
|
c.WriteAddFail()
|
||||||
@ -465,9 +464,9 @@ loop:
|
|||||||
} else {
|
} else {
|
||||||
tl.Remark = t.Remark + "_" + strconv.Itoa(tl.Port)
|
tl.Remark = t.Remark + "_" + strconv.Itoa(tl.Port)
|
||||||
if t.TargetAddr != "" {
|
if t.TargetAddr != "" {
|
||||||
tl.Target = t.TargetAddr + ":" + strconv.Itoa(targets[i])
|
tl.Target.TargetStr = t.TargetAddr + ":" + strconv.Itoa(targets[i])
|
||||||
} else {
|
} else {
|
||||||
tl.Target = strconv.Itoa(targets[i])
|
tl.Target.TargetStr = strconv.Itoa(targets[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tl.Id = int(file.GetCsvDb().GetTaskId())
|
tl.Id = int(file.GetCsvDb().GetTaskId())
|
||||||
|
@ -163,7 +163,7 @@ re:
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.Close()
|
c.Close()
|
||||||
logs.Notice("Temporary access login key ", vkey)
|
logs.Notice("web access login key ", vkey)
|
||||||
NewRPClient(cnf.CommonConfig.Server, vkey, cnf.CommonConfig.Tp, cnf.CommonConfig.ProxyUrl, cnf).Start()
|
NewRPClient(cnf.CommonConfig.Server, vkey, cnf.CommonConfig.Tp, cnf.CommonConfig.ProxyUrl, cnf).Start()
|
||||||
CloseLocalServer()
|
CloseLocalServer()
|
||||||
goto re
|
goto re
|
||||||
|
@ -63,7 +63,7 @@ func session(healths []*file.Health, h *sheap.IntHeap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//只针对一个端口 面向多个目标的情况
|
// work when just one port and many target
|
||||||
func check(t *file.Health) {
|
func check(t *file.Health) {
|
||||||
arr := strings.Split(t.HealthCheckTarget, ",")
|
arr := strings.Split(t.HealthCheckTarget, ",")
|
||||||
var err error
|
var err error
|
||||||
@ -88,7 +88,7 @@ func check(t *file.Health) {
|
|||||||
t.HealthMap[v] = 0
|
t.HealthMap[v] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.HealthMap[v] == t.HealthMaxFail {
|
if t.HealthMap[v] > 0 && t.HealthMap[v]%t.HealthMaxFail == 0 {
|
||||||
//send fail remove
|
//send fail remove
|
||||||
serverConn.SendHealthInfo(v, "0")
|
serverConn.SendHealthInfo(v, "0")
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ import (
|
|||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/daemon"
|
"github.com/cnlh/nps/lib/daemon"
|
||||||
"github.com/cnlh/nps/lib/version"
|
"github.com/cnlh/nps/lib/version"
|
||||||
|
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -59,7 +61,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if *configPath == "" {
|
if *configPath == "" {
|
||||||
*configPath = "npc.conf"
|
*configPath = filepath.Join(beego.AppPath, "conf", "npc.conf")
|
||||||
}
|
}
|
||||||
client.StartFromFile(*configPath)
|
client.StartFromFile(*configPath)
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//Get the corresponding IP address through domain name
|
//Get the corresponding IP address through domain name
|
||||||
@ -346,12 +344,3 @@ func BytesToNum(b []byte) int {
|
|||||||
x, _ := strconv.Atoi(str)
|
x, _ := strconv.Atoi(str)
|
||||||
return int(x)
|
return int(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMapKeys(m sync.Map) (keys []int) {
|
|
||||||
m.Range(func(key, value interface{}) bool {
|
|
||||||
keys = append(keys, key.(int))
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
sort.Ints(keys)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
@ -17,6 +17,7 @@ type CommonConfig struct {
|
|||||||
ProxyUrl string
|
ProxyUrl string
|
||||||
Client *file.Client
|
Client *file.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalServer struct {
|
type LocalServer struct {
|
||||||
Type string
|
Type string
|
||||||
Port int
|
Port int
|
||||||
@ -24,6 +25,7 @@ type LocalServer struct {
|
|||||||
Password string
|
Password string
|
||||||
Target string
|
Target string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
content string
|
content string
|
||||||
title []string
|
title []string
|
||||||
@ -146,6 +148,7 @@ func dealCommon(s string) *CommonConfig {
|
|||||||
|
|
||||||
func dealHost(s string) *file.Host {
|
func dealHost(s string) *file.Host {
|
||||||
h := &file.Host{}
|
h := &file.Host{}
|
||||||
|
h.Target = new(file.Target)
|
||||||
var headerChange string
|
var headerChange string
|
||||||
for _, v := range splitStr(s) {
|
for _, v := range splitStr(s) {
|
||||||
item := strings.Split(v, "=")
|
item := strings.Split(v, "=")
|
||||||
@ -158,7 +161,7 @@ func dealHost(s string) *file.Host {
|
|||||||
case "host":
|
case "host":
|
||||||
h.Host = item[1]
|
h.Host = item[1]
|
||||||
case "target_addr":
|
case "target_addr":
|
||||||
h.Target = strings.Replace(item[1], ",", "\n", -1)
|
h.Target.TargetStr = strings.Replace(item[1], ",", "\n", -1)
|
||||||
case "host_change":
|
case "host_change":
|
||||||
h.HostChange = item[1]
|
h.HostChange = item[1]
|
||||||
case "scheme":
|
case "scheme":
|
||||||
@ -204,6 +207,7 @@ func dealHealth(s string) *file.Health {
|
|||||||
|
|
||||||
func dealTunnel(s string) *file.Tunnel {
|
func dealTunnel(s string) *file.Tunnel {
|
||||||
t := &file.Tunnel{}
|
t := &file.Tunnel{}
|
||||||
|
t.Target = new(file.Target)
|
||||||
for _, v := range splitStr(s) {
|
for _, v := range splitStr(s) {
|
||||||
item := strings.Split(v, "=")
|
item := strings.Split(v, "=")
|
||||||
if len(item) == 0 {
|
if len(item) == 0 {
|
||||||
@ -219,7 +223,7 @@ func dealTunnel(s string) *file.Tunnel {
|
|||||||
case "mode":
|
case "mode":
|
||||||
t.Mode = item[1]
|
t.Mode = item[1]
|
||||||
case "target_port", "target_addr":
|
case "target_port", "target_addr":
|
||||||
t.Target = strings.Replace(item[1], ",", "\n", -1)
|
t.Target.TargetStr = strings.Replace(item[1], ",", "\n", -1)
|
||||||
case "target_ip":
|
case "target_ip":
|
||||||
t.TargetAddr = item[1]
|
t.TargetAddr = item[1]
|
||||||
case "password":
|
case "password":
|
||||||
|
@ -25,17 +25,14 @@ import (
|
|||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
Conn net.Conn
|
Conn net.Conn
|
||||||
sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//new conn
|
//new conn
|
||||||
func NewConn(conn net.Conn) *Conn {
|
func NewConn(conn net.Conn) *Conn {
|
||||||
c := new(Conn)
|
return &Conn{Conn: conn}
|
||||||
c.Conn = conn
|
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//从tcp报文中解析出host,连接类型等
|
//get host 、connection type、method...from connection
|
||||||
func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) {
|
func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) {
|
||||||
var b [32 * 1024]byte
|
var b [32 * 1024]byte
|
||||||
var n int
|
var n int
|
||||||
@ -53,14 +50,14 @@ func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.
|
|||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if hostPortURL.Opaque == "443" { //https访问
|
if hostPortURL.Opaque == "443" {
|
||||||
if strings.Index(r.Host, ":") == -1 { //host不带端口, 默认80
|
if strings.Index(r.Host, ":") == -1 {
|
||||||
address = r.Host + ":443"
|
address = r.Host + ":443"
|
||||||
} else {
|
} else {
|
||||||
address = r.Host
|
address = r.Host
|
||||||
}
|
}
|
||||||
} else { //http访问
|
} else {
|
||||||
if strings.Index(r.Host, ":") == -1 { //host不带端口, 默认80
|
if strings.Index(r.Host, ":") == -1 {
|
||||||
address = r.Host + ":80"
|
address = r.Host + ":80"
|
||||||
} else {
|
} else {
|
||||||
address = r.Host
|
address = r.Host
|
||||||
@ -117,7 +114,7 @@ func (s *Conn) ReadFlag() (string, error) {
|
|||||||
return string(buf), binary.Read(s, binary.LittleEndian, &buf)
|
return string(buf), binary.Read(s, binary.LittleEndian, &buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置连接为长连接
|
//set alive
|
||||||
func (s *Conn) SetAlive(tp string) {
|
func (s *Conn) SetAlive(tp string) {
|
||||||
switch s.Conn.(type) {
|
switch s.Conn.(type) {
|
||||||
case *kcp.UDPSession:
|
case *kcp.UDPSession:
|
||||||
@ -132,7 +129,7 @@ func (s *Conn) SetAlive(tp string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置连接为长连接
|
//set read deadline
|
||||||
func (s *Conn) SetReadDeadline(t time.Duration, tp string) {
|
func (s *Conn) SetReadDeadline(t time.Duration, tp string) {
|
||||||
switch s.Conn.(type) {
|
switch s.Conn.(type) {
|
||||||
case *kcp.UDPSession:
|
case *kcp.UDPSession:
|
||||||
@ -176,8 +173,6 @@ func (s *Conn) GetLinkInfo() (lk *Link, err error) {
|
|||||||
func (s *Conn) SendHealthInfo(info, status string) (int, error) {
|
func (s *Conn) SendHealthInfo(info, status string) (int, error) {
|
||||||
raw := bytes.NewBuffer([]byte{})
|
raw := bytes.NewBuffer([]byte{})
|
||||||
common.BinaryWrite(raw, info, status)
|
common.BinaryWrite(raw, info, status)
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write(raw.Bytes())
|
return s.Write(raw.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +206,7 @@ func (s *Conn) SendHostInfo(h *file.Host) (int, error) {
|
|||||||
*/
|
*/
|
||||||
raw := bytes.NewBuffer([]byte{})
|
raw := bytes.NewBuffer([]byte{})
|
||||||
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_HOST))
|
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_HOST))
|
||||||
common.BinaryWrite(raw, h.Host, h.Target, h.HeaderChange, h.HostChange, h.Remark, h.Location, h.Scheme)
|
common.BinaryWrite(raw, h.Host, h.Target.TargetStr, h.HeaderChange, h.HostChange, h.Remark, h.Location, h.Scheme)
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write(raw.Bytes())
|
return s.Write(raw.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,9 +237,10 @@ func (s *Conn) GetHostInfo() (h *file.Host, err error) {
|
|||||||
} else {
|
} else {
|
||||||
arr := strings.Split(string(buf[:l]), common.CONN_DATA_SEQ)
|
arr := strings.Split(string(buf[:l]), common.CONN_DATA_SEQ)
|
||||||
h = new(file.Host)
|
h = new(file.Host)
|
||||||
|
h.Target = new(file.Target)
|
||||||
h.Id = int(file.GetCsvDb().GetHostId())
|
h.Id = int(file.GetCsvDb().GetHostId())
|
||||||
h.Host = arr[0]
|
h.Host = arr[0]
|
||||||
h.Target = arr[1]
|
h.Target.TargetStr = arr[1]
|
||||||
h.HeaderChange = arr[2]
|
h.HeaderChange = arr[2]
|
||||||
h.HostChange = arr[3]
|
h.HostChange = arr[3]
|
||||||
h.Remark = arr[4]
|
h.Remark = arr[4]
|
||||||
@ -275,8 +269,6 @@ func (s *Conn) SendConfigInfo(c *config.CommonConfig) (int, error) {
|
|||||||
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_CONF))
|
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_CONF))
|
||||||
common.BinaryWrite(raw, c.Cnf.U, c.Cnf.P, common.GetStrByBool(c.Cnf.Crypt), common.GetStrByBool(c.Cnf.Compress), strconv.Itoa(c.Client.RateLimit),
|
common.BinaryWrite(raw, c.Cnf.U, c.Cnf.P, common.GetStrByBool(c.Cnf.Crypt), common.GetStrByBool(c.Cnf.Compress), strconv.Itoa(c.Client.RateLimit),
|
||||||
strconv.Itoa(int(c.Client.Flow.FlowLimit)), strconv.Itoa(c.Client.MaxConn), c.Client.Remark)
|
strconv.Itoa(int(c.Client.Flow.FlowLimit)), strconv.Itoa(c.Client.MaxConn), c.Client.Remark)
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write(raw.Bytes())
|
return s.Write(raw.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,9 +308,7 @@ func (s *Conn) SendTaskInfo(t *file.Tunnel) (int, error) {
|
|||||||
*/
|
*/
|
||||||
raw := bytes.NewBuffer([]byte{})
|
raw := bytes.NewBuffer([]byte{})
|
||||||
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_TASK))
|
binary.Write(raw, binary.LittleEndian, []byte(common.NEW_TASK))
|
||||||
common.BinaryWrite(raw, t.Mode, t.Ports, t.Target, t.Remark, t.TargetAddr, t.Password, t.LocalPath, t.StripPre, t.ServerIp)
|
common.BinaryWrite(raw, t.Mode, t.Ports, t.Target.TargetStr, t.Remark, t.TargetAddr, t.Password, t.LocalPath, t.StripPre, t.ServerIp)
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write(raw.Bytes())
|
return s.Write(raw.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,9 +324,10 @@ func (s *Conn) GetTaskInfo() (t *file.Tunnel, err error) {
|
|||||||
} else {
|
} else {
|
||||||
arr := strings.Split(string(buf[:l]), common.CONN_DATA_SEQ)
|
arr := strings.Split(string(buf[:l]), common.CONN_DATA_SEQ)
|
||||||
t = new(file.Tunnel)
|
t = new(file.Tunnel)
|
||||||
|
t.Target = new(file.Target)
|
||||||
t.Mode = arr[0]
|
t.Mode = arr[0]
|
||||||
t.Ports = arr[1]
|
t.Ports = arr[1]
|
||||||
t.Target = arr[2]
|
t.Target.TargetStr = arr[2]
|
||||||
t.Id = int(file.GetCsvDb().GetTaskId())
|
t.Id = int(file.GetCsvDb().GetTaskId())
|
||||||
t.Status = true
|
t.Status = true
|
||||||
t.Flow = new(file.Flow)
|
t.Flow = new(file.Flow)
|
||||||
@ -375,26 +366,20 @@ func (s *Conn) WriteClose() (int, error) {
|
|||||||
|
|
||||||
//write main
|
//write main
|
||||||
func (s *Conn) WriteMain() (int, error) {
|
func (s *Conn) WriteMain() (int, error) {
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write([]byte(common.WORK_MAIN))
|
return s.Write([]byte(common.WORK_MAIN))
|
||||||
}
|
}
|
||||||
|
|
||||||
//write main
|
//write main
|
||||||
func (s *Conn) WriteConfig() (int, error) {
|
func (s *Conn) WriteConfig() (int, error) {
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write([]byte(common.WORK_CONFIG))
|
return s.Write([]byte(common.WORK_CONFIG))
|
||||||
}
|
}
|
||||||
|
|
||||||
//write chan
|
//write chan
|
||||||
func (s *Conn) WriteChan() (int, error) {
|
func (s *Conn) WriteChan() (int, error) {
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
return s.Write([]byte(common.WORK_CHAN))
|
return s.Write([]byte(common.WORK_CHAN))
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取长度+内容
|
//get the assembled amount data(len 4 and content)
|
||||||
func GetLenBytes(buf []byte) (b []byte, err error) {
|
func GetLenBytes(buf []byte) (b []byte, err error) {
|
||||||
raw := bytes.NewBuffer([]byte{})
|
raw := bytes.NewBuffer([]byte{})
|
||||||
if err = binary.Write(raw, binary.LittleEndian, int32(len(buf))); err != nil {
|
if err = binary.Write(raw, binary.LittleEndian, int32(len(buf))); err != nil {
|
||||||
@ -407,6 +392,7 @@ func GetLenBytes(buf []byte) (b []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//udp connection setting
|
||||||
func SetUdpSession(sess *kcp.UDPSession) {
|
func SetUdpSession(sess *kcp.UDPSession) {
|
||||||
sess.SetStreamMode(true)
|
sess.SetStreamMode(true)
|
||||||
sess.SetWindowSize(1024, 1024)
|
sess.SetWindowSize(1024, 1024)
|
||||||
@ -450,13 +436,7 @@ func GetConn(conn net.Conn, cpt, snappy bool, rt *rate.Rate, isServer bool) (io.
|
|||||||
}
|
}
|
||||||
return rate.NewRateConn(crypt.NewTlsClientConn(conn), rt)
|
return rate.NewRateConn(crypt.NewTlsClientConn(conn), rt)
|
||||||
} else if snappy {
|
} else if snappy {
|
||||||
return NewSnappyConn(conn, cpt, rt)
|
return rate.NewRateConn(NewSnappyConn(conn), rt)
|
||||||
}
|
}
|
||||||
return rate.NewRateConn(conn, rt)
|
return rate.NewRateConn(conn, rt)
|
||||||
}
|
}
|
||||||
|
|
||||||
//read length or id (content length=4)
|
|
||||||
func GetLen(reader io.Reader) (int, error) {
|
|
||||||
var l int32
|
|
||||||
return int(l), binary.Read(reader, binary.LittleEndian, &l)
|
|
||||||
}
|
|
||||||
|
@ -2,22 +2,20 @@ package conn
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/pool"
|
"github.com/cnlh/nps/lib/pool"
|
||||||
"github.com/cnlh/nps/lib/rate"
|
|
||||||
"github.com/cnlh/nps/vender/github.com/golang/snappy"
|
"github.com/cnlh/nps/vender/github.com/golang/snappy"
|
||||||
|
"github.com/fatedier/frp/utils/net"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SnappyConn struct {
|
type SnappyConn struct {
|
||||||
w *snappy.Writer
|
w *snappy.Writer
|
||||||
r *snappy.Reader
|
r *snappy.Reader
|
||||||
rate *rate.Rate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSnappyConn(conn io.ReadWriteCloser, crypt bool, rate *rate.Rate) *SnappyConn {
|
func NewSnappyConn(conn io.ReadWriteCloser) net.Conn {
|
||||||
c := new(SnappyConn)
|
c := new(SnappyConn)
|
||||||
c.w = snappy.NewBufferedWriter(conn)
|
c.w = snappy.NewBufferedWriter(conn)
|
||||||
c.r = snappy.NewReader(conn)
|
c.r = snappy.NewReader(conn)
|
||||||
c.rate = rate
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,9 +27,6 @@ func (s *SnappyConn) Write(b []byte) (n int, err error) {
|
|||||||
if err = s.w.Flush(); err != nil {
|
if err = s.w.Flush(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.rate != nil {
|
|
||||||
s.rate.Get(int64(n))
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,9 +38,6 @@ func (s *SnappyConn) Read(b []byte) (n int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
copy(b, buf[:n])
|
copy(b, buf[:n])
|
||||||
if s.rate != nil {
|
|
||||||
s.rate.Get(int64(n))
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package file
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,3 +21,15 @@ func GetCsvDb() *Csv {
|
|||||||
})
|
})
|
||||||
return CsvDb
|
return CsvDb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMapKeys(m sync.Map, isSort bool, sortKey, order string) (keys []int) {
|
||||||
|
if sortKey != "" && isSort {
|
||||||
|
return sortClientByKey(m, sortKey, order)
|
||||||
|
}
|
||||||
|
m.Range(func(key, value interface{}) bool {
|
||||||
|
keys = append(keys, key.(int))
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
sort.Ints(keys)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/cnlh/nps/lib/common"
|
"github.com/cnlh/nps/lib/common"
|
||||||
"github.com/cnlh/nps/lib/crypt"
|
"github.com/cnlh/nps/lib/crypt"
|
||||||
"github.com/cnlh/nps/lib/rate"
|
"github.com/cnlh/nps/lib/rate"
|
||||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
|
||||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -52,7 +51,7 @@ func (s *Csv) StoreTasksToCsv() {
|
|||||||
record := []string{
|
record := []string{
|
||||||
strconv.Itoa(task.Port),
|
strconv.Itoa(task.Port),
|
||||||
task.Mode,
|
task.Mode,
|
||||||
task.Target,
|
task.Target.TargetStr,
|
||||||
common.GetStrByBool(task.Status),
|
common.GetStrByBool(task.Status),
|
||||||
strconv.Itoa(task.Id),
|
strconv.Itoa(task.Id),
|
||||||
strconv.Itoa(task.Client.Id),
|
strconv.Itoa(task.Client.Id),
|
||||||
@ -101,12 +100,13 @@ func (s *Csv) LoadTaskFromCsv() {
|
|||||||
post := &Tunnel{
|
post := &Tunnel{
|
||||||
Port: common.GetIntNoErrByStr(item[0]),
|
Port: common.GetIntNoErrByStr(item[0]),
|
||||||
Mode: item[1],
|
Mode: item[1],
|
||||||
Target: item[2],
|
|
||||||
Status: common.GetBoolByStr(item[3]),
|
Status: common.GetBoolByStr(item[3]),
|
||||||
Id: common.GetIntNoErrByStr(item[4]),
|
Id: common.GetIntNoErrByStr(item[4]),
|
||||||
Remark: item[6],
|
Remark: item[6],
|
||||||
Password: item[9],
|
Password: item[9],
|
||||||
}
|
}
|
||||||
|
post.Target = new(Target)
|
||||||
|
post.Target.TargetStr = item[2]
|
||||||
post.Flow = new(Flow)
|
post.Flow = new(Flow)
|
||||||
post.Flow.ExportFlow = int64(common.GetIntNoErrByStr(item[7]))
|
post.Flow.ExportFlow = int64(common.GetIntNoErrByStr(item[7]))
|
||||||
post.Flow.InletFlow = int64(common.GetIntNoErrByStr(item[8]))
|
post.Flow.InletFlow = int64(common.GetIntNoErrByStr(item[8]))
|
||||||
@ -212,7 +212,7 @@ func (s *Csv) StoreHostToCsv() {
|
|||||||
}
|
}
|
||||||
record := []string{
|
record := []string{
|
||||||
host.Host,
|
host.Host,
|
||||||
host.Target,
|
host.Target.TargetStr,
|
||||||
strconv.Itoa(host.Client.Id),
|
strconv.Itoa(host.Client.Id),
|
||||||
host.HeaderChange,
|
host.HeaderChange,
|
||||||
host.HostChange,
|
host.HostChange,
|
||||||
@ -274,6 +274,16 @@ func (s *Csv) LoadClientFromCsv() {
|
|||||||
} else {
|
} else {
|
||||||
post.ConfigConnAllow = true
|
post.ConfigConnAllow = true
|
||||||
}
|
}
|
||||||
|
if len(item) >= 13 {
|
||||||
|
post.WebUserName = item[12]
|
||||||
|
} else {
|
||||||
|
post.WebUserName = ""
|
||||||
|
}
|
||||||
|
if len(item) >= 14 {
|
||||||
|
post.WebPassword = item[13]
|
||||||
|
} else {
|
||||||
|
post.WebPassword = ""
|
||||||
|
}
|
||||||
s.Clients.Store(post.Id, post)
|
s.Clients.Store(post.Id, post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,7 +299,6 @@ func (s *Csv) LoadHostFromCsv() {
|
|||||||
for _, item := range records {
|
for _, item := range records {
|
||||||
post := &Host{
|
post := &Host{
|
||||||
Host: item[0],
|
Host: item[0],
|
||||||
Target: item[1],
|
|
||||||
HeaderChange: item[3],
|
HeaderChange: item[3],
|
||||||
HostChange: item[4],
|
HostChange: item[4],
|
||||||
Remark: item[5],
|
Remark: item[5],
|
||||||
@ -299,6 +308,8 @@ func (s *Csv) LoadHostFromCsv() {
|
|||||||
if post.Client, err = s.GetClient(common.GetIntNoErrByStr(item[2])); err != nil {
|
if post.Client, err = s.GetClient(common.GetIntNoErrByStr(item[2])); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
post.Target = new(Target)
|
||||||
|
post.Target.TargetStr = item[1]
|
||||||
post.Flow = new(Flow)
|
post.Flow = new(Flow)
|
||||||
post.Flow.ExportFlow = int64(common.GetIntNoErrByStr(item[8]))
|
post.Flow.ExportFlow = int64(common.GetIntNoErrByStr(item[8]))
|
||||||
post.Flow.InletFlow = int64(common.GetIntNoErrByStr(item[9]))
|
post.Flow.InletFlow = int64(common.GetIntNoErrByStr(item[9]))
|
||||||
@ -344,12 +355,12 @@ func (s *Csv) IsHostExist(h *Host) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Csv) NewHost(t *Host) error {
|
func (s *Csv) NewHost(t *Host) error {
|
||||||
if s.IsHostExist(t) {
|
|
||||||
return errors.New("host has exist")
|
|
||||||
}
|
|
||||||
if t.Location == "" {
|
if t.Location == "" {
|
||||||
t.Location = "/"
|
t.Location = "/"
|
||||||
}
|
}
|
||||||
|
if s.IsHostExist(t) {
|
||||||
|
return errors.New("host has exist")
|
||||||
|
}
|
||||||
t.Flow = new(Flow)
|
t.Flow = new(Flow)
|
||||||
s.Hosts.Store(t.Id, t)
|
s.Hosts.Store(t.Id, t)
|
||||||
s.StoreHostToCsv()
|
s.StoreHostToCsv()
|
||||||
@ -359,7 +370,7 @@ func (s *Csv) NewHost(t *Host) error {
|
|||||||
func (s *Csv) GetHost(start, length int, id int, search string) ([]*Host, int) {
|
func (s *Csv) GetHost(start, length int, id int, search string) ([]*Host, int) {
|
||||||
list := make([]*Host, 0)
|
list := make([]*Host, 0)
|
||||||
var cnt int
|
var cnt int
|
||||||
keys := common.GetMapKeys(s.Hosts)
|
keys := GetMapKeys(s.Hosts, false, "", "")
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if value, ok := s.Hosts.Load(key); ok {
|
if value, ok := s.Hosts.Load(key); ok {
|
||||||
v := value.(*Host)
|
v := value.(*Host)
|
||||||
@ -387,6 +398,9 @@ func (s *Csv) DelClient(id int) error {
|
|||||||
|
|
||||||
func (s *Csv) NewClient(c *Client) error {
|
func (s *Csv) NewClient(c *Client) error {
|
||||||
var isNotSet bool
|
var isNotSet bool
|
||||||
|
if c.WebUserName != "" && !s.VerifyUserName(c.WebUserName, c.Id) {
|
||||||
|
return errors.New("web login username duplicate, please reset")
|
||||||
|
}
|
||||||
reset:
|
reset:
|
||||||
if c.VerifyKey == "" || isNotSet {
|
if c.VerifyKey == "" || isNotSet {
|
||||||
isNotSet = true
|
isNotSet = true
|
||||||
@ -396,7 +410,7 @@ reset:
|
|||||||
c.Rate = rate.NewRate(int64(2 << 23))
|
c.Rate = rate.NewRate(int64(2 << 23))
|
||||||
c.Rate.Start()
|
c.Rate.Start()
|
||||||
}
|
}
|
||||||
if !s.VerifyVkey(c.VerifyKey, c.id) {
|
if !s.VerifyVkey(c.VerifyKey, c.Id) {
|
||||||
if isNotSet {
|
if isNotSet {
|
||||||
goto reset
|
goto reset
|
||||||
}
|
}
|
||||||
@ -425,6 +439,18 @@ func (s *Csv) VerifyVkey(vkey string, id int) (res bool) {
|
|||||||
})
|
})
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
func (s *Csv) VerifyUserName(username string, id int) (res bool) {
|
||||||
|
res = true
|
||||||
|
s.Clients.Range(func(key, value interface{}) bool {
|
||||||
|
v := value.(*Client)
|
||||||
|
if v.WebUserName == username && v.Id != id {
|
||||||
|
res = false
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Csv) GetClientId() int32 {
|
func (s *Csv) GetClientId() int32 {
|
||||||
return atomic.AddInt32(&s.ClientIncreaseId, 1)
|
return atomic.AddInt32(&s.ClientIncreaseId, 1)
|
||||||
@ -447,10 +473,10 @@ func (s *Csv) UpdateClient(t *Client) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Csv) GetClientList(start, length int, search string, clientId int) ([]*Client, int) {
|
func (s *Csv) GetClientList(start, length int, search, sort, order string, clientId int) ([]*Client, int) {
|
||||||
list := make([]*Client, 0)
|
list := make([]*Client, 0)
|
||||||
var cnt int
|
var cnt int
|
||||||
keys := common.GetMapKeys(s.Clients)
|
keys := GetMapKeys(s.Clients, true, sort, order)
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if value, ok := s.Clients.Load(key); ok {
|
if value, ok := s.Clients.Load(key); ok {
|
||||||
v := value.(*Client)
|
v := value.(*Client)
|
||||||
@ -477,11 +503,7 @@ func (s *Csv) GetClientList(start, length int, search string, clientId int) ([]*
|
|||||||
func (s *Csv) IsPubClient(id int) bool {
|
func (s *Csv) IsPubClient(id int) bool {
|
||||||
client, err := s.GetClient(id)
|
client, err := s.GetClient(id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if client.VerifyKey == beego.AppConfig.String("public_vkey") {
|
return client.NoDisplay
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -589,6 +611,8 @@ func (s *Csv) StoreClientsToCsv() {
|
|||||||
strconv.Itoa(int(client.Flow.FlowLimit)),
|
strconv.Itoa(int(client.Flow.FlowLimit)),
|
||||||
strconv.Itoa(int(client.MaxConn)),
|
strconv.Itoa(int(client.MaxConn)),
|
||||||
common.GetStrByBool(client.ConfigConnAllow),
|
common.GetStrByBool(client.ConfigConnAllow),
|
||||||
|
client.WebUserName,
|
||||||
|
client.WebPassword,
|
||||||
}
|
}
|
||||||
err := writer.Write(record)
|
err := writer.Write(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
131
lib/file/obj.go
131
lib/file/obj.go
@ -5,13 +5,14 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Flow struct {
|
type Flow struct {
|
||||||
ExportFlow int64 //出口流量
|
ExportFlow int64
|
||||||
InletFlow int64 //入口流量
|
InletFlow int64
|
||||||
FlowLimit int64 //流量限制,出口+入口 /M
|
FlowLimit int64
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,20 +26,21 @@ func (s *Flow) Add(in, out int64) {
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
Cnf *Config
|
Cnf *Config
|
||||||
Id int //id
|
Id int //id
|
||||||
VerifyKey string //验证密钥
|
VerifyKey string //verify key
|
||||||
Addr string //客户端ip地址
|
Addr string //the ip of client
|
||||||
Remark string //备注
|
Remark string //remark
|
||||||
Status bool //是否开启
|
Status bool //is allow connect
|
||||||
IsConnect bool //是否连接
|
IsConnect bool //is the client connect
|
||||||
RateLimit int //速度限制 /kb
|
RateLimit int //rate /kb
|
||||||
Flow *Flow //流量
|
Flow *Flow //flow setting
|
||||||
Rate *rate.Rate //速度控制
|
Rate *rate.Rate //rate limit
|
||||||
NoStore bool
|
NoStore bool //no store to file
|
||||||
NoDisplay bool
|
NoDisplay bool //no display on web
|
||||||
MaxConn int //客户端最大连接数
|
MaxConn int //the max connection num of client allow
|
||||||
NowConn int //当前连接数
|
NowConn int32 //the connection num of now
|
||||||
id int
|
WebUserName string //the username of web login
|
||||||
ConfigConnAllow bool
|
WebPassword string //the password of web login
|
||||||
|
ConfigConnAllow bool //is allow connected by config file
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,30 +63,21 @@ func NewClient(vKey string, noStore bool, noDisplay bool) *Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Client) CutConn() {
|
func (s *Client) CutConn() {
|
||||||
s.Lock()
|
atomic.AddInt32(&s.NowConn, 1)
|
||||||
defer s.Unlock()
|
|
||||||
s.NowConn++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Client) AddConn() {
|
func (s *Client) AddConn() {
|
||||||
s.Lock()
|
atomic.AddInt32(&s.NowConn, -1)
|
||||||
defer s.Unlock()
|
|
||||||
s.NowConn--
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Client) GetConn() bool {
|
func (s *Client) GetConn() bool {
|
||||||
if s.MaxConn == 0 || s.NowConn < s.MaxConn {
|
if s.MaxConn == 0 || int(s.NowConn) < s.MaxConn {
|
||||||
s.CutConn()
|
s.CutConn()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//modify the hosts and the tunnels by health information
|
|
||||||
func (s *Client) ModifyTarget() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Client) HasTunnel(t *Tunnel) (exist bool) {
|
func (s *Client) HasTunnel(t *Tunnel) (exist bool) {
|
||||||
GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*Tunnel)
|
v := value.(*Tunnel)
|
||||||
@ -114,13 +107,11 @@ type Tunnel struct {
|
|||||||
Id int //Id
|
Id int //Id
|
||||||
Port int //服务端监听端口
|
Port int //服务端监听端口
|
||||||
ServerIp string
|
ServerIp string
|
||||||
Mode string //启动方式
|
Mode string //启动方式
|
||||||
Target string //目标
|
Status bool //设置是否开启
|
||||||
TargetArr []string //目标
|
RunStatus bool //当前运行状态
|
||||||
Status bool //设置是否开启
|
Client *Client //所属客户端id
|
||||||
RunStatus bool //当前运行状态
|
Ports string //客户端与服务端传递
|
||||||
Client *Client //所属客户端id
|
|
||||||
Ports string //客户端与服务端传递
|
|
||||||
Flow *Flow
|
Flow *Flow
|
||||||
Password string //私密模式密码,唯一
|
Password string //私密模式密码,唯一
|
||||||
Remark string //备注
|
Remark string //备注
|
||||||
@ -128,7 +119,7 @@ type Tunnel struct {
|
|||||||
NoStore bool
|
NoStore bool
|
||||||
LocalPath string
|
LocalPath string
|
||||||
StripPre string
|
StripPre string
|
||||||
NowIndex int
|
Target *Target
|
||||||
Health
|
Health
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
@ -146,9 +137,16 @@ type Health struct {
|
|||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Tunnel) GetRandomTarget() (string, error) {
|
type Target struct {
|
||||||
|
nowIndex int
|
||||||
|
TargetStr string
|
||||||
|
TargetArr []string //目标
|
||||||
|
sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Target) GetRandomTarget() (string, error) {
|
||||||
if s.TargetArr == nil {
|
if s.TargetArr == nil {
|
||||||
s.TargetArr = strings.Split(s.Target, "\n")
|
s.TargetArr = strings.Split(s.TargetStr, "\n")
|
||||||
}
|
}
|
||||||
if len(s.TargetArr) == 1 {
|
if len(s.TargetArr) == 1 {
|
||||||
return s.TargetArr[0], nil
|
return s.TargetArr[0], nil
|
||||||
@ -158,54 +156,33 @@ func (s *Tunnel) GetRandomTarget() (string, error) {
|
|||||||
}
|
}
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
if s.NowIndex >= len(s.TargetArr)-1 {
|
if s.nowIndex >= len(s.TargetArr)-1 {
|
||||||
s.NowIndex = -1
|
s.nowIndex = -1
|
||||||
}
|
}
|
||||||
s.NowIndex++
|
s.nowIndex++
|
||||||
return s.TargetArr[s.NowIndex], nil
|
return s.TargetArr[s.nowIndex], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
U string //socks5验证用户名
|
U string
|
||||||
P string //socks5验证密码
|
P string
|
||||||
Compress bool //压缩方式
|
Compress bool
|
||||||
Crypt bool //是否加密
|
Crypt bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Host struct {
|
type Host struct {
|
||||||
Id int
|
Id int
|
||||||
Host string //启动方式
|
Host string //host
|
||||||
Target string //目标
|
HeaderChange string //header change
|
||||||
HeaderChange string //host修改
|
HostChange string //host change
|
||||||
HostChange string //host修改
|
Location string //url router
|
||||||
Location string //url 路由
|
Remark string //remark
|
||||||
|
Scheme string //http https all
|
||||||
|
NoStore bool
|
||||||
|
IsClose bool
|
||||||
Flow *Flow
|
Flow *Flow
|
||||||
Client *Client
|
Client *Client
|
||||||
Remark string //备注
|
Target *Target //目标
|
||||||
NowIndex int
|
|
||||||
TargetArr []string
|
|
||||||
NoStore bool
|
|
||||||
Scheme string //http https all
|
|
||||||
IsClose bool
|
|
||||||
Health
|
Health
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Host) GetRandomTarget() (string, error) {
|
|
||||||
if s.TargetArr == nil {
|
|
||||||
s.TargetArr = strings.Split(s.Target, "\n")
|
|
||||||
}
|
|
||||||
if len(s.TargetArr) == 1 {
|
|
||||||
return s.TargetArr[0], nil
|
|
||||||
}
|
|
||||||
if len(s.TargetArr) == 0 {
|
|
||||||
return "", errors.New("all inward-bending targets are offline")
|
|
||||||
}
|
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
if s.NowIndex >= len(s.TargetArr)-1 {
|
|
||||||
s.NowIndex = -1
|
|
||||||
}
|
|
||||||
s.NowIndex++
|
|
||||||
return s.TargetArr[s.NowIndex], nil
|
|
||||||
}
|
|
||||||
|
41
lib/file/sort.go
Normal file
41
lib/file/sort.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A data structure to hold a key/value pair.
|
||||||
|
type Pair struct {
|
||||||
|
key string //sort key
|
||||||
|
cId int
|
||||||
|
order string
|
||||||
|
clientFlow *Flow
|
||||||
|
}
|
||||||
|
|
||||||
|
// A slice of Pairs that implements sort.Interface to sort by Value.
|
||||||
|
type PairList []*Pair
|
||||||
|
|
||||||
|
func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||||
|
func (p PairList) Len() int { return len(p) }
|
||||||
|
func (p PairList) Less(i, j int) bool {
|
||||||
|
if p[i].order == "desc" {
|
||||||
|
return reflect.ValueOf(*p[i].clientFlow).FieldByName(p[i].key).Int() < reflect.ValueOf(*p[j].clientFlow).FieldByName(p[j].key).Int()
|
||||||
|
}
|
||||||
|
return reflect.ValueOf(*p[i].clientFlow).FieldByName(p[i].key).Int() > reflect.ValueOf(*p[j].clientFlow).FieldByName(p[j].key).Int()
|
||||||
|
}
|
||||||
|
|
||||||
|
// A function to turn a map into a PairList, then sort and return it.
|
||||||
|
func sortClientByKey(m sync.Map, sortKey, order string) (res []int) {
|
||||||
|
p := make(PairList, 0)
|
||||||
|
m.Range(func(key, value interface{}) bool {
|
||||||
|
p = append(p, &Pair{sortKey, value.(*Client).Id, order, value.(*Client).Flow})
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
sort.Sort(p)
|
||||||
|
for _, v := range p {
|
||||||
|
res = append(res, v.cId)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -59,16 +59,9 @@ func (s *Mux) NewConn() (*conn, error) {
|
|||||||
return nil, errors.New("the mux has closed")
|
return nil, errors.New("the mux has closed")
|
||||||
}
|
}
|
||||||
conn := NewConn(s.getId(), s)
|
conn := NewConn(s.getId(), s)
|
||||||
raw := bytes.NewBuffer([]byte{})
|
|
||||||
if err := binary.Write(raw, binary.LittleEndian, MUX_NEW_CONN); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := binary.Write(raw, binary.LittleEndian, conn.connId); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
//it must be set before send
|
//it must be set before send
|
||||||
s.connMap.Set(conn.connId, conn)
|
s.connMap.Set(conn.connId, conn)
|
||||||
if _, err := s.conn.Write(raw.Bytes()); err != nil {
|
if err := s.sendInfo(MUX_NEW_CONN, conn.connId, nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
//set a timer timeout 30 second
|
//set a timer timeout 30 second
|
||||||
|
@ -25,14 +25,14 @@ func TestNewMux(t *testing.T) {
|
|||||||
client()
|
client()
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
go func() {
|
go func() {
|
||||||
m2 := NewMux(conn2)
|
m2 := NewMux(conn2, "tcp")
|
||||||
for {
|
for {
|
||||||
c, err := m2.Accept()
|
c, err := m2.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
go func(c net.Conn) {
|
go func(c net.Conn) {
|
||||||
c2, err := net.Dial("tcp", "10.1.50.196:4000")
|
c2, err := net.Dial("tcp", "127.0.0.1:8082")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ func TestNewMux(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
m1 := NewMux(conn1)
|
m1 := NewMux(conn1, "tcp")
|
||||||
l, err := net.Listen("tcp", "127.0.0.1:7777")
|
l, err := net.Listen("tcp", "127.0.0.1:7777")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
@ -52,12 +52,6 @@ func GetBufPoolCopy() ([]byte) {
|
|||||||
return (*BufPoolCopy.Get().(*[]byte))[:PoolSizeCopy]
|
return (*BufPoolCopy.Get().(*[]byte))[:PoolSizeCopy]
|
||||||
}
|
}
|
||||||
|
|
||||||
func PutBufPoolSmall(buf []byte) {
|
|
||||||
if cap(buf) == PoolSizeSmall {
|
|
||||||
BufPoolSmall.Put(buf[:PoolSizeSmall])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PutBufPoolMax(buf []byte) {
|
func PutBufPoolMax(buf []byte) {
|
||||||
if cap(buf) == PoolSize {
|
if cap(buf) == PoolSize {
|
||||||
BufPoolMax.Put(buf[:PoolSize])
|
BufPoolMax.Put(buf[:PoolSize])
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Rate struct {
|
type Rate struct {
|
||||||
bucketSize int64 //木桶容量
|
bucketSize int64
|
||||||
bucketSurplusSize int64 //当前桶中体积
|
bucketSurplusSize int64
|
||||||
bucketAddSize int64 //每次加水大小
|
bucketAddSize int64
|
||||||
stopChan chan bool //停止
|
stopChan chan bool
|
||||||
NowRate int64
|
NowRate int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,5 @@ func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string,
|
|||||||
}
|
}
|
||||||
conn.CopyWaitGroup(target, c.Conn, link.Crypt, link.Compress, client.Rate, flow, true, rb)
|
conn.CopyWaitGroup(target, c.Conn, link.Crypt, link.Compress, client.Rate, flow, true, rb)
|
||||||
}
|
}
|
||||||
client.AddConn()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -85,11 +85,12 @@ func (s *httpServer) processHttps(c net.Conn) {
|
|||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer host.Client.AddConn()
|
||||||
if err = s.auth(r, conn.NewConn(c), host.Client.Cnf.U, host.Client.Cnf.P); err != nil {
|
if err = s.auth(r, conn.NewConn(c), host.Client.Cnf.U, host.Client.Cnf.P); err != nil {
|
||||||
logs.Warn("auth error", err, r.RemoteAddr)
|
logs.Warn("auth error", err, r.RemoteAddr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if targetAddr, err = host.GetRandomTarget(); err != nil {
|
if targetAddr, err = host.Target.GetRandomTarget(); err != nil {
|
||||||
logs.Warn(err.Error())
|
logs.Warn(err.Error())
|
||||||
}
|
}
|
||||||
logs.Trace("new https connection,clientId %d,host %s,remote address %s", host.Client.Id, r.Host, c.RemoteAddr().String())
|
logs.Trace("new https connection,clientId %d,host %s,remote address %s", host.Client.Id, r.Host, c.RemoteAddr().String())
|
||||||
@ -101,7 +102,6 @@ func (s *httpServer) Start() error {
|
|||||||
if s.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil {
|
if s.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil {
|
||||||
s.errorContent = []byte("easyProxy 404")
|
s.errorContent = []byte("easyProxy 404")
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.httpPort > 0 {
|
if s.httpPort > 0 {
|
||||||
s.httpServer = s.NewServer(s.httpPort, "http")
|
s.httpServer = s.NewServer(s.httpPort, "http")
|
||||||
go func() {
|
go func() {
|
||||||
@ -181,7 +181,6 @@ func (s *httpServer) handleTunneling(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) process(c *conn.Conn, r *http.Request) {
|
func (s *httpServer) process(c *conn.Conn, r *http.Request) {
|
||||||
//多客户端域名代理
|
|
||||||
var (
|
var (
|
||||||
isConn = true
|
isConn = true
|
||||||
host *file.Host
|
host *file.Host
|
||||||
@ -203,6 +202,7 @@ func (s *httpServer) process(c *conn.Conn, r *http.Request) {
|
|||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer host.Client.AddConn()
|
||||||
logs.Trace("new %s connection,clientId %d,host %s,url %s,remote address %s", r.URL.Scheme, host.Client.Id, r.Host, r.URL, r.RemoteAddr)
|
logs.Trace("new %s connection,clientId %d,host %s,url %s,remote address %s", r.URL.Scheme, host.Client.Id, r.Host, r.URL, r.RemoteAddr)
|
||||||
lastHost = host
|
lastHost = host
|
||||||
for {
|
for {
|
||||||
@ -212,7 +212,7 @@ func (s *httpServer) process(c *conn.Conn, r *http.Request) {
|
|||||||
logs.Warn("auth error", err, r.RemoteAddr)
|
logs.Warn("auth error", err, r.RemoteAddr)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if targetAddr, err = host.GetRandomTarget(); err != nil {
|
if targetAddr, err = host.Target.GetRandomTarget(); err != nil {
|
||||||
logs.Warn(err.Error())
|
logs.Warn(err.Error())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -249,10 +249,6 @@ func (s *httpServer) process(c *conn.Conn, r *http.Request) {
|
|||||||
logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
|
logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
|
||||||
break
|
break
|
||||||
} else if host != lastHost {
|
} else if host != lastHost {
|
||||||
host.Client.AddConn()
|
|
||||||
if !hostTmp.Client.GetConn() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
host = hostTmp
|
host = hostTmp
|
||||||
lastHost = host
|
lastHost = host
|
||||||
isConn = true
|
isConn = true
|
||||||
@ -283,9 +279,6 @@ end:
|
|||||||
target.Close()
|
target.Close()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if host != nil {
|
|
||||||
host.Client.AddConn()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) NewServer(port int, scheme string) *http.Server {
|
func (s *httpServer) NewServer(port int, scheme string) *http.Server {
|
||||||
|
@ -259,6 +259,7 @@ func (s *Sock5ModeServer) Start() error {
|
|||||||
}
|
}
|
||||||
logs.Trace("New socks5 connection,client %d,remote address %s", s.task.Client.Id, c.RemoteAddr())
|
logs.Trace("New socks5 connection,client %d,remote address %s", s.task.Client.Id, c.RemoteAddr())
|
||||||
s.handleConn(c)
|
s.handleConn(c)
|
||||||
|
s.task.Client.AddConn()
|
||||||
}, &s.listener)
|
}, &s.listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ func (s *TunnelModeServer) Start() error {
|
|||||||
}
|
}
|
||||||
logs.Trace("new tcp connection,local port %d,client %d,remote address %s", s.task.Port, s.task.Client.Id, c.RemoteAddr())
|
logs.Trace("new tcp connection,local port %d,client %d,remote address %s", s.task.Port, s.task.Client.Id, c.RemoteAddr())
|
||||||
s.process(conn.NewConn(c), s)
|
s.process(conn.NewConn(c), s)
|
||||||
|
s.task.Client.AddConn()
|
||||||
}, &s.listener)
|
}, &s.listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ type process func(c *conn.Conn, s *TunnelModeServer) error
|
|||||||
|
|
||||||
//tcp隧道模式
|
//tcp隧道模式
|
||||||
func ProcessTunnel(c *conn.Conn, s *TunnelModeServer) error {
|
func ProcessTunnel(c *conn.Conn, s *TunnelModeServer) error {
|
||||||
targetAddr, err := s.task.GetRandomTarget()
|
targetAddr, err := s.task.Target.GetRandomTarget()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
logs.Warn("tcp port %d ,client id %d,task id %d connect error %s", s.task.Port, s.task.Client.Id, s.task.Id, err.Error())
|
logs.Warn("tcp port %d ,client id %d,task id %d connect error %s", s.task.Port, s.task.Client.Id, s.task.Id, err.Error())
|
||||||
|
@ -54,7 +54,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer s.task.Client.AddConn()
|
defer s.task.Client.AddConn()
|
||||||
link := conn.NewLink(common.CONN_UDP, s.task.Target, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, addr.String())
|
link := conn.NewLink(common.CONN_UDP, s.task.Target.TargetStr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, addr.String())
|
||||||
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, addr.String(), s.task); err != nil {
|
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, addr.String(), s.task); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,8 +57,12 @@ func DealBridgeTask() {
|
|||||||
case t := <-Bridge.CloseTask:
|
case t := <-Bridge.CloseTask:
|
||||||
StopServer(t.Id)
|
StopServer(t.Id)
|
||||||
case id := <-Bridge.CloseClient:
|
case id := <-Bridge.CloseClient:
|
||||||
DelTunnelAndHostByClientId(id)
|
DelTunnelAndHostByClientId(id, true)
|
||||||
file.GetCsvDb().DelClient(id)
|
if v, ok := file.GetCsvDb().Clients.Load(id); ok {
|
||||||
|
if v.(*file.Client).NoStore {
|
||||||
|
file.GetCsvDb().DelClient(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
case tunnel := <-Bridge.OpenTask:
|
case tunnel := <-Bridge.OpenTask:
|
||||||
StartTask(tunnel.Id)
|
StartTask(tunnel.Id)
|
||||||
case s := <-Bridge.SecretChan:
|
case s := <-Bridge.SecretChan:
|
||||||
@ -68,7 +72,7 @@ func DealBridgeTask() {
|
|||||||
logs.Info("Connections exceed the current client %d limit", t.Client.Id)
|
logs.Info("Connections exceed the current client %d limit", t.Client.Id)
|
||||||
s.Conn.Close()
|
s.Conn.Close()
|
||||||
} else if t.Status {
|
} else if t.Status {
|
||||||
go proxy.NewBaseServer(Bridge, t).DealClient(s.Conn, t.Client, t.Target, nil, common.CONN_TCP, nil, t.Flow)
|
go proxy.NewBaseServer(Bridge, t).DealClient(s.Conn, t.Client, t.Target.TargetStr, nil, common.CONN_TCP, nil, t.Flow)
|
||||||
} else {
|
} else {
|
||||||
s.Conn.Close()
|
s.Conn.Close()
|
||||||
logs.Trace("This key %s cannot be processed,status is close", s.Password)
|
logs.Trace("This key %s cannot be processed,status is close", s.Password)
|
||||||
@ -133,7 +137,6 @@ func NewMode(Bridge *bridge.Bridge, c *file.Tunnel) proxy.Service {
|
|||||||
t := &file.Tunnel{
|
t := &file.Tunnel{
|
||||||
Port: 0,
|
Port: 0,
|
||||||
Mode: "httpHostServer",
|
Mode: "httpHostServer",
|
||||||
Target: "",
|
|
||||||
Status: true,
|
Status: true,
|
||||||
}
|
}
|
||||||
AddTask(t)
|
AddTask(t)
|
||||||
@ -223,7 +226,7 @@ func DelTask(id int) error {
|
|||||||
func GetTunnel(start, length int, typeVal string, clientId int, search string) ([]*file.Tunnel, int) {
|
func GetTunnel(start, length int, typeVal string, clientId int, search string) ([]*file.Tunnel, int) {
|
||||||
list := make([]*file.Tunnel, 0)
|
list := make([]*file.Tunnel, 0)
|
||||||
var cnt int
|
var cnt int
|
||||||
keys := common.GetMapKeys(file.GetCsvDb().Tasks)
|
keys := file.GetMapKeys(file.GetCsvDb().Tasks, false, "", "")
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if value, ok := file.GetCsvDb().Tasks.Load(key); ok {
|
if value, ok := file.GetCsvDb().Tasks.Load(key); ok {
|
||||||
v := value.(*file.Tunnel)
|
v := value.(*file.Tunnel)
|
||||||
@ -255,8 +258,8 @@ func GetTunnel(start, length int, typeVal string, clientId int, search string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取客户端列表
|
//获取客户端列表
|
||||||
func GetClientList(start, length int, search string, clientId int) (list []*file.Client, cnt int) {
|
func GetClientList(start, length int, search, sort, order string, clientId int) (list []*file.Client, cnt int) {
|
||||||
list, cnt = file.GetCsvDb().GetClientList(start, length, search, clientId)
|
list, cnt = file.GetCsvDb().GetClientList(start, length, search, sort, order, clientId)
|
||||||
dealClientData()
|
dealClientData()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -293,10 +296,13 @@ func dealClientData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//根据客户端id删除其所属的所有隧道和域名
|
//根据客户端id删除其所属的所有隧道和域名
|
||||||
func DelTunnelAndHostByClientId(clientId int) {
|
func DelTunnelAndHostByClientId(clientId int, justDelNoStore bool) {
|
||||||
var ids []int
|
var ids []int
|
||||||
file.GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Tasks.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Tunnel)
|
v := value.(*file.Tunnel)
|
||||||
|
if justDelNoStore && !v.NoStore {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if v.Client.Id == clientId {
|
if v.Client.Id == clientId {
|
||||||
ids = append(ids, v.Id)
|
ids = append(ids, v.Id)
|
||||||
}
|
}
|
||||||
@ -308,6 +314,9 @@ func DelTunnelAndHostByClientId(clientId int) {
|
|||||||
ids = ids[:0]
|
ids = ids[:0]
|
||||||
file.GetCsvDb().Hosts.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Hosts.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Host)
|
v := value.(*file.Host)
|
||||||
|
if justDelNoStore && !v.NoStore {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if v.Client.Id == clientId {
|
if v.Client.Id == clientId {
|
||||||
ids = append(ids, v.Id)
|
ids = append(ids, v.Id)
|
||||||
}
|
}
|
||||||
@ -378,7 +387,7 @@ func GetDashboardData() map[string]interface{} {
|
|||||||
tcpCount := 0
|
tcpCount := 0
|
||||||
|
|
||||||
file.GetCsvDb().Clients.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Clients.Range(func(key, value interface{}) bool {
|
||||||
tcpCount += value.(*file.Client).NowConn
|
tcpCount += int(value.(*file.Client).NowConn)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
data["tcpCount"] = tcpCount
|
data["tcpCount"] = tcpCount
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/cnlh/nps/lib/file"
|
"github.com/cnlh/nps/lib/file"
|
||||||
"github.com/cnlh/nps/lib/rate"
|
"github.com/cnlh/nps/lib/rate"
|
||||||
"github.com/cnlh/nps/server"
|
"github.com/cnlh/nps/server"
|
||||||
|
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientController struct {
|
type ClientController struct {
|
||||||
@ -26,7 +27,7 @@ func (s *ClientController) List() {
|
|||||||
} else {
|
} else {
|
||||||
clientId = clientIdSession.(int)
|
clientId = clientIdSession.(int)
|
||||||
}
|
}
|
||||||
list, cnt := server.GetClientList(start, length, s.GetString("search"), clientId)
|
list, cnt := server.GetClientList(start, length, s.GetString("search"), s.GetString("sort"), s.GetString("order"), clientId)
|
||||||
s.AjaxTable(list, cnt, cnt)
|
s.AjaxTable(list, cnt, cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +52,8 @@ func (s *ClientController) Add() {
|
|||||||
ConfigConnAllow: s.GetBoolNoErr("config_conn_allow"),
|
ConfigConnAllow: s.GetBoolNoErr("config_conn_allow"),
|
||||||
RateLimit: s.GetIntNoErr("rate_limit"),
|
RateLimit: s.GetIntNoErr("rate_limit"),
|
||||||
MaxConn: s.GetIntNoErr("max_conn"),
|
MaxConn: s.GetIntNoErr("max_conn"),
|
||||||
|
WebUserName: s.GetString("web_username"),
|
||||||
|
WebPassword: s.GetString("web_password"),
|
||||||
Flow: &file.Flow{
|
Flow: &file.Flow{
|
||||||
ExportFlow: 0,
|
ExportFlow: 0,
|
||||||
InletFlow: 0,
|
InletFlow: 0,
|
||||||
@ -98,20 +101,29 @@ func (s *ClientController) Edit() {
|
|||||||
if c, err := file.GetCsvDb().GetClient(id); err != nil {
|
if c, err := file.GetCsvDb().GetClient(id); err != nil {
|
||||||
s.error()
|
s.error()
|
||||||
} else {
|
} else {
|
||||||
if !file.GetCsvDb().VerifyVkey(s.GetString("vkey"), c.Id) {
|
if s.GetString("web_username") != "" {
|
||||||
s.AjaxErr("Vkey duplicate, please reset")
|
if s.GetString("web_username") == beego.AppConfig.String("web_username") || !file.GetCsvDb().VerifyUserName(s.GetString("web_username"), c.Id) {
|
||||||
|
s.AjaxErr("web login username duplicate, please reset")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s.GetSession("isAdmin").(bool) {
|
||||||
|
if !file.GetCsvDb().VerifyVkey(s.GetString("vkey"), c.Id) {
|
||||||
|
s.AjaxErr("Vkey duplicate, please reset")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.VerifyKey = s.GetString("vkey")
|
||||||
|
c.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
|
||||||
|
c.RateLimit = s.GetIntNoErr("rate_limit")
|
||||||
|
c.MaxConn = s.GetIntNoErr("max_conn")
|
||||||
}
|
}
|
||||||
c.VerifyKey = s.GetString("vkey")
|
|
||||||
c.Remark = s.GetString("remark")
|
c.Remark = s.GetString("remark")
|
||||||
c.Cnf.U = s.GetString("u")
|
c.Cnf.U = s.GetString("u")
|
||||||
c.Cnf.P = s.GetString("p")
|
c.Cnf.P = s.GetString("p")
|
||||||
c.Cnf.Compress = common.GetBoolByStr(s.GetString("compress"))
|
c.Cnf.Compress = common.GetBoolByStr(s.GetString("compress"))
|
||||||
c.Cnf.Crypt = s.GetBoolNoErr("crypt")
|
c.Cnf.Crypt = s.GetBoolNoErr("crypt")
|
||||||
if s.GetSession("isAdmin").(bool) {
|
c.WebUserName = s.GetString("web_username")
|
||||||
c.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
|
c.WebPassword = s.GetString("web_password")
|
||||||
c.RateLimit = s.GetIntNoErr("rate_limit")
|
|
||||||
c.MaxConn = s.GetIntNoErr("max_conn")
|
|
||||||
}
|
|
||||||
c.ConfigConnAllow = s.GetBoolNoErr("config_conn_allow")
|
c.ConfigConnAllow = s.GetBoolNoErr("config_conn_allow")
|
||||||
if c.Rate != nil {
|
if c.Rate != nil {
|
||||||
c.Rate.Stop()
|
c.Rate.Stop()
|
||||||
@ -148,7 +160,7 @@ func (s *ClientController) Del() {
|
|||||||
if err := file.GetCsvDb().DelClient(id); err != nil {
|
if err := file.GetCsvDb().DelClient(id); err != nil {
|
||||||
s.AjaxErr("delete error")
|
s.AjaxErr("delete error")
|
||||||
}
|
}
|
||||||
server.DelTunnelAndHostByClientId(id)
|
server.DelTunnelAndHostByClientId(id, false)
|
||||||
server.DelClientConnect(id)
|
server.DelClientConnect(id)
|
||||||
s.AjaxOk("delete success")
|
s.AjaxOk("delete success")
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ func (s *IndexController) Add() {
|
|||||||
Port: s.GetIntNoErr("port"),
|
Port: s.GetIntNoErr("port"),
|
||||||
ServerIp: s.GetString("server_ip"),
|
ServerIp: s.GetString("server_ip"),
|
||||||
Mode: s.GetString("type"),
|
Mode: s.GetString("type"),
|
||||||
Target: s.GetString("target"),
|
Target: &file.Target{TargetStr: s.GetString("target")},
|
||||||
Id: int(file.GetCsvDb().GetTaskId()),
|
Id: int(file.GetCsvDb().GetTaskId()),
|
||||||
Status: true,
|
Status: true,
|
||||||
Remark: s.GetString("remark"),
|
Remark: s.GetString("remark"),
|
||||||
@ -145,29 +145,30 @@ func (s *IndexController) Edit() {
|
|||||||
if t, err := file.GetCsvDb().GetTask(id); err != nil {
|
if t, err := file.GetCsvDb().GetTask(id); err != nil {
|
||||||
s.error()
|
s.error()
|
||||||
} else {
|
} else {
|
||||||
var portChange bool
|
if client, err := file.GetCsvDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
|
||||||
|
s.AjaxErr("modified error,the client is not exist")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
t.Client = client
|
||||||
|
}
|
||||||
if s.GetIntNoErr("port") != t.Port {
|
if s.GetIntNoErr("port") != t.Port {
|
||||||
portChange = true
|
if !tool.TestServerPort(s.GetIntNoErr("port"), t.Mode) {
|
||||||
|
s.AjaxErr("The port cannot be opened because it may has been occupied or is no longer allowed.")
|
||||||
|
return
|
||||||
|
}
|
||||||
t.Port = s.GetIntNoErr("port")
|
t.Port = s.GetIntNoErr("port")
|
||||||
}
|
}
|
||||||
t.ServerIp = s.GetString("server_ip")
|
t.ServerIp = s.GetString("server_ip")
|
||||||
t.Mode = s.GetString("type")
|
t.Mode = s.GetString("type")
|
||||||
t.Target = s.GetString("target")
|
t.Target = &file.Target{TargetStr: s.GetString("target")}
|
||||||
t.Password = s.GetString("password")
|
t.Password = s.GetString("password")
|
||||||
t.Id = id
|
t.Id = id
|
||||||
t.LocalPath = s.GetString("local_path")
|
t.LocalPath = s.GetString("local_path")
|
||||||
t.StripPre = s.GetString("strip_pre")
|
t.StripPre = s.GetString("strip_pre")
|
||||||
t.Remark = s.GetString("remark")
|
t.Remark = s.GetString("remark")
|
||||||
if portChange && !tool.TestServerPort(t.Port, t.Mode) {
|
|
||||||
s.AjaxErr("The port cannot be opened because it may has been occupied or is no longer allowed.")
|
|
||||||
}
|
|
||||||
if t.Client, err = file.GetCsvDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
|
|
||||||
s.AjaxErr("modified error")
|
|
||||||
}
|
|
||||||
file.GetCsvDb().UpdateTask(t)
|
file.GetCsvDb().UpdateTask(t)
|
||||||
server.StopServer(t.Id)
|
server.StopServer(t.Id)
|
||||||
server.StartTask(t.Id)
|
server.StartTask(t.Id)
|
||||||
t.TargetArr = nil
|
|
||||||
}
|
}
|
||||||
s.AjaxOk("modified success")
|
s.AjaxOk("modified success")
|
||||||
}
|
}
|
||||||
@ -243,7 +244,7 @@ func (s *IndexController) AddHost() {
|
|||||||
h := &file.Host{
|
h := &file.Host{
|
||||||
Id: int(file.GetCsvDb().GetHostId()),
|
Id: int(file.GetCsvDb().GetHostId()),
|
||||||
Host: s.GetString("host"),
|
Host: s.GetString("host"),
|
||||||
Target: s.GetString("target"),
|
Target: &file.Target{TargetStr: s.GetString("target")},
|
||||||
HeaderChange: s.GetString("header"),
|
HeaderChange: s.GetString("header"),
|
||||||
HostChange: s.GetString("hostchange"),
|
HostChange: s.GetString("hostchange"),
|
||||||
Remark: s.GetString("remark"),
|
Remark: s.GetString("remark"),
|
||||||
@ -277,20 +278,29 @@ func (s *IndexController) EditHost() {
|
|||||||
if h, err := file.GetCsvDb().GetHostById(id); err != nil {
|
if h, err := file.GetCsvDb().GetHostById(id); err != nil {
|
||||||
s.error()
|
s.error()
|
||||||
} else {
|
} else {
|
||||||
|
if h.Host != s.GetString("host") {
|
||||||
|
tmpHost := new(file.Host)
|
||||||
|
tmpHost.Host = s.GetString("host")
|
||||||
|
tmpHost.Location = s.GetString("location")
|
||||||
|
tmpHost.Scheme = s.GetString("scheme")
|
||||||
|
if file.GetCsvDb().IsHostExist(tmpHost) {
|
||||||
|
s.AjaxErr("host has exist")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if client, err := file.GetCsvDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
|
||||||
|
s.AjaxErr("modified error,the client is not exist")
|
||||||
|
} else {
|
||||||
|
h.Client = client
|
||||||
|
}
|
||||||
h.Host = s.GetString("host")
|
h.Host = s.GetString("host")
|
||||||
h.Target = s.GetString("target")
|
h.Target = &file.Target{TargetStr: s.GetString("target")}
|
||||||
h.HeaderChange = s.GetString("header")
|
h.HeaderChange = s.GetString("header")
|
||||||
h.HostChange = s.GetString("hostchange")
|
h.HostChange = s.GetString("hostchange")
|
||||||
h.Remark = s.GetString("remark")
|
h.Remark = s.GetString("remark")
|
||||||
h.TargetArr = nil
|
|
||||||
h.Location = s.GetString("location")
|
h.Location = s.GetString("location")
|
||||||
h.Scheme = s.GetString("scheme")
|
h.Scheme = s.GetString("scheme")
|
||||||
file.GetCsvDb().StoreHostToCsv()
|
file.GetCsvDb().StoreHostToCsv()
|
||||||
var err error
|
|
||||||
if h.Client, err = file.GetCsvDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
|
|
||||||
s.AjaxErr("modified error")
|
|
||||||
}
|
|
||||||
h.TargetArr = nil
|
|
||||||
}
|
}
|
||||||
s.AjaxOk("modified success")
|
s.AjaxOk("modified success")
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,25 @@ func (self *LoginController) Verify() {
|
|||||||
server.Bridge.Register.Store(common.GetIpByAddr(self.Ctx.Request.RemoteAddr), time.Now().Add(time.Hour*time.Duration(2)))
|
server.Bridge.Register.Store(common.GetIpByAddr(self.Ctx.Request.RemoteAddr), time.Now().Add(time.Hour*time.Duration(2)))
|
||||||
}
|
}
|
||||||
b, err := beego.AppConfig.Bool("allow_user_login")
|
b, err := beego.AppConfig.Bool("allow_user_login")
|
||||||
if err == nil && b && self.GetString("username") == "user" && !auth {
|
if err == nil && b && !auth {
|
||||||
file.GetCsvDb().Clients.Range(func(key, value interface{}) bool {
|
file.GetCsvDb().Clients.Range(func(key, value interface{}) bool {
|
||||||
v := value.(*file.Client)
|
v := value.(*file.Client)
|
||||||
if v.VerifyKey == self.GetString("password") && v.Status {
|
if !v.Status || v.NoDisplay {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if v.WebUserName == "" && v.WebPassword == "" {
|
||||||
|
if self.GetString("username") != "user" || v.VerifyKey != self.GetString("password") {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
auth = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !auth && v.WebPassword == self.GetString("password") && self.GetString("username") == v.WebUserName {
|
||||||
|
auth = true
|
||||||
|
}
|
||||||
|
if auth {
|
||||||
self.SetSession("isAdmin", false)
|
self.SetSession("isAdmin", false)
|
||||||
self.SetSession("clientId", v.Id)
|
self.SetSession("clientId", v.Id)
|
||||||
auth = true
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -60,6 +60,20 @@
|
|||||||
<span class="help-block m-b-none">unique, non-filling will be generated automatically</span>
|
<span class="help-block m-b-none">unique, non-filling will be generated automatically</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group" id="web_username">
|
||||||
|
<label class="control-label col-sm-2" langtag="info-client-web-username">web登陆用户名</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input class="form-control" type="text" name="web_username"
|
||||||
|
placeholder="empty means to be unrestricted">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" id="web_password">
|
||||||
|
<label class="control-label col-sm-2" langtag="info-client-web-password">web登陆密码</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input class="form-control" type="text" name="web_password"
|
||||||
|
placeholder="empty means to be unrestricted">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group" id="config_conn_allow">
|
<div class="form-group" id="config_conn_allow">
|
||||||
<label class="control-label col-sm-2" langtag="info-config-conn-allow">是否允许客户端以配置文件模式连接</label>
|
<label class="control-label col-sm-2" langtag="info-config-conn-allow">是否允许客户端以配置文件模式连接</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
<span class="help-block m-b-none">only socks5 , web, HTTP forward proxy </span>
|
<span class="help-block m-b-none">only socks5 , web, HTTP forward proxy </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{if eq true .isAdmin}}
|
||||||
<div class="form-group" id="vkey">
|
<div class="form-group" id="vkey">
|
||||||
<label class="control-label col-sm-2" langtag="info-client-vkey">客户端验证密钥</label>
|
<label class="control-label col-sm-2" langtag="info-client-vkey">客户端验证密钥</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
@ -62,6 +63,21 @@
|
|||||||
<span class="help-block m-b-none">unique, non-filling will be generated automatically</span>
|
<span class="help-block m-b-none">unique, non-filling will be generated automatically</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
|
<div class="form-group" id="web_username">
|
||||||
|
<label class="control-label col-sm-2" langtag="info-client-web-username">web登陆用户名</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input class="form-control" value="{{.c.WebUserName}}" type="text" name="web_username"
|
||||||
|
placeholder="empty means to be unrestricted">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" id="web_password">
|
||||||
|
<label class="control-label col-sm-2" langtag="info-client-web-password">web登陆密码</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<input class="form-control" value="{{.c.WebPassword}}" type="text" name="web_password"
|
||||||
|
placeholder="empty means to be unrestricted">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group" id="config_conn_allow">
|
<div class="form-group" id="config_conn_allow">
|
||||||
<label class="control-label col-sm-2" langtag="info-config-conn-allow">是否允许客户端以配置文件模式连接</label>
|
<label class="control-label col-sm-2" langtag="info-config-conn-allow">是否允许客户端以配置文件模式连接</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
@ -93,7 +109,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-4 col-sm-offset-2">
|
<div class="col-sm-4 col-sm-offset-2">
|
||||||
<button class="btn btn-success" href="#" id="add"><i
|
<button class="btn btn-success" href="#" id="add"><i
|
||||||
class="fa fa-fw fa-lg fa-eye"></i>新增
|
class="fa fa-fw fa-lg fa-eye"></i><span langtag="info-save">保存</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -127,6 +127,8 @@
|
|||||||
+ '<b langtag="info-now-conn-num">当前连接数</b>:' + row.NowConn + `       `
|
+ '<b langtag="info-now-conn-num">当前连接数</b>:' + row.NowConn + `       `
|
||||||
+ '<b langtag="info-flow-limit">流量限制</b>:' + row.Flow.FlowLimit + `m       `
|
+ '<b langtag="info-flow-limit">流量限制</b>:' + row.Flow.FlowLimit + `m       `
|
||||||
+ '<b langtag="info-rate-limit">带宽限制</b>:' + row.RateLimit + `kb/s       `
|
+ '<b langtag="info-rate-limit">带宽限制</b>:' + row.RateLimit + `kb/s       `
|
||||||
|
+ '<b langtag="info-client-web-username">web登陆用户名</b>:' + row.WebUserName + `       `
|
||||||
|
+ '<b langtag="info-client-web-password">web登陆密码</b>:' + row.WebPassword + `       `
|
||||||
+ `       ` + "<br/><br>"
|
+ `       ` + "<br/><br>"
|
||||||
+ '<b langtag="info-crypt">加密</b>:' + row.Cnf.Crypt + `       `
|
+ '<b langtag="info-crypt">加密</b>:' + row.Cnf.Crypt + `       `
|
||||||
+ '<b langtag="info-compress">压缩</b>:' + row.Cnf.Compress + `       `
|
+ '<b langtag="info-compress">压缩</b>:' + row.Cnf.Compress + `       `
|
||||||
@ -141,19 +143,16 @@
|
|||||||
field: 'Id',//域值
|
field: 'Id',//域值
|
||||||
title: 'id',//标题
|
title: 'id',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Remark',//域值
|
field: 'Remark',//域值
|
||||||
title: 'remark',//标题
|
title: 'remark',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'VerifyKey',//域值
|
field: 'VerifyKey',//域值
|
||||||
title: 'vkey',//标题
|
title: 'vkey',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (!row.NoStore) {
|
if (!row.NoStore) {
|
||||||
return value
|
return value
|
||||||
@ -166,10 +165,9 @@
|
|||||||
field: 'Addr',//域值
|
field: 'Addr',//域值
|
||||||
title: 'client addr',//标题
|
title: 'client addr',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Addr',//域值
|
field: 'InletFlow',//域值
|
||||||
title: 'in flow',//标题
|
title: 'in flow',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
sortable: true,//启用排序
|
||||||
@ -178,7 +176,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Addr',//域值
|
field: 'ExportFlow',//域值
|
||||||
title: 'out flow',//标题
|
title: 'out flow',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
sortable: true,//启用排序
|
||||||
@ -190,7 +188,6 @@
|
|||||||
field: 'IsConnect',//域值
|
field: 'IsConnect',//域值
|
||||||
title: 'speed',//内容
|
title: 'speed',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
return change(row.Rate.NowRate) + "/S"
|
return change(row.Rate.NowRate) + "/S"
|
||||||
}
|
}
|
||||||
@ -199,7 +196,6 @@
|
|||||||
field: 'Status',//域值
|
field: 'Status',//域值
|
||||||
title: 'run',//内容
|
title: 'run',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (value) {
|
if (value) {
|
||||||
return '<span class="badge badge-primary">open</span>'
|
return '<span class="badge badge-primary">open</span>'
|
||||||
@ -212,7 +208,6 @@
|
|||||||
field: 'IsConnect',//域值
|
field: 'IsConnect',//域值
|
||||||
title: 'status',//内容
|
title: 'status',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (value) {
|
if (value) {
|
||||||
return '<span class="badge badge-primary">online</span>'
|
return '<span class="badge badge-primary">online</span>'
|
||||||
@ -225,7 +220,6 @@
|
|||||||
field: 'option',//域值
|
field: 'option',//域值
|
||||||
title: 'option',//内容
|
title: 'option',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
btn_group = '<div class="btn-group">'
|
btn_group = '<div class="btn-group">'
|
||||||
btn = `{{if eq true .isAdmin}}<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button>{{end}}<button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
btn = `{{if eq true .isAdmin}}<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button>{{end}}<button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
||||||
@ -241,7 +235,6 @@
|
|||||||
field: 'show',//域值
|
field: 'show',//域值
|
||||||
title: 'show',//内容
|
title: 'show',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
return `<button onclick="tunnel(` + row.Id + `)" class="btn-info">tunnel</button><button onclick="host(` + row.Id + `)" class="btn-primary">host</button>`
|
return `<button onclick="tunnel(` + row.Id + `)" class="btn-info">tunnel</button><button onclick="host(` + row.Id + `)" class="btn-primary">host</button>`
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
<label class="col-sm-2 control-label" langtag="info-target">内网目标(ip:端口)</label>
|
<label class="col-sm-2 control-label" langtag="info-target">内网目标(ip:端口)</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<textarea class="form-control" name="target" rows="4" placeholder="10.1.50.203:22
|
<textarea class="form-control" name="target" rows="4" placeholder="10.1.50.203:22
|
||||||
10.1.50.202:22">{{.t.Target}}</textarea>
|
10.1.50.202:22">{{.t.Target.TargetStr}}</textarea>
|
||||||
<span class="help-block m-b-none">can only fill in ports if it is local machine proxy, only tcp supports load balancing
|
<span class="help-block m-b-none">can only fill in ports if it is local machine proxy, only tcp supports load balancing
|
||||||
|
|
||||||
</span></div>
|
</span></div>
|
||||||
@ -89,7 +89,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-4 col-sm-offset-2">
|
<div class="col-sm-4 col-sm-offset-2">
|
||||||
<button class="btn btn-success" href="#" id="add"><i
|
<button class="btn btn-success" href="#" id="add"><i
|
||||||
class="fa fa-fw fa-lg fa-eye"></i>新增
|
class="fa fa-fw fa-lg fa-eye"></i><span langtag="info-save">保存</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
<textarea class="form-control" rows="4" type="text" name="target"
|
<textarea class="form-control" rows="4" type="text" name="target"
|
||||||
placeholder="such as
|
placeholder="such as
|
||||||
10.1.50.203:80
|
10.1.50.203:80
|
||||||
10.1.50.202:80">{{.h.Target}}</textarea>
|
10.1.50.202:80">{{.h.Target.TargetStr}}</textarea>
|
||||||
<span class="help-block m-b-none">Line break if load balancing</span>
|
<span class="help-block m-b-none">Line break if load balancing</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -74,7 +74,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-4 col-sm-offset-2">
|
<div class="col-sm-4 col-sm-offset-2">
|
||||||
<button class="btn btn-success" href="#" id="add"><i
|
<button class="btn btn-success" href="#" id="add"><i
|
||||||
class="fa fa-fw fa-lg fa-eye"></i>新增
|
class="fa fa-fw fa-lg fa-eye"></i><span langtag="info-save">保存</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,13 +77,13 @@
|
|||||||
field: 'Id',//域值
|
field: 'Id',//域值
|
||||||
title: 'id',//标题
|
title: 'id',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Id',//域值
|
field: 'Id',//域值
|
||||||
title: 'client id',//标题
|
title: 'client id',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
return row.Client.Id
|
return row.Client.Id
|
||||||
}
|
}
|
||||||
@ -92,37 +92,40 @@
|
|||||||
field: 'Remark',//域值
|
field: 'Remark',//域值
|
||||||
title: 'remark',//标题
|
title: 'remark',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Host',//域值
|
field: 'Host',//域值
|
||||||
title: 'host',//标题
|
title: 'host',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Scheme',//域值
|
field: 'Scheme',//域值
|
||||||
title: 'scheme',//标题
|
title: 'scheme',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Target',//域值
|
field: 'Target',//域值
|
||||||
title: 'target',//标题
|
title: 'target',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
|
formatter: function (value, row, index) {
|
||||||
|
return row.Target.TargetStr
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Location',//域值
|
field: 'Location',//域值
|
||||||
title: 'location',//标题
|
title: 'location',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: '',//域值
|
field: '',//域值
|
||||||
title: 'client status',//内容
|
title: 'client status',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (row.Client.IsConnect) {
|
if (row.Client.IsConnect) {
|
||||||
return '<span class="badge badge-primary">online</span>'
|
return '<span class="badge badge-primary">online</span>'
|
||||||
@ -135,7 +138,7 @@
|
|||||||
field: 'option',//域值
|
field: 'option',//域值
|
||||||
title: 'option',//内容
|
title: 'option',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
btn_group = '<div class="btn-group">'
|
btn_group = '<div class="btn-group">'
|
||||||
btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
||||||
|
@ -76,13 +76,11 @@
|
|||||||
field: 'Id',//域值
|
field: 'Id',//域值
|
||||||
title: 'id',//标题
|
title: 'id',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Id',//域值
|
field: 'Id',//域值
|
||||||
title: 'client id',//标题
|
title: 'client id',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
return row.Client.Id
|
return row.Client.Id
|
||||||
}
|
}
|
||||||
@ -91,37 +89,36 @@
|
|||||||
field: 'Remark',//域值
|
field: 'Remark',//域值
|
||||||
title: 'remark',//标题
|
title: 'remark',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Mode',//域值
|
field: 'Mode',//域值
|
||||||
title: 'mode',//标题
|
title: 'mode',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Port',//域值
|
field: 'Port',//域值
|
||||||
title: 'port',//标题
|
title: 'port',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Target',//域值
|
field: 'Target',//域值
|
||||||
title: 'target',//标题
|
title: 'target',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
formatter: function (value, row, index) {
|
||||||
|
return row.Target.TargetStr
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Password',//域值
|
field: 'Password',//域值
|
||||||
title: 'secret',//标题
|
title: 'secret',//标题
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'Status',//域值
|
field: 'Status',//域值
|
||||||
title: 'setting',//内容
|
title: 'setting',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (value) {
|
if (value) {
|
||||||
return '<span class="badge badge-primary">open</span>'
|
return '<span class="badge badge-primary">open</span>'
|
||||||
@ -134,7 +131,7 @@
|
|||||||
field: 'RunStatus',//域值
|
field: 'RunStatus',//域值
|
||||||
title: 'run',//内容
|
title: 'run',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (value) {
|
if (value) {
|
||||||
return '<span class="badge badge-primary">open</span>'
|
return '<span class="badge badge-primary">open</span>'
|
||||||
@ -147,7 +144,7 @@
|
|||||||
field: '',//域值
|
field: '',//域值
|
||||||
title: 'client',//内容
|
title: 'client',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
if (row.Client.IsConnect) {
|
if (row.Client.IsConnect) {
|
||||||
return '<span class="badge badge-primary">online</span>'
|
return '<span class="badge badge-primary">online</span>'
|
||||||
@ -160,7 +157,7 @@
|
|||||||
field: 'option',//域值
|
field: 'option',//域值
|
||||||
title: 'option',//内容
|
title: 'option',//内容
|
||||||
visible: true,//false表示不显示
|
visible: true,//false表示不显示
|
||||||
sortable: true,//启用排序
|
|
||||||
formatter: function (value, row, index) {
|
formatter: function (value, row, index) {
|
||||||
btn_group = '<div class="btn-group">'
|
btn_group = '<div class="btn-group">'
|
||||||
btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user