public key bug and multiuser enhancement and server ip support and config file of client optimization

This commit is contained in:
刘河
2019-03-26 23:34:55 +08:00
parent 00a4a33c5f
commit 42a73fa392
22 changed files with 155 additions and 70 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/crypt"
"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"
"net/http"
"os"
@@ -59,6 +60,7 @@ func (s *Csv) StoreTasksToCsv() {
strconv.Itoa(int(task.Flow.ExportFlow)),
strconv.Itoa(int(task.Flow.InletFlow)),
task.Password,
task.ServerIp,
}
err := writer.Write(record)
if err != nil {
@@ -111,6 +113,11 @@ func (s *Csv) LoadTaskFromCsv() {
if post.Client, err = s.GetClient(common.GetIntNoErrByStr(item[5])); err != nil {
continue
}
if len(item) > 10 {
post.ServerIp = item[10]
} else {
post.ServerIp = "0.0.0.0"
}
s.Tasks.Store(post.Id, post)
if post.Id > int(s.TaskIncreaseId) {
s.TaskIncreaseId = int32(s.TaskIncreaseId)
@@ -440,7 +447,7 @@ func (s *Csv) UpdateClient(t *Client) error {
return nil
}
func (s *Csv) GetClientList(start, length int, search string) ([]*Client, int) {
func (s *Csv) GetClientList(start, length int, search string, clientId int) ([]*Client, int) {
list := make([]*Client, 0)
var cnt int
keys := common.GetMapKeys(s.Clients)
@@ -450,6 +457,9 @@ func (s *Csv) GetClientList(start, length int, search string) ([]*Client, int) {
if v.NoDisplay {
continue
}
if clientId != 0 && clientId != v.Id {
continue
}
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || strings.Contains(v.VerifyKey, search) || strings.Contains(v.Remark, search)) {
continue
}
@@ -464,6 +474,18 @@ func (s *Csv) GetClientList(start, length int, search string) ([]*Client, int) {
return list, cnt
}
func (s *Csv) IsPubClient(id int) bool {
client, err := s.GetClient(id)
if err == nil {
if client.VerifyKey == beego.AppConfig.String("public_vkey") {
return true
} else {
return false
}
}
return false
}
func (s *Csv) GetClient(id int) (c *Client, err error) {
if v, ok := s.Clients.Load(id); ok {
c = v.(*Client)

View File

@@ -111,8 +111,9 @@ func (s *Client) HasHost(h *Host) bool {
}
type Tunnel struct {
Id int //Id
Port int //服务端监听端口
Id int //Id
Port int //服务端监听端口
ServerIp string
Mode string //启动方式
Target string //目标
TargetArr []string //目标