mirror of https://github.com/ehang-io/nps
Web api
parent
b3dd70062b
commit
f0c6eff23a
|
@ -14,3 +14,6 @@ hostPort=80
|
|||
|
||||
##客户端与服务端通信端口
|
||||
tcpport=8284
|
||||
|
||||
#web api免验证IP地址
|
||||
authip=127.0.0.1
|
||||
|
|
|
@ -19,8 +19,11 @@ func (s *BaseController) Prepare() {
|
|||
controllerName, actionName := s.GetControllerAndAction()
|
||||
s.controllerName = strings.ToLower(controllerName[0 : len(controllerName)-10])
|
||||
s.actionName = strings.ToLower(actionName)
|
||||
if s.GetSession("auth") != true {
|
||||
s.Redirect("/login/index", 302)
|
||||
arr := strings.Split(s.Ctx.Request.RemoteAddr, ":")
|
||||
if len(arr) > 0 && arr[0] != beego.AppConfig.String("authip") {
|
||||
if s.GetSession("auth") != true {
|
||||
s.Redirect("/login/index", 302)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ type ClientController struct {
|
|||
BaseController
|
||||
}
|
||||
|
||||
func (s *ClientController) Client() {
|
||||
func (s *ClientController) List() {
|
||||
if s.Ctx.Request.Method == "GET" {
|
||||
s.Data["menu"] = "client"
|
||||
s.SetInfo("客户端管理")
|
||||
|
@ -32,7 +32,7 @@ func (s *ClientController) Add() {
|
|||
VerifyKey: utils.GetRandomString(16),
|
||||
Id: server.CsvDb.GetClientId(),
|
||||
Status: true,
|
||||
Remark: s.GetString("Remark"),
|
||||
Remark: s.GetString("remark"),
|
||||
Cnf: &utils.Config{
|
||||
U: s.GetString("u"),
|
||||
P: s.GetString("p"),
|
||||
|
@ -55,12 +55,26 @@ func (s *ClientController) Add() {
|
|||
s.AjaxOk("添加成功")
|
||||
}
|
||||
}
|
||||
func (s *ClientController) GetClient() {
|
||||
if s.Ctx.Request.Method == "POST" {
|
||||
id := s.GetIntNoErr("id")
|
||||
data := make(map[string]interface{})
|
||||
if c, err := server.CsvDb.GetClient(id); err != nil {
|
||||
data["code"] = 0
|
||||
} else {
|
||||
data["code"] = 1
|
||||
data["data"] = c
|
||||
}
|
||||
s.Data["json"] = data
|
||||
s.ServeJSON()
|
||||
}
|
||||
}
|
||||
|
||||
//修改客户端
|
||||
func (s *ClientController) Edit() {
|
||||
id := s.GetIntNoErr("id")
|
||||
if s.Ctx.Request.Method == "GET" {
|
||||
s.Data["menu"] = "client"
|
||||
id := s.GetIntNoErr("id")
|
||||
if c, err := server.CsvDb.GetClient(id); err != nil {
|
||||
s.error()
|
||||
} else {
|
||||
|
@ -69,11 +83,10 @@ func (s *ClientController) Edit() {
|
|||
s.SetInfo("修改")
|
||||
s.display()
|
||||
} else {
|
||||
id := s.GetIntNoErr("Id")
|
||||
if c, err := server.CsvDb.GetClient(id); err != nil {
|
||||
s.error()
|
||||
} else {
|
||||
c.Remark = s.GetString("Remark")
|
||||
c.Remark = s.GetString("remark")
|
||||
c.Cnf.U = s.GetString("u")
|
||||
c.Cnf.P = s.GetString("p")
|
||||
c.Cnf.Compress = s.GetString("compress")
|
||||
|
|
|
@ -101,7 +101,18 @@ func (s *IndexController) Add() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IndexController) GetOneTunnel() {
|
||||
id := s.GetIntNoErr("id")
|
||||
data := make(map[string]interface{})
|
||||
if t, err := server.CsvDb.GetTask(id); err != nil {
|
||||
data["code"] = 0
|
||||
} else {
|
||||
data["code"] = 1
|
||||
data["data"] = t
|
||||
}
|
||||
s.Data["json"] = data
|
||||
s.ServeJSON()
|
||||
}
|
||||
func (s *IndexController) Edit() {
|
||||
id := s.GetIntNoErr("id")
|
||||
if s.Ctx.Request.Method == "GET" {
|
||||
|
@ -175,6 +186,20 @@ func (s *IndexController) HostList() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *IndexController) GetHost() {
|
||||
if s.Ctx.Request.Method == "POST" {
|
||||
data := make(map[string]interface{})
|
||||
if h, err := server.GetInfoByHost(s.GetString("host")); err != nil {
|
||||
data["code"] = 0
|
||||
} else {
|
||||
data["data"] = h
|
||||
data["code"] = 1
|
||||
}
|
||||
s.Data["json"] = data
|
||||
s.ServeJSON()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IndexController) DelHost() {
|
||||
host := s.GetString("host")
|
||||
if err := server.CsvDb.DelHost(host); err != nil {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<form>
|
||||
<div class="form-group" id="target">
|
||||
<label class="control-label">备注</label>
|
||||
<input class="form-control" type="text" name="Remark" placeholder="客户端备注">
|
||||
<input class="form-control" type="text" name="remark" placeholder="客户端备注">
|
||||
</div>
|
||||
<div class="form-group" id="flow_limit">
|
||||
<label class="control-label">流量限制(单位:M,为空不限制)</label>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<input type="hidden" name="Id" value="{{.c.Id}}">
|
||||
<div class="form-group" id="target">
|
||||
<label class="control-label">备注</label>
|
||||
<input class="form-control" value="{{.c.Remark}}" type="text" name="Remark" placeholder="客户端备注">
|
||||
<input class="form-control" value="{{.c.Remark}}" type="text" name="remark" placeholder="客户端备注">
|
||||
</div>
|
||||
<div class="form-group" id="flow_limit">
|
||||
<label class="control-label">流量限制(单位:M,为空不限制)</label>
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
autoWidth: false,
|
||||
ordering: false,
|
||||
ajax: {
|
||||
url: '/client/client',
|
||||
url: '/client/list',
|
||||
type: 'POST'
|
||||
},
|
||||
dom: '<"top"fl><"toolbar">rt<"bottom"ip><"clear">',
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<ul class="app-menu">
|
||||
<li><a class="app-menu__item {{if eq "index" .menu}}active{{end}}" href="/"><i
|
||||
class="app-menu__icon fa fa-dashboard"></i><span class="app-menu__label">dashboard</span></a></li>
|
||||
<li><a class="app-menu__item {{if eq "client" .menu}}active{{end}}" href="/client/client"><i
|
||||
<li><a class="app-menu__item {{if eq "client" .menu}}active{{end}}" href="/client/list"><i
|
||||
class="app-menu__icon fa fa-dot-circle-o"></i><span class="app-menu__label">客户端管理</span></a></li>
|
||||
<li><a class="app-menu__item {{if eq "host" .menu}}active{{end}}" href="/index/hostlist"><i
|
||||
class="app-menu__icon fa fa-lemon-o"></i><span class="app-menu__label">域名代理</span></a></li>
|
||||
|
|
Loading…
Reference in New Issue