mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 03:16:53 +00:00
Code optimization
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/hex"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AuthController struct {
|
||||
@@ -31,3 +32,10 @@ func (s *AuthController) GetAuthKey() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AuthController) GetTime() {
|
||||
m := make(map[string]interface{})
|
||||
m["time"] = time.Now().Unix()
|
||||
s.Data["json"] = m
|
||||
s.ServeJSON()
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ func (s *ClientController) List() {
|
||||
return
|
||||
}
|
||||
start, length := s.GetAjaxParams()
|
||||
list, cnt := server.GetClientList(start, length)
|
||||
list, cnt := server.GetClientList(start, length, s.GetString("search"))
|
||||
s.AjaxTable(list, cnt, cnt)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (s *ClientController) Add() {
|
||||
} else {
|
||||
t := &file.Client{
|
||||
VerifyKey: s.GetString("vkey"),
|
||||
Id: file.GetCsvDb().GetClientId(),
|
||||
Id: int(file.GetCsvDb().GetClientId()),
|
||||
Status: true,
|
||||
Remark: s.GetString("remark"),
|
||||
Cnf: &file.Config{
|
||||
@@ -41,8 +41,9 @@ func (s *ClientController) Add() {
|
||||
Compress: common.GetBoolByStr(s.GetString("compress")),
|
||||
Crypt: s.GetBoolNoErr("crypt"),
|
||||
},
|
||||
RateLimit: s.GetIntNoErr("rate_limit"),
|
||||
MaxConn: s.GetIntNoErr("max_conn"),
|
||||
ConfigConnAllow: s.GetBoolNoErr("config_conn_allow"),
|
||||
RateLimit: s.GetIntNoErr("rate_limit"),
|
||||
MaxConn: s.GetIntNoErr("max_conn"),
|
||||
Flow: &file.Flow{
|
||||
ExportFlow: 0,
|
||||
InletFlow: 0,
|
||||
@@ -102,6 +103,7 @@ func (s *ClientController) Edit() {
|
||||
c.Flow.FlowLimit = int64(s.GetIntNoErr("flow_limit"))
|
||||
c.RateLimit = s.GetIntNoErr("rate_limit")
|
||||
c.MaxConn = s.GetIntNoErr("max_conn")
|
||||
c.ConfigConnAllow = s.GetBoolNoErr("config_conn_allow")
|
||||
if c.Rate != nil {
|
||||
c.Rate.Stop()
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ func (s *IndexController) GetTunnel() {
|
||||
start, length := s.GetAjaxParams()
|
||||
taskType := s.GetString("type")
|
||||
clientId := s.GetIntNoErr("client_id")
|
||||
list, cnt := server.GetTunnel(start, length, taskType, clientId)
|
||||
list, cnt := server.GetTunnel(start, length, taskType, clientId, s.GetString("search"))
|
||||
s.AjaxTable(list, cnt, cnt)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (s *IndexController) Add() {
|
||||
Port: s.GetIntNoErr("port"),
|
||||
Mode: s.GetString("type"),
|
||||
Target: s.GetString("target"),
|
||||
Id: file.GetCsvDb().GetTaskId(),
|
||||
Id: int(file.GetCsvDb().GetTaskId()),
|
||||
Status: true,
|
||||
Remark: s.GetString("remark"),
|
||||
Password: s.GetString("password"),
|
||||
@@ -196,7 +196,7 @@ func (s *IndexController) HostList() {
|
||||
} else {
|
||||
start, length := s.GetAjaxParams()
|
||||
clientId := s.GetIntNoErr("client_id")
|
||||
list, cnt := file.GetCsvDb().GetHost(start, length, clientId)
|
||||
list, cnt := file.GetCsvDb().GetHost(start, length, clientId, s.GetString("search"))
|
||||
s.AjaxTable(list, cnt, cnt)
|
||||
}
|
||||
}
|
||||
@@ -231,7 +231,7 @@ func (s *IndexController) AddHost() {
|
||||
s.display("index/hadd")
|
||||
} else {
|
||||
h := &file.Host{
|
||||
Id: file.GetCsvDb().GetHostId(),
|
||||
Id: int(file.GetCsvDb().GetHostId()),
|
||||
Host: s.GetString("host"),
|
||||
Target: s.GetString("target"),
|
||||
HeaderChange: s.GetString("header"),
|
||||
@@ -275,7 +275,7 @@ func (s *IndexController) EditHost() {
|
||||
h.TargetArr = nil
|
||||
h.Location = s.GetString("location")
|
||||
h.Scheme = s.GetString("scheme")
|
||||
file.GetCsvDb().UpdateHost(h)
|
||||
file.GetCsvDb().StoreHostToCsv()
|
||||
var err error
|
||||
if h.Client, err = file.GetCsvDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
|
||||
s.AjaxErr("modified error")
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/server"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LoginController struct {
|
||||
@@ -15,6 +18,7 @@ func (self *LoginController) Verify() {
|
||||
if self.GetString("password") == beego.AppConfig.String("web_password") && self.GetString("username") == beego.AppConfig.String("web_username") {
|
||||
self.SetSession("auth", true)
|
||||
self.Data["json"] = map[string]interface{}{"status": 1, "msg": "login success"}
|
||||
server.Bridge.Register.Store(common.GetIpByAddr(self.Ctx.Request.RemoteAddr), time.Now().Add(time.Hour*time.Duration(2)))
|
||||
self.ServeJSON()
|
||||
} else {
|
||||
self.Data["json"] = map[string]interface{}{"status": 0, "msg": "username or password incorrect"}
|
||||
|
Reference in New Issue
Block a user