Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
yisier committed May 31, 2023
2 parents 5202ff3 + c7db78d commit 00e4fc7
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 6 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,51 @@ jobs:
npc_sdk.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


build_docker:

runs-on: ubuntu-latest
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push nps
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.nps
platforms: linux/amd64,linux/arm,linux/arm64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/nps:latest
${{ secrets.DOCKERHUB_USERNAME }}/nps:${{ env.RELEASE_VERSION }}
- name: Build and push npc
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.npc
platforms: linux/amd64,linux/arm,linux/arm64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/npc:latest
${{ secrets.DOCKERHUB_USERNAME }}/npc:${{ env.RELEASE_VERSION }}
2 changes: 2 additions & 0 deletions conf/clients.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"a82kjhdyllqnlruk","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":551,"InletFlow":551,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.12","BlackIpList":[""]}
*#*
2 changes: 2 additions & 0 deletions conf/hosts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"Id":1,"Host":"testlocal.com","HeaderChange":"","HostChange":"","Location":"/","Remark":"","Scheme":"all","CertFilePath":"","KeyFilePath":"","NoStore":false,"IsClose":false,"Flow":{"ExportFlow":0,"InletFlow":0,"FlowLimit":0},"Client":{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"a82kjhdyllqnlruk","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":551,"InletFlow":551,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.12","BlackIpList":[""]},"Target":{"TargetStr":"127.0.0.1:8080","TargetArr":["127.0.0.1:8080"],"LocalProxy":false}}
*#*
2 changes: 1 addition & 1 deletion conf/nps.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ http_add_origin_header=false
disconnect_timeout=60

#管理面板开启验证码校验
open_captcha=true
open_captcha=false
24 changes: 24 additions & 0 deletions lib/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewJsonDb(runPath string) *JsonDb {
TaskFilePath: filepath.Join(runPath, "conf", "tasks.json"),
HostFilePath: filepath.Join(runPath, "conf", "hosts.json"),
ClientFilePath: filepath.Join(runPath, "conf", "clients.json"),
GlobalFilePath: filepath.Join(runPath, "conf", "global.json"),
}
}

Expand All @@ -28,13 +29,15 @@ type JsonDb struct {
Hosts sync.Map
HostsTmp sync.Map
Clients sync.Map
Global sync.Map
RunPath string
ClientIncreaseId int32 //client increased id
TaskIncreaseId int32 //task increased id
HostIncreaseId int32 //host increased id
TaskFilePath string //task file path
HostFilePath string //host file path
ClientFilePath string //client file path
GlobalFilePath string //global file path
}

func (s *JsonDb) LoadTaskFromJsonFile() {
Expand Down Expand Up @@ -91,6 +94,16 @@ func (s *JsonDb) LoadHostFromJsonFile() {
})
}

func (s *JsonDb) LoadGlobalFromJsonFile() {
loadSyncMapFromFile(s.GlobalFilePath, func(v string) {
post := new(Glob)
if json.Unmarshal([]byte(v), &post) != nil {
return
}
s.Global.Store("value", post)
})
}

func (s *JsonDb) GetClient(id int) (c *Client, err error) {
if v, ok := s.Clients.Load(id); ok {
c = v.(*Client)
Expand Down Expand Up @@ -124,6 +137,14 @@ func (s *JsonDb) StoreClientsToJsonFile() {
clientLock.Unlock()
}

var globalLock sync.Mutex

func (s *JsonDb) StoreGlobalToJsonFile() {
globalLock.Lock()
storeSyncMapToFile(s.Global, s.GlobalFilePath)
globalLock.Unlock()
}

func (s *JsonDb) GetClientId() int32 {
return atomic.AddInt32(&s.ClientIncreaseId, 1)
}
Expand Down Expand Up @@ -174,6 +195,9 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
return true
}
b, err = json.Marshal(obj)
case *Glob:
obj := value.(*Glob)
b, err = json.Marshal(obj)
default:
return true
}
Expand Down
5 changes: 5 additions & 0 deletions lib/file/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,8 @@ func (s *Target) GetRandomTarget() (string, error) {
s.nowIndex++
return s.TargetArr[s.nowIndex], nil
}

type Glob struct {
BlackIpList []string
sync.RWMutex
}
10 changes: 5 additions & 5 deletions server/proxy/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {

s.task.Client.Flow.Add(int64(len(data)), int64(len(data)))
for {
clientConn.SetReadDeadline(time.Now().Add(time.Minute * 10))
clientConn.SetReadDeadline(time.Now().Add(time.Duration(60) * time.Second))
if n, err := target.Read(buf); err != nil {
s.addrMap.Delete(addr.String())
logs.Warn(err)
Expand All @@ -107,10 +107,10 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
}
s.task.Client.Flow.Add(int64(n), int64(n))
}
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
return
}
//if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
// logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
// return
//}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func flowSession(m time.Duration) {
file.GetDb().JsonDb.StoreHostToJsonFile()
file.GetDb().JsonDb.StoreTasksToJsonFile()
file.GetDb().JsonDb.StoreClientsToJsonFile()
file.GetDb().JsonDb.StoreGlobalToJsonFile()
}
}
}
8 changes: 8 additions & 0 deletions web/static/page/languages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@
<lang id="word-">
</lang>


<lang id="word-globalparam">
<zh-CN>全局参数</zh-CN>
<en-US>global Param</en-US>
</lang>

<lang id="info-autogenerated">
<zh-CN>唯一值,不填将自动生成</zh-CN>
<en-US>Unique, non-filling will be generated automatically</en-US>
Expand Down Expand Up @@ -1005,5 +1011,7 @@
</array>
</series>
</lang>


</charts>
</content>
51 changes: 51 additions & 0 deletions web/views/index/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,57 @@ <h1 class="no-margins">{{.data.tcpCount}}</h1>
</div>
</div>




<!--全局参数-->
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5 langtag="word-globalparam"></h5>
</div>
<div class="ibox-content">

<form class="form-horizontal">
<div class="form-group" id="black_ip_list">
<label class="control-label font-bold" langtag="word-blackiplist"></label>
<div class="col-sm-4">
<textarea class="form-control" rows="10" type="text" name="blackiplist" placeholder="" langtag="info-suchasblackiplist">{{.BlackIpList}}</textarea>
<span class="help-block m-b-none" langtag="info-descblackiplist"></span>
</div>
</div>

<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" type="button" onclick="submitform('add', '{{.web_base_url}}/index/add', $('form').serializeArray())">
<i class="fa fa-fw fa-lg fa-check-circle"></i> <span langtag="word-add"></span>
</button>
</div>
</div>
</form>

</div>
</div>
</div>
</div>

















<div class="row">
<div class="col-lg-6">
<div class="ibox float-e-margins">
Expand Down

0 comments on commit 00e4fc7

Please sign in to comment.