-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.go
57 lines (52 loc) · 1.63 KB
/
dashboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package handler
import (
"fmt"
"github.com/webx-top/db"
"github.com/webx-top/echo"
"github.com/webx-top/echo/code"
"github.com/nging-plugins/frpmanager/application/dbschema"
)
func ServerDashboard(ctx echo.Context) error {
id := ctx.Paramx(`id`).Uint()
m := dbschema.NewNgingFrpServer(ctx)
err := m.Get(nil, db.And(
db.Cond{`id`: id},
db.Cond{`disabled`: `N`},
))
if err != nil {
if err != db.ErrNoMoreRows {
return err
}
return ctx.NewError(code.DataNotFound, `没有找到启用的配置信息`)
}
if m.DashboardPort > 0 {
dashboardHost := m.DashboardAddr
if m.DashboardAddr == `0.0.0.0` || len(m.DashboardAddr) == 0 {
dashboardHost = ctx.Domain()
}
return ctx.Redirect(fmt.Sprintf(`http://%s:%d/`, dashboardHost, m.DashboardPort))
}
return ctx.NewError(code.Unsupported, `配置信息中未启用管理面板访问功能。如要启用,请将面板端口设为一个大于0的数值`)
}
func ClientDashboard(ctx echo.Context) error {
id := ctx.Paramx(`id`).Uint()
m := dbschema.NewNgingFrpClient(ctx)
err := m.Get(nil, db.And(
db.Cond{`id`: id},
db.Cond{`disabled`: `N`},
))
if err != nil {
if err != db.ErrNoMoreRows {
return err
}
return ctx.NewError(code.DataNotFound, `没有找到启用的配置信息`)
}
if m.AdminPort > 0 {
dashboardHost := m.AdminAddr
if m.AdminAddr == `0.0.0.0` || len(m.AdminAddr) == 0 {
dashboardHost = ctx.Domain()
}
return ctx.Redirect(fmt.Sprintf(`http://%s:%d/`, dashboardHost, m.AdminPort))
}
return ctx.NewError(code.Unsupported, `配置信息中未启用管理面板访问功能。如要启用,请将面板端口设为一个大于0的数值`)
}