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