Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d4c80eedb | ||
|
|
af4bd950b7 | ||
|
|
f85f9b0920 | ||
|
|
89ea96c28e | ||
|
|
6f2e3f5f13 | ||
|
|
ee91e8312f | ||
|
|
004a29846e | ||
|
|
01eb22a0fe | ||
|
|
bb2d2c5c86 | ||
|
|
e0c36e3c45 | ||
|
|
9fa9f74b90 | ||
|
|
7308748957 | ||
|
|
748105eae1 | ||
|
|
33f45dfc92 | ||
|
|
dda1e3054a | ||
|
|
a8030fa045 | ||
|
|
9de66f080d | ||
|
|
7a57180ecd | ||
|
|
48e1e0b631 | ||
|
|
d5fe38ba8d | ||
|
|
cb8035452b | ||
|
|
c2cab60940 | ||
|
|
58e7e1b283 | ||
|
|
5d108b1b6f | ||
|
|
8fbbbd65c4 | ||
|
|
7e0a96857c | ||
|
|
139b0e037e | ||
|
|
7cbfa2458b | ||
|
|
abc5162bca | ||
|
|
d3cf71dad8 | ||
|
|
0909164a06 | ||
|
|
6df50d97e9 | ||
|
|
98f8fb3bec | ||
|
|
0f5f175f08 | ||
|
|
16a2a6cb35 | ||
|
|
da38fcaa0c | ||
|
|
b6fd9aeb14 | ||
|
|
201c3e2f97 | ||
|
|
d834c2517a | ||
|
|
dc98081a92 | ||
|
|
30e9753c80 | ||
|
|
70cd06dc85 | ||
|
|
194a919a73 | ||
|
|
b57b242232 | ||
|
|
cc76172a46 | ||
|
|
5858f98ec6 | ||
|
|
941e000142 | ||
|
|
7dd58fd9dc | ||
|
|
2b560a225e | ||
|
|
c768f22059 | ||
|
|
f738ba9152 | ||
|
|
95c27119ac | ||
|
|
2b2b516788 | ||
|
|
0bb63b5bb7 | ||
|
|
48012072d7 | ||
|
|
0053949bc0 | ||
|
|
88e7246366 | ||
|
|
fbedf3b605 | ||
|
|
d5659e627d | ||
|
|
709d4dc805 | ||
|
|
37f052e9a5 | ||
|
|
58c765e97f | ||
|
|
da332c2756 | ||
|
|
e9d329bf8b | ||
|
|
775b46cf8f | ||
|
|
c99eb54811 | ||
|
|
7917c68b6f | ||
|
|
75ce1490cc | ||
|
|
6f1cd668b6 | ||
|
|
5b7cb59997 | ||
|
|
67242ec80e | ||
|
|
2af5e059eb | ||
|
|
1d992b0e97 | ||
|
|
0c650987d6 | ||
|
|
e8af3960f8 | ||
|
|
1d95087abb | ||
|
|
c350fceef3 | ||
|
|
e6970abcb8 | ||
|
|
9cf5f56e59 | ||
|
|
c2ebf81e6c | ||
|
|
19a2af8bfa | ||
|
|
df5c1262d2 | ||
|
|
26340110c1 | ||
|
|
452f03bb78 | ||
|
|
609794b2d8 | ||
|
|
554d0daf6d | ||
|
|
e4015282a5 | ||
|
|
a7453a4baa | ||
|
|
913a98b4de | ||
|
|
89f391ca22 | ||
|
|
e585149a7e | ||
|
|
f9f7cd723a | ||
|
|
4a813f08cd | ||
|
|
e75757f2bc | ||
|
|
91010325eb | ||
|
|
441c0bd628 | ||
|
|
a91b97ff2b | ||
|
|
fb775a0ee9 | ||
|
|
8ed02c8103 | ||
|
|
42a306ff22 | ||
|
|
a637783249 | ||
|
|
7ffff890a8 | ||
|
|
dbfbdddb3a | ||
|
|
f85b3a40ea | ||
|
|
27421bbd46 | ||
|
|
129d2ccef0 | ||
|
|
a553bad1ef | ||
|
|
ae7020437b | ||
|
|
74e6c7a87c | ||
|
|
658c5ae6dd | ||
|
|
7a24a69223 | ||
|
|
de90acaae4 | ||
|
|
51080f2669 | ||
|
|
fa5d97b74c | ||
|
|
42ba081cd1 | ||
|
|
404d733ba1 | ||
|
|
2f3398e251 | ||
|
|
5c09e272f3 | ||
|
|
d045f0526f | ||
|
|
0766ec9d5a | ||
|
|
4511b48382 | ||
|
|
151e58fbb9 | ||
|
|
c833ac2e96 | ||
|
|
99983330a3 | ||
|
|
a14e81a28f | ||
|
|
fc714a15a3 | ||
|
|
8a8f9d2912 | ||
|
|
58a0521605 | ||
|
|
e129b52f1c | ||
|
|
5cefd900a4 | ||
|
|
857dc70b4d | ||
|
|
e3036025bc | ||
|
|
76035dc3c2 | ||
|
|
22c55d0b83 | ||
|
|
9780937a1f | ||
|
|
b4eb6e92e0 |
@@ -9,7 +9,8 @@
|
|||||||
* `高扩展性` - 可以自由扩展新的节点,支持亿级数据
|
* `高扩展性` - 可以自由扩展新的节点,支持亿级数据
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
[点这里查看文档](https://github.com/TeaOSLab/EdgeDocs)
|
* [新手指南](https://edge.teaos.cn/docs/QuickStart/Index.md)
|
||||||
|
* [文档](http://edge.teaos.cn/docs)
|
||||||
|
|
||||||
## 架构
|
## 架构
|
||||||

|

|
||||||
@@ -23,4 +24,5 @@
|
|||||||
有什么问题和建议都可以加入QQ群 `659832182`。
|
有什么问题和建议都可以加入QQ群 `659832182`。
|
||||||
|
|
||||||
## 感谢
|
## 感谢
|
||||||
* 感谢[JetBrains公司](https://www.jetbrains.com/)提供免费的IDE开发Licence。
|
* 感谢[JetBrains公司](https://www.jetbrains.com/)提供免费的IDE开发Licence。
|
||||||
|
* 感谢[Gitee](https://gitee.com/)提供国内源代码托管平台
|
||||||
9
build/build-all.sh
Executable file
9
build/build-all.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
./build.sh linux amd64
|
||||||
|
./build.sh linux 386
|
||||||
|
./build.sh linux arm64
|
||||||
|
./build.sh linux mips64
|
||||||
|
./build.sh linux mips64le
|
||||||
|
./build.sh darwin amd64
|
||||||
|
./build.sh darwin arm64
|
||||||
1
build/licenses/README.md
Normal file
1
build/licenses/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
这个目录下我们列举了所有需要公开声明的第三方License,如果有遗漏,烦请告知 iwind.liu@gmail.com。再次感谢这些开源软件项目和贡献人员!
|
||||||
30
build/licenses/miekg-dns.md
Normal file
30
build/licenses/miekg-dns.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
As this is fork of the official Go code the same license applies.
|
||||||
|
Extensions of the original work are copyright (c) 2011 Miek Gieben
|
||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/apps"
|
"github.com/TeaOSLab/EdgeAdmin/internal/apps"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
|
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
|
||||||
@@ -13,7 +14,14 @@ func main() {
|
|||||||
app := apps.NewAppCmd().
|
app := apps.NewAppCmd().
|
||||||
Version(teaconst.Version).
|
Version(teaconst.Version).
|
||||||
Product(teaconst.ProductName).
|
Product(teaconst.ProductName).
|
||||||
Usage(teaconst.ProcessName + " [-v|start|stop|restart|service|daemon]")
|
Usage(teaconst.ProcessName+" [-v|start|stop|restart|service|daemon|reset]").
|
||||||
|
Option("-h", "show this help").
|
||||||
|
Option("-v", "show version").
|
||||||
|
Option("start", "start the service").
|
||||||
|
Option("stop", "stop the service").
|
||||||
|
Option("service", "register service into systemd").
|
||||||
|
Option("daemon", "start the service with daemon").
|
||||||
|
Option("reset", "reset configs")
|
||||||
|
|
||||||
app.On("daemon", func() {
|
app.On("daemon", func() {
|
||||||
nodes.NewAdminNode().Daemon()
|
nodes.NewAdminNode().Daemon()
|
||||||
@@ -26,6 +34,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
fmt.Println("done")
|
fmt.Println("done")
|
||||||
})
|
})
|
||||||
|
app.On("reset", func() {
|
||||||
|
err := configs.ResetAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[ERROR]reset failed: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("done")
|
||||||
|
})
|
||||||
app.Run(func() {
|
app.Run(func() {
|
||||||
adminNode := nodes.NewAdminNode()
|
adminNode := nodes.NewAdminNode()
|
||||||
adminNode.Run()
|
adminNode.Run()
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -9,13 +9,12 @@ require (
|
|||||||
github.com/cespare/xxhash v1.1.0
|
github.com/cespare/xxhash v1.1.0
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/go-yaml/yaml v2.1.0+incompatible
|
github.com/go-yaml/yaml v2.1.0+incompatible
|
||||||
github.com/iwind/TeaGo v0.0.0-20201206115018-cdd967bfb13d
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f
|
||||||
github.com/miekg/dns v1.1.35
|
github.com/miekg/dns v1.1.35
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/tealeg/xlsx/v3 v3.2.3
|
github.com/tealeg/xlsx/v3 v3.2.3
|
||||||
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119
|
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119
|
||||||
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c // indirect
|
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c
|
||||||
google.golang.org/grpc v1.32.0
|
google.golang.org/grpc v1.32.0
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
||||||
)
|
)
|
||||||
|
|||||||
12
go.sum
12
go.sum
@@ -9,6 +9,7 @@ github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiU
|
|||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
|
||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
@@ -53,9 +54,8 @@ github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
|||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
github.com/iwind/TeaGo v0.0.0-20200923021120-f5d76441fe9e/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f h1:r2O8PONj/KiuZjJHVHn7KlCePUIjNtgAmvLfgRafQ8o=
|
||||||
github.com/iwind/TeaGo v0.0.0-20201206115018-cdd967bfb13d h1:J4ohNUwOqCQkY62LFwaygfGtHJj+87pnzr+RJxEYSBo=
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/iwind/TeaGo v0.0.0-20201206115018-cdd967bfb13d/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
|
||||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
@@ -65,12 +65,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/miekg/dns v1.1.35 h1:oTfOaDH+mZkdcgdIjH6yBajRGtIwcwcaR+rt23ZSrJs=
|
github.com/miekg/dns v1.1.35 h1:oTfOaDH+mZkdcgdIjH6yBajRGtIwcwcaR+rt23ZSrJs=
|
||||||
github.com/miekg/dns v1.1.35/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
github.com/miekg/dns v1.1.35/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
|
||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package configloaders
|
package configloaders
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||||
@@ -14,6 +15,7 @@ const (
|
|||||||
AdminModuleCodeServer AdminModuleCode = "server" // 网站
|
AdminModuleCodeServer AdminModuleCode = "server" // 网站
|
||||||
AdminModuleCodeNode AdminModuleCode = "node" // 节点
|
AdminModuleCodeNode AdminModuleCode = "node" // 节点
|
||||||
AdminModuleCodeDNS AdminModuleCode = "dns" // DNS
|
AdminModuleCodeDNS AdminModuleCode = "dns" // DNS
|
||||||
|
AdminModuleCodeNS AdminModuleCode = "ns" // 域名服务
|
||||||
AdminModuleCodeAdmin AdminModuleCode = "admin" // 系统用户
|
AdminModuleCodeAdmin AdminModuleCode = "admin" // 系统用户
|
||||||
AdminModuleCodeUser AdminModuleCode = "user" // 平台用户
|
AdminModuleCodeUser AdminModuleCode = "user" // 平台用户
|
||||||
AdminModuleCodeFinance AdminModuleCode = "finance" // 财务
|
AdminModuleCodeFinance AdminModuleCode = "finance" // 财务
|
||||||
@@ -68,7 +70,7 @@ func NotifyAdminModuleMappingChange() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户是否存在
|
// CheckAdmin 检查用户是否存在
|
||||||
func CheckAdmin(adminId int64) bool {
|
func CheckAdmin(adminId int64) bool {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
defer locker.Unlock()
|
defer locker.Unlock()
|
||||||
@@ -82,7 +84,7 @@ func CheckAdmin(adminId int64) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查模块是否允许访问
|
// AllowModule 检查模块是否允许访问
|
||||||
func AllowModule(adminId int64, module string) bool {
|
func AllowModule(adminId int64, module string) bool {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
defer locker.Unlock()
|
defer locker.Unlock()
|
||||||
@@ -103,7 +105,7 @@ func AllowModule(adminId int64, module string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取管理员第一个可访问模块
|
// FindFirstAdminModule 获取管理员第一个可访问模块
|
||||||
func FindFirstAdminModule(adminId int64) (module AdminModuleCode, ok bool) {
|
func FindFirstAdminModule(adminId int64) (module AdminModuleCode, ok bool) {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
defer locker.Unlock()
|
defer locker.Unlock()
|
||||||
@@ -118,7 +120,7 @@ func FindFirstAdminModule(adminId int64) (module AdminModuleCode, ok bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找某个管理员名称
|
// FindAdminFullname 查找某个管理员名称
|
||||||
func FindAdminFullname(adminId int64) string {
|
func FindAdminFullname(adminId int64) string {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
defer locker.Unlock()
|
defer locker.Unlock()
|
||||||
@@ -130,9 +132,9 @@ func FindAdminFullname(adminId int64) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// 所有权限列表
|
// AllModuleMaps 所有权限列表
|
||||||
func AllModuleMaps() []maps.Map {
|
func AllModuleMaps() []maps.Map {
|
||||||
return []maps.Map{
|
m := []maps.Map{
|
||||||
{
|
{
|
||||||
"name": "看板",
|
"name": "看板",
|
||||||
"code": AdminModuleCodeDashboard,
|
"code": AdminModuleCodeDashboard,
|
||||||
@@ -153,6 +155,15 @@ func AllModuleMaps() []maps.Map {
|
|||||||
"code": AdminModuleCodeDNS,
|
"code": AdminModuleCodeDNS,
|
||||||
"url": "/dns",
|
"url": "/dns",
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
if teaconst.IsPlus {
|
||||||
|
m = append(m, maps.Map{
|
||||||
|
"name": "域名服务",
|
||||||
|
"code": AdminModuleCodeNS,
|
||||||
|
"url": "/ns",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
m = append(m, []maps.Map{
|
||||||
{
|
{
|
||||||
"name": "平台用户",
|
"name": "平台用户",
|
||||||
"code": AdminModuleCodeUser,
|
"code": AdminModuleCodeUser,
|
||||||
@@ -178,5 +189,6 @@ func AllModuleMaps() []maps.Map {
|
|||||||
"code": AdminModuleCodeSetting,
|
"code": AdminModuleCodeSetting,
|
||||||
"url": "/settings",
|
"url": "/settings",
|
||||||
},
|
},
|
||||||
}
|
}...)
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ func UpdateSecurityConfig(securityConfig *systemconfigs.SecurityConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = securityConfig.Init()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
sharedSecurityConfig = securityConfig
|
sharedSecurityConfig = securityConfig
|
||||||
|
|
||||||
// 通知更新
|
// 通知更新
|
||||||
@@ -86,6 +90,10 @@ func loadSecurityConfig() (*systemconfigs.SecurityConfig, error) {
|
|||||||
sharedSecurityConfig = defaultSecurityConfig()
|
sharedSecurityConfig = defaultSecurityConfig()
|
||||||
return sharedSecurityConfig, nil
|
return sharedSecurityConfig, nil
|
||||||
}
|
}
|
||||||
|
err = config.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
sharedSecurityConfig = config
|
sharedSecurityConfig = config
|
||||||
return sharedSecurityConfig, nil
|
return sharedSecurityConfig, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// API配置
|
// APIConfig API配置
|
||||||
type APIConfig struct {
|
type APIConfig struct {
|
||||||
RPC struct {
|
RPC struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
@@ -18,7 +18,7 @@ type APIConfig struct {
|
|||||||
Secret string `yaml:"secret"`
|
Secret string `yaml:"secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载API配置
|
// LoadAPIConfig 加载API配置
|
||||||
func LoadAPIConfig() (*APIConfig, error) {
|
func LoadAPIConfig() (*APIConfig, error) {
|
||||||
// 候选文件
|
// 候选文件
|
||||||
localFile := Tea.ConfigFile("api.yaml")
|
localFile := Tea.ConfigFile("api.yaml")
|
||||||
@@ -59,7 +59,50 @@ func LoadAPIConfig() (*APIConfig, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写入API配置
|
// ResetAPIConfig 重置配置
|
||||||
|
func ResetAPIConfig() error {
|
||||||
|
filename := "api.yaml"
|
||||||
|
|
||||||
|
{
|
||||||
|
configFile := Tea.ConfigFile(filename)
|
||||||
|
stat, err := os.Stat(configFile)
|
||||||
|
if err == nil && !stat.IsDir() {
|
||||||
|
err = os.Remove(configFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置 ~/.edge-admin/api.yaml
|
||||||
|
homeDir, homeErr := os.UserHomeDir()
|
||||||
|
if homeErr == nil {
|
||||||
|
configFile := homeDir + "/." + teaconst.ProcessName + "/" + filename
|
||||||
|
stat, err := os.Stat(configFile)
|
||||||
|
if err == nil && !stat.IsDir() {
|
||||||
|
err = os.Remove(configFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置 /etc/edge-admin/api.yaml
|
||||||
|
{
|
||||||
|
configFile := "/etc/" + teaconst.ProcessName + "/" + filename
|
||||||
|
stat, err := os.Stat(configFile)
|
||||||
|
if err == nil && !stat.IsDir() {
|
||||||
|
err = os.Remove(configFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteFile 写入API配置
|
||||||
func (this *APIConfig) WriteFile(path string) error {
|
func (this *APIConfig) WriteFile(path string) error {
|
||||||
data, err := yaml.Marshal(this)
|
data, err := yaml.Marshal(this)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -84,7 +127,7 @@ func (this *APIConfig) WriteFile(path string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写入 /etc/.edge-admin
|
// 写入 /etc/edge-admin
|
||||||
{
|
{
|
||||||
dir := "/etc/" + teaconst.ProcessName
|
dir := "/etc/" + teaconst.ProcessName
|
||||||
stat, err := os.Stat(dir)
|
stat, err := os.Stat(dir)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.10"
|
Version = "0.2.2"
|
||||||
|
|
||||||
ProductName = "Edge Admin"
|
ProductName = "Edge Admin"
|
||||||
ProcessName = "edge-admin"
|
ProcessName = "edge-admin"
|
||||||
|
|||||||
6
internal/const/plus.go
Normal file
6
internal/const/plus.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package teaconst
|
||||||
|
|
||||||
|
// IsPlus 是否为企业版
|
||||||
|
var IsPlus = false
|
||||||
@@ -87,7 +87,7 @@ func (this *AdminNode) Run() {
|
|||||||
Start()
|
Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实现守护进程
|
// Daemon 实现守护进程
|
||||||
func (this *AdminNode) Daemon() {
|
func (this *AdminNode) Daemon() {
|
||||||
path := os.TempDir() + "/edge-admin.sock"
|
path := os.TempDir() + "/edge-admin.sock"
|
||||||
isDebug := lists.ContainsString(os.Args, "debug")
|
isDebug := lists.ContainsString(os.Args, "debug")
|
||||||
@@ -132,7 +132,7 @@ func (this *AdminNode) Daemon() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安装系统服务
|
// InstallSystemService 安装系统服务
|
||||||
func (this *AdminNode) InstallSystemService() error {
|
func (this *AdminNode) InstallSystemService() error {
|
||||||
shortName := teaconst.SystemdServiceName
|
shortName := teaconst.SystemdServiceName
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ func (this *AdminNode) InstallSystemService() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加子PID
|
// AddSubPID 添加子PID
|
||||||
func (this *AdminNode) AddSubPID(pid int) {
|
func (this *AdminNode) AddSubPID(pid int) {
|
||||||
this.subPIDs = append(this.subPIDs, pid)
|
this.subPIDs = append(this.subPIDs, pid)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RPC客户端
|
// RPCClient RPC客户端
|
||||||
type RPCClient struct {
|
type RPCClient struct {
|
||||||
apiConfig *configs.APIConfig
|
apiConfig *configs.APIConfig
|
||||||
conns []*grpc.ClientConn
|
conns []*grpc.ClientConn
|
||||||
@@ -30,7 +30,7 @@ type RPCClient struct {
|
|||||||
locker sync.Mutex
|
locker sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造新的RPC客户端
|
// NewRPCClient 构造新的RPC客户端
|
||||||
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
||||||
if apiConfig == nil {
|
if apiConfig == nil {
|
||||||
return nil, errors.New("api config should not be nil")
|
return nil, errors.New("api config should not be nil")
|
||||||
@@ -91,6 +91,14 @@ func (this *RPCClient) NodeIPAddressRPC() pb.NodeIPAddressServiceClient {
|
|||||||
return pb.NewNodeIPAddressServiceClient(this.pickConn())
|
return pb.NewNodeIPAddressServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NodeValueRPC() pb.NodeValueServiceClient {
|
||||||
|
return pb.NewNodeValueServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NodeThresholdRPC() pb.NodeThresholdServiceClient {
|
||||||
|
return pb.NewNodeThresholdServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) ServerRPC() pb.ServerServiceClient {
|
func (this *RPCClient) ServerRPC() pb.ServerServiceClient {
|
||||||
return pb.NewServerServiceClient(this.pickConn())
|
return pb.NewServerServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -123,6 +131,10 @@ func (this *RPCClient) ServerHTTPFirewallDailyStatRPC() pb.ServerHTTPFirewallDai
|
|||||||
return pb.NewServerHTTPFirewallDailyStatServiceClient(this.pickConn())
|
return pb.NewServerHTTPFirewallDailyStatServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) ServerDailyStatRPC() pb.ServerDailyStatServiceClient {
|
||||||
|
return pb.NewServerDailyStatServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) ServerGroupRPC() pb.ServerGroupServiceClient {
|
func (this *RPCClient) ServerGroupRPC() pb.ServerGroupServiceClient {
|
||||||
return pb.NewServerGroupServiceClient(this.pickConn())
|
return pb.NewServerGroupServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -139,6 +151,10 @@ func (this *RPCClient) DBNodeRPC() pb.DBNodeServiceClient {
|
|||||||
return pb.NewDBNodeServiceClient(this.pickConn())
|
return pb.NewDBNodeServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MonitorNodeRPC() pb.MonitorNodeServiceClient {
|
||||||
|
return pb.NewMonitorNodeServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) DBRPC() pb.DBServiceClient {
|
func (this *RPCClient) DBRPC() pb.DBServiceClient {
|
||||||
return pb.NewDBServiceClient(this.pickConn())
|
return pb.NewDBServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -203,11 +219,15 @@ func (this *RPCClient) HTTPRewriteRuleRPC() pb.HTTPRewriteRuleServiceClient {
|
|||||||
return pb.NewHTTPRewriteRuleServiceClient(this.pickConn())
|
return pb.NewHTTPRewriteRuleServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 访问日志
|
// HTTPAccessLogRPC 访问日志
|
||||||
func (this *RPCClient) HTTPAccessLogRPC() pb.HTTPAccessLogServiceClient {
|
func (this *RPCClient) HTTPAccessLogRPC() pb.HTTPAccessLogServiceClient {
|
||||||
return pb.NewHTTPAccessLogServiceClient(this.pickConn())
|
return pb.NewHTTPAccessLogServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) HTTPFastcgiRPC() pb.HTTPFastcgiServiceClient {
|
||||||
|
return pb.NewHTTPFastcgiServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) SSLCertRPC() pb.SSLCertServiceClient {
|
func (this *RPCClient) SSLCertRPC() pb.SSLCertServiceClient {
|
||||||
return pb.NewSSLCertServiceClient(this.pickConn())
|
return pb.NewSSLCertServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -224,6 +244,34 @@ func (this *RPCClient) MessageRPC() pb.MessageServiceClient {
|
|||||||
return pb.NewMessageServiceClient(this.pickConn())
|
return pb.NewMessageServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageRecipientGroupRPC() pb.MessageRecipientGroupServiceClient {
|
||||||
|
return pb.NewMessageRecipientGroupServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageRecipientRPC() pb.MessageRecipientServiceClient {
|
||||||
|
return pb.NewMessageRecipientServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageMediaRPC() pb.MessageMediaServiceClient {
|
||||||
|
return pb.NewMessageMediaServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageMediaInstanceRPC() pb.MessageMediaInstanceServiceClient {
|
||||||
|
return pb.NewMessageMediaInstanceServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageTaskRPC() pb.MessageTaskServiceClient {
|
||||||
|
return pb.NewMessageTaskServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageTaskLogRPC() pb.MessageTaskLogServiceClient {
|
||||||
|
return pb.NewMessageTaskLogServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) MessageReceiverRPC() pb.MessageReceiverServiceClient {
|
||||||
|
return pb.NewMessageReceiverServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) IPLibraryRPC() pb.IPLibraryServiceClient {
|
func (this *RPCClient) IPLibraryRPC() pb.IPLibraryServiceClient {
|
||||||
return pb.NewIPLibraryServiceClient(this.pickConn())
|
return pb.NewIPLibraryServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -288,6 +336,10 @@ func (this *RPCClient) UserBillRPC() pb.UserBillServiceClient {
|
|||||||
return pb.NewUserBillServiceClient(this.pickConn())
|
return pb.NewUserBillServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccessKeyRPC() pb.UserAccessKeyServiceClient {
|
||||||
|
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) LoginRPC() pb.LoginServiceClient {
|
func (this *RPCClient) LoginRPC() pb.LoginServiceClient {
|
||||||
return pb.NewLoginServiceClient(this.pickConn())
|
return pb.NewLoginServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -296,7 +348,43 @@ func (this *RPCClient) NodeTaskRPC() pb.NodeTaskServiceClient {
|
|||||||
return pb.NewNodeTaskServiceClient(this.pickConn())
|
return pb.NewNodeTaskServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造Admin上下文
|
func (this *RPCClient) AuthorityKeyRPC() pb.AuthorityKeyServiceClient {
|
||||||
|
return pb.NewAuthorityKeyServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) AuthorityNodeRPC() pb.AuthorityNodeServiceClient {
|
||||||
|
return pb.NewAuthorityNodeServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) LatestItemRPC() pb.LatestItemServiceClient {
|
||||||
|
return pb.NewLatestItemServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NSClusterRPC() pb.NSClusterServiceClient {
|
||||||
|
return pb.NewNSClusterServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NSNodeRPC() pb.NSNodeServiceClient {
|
||||||
|
return pb.NewNSNodeServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NSDomainRPC() pb.NSDomainServiceClient {
|
||||||
|
return pb.NewNSDomainServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NSRecordRPC() pb.NSRecordServiceClient {
|
||||||
|
return pb.NewNSRecordServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NSRouteRPC() pb.NSRouteServiceClient {
|
||||||
|
return pb.NewNSRouteServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) NSAccessLogRPC() pb.NSAccessLogServiceClient {
|
||||||
|
return pb.NewNSAccessLogServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context 构造Admin上下文
|
||||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
m := maps.Map{
|
m := maps.Map{
|
||||||
@@ -319,7 +407,7 @@ func (this *RPCClient) Context(adminId int64) context.Context {
|
|||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造API上下文
|
// APIContext 构造API上下文
|
||||||
func (this *RPCClient) APIContext(apiNodeId int64) context.Context {
|
func (this *RPCClient) APIContext(apiNodeId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
m := maps.Map{
|
m := maps.Map{
|
||||||
@@ -342,6 +430,12 @@ func (this *RPCClient) APIContext(apiNodeId int64) context.Context {
|
|||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateConfig 修改配置
|
||||||
|
func (this *RPCClient) UpdateConfig(config *configs.APIConfig) error {
|
||||||
|
this.apiConfig = config
|
||||||
|
return this.init()
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
func (this *RPCClient) init() error {
|
func (this *RPCClient) init() error {
|
||||||
// 重新连接
|
// 重新连接
|
||||||
@@ -369,6 +463,8 @@ func (this *RPCClient) init() error {
|
|||||||
if len(conns) == 0 {
|
if len(conns) == 0 {
|
||||||
return errors.New("[RPC]no available endpoints")
|
return errors.New("[RPC]no available endpoints")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 这里不需要加锁,因为会和pickConn冲突
|
||||||
this.conns = conns
|
this.conns = conns
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestRPC_Dial_HTTP(t *testing.T) {
|
|||||||
RPC: struct {
|
RPC: struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
}{
|
}{
|
||||||
Endpoints: []string{"127.0.0.1:8003"},
|
Endpoints: []string{"http://127.0.0.1:8004"},
|
||||||
},
|
},
|
||||||
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
||||||
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
||||||
@@ -58,7 +58,7 @@ func TestRPC_Dial_HTTP_2(t *testing.T) {
|
|||||||
RPC: struct {
|
RPC: struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
}{
|
}{
|
||||||
Endpoints: []string{"http://127.0.0.1:8003"},
|
Endpoints: []string{"https://127.0.0.1:8003"},
|
||||||
},
|
},
|
||||||
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
||||||
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
var isConfigured bool
|
var isConfigured bool
|
||||||
|
|
||||||
// 判断系统是否已经配置过
|
// IsConfigured 判断系统是否已经配置过
|
||||||
func IsConfigured() bool {
|
func IsConfigured() bool {
|
||||||
if isConfigured {
|
if isConfigured {
|
||||||
return true
|
return true
|
||||||
|
|||||||
74
internal/tasks/task_authority.go
Normal file
74
internal/tasks/task_authority.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
events.On(events.EventStart, func() {
|
||||||
|
task := NewAuthorityTask()
|
||||||
|
go task.Start()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthorityTask struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthorityTask() *AuthorityTask {
|
||||||
|
return &AuthorityTask{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *AuthorityTask) Start() {
|
||||||
|
ticker := time.NewTicker(10 * time.Minute)
|
||||||
|
if Tea.IsTesting() {
|
||||||
|
// 快速测试
|
||||||
|
ticker = time.NewTicker(1 * time.Minute)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化的时候先获取一次
|
||||||
|
timeout := time.NewTimer(3 * time.Second)
|
||||||
|
<-timeout.C
|
||||||
|
err := this.Loop()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[TASK][AuthorityTask]" + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定时获取
|
||||||
|
for range ticker.C {
|
||||||
|
err := this.Loop()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[TASK][AuthorityTask]" + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *AuthorityTask) Loop() error {
|
||||||
|
// 如果还没有安装直接返回
|
||||||
|
if !setup.IsConfigured() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp, err := rpcClient.AuthorityKeyRPC().ReadAuthorityKey(rpcClient.Context(0), &pb.ReadAuthorityKeyRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.AuthorityKey != nil {
|
||||||
|
teaconst.IsPlus = true
|
||||||
|
} else {
|
||||||
|
teaconst.IsPlus = false
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
98
internal/tasks/task_sync_api_nodes.go
Normal file
98
internal/tasks/task_sync_api_nodes.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
events.On(events.EventStart, func() {
|
||||||
|
task := NewSyncAPINodesTask()
|
||||||
|
go task.Start()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// API节点同步任务
|
||||||
|
type SyncAPINodesTask struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSyncAPINodesTask() *SyncAPINodesTask {
|
||||||
|
return &SyncAPINodesTask{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SyncAPINodesTask) Start() {
|
||||||
|
ticker := time.NewTicker(5 * time.Minute)
|
||||||
|
if Tea.IsTesting() {
|
||||||
|
// 快速测试
|
||||||
|
ticker = time.NewTicker(1 * time.Minute)
|
||||||
|
}
|
||||||
|
for range ticker.C {
|
||||||
|
err := this.Loop()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[TASK][SYNC_API_NODES]" + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SyncAPINodesTask) Loop() error {
|
||||||
|
// 如果还没有安装直接返回
|
||||||
|
if !setup.IsConfigured() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有可用的节点
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp, err := rpcClient.APINodeRPC().FindAllEnabledAPINodes(rpcClient.Context(0), &pb.FindAllEnabledAPINodesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
newEndpoints := []string{}
|
||||||
|
for _, node := range resp.Nodes {
|
||||||
|
if !node.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newEndpoints = append(newEndpoints, node.AccessAddrs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 和现有的对比
|
||||||
|
config, err := configs.LoadAPIConfig()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if this.isSame(newEndpoints, config.RPC.Endpoints) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改RPC对象配置
|
||||||
|
config.RPC.Endpoints = newEndpoints
|
||||||
|
err = rpcClient.UpdateConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存到文件
|
||||||
|
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SyncAPINodesTask) isSame(endpoints1 []string, endpoints2 []string) bool {
|
||||||
|
sort.Strings(endpoints1)
|
||||||
|
sort.Strings(endpoints2)
|
||||||
|
return strings.Join(endpoints1, "&") == strings.Join(endpoints2, "&")
|
||||||
|
}
|
||||||
15
internal/tasks/task_sync_api_nodes_test.go
Normal file
15
internal/tasks/task_sync_api_nodes_test.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSyncAPINodesTask_Loop(t *testing.T) {
|
||||||
|
task := NewSyncAPINodesTask()
|
||||||
|
err := task.Loop()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自动同步集群任务
|
// SyncClusterTask 自动同步集群任务
|
||||||
type SyncClusterTask struct {
|
type SyncClusterTask struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64) (resu
|
|||||||
this.locker.Lock()
|
this.locker.Lock()
|
||||||
item, ok := this.m[key]
|
item, ok := this.m[key]
|
||||||
if ok {
|
if ok {
|
||||||
result := types.Int64(item.Value) + delta
|
result = types.Int64(item.Value) + delta
|
||||||
item.Value = result
|
item.Value = result
|
||||||
item.expiredAt = expiredAt
|
item.expiredAt = expiredAt
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ func FormatBytes(bytes int64) string {
|
|||||||
return fmt.Sprintf("%.2fMB", float64(bytes)/1024/1024)
|
return fmt.Sprintf("%.2fMB", float64(bytes)/1024/1024)
|
||||||
} else if bytes < 1024*1024*1024*1024 {
|
} else if bytes < 1024*1024*1024*1024 {
|
||||||
return fmt.Sprintf("%.2fGB", float64(bytes)/1024/1024/1024)
|
return fmt.Sprintf("%.2fGB", float64(bytes)/1024/1024/1024)
|
||||||
|
} else if bytes < 1024*1024*1024*1024*1024 {
|
||||||
|
return fmt.Sprintf("%.2fTB", float64(bytes)/1024/1024/1024/1024)
|
||||||
|
} else if bytes < 1024*1024*1024*1024*1024*1024 {
|
||||||
|
return fmt.Sprintf("%.2fPB", float64(bytes)/1024/1024/1024/1024/1024)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("%.2fPB", float64(bytes)/1024/1024/1024/1024)
|
return fmt.Sprintf("%.2fEB", float64(bytes)/1024/1024/1024/1024/1024/1024)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +39,12 @@ func FormatBits(bits int64) string {
|
|||||||
} else if bits < 1000*1000*1000 {
|
} else if bits < 1000*1000*1000 {
|
||||||
return fmt.Sprintf("%.2fMB", float64(bits)/1000/1000)
|
return fmt.Sprintf("%.2fMB", float64(bits)/1000/1000)
|
||||||
} else if bits < 1000*1000*1000*1000 {
|
} else if bits < 1000*1000*1000*1000 {
|
||||||
return fmt.Sprintf("%.2fGB", float64(bits)/1000/10001000)
|
return fmt.Sprintf("%.2fGB", float64(bits)/1000/1000/1000)
|
||||||
|
} else if bits < 1000*1000*1000*1000*1000 {
|
||||||
|
return fmt.Sprintf("%.2fTB", float64(bits)/1000/1000/1000/1000)
|
||||||
|
} else if bits < 1000*1000*1000*1000*1000*1000 {
|
||||||
|
return fmt.Sprintf("%.2fPB", float64(bits)/1000/1000/1000/1000/1000)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("%.2fPB", float64(bits)/1000/1000/1000/1000)
|
return fmt.Sprintf("%.2fEB", float64(bits)/1000/1000/1000/1000/1000/1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type ParentAction struct {
|
|||||||
rpcClient *rpc.RPCClient
|
rpcClient *rpc.RPCClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// 可以调用自身的一个简便方法
|
// Parent 可以调用自身的一个简便方法
|
||||||
func (this *ParentAction) Parent() *ParentAction {
|
func (this *ParentAction) Parent() *ParentAction {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ func (this *ParentAction) CreateLogInfo(description string, args ...interface{})
|
|||||||
this.CreateLog(oplogs.LevelInfo, description, args...)
|
this.CreateLog(oplogs.LevelInfo, description, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取RPC
|
// RPC 获取RPC
|
||||||
func (this *ParentAction) RPC() *rpc.RPCClient {
|
func (this *ParentAction) RPC() *rpc.RPCClient {
|
||||||
if this.rpcClient != nil {
|
if this.rpcClient != nil {
|
||||||
return this.rpcClient
|
return this.rpcClient
|
||||||
@@ -114,7 +114,7 @@ func (this *ParentAction) RPC() *rpc.RPCClient {
|
|||||||
return rpcClient
|
return rpcClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取Context
|
// AdminContext 获取Context
|
||||||
func (this *ParentAction) AdminContext() context.Context {
|
func (this *ParentAction) AdminContext() context.Context {
|
||||||
if this.rpcClient == nil {
|
if this.rpcClient == nil {
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package actionutils
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
rpcerrors "github.com/TeaOSLab/EdgeCommon/pkg/rpc/errors"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -12,28 +14,45 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 提示服务器错误信息
|
// Fail 提示服务器错误信息
|
||||||
func Fail(action actions.ActionWrapper, err error) {
|
func Fail(action actions.ActionWrapper, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Println("[" + reflect.TypeOf(action).String() + "]" + findStack(err.Error()))
|
logs.Println("[" + reflect.TypeOf(action).String() + "]" + findStack(err.Error()))
|
||||||
}
|
}
|
||||||
action.Object().Fail(teaconst.ErrServer)
|
action.Object().Fail(teaconst.ErrServer + "(" + err.Error() + ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提示页面错误信息
|
// FailPage 提示页面错误信息
|
||||||
func FailPage(action actions.ActionWrapper, err error) {
|
func FailPage(action actions.ActionWrapper, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Println("[" + reflect.TypeOf(action).String() + "]" + findStack(err.Error()))
|
logs.Println("[" + reflect.TypeOf(action).String() + "]" + findStack(err.Error()))
|
||||||
}
|
}
|
||||||
action.Object().WriteString(teaconst.ErrServer)
|
err = rpcerrors.HumanError(err)
|
||||||
|
action.Object().ResponseWriter.WriteHeader(http.StatusInternalServerError)
|
||||||
|
if len(action.Object().Request.Header.Get("X-Requested-With")) > 0 {
|
||||||
|
action.Object().WriteString(teaconst.ErrServer)
|
||||||
|
} else {
|
||||||
|
action.Object().WriteString(`<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body>
|
||||||
|
<div style="background: #eee; border: 1px #ccc solid; padding: 10px; font-size: 12px; line-height: 1.8">
|
||||||
|
` + teaconst.ErrServer + `
|
||||||
|
<div>可以通过查看 <strong><em>$安装目录/logs/run.log</em></strong> 日志文件查看具体的错误提示。</div>
|
||||||
|
<hr style="border-top: 1px #ccc solid"/>
|
||||||
|
<div style="color: red">Error: ` + err.Error() + `</pre>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断动作的文件路径是否相当
|
// MatchPath 判断动作的文件路径是否相当
|
||||||
func MatchPath(action *actions.ActionObject, path string) bool {
|
func MatchPath(action *actions.ActionObject, path string) bool {
|
||||||
return action.Request.URL.Path == path
|
return action.Request.URL.Path == path
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找父级Action
|
// FindParentAction 查找父级Action
|
||||||
func FindParentAction(actionPtr actions.ActionWrapper) *ParentAction {
|
func FindParentAction(actionPtr actions.ActionWrapper) *ParentAction {
|
||||||
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
||||||
if parentActionValue.IsValid() {
|
if parentActionValue.IsValid() {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func (this *AdminAction) RunGet(params struct {
|
|||||||
"username": admin.Username,
|
"username": admin.Username,
|
||||||
"isOn": admin.IsOn,
|
"isOn": admin.IsOn,
|
||||||
"isSuper": admin.IsSuper,
|
"isSuper": admin.IsSuper,
|
||||||
|
"canLogin": admin.CanLogin,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 权限
|
// 权限
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Pass2 string
|
Pass2 string
|
||||||
ModuleCodes []string
|
ModuleCodes []string
|
||||||
IsSuper bool
|
IsSuper bool
|
||||||
|
CanLogin bool
|
||||||
|
|
||||||
// OTP
|
// OTP
|
||||||
OtpOn bool
|
OtpOn bool
|
||||||
@@ -88,6 +89,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Fullname: params.Fullname,
|
Fullname: params.Fullname,
|
||||||
ModulesJSON: modulesJSON,
|
ModulesJSON: modulesJSON,
|
||||||
IsSuper: params.IsSuper,
|
IsSuper: params.IsSuper,
|
||||||
|
CanLogin: params.CanLogin,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
"fullname": admin.Fullname,
|
"fullname": admin.Fullname,
|
||||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", admin.CreatedAt),
|
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", admin.CreatedAt),
|
||||||
"otpLoginIsOn": admin.OtpLogin != nil && admin.OtpLogin.IsOn,
|
"otpLoginIsOn": admin.OtpLogin != nil && admin.OtpLogin.IsOn,
|
||||||
|
"canLogin": admin.CanLogin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["admins"] = adminMaps
|
this.Data["admins"] = adminMaps
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ func init() {
|
|||||||
Post("/delete", new(DeleteAction)).
|
Post("/delete", new(DeleteAction)).
|
||||||
Get("/admin", new(AdminAction)).
|
Get("/admin", new(AdminAction)).
|
||||||
Get("/otpQrcode", new(OtpQrcodeAction)).
|
Get("/otpQrcode", new(OtpQrcodeAction)).
|
||||||
|
Post("/options", new(OptionsAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
40
internal/web/actions/default/admins/options.go
Normal file
40
internal/web/actions/default/admins/options.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package admins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 系统用户选项
|
||||||
|
// 组件中需要用到的系统用户选项
|
||||||
|
type OptionsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *OptionsAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *OptionsAction) RunPost(params struct{}) {
|
||||||
|
// TODO 实现关键词搜索
|
||||||
|
adminsResp, err := this.RPC().AdminRPC().ListEnabledAdmins(this.AdminContext(), &pb.ListEnabledAdminsRequest{
|
||||||
|
Offset: 0,
|
||||||
|
Size: 1000,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
adminMaps := []maps.Map{}
|
||||||
|
for _, admin := range adminsResp.Admins {
|
||||||
|
adminMaps = append(adminMaps, maps.Map{
|
||||||
|
"id": admin.Id,
|
||||||
|
"name": admin.Fullname,
|
||||||
|
"username": admin.Username,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["admins"] = adminMaps
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreatePopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunPost(params struct {
|
||||||
|
AdminId int64
|
||||||
|
InstanceId int64
|
||||||
|
User string
|
||||||
|
|
||||||
|
TelegramToken string
|
||||||
|
|
||||||
|
GroupIds string
|
||||||
|
Description string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("adminId", params.AdminId).
|
||||||
|
Gt(0, "请选择系统用户").
|
||||||
|
Field("instanceId", params.InstanceId).
|
||||||
|
Gt(0, "请选择媒介")
|
||||||
|
|
||||||
|
groupIds := utils.SplitNumbers(params.GroupIds)
|
||||||
|
|
||||||
|
resp, err := this.RPC().MessageRecipientRPC().CreateMessageRecipient(this.AdminContext(), &pb.CreateMessageRecipientRequest{
|
||||||
|
AdminId: params.AdminId,
|
||||||
|
MessageMediaInstanceId: params.InstanceId,
|
||||||
|
User: params.User,
|
||||||
|
MessageRecipientGroupIds: groupIds,
|
||||||
|
Description: params.Description,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer this.CreateLogInfo("创建媒介接收人 %d", resp.MessageRecipientId)
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
24
internal/web/actions/default/admins/recipients/delete.go
Normal file
24
internal/web/actions/default/admins/recipients/delete.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DeleteAction) RunPost(params struct {
|
||||||
|
RecipientId int64
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("删除媒介接收人 %d", params.RecipientId)
|
||||||
|
|
||||||
|
_, err := this.RPC().MessageRecipientRPC().DeleteMessageRecipient(this.AdminContext(), &pb.DeleteMessageRecipientRequest{MessageRecipientId: params.RecipientId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package groups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreatePopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunPost(params struct {
|
||||||
|
Name string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("name", params.Name).
|
||||||
|
Require("请输入分组名称")
|
||||||
|
|
||||||
|
_, err := this.RPC().MessageRecipientGroupRPC().CreateMessageRecipientGroup(this.AdminContext(), &pb.CreateMessageRecipientGroupRequest{Name: params.Name})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package groups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DeleteAction) RunPost(params struct {
|
||||||
|
GroupId int64
|
||||||
|
}) {
|
||||||
|
_, err := this.RPC().MessageRecipientGroupRPC().DeleteMessageRecipientGroup(this.AdminContext(), &pb.DeleteMessageRecipientGroupRequest{MessageRecipientGroupId: params.GroupId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package groups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "", "group")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
|
groupsResp, err := this.RPC().MessageRecipientGroupRPC().FindAllEnabledMessageRecipientGroups(this.AdminContext(), &pb.FindAllEnabledMessageRecipientGroupsRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupMaps := []maps.Map{}
|
||||||
|
for _, group := range groupsResp.MessageRecipientGroups {
|
||||||
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
"isOn": group.IsOn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["groups"] = groupMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package groups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
|
"github.com/iwind/TeaGo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeAdmin)).
|
||||||
|
Data("teaMenu", "admins").
|
||||||
|
Data("teaSubMenu", "recipients").
|
||||||
|
Prefix("/admins/recipients/groups").
|
||||||
|
Get("", new(IndexAction)).
|
||||||
|
GetPost("/createPopup", new(CreatePopupAction)).
|
||||||
|
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||||
|
Post("/delete", new(DeleteAction)).
|
||||||
|
Get("/selectPopup", new(SelectPopupAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package groups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SelectPopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SelectPopupAction) RunGet(params struct {
|
||||||
|
GroupIds string
|
||||||
|
}) {
|
||||||
|
selectedGroupIds := utils.SplitNumbers(params.GroupIds)
|
||||||
|
|
||||||
|
groupsResp, err := this.RPC().MessageRecipientGroupRPC().FindAllEnabledMessageRecipientGroups(this.AdminContext(), &pb.FindAllEnabledMessageRecipientGroupsRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupMaps := []maps.Map{}
|
||||||
|
for _, group := range groupsResp.MessageRecipientGroups {
|
||||||
|
if lists.ContainsInt64(selectedGroupIds, group.Id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
"isOn": group.IsOn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["groups"] = groupMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package groups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdatePopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdatePopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdatePopupAction) RunGet(params struct {
|
||||||
|
GroupId int64
|
||||||
|
}) {
|
||||||
|
groupResp, err := this.RPC().MessageRecipientGroupRPC().FindEnabledMessageRecipientGroup(this.AdminContext(), &pb.FindEnabledMessageRecipientGroupRequest{MessageRecipientGroupId: params.GroupId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
group := groupResp.MessageRecipientGroup
|
||||||
|
if group == nil {
|
||||||
|
this.NotFound("messageRecipientGroup", params.GroupId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["group"] = maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
"isOn": group.IsOn,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdatePopupAction) RunPost(params struct {
|
||||||
|
GroupId int64
|
||||||
|
Name string
|
||||||
|
IsOn bool
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("name", params.Name).
|
||||||
|
Require("请输入分组名称")
|
||||||
|
|
||||||
|
_, err := this.RPC().MessageRecipientGroupRPC().UpdateMessageRecipientGroup(this.AdminContext(), &pb.UpdateMessageRecipientGroupRequest{
|
||||||
|
MessageRecipientGroupId: params.GroupId,
|
||||||
|
Name: params.Name,
|
||||||
|
IsOn: params.IsOn,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
70
internal/web/actions/default/admins/recipients/index.go
Normal file
70
internal/web/actions/default/admins/recipients/index.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "", "recipient")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
}) {
|
||||||
|
// TODO 增加系统用户、媒介类型等条件搜索
|
||||||
|
countResp, err := this.RPC().MessageRecipientRPC().CountAllEnabledMessageRecipients(this.AdminContext(), &pb.CountAllEnabledMessageRecipientsRequest{
|
||||||
|
AdminId: 0,
|
||||||
|
MediaType: "",
|
||||||
|
MessageRecipientGroupId: 0,
|
||||||
|
Keyword: "",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count := countResp.Count
|
||||||
|
page := this.NewPage(count)
|
||||||
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
|
recipientsResp, err := this.RPC().MessageRecipientRPC().ListEnabledMessageRecipients(this.AdminContext(), &pb.ListEnabledMessageRecipientsRequest{
|
||||||
|
AdminId: 0,
|
||||||
|
MediaType: "",
|
||||||
|
MessageRecipientGroupId: 0,
|
||||||
|
Keyword: "",
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
|
})
|
||||||
|
|
||||||
|
recipientMaps := []maps.Map{}
|
||||||
|
for _, recipient := range recipientsResp.MessageRecipients {
|
||||||
|
if recipient.Admin == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if recipient.MessageMediaInstance == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
recipientMaps = append(recipientMaps, maps.Map{
|
||||||
|
"id": recipient.Id,
|
||||||
|
"admin": maps.Map{
|
||||||
|
"id": recipient.Admin.Id,
|
||||||
|
"fullname": recipient.Admin.Fullname,
|
||||||
|
"username": recipient.Admin.Username,
|
||||||
|
},
|
||||||
|
"groups": recipient.MessageRecipientGroups,
|
||||||
|
"isOn": recipient.IsOn,
|
||||||
|
"instance": maps.Map{
|
||||||
|
"name": recipient.MessageMediaInstance.Name,
|
||||||
|
},
|
||||||
|
"user": recipient.User,
|
||||||
|
"description": recipient.Description,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["recipients"] = recipientMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
25
internal/web/actions/default/admins/recipients/init.go
Normal file
25
internal/web/actions/default/admins/recipients/init.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
|
"github.com/iwind/TeaGo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeAdmin)).
|
||||||
|
Data("teaMenu", "admins").
|
||||||
|
Data("teaSubMenu", "recipients").
|
||||||
|
Prefix("/admins/recipients").
|
||||||
|
Get("", new(IndexAction)).
|
||||||
|
GetPost("/createPopup", new(CreatePopupAction)).
|
||||||
|
GetPost("/update", new(UpdateAction)).
|
||||||
|
Post("/delete", new(DeleteAction)).
|
||||||
|
Post("/mediaOptions", new(MediaOptionsAction)).
|
||||||
|
Get("/recipient", new(RecipientAction)).
|
||||||
|
GetPost("/test", new(TestAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreatePopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunPost(params struct {
|
||||||
|
Name string
|
||||||
|
MediaType string
|
||||||
|
|
||||||
|
EmailSmtp string
|
||||||
|
EmailUsername string
|
||||||
|
EmailPassword string
|
||||||
|
EmailFrom string
|
||||||
|
|
||||||
|
WebHookURL string
|
||||||
|
WebHookMethod string
|
||||||
|
WebHookHeaderNames []string
|
||||||
|
WebHookHeaderValues []string
|
||||||
|
WebHookContentType string
|
||||||
|
WebHookParamNames []string
|
||||||
|
WebHookParamValues []string
|
||||||
|
WebHookBody string
|
||||||
|
|
||||||
|
ScriptType string
|
||||||
|
ScriptPath string
|
||||||
|
ScriptLang string
|
||||||
|
ScriptCode string
|
||||||
|
ScriptCwd string
|
||||||
|
ScriptEnvNames []string
|
||||||
|
ScriptEnvValues []string
|
||||||
|
|
||||||
|
DingTalkWebHookURL string
|
||||||
|
|
||||||
|
QyWeixinCorporateId string
|
||||||
|
QyWeixinAgentId string
|
||||||
|
QyWeixinAppSecret string
|
||||||
|
QyWeixinTextFormat string
|
||||||
|
|
||||||
|
QyWeixinRobotWebHookURL string
|
||||||
|
QyWeixinRobotTextFormat string
|
||||||
|
|
||||||
|
AliyunSmsSign string
|
||||||
|
AliyunSmsTemplateCode string
|
||||||
|
AliyunSmsTemplateVarNames []string
|
||||||
|
AliyunSmsTemplateVarValues []string
|
||||||
|
AliyunSmsAccessKeyId string
|
||||||
|
AliyunSmsAccessKeySecret string
|
||||||
|
|
||||||
|
TelegramToken string
|
||||||
|
|
||||||
|
Description string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("name", params.Name).
|
||||||
|
Require("请输入媒介名称").
|
||||||
|
Field("mediaType", params.MediaType).
|
||||||
|
Require("请选择媒介类型")
|
||||||
|
|
||||||
|
options := maps.Map{}
|
||||||
|
|
||||||
|
switch params.MediaType {
|
||||||
|
case "email":
|
||||||
|
params.Must.
|
||||||
|
Field("emailSmtp", params.EmailSmtp).
|
||||||
|
Require("请输入SMTP地址").
|
||||||
|
Field("emailUsername", params.EmailUsername).
|
||||||
|
Require("请输入邮箱账号").
|
||||||
|
Field("emailPassword", params.EmailPassword).
|
||||||
|
Require("请输入密码或授权码")
|
||||||
|
|
||||||
|
options["smtp"] = params.EmailSmtp
|
||||||
|
options["username"] = params.EmailUsername
|
||||||
|
options["password"] = params.EmailPassword
|
||||||
|
options["from"] = params.EmailFrom
|
||||||
|
case "webHook":
|
||||||
|
params.Must.
|
||||||
|
Field("webHookURL", params.WebHookURL).
|
||||||
|
Require("请输入URL地址").
|
||||||
|
Match("(?i)^(http|https)://", "URL地址必须以http或https开头").
|
||||||
|
Field("webHookMethod", params.WebHookMethod).
|
||||||
|
Require("请选择请求方法")
|
||||||
|
|
||||||
|
options["url"] = params.WebHookURL
|
||||||
|
options["method"] = params.WebHookMethod
|
||||||
|
options["contentType"] = params.WebHookContentType
|
||||||
|
|
||||||
|
headers := []maps.Map{}
|
||||||
|
if len(params.WebHookHeaderNames) > 0 {
|
||||||
|
for index, name := range params.WebHookHeaderNames {
|
||||||
|
if index < len(params.WebHookHeaderValues) {
|
||||||
|
headers = append(headers, maps.Map{
|
||||||
|
"name": name,
|
||||||
|
"value": params.WebHookHeaderValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["headers"] = headers
|
||||||
|
|
||||||
|
if params.WebHookContentType == "params" {
|
||||||
|
webHookParams := []maps.Map{}
|
||||||
|
for index, name := range params.WebHookParamNames {
|
||||||
|
if index < len(params.WebHookParamValues) {
|
||||||
|
webHookParams = append(webHookParams, maps.Map{
|
||||||
|
"name": name,
|
||||||
|
"value": params.WebHookParamValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["params"] = webHookParams
|
||||||
|
} else if params.WebHookContentType == "body" {
|
||||||
|
options["body"] = params.WebHookBody
|
||||||
|
}
|
||||||
|
case "script":
|
||||||
|
if params.ScriptType == "path" {
|
||||||
|
params.Must.
|
||||||
|
Field("scriptPath", params.ScriptPath).
|
||||||
|
Require("请输入脚本路径")
|
||||||
|
} else if params.ScriptType == "code" {
|
||||||
|
params.Must.
|
||||||
|
Field("scriptCode", params.ScriptCode).
|
||||||
|
Require("请输入脚本代码")
|
||||||
|
} else {
|
||||||
|
params.Must.
|
||||||
|
Field("scriptPath", params.ScriptPath).
|
||||||
|
Require("请输入脚本路径")
|
||||||
|
}
|
||||||
|
|
||||||
|
options["scriptType"] = params.ScriptType
|
||||||
|
options["path"] = params.ScriptPath
|
||||||
|
options["scriptLang"] = params.ScriptLang
|
||||||
|
options["script"] = params.ScriptCode
|
||||||
|
options["cwd"] = params.ScriptCwd
|
||||||
|
|
||||||
|
env := []maps.Map{}
|
||||||
|
for index, envName := range params.ScriptEnvNames {
|
||||||
|
if index < len(params.ScriptEnvValues) {
|
||||||
|
env = append(env, maps.Map{
|
||||||
|
"name": envName,
|
||||||
|
"value": params.ScriptEnvValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["env"] = env
|
||||||
|
case "dingTalk":
|
||||||
|
params.Must.
|
||||||
|
Field("dingTalkWebHookURL", params.DingTalkWebHookURL).
|
||||||
|
Require("请输入Hook地址").
|
||||||
|
Match("^https:", "Hook地址必须以https://开头")
|
||||||
|
|
||||||
|
options["webHookURL"] = params.DingTalkWebHookURL
|
||||||
|
case "qyWeixin":
|
||||||
|
params.Must.
|
||||||
|
Field("qyWeixinCorporateId", params.QyWeixinCorporateId).
|
||||||
|
Require("请输入企业ID").
|
||||||
|
Field("qyWeixinAgentId", params.QyWeixinAgentId).
|
||||||
|
Require("请输入应用AgentId").
|
||||||
|
Field("qyWeixinSecret", params.QyWeixinAppSecret).
|
||||||
|
Require("请输入应用Secret")
|
||||||
|
|
||||||
|
options["corporateId"] = params.QyWeixinCorporateId
|
||||||
|
options["agentId"] = params.QyWeixinAgentId
|
||||||
|
options["appSecret"] = params.QyWeixinAppSecret
|
||||||
|
options["textFormat"] = params.QyWeixinTextFormat
|
||||||
|
case "qyWeixinRobot":
|
||||||
|
params.Must.
|
||||||
|
Field("qyWeixinRobotWebHookURL", params.QyWeixinRobotWebHookURL).
|
||||||
|
Require("请输入WebHook地址").
|
||||||
|
Match("^https:", "WebHook地址必须以https://开头")
|
||||||
|
|
||||||
|
options["webHookURL"] = params.QyWeixinRobotWebHookURL
|
||||||
|
options["textFormat"] = params.QyWeixinRobotTextFormat
|
||||||
|
case "aliyunSms":
|
||||||
|
params.Must.
|
||||||
|
Field("aliyunSmsSign", params.AliyunSmsSign).
|
||||||
|
Require("请输入签名名称").
|
||||||
|
Field("aliyunSmsTemplateCode", params.AliyunSmsTemplateCode).
|
||||||
|
Require("请输入模板CODE").
|
||||||
|
Field("aliyunSmsAccessKeyId", params.AliyunSmsAccessKeyId).
|
||||||
|
Require("请输入AccessKey ID").
|
||||||
|
Field("aliyunSmsAccessKeySecret", params.AliyunSmsAccessKeySecret).
|
||||||
|
Require("请输入AccessKey Secret")
|
||||||
|
|
||||||
|
options["sign"] = params.AliyunSmsSign
|
||||||
|
options["templateCode"] = params.AliyunSmsTemplateCode
|
||||||
|
options["accessKeyId"] = params.AliyunSmsAccessKeyId
|
||||||
|
options["accessKeySecret"] = params.AliyunSmsAccessKeySecret
|
||||||
|
|
||||||
|
variables := []maps.Map{}
|
||||||
|
for index, name := range params.AliyunSmsTemplateVarNames {
|
||||||
|
if index < len(params.AliyunSmsTemplateVarValues) {
|
||||||
|
variables = append(variables, maps.Map{
|
||||||
|
"name": name,
|
||||||
|
"value": params.AliyunSmsTemplateVarValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["variables"] = variables
|
||||||
|
case "telegram":
|
||||||
|
params.Must.
|
||||||
|
Field("telegramToken", params.TelegramToken).
|
||||||
|
Require("请输入机器人Token")
|
||||||
|
options["token"] = params.TelegramToken
|
||||||
|
default:
|
||||||
|
this.Fail("错误的媒介类型")
|
||||||
|
}
|
||||||
|
|
||||||
|
optionsJSON, err := json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := this.RPC().MessageMediaInstanceRPC().CreateMessageMediaInstance(this.AdminContext(), &pb.CreateMessageMediaInstanceRequest{
|
||||||
|
Name: params.Name,
|
||||||
|
MediaType: params.MediaType,
|
||||||
|
ParamsJSON: optionsJSON,
|
||||||
|
Description: params.Description,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer this.CreateLogInfo("创建消息媒介 %d", resp.MessageMediaInstanceId)
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DeleteAction) RunPost(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("删除消息媒介 %d", params.InstanceId)
|
||||||
|
|
||||||
|
_, err := this.RPC().MessageMediaInstanceRPC().DeleteMessageMediaInstance(this.AdminContext(), &pb.DeleteMessageMediaInstanceRequest{MessageMediaInstanceId: params.InstanceId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "", "instance")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
}) {
|
||||||
|
// TODO 增加系统用户、媒介类型等条件搜索
|
||||||
|
countResp, err := this.RPC().MessageMediaInstanceRPC().CountAllEnabledMessageMediaInstances(this.AdminContext(), &pb.CountAllEnabledMessageMediaInstancesRequest{
|
||||||
|
MediaType: "",
|
||||||
|
Keyword: "",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count := countResp.Count
|
||||||
|
page := this.NewPage(count)
|
||||||
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
|
instancesResp, err := this.RPC().MessageMediaInstanceRPC().ListEnabledMessageMediaInstances(this.AdminContext(), &pb.ListEnabledMessageMediaInstancesRequest{
|
||||||
|
MediaType: "",
|
||||||
|
Keyword: "",
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
|
})
|
||||||
|
|
||||||
|
instanceMaps := []maps.Map{}
|
||||||
|
for _, instance := range instancesResp.MessageMediaInstances {
|
||||||
|
if instance.MessageMedia == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
instanceMaps = append(instanceMaps, maps.Map{
|
||||||
|
"id": instance.Id,
|
||||||
|
"name": instance.Name,
|
||||||
|
"isOn": instance.IsOn,
|
||||||
|
"media": maps.Map{
|
||||||
|
"name": instance.MessageMedia.Name,
|
||||||
|
},
|
||||||
|
"description": instance.Description,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["instances"] = instanceMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
|
"github.com/iwind/TeaGo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeAdmin)).
|
||||||
|
Data("teaMenu", "admins").
|
||||||
|
Data("teaSubMenu", "instances").
|
||||||
|
Prefix("/admins/recipients/instances").
|
||||||
|
Get("", new(IndexAction)).
|
||||||
|
GetPost("/createPopup", new(CreatePopupAction)).
|
||||||
|
GetPost("/update", new(UpdateAction)).
|
||||||
|
Post("/delete", new(DeleteAction)).
|
||||||
|
Get("/instance", new(InstanceAction)).
|
||||||
|
GetPost("/test", new(TestAction)).
|
||||||
|
Post("/options", new(OptionsAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InstanceAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstanceAction) Init() {
|
||||||
|
this.Nav("", "", "instance")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstanceAction) RunGet(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
}) {
|
||||||
|
instanceResp, err := this.RPC().MessageMediaInstanceRPC().FindEnabledMessageMediaInstance(this.AdminContext(), &pb.FindEnabledMessageMediaInstanceRequest{MessageMediaInstanceId: params.InstanceId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
instance := instanceResp.MessageMediaInstance
|
||||||
|
if instance == nil || instance.MessageMedia == nil {
|
||||||
|
this.NotFound("messageMediaInstance", params.InstanceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaParams := maps.Map{}
|
||||||
|
if len(instance.ParamsJSON) > 0 {
|
||||||
|
err = json.Unmarshal(instance.ParamsJSON, &mediaParams)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["instance"] = maps.Map{
|
||||||
|
"id": instance.Id,
|
||||||
|
"name": instance.Name,
|
||||||
|
"isOn": instance.IsOn,
|
||||||
|
"media": maps.Map{
|
||||||
|
"type": instance.MessageMedia.Type,
|
||||||
|
"name": instance.MessageMedia.Name,
|
||||||
|
},
|
||||||
|
"description": instance.Description,
|
||||||
|
"params": mediaParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 媒介类型选项
|
||||||
|
type OptionsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *OptionsAction) RunPost(params struct{}) {
|
||||||
|
resp, err := this.RPC().MessageMediaInstanceRPC().ListEnabledMessageMediaInstances(this.AdminContext(), &pb.ListEnabledMessageMediaInstancesRequest{
|
||||||
|
Offset: 0,
|
||||||
|
Size: 1000,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
instanceMaps := []maps.Map{}
|
||||||
|
for _, instance := range resp.MessageMediaInstances {
|
||||||
|
instanceMaps = append(instanceMaps, maps.Map{
|
||||||
|
"id": instance.Id,
|
||||||
|
"name": instance.Name,
|
||||||
|
"description": instance.Description,
|
||||||
|
"media": maps.Map{
|
||||||
|
"type": instance.MessageMedia.Type,
|
||||||
|
"name": instance.MessageMedia.Name,
|
||||||
|
"userDescription": instance.MessageMedia.UserDescription,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["instances"] = instanceMaps
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestAction) Init() {
|
||||||
|
this.Nav("", "", "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestAction) RunGet(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
}) {
|
||||||
|
instanceResp, err := this.RPC().MessageMediaInstanceRPC().FindEnabledMessageMediaInstance(this.AdminContext(), &pb.FindEnabledMessageMediaInstanceRequest{MessageMediaInstanceId: params.InstanceId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
instance := instanceResp.MessageMediaInstance
|
||||||
|
if instance == nil || instance.MessageMedia == nil {
|
||||||
|
this.NotFound("messageMediaInstance", params.InstanceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaParams := maps.Map{}
|
||||||
|
if len(instance.ParamsJSON) > 0 {
|
||||||
|
err = json.Unmarshal(instance.ParamsJSON, &mediaParams)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["instance"] = maps.Map{
|
||||||
|
"id": instance.Id,
|
||||||
|
"isOn": instance.IsOn,
|
||||||
|
"media": maps.Map{
|
||||||
|
"type": instance.MessageMedia.Type,
|
||||||
|
"name": instance.MessageMedia.Name,
|
||||||
|
"userDescription": instance.MessageMedia.UserDescription,
|
||||||
|
},
|
||||||
|
"description": instance.Description,
|
||||||
|
"params": mediaParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestAction) RunPost(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
Subject string
|
||||||
|
Body string
|
||||||
|
User string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("instanceId", params.InstanceId).
|
||||||
|
Gt(0, "请选择正确的媒介")
|
||||||
|
|
||||||
|
resp, err := this.RPC().MessageTaskRPC().CreateMessageTask(this.AdminContext(), &pb.CreateMessageTaskRequest{
|
||||||
|
RecipientId: 0,
|
||||||
|
InstanceId: params.InstanceId,
|
||||||
|
User: params.User,
|
||||||
|
Subject: params.Subject,
|
||||||
|
Body: params.Body,
|
||||||
|
IsPrimary: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["taskId"] = resp.MessageTaskId
|
||||||
|
|
||||||
|
defer this.CreateLogInfo("创建媒介测试任务 %d", resp.MessageTaskId)
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,287 @@
|
|||||||
|
package instances
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) Init() {
|
||||||
|
this.Nav("", "", "update")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) RunGet(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
}) {
|
||||||
|
instanceResp, err := this.RPC().MessageMediaInstanceRPC().FindEnabledMessageMediaInstance(this.AdminContext(), &pb.FindEnabledMessageMediaInstanceRequest{MessageMediaInstanceId: params.InstanceId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
instance := instanceResp.MessageMediaInstance
|
||||||
|
if instance == nil || instance.MessageMedia == nil {
|
||||||
|
this.NotFound("messageMediaInstance", params.InstanceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaParams := maps.Map{}
|
||||||
|
if len(instance.ParamsJSON) > 0 {
|
||||||
|
err = json.Unmarshal(instance.ParamsJSON, &mediaParams)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["instance"] = maps.Map{
|
||||||
|
"id": instance.Id,
|
||||||
|
"name": instance.Name,
|
||||||
|
"isOn": instance.IsOn,
|
||||||
|
"media": maps.Map{
|
||||||
|
"type": instance.MessageMedia.Type,
|
||||||
|
"name": instance.MessageMedia.Name,
|
||||||
|
},
|
||||||
|
"description": instance.Description,
|
||||||
|
"params": mediaParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) RunPost(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
Name string
|
||||||
|
MediaType string
|
||||||
|
|
||||||
|
EmailSmtp string
|
||||||
|
EmailUsername string
|
||||||
|
EmailPassword string
|
||||||
|
EmailFrom string
|
||||||
|
|
||||||
|
WebHookURL string
|
||||||
|
WebHookMethod string
|
||||||
|
WebHookHeaderNames []string
|
||||||
|
WebHookHeaderValues []string
|
||||||
|
WebHookContentType string
|
||||||
|
WebHookParamNames []string
|
||||||
|
WebHookParamValues []string
|
||||||
|
WebHookBody string
|
||||||
|
|
||||||
|
ScriptType string
|
||||||
|
ScriptPath string
|
||||||
|
ScriptLang string
|
||||||
|
ScriptCode string
|
||||||
|
ScriptCwd string
|
||||||
|
ScriptEnvNames []string
|
||||||
|
ScriptEnvValues []string
|
||||||
|
|
||||||
|
DingTalkWebHookURL string
|
||||||
|
|
||||||
|
QyWeixinCorporateId string
|
||||||
|
QyWeixinAgentId string
|
||||||
|
QyWeixinAppSecret string
|
||||||
|
QyWeixinTextFormat string
|
||||||
|
|
||||||
|
QyWeixinRobotWebHookURL string
|
||||||
|
QyWeixinRobotTextFormat string
|
||||||
|
|
||||||
|
AliyunSmsSign string
|
||||||
|
AliyunSmsTemplateCode string
|
||||||
|
AliyunSmsTemplateVarNames []string
|
||||||
|
AliyunSmsTemplateVarValues []string
|
||||||
|
AliyunSmsAccessKeyId string
|
||||||
|
AliyunSmsAccessKeySecret string
|
||||||
|
|
||||||
|
TelegramToken string
|
||||||
|
|
||||||
|
GroupIds string
|
||||||
|
Description string
|
||||||
|
IsOn bool
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改消息媒介 %d", params.InstanceId)
|
||||||
|
|
||||||
|
params.Must.
|
||||||
|
Field("name", params.Name).
|
||||||
|
Require("请输入媒介名称").
|
||||||
|
Field("mediaType", params.MediaType).
|
||||||
|
Require("请选择媒介类型")
|
||||||
|
|
||||||
|
options := maps.Map{}
|
||||||
|
|
||||||
|
switch params.MediaType {
|
||||||
|
case "email":
|
||||||
|
params.Must.
|
||||||
|
Field("emailSmtp", params.EmailSmtp).
|
||||||
|
Require("请输入SMTP地址").
|
||||||
|
Field("emailUsername", params.EmailUsername).
|
||||||
|
Require("请输入邮箱账号").
|
||||||
|
Field("emailPassword", params.EmailPassword).
|
||||||
|
Require("请输入密码或授权码")
|
||||||
|
|
||||||
|
options["smtp"] = params.EmailSmtp
|
||||||
|
options["username"] = params.EmailUsername
|
||||||
|
options["password"] = params.EmailPassword
|
||||||
|
options["from"] = params.EmailFrom
|
||||||
|
case "webHook":
|
||||||
|
params.Must.
|
||||||
|
Field("webHookURL", params.WebHookURL).
|
||||||
|
Require("请输入URL地址").
|
||||||
|
Match("(?i)^(http|https)://", "URL地址必须以http或https开头").
|
||||||
|
Field("webHookMethod", params.WebHookMethod).
|
||||||
|
Require("请选择请求方法")
|
||||||
|
|
||||||
|
options["url"] = params.WebHookURL
|
||||||
|
options["method"] = params.WebHookMethod
|
||||||
|
options["contentType"] = params.WebHookContentType
|
||||||
|
|
||||||
|
headers := []maps.Map{}
|
||||||
|
if len(params.WebHookHeaderNames) > 0 {
|
||||||
|
for index, name := range params.WebHookHeaderNames {
|
||||||
|
if index < len(params.WebHookHeaderValues) {
|
||||||
|
headers = append(headers, maps.Map{
|
||||||
|
"name": name,
|
||||||
|
"value": params.WebHookHeaderValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["headers"] = headers
|
||||||
|
|
||||||
|
if params.WebHookContentType == "params" {
|
||||||
|
webHookParams := []maps.Map{}
|
||||||
|
for index, name := range params.WebHookParamNames {
|
||||||
|
if index < len(params.WebHookParamValues) {
|
||||||
|
webHookParams = append(webHookParams, maps.Map{
|
||||||
|
"name": name,
|
||||||
|
"value": params.WebHookParamValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["params"] = webHookParams
|
||||||
|
} else if params.WebHookContentType == "body" {
|
||||||
|
options["body"] = params.WebHookBody
|
||||||
|
}
|
||||||
|
case "script":
|
||||||
|
if params.ScriptType == "path" {
|
||||||
|
params.Must.
|
||||||
|
Field("scriptPath", params.ScriptPath).
|
||||||
|
Require("请输入脚本路径")
|
||||||
|
} else if params.ScriptType == "code" {
|
||||||
|
params.Must.
|
||||||
|
Field("scriptCode", params.ScriptCode).
|
||||||
|
Require("请输入脚本代码")
|
||||||
|
} else {
|
||||||
|
params.Must.
|
||||||
|
Field("scriptPath", params.ScriptPath).
|
||||||
|
Require("请输入脚本路径")
|
||||||
|
}
|
||||||
|
|
||||||
|
options["scriptType"] = params.ScriptType
|
||||||
|
options["path"] = params.ScriptPath
|
||||||
|
options["scriptLang"] = params.ScriptLang
|
||||||
|
options["script"] = params.ScriptCode
|
||||||
|
options["cwd"] = params.ScriptCwd
|
||||||
|
|
||||||
|
env := []maps.Map{}
|
||||||
|
for index, envName := range params.ScriptEnvNames {
|
||||||
|
if index < len(params.ScriptEnvValues) {
|
||||||
|
env = append(env, maps.Map{
|
||||||
|
"name": envName,
|
||||||
|
"value": params.ScriptEnvValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["env"] = env
|
||||||
|
case "dingTalk":
|
||||||
|
params.Must.
|
||||||
|
Field("dingTalkWebHookURL", params.DingTalkWebHookURL).
|
||||||
|
Require("请输入Hook地址").
|
||||||
|
Match("^https:", "Hook地址必须以https://开头")
|
||||||
|
|
||||||
|
options["webHookURL"] = params.DingTalkWebHookURL
|
||||||
|
case "qyWeixin":
|
||||||
|
params.Must.
|
||||||
|
Field("qyWeixinCorporateId", params.QyWeixinCorporateId).
|
||||||
|
Require("请输入企业ID").
|
||||||
|
Field("qyWeixinAgentId", params.QyWeixinAgentId).
|
||||||
|
Require("请输入应用AgentId").
|
||||||
|
Field("qyWeixinSecret", params.QyWeixinAppSecret).
|
||||||
|
Require("请输入应用Secret")
|
||||||
|
|
||||||
|
options["corporateId"] = params.QyWeixinCorporateId
|
||||||
|
options["agentId"] = params.QyWeixinAgentId
|
||||||
|
options["appSecret"] = params.QyWeixinAppSecret
|
||||||
|
options["textFormat"] = params.QyWeixinTextFormat
|
||||||
|
case "qyWeixinRobot":
|
||||||
|
params.Must.
|
||||||
|
Field("qyWeixinRobotWebHookURL", params.QyWeixinRobotWebHookURL).
|
||||||
|
Require("请输入WebHook地址").
|
||||||
|
Match("^https:", "WebHook地址必须以https://开头")
|
||||||
|
|
||||||
|
options["webHookURL"] = params.QyWeixinRobotWebHookURL
|
||||||
|
options["textFormat"] = params.QyWeixinRobotTextFormat
|
||||||
|
case "aliyunSms":
|
||||||
|
params.Must.
|
||||||
|
Field("aliyunSmsSign", params.AliyunSmsSign).
|
||||||
|
Require("请输入签名名称").
|
||||||
|
Field("aliyunSmsTemplateCode", params.AliyunSmsTemplateCode).
|
||||||
|
Require("请输入模板CODE").
|
||||||
|
Field("aliyunSmsAccessKeyId", params.AliyunSmsAccessKeyId).
|
||||||
|
Require("请输入AccessKey ID").
|
||||||
|
Field("aliyunSmsAccessKeySecret", params.AliyunSmsAccessKeySecret).
|
||||||
|
Require("请输入AccessKey Secret")
|
||||||
|
|
||||||
|
options["sign"] = params.AliyunSmsSign
|
||||||
|
options["templateCode"] = params.AliyunSmsTemplateCode
|
||||||
|
options["accessKeyId"] = params.AliyunSmsAccessKeyId
|
||||||
|
options["accessKeySecret"] = params.AliyunSmsAccessKeySecret
|
||||||
|
|
||||||
|
variables := []maps.Map{}
|
||||||
|
for index, name := range params.AliyunSmsTemplateVarNames {
|
||||||
|
if index < len(params.AliyunSmsTemplateVarValues) {
|
||||||
|
variables = append(variables, maps.Map{
|
||||||
|
"name": name,
|
||||||
|
"value": params.AliyunSmsTemplateVarValues[index],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options["variables"] = variables
|
||||||
|
case "telegram":
|
||||||
|
params.Must.
|
||||||
|
Field("telegramToken", params.TelegramToken).
|
||||||
|
Require("请输入机器人Token")
|
||||||
|
options["token"] = params.TelegramToken
|
||||||
|
default:
|
||||||
|
this.Fail("错误的媒介类型")
|
||||||
|
}
|
||||||
|
|
||||||
|
optionsJSON, err := json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().MessageMediaInstanceRPC().UpdateMessageMediaInstance(this.AdminContext(), &pb.UpdateMessageMediaInstanceRequest{
|
||||||
|
MessageMediaInstanceId: params.InstanceId,
|
||||||
|
Name: params.Name,
|
||||||
|
MediaType: params.MediaType,
|
||||||
|
ParamsJSON: optionsJSON,
|
||||||
|
Description: params.Description,
|
||||||
|
IsOn: params.IsOn,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
61
internal/web/actions/default/admins/recipients/logs/index.go
Normal file
61
internal/web/actions/default/admins/recipients/logs/index.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "", "log")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
|
countResp, err := this.RPC().MessageTaskLogRPC().CountMessageTaskLogs(this.AdminContext(), &pb.CountMessageTaskLogsRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
page := this.NewPage(countResp.Count)
|
||||||
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
|
logsResp, err := this.RPC().MessageTaskLogRPC().ListMessageTaskLogs(this.AdminContext(), &pb.ListMessageTaskLogsRequest{
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logMaps := []maps.Map{}
|
||||||
|
for _, log := range logsResp.MessageTaskLogs {
|
||||||
|
if log.MessageTask.MessageRecipient != nil {
|
||||||
|
log.MessageTask.User = log.MessageTask.MessageRecipient.User
|
||||||
|
}
|
||||||
|
logMaps = append(logMaps, maps.Map{
|
||||||
|
"task": maps.Map{
|
||||||
|
"id": log.MessageTask.Id,
|
||||||
|
"user": log.MessageTask.User,
|
||||||
|
"subject": log.MessageTask.Subject,
|
||||||
|
"body": log.MessageTask.Body,
|
||||||
|
"instance": maps.Map{
|
||||||
|
"id": log.MessageTask.MessageMediaInstance.Id,
|
||||||
|
"name": log.MessageTask.MessageMediaInstance.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"isOk": log.IsOk,
|
||||||
|
"error": log.Error,
|
||||||
|
"response": log.Response,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["logs"] = logMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
19
internal/web/actions/default/admins/recipients/logs/init.go
Normal file
19
internal/web/actions/default/admins/recipients/logs/init.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
|
"github.com/iwind/TeaGo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeAdmin)).
|
||||||
|
Data("teaMenu", "admins").
|
||||||
|
Data("teaSubMenu", "recipients").
|
||||||
|
Prefix("/admins/recipients/logs").
|
||||||
|
Get("", new(IndexAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 媒介类型选项
|
||||||
|
type MediaOptionsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MediaOptionsAction) RunPost(params struct{}) {
|
||||||
|
resp, err := this.RPC().MessageMediaRPC().FindAllMessageMedias(this.AdminContext(), &pb.FindAllMessageMediasRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mediaMaps := []maps.Map{}
|
||||||
|
for _, media := range resp.MessageMedias {
|
||||||
|
mediaMaps = append(mediaMaps, maps.Map{
|
||||||
|
"id": media.Id,
|
||||||
|
"type": media.Type,
|
||||||
|
"name": media.Name,
|
||||||
|
"description": media.Description,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["medias"] = mediaMaps
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
50
internal/web/actions/default/admins/recipients/recipient.go
Normal file
50
internal/web/actions/default/admins/recipients/recipient.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RecipientAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RecipientAction) Init() {
|
||||||
|
this.Nav("", "", "recipient")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RecipientAction) RunGet(params struct {
|
||||||
|
RecipientId int64
|
||||||
|
}) {
|
||||||
|
recipientResp, err := this.RPC().MessageRecipientRPC().FindEnabledMessageRecipient(this.AdminContext(), &pb.FindEnabledMessageRecipientRequest{MessageRecipientId: params.RecipientId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recipient := recipientResp.MessageRecipient
|
||||||
|
if recipient == nil || recipient.Admin == nil || recipient.MessageMediaInstance == nil {
|
||||||
|
this.NotFound("messageRecipient", params.RecipientId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["recipient"] = maps.Map{
|
||||||
|
"id": recipient.Id,
|
||||||
|
"admin": maps.Map{
|
||||||
|
"id": recipient.Admin.Id,
|
||||||
|
"fullname": recipient.Admin.Fullname,
|
||||||
|
"username": recipient.Admin.Username,
|
||||||
|
},
|
||||||
|
"groups": recipient.MessageRecipientGroups,
|
||||||
|
"isOn": recipient.IsOn,
|
||||||
|
"instance": maps.Map{
|
||||||
|
"id": recipient.MessageMediaInstance.Id,
|
||||||
|
"name": recipient.MessageMediaInstance.Name,
|
||||||
|
"description": recipient.MessageMediaInstance.Description,
|
||||||
|
},
|
||||||
|
"user": recipient.User,
|
||||||
|
"description": recipient.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
19
internal/web/actions/default/admins/recipients/tasks/init.go
Normal file
19
internal/web/actions/default/admins/recipients/tasks/init.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
|
"github.com/iwind/TeaGo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||||
|
server.
|
||||||
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeAdmin)).
|
||||||
|
Data("teaMenu", "admins").
|
||||||
|
Data("teaSubMenu", "recipients").
|
||||||
|
Prefix("/admins/recipients/tasks").
|
||||||
|
Post("/taskInfo", new(TaskInfoAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TaskInfoAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TaskInfoAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TaskInfoAction) RunPost(params struct {
|
||||||
|
TaskId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().MessageTaskRPC().FindEnabledMessageTask(this.AdminContext(), &pb.FindEnabledMessageTaskRequest{MessageTaskId: params.TaskId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.MessageTask == nil {
|
||||||
|
this.NotFound("messageTask", params.TaskId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result := resp.MessageTask.Result
|
||||||
|
this.Data["status"] = resp.MessageTask.Status
|
||||||
|
this.Data["result"] = maps.Map{
|
||||||
|
"isOk": result.IsOk,
|
||||||
|
"response": result.Response,
|
||||||
|
"error": result.Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
113
internal/web/actions/default/admins/recipients/test.go
Normal file
113
internal/web/actions/default/admins/recipients/test.go
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestAction) Init() {
|
||||||
|
this.Nav("", "", "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestAction) RunGet(params struct {
|
||||||
|
RecipientId int64
|
||||||
|
}) {
|
||||||
|
recipientResp, err := this.RPC().MessageRecipientRPC().FindEnabledMessageRecipient(this.AdminContext(), &pb.FindEnabledMessageRecipientRequest{MessageRecipientId: params.RecipientId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recipient := recipientResp.MessageRecipient
|
||||||
|
if recipient == nil || recipient.Admin == nil || recipient.MessageMediaInstance == nil {
|
||||||
|
this.NotFound("messageRecipient", params.RecipientId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["recipient"] = maps.Map{
|
||||||
|
"id": recipient.Id,
|
||||||
|
"admin": maps.Map{
|
||||||
|
"id": recipient.Admin.Id,
|
||||||
|
"fullname": recipient.Admin.Fullname,
|
||||||
|
"username": recipient.Admin.Username,
|
||||||
|
},
|
||||||
|
"instance": maps.Map{
|
||||||
|
"id": recipient.MessageMediaInstance.Id,
|
||||||
|
"name": recipient.MessageMediaInstance.Name,
|
||||||
|
"description": recipient.MessageMediaInstance.Description,
|
||||||
|
},
|
||||||
|
"user": recipient.User,
|
||||||
|
}
|
||||||
|
|
||||||
|
instanceResp, err := this.RPC().MessageMediaInstanceRPC().FindEnabledMessageMediaInstance(this.AdminContext(), &pb.FindEnabledMessageMediaInstanceRequest{MessageMediaInstanceId: recipient.MessageMediaInstance.Id})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
instance := instanceResp.MessageMediaInstance
|
||||||
|
if instance == nil || instance.MessageMedia == nil {
|
||||||
|
this.NotFound("messageMediaInstance", recipient.MessageMediaInstance.Id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaParams := maps.Map{}
|
||||||
|
if len(instance.ParamsJSON) > 0 {
|
||||||
|
err = json.Unmarshal(instance.ParamsJSON, &mediaParams)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["instance"] = maps.Map{
|
||||||
|
"id": instance.Id,
|
||||||
|
"isOn": instance.IsOn,
|
||||||
|
"media": maps.Map{
|
||||||
|
"type": instance.MessageMedia.Type,
|
||||||
|
"name": instance.MessageMedia.Name,
|
||||||
|
"userDescription": instance.MessageMedia.UserDescription,
|
||||||
|
},
|
||||||
|
"description": instance.Description,
|
||||||
|
"params": mediaParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestAction) RunPost(params struct {
|
||||||
|
InstanceId int64
|
||||||
|
Subject string
|
||||||
|
Body string
|
||||||
|
User string
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("instanceId", params.InstanceId).
|
||||||
|
Gt(0, "请选择正确的媒介")
|
||||||
|
|
||||||
|
resp, err := this.RPC().MessageTaskRPC().CreateMessageTask(this.AdminContext(), &pb.CreateMessageTaskRequest{
|
||||||
|
RecipientId: 0,
|
||||||
|
InstanceId: params.InstanceId,
|
||||||
|
User: params.User,
|
||||||
|
Subject: params.Subject,
|
||||||
|
Body: params.Body,
|
||||||
|
IsPrimary: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["taskId"] = resp.MessageTaskId
|
||||||
|
|
||||||
|
defer this.CreateLogInfo("创建媒介测试任务 %d", resp.MessageTaskId)
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
92
internal/web/actions/default/admins/recipients/update.go
Normal file
92
internal/web/actions/default/admins/recipients/update.go
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package recipients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) Init() {
|
||||||
|
this.Nav("", "", "update")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) RunGet(params struct {
|
||||||
|
RecipientId int64
|
||||||
|
}) {
|
||||||
|
recipientResp, err := this.RPC().MessageRecipientRPC().FindEnabledMessageRecipient(this.AdminContext(), &pb.FindEnabledMessageRecipientRequest{MessageRecipientId: params.RecipientId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recipient := recipientResp.MessageRecipient
|
||||||
|
if recipient == nil || recipient.Admin == nil || recipient.MessageMediaInstance == nil {
|
||||||
|
this.NotFound("messageRecipient", params.RecipientId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["recipient"] = maps.Map{
|
||||||
|
"id": recipient.Id,
|
||||||
|
"admin": maps.Map{
|
||||||
|
"id": recipient.Admin.Id,
|
||||||
|
"fullname": recipient.Admin.Fullname,
|
||||||
|
"username": recipient.Admin.Username,
|
||||||
|
},
|
||||||
|
"groups": recipient.MessageRecipientGroups,
|
||||||
|
"isOn": recipient.IsOn,
|
||||||
|
"instance": maps.Map{
|
||||||
|
"id": recipient.MessageMediaInstance.Id,
|
||||||
|
"name": recipient.MessageMediaInstance.Name,
|
||||||
|
},
|
||||||
|
"user": recipient.User,
|
||||||
|
"description": recipient.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdateAction) RunPost(params struct {
|
||||||
|
RecipientId int64
|
||||||
|
|
||||||
|
AdminId int64
|
||||||
|
User string
|
||||||
|
InstanceId int64
|
||||||
|
|
||||||
|
GroupIds string
|
||||||
|
Description string
|
||||||
|
IsOn bool
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改媒介接收人 %d", params.RecipientId)
|
||||||
|
|
||||||
|
params.Must.
|
||||||
|
Field("adminId", params.AdminId).
|
||||||
|
Gt(0, "请选择系统用户").
|
||||||
|
Field("instanceId", params.InstanceId).
|
||||||
|
Gt(0, "请选择媒介")
|
||||||
|
|
||||||
|
groupIds := utils.SplitNumbers(params.GroupIds)
|
||||||
|
|
||||||
|
_, err := this.RPC().MessageRecipientRPC().UpdateMessageRecipient(this.AdminContext(), &pb.UpdateMessageRecipientRequest{
|
||||||
|
MessageRecipientId: params.RecipientId,
|
||||||
|
AdminId: params.AdminId,
|
||||||
|
MessageMediaInstanceId: params.InstanceId,
|
||||||
|
User: params.User,
|
||||||
|
MessageRecipientGroupIds: groupIds,
|
||||||
|
Description: params.Description,
|
||||||
|
IsOn: params.IsOn,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -45,6 +45,7 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
"username": admin.Username,
|
"username": admin.Username,
|
||||||
"isOn": admin.IsOn,
|
"isOn": admin.IsOn,
|
||||||
"isSuper": admin.IsSuper,
|
"isSuper": admin.IsSuper,
|
||||||
|
"canLogin": admin.CanLogin,
|
||||||
"otpLoginIsOn": otpLoginIsOn,
|
"otpLoginIsOn": otpLoginIsOn,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
ModuleCodes []string
|
ModuleCodes []string
|
||||||
IsOn bool
|
IsOn bool
|
||||||
IsSuper bool
|
IsSuper bool
|
||||||
|
CanLogin bool
|
||||||
|
|
||||||
// OTP
|
// OTP
|
||||||
OtpOn bool
|
OtpOn bool
|
||||||
@@ -139,6 +141,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
ModulesJSON: modulesJSON,
|
ModulesJSON: modulesJSON,
|
||||||
IsSuper: params.IsSuper,
|
IsSuper: params.IsSuper,
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
|
CanLogin: params.CanLogin,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package node
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
@@ -18,7 +19,18 @@ func (this *LogsAction) Init() {
|
|||||||
|
|
||||||
func (this *LogsAction) RunGet(params struct {
|
func (this *LogsAction) RunGet(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
|
|
||||||
|
DayFrom string
|
||||||
|
DayTo string
|
||||||
|
Keyword string
|
||||||
|
Level string
|
||||||
}) {
|
}) {
|
||||||
|
this.Data["nodeId"] = params.NodeId
|
||||||
|
this.Data["dayFrom"] = params.DayFrom
|
||||||
|
this.Data["dayTo"] = params.DayTo
|
||||||
|
this.Data["keyword"] = params.Keyword
|
||||||
|
this.Data["level"] = params.Level
|
||||||
|
|
||||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -36,8 +48,12 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||||
Role: "api",
|
Role: nodeconfigs.NodeRoleAPI,
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
|
DayFrom: params.DayFrom,
|
||||||
|
DayTo: params.DayTo,
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
Level: params.Level,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -47,8 +63,13 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
page := this.NewPage(count, 20)
|
page := this.NewPage(count, 20)
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Role: "api",
|
Role: nodeconfigs.NodeRoleAPI,
|
||||||
|
DayFrom: params.DayFrom,
|
||||||
|
DayTo: params.DayTo,
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
Level: params.Level,
|
||||||
|
|
||||||
Offset: page.Offset,
|
Offset: page.Offset,
|
||||||
Size: page.Size,
|
Size: page.Size,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cluster
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
@@ -79,9 +80,9 @@ func (this *CreateBatchAction) RunPost(params struct {
|
|||||||
resp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
|
resp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
|
||||||
Name: ip,
|
Name: ip,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
GroupId: params.GroupId,
|
NodeGroupId: params.GroupId,
|
||||||
RegionId: params.RegionId,
|
NodeRegionId: params.RegionId,
|
||||||
Login: nil,
|
NodeLogin: nil,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -90,6 +91,7 @@ func (this *CreateBatchAction) RunPost(params struct {
|
|||||||
nodeId := resp.NodeId
|
nodeId := resp.NodeId
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||||
NodeId: nodeId,
|
NodeId: nodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
Name: "IP地址",
|
Name: "IP地址",
|
||||||
Ip: ip,
|
Ip: ip,
|
||||||
CanAccess: true,
|
CanAccess: true,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
@@ -133,9 +134,9 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
createResp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
|
createResp, err := this.RPC().NodeRPC().CreateNode(this.AdminContext(), &pb.CreateNodeRequest{
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
GroupId: params.GroupId,
|
NodeGroupId: params.GroupId,
|
||||||
RegionId: params.RegionId,
|
NodeRegionId: params.RegionId,
|
||||||
Login: loginInfo,
|
NodeLogin: loginInfo,
|
||||||
DnsDomainId: params.DnsDomainId,
|
DnsDomainId: params.DnsDomainId,
|
||||||
DnsRoutes: dnsRouteCodes,
|
DnsRoutes: dnsRouteCodes,
|
||||||
})
|
})
|
||||||
@@ -156,6 +157,7 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
} else {
|
} else {
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||||
NodeId: nodeId,
|
NodeId: nodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
Name: address.GetString("name"),
|
Name: address.GetString("name"),
|
||||||
Ip: address.GetString("ip"),
|
Ip: address.GetString("ip"),
|
||||||
CanAccess: address.GetBool("canAccess"),
|
CanAccess: address.GetBool("canAccess"),
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.Data["group"] = maps.Map{
|
this.Data["group"] = maps.Map{
|
||||||
"id": createResp.GroupId,
|
"id": createResp.NodeGroupId,
|
||||||
"name": params.Name,
|
"name": params.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建集群分组", createResp.GroupId)
|
defer this.CreateLog(oplogs.LevelInfo, "创建节点分组", createResp.NodeGroupId)
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
this.Fail("此分组正在被使用不能删除,请修改节点后再删除")
|
this.Fail("此分组正在被使用不能删除,请修改节点后再删除")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().NodeGroupRPC().DeleteNodeGroup(this.AdminContext(), &pb.DeleteNodeGroupRequest{GroupId: params.GroupId})
|
_, err = this.RPC().NodeGroupRPC().DeleteNodeGroup(this.AdminContext(), &pb.DeleteNodeGroupRequest{NodeGroupId: params.GroupId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
}) {
|
}) {
|
||||||
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{
|
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithNodeClusterIdRequest{
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -27,7 +27,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
groupMaps := []maps.Map{}
|
groupMaps := []maps.Map{}
|
||||||
for _, group := range groupsResp.Groups {
|
for _, group := range groupsResp.NodeGroups {
|
||||||
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGroupId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGroupIdRequest{NodeGroupId: group.Id})
|
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGroupId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGroupIdRequest{NodeGroupId: group.Id})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ func (this *SelectPopupAction) Init() {
|
|||||||
func (this *SelectPopupAction) RunGet(params struct {
|
func (this *SelectPopupAction) RunGet(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
}) {
|
}) {
|
||||||
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{NodeClusterId: params.ClusterId})
|
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithNodeClusterIdRequest{NodeClusterId: params.ClusterId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
groupMaps := []maps.Map{}
|
groupMaps := []maps.Map{}
|
||||||
for _, group := range groupsResp.Groups {
|
for _, group := range groupsResp.NodeGroups {
|
||||||
groupMaps = append(groupMaps, maps.Map{
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
"id": group.Id,
|
"id": group.Id,
|
||||||
"name": group.Name,
|
"name": group.Name,
|
||||||
@@ -44,12 +44,12 @@ func (this *SelectPopupAction) RunPost(params struct {
|
|||||||
this.Fail("请选择要使用的分组")
|
this.Fail("请选择要使用的分组")
|
||||||
}
|
}
|
||||||
|
|
||||||
groupResp, err := this.RPC().NodeGroupRPC().FindEnabledNodeGroup(this.AdminContext(), &pb.FindEnabledNodeGroupRequest{GroupId: params.GroupId})
|
groupResp, err := this.RPC().NodeGroupRPC().FindEnabledNodeGroup(this.AdminContext(), &pb.FindEnabledNodeGroupRequest{NodeGroupId: params.GroupId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
group := groupResp.Group
|
group := groupResp.NodeGroup
|
||||||
if group == nil {
|
if group == nil {
|
||||||
this.NotFound("nodeGroup", params.GroupId)
|
this.NotFound("nodeGroup", params.GroupId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type SortAction struct {
|
|||||||
func (this *SortAction) RunPost(params struct {
|
func (this *SortAction) RunPost(params struct {
|
||||||
GroupIds []int64
|
GroupIds []int64
|
||||||
}) {
|
}) {
|
||||||
_, err := this.RPC().NodeGroupRPC().UpdateNodeGroupOrders(this.AdminContext(), &pb.UpdateNodeGroupOrdersRequest{GroupIds: params.GroupIds})
|
_, err := this.RPC().NodeGroupRPC().UpdateNodeGroupOrders(this.AdminContext(), &pb.UpdateNodeGroupOrdersRequest{NodeGroupIds: params.GroupIds})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ func (this *UpdatePopupAction) Init() {
|
|||||||
func (this *UpdatePopupAction) RunGet(params struct {
|
func (this *UpdatePopupAction) RunGet(params struct {
|
||||||
GroupId int64
|
GroupId int64
|
||||||
}) {
|
}) {
|
||||||
groupResp, err := this.RPC().NodeGroupRPC().FindEnabledNodeGroup(this.AdminContext(), &pb.FindEnabledNodeGroupRequest{GroupId: params.GroupId})
|
groupResp, err := this.RPC().NodeGroupRPC().FindEnabledNodeGroup(this.AdminContext(), &pb.FindEnabledNodeGroupRequest{NodeGroupId: params.GroupId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
group := groupResp.Group
|
group := groupResp.NodeGroup
|
||||||
if group == nil {
|
if group == nil {
|
||||||
this.NotFound("nodeGroup", params.GroupId)
|
this.NotFound("nodeGroup", params.GroupId)
|
||||||
return
|
return
|
||||||
@@ -48,8 +48,8 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入分组名称")
|
Require("请输入分组名称")
|
||||||
_, err := this.RPC().NodeGroupRPC().UpdateNodeGroup(this.AdminContext(), &pb.UpdateNodeGroupRequest{
|
_, err := this.RPC().NodeGroupRPC().UpdateNodeGroup(this.AdminContext(), &pb.UpdateNodeGroupRequest{
|
||||||
GroupId: params.GroupId,
|
NodeGroupId: params.GroupId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -36,10 +36,19 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["activeState"] = params.ActiveState
|
this.Data["activeState"] = params.ActiveState
|
||||||
this.Data["keyword"] = params.Keyword
|
this.Data["keyword"] = params.Keyword
|
||||||
|
|
||||||
|
countAllResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["countAll"] = countAllResp.Count
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
|
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
GroupId: params.GroupId,
|
NodeGroupId: params.GroupId,
|
||||||
RegionId: params.RegionId,
|
NodeRegionId: params.RegionId,
|
||||||
InstallState: types.Int32(params.InstalledState),
|
InstallState: types.Int32(params.InstalledState),
|
||||||
ActiveState: types.Int32(params.ActiveState),
|
ActiveState: types.Int32(params.ActiveState),
|
||||||
Keyword: params.Keyword,
|
Keyword: params.Keyword,
|
||||||
@@ -56,12 +65,16 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
Offset: page.Offset,
|
Offset: page.Offset,
|
||||||
Size: page.Size,
|
Size: page.Size,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
GroupId: params.GroupId,
|
NodeGroupId: params.GroupId,
|
||||||
RegionId: params.RegionId,
|
NodeRegionId: params.RegionId,
|
||||||
InstallState: types.Int32(params.InstalledState),
|
InstallState: types.Int32(params.InstalledState),
|
||||||
ActiveState: types.Int32(params.ActiveState),
|
ActiveState: types.Int32(params.ActiveState),
|
||||||
Keyword: params.Keyword,
|
Keyword: params.Keyword,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
nodeMaps := []maps.Map{}
|
nodeMaps := []maps.Map{}
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.Nodes {
|
||||||
// 状态
|
// 状态
|
||||||
@@ -78,7 +91,10 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IP
|
// IP
|
||||||
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{NodeId: node.Id})
|
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{
|
||||||
|
NodeId: node.Id,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
@@ -95,19 +111,19 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
|
|
||||||
// 分组
|
// 分组
|
||||||
var groupMap maps.Map = nil
|
var groupMap maps.Map = nil
|
||||||
if node.Group != nil {
|
if node.NodeGroup != nil {
|
||||||
groupMap = maps.Map{
|
groupMap = maps.Map{
|
||||||
"id": node.Group.Id,
|
"id": node.NodeGroup.Id,
|
||||||
"name": node.Group.Name,
|
"name": node.NodeGroup.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 区域
|
// 区域
|
||||||
var regionMap maps.Map = nil
|
var regionMap maps.Map = nil
|
||||||
if node.Region != nil {
|
if node.NodeRegion != nil {
|
||||||
regionMap = maps.Map{
|
regionMap = maps.Map{
|
||||||
"id": node.Region.Id,
|
"id": node.NodeRegion.Id,
|
||||||
"name": node.Region.Name,
|
"name": node.NodeRegion.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,14 +169,14 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
|
|
||||||
// 所有分组
|
// 所有分组
|
||||||
groupMaps := []maps.Map{}
|
groupMaps := []maps.Map{}
|
||||||
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{
|
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithNodeClusterIdRequest{
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, group := range groupsResp.Groups {
|
for _, group := range groupsResp.NodeGroups {
|
||||||
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGroupId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGroupIdRequest{NodeGroupId: group.Id})
|
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGroupId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGroupIdRequest{NodeGroupId: group.Id})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -194,5 +210,15 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
this.Data["regions"] = regionMaps
|
this.Data["regions"] = regionMaps
|
||||||
|
|
||||||
|
// 记录最近访问
|
||||||
|
_, err = this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{
|
||||||
|
ItemType: "cluster",
|
||||||
|
ItemId: params.ClusterId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/groups"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/groups"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/monitor"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/thresholds"
|
||||||
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||||
"github.com/iwind/TeaGo"
|
"github.com/iwind/TeaGo"
|
||||||
@@ -28,7 +30,7 @@ func init() {
|
|||||||
GetPost("/installManual", new(InstallManualAction)).
|
GetPost("/installManual", new(InstallManualAction)).
|
||||||
|
|
||||||
// 节点相关
|
// 节点相关
|
||||||
Get("/node", new(node.NodeAction)).
|
Get("/node", new(node.IndexAction)).
|
||||||
GetPost("/node/update", new(node.UpdateAction)).
|
GetPost("/node/update", new(node.UpdateAction)).
|
||||||
GetPost("/node/install", new(node.InstallAction)).
|
GetPost("/node/install", new(node.InstallAction)).
|
||||||
Post("/node/updateInstallStatus", new(node.UpdateInstallStatusAction)).
|
Post("/node/updateInstallStatus", new(node.UpdateInstallStatusAction)).
|
||||||
@@ -36,6 +38,15 @@ func init() {
|
|||||||
Get("/node/logs", new(node.LogsAction)).
|
Get("/node/logs", new(node.LogsAction)).
|
||||||
Post("/node/start", new(node.StartAction)).
|
Post("/node/start", new(node.StartAction)).
|
||||||
Post("/node/stop", new(node.StopAction)).
|
Post("/node/stop", new(node.StopAction)).
|
||||||
|
Post("/node/up", new(node.UpAction)).
|
||||||
|
Get("/node/monitor", new(monitor.IndexAction)).
|
||||||
|
Post("/node/monitor/cpu", new(monitor.CpuAction)).
|
||||||
|
Post("/node/monitor/memory", new(monitor.MemoryAction)).
|
||||||
|
Post("/node/monitor/load", new(monitor.LoadAction)).
|
||||||
|
Post("/node/monitor/trafficIn", new(monitor.TrafficInAction)).
|
||||||
|
Post("/node/monitor/trafficOut", new(monitor.TrafficOutAction)).
|
||||||
|
Post("/node/monitor/connections", new(monitor.ConnectionsAction)).
|
||||||
|
Get("/node/thresholds", new(thresholds.IndexAction)).
|
||||||
|
|
||||||
// 分组相关
|
// 分组相关
|
||||||
Get("/groups", new(groups.IndexAction)).
|
Get("/groups", new(groups.IndexAction)).
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func (this *InstallManualAction) RunGet(params struct {
|
|||||||
}) {
|
}) {
|
||||||
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "manual")
|
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "manual")
|
||||||
|
|
||||||
nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{NodeClusterId: params.ClusterId})
|
nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithNodeClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithNodeClusterIdRequest{NodeClusterId: params.ClusterId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (this *InstallRemoteAction) RunGet(params struct {
|
|||||||
}) {
|
}) {
|
||||||
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "install")
|
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "install")
|
||||||
|
|
||||||
nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithClusterIdRequest{NodeClusterId: params.ClusterId})
|
nodesResp, err := this.RPC().NodeRPC().FindAllNotInstalledNodesWithNodeClusterId(this.AdminContext(), &pb.FindAllNotInstalledNodesWithNodeClusterIdRequest{NodeClusterId: params.ClusterId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package node
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
@@ -11,16 +12,16 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeAction struct {
|
type IndexAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NodeAction) Init() {
|
func (this *IndexAction) Init() {
|
||||||
this.Nav("", "node", "node")
|
this.Nav("", "node", "node")
|
||||||
this.SecondMenu("nodes")
|
this.SecondMenu("nodes")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NodeAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
this.Data["nodeId"] = params.NodeId
|
this.Data["nodeId"] = params.NodeId
|
||||||
@@ -55,7 +56,10 @@ func (this *NodeAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IP地址
|
// IP地址
|
||||||
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{NodeId: params.NodeId})
|
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
@@ -114,17 +118,17 @@ func (this *NodeAction) RunGet(params struct {
|
|||||||
grantMap := maps.Map{}
|
grantMap := maps.Map{}
|
||||||
grantId := loginParams.GetInt64("grantId")
|
grantId := loginParams.GetInt64("grantId")
|
||||||
if grantId > 0 {
|
if grantId > 0 {
|
||||||
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: grantId})
|
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if grantResp.Grant != nil {
|
if grantResp.NodeGrant != nil {
|
||||||
grantMap = maps.Map{
|
grantMap = maps.Map{
|
||||||
"id": grantResp.Grant.Id,
|
"id": grantResp.NodeGrant.Id,
|
||||||
"name": grantResp.Grant.Name,
|
"name": grantResp.NodeGrant.Name,
|
||||||
"method": grantResp.Grant.Method,
|
"method": grantResp.NodeGrant.Method,
|
||||||
"methodName": grantutils.FindGrantMethodName(grantResp.Grant.Method),
|
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,19 +173,46 @@ func (this *NodeAction) RunGet(params struct {
|
|||||||
|
|
||||||
// 分组
|
// 分组
|
||||||
var groupMap maps.Map = nil
|
var groupMap maps.Map = nil
|
||||||
if node.Group != nil {
|
if node.NodeGroup != nil {
|
||||||
groupMap = maps.Map{
|
groupMap = maps.Map{
|
||||||
"id": node.Group.Id,
|
"id": node.NodeGroup.Id,
|
||||||
"name": node.Group.Name,
|
"name": node.NodeGroup.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 区域
|
// 区域
|
||||||
var regionMap maps.Map = nil
|
var regionMap maps.Map = nil
|
||||||
if node.Region != nil {
|
if node.NodeRegion != nil {
|
||||||
regionMap = maps.Map{
|
regionMap = maps.Map{
|
||||||
"id": node.Region.Id,
|
"id": node.NodeRegion.Id,
|
||||||
"name": node.Region.Name,
|
"name": node.NodeRegion.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 缓存硬盘 & 内存容量
|
||||||
|
var maxCacheDiskCapacity maps.Map = nil
|
||||||
|
if node.MaxCacheDiskCapacity != nil {
|
||||||
|
maxCacheDiskCapacity = maps.Map{
|
||||||
|
"count": node.MaxCacheDiskCapacity.Count,
|
||||||
|
"unit": node.MaxCacheDiskCapacity.Unit,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maxCacheDiskCapacity = maps.Map{
|
||||||
|
"count": 0,
|
||||||
|
"unit": "gb",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var maxCacheMemoryCapacity maps.Map = nil
|
||||||
|
if node.MaxCacheMemoryCapacity != nil {
|
||||||
|
maxCacheMemoryCapacity = maps.Map{
|
||||||
|
"count": node.MaxCacheMemoryCapacity.Count,
|
||||||
|
"unit": node.MaxCacheMemoryCapacity.Unit,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maxCacheMemoryCapacity = maps.Map{
|
||||||
|
"count": 0,
|
||||||
|
"unit": "gb",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,24 +230,29 @@ func (this *NodeAction) RunGet(params struct {
|
|||||||
"isOn": node.IsOn,
|
"isOn": node.IsOn,
|
||||||
|
|
||||||
"status": maps.Map{
|
"status": maps.Map{
|
||||||
"isActive": status.IsActive,
|
"isActive": status.IsActive,
|
||||||
"updatedAt": status.UpdatedAt,
|
"updatedAt": status.UpdatedAt,
|
||||||
"hostname": status.Hostname,
|
"hostname": status.Hostname,
|
||||||
"cpuUsage": status.CPUUsage,
|
"cpuUsage": status.CPUUsage,
|
||||||
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
||||||
"memUsage": status.MemoryUsage,
|
"memUsage": status.MemoryUsage,
|
||||||
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
||||||
"connectionCount": status.ConnectionCount,
|
"connectionCount": status.ConnectionCount,
|
||||||
"buildVersion": status.BuildVersion,
|
"buildVersion": status.BuildVersion,
|
||||||
"cpuPhysicalCount": status.CPUPhysicalCount,
|
"cpuPhysicalCount": status.CPUPhysicalCount,
|
||||||
"cpuLogicalCount": status.CPULogicalCount,
|
"cpuLogicalCount": status.CPULogicalCount,
|
||||||
"load1m": fmt.Sprintf("%.2f", status.Load1m),
|
"load1m": fmt.Sprintf("%.2f", status.Load1m),
|
||||||
"load5m": fmt.Sprintf("%.2f", status.Load5m),
|
"load5m": fmt.Sprintf("%.2f", status.Load5m),
|
||||||
"load15m": fmt.Sprintf("%.2f", status.Load15m),
|
"load15m": fmt.Sprintf("%.2f", status.Load15m),
|
||||||
|
"cacheTotalDiskSize": numberutils.FormatBytes(status.CacheTotalDiskSize),
|
||||||
|
"cacheTotalMemorySize": numberutils.FormatBytes(status.CacheTotalMemorySize),
|
||||||
},
|
},
|
||||||
|
|
||||||
"group": groupMap,
|
"group": groupMap,
|
||||||
"region": regionMap,
|
"region": regionMap,
|
||||||
|
|
||||||
|
"maxCacheDiskCapacity": maxCacheDiskCapacity,
|
||||||
|
"maxCacheMemoryCapacity": maxCacheMemoryCapacity,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
@@ -17,13 +17,25 @@ func (this *LogsAction) Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *LogsAction) RunGet(params struct {
|
func (this *LogsAction) RunGet(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
|
DayFrom string
|
||||||
|
DayTo string
|
||||||
|
Keyword string
|
||||||
|
Level string
|
||||||
}) {
|
}) {
|
||||||
this.Data["nodeId"] = params.NodeId
|
this.Data["nodeId"] = params.NodeId
|
||||||
|
this.Data["dayFrom"] = params.DayFrom
|
||||||
|
this.Data["dayTo"] = params.DayTo
|
||||||
|
this.Data["keyword"] = params.Keyword
|
||||||
|
this.Data["level"] = params.Level
|
||||||
|
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||||
Role: "node",
|
Role: "node",
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
|
DayFrom: params.DayFrom,
|
||||||
|
DayTo: params.DayTo,
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
Level: params.Level,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -33,10 +45,14 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
page := this.NewPage(count, 20)
|
page := this.NewPage(count, 20)
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Role: "node",
|
Role: "node",
|
||||||
Offset: page.Offset,
|
DayFrom: params.DayFrom,
|
||||||
Size: page.Size,
|
DayTo: params.DayTo,
|
||||||
|
Keyword: params.Keyword,
|
||||||
|
Level: params.Level,
|
||||||
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
})
|
})
|
||||||
|
|
||||||
logs := []maps.Map{}
|
logs := []maps.Map{}
|
||||||
@@ -47,6 +63,7 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||||
"level": log.Level,
|
"level": log.Level,
|
||||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
||||||
|
"count": log.Count,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["logs"] = logs
|
this.Data["logs"] = logs
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConnectionsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ConnectionsAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: nodeconfigs.NodeValueItemConnections,
|
||||||
|
Range: nodeconfigs.NodeValueRangeMinute,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
valuesMap := map[string]int64{} // YmdHi => count
|
||||||
|
for _, v := range resp.NodeValues {
|
||||||
|
if len(v.ValueJSON) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
valueMap := maps.Map{}
|
||||||
|
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetInt64("total")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过去一个小时
|
||||||
|
result := []maps.Map{}
|
||||||
|
for i := 60; i >= 1; i-- {
|
||||||
|
timestamp := time.Now().Unix() - int64(i)*60
|
||||||
|
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||||
|
total, ok := valuesMap[minute]
|
||||||
|
if ok {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": total,
|
||||||
|
"text": numberutils.FormatInt64(total),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": 0,
|
||||||
|
"text": "0",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["values"] = result
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CpuAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CpuAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: nodeconfigs.NodeValueItemCPU,
|
||||||
|
Range: nodeconfigs.NodeValueRangeMinute,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
valuesMap := map[string]float32{} // YmdHi => usage
|
||||||
|
for _, v := range resp.NodeValues {
|
||||||
|
if len(v.ValueJSON) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
valueMap := maps.Map{}
|
||||||
|
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetFloat32("usage") * 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过去一个小时
|
||||||
|
result := []maps.Map{}
|
||||||
|
for i := 60; i >= 1; i-- {
|
||||||
|
timestamp := time.Now().Unix() - int64(i)*60
|
||||||
|
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||||
|
total, ok := valuesMap[minute]
|
||||||
|
if ok {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": total,
|
||||||
|
"text": fmt.Sprintf("%.2f%%", total),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": 0,
|
||||||
|
"text": "0.0%",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["values"] = result
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "node", "monitor")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
this.Data["nodeId"] = params.NodeId
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoadAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *LoadAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: nodeconfigs.NodeValueItemLoad,
|
||||||
|
Range: nodeconfigs.NodeValueRangeMinute,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
valuesMap := map[string]float32{} // YmdHi => load5m
|
||||||
|
for _, v := range resp.NodeValues {
|
||||||
|
if len(v.ValueJSON) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
valueMap := maps.Map{}
|
||||||
|
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetFloat32("load5m")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过去一个小时
|
||||||
|
result := []maps.Map{}
|
||||||
|
for i := 60; i >= 1; i-- {
|
||||||
|
timestamp := time.Now().Unix() - int64(i)*60
|
||||||
|
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||||
|
total, ok := valuesMap[minute]
|
||||||
|
if ok {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": total,
|
||||||
|
"text": fmt.Sprintf("5分钟: %.2f", total),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": 0,
|
||||||
|
"text": "5分钟: 0.0",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["values"] = result
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MemoryAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MemoryAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: nodeconfigs.NodeValueItemMemory,
|
||||||
|
Range: nodeconfigs.NodeValueRangeMinute,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
valuesMap := map[string]float32{} // YmdHi => usage
|
||||||
|
for _, v := range resp.NodeValues {
|
||||||
|
if len(v.ValueJSON) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
valueMap := maps.Map{}
|
||||||
|
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetFloat32("usage") * 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过去一个小时
|
||||||
|
result := []maps.Map{}
|
||||||
|
for i := 60; i >= 1; i-- {
|
||||||
|
timestamp := time.Now().Unix() - int64(i)*60
|
||||||
|
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||||
|
total, ok := valuesMap[minute]
|
||||||
|
if ok {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": total,
|
||||||
|
"text": fmt.Sprintf("%.2f%%", total),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": 0,
|
||||||
|
"text": "0.0%",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["values"] = result
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TrafficInAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TrafficInAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: nodeconfigs.NodeValueItemTrafficIn,
|
||||||
|
Range: nodeconfigs.NodeValueRangeMinute,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
valuesMap := map[string]int64{} // YmdHi => bytes
|
||||||
|
for _, v := range resp.NodeValues {
|
||||||
|
if len(v.ValueJSON) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
valueMap := maps.Map{}
|
||||||
|
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetInt64("total")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过去一个小时
|
||||||
|
result := []maps.Map{}
|
||||||
|
for i := 60; i >= 1; i-- {
|
||||||
|
timestamp := time.Now().Unix() - int64(i)*60
|
||||||
|
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||||
|
total, ok := valuesMap[minute]
|
||||||
|
if ok {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": total / 60,
|
||||||
|
"text": numberutils.FormatBytes(total / 60),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": 0,
|
||||||
|
"text": numberutils.FormatBytes(0),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["values"] = result
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package monitor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TrafficOutAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TrafficOutAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: nodeconfigs.NodeValueItemTrafficOut,
|
||||||
|
Range: nodeconfigs.NodeValueRangeMinute,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
valuesMap := map[string]int64{} // YmdHi => bytes
|
||||||
|
for _, v := range resp.NodeValues {
|
||||||
|
if len(v.ValueJSON) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
valueMap := maps.Map{}
|
||||||
|
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetInt64("total")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过去一个小时
|
||||||
|
result := []maps.Map{}
|
||||||
|
for i := 60; i >= 1; i-- {
|
||||||
|
timestamp := time.Now().Unix() - int64(i)*60
|
||||||
|
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||||
|
total, ok := valuesMap[minute]
|
||||||
|
if ok {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": total / 60,
|
||||||
|
"text": numberutils.FormatBytes(total / 60),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = append(result, maps.Map{
|
||||||
|
"label": timeutil.FormatTime("H:i", timestamp),
|
||||||
|
"value": 0,
|
||||||
|
"text": numberutils.FormatBytes(0),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["values"] = result
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package thresholds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "node", "threshold")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
ClusterId int64
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
this.Data["nodeId"] = params.NodeId
|
||||||
|
|
||||||
|
// 列出所有阈值
|
||||||
|
thresholdsResp, err := this.RPC().NodeThresholdRPC().FindAllEnabledNodeThresholds(this.AdminContext(), &pb.FindAllEnabledNodeThresholdsRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
thresholdMaps := []maps.Map{}
|
||||||
|
for _, threshold := range thresholdsResp.NodeThresholds {
|
||||||
|
thresholdMaps = append(thresholdMaps, maps.Map{
|
||||||
|
"id": threshold.Id,
|
||||||
|
"itemName": nodeconfigs.FindNodeValueItemName(threshold.Item),
|
||||||
|
"paramName": nodeconfigs.FindNodeValueItemParamName(threshold.Item, threshold.Param),
|
||||||
|
"operatorName": nodeconfigs.FindNodeValueOperatorName(threshold.Operator),
|
||||||
|
"value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON),
|
||||||
|
"sumMethodName": nodeconfigs.FindNodeValueSumMethodName(threshold.SumMethod),
|
||||||
|
"duration": threshold.Duration,
|
||||||
|
"durationUnitName": nodeconfigs.FindNodeValueDurationUnitName(threshold.DurationUnit),
|
||||||
|
"isOn": threshold.IsOn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["thresholds"] = thresholdMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
28
internal/web/actions/default/clusters/cluster/node/up.go
Normal file
28
internal/web/actions/default/clusters/cluster/node/up.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package node
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 手动上线
|
||||||
|
type UpAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpAction) RunPost(params struct {
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("手动上线节点 %d", params.NodeId)
|
||||||
|
|
||||||
|
_, err := this.RPC().NodeRPC().UpdateNodeUp(this.AdminContext(), &pb.UpdateNodeUpRequest{
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
IsUp: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -6,7 +6,9 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
@@ -45,7 +47,10 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IP地址
|
// IP地址
|
||||||
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{NodeId: params.NodeId})
|
ipAddressesResp, err := this.RPC().NodeIPAddressRPC().FindAllEnabledIPAddressesWithNodeId(this.AdminContext(), &pb.FindAllEnabledIPAddressesWithNodeIdRequest{
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
@@ -114,17 +119,17 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
grantMap := maps.Map{}
|
grantMap := maps.Map{}
|
||||||
grantId := loginParams.GetInt64("grantId")
|
grantId := loginParams.GetInt64("grantId")
|
||||||
if grantId > 0 {
|
if grantId > 0 {
|
||||||
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: grantId})
|
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if grantResp.Grant != nil {
|
if grantResp.NodeGrant != nil {
|
||||||
grantMap = maps.Map{
|
grantMap = maps.Map{
|
||||||
"id": grantResp.Grant.Id,
|
"id": grantResp.NodeGrant.Id,
|
||||||
"name": grantResp.Grant.Name,
|
"name": grantResp.NodeGrant.Name,
|
||||||
"method": grantResp.Grant.Method,
|
"method": grantResp.NodeGrant.Method,
|
||||||
"methodName": grantutils.FindGrantMethodName(grantResp.Grant.Method),
|
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,32 +145,61 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
|
|
||||||
// 分组
|
// 分组
|
||||||
var groupMap maps.Map = nil
|
var groupMap maps.Map = nil
|
||||||
if node.Group != nil {
|
if node.NodeGroup != nil {
|
||||||
groupMap = maps.Map{
|
groupMap = maps.Map{
|
||||||
"id": node.Group.Id,
|
"id": node.NodeGroup.Id,
|
||||||
"name": node.Group.Name,
|
"name": node.NodeGroup.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 区域
|
// 区域
|
||||||
var regionMap maps.Map = nil
|
var regionMap maps.Map = nil
|
||||||
if node.Region != nil {
|
if node.NodeRegion != nil {
|
||||||
regionMap = maps.Map{
|
regionMap = maps.Map{
|
||||||
"id": node.Region.Id,
|
"id": node.NodeRegion.Id,
|
||||||
"name": node.Region.Name,
|
"name": node.NodeRegion.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 缓存硬盘 & 内存容量
|
||||||
|
var maxCacheDiskCapacity maps.Map = nil
|
||||||
|
if node.MaxCacheDiskCapacity != nil {
|
||||||
|
maxCacheDiskCapacity = maps.Map{
|
||||||
|
"count": node.MaxCacheDiskCapacity.Count,
|
||||||
|
"unit": node.MaxCacheDiskCapacity.Unit,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maxCacheDiskCapacity = maps.Map{
|
||||||
|
"count": 0,
|
||||||
|
"unit": "gb",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var maxCacheMemoryCapacity maps.Map = nil
|
||||||
|
if node.MaxCacheMemoryCapacity != nil {
|
||||||
|
maxCacheMemoryCapacity = maps.Map{
|
||||||
|
"count": node.MaxCacheMemoryCapacity.Count,
|
||||||
|
"unit": node.MaxCacheMemoryCapacity.Unit,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maxCacheMemoryCapacity = maps.Map{
|
||||||
|
"count": 0,
|
||||||
|
"unit": "gb",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Data["node"] = maps.Map{
|
this.Data["node"] = maps.Map{
|
||||||
"id": node.Id,
|
"id": node.Id,
|
||||||
"name": node.Name,
|
"name": node.Name,
|
||||||
"ipAddresses": ipAddressMaps,
|
"ipAddresses": ipAddressMaps,
|
||||||
"cluster": clusterMap,
|
"cluster": clusterMap,
|
||||||
"login": loginMap,
|
"login": loginMap,
|
||||||
"maxCPU": node.MaxCPU,
|
"maxCPU": node.MaxCPU,
|
||||||
"isOn": node.IsOn,
|
"isOn": node.IsOn,
|
||||||
"group": groupMap,
|
"group": groupMap,
|
||||||
"region": regionMap,
|
"region": regionMap,
|
||||||
|
"maxCacheDiskCapacity": maxCacheDiskCapacity,
|
||||||
|
"maxCacheMemoryCapacity": maxCacheMemoryCapacity,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 所有集群
|
// 所有集群
|
||||||
@@ -190,18 +224,20 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *UpdateAction) RunPost(params struct {
|
func (this *UpdateAction) RunPost(params struct {
|
||||||
LoginId int64
|
LoginId int64
|
||||||
NodeId int64
|
NodeId int64
|
||||||
GroupId int64
|
GroupId int64
|
||||||
RegionId int64
|
RegionId int64
|
||||||
Name string
|
Name string
|
||||||
IPAddressesJSON []byte `alias:"ipAddressesJSON"`
|
IPAddressesJSON []byte `alias:"ipAddressesJSON"`
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
GrantId int64
|
GrantId int64
|
||||||
SshHost string
|
SshHost string
|
||||||
SshPort int
|
SshPort int
|
||||||
MaxCPU int32
|
MaxCPU int32
|
||||||
IsOn bool
|
IsOn bool
|
||||||
|
MaxCacheDiskCapacityJSON []byte
|
||||||
|
MaxCacheMemoryCapacityJSON []byte
|
||||||
|
|
||||||
DnsDomainId int64
|
DnsDomainId int64
|
||||||
DnsRoutesJSON []byte
|
DnsRoutesJSON []byte
|
||||||
@@ -258,18 +294,49 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
}.AsJSON(),
|
}.AsJSON(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 缓存硬盘 & 内存容量
|
||||||
|
var pbMaxCacheDiskCapacity *pb.SizeCapacity
|
||||||
|
if len(params.MaxCacheDiskCapacityJSON) > 0 {
|
||||||
|
var sizeCapacity = &shared.SizeCapacity{}
|
||||||
|
err := json.Unmarshal(params.MaxCacheDiskCapacityJSON, sizeCapacity)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pbMaxCacheDiskCapacity = &pb.SizeCapacity{
|
||||||
|
Count: sizeCapacity.Count,
|
||||||
|
Unit: sizeCapacity.Unit,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var pbMaxCacheMemoryCapacity *pb.SizeCapacity
|
||||||
|
if len(params.MaxCacheMemoryCapacityJSON) > 0 {
|
||||||
|
var sizeCapacity = &shared.SizeCapacity{}
|
||||||
|
err := json.Unmarshal(params.MaxCacheMemoryCapacityJSON, sizeCapacity)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pbMaxCacheMemoryCapacity = &pb.SizeCapacity{
|
||||||
|
Count: sizeCapacity.Count,
|
||||||
|
Unit: sizeCapacity.Unit,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
_, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{
|
_, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
GroupId: params.GroupId,
|
NodeGroupId: params.GroupId,
|
||||||
RegionId: params.RegionId,
|
NodeRegionId: params.RegionId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
Login: loginInfo,
|
NodeLogin: loginInfo,
|
||||||
MaxCPU: params.MaxCPU,
|
MaxCPU: params.MaxCPU,
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
DnsDomainId: params.DnsDomainId,
|
DnsDomainId: params.DnsDomainId,
|
||||||
DnsRoutes: dnsRouteCodes,
|
DnsRoutes: dnsRouteCodes,
|
||||||
|
MaxCacheDiskCapacity: pbMaxCacheDiskCapacity,
|
||||||
|
MaxCacheMemoryCapacity: pbMaxCacheMemoryCapacity,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -277,14 +344,17 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 禁用老的IP地址
|
// 禁用老的IP地址
|
||||||
_, err = this.RPC().NodeIPAddressRPC().DisableAllIPAddressesWithNodeId(this.AdminContext(), &pb.DisableAllIPAddressesWithNodeIdRequest{NodeId: params.NodeId})
|
_, err = this.RPC().NodeIPAddressRPC().DisableAllIPAddressesWithNodeId(this.AdminContext(), &pb.DisableAllIPAddressesWithNodeIdRequest{
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加新的IP地址
|
// 添加新的IP地址
|
||||||
err = ipaddressutils.UpdateNodeIPAddresses(this.Parent(), params.NodeId, params.IPAddressesJSON)
|
err = ipaddressutils.UpdateNodeIPAddresses(this.Parent(), params.NodeId, nodeconfigs.NodeRoleNode, params.IPAddressesJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
// http api
|
// http api
|
||||||
HttpAPIURL string
|
HttpAPIURL string
|
||||||
|
|
||||||
|
// html
|
||||||
|
HtmlContent string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
CSRF *actionutils.CSRF
|
CSRF *actionutils.CSRF
|
||||||
}) {
|
}) {
|
||||||
@@ -90,6 +93,13 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
actionParams = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
actionParams = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
||||||
URL: params.HttpAPIURL,
|
URL: params.HttpAPIURL,
|
||||||
}
|
}
|
||||||
|
case firewallconfigs.FirewallActionTypeHTML:
|
||||||
|
params.Must.
|
||||||
|
Field("htmlContent", params.HtmlContent).
|
||||||
|
Require("请输入HTML内容")
|
||||||
|
actionParams = &firewallconfigs.FirewallActionHTMLConfig{
|
||||||
|
Content: params.HtmlContent,
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
this.Fail("选择的类型'" + params.Type + "'暂时不支持")
|
this.Fail("选择的类型'" + params.Type + "'暂时不支持")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
// http api
|
// http api
|
||||||
HttpAPIURL string
|
HttpAPIURL string
|
||||||
|
|
||||||
|
// HTML内容
|
||||||
|
HtmlContent string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
CSRF *actionutils.CSRF
|
CSRF *actionutils.CSRF
|
||||||
}) {
|
}) {
|
||||||
@@ -119,6 +122,13 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
actionParams = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
actionParams = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
||||||
URL: params.HttpAPIURL,
|
URL: params.HttpAPIURL,
|
||||||
}
|
}
|
||||||
|
case firewallconfigs.FirewallActionTypeHTML:
|
||||||
|
params.Must.
|
||||||
|
Field("htmlContent", params.HtmlContent).
|
||||||
|
Require("请输入HTML内容")
|
||||||
|
actionParams = &firewallconfigs.FirewallActionHTMLConfig{
|
||||||
|
Content: params.HtmlContent,
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
this.Fail("选择的类型'" + params.Type + "'暂时不支持")
|
this.Fail("选择的类型'" + params.Type + "'暂时不支持")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package settings
|
package health
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -9,16 +9,16 @@ import (
|
|||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HealthAction struct {
|
type IndexAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HealthAction) Init() {
|
func (this *IndexAction) Init() {
|
||||||
this.Nav("", "setting", "")
|
this.Nav("", "setting", "")
|
||||||
this.SecondMenu("health")
|
this.SecondMenu("health")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HealthAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
}) {
|
}) {
|
||||||
configResp, err := this.RPC().NodeClusterRPC().FindNodeClusterHealthCheckConfig(this.AdminContext(), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: params.ClusterId})
|
configResp, err := this.RPC().NodeClusterRPC().FindNodeClusterHealthCheckConfig(this.AdminContext(), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: params.ClusterId})
|
||||||
@@ -40,7 +40,7 @@ func (this *HealthAction) RunGet(params struct {
|
|||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HealthAction) RunPost(params struct {
|
func (this *IndexAction) RunPost(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
HealthCheckJSON []byte
|
HealthCheckJSON []byte
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package settings
|
package health
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
@@ -7,20 +7,19 @@ import (
|
|||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HealthRunPopupAction struct {
|
type RunPopupAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HealthRunPopupAction) Init() {
|
func (this *RunPopupAction) Init() {
|
||||||
this.Nav("", "", "")
|
this.Nav("", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HealthRunPopupAction) RunGet(params struct{}) {
|
func (this *RunPopupAction) RunGet(params struct{}) {
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HealthRunPopupAction) RunPost(params struct {
|
func (this *RunPopupAction) RunPost(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -35,13 +35,13 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
// 认证
|
// 认证
|
||||||
var grantMap interface{} = nil
|
var grantMap interface{} = nil
|
||||||
|
|
||||||
if cluster.GrantId > 0 {
|
if cluster.NodeGrantId > 0 {
|
||||||
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: cluster.GrantId})
|
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: cluster.NodeGrantId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
grant := grantResp.Grant
|
grant := grantResp.NodeGrant
|
||||||
if grant != nil {
|
if grant != nil {
|
||||||
grantMap = maps.Map{
|
grantMap = maps.Map{
|
||||||
"id": grant.Id,
|
"id": grant.Id,
|
||||||
@@ -62,7 +62,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存设置
|
// RunPost 保存设置
|
||||||
func (this *IndexAction) RunPost(params struct {
|
func (this *IndexAction) RunPost(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
Name string
|
Name string
|
||||||
@@ -81,7 +81,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
_, err := this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{
|
_, err := this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: params.ClusterId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
GrantId: params.GrantId,
|
NodeGrantId: params.GrantId,
|
||||||
InstallDir: params.InstallDir,
|
InstallDir: params.InstallDir,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/cache"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/cache"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns"
|
||||||
firewallActions "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/firewall-actions"
|
firewallActions "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/firewall-actions"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/health"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/message"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/services"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/services"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/thresholds"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf"
|
||||||
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
||||||
@@ -22,8 +25,8 @@ func init() {
|
|||||||
GetPost("", new(IndexAction)).
|
GetPost("", new(IndexAction)).
|
||||||
|
|
||||||
// 健康检查
|
// 健康检查
|
||||||
GetPost("/health", new(HealthAction)).
|
GetPost("/health", new(health.IndexAction)).
|
||||||
GetPost("/healthRunPopup", new(HealthRunPopupAction)).
|
GetPost("/health/runPopup", new(health.RunPopupAction)).
|
||||||
|
|
||||||
// 缓存
|
// 缓存
|
||||||
GetPost("/cache", new(cache.IndexAction)).
|
GetPost("/cache", new(cache.IndexAction)).
|
||||||
@@ -35,6 +38,12 @@ func init() {
|
|||||||
Prefix("/clusters/cluster/settings/dns").
|
Prefix("/clusters/cluster/settings/dns").
|
||||||
GetPost("", new(dns.IndexAction)).
|
GetPost("", new(dns.IndexAction)).
|
||||||
|
|
||||||
|
// 消息
|
||||||
|
Prefix("/clusters/cluster/settings/message").
|
||||||
|
GetPost("", new(message.IndexAction)).
|
||||||
|
Get("/selectReceiverPopup", new(message.SelectReceiverPopupAction)).
|
||||||
|
Post("/selectedReceivers", new(message.SelectedReceiversAction)).
|
||||||
|
|
||||||
// TOA
|
// TOA
|
||||||
Prefix("/clusters/cluster/settings/toa").
|
Prefix("/clusters/cluster/settings/toa").
|
||||||
GetPost("", new(toa.IndexAction)).
|
GetPost("", new(toa.IndexAction)).
|
||||||
@@ -51,6 +60,13 @@ func init() {
|
|||||||
GetPost("/updatePopup", new(firewallActions.UpdatePopupAction)).
|
GetPost("/updatePopup", new(firewallActions.UpdatePopupAction)).
|
||||||
Post("/delete", new(firewallActions.DeleteAction)).
|
Post("/delete", new(firewallActions.DeleteAction)).
|
||||||
|
|
||||||
|
// 阈值
|
||||||
|
Prefix("/clusters/cluster/settings/thresholds").
|
||||||
|
Get("", new(thresholds.IndexAction)).
|
||||||
|
GetPost("/createPopup", new(thresholds.CreatePopupAction)).
|
||||||
|
GetPost("/updatePopup", new(thresholds.UpdatePopupAction)).
|
||||||
|
Post("/delete", new(thresholds.DeleteAction)).
|
||||||
|
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "setting", "")
|
||||||
|
this.SecondMenu("message")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct{}) {
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
ClusterId int64
|
||||||
|
ReceiversJSON []byte
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改集群 %d 消息接收人", params.ClusterId)
|
||||||
|
|
||||||
|
receiverMaps := []maps.Map{}
|
||||||
|
if len(params.ReceiversJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.ReceiversJSON, &receiverMaps)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pbReceiverOptions := &pb.UpdateMessageReceiversRequest_RecipientOptions{}
|
||||||
|
for _, receiverMap := range receiverMaps {
|
||||||
|
recipientId := int64(0)
|
||||||
|
groupId := int64(0)
|
||||||
|
receiverType := receiverMap.GetString("type")
|
||||||
|
switch receiverType {
|
||||||
|
case "recipient":
|
||||||
|
recipientId = receiverMap.GetInt64("id")
|
||||||
|
case "group":
|
||||||
|
groupId = receiverMap.GetInt64("id")
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pbReceiverOptions.RecipientOptions = append(pbReceiverOptions.RecipientOptions, &pb.UpdateMessageReceiversRequest_RecipientOption{
|
||||||
|
MessageRecipientId: recipientId,
|
||||||
|
MessageRecipientGroupId: groupId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := this.RPC().MessageReceiverRPC().UpdateMessageReceivers(this.AdminContext(), &pb.UpdateMessageReceiversRequest{
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
NodeId: 0,
|
||||||
|
ServerId: 0,
|
||||||
|
ParamsJSON: nil,
|
||||||
|
RecipientOptions: map[string]*pb.UpdateMessageReceiversRequest_RecipientOptions{
|
||||||
|
"*": pbReceiverOptions,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SelectReceiverPopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SelectReceiverPopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SelectReceiverPopupAction) RunGet(params struct {
|
||||||
|
RecipientIds string
|
||||||
|
GroupIds string
|
||||||
|
}) {
|
||||||
|
recipientIds := utils.SplitNumbers(params.RecipientIds)
|
||||||
|
groupIds := utils.SplitNumbers(params.GroupIds)
|
||||||
|
|
||||||
|
// 所有接收人
|
||||||
|
recipientsResp, err := this.RPC().MessageRecipientRPC().ListEnabledMessageRecipients(this.AdminContext(), &pb.ListEnabledMessageRecipientsRequest{
|
||||||
|
AdminId: 0,
|
||||||
|
MediaType: "",
|
||||||
|
MessageRecipientGroupId: 0,
|
||||||
|
Keyword: "",
|
||||||
|
Offset: 0,
|
||||||
|
Size: 1000, // TODO 支持搜索
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recipientMaps := []maps.Map{}
|
||||||
|
for _, recipient := range recipientsResp.MessageRecipients {
|
||||||
|
if !recipient.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if lists.ContainsInt64(recipientIds, recipient.Id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
recipientMaps = append(recipientMaps, maps.Map{
|
||||||
|
"id": recipient.Id,
|
||||||
|
"name": recipient.Admin.Fullname,
|
||||||
|
"instanceName": recipient.MessageMediaInstance.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["recipients"] = recipientMaps
|
||||||
|
|
||||||
|
// 所有分组
|
||||||
|
groupsResp, err := this.RPC().MessageRecipientGroupRPC().FindAllEnabledMessageRecipientGroups(this.AdminContext(), &pb.FindAllEnabledMessageRecipientGroupsRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupMaps := []maps.Map{}
|
||||||
|
for _, group := range groupsResp.MessageRecipientGroups {
|
||||||
|
if !group.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if lists.ContainsInt64(groupIds, group.Id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["groups"] = groupMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SelectedReceiversAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SelectedReceiversAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SelectedReceiversAction) RunPost(params struct {
|
||||||
|
ClusterId int64
|
||||||
|
NodeId int64
|
||||||
|
ServerId int64
|
||||||
|
}) {
|
||||||
|
receiversResp, err := this.RPC().MessageReceiverRPC().FindAllEnabledMessageReceivers(this.AdminContext(), &pb.FindAllEnabledMessageReceiversRequest{
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
ServerId: params.ServerId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
receiverMaps := []maps.Map{}
|
||||||
|
for _, receiver := range receiversResp.MessageReceivers {
|
||||||
|
id := int64(0)
|
||||||
|
name := ""
|
||||||
|
receiverType := ""
|
||||||
|
subName := ""
|
||||||
|
if receiver.MessageRecipient != nil {
|
||||||
|
id = receiver.MessageRecipient.Id
|
||||||
|
name = receiver.MessageRecipient.Admin.Fullname
|
||||||
|
subName = receiver.MessageRecipient.MessageMediaInstance.Name
|
||||||
|
receiverType = "recipient"
|
||||||
|
} else if receiver.MessageRecipientGroup != nil {
|
||||||
|
id = receiver.MessageRecipientGroup.Id
|
||||||
|
name = receiver.MessageRecipientGroup.Name
|
||||||
|
receiverType = "group"
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
receiverMaps = append(receiverMaps, maps.Map{
|
||||||
|
"id": id,
|
||||||
|
"name": name,
|
||||||
|
"subName": subName,
|
||||||
|
"type": receiverType,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["receivers"] = receiverMaps
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package thresholds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreatePopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunGet(params struct {
|
||||||
|
ClusterId int64
|
||||||
|
NodeId int64
|
||||||
|
}) {
|
||||||
|
this.Data["clusterId"] = params.ClusterId
|
||||||
|
this.Data["nodeId"] = params.NodeId
|
||||||
|
this.Data["items"] = nodeconfigs.FindAllNodeValueItemDefinitions()
|
||||||
|
this.Data["operators"] = nodeconfigs.FindAllNodeValueOperatorDefinitions()
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CreatePopupAction) RunPost(params struct {
|
||||||
|
ClusterId int64
|
||||||
|
NodeId int64
|
||||||
|
Item string
|
||||||
|
Param string
|
||||||
|
SumMethod string
|
||||||
|
Operator string
|
||||||
|
Value string
|
||||||
|
Duration int32
|
||||||
|
DurationUnit string
|
||||||
|
Message string
|
||||||
|
NotifyDuration int32
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
if params.ClusterId <= 0 && params.NodeId >= 0 {
|
||||||
|
this.Fail("集群或者节点至少需要填写其中一个参数")
|
||||||
|
}
|
||||||
|
|
||||||
|
valueJSON, err := json.Marshal(params.Value)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, err := this.RPC().NodeThresholdRPC().CreateNodeThreshold(this.AdminContext(), &pb.CreateNodeThresholdRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
NodeId: params.NodeId,
|
||||||
|
Item: params.Item,
|
||||||
|
Param: params.Param,
|
||||||
|
Operator: params.Operator,
|
||||||
|
ValueJSON: valueJSON,
|
||||||
|
Message: params.Message,
|
||||||
|
Duration: params.Duration,
|
||||||
|
DurationUnit: params.DurationUnit,
|
||||||
|
SumMethod: params.SumMethod,
|
||||||
|
NotifyDuration: params.NotifyDuration,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer this.CreateLogInfo("创建节点阈值 %d", resp.NodeThresholdId)
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package thresholds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DeleteAction 删除阈值
|
||||||
|
type DeleteAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DeleteAction) RunPost(params struct {
|
||||||
|
ThresholdId int64
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("删除阈值 %d", params.ThresholdId)
|
||||||
|
|
||||||
|
_, err := this.RPC().NodeThresholdRPC().DeleteNodeThreshold(this.AdminContext(), &pb.DeleteNodeThresholdRequest{NodeThresholdId: params.ThresholdId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package thresholds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "setting", "setting")
|
||||||
|
this.SecondMenu("threshold")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
ClusterId int64
|
||||||
|
}) {
|
||||||
|
// 列出所有阈值
|
||||||
|
thresholdsResp, err := this.RPC().NodeThresholdRPC().FindAllEnabledNodeThresholds(this.AdminContext(), &pb.FindAllEnabledNodeThresholdsRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeClusterId: params.ClusterId,
|
||||||
|
NodeId: 0,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
thresholdMaps := []maps.Map{}
|
||||||
|
for _, threshold := range thresholdsResp.NodeThresholds {
|
||||||
|
var nodeMap maps.Map = nil
|
||||||
|
if threshold.Node != nil {
|
||||||
|
nodeMap = maps.Map{
|
||||||
|
"id": threshold.Node.Id,
|
||||||
|
"name": threshold.Node.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thresholdMaps = append(thresholdMaps, maps.Map{
|
||||||
|
"id": threshold.Id,
|
||||||
|
"itemName": nodeconfigs.FindNodeValueItemName(threshold.Item),
|
||||||
|
"paramName": nodeconfigs.FindNodeValueItemParamName(threshold.Item, threshold.Param),
|
||||||
|
"operatorName": nodeconfigs.FindNodeValueOperatorName(threshold.Operator),
|
||||||
|
"value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON),
|
||||||
|
"sumMethodName": nodeconfigs.FindNodeValueSumMethodName(threshold.SumMethod),
|
||||||
|
"duration": threshold.Duration,
|
||||||
|
"durationUnitName": nodeconfigs.FindNodeValueDurationUnitName(threshold.DurationUnit),
|
||||||
|
"isOn": threshold.IsOn,
|
||||||
|
"node": nodeMap,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["thresholds"] = thresholdMaps
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package thresholds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdatePopupAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdatePopupAction) Init() {
|
||||||
|
this.Nav("", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdatePopupAction) RunGet(params struct {
|
||||||
|
ThresholdId int64
|
||||||
|
}) {
|
||||||
|
// 通用参数
|
||||||
|
this.Data["items"] = nodeconfigs.FindAllNodeValueItemDefinitions()
|
||||||
|
this.Data["operators"] = nodeconfigs.FindAllNodeValueOperatorDefinitions()
|
||||||
|
|
||||||
|
// 阈值详情
|
||||||
|
thresholdResp, err := this.RPC().NodeThresholdRPC().FindEnabledNodeThreshold(this.AdminContext(), &pb.FindEnabledNodeThresholdRequest{NodeThresholdId: params.ThresholdId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
threshold := thresholdResp.NodeThreshold
|
||||||
|
if threshold == nil {
|
||||||
|
this.NotFound("nodeThreshold", params.ThresholdId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
valueInterface := new(interface{})
|
||||||
|
err = json.Unmarshal(threshold.ValueJSON, valueInterface)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["threshold"] = maps.Map{
|
||||||
|
"id": threshold.Id,
|
||||||
|
"item": threshold.Item,
|
||||||
|
"param": threshold.Param,
|
||||||
|
"message": threshold.Message,
|
||||||
|
"notifyDuration": threshold.NotifyDuration,
|
||||||
|
"value": nodeconfigs.UnmarshalNodeValue(threshold.ValueJSON),
|
||||||
|
"operator": threshold.Operator,
|
||||||
|
"duration": threshold.Duration,
|
||||||
|
"durationUnit": threshold.DurationUnit,
|
||||||
|
"isOn": threshold.IsOn,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpdatePopupAction) RunPost(params struct {
|
||||||
|
ThresholdId int64
|
||||||
|
Item string
|
||||||
|
Param string
|
||||||
|
SumMethod string
|
||||||
|
Operator string
|
||||||
|
Value string
|
||||||
|
Duration int32
|
||||||
|
DurationUnit string
|
||||||
|
Message string
|
||||||
|
NotifyDuration int32
|
||||||
|
IsOn bool
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改节点阈值 %d", params.ThresholdId)
|
||||||
|
|
||||||
|
valueJSON, err := json.Marshal(params.Value)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().NodeThresholdRPC().UpdateNodeThreshold(this.AdminContext(), &pb.UpdateNodeThresholdRequest{
|
||||||
|
NodeThresholdId: params.ThresholdId,
|
||||||
|
Item: params.Item,
|
||||||
|
Param: params.Param,
|
||||||
|
Operator: params.Operator,
|
||||||
|
ValueJSON: valueJSON,
|
||||||
|
Message: params.Message,
|
||||||
|
NotifyDuration: params.NotifyDuration,
|
||||||
|
Duration: params.Duration,
|
||||||
|
DurationUnit: params.DurationUnit,
|
||||||
|
SumMethod: params.SumMethod,
|
||||||
|
IsOn: params.IsOn,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -58,17 +58,17 @@ func (this *UpdateNodeSSHAction) RunGet(params struct {
|
|||||||
|
|
||||||
// 认证信息
|
// 认证信息
|
||||||
grantId := loginParams.GetInt64("grantId")
|
grantId := loginParams.GetInt64("grantId")
|
||||||
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: grantId})
|
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
}
|
}
|
||||||
var grantMap maps.Map = nil
|
var grantMap maps.Map = nil
|
||||||
if grantResp.Grant != nil {
|
if grantResp.NodeGrant != nil {
|
||||||
grantMap = maps.Map{
|
grantMap = maps.Map{
|
||||||
"id": grantResp.Grant.Id,
|
"id": grantResp.NodeGrant.Id,
|
||||||
"name": grantResp.Grant.Name,
|
"name": grantResp.NodeGrant.Name,
|
||||||
"method": grantResp.Grant.Method,
|
"method": grantResp.NodeGrant.Method,
|
||||||
"methodName": grantutils.FindGrantMethodName(grantResp.Grant.Method),
|
"methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Data["grant"] = grantMap
|
this.Data["grant"] = grantMap
|
||||||
@@ -108,8 +108,8 @@ func (this *UpdateNodeSSHAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := this.RPC().NodeRPC().UpdateNodeLogin(this.AdminContext(), &pb.UpdateNodeLoginRequest{
|
_, err := this.RPC().NodeRPC().UpdateNodeLogin(this.AdminContext(), &pb.UpdateNodeLoginRequest{
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Login: login,
|
NodeLogin: login,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func (this *UpgradeRemoteAction) RunGet(params struct {
|
|||||||
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "upgrade")
|
this.Data["leftMenuItems"] = LeftMenuItemsForInstall(this.AdminContext(), params.ClusterId, "upgrade")
|
||||||
|
|
||||||
nodes := []maps.Map{}
|
nodes := []maps.Map{}
|
||||||
resp, err := this.RPC().NodeRPC().FindAllUpgradeNodesWithClusterId(this.AdminContext(), &pb.FindAllUpgradeNodesWithClusterIdRequest{NodeClusterId: params.ClusterId})
|
resp, err := this.RPC().NodeRPC().FindAllUpgradeNodesWithNodeClusterId(this.AdminContext(), &pb.FindAllUpgradeNodesWithNodeClusterIdRequest{NodeClusterId: params.ClusterId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 安装升级相关的左侧菜单
|
// LeftMenuItemsForInstall 安装升级相关的左侧菜单
|
||||||
func LeftMenuItemsForInstall(ctx context.Context, clusterId int64, selectedItem string) []maps.Map {
|
func LeftMenuItemsForInstall(ctx context.Context, clusterId int64, selectedItem string) []maps.Map {
|
||||||
rpcClient, _ := rpc.SharedRPC()
|
rpcClient, _ := rpc.SharedRPC()
|
||||||
countNotInstalled := int64(0)
|
countNotInstalled := int64(0)
|
||||||
countUpgrade := int64(0)
|
countUpgrade := int64(0)
|
||||||
if rpcClient != nil {
|
if rpcClient != nil {
|
||||||
{
|
{
|
||||||
resp, err := rpcClient.NodeRPC().CountAllNotInstalledNodesWithClusterId(ctx, &pb.CountAllNotInstalledNodesWithClusterIdRequest{NodeClusterId: clusterId})
|
resp, err := rpcClient.NodeRPC().CountAllNotInstalledNodesWithNodeClusterId(ctx, &pb.CountAllNotInstalledNodesWithNodeClusterIdRequest{NodeClusterId: clusterId})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
countNotInstalled = resp.Count
|
countNotInstalled = resp.Count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
resp, err := rpcClient.NodeRPC().CountAllUpgradeNodesWithClusterId(ctx, &pb.CountAllUpgradeNodesWithClusterIdRequest{NodeClusterId: clusterId})
|
resp, err := rpcClient.NodeRPC().CountAllUpgradeNodesWithNodeClusterId(ctx, &pb.CountAllUpgradeNodesWithNodeClusterIdRequest{NodeClusterId: clusterId})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
countUpgrade = resp.Count
|
countUpgrade = resp.Count
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package clusterutils
|
package clusterutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
@@ -21,10 +24,10 @@ func NewClusterHelper() *ClusterHelper {
|
|||||||
return &ClusterHelper{}
|
return &ClusterHelper{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) {
|
||||||
action := actionPtr.Object()
|
action := actionPtr.Object()
|
||||||
if action.Request.Method != http.MethodGet {
|
if action.Request.Method != http.MethodGet {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
action.Data["teaMenu"] = "clusters"
|
action.Data["teaMenu"] = "clusters"
|
||||||
@@ -64,6 +67,8 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
|||||||
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置菜单
|
// 设置菜单
|
||||||
@@ -86,22 +91,58 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt
|
|||||||
"isActive": selectedItem == "waf",
|
"isActive": selectedItem == "waf",
|
||||||
"isOn": cluster.HttpFirewallPolicyId > 0,
|
"isOn": cluster.HttpFirewallPolicyId > 0,
|
||||||
})
|
})
|
||||||
items = append(items, maps.Map{
|
|
||||||
"name": "WAF动作",
|
{
|
||||||
"url": "/clusters/cluster/settings/firewall-actions?clusterId=" + clusterId,
|
hasActions, _ := this.checkFirewallActions(cluster.Id)
|
||||||
"isActive": selectedItem == "firewallAction",
|
items = append(items, maps.Map{
|
||||||
})
|
"name": "WAF动作",
|
||||||
items = append(items, maps.Map{
|
"url": "/clusters/cluster/settings/firewall-actions?clusterId=" + clusterId,
|
||||||
"name": "健康检查",
|
"isActive": selectedItem == "firewallAction",
|
||||||
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
|
"isOn": hasActions,
|
||||||
"isActive": selectedItem == "health",
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
healthCheckIsOn, _ := this.checkHealthCheckIsOn(cluster.Id)
|
||||||
|
items = append(items, maps.Map{
|
||||||
|
"name": "健康检查",
|
||||||
|
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
|
||||||
|
"isActive": selectedItem == "health",
|
||||||
|
"isOn": healthCheckIsOn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
items = append(items, maps.Map{
|
items = append(items, maps.Map{
|
||||||
"name": "DNS设置",
|
"name": "DNS设置",
|
||||||
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
|
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
|
||||||
"isActive": selectedItem == "dns",
|
"isActive": selectedItem == "dns",
|
||||||
"isOn": cluster.DnsDomainId > 0 || len(cluster.DnsName) > 0,
|
"isOn": cluster.DnsDomainId > 0 || len(cluster.DnsName) > 0,
|
||||||
})
|
})
|
||||||
|
if teaconst.IsPlus {
|
||||||
|
hasThresholds, _ := this.checkThresholds(cluster.Id)
|
||||||
|
items = append(items, maps.Map{
|
||||||
|
"name": "阈值设置",
|
||||||
|
"url": "/clusters/cluster/settings/thresholds?clusterId=" + clusterId,
|
||||||
|
"isActive": selectedItem == "threshold",
|
||||||
|
"isOn": hasThresholds,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if teaconst.IsPlus {
|
||||||
|
hasMessageReceivers, _ := this.checkMessages(cluster.Id)
|
||||||
|
items = append(items, maps.Map{
|
||||||
|
"name": "消息通知",
|
||||||
|
"url": "/clusters/cluster/settings/message?clusterId=" + clusterId,
|
||||||
|
"isActive": selectedItem == "message",
|
||||||
|
"isOn": hasMessageReceivers,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
items = append(items, maps.Map{
|
||||||
|
"name": "-",
|
||||||
|
"url": "",
|
||||||
|
"isActive": false,
|
||||||
|
})
|
||||||
|
|
||||||
items = append(items, maps.Map{
|
items = append(items, maps.Map{
|
||||||
"name": "系统服务",
|
"name": "系统服务",
|
||||||
"url": "/clusters/cluster/settings/services?clusterId=" + clusterId,
|
"url": "/clusters/cluster/settings/services?clusterId=" + clusterId,
|
||||||
@@ -114,3 +155,68 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查健康检查是否开启
|
||||||
|
func (this *ClusterHelper) checkHealthCheckIsOn(clusterId int64) (bool, error) {
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
resp, err := rpcClient.NodeClusterRPC().FindNodeClusterHealthCheckConfig(rpcClient.Context(0), &pb.FindNodeClusterHealthCheckConfigRequest{NodeClusterId: clusterId})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if len(resp.HealthCheckJSON) > 0 {
|
||||||
|
healthCheckConfig := &serverconfigs.HealthCheckConfig{}
|
||||||
|
err = json.Unmarshal(resp.HealthCheckJSON, healthCheckConfig)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return healthCheckConfig.IsOn, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否有WAF动作
|
||||||
|
func (this *ClusterHelper) checkFirewallActions(clusterId int64) (bool, error) {
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
resp, err := rpcClient.NodeClusterFirewallActionRPC().CountAllEnabledNodeClusterFirewallActions(rpcClient.Context(0), &pb.CountAllEnabledNodeClusterFirewallActionsRequest{NodeClusterId: clusterId})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return resp.Count > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查阈值是否已经设置
|
||||||
|
func (this *ClusterHelper) checkThresholds(clusterId int64) (bool, error) {
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
resp, err := rpcClient.NodeThresholdRPC().CountAllEnabledNodeThresholds(rpcClient.Context(0), &pb.CountAllEnabledNodeThresholdsRequest{
|
||||||
|
Role: "node",
|
||||||
|
NodeClusterId: clusterId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return resp.Count > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查消息通知是否已经设置
|
||||||
|
func (this *ClusterHelper) checkMessages(clusterId int64) (bool, error) {
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
resp, err := rpcClient.MessageReceiverRPC().CountAllEnabledMessageReceivers(rpcClient.Context(0), &pb.CountAllEnabledMessageReceiversRequest{
|
||||||
|
NodeClusterId: clusterId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return resp.Count > 0, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
|
|
||||||
createResp, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{
|
createResp, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
GrantId: params.GrantId,
|
NodeGrantId: params.GrantId,
|
||||||
InstallDir: params.InstallDir,
|
InstallDir: params.InstallDir,
|
||||||
DnsDomainId: params.DnsDomainId,
|
DnsDomainId: params.DnsDomainId,
|
||||||
DnsName: params.DnsName,
|
DnsName: params.DnsName,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建SSH认证 %d", createResp.GrantId)
|
defer this.CreateLog(oplogs.LevelInfo, "创建SSH认证 %d", createResp.NodeGrantId)
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user