Compare commits
170 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3674fa2c1 | ||
|
|
a14cbe1319 | ||
|
|
c03c35de88 | ||
|
|
dc6c649af8 | ||
|
|
b0d2bdb0ba | ||
|
|
9239dd9a8b | ||
|
|
07a368a0bd | ||
|
|
b8d6d1c249 | ||
|
|
0f1d6a1ad2 | ||
|
|
37c6928ffc | ||
|
|
7478b6dbe0 | ||
|
|
e3cd6e1441 | ||
|
|
8081d968b6 | ||
|
|
a226eee6ef | ||
|
|
8b5a21e593 | ||
|
|
2c71f6c6be | ||
|
|
1a50b01edf | ||
|
|
05f08eeb4c | ||
|
|
fdc3ebb5c5 | ||
|
|
8f06bccd48 | ||
|
|
16b4eb67d4 | ||
|
|
ffa545cb41 | ||
|
|
f67454d51c | ||
|
|
8ae54c56db | ||
|
|
9a17adcc6f | ||
|
|
4dd6903025 | ||
|
|
085770d0ad | ||
|
|
fbaba7c37d | ||
|
|
d5cea208d2 | ||
|
|
36397adca4 | ||
|
|
4971e25d44 | ||
|
|
150357441d | ||
|
|
c4ee663285 | ||
|
|
8c95b4a9b9 | ||
|
|
32ba919851 | ||
|
|
eb37345e85 | ||
|
|
681e454917 | ||
|
|
7c7b82dee4 | ||
|
|
2ae47af8f0 | ||
|
|
b72d91d0d4 | ||
|
|
56010e7203 | ||
|
|
f658698f7b | ||
|
|
b708b9c6df | ||
|
|
c2908e17fa | ||
|
|
302daab824 | ||
|
|
ec49f238d6 | ||
|
|
3e43a5d866 | ||
|
|
a99d5e68e9 | ||
|
|
28514276ec | ||
|
|
b611427c17 | ||
|
|
ce7a4ead04 | ||
|
|
5fe15a85fd | ||
|
|
ae412909f6 | ||
|
|
c6ed579797 | ||
|
|
b2a525268e | ||
|
|
eb78b4881c | ||
|
|
4ce6e5a9f6 | ||
|
|
15d7e75555 | ||
|
|
6453cc6ccc | ||
|
|
d882a2eb63 | ||
|
|
065ac4aa25 | ||
|
|
dea54fc55e | ||
|
|
8f425bd9c7 | ||
|
|
9d909d73b8 | ||
|
|
b417d50a28 | ||
|
|
aa93a2f702 | ||
|
|
ba7125e773 | ||
|
|
46a7eaa4bb | ||
|
|
887439a6fe | ||
|
|
0e2b07d06d | ||
|
|
b7d4bde11b | ||
|
|
9707360948 | ||
|
|
103a8eb092 | ||
|
|
dcba4f9376 | ||
|
|
12aaa6fcb1 | ||
|
|
d8393481a4 | ||
|
|
70d3202a2c | ||
|
|
c7f1bbc03d | ||
|
|
61a55cb3f4 | ||
|
|
6a484af775 | ||
|
|
3074d41cf2 | ||
|
|
54199058e3 | ||
|
|
87a533791b | ||
|
|
c3109bb2c6 | ||
|
|
031cb836d2 | ||
|
|
aa0a9134cb | ||
|
|
749eac74fe | ||
|
|
ac39908737 | ||
|
|
bb8f4bf488 | ||
|
|
db0d157a74 | ||
|
|
bd8e1bbe71 | ||
|
|
7aba898cf5 | ||
|
|
baf039755f | ||
|
|
70977f7d80 | ||
|
|
884342d6af | ||
|
|
411b0fb4c2 | ||
|
|
8053fb2399 | ||
|
|
ed42dcab9c | ||
|
|
866b5b0f2f | ||
|
|
5834a1a0fa | ||
|
|
8c6d845603 | ||
|
|
667f363f3c | ||
|
|
e209ff38d9 | ||
|
|
ea915993b6 | ||
|
|
72d0468c6a | ||
|
|
35ae13b1c3 | ||
|
|
1d9460f565 | ||
|
|
e9a3ed71b4 | ||
|
|
e344e5b7e6 | ||
|
|
e814064403 | ||
|
|
f5aeb5cbcd | ||
|
|
f41164b892 | ||
|
|
03073c8364 | ||
|
|
a359bff531 | ||
|
|
3789ac6433 | ||
|
|
9f53f59f18 | ||
|
|
521bd746e3 | ||
|
|
3d8e43a42b | ||
|
|
9452e1852d | ||
|
|
3920d24af6 | ||
|
|
3af11e6ba8 | ||
|
|
7bcde46d49 | ||
|
|
0b73041718 | ||
|
|
dcdc0cb8c1 | ||
|
|
ad6ac1aad6 | ||
|
|
249dc6accd | ||
|
|
939e5999ca | ||
|
|
1f91e57d56 | ||
|
|
81e749dc60 | ||
|
|
241b2afda8 | ||
|
|
94cc29f227 | ||
|
|
6d6659eee1 | ||
|
|
5220be0775 | ||
|
|
07ebbf0863 | ||
|
|
b60c767fc5 | ||
|
|
371c3b78c3 | ||
|
|
6a3aa219d5 | ||
|
|
df586ddfdd | ||
|
|
f3b2bbfec0 | ||
|
|
3ea2114798 | ||
|
|
809cf70e0e | ||
|
|
390619535f | ||
|
|
3392ac1fa8 | ||
|
|
b09d94abbe | ||
|
|
03ac01d21f | ||
|
|
12b1d785e5 | ||
|
|
71c58e9d2e | ||
|
|
13c2997a52 | ||
|
|
47b840cac9 | ||
|
|
3f7f243f50 | ||
|
|
1d1e83b18d | ||
|
|
6f3a602c76 | ||
|
|
afb7a4c6a7 | ||
|
|
d0c950d4ca | ||
|
|
63ee7d5211 | ||
|
|
6b0d875745 | ||
|
|
a47a9b9c0c | ||
|
|
27040a3e5c | ||
|
|
c7a8a40e22 | ||
|
|
408de6af63 | ||
|
|
8a324afaa1 | ||
|
|
54bc4cede0 | ||
|
|
4cfbea80b0 | ||
|
|
64cb8286bd | ||
|
|
3e92e0afc6 | ||
|
|
8a91308280 | ||
|
|
3da861d71e | ||
|
|
3566e18e99 | ||
|
|
6e608e627a | ||
|
|
65f7fb979b |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
*_plus.go
|
*_plus.go
|
||||||
*-plus.sh
|
*-plus.sh
|
||||||
|
*_plus.html
|
||||||
|
*_plus.js
|
||||||
*@plus.js
|
*@plus.js
|
||||||
@@ -20,6 +20,18 @@ function build() {
|
|||||||
TAG="community"
|
TAG="community"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# checking environment
|
||||||
|
echo "checking required commands ..."
|
||||||
|
commands=("zip" "unzip" "go" "find" "sed")
|
||||||
|
for cmd in "${commands[@]}"; do
|
||||||
|
if [ `which ${cmd}` ]; then
|
||||||
|
echo "checking ${cmd}: ok"
|
||||||
|
else
|
||||||
|
echo "checking ${cmd}: not found"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
VERSION=$(lookup-version $ROOT/../internal/const/const.go)
|
VERSION=$(lookup-version $ROOT/../internal/const/const.go)
|
||||||
ZIP="${NAME}-${OS}-${ARCH}-${TAG}-v${VERSION}.zip"
|
ZIP="${NAME}-${OS}-${ARCH}-${TAG}-v${VERSION}.zip"
|
||||||
|
|
||||||
@@ -38,6 +50,10 @@ function build() {
|
|||||||
echo "=============================="
|
echo "=============================="
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
|
# generate files
|
||||||
|
echo "generating files ..."
|
||||||
|
go run -tags $TAG $ROOT/../cmd/edge-admin/main.go generate
|
||||||
|
|
||||||
# create dir & copy files
|
# create dir & copy files
|
||||||
echo "copying ..."
|
echo "copying ..."
|
||||||
if [ ! -d $DIST ]; then
|
if [ ! -d $DIST ]; then
|
||||||
@@ -51,6 +67,19 @@ function build() {
|
|||||||
rm -f $DIST/web/tmp/*
|
rm -f $DIST/web/tmp/*
|
||||||
cp $ROOT/configs/server.template.yaml $DIST/configs/
|
cp $ROOT/configs/server.template.yaml $DIST/configs/
|
||||||
|
|
||||||
|
# change _plus.[ext] to .[ext]
|
||||||
|
if [ "${TAG}" = "plus" ]; then
|
||||||
|
echo "converting filenames ..."
|
||||||
|
exts=("html" "js" "css")
|
||||||
|
for ext in "${exts[@]}"; do
|
||||||
|
pattern="*_plus."${ext}
|
||||||
|
find $DIST/web/views -type f -name $pattern | \
|
||||||
|
while read filename; do
|
||||||
|
mv ${filename} "${filename/_plus."${ext}"/."${ext}"}"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
EDGE_API_ZIP_FILE=$ROOT"/../../EdgeAPI/dist/edge-api-${OS}-${ARCH}-${TAG}-v${APINodeVersion}.zip"
|
EDGE_API_ZIP_FILE=$ROOT"/../../EdgeAPI/dist/edge-api-${OS}-${ARCH}-${TAG}-v${APINodeVersion}.zip"
|
||||||
cp $EDGE_API_ZIP_FILE $DIST/
|
cp $EDGE_API_ZIP_FILE $DIST/
|
||||||
cd $DIST/
|
cd $DIST/
|
||||||
@@ -60,13 +89,14 @@ function build() {
|
|||||||
|
|
||||||
# build
|
# build
|
||||||
echo "building "${NAME}" ..."
|
echo "building "${NAME}" ..."
|
||||||
env GOOS=$OS GOARCH=$GOARCH go build -tags $TAG -ldflags="-s -w" -o $DIST/bin/${NAME} $ROOT/../cmd/edge-admin/main.go
|
env GOOS=$OS GOARCH=$ARCH go build -tags $TAG -ldflags="-s -w" -o $DIST/bin/${NAME} $ROOT/../cmd/edge-admin/main.go
|
||||||
|
|
||||||
# delete hidden files
|
# delete hidden files
|
||||||
find $DIST -name ".DS_Store" -delete
|
find $DIST -name ".DS_Store" -delete
|
||||||
find $DIST -name ".gitignore" -delete
|
find $DIST -name ".gitignore" -delete
|
||||||
find $DIST -name "*.less" -delete
|
find $DIST -name "*.less" -delete
|
||||||
find $DIST -name "*.css.map" -delete
|
find $DIST -name "*.css.map" -delete
|
||||||
|
find $DIST -name "*.js.map" -delete
|
||||||
|
|
||||||
# zip
|
# zip
|
||||||
echo "zip files ..."
|
echo "zip files ..."
|
||||||
|
|||||||
3
build/generate.sh
Executable file
3
build/generate.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
go run -tags=community ../cmd/edge-admin/main.go generate
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/apps"
|
"github.com/TeaOSLab/EdgeAdmin/internal/apps"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
"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/gen"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
|
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
@@ -70,6 +71,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
fmt.Println("change demo mode successfully")
|
fmt.Println("change demo mode successfully")
|
||||||
})
|
})
|
||||||
|
app.On("generate", func() {
|
||||||
|
err := gen.Generate()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("generate failed: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
app.Run(func() {
|
app.Run(func() {
|
||||||
adminNode := nodes.NewAdminNode()
|
adminNode := nodes.NewAdminNode()
|
||||||
adminNode.Run()
|
adminNode.Run()
|
||||||
|
|||||||
6
go.mod
6
go.mod
@@ -10,9 +10,11 @@ require (
|
|||||||
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/google/go-cmp v0.5.6 // indirect
|
github.com/google/go-cmp v0.5.6 // indirect
|
||||||
github.com/iwind/TeaGo v0.0.0-20210720011303-fc255c995afa
|
github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24
|
||||||
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3
|
github.com/iwind/gosock v0.0.0-20211103081026-ee4652210ca4
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/miekg/dns v1.1.35
|
github.com/miekg/dns v1.1.35
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
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
|
||||||
|
|||||||
14
go.sum
14
go.sum
@@ -62,12 +62,18 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
|
|||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
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-20210628135026-38575a4ab060/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20210628135026-38575a4ab060/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/iwind/TeaGo v0.0.0-20210720011303-fc255c995afa h1:woN88uEmRRUNFD7pRZEtX9heDcjFn0ClMxjF5ButKow=
|
github.com/iwind/TeaGo v0.0.0-20210831140440-a2a442471b13 h1:HuEJ5xJfujW1Q6rNDhOu5LQXEBB2qLPah3jYslT8Gz4=
|
||||||
github.com/iwind/TeaGo v0.0.0-20210720011303-fc255c995afa/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20210831140440-a2a442471b13/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
|
github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24 h1:1cGulkD2SNJJRok5OKwyhP/Ddm+PgSWKOupn0cR36/A=
|
||||||
|
github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3 h1:aBSonas7vFcgTj9u96/bWGILGv1ZbUSTLiOzcI1ZT6c=
|
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3 h1:aBSonas7vFcgTj9u96/bWGILGv1ZbUSTLiOzcI1ZT6c=
|
||||||
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA=
|
github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA=
|
||||||
|
github.com/iwind/gosock v0.0.0-20211103081026-ee4652210ca4 h1:VWGsCqTzObdlbf7UUE3oceIpcEKi4C/YBUszQXk118A=
|
||||||
|
github.com/iwind/gosock v0.0.0-20211103081026-ee4652210ca4/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA=
|
||||||
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/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
@@ -77,8 +83,12 @@ 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 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/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||||
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.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
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=
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
AdminModuleCodeAdmin AdminModuleCode = "admin" // 系统用户
|
AdminModuleCodeAdmin AdminModuleCode = "admin" // 系统用户
|
||||||
AdminModuleCodeUser AdminModuleCode = "user" // 平台用户
|
AdminModuleCodeUser AdminModuleCode = "user" // 平台用户
|
||||||
AdminModuleCodeFinance AdminModuleCode = "finance" // 财务
|
AdminModuleCodeFinance AdminModuleCode = "finance" // 财务
|
||||||
|
AdminModuleCodePlan AdminModuleCode = "plan" // 套餐
|
||||||
AdminModuleCodeLog AdminModuleCode = "log" // 日志
|
AdminModuleCodeLog AdminModuleCode = "log" // 日志
|
||||||
AdminModuleCodeSetting AdminModuleCode = "setting" // 设置
|
AdminModuleCodeSetting AdminModuleCode = "setting" // 设置
|
||||||
AdminModuleCodeCommon AdminModuleCode = "common" // 只要登录就可以访问的模块
|
AdminModuleCodeCommon AdminModuleCode = "common" // 只要登录就可以访问的模块
|
||||||
@@ -203,6 +204,11 @@ func AllModuleMaps() []maps.Map {
|
|||||||
"code": AdminModuleCodeFinance,
|
"code": AdminModuleCodeFinance,
|
||||||
"url": "/finance",
|
"url": "/finance",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "套餐管理",
|
||||||
|
"code": AdminModuleCodePlan,
|
||||||
|
"url": "/plans",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "日志审计",
|
"name": "日志审计",
|
||||||
"code": AdminModuleCodeLog,
|
"code": AdminModuleCodeLog,
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ import (
|
|||||||
var plusConfigFile = "plus.cache.json"
|
var plusConfigFile = "plus.cache.json"
|
||||||
|
|
||||||
type PlusConfig struct {
|
type PlusConfig struct {
|
||||||
IsPlus bool `json:"isPlus"`
|
IsPlus bool `json:"isPlus"`
|
||||||
|
Components []string `json:"components"`
|
||||||
|
DayTo string `json:"dayTo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadPlusConfig() *PlusConfig {
|
func ReadPlusConfig() *PlusConfig {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.3.2"
|
Version = "0.3.7"
|
||||||
|
|
||||||
APINodeVersion = "0.3.2"
|
APINodeVersion = "0.3.7"
|
||||||
|
|
||||||
ProductName = "Edge Admin"
|
ProductName = "Edge Admin"
|
||||||
ProcessName = "edge-admin"
|
ProcessName = "edge-admin"
|
||||||
@@ -18,4 +18,5 @@ const (
|
|||||||
CookieSID = "edgesid"
|
CookieSID = "edgesid"
|
||||||
|
|
||||||
SystemdServiceName = "edge-admin"
|
SystemdServiceName = "edge-admin"
|
||||||
|
UpdatesURL = "https://goedge.cn/api/boot/versions?os=${os}&arch=${arch}"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
//go:build community
|
||||||
|
// +build community
|
||||||
|
|
||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
// IsPlus 是否为企业版
|
|
||||||
var IsPlus = false
|
var IsPlus = false
|
||||||
|
|||||||
129
internal/gen/generate.go
Normal file
129
internal/gen/generate.go
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/files"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Generate() error {
|
||||||
|
err := generateComponentsJSFile()
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("generate 'components.js' failed: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成Javascript文件
|
||||||
|
func generateComponentsJSFile() error {
|
||||||
|
var buffer = bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
|
var webRoot string
|
||||||
|
if Tea.IsTesting() {
|
||||||
|
webRoot = Tea.Root + "/../web/public/js/components/"
|
||||||
|
} else {
|
||||||
|
webRoot = Tea.Root + "/web/public/js/components/"
|
||||||
|
}
|
||||||
|
f := files.NewFile(webRoot)
|
||||||
|
|
||||||
|
f.Range(func(file *files.File) {
|
||||||
|
if !file.IsFile() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if file.Ext() != ".js" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := file.ReadAll()
|
||||||
|
if err != nil {
|
||||||
|
logs.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
buffer.Write(data)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
})
|
||||||
|
|
||||||
|
// 条件组件
|
||||||
|
typesJSON, err := json.Marshal(condutils.ReadAllAvailableCondTypes())
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("ComponentsAction marshal request cond types failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("window.REQUEST_COND_COMPONENTS = ")
|
||||||
|
buffer.Write(typesJSON)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 条件操作符
|
||||||
|
requestOperatorsJSON, err := json.Marshal(shared.AllRequestOperators())
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("ComponentsAction marshal request operators failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("window.REQUEST_COND_OPERATORS = ")
|
||||||
|
buffer.Write(requestOperatorsJSON)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求变量
|
||||||
|
requestVariablesJSON, err := json.Marshal(shared.DefaultRequestVariables())
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("ComponentsAction marshal request variables failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("window.REQUEST_VARIABLES = ")
|
||||||
|
buffer.Write(requestVariablesJSON)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指标
|
||||||
|
metricHTTPKeysJSON, err := json.Marshal(serverconfigs.FindAllMetricKeyDefinitions(serverconfigs.MetricItemCategoryHTTP))
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("ComponentsAction marshal metric http keys failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("window.METRIC_HTTP_KEYS = ")
|
||||||
|
buffer.Write(metricHTTPKeysJSON)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP地址阈值项目
|
||||||
|
ipAddrThresholdItemsJSON, err := json.Marshal(nodeconfigs.FindAllIPAddressThresholdItems())
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("ComponentsAction marshal ip addr threshold items failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("window.IP_ADDR_THRESHOLD_ITEMS = ")
|
||||||
|
buffer.Write(ipAddrThresholdItemsJSON)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP地址阈值动作
|
||||||
|
ipAddrThresholdActionsJSON, err := json.Marshal(nodeconfigs.FindAllIPAddressThresholdActions())
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("ComponentsAction marshal ip addr threshold actions failed: " + err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("window.IP_ADDR_THRESHOLD_ACTIONS = ")
|
||||||
|
buffer.Write(ipAddrThresholdActionsJSON)
|
||||||
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
|
}
|
||||||
|
|
||||||
|
fp, err := os.OpenFile(filepath.Clean(Tea.PublicFile("/js/components.js")), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(fp, buffer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
13
internal/gen/generate_test.go
Normal file
13
internal/gen/generate_test.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestGenerate(t *testing.T) {
|
||||||
|
err := Generate()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
@@ -326,6 +326,16 @@ func (this *AdminNode) listenSock() error {
|
|||||||
case "demo":
|
case "demo":
|
||||||
teaconst.IsDemoMode = !teaconst.IsDemoMode
|
teaconst.IsDemoMode = !teaconst.IsDemoMode
|
||||||
_ = cmd.ReplyOk()
|
_ = cmd.ReplyOk()
|
||||||
|
case "info":
|
||||||
|
exePath, _ := os.Executable()
|
||||||
|
_ = cmd.Reply(&gosock.Command{
|
||||||
|
Code: "info",
|
||||||
|
Params: map[string]interface{}{
|
||||||
|
"pid": os.Getpid(),
|
||||||
|
"version": teaconst.Version,
|
||||||
|
"path": exePath,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ type RPCClient struct {
|
|||||||
apiConfig *configs.APIConfig
|
apiConfig *configs.APIConfig
|
||||||
conns []*grpc.ClientConn
|
conns []*grpc.ClientConn
|
||||||
|
|
||||||
locker sync.Mutex
|
locker sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRPCClient 构造新的RPC客户端
|
// NewRPCClient 构造新的RPC客户端
|
||||||
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
func NewRPCClient(apiConfig *configs.APIConfig, isPrimary bool) (*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")
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,9 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置RPC
|
// 设置RPC
|
||||||
dao.SetRPC(client)
|
if isPrimary {
|
||||||
|
dao.SetRPC(client)
|
||||||
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
@@ -380,6 +382,18 @@ func (this *RPCClient) UserBillRPC() pb.UserBillServiceClient {
|
|||||||
return pb.NewUserBillServiceClient(this.pickConn())
|
return pb.NewUserBillServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccountRPC() pb.UserAccountServiceClient {
|
||||||
|
return pb.NewUserAccountServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccountLogRPC() pb.UserAccountLogServiceClient {
|
||||||
|
return pb.NewUserAccountLogServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserAccountDailyStatRPC() pb.UserAccountDailyStatServiceClient {
|
||||||
|
return pb.NewUserAccountDailyStatServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) UserAccessKeyRPC() pb.UserAccessKeyServiceClient {
|
func (this *RPCClient) UserAccessKeyRPC() pb.UserAccessKeyServiceClient {
|
||||||
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
return pb.NewUserAccessKeyServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
@@ -464,6 +478,14 @@ func (this *RPCClient) ServerStatBoardChartRPC() pb.ServerStatBoardChartServiceC
|
|||||||
return pb.NewServerStatBoardChartServiceClient(this.pickConn())
|
return pb.NewServerStatBoardChartServiceClient(this.pickConn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) PlanRPC() pb.PlanServiceClient {
|
||||||
|
return pb.NewPlanServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) UserPlanRPC() pb.UserPlanServiceClient {
|
||||||
|
return pb.NewUserPlanServiceClient(this.pickConn())
|
||||||
|
}
|
||||||
|
|
||||||
// Context 构造Admin上下文
|
// Context 构造Admin上下文
|
||||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@@ -513,7 +535,11 @@ func (this *RPCClient) APIContext(apiNodeId int64) context.Context {
|
|||||||
// UpdateConfig 修改配置
|
// UpdateConfig 修改配置
|
||||||
func (this *RPCClient) UpdateConfig(config *configs.APIConfig) error {
|
func (this *RPCClient) UpdateConfig(config *configs.APIConfig) error {
|
||||||
this.apiConfig = config
|
this.apiConfig = config
|
||||||
return this.init()
|
|
||||||
|
this.locker.Lock()
|
||||||
|
err := this.init()
|
||||||
|
this.locker.Unlock()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
@@ -591,3 +617,20 @@ func (this *RPCClient) pickConn() *grpc.ClientConn {
|
|||||||
|
|
||||||
return this.conns[rands.Int(0, len(this.conns)-1)]
|
return this.conns[rands.Int(0, len(this.conns)-1)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close 关闭
|
||||||
|
func (this *RPCClient) Close() error {
|
||||||
|
this.locker.Lock()
|
||||||
|
defer this.locker.Unlock()
|
||||||
|
|
||||||
|
var lastErr error
|
||||||
|
for _, conn := range this.conns {
|
||||||
|
var err = conn.Close()
|
||||||
|
if err != nil {
|
||||||
|
lastErr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastErr
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestRPCClient_NodeRPC(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
rpc, err := NewRPCClient(config)
|
rpc, err := NewRPCClient(config, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ func TestRPC_Dial_HTTP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
||||||
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
||||||
})
|
}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ func TestRPC_Dial_HTTP_2(t *testing.T) {
|
|||||||
},
|
},
|
||||||
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
||||||
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
||||||
})
|
}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ func TestRPC_Dial_HTTPS(t *testing.T) {
|
|||||||
},
|
},
|
||||||
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
NodeId: "a7e55782dab39bce0901058a1e14a0e6",
|
||||||
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y",
|
||||||
})
|
}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func SharedRPC() (*RPCClient, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client, err := NewRPCClient(config)
|
client, err := NewRPCClient(config, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package setup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var isConfigured bool
|
var isConfigured bool
|
||||||
@@ -16,3 +18,16 @@ func IsConfigured() bool {
|
|||||||
isConfigured = err == nil
|
isConfigured = err == nil
|
||||||
return isConfigured
|
return isConfigured
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNewInstalled IsNew 检查是否新安装
|
||||||
|
func IsNewInstalled() bool {
|
||||||
|
homeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
_, err = os.Stat(homeDir + "/." + teaconst.ProcessName + "/api.yaml")
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newEndpoints := []string{}
|
newEndpoints := []string{}
|
||||||
for _, node := range resp.Nodes {
|
for _, node := range resp.ApiNodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (this *SyncClusterTask) loop() error {
|
|||||||
}
|
}
|
||||||
ctx := rpcClient.Context(0)
|
ctx := rpcClient.Context(0)
|
||||||
|
|
||||||
tasksResp, err := rpcClient.NodeTaskRPC().FindNotifyingNodeTasks(ctx, &pb.FindNotifyingNodeTasksRequest{Size: 100})
|
tasksResp, err := rpcClient.NodeTaskRPC().FindNotifyingNodeTasks(ctx, &pb.FindNotifyingNodeTasksRequest{Size: 500})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 将IP转换为整型
|
// IP2Long 将IP转换为整型
|
||||||
func IP2Long(ip string) uint64 {
|
func IP2Long(ip string) uint64 {
|
||||||
s := net.ParseIP(ip)
|
s := net.ParseIP(ip)
|
||||||
if len(s) != 16 {
|
if len(s) != 16 {
|
||||||
@@ -23,7 +26,7 @@ func IP2Long(ip string) uint64 {
|
|||||||
return uint64(binary.BigEndian.Uint32(s.To4()))
|
return uint64(binary.BigEndian.Uint32(s.To4()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否为IPv4
|
// IsIPv4 判断是否为IPv4
|
||||||
func IsIPv4(ip string) bool {
|
func IsIPv4(ip string) bool {
|
||||||
if !regexp.MustCompile(`^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$`).MatchString(ip) {
|
if !regexp.MustCompile(`^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$`).MatchString(ip) {
|
||||||
return false
|
return false
|
||||||
@@ -34,10 +37,100 @@ func IsIPv4(ip string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否为IPv6
|
// IsIPv6 判断是否为IPv6
|
||||||
func IsIPv6(ip string) bool {
|
func IsIPv6(ip string) bool {
|
||||||
if !strings.Contains(ip, ":") {
|
if !strings.Contains(ip, ":") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return len(net.ParseIP(ip)) == net.IPv6len
|
return len(net.ParseIP(ip)) == net.IPv6len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExtractIP 分解IP
|
||||||
|
// 只支持D段掩码的CIDR
|
||||||
|
// 最多只记录255个值
|
||||||
|
func ExtractIP(ipStrings string) ([]string, error) {
|
||||||
|
ipStrings = strings.ReplaceAll(ipStrings, " ", "")
|
||||||
|
|
||||||
|
// CIDR
|
||||||
|
if strings.Contains(ipStrings, "/") {
|
||||||
|
_, cidrNet, err := net.ParseCIDR(ipStrings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var index = strings.Index(ipStrings, "/")
|
||||||
|
var ipFrom = ipStrings[:index]
|
||||||
|
var bits = types.Int(ipStrings[index+1:])
|
||||||
|
if bits < 24 {
|
||||||
|
return nil, errors.New("CIDR bits should be greater than 24")
|
||||||
|
}
|
||||||
|
|
||||||
|
var ipv4 = net.ParseIP(ipFrom).To4()
|
||||||
|
if len(ipv4) == 0 {
|
||||||
|
return nil, errors.New("support IPv4 only")
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = []string{}
|
||||||
|
ipv4[3] = 0 // 从0开始
|
||||||
|
for i := 0; i <= 255; i++ {
|
||||||
|
if cidrNet.Contains(ipv4) {
|
||||||
|
result = append(result, ipv4.String())
|
||||||
|
}
|
||||||
|
ipv4 = NextIP(ipv4)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP Range
|
||||||
|
if strings.Contains(ipStrings, "-") {
|
||||||
|
var index = strings.Index(ipStrings, "-")
|
||||||
|
var ipFromString = ipStrings[:index]
|
||||||
|
var ipToString = ipStrings[index+1:]
|
||||||
|
|
||||||
|
var ipFrom = net.ParseIP(ipFromString).To4()
|
||||||
|
if len(ipFrom) == 0 {
|
||||||
|
return nil, errors.New("invalid ip '" + ipFromString + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
var ipTo = net.ParseIP(ipToString).To4()
|
||||||
|
if len(ipTo) == 0 {
|
||||||
|
return nil, errors.New("invalid ip '" + ipToString + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
if bytes.Compare(ipFrom, ipTo) > 0 {
|
||||||
|
ipFrom, ipTo = ipTo, ipFrom
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = []string{}
|
||||||
|
for i := 0; i < 255; i++ {
|
||||||
|
if bytes.Compare(ipFrom, ipTo) > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
result = append(result, ipFrom.String())
|
||||||
|
ipFrom = NextIP(ipFrom)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{ipStrings}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NextIP IP增加1
|
||||||
|
func NextIP(prevIP net.IP) net.IP {
|
||||||
|
var ip = make(net.IP, len(prevIP))
|
||||||
|
copy(ip, prevIP)
|
||||||
|
var index = len(ip) - 1
|
||||||
|
for {
|
||||||
|
if ip[index] == 255 {
|
||||||
|
ip[index] = 0
|
||||||
|
index--
|
||||||
|
if index < 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ip[index]++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -83,3 +84,27 @@ func TestIsIPv6(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExtractIP(t *testing.T) {
|
||||||
|
t.Log(ExtractIP("192.168.1.100"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractIP_CIDR(t *testing.T) {
|
||||||
|
t.Log(ExtractIP("192.168.2.100/24"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractIP_Range(t *testing.T) {
|
||||||
|
t.Log(ExtractIP("192.168.2.100 - 192.168.4.2"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNextIP(t *testing.T) {
|
||||||
|
for _, ip := range []string{"192.168.1.1", "0.0.0.0", "255.255.255.255", "192.168.2.255", "192.168.255.255"} {
|
||||||
|
t.Log(ip+":", NextIP(net.ParseIP(ip).To4()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNextIP_Copy(t *testing.T) {
|
||||||
|
var ip = net.ParseIP("192.168.1.100")
|
||||||
|
var nextIP = NextIP(ip)
|
||||||
|
t.Log(ip, nextIP)
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,13 +17,19 @@ func LookupCNAME(host string) (string, error) {
|
|||||||
|
|
||||||
m.SetQuestion(host+".", dns.TypeCNAME)
|
m.SetQuestion(host+".", dns.TypeCNAME)
|
||||||
m.RecursionDesired = true
|
m.RecursionDesired = true
|
||||||
r, _, err := c.Exchange(m, config.Servers[0]+":"+config.Port)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if len(r.Answer) == 0 {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.Answer[0].(*dns.CNAME).Target, nil
|
var lastErr error
|
||||||
|
for _, serverAddr := range config.Servers {
|
||||||
|
r, _, err := c.Exchange(m, configutils.QuoteIP(serverAddr)+":"+config.Port)
|
||||||
|
if err != nil {
|
||||||
|
lastErr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(r.Answer) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Answer[0].(*dns.CNAME).Target, nil
|
||||||
|
}
|
||||||
|
return "", lastErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,38 +13,30 @@ func FormatInt(value int) string {
|
|||||||
return strconv.Itoa(value)
|
return strconv.Itoa(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatBytes(bytes int64) string {
|
func Pow1024(n int) int64 {
|
||||||
if bytes < 1024 {
|
if n <= 0 {
|
||||||
return FormatInt64(bytes) + "B"
|
return 1
|
||||||
} else if bytes < 1024*1024 {
|
|
||||||
return fmt.Sprintf("%.2fKB", float64(bytes)/1024)
|
|
||||||
} else if bytes < 1024*1024*1024 {
|
|
||||||
return fmt.Sprintf("%.2fMB", float64(bytes)/1024/1024)
|
|
||||||
} else if bytes < 1024*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 {
|
|
||||||
return fmt.Sprintf("%.2fEB", float64(bytes)/1024/1024/1024/1024/1024/1024)
|
|
||||||
}
|
}
|
||||||
|
if n == 1 {
|
||||||
|
return 1024
|
||||||
|
}
|
||||||
|
return Pow1024(n-1) * 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatBits(bits int64) string {
|
func FormatBytes(bytes int64) string {
|
||||||
if bits < 1000 {
|
if bytes < Pow1024(1) {
|
||||||
return FormatInt64(bits) + "B"
|
return FormatInt64(bytes) + "B"
|
||||||
} else if bits < 1000*1000 {
|
} else if bytes < Pow1024(2) {
|
||||||
return fmt.Sprintf("%.2fKB", float64(bits)/1000)
|
return fmt.Sprintf("%.2fKB", float64(bytes)/float64(Pow1024(1)))
|
||||||
} else if bits < 1000*1000*1000 {
|
} else if bytes < Pow1024(3) {
|
||||||
return fmt.Sprintf("%.2fMB", float64(bits)/1000/1000)
|
return fmt.Sprintf("%.2fMB", float64(bytes)/float64(Pow1024(2)))
|
||||||
} else if bits < 1000*1000*1000*1000 {
|
} else if bytes < Pow1024(4) {
|
||||||
return fmt.Sprintf("%.2fGB", float64(bits)/1000/1000/1000)
|
return fmt.Sprintf("%.2fGB", float64(bytes)/float64(Pow1024(3)))
|
||||||
} else if bits < 1000*1000*1000*1000*1000 {
|
} else if bytes < Pow1024(5) {
|
||||||
return fmt.Sprintf("%.2fTB", float64(bits)/1000/1000/1000/1000)
|
return fmt.Sprintf("%.2fTB", float64(bytes)/float64(Pow1024(4)))
|
||||||
} else if bits < 1000*1000*1000*1000*1000*1000 {
|
} else if bytes < Pow1024(6) {
|
||||||
return fmt.Sprintf("%.2fPB", float64(bits)/1000/1000/1000/1000/1000)
|
return fmt.Sprintf("%.2fPB", float64(bytes)/float64(Pow1024(5)))
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("%.2fEB", float64(bits)/1000/1000/1000/1000/1000/1000)
|
return fmt.Sprintf("%.2fEB", float64(bytes)/float64(Pow1024(6)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
internal/utils/numberutils/utils_test.go
Normal file
16
internal/utils/numberutils/utils_test.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package numberutils
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestFormatBytes(t *testing.T) {
|
||||||
|
t.Log(FormatBytes(1))
|
||||||
|
t.Log(FormatBytes(1000))
|
||||||
|
t.Log(FormatBytes(1_000_000))
|
||||||
|
t.Log(FormatBytes(1_000_000_000))
|
||||||
|
t.Log(FormatBytes(1_000_000_000_000))
|
||||||
|
t.Log(FormatBytes(1_000_000_000_000_000))
|
||||||
|
t.Log(FormatBytes(1_000_000_000_000_000_000))
|
||||||
|
t.Log(FormatBytes(9_000_000_000_000_000_000))
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@ type ParentAction struct {
|
|||||||
actions.ActionObject
|
actions.ActionObject
|
||||||
|
|
||||||
rpcClient *rpc.RPCClient
|
rpcClient *rpc.RPCClient
|
||||||
|
|
||||||
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent 可以调用自身的一个简便方法
|
// Parent 可以调用自身的一个简便方法
|
||||||
@@ -117,6 +119,10 @@ func (this *ParentAction) RPC() *rpc.RPCClient {
|
|||||||
|
|
||||||
// AdminContext 获取Context
|
// AdminContext 获取Context
|
||||||
func (this *ParentAction) AdminContext() context.Context {
|
func (this *ParentAction) AdminContext() context.Context {
|
||||||
|
if this.ctx != nil {
|
||||||
|
return this.ctx
|
||||||
|
}
|
||||||
|
|
||||||
if this.rpcClient == nil {
|
if this.rpcClient == nil {
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,7 +131,8 @@ func (this *ParentAction) AdminContext() context.Context {
|
|||||||
}
|
}
|
||||||
this.rpcClient = rpcClient
|
this.rpcClient = rpcClient
|
||||||
}
|
}
|
||||||
return this.rpcClient.Context(this.AdminId())
|
this.ctx = this.rpcClient.Context(this.AdminId())
|
||||||
|
return this.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
// ViewData 视图里可以使用的数据
|
// ViewData 视图里可以使用的数据
|
||||||
|
|||||||
@@ -13,16 +13,35 @@ type DeleteAction struct {
|
|||||||
func (this *DeleteAction) RunPost(params struct {
|
func (this *DeleteAction) RunPost(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
// TODO 检查权限
|
// 创建日志
|
||||||
|
defer this.CreateLog(oplogs.LevelInfo, "删除API节点 %d", params.NodeId)
|
||||||
|
|
||||||
_, err := this.RPC().APINodeRPC().DeleteAPINode(this.AdminContext(), &pb.DeleteAPINodeRequest{NodeId: params.NodeId})
|
// 检查是否是唯一的节点
|
||||||
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var apiNode = nodeResp.ApiNode
|
||||||
|
if apiNode == nil {
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
if apiNode.IsOn {
|
||||||
|
countResp, err := this.RPC().APINodeRPC().CountAllEnabledAndOnAPINodes(this.AdminContext(), &pb.CountAllEnabledAndOnAPINodesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if countResp.Count == 1 {
|
||||||
|
this.Fail("无法删除此节点:必须保留至少一个可用的API节点")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().APINodeRPC().DeleteAPINode(this.AdminContext(), &pb.DeleteAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除API节点 %d", params.NodeId)
|
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.ApiNodes {
|
||||||
// 状态
|
// 状态
|
||||||
status := &nodeconfigs.NodeStatus{}
|
status := &nodeconfigs.NodeStatus{}
|
||||||
if len(node.StatusJSON) > 0 {
|
if len(node.StatusJSON) > 0 {
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建API节点 %d", createResp.NodeId)
|
defer this.CreateLog(oplogs.LevelInfo, "创建API节点 %d", createResp.ApiNodeId)
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := nodeResp.Node
|
node := nodeResp.ApiNode
|
||||||
if node == nil {
|
if node == nil {
|
||||||
this.NotFound("apiNode", params.NodeId)
|
this.NotFound("apiNode", params.NodeId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
// API节点信息
|
// API节点信息
|
||||||
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := nodeResp.Node
|
node := nodeResp.ApiNode
|
||||||
if node == nil {
|
if node == nil {
|
||||||
this.NotFound("apiNode", params.NodeId)
|
this.NotFound("apiNode", params.NodeId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
this.Data["keyword"] = params.Keyword
|
this.Data["keyword"] = params.Keyword
|
||||||
this.Data["level"] = params.Level
|
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{ApiNodeId: params.NodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNode := apiNodeResp.Node
|
apiNode := apiNodeResp.ApiNode
|
||||||
if apiNode == nil {
|
if apiNode == nil {
|
||||||
this.NotFound("apiNode", params.NodeId)
|
this.NotFound("apiNode", params.NodeId)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
NodeId int64
|
NodeId int64
|
||||||
}) {
|
}) {
|
||||||
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{
|
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{
|
||||||
NodeId: params.NodeId,
|
ApiNodeId: params.NodeId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node := nodeResp.Node
|
node := nodeResp.ApiNode
|
||||||
if node == nil {
|
if node == nil {
|
||||||
this.WriteString("要操作的节点不存在")
|
this.WriteString("要操作的节点不存在")
|
||||||
return
|
return
|
||||||
@@ -281,7 +281,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().APINodeRPC().UpdateAPINode(this.AdminContext(), &pb.UpdateAPINodeRequest{
|
_, err = this.RPC().APINodeRPC().UpdateAPINode(this.AdminContext(), &pb.UpdateAPINodeRequest{
|
||||||
NodeId: params.NodeId,
|
ApiNodeId: params.NodeId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
HttpJSON: httpJSON,
|
HttpJSON: httpJSON,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cluster
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"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"
|
||||||
@@ -75,7 +76,7 @@ func (this *CreateNodeAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
@@ -167,9 +168,13 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
nodeId := createResp.NodeId
|
nodeId := createResp.NodeId
|
||||||
|
|
||||||
// IP地址
|
// IP地址
|
||||||
|
var resultIPAddresses = []string{}
|
||||||
for _, addr := range ipAddresses {
|
for _, addr := range ipAddresses {
|
||||||
|
var resultAddrIds = []int64{}
|
||||||
|
|
||||||
addrId := addr.GetInt64("id")
|
addrId := addr.GetInt64("id")
|
||||||
if addrId > 0 {
|
if addrId > 0 {
|
||||||
|
resultAddrIds = append(resultAddrIds, addrId)
|
||||||
_, err = this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressNodeId(this.AdminContext(), &pb.UpdateNodeIPAddressNodeIdRequest{
|
_, err = this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressNodeId(this.AdminContext(), &pb.UpdateNodeIPAddressNodeIdRequest{
|
||||||
NodeIPAddressId: addrId,
|
NodeIPAddressId: addrId,
|
||||||
NodeId: nodeId,
|
NodeId: nodeId,
|
||||||
@@ -178,20 +183,50 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultIPAddresses = append(resultIPAddresses, addr.GetString("ip"))
|
||||||
} else {
|
} else {
|
||||||
createResp, err := this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
var ipStrings = addr.GetString("ip")
|
||||||
NodeId: nodeId,
|
result, err := utils.ExtractIP(ipStrings)
|
||||||
Role: nodeconfigs.NodeRoleNode,
|
|
||||||
Name: addr.GetString("name"),
|
|
||||||
Ip: addr.GetString("ip"),
|
|
||||||
CanAccess: addr.GetBool("canAccess"),
|
|
||||||
IsUp: addr.GetBool("isUp"),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.Fail("节点创建成功,但是保存IP失败:" + err.Error())
|
||||||
return
|
}
|
||||||
|
|
||||||
|
resultIPAddresses = append(resultIPAddresses, result...)
|
||||||
|
|
||||||
|
if len(result) == 1 {
|
||||||
|
// 单个创建
|
||||||
|
createResp, err := this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||||
|
NodeId: nodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
Name: addr.GetString("name"),
|
||||||
|
Ip: result[0],
|
||||||
|
CanAccess: addr.GetBool("canAccess"),
|
||||||
|
IsUp: addr.GetBool("isUp"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addrId = createResp.NodeIPAddressId
|
||||||
|
resultAddrIds = append(resultAddrIds, addrId)
|
||||||
|
} else if len(result) > 1 {
|
||||||
|
// 批量创建
|
||||||
|
createResp, err := this.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(this.AdminContext(), &pb.CreateNodeIPAddressesRequest{
|
||||||
|
NodeId: nodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
Name: addr.GetString("name"),
|
||||||
|
IpList: result,
|
||||||
|
CanAccess: addr.GetBool("canAccess"),
|
||||||
|
IsUp: addr.GetBool("isUp"),
|
||||||
|
GroupValue: ipStrings,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resultAddrIds = append(resultAddrIds, createResp.NodeIPAddressIds...)
|
||||||
}
|
}
|
||||||
addrId = createResp.NodeIPAddressId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 阈值
|
// 阈值
|
||||||
@@ -202,13 +237,16 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(this.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
|
||||||
NodeIPAddressId: addrId,
|
for _, addrId := range resultAddrIds {
|
||||||
NodeIPAddressThresholdsJSON: thresholdsJSON,
|
_, err = this.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(this.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
||||||
})
|
NodeIPAddressId: addrId,
|
||||||
if err != nil {
|
NodeIPAddressThresholdsJSON: thresholdsJSON,
|
||||||
this.ErrorPage(err)
|
})
|
||||||
return
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,11 +262,6 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if nodeResp.Node != nil {
|
if nodeResp.Node != nil {
|
||||||
var addresses = []string{}
|
|
||||||
for _, addrMap := range ipAddresses {
|
|
||||||
addresses = append(addresses, addrMap.GetString("ip"))
|
|
||||||
}
|
|
||||||
|
|
||||||
var grantMap maps.Map = nil
|
var grantMap maps.Map = nil
|
||||||
grantId := params.GrantId
|
grantId := params.GrantId
|
||||||
if grantId > 0 {
|
if grantId > 0 {
|
||||||
@@ -253,7 +286,7 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
"name": nodeResp.Node.Name,
|
"name": nodeResp.Node.Name,
|
||||||
"uniqueId": nodeResp.Node.UniqueId,
|
"uniqueId": nodeResp.Node.UniqueId,
|
||||||
"secret": nodeResp.Node.Secret,
|
"secret": nodeResp.Node.Secret,
|
||||||
"addresses": addresses,
|
"addresses": resultIPAddresses,
|
||||||
"login": maps.Map{
|
"login": maps.Map{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "SSH",
|
"name": "SSH",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func init() {
|
|||||||
server.
|
server.
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
||||||
Helper(clusters.NewClusterHelper()).
|
Helper(clusters.NewClusterHelper()).
|
||||||
|
Data("teaMenu", "clusters").
|
||||||
Prefix("/clusters/cluster").
|
Prefix("/clusters/cluster").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
Get("/nodes", new(NodesAction)).
|
Get("/nodes", new(NodesAction)).
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (this *InstallNodesAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, apiNode := range apiNodesResp.Nodes {
|
for _, apiNode := range apiNodesResp.ApiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,9 +86,16 @@ func (this *DetailAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否有备用IP
|
||||||
|
var originIP = addr.Ip
|
||||||
|
if len(addr.BackupIP) > 0 {
|
||||||
|
addr.Ip = addr.BackupIP
|
||||||
|
}
|
||||||
|
|
||||||
ipAddressMaps = append(ipAddressMaps, maps.Map{
|
ipAddressMaps = append(ipAddressMaps, maps.Map{
|
||||||
"id": addr.Id,
|
"id": addr.Id,
|
||||||
"name": addr.Name,
|
"name": addr.Name,
|
||||||
|
"originIP": originIP,
|
||||||
"ip": addr.Ip,
|
"ip": addr.Ip,
|
||||||
"canAccess": addr.CanAccess,
|
"canAccess": addr.CanAccess,
|
||||||
"isOn": addr.IsOn,
|
"isOn": addr.IsOn,
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
|
|||||||
@@ -69,6 +69,20 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
|
|
||||||
logs := []maps.Map{}
|
logs := []maps.Map{}
|
||||||
for _, log := range logsResp.NodeLogs {
|
for _, log := range logsResp.NodeLogs {
|
||||||
|
// 服务信息
|
||||||
|
var serverMap = maps.Map{"id": 0}
|
||||||
|
if log.ServerId > 0 {
|
||||||
|
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: log.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var server = serverResp.Server
|
||||||
|
if server != nil {
|
||||||
|
serverMap = maps.Map{"id": server.Id, "name": server.Name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logs = append(logs, maps.Map{
|
logs = append(logs, maps.Map{
|
||||||
"tag": log.Tag,
|
"tag": log.Tag,
|
||||||
"description": log.Description,
|
"description": log.Description,
|
||||||
@@ -76,6 +90,7 @@ func (this *LogsAction) RunGet(params struct {
|
|||||||
"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,
|
"count": log.Count,
|
||||||
|
"server": serverMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["logs"] = logs
|
this.Data["logs"] = logs
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ 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/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/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"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -21,6 +23,7 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
}) {
|
}) {
|
||||||
|
// 基本信息
|
||||||
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId})
|
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: params.ClusterId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -53,21 +56,42 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
this.Data["grant"] = grantMap
|
this.Data["grant"] = grantMap
|
||||||
|
|
||||||
this.Data["cluster"] = maps.Map{
|
// 时区
|
||||||
"id": cluster.Id,
|
this.Data["timeZoneGroups"] = nodeconfigs.FindAllTimeZoneGroups()
|
||||||
"name": cluster.Name,
|
this.Data["timeZoneLocations"] = nodeconfigs.FindAllTimeZoneLocations()
|
||||||
"installDir": cluster.InstallDir,
|
|
||||||
|
if len(cluster.TimeZone) == 0 {
|
||||||
|
cluster.TimeZone = nodeconfigs.DefaultTimeZoneLocation
|
||||||
}
|
}
|
||||||
|
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(cluster.TimeZone)
|
||||||
|
|
||||||
|
this.Data["cluster"] = maps.Map{
|
||||||
|
"id": cluster.Id,
|
||||||
|
"name": cluster.Name,
|
||||||
|
"installDir": cluster.InstallDir,
|
||||||
|
"timeZone": cluster.TimeZone,
|
||||||
|
"nodeMaxThreads": cluster.NodeMaxThreads,
|
||||||
|
"nodeTCPMaxConnections": cluster.NodeTCPMaxConnections,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认值
|
||||||
|
this.Data["defaultNodeMaxThreads"] = nodeconfigs.DefaultMaxThreads
|
||||||
|
this.Data["defaultNodeMaxThreadsMin"] = nodeconfigs.DefaultMaxThreadsMin
|
||||||
|
this.Data["defaultNodeMaxThreadsMax"] = nodeconfigs.DefaultMaxThreadsMax
|
||||||
|
this.Data["defaultNodeTCPMaxConnections"] = nodeconfigs.DefaultTCPMaxConnections
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunPost 保存设置
|
// RunPost 保存设置
|
||||||
func (this *IndexAction) RunPost(params struct {
|
func (this *IndexAction) RunPost(params struct {
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
Name string
|
Name string
|
||||||
GrantId int64
|
GrantId int64
|
||||||
InstallDir string
|
InstallDir string
|
||||||
|
TimeZone string
|
||||||
|
NodeMaxThreads int32
|
||||||
|
NodeTCPMaxConnections int32
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -78,11 +102,21 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入集群名称")
|
Require("请输入集群名称")
|
||||||
|
|
||||||
|
if params.NodeMaxThreads > 0 {
|
||||||
|
params.Must.
|
||||||
|
Field("nodeMaxThreads", params.NodeMaxThreads).
|
||||||
|
Gte(int64(nodeconfigs.DefaultMaxThreadsMin), "单节点最大线程数最小值不能小于"+types.String(nodeconfigs.DefaultMaxThreadsMin)).
|
||||||
|
Lte(int64(nodeconfigs.DefaultMaxThreadsMax), "单节点最大线程数最大值不能大于"+types.String(nodeconfigs.DefaultMaxThreadsMax))
|
||||||
|
}
|
||||||
|
|
||||||
_, 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,
|
||||||
NodeGrantId: params.GrantId,
|
NodeGrantId: params.GrantId,
|
||||||
InstallDir: params.InstallDir,
|
InstallDir: params.InstallDir,
|
||||||
|
TimeZone: params.TimeZone,
|
||||||
|
NodeMaxThreads: params.NodeMaxThreads,
|
||||||
|
NodeTCPMaxConnections: params.NodeTCPMaxConnections,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ func NewClustersHelper() *ClustersHelper {
|
|||||||
return &ClustersHelper{}
|
return &ClustersHelper{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ClustersHelper) BeforeAction(action *actions.ActionObject) {
|
func (this *ClustersHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||||
|
var action = actionPtr.Object()
|
||||||
if action.Request.Method != http.MethodGet {
|
if action.Request.Method != http.MethodGet {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -58,7 +60,9 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
Su: params.Su,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -59,7 +61,9 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
Su: params.Su,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,6 +76,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
"name": params.Name,
|
"name": params.Name,
|
||||||
"method": params.Method,
|
"method": params.Method,
|
||||||
"methodName": grantutils.FindGrantMethodName(params.Method),
|
"methodName": grantutils.FindGrantMethodName(params.Method),
|
||||||
|
"username": params.Username,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ func (this *GrantAction) RunGet(params struct {
|
|||||||
"username": grant.Username,
|
"username": grant.Username,
|
||||||
"password": strings.Repeat("*", len(grant.Password)),
|
"password": strings.Repeat("*", len(grant.Password)),
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
|
"passphrase": strings.Repeat("*", len(grant.Passphrase)),
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"su": grant.Su,
|
"su": grant.Su,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ func init() {
|
|||||||
server.
|
server.
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
||||||
Helper(clusterutils.NewClustersHelper()).
|
Helper(clusterutils.NewClustersHelper()).
|
||||||
|
Data("teaMenu", "clusters").
|
||||||
Data("teaSubMenu", "grant").
|
Data("teaSubMenu", "grant").
|
||||||
Prefix("/clusters/grants").
|
Prefix("/clusters/grants").
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
"username": grant.Username,
|
"username": grant.Username,
|
||||||
"password": grant.Password,
|
"password": grant.Password,
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
|
"passphrase": grant.Passphrase,
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"su": grant.Su,
|
"su": grant.Su,
|
||||||
}
|
}
|
||||||
@@ -57,7 +58,9 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -93,7 +96,9 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
Su: params.Su,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
|||||||
"password": grant.Password,
|
"password": grant.Password,
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
|
"passphrase": grant.Passphrase,
|
||||||
|
"su": grant.Su,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
@@ -56,7 +58,9 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
PrivateKey string
|
PrivateKey string
|
||||||
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -91,8 +95,10 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Username: params.Username,
|
Username: params.Username,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
|
Su: params.Su,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -105,6 +111,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
"name": params.Name,
|
"name": params.Name,
|
||||||
"method": params.Method,
|
"method": params.Method,
|
||||||
"methodName": grantutils.FindGrantMethodName(params.Method),
|
"methodName": grantutils.FindGrantMethodName(params.Method),
|
||||||
|
"username": params.Username,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
|
|||||||
@@ -121,6 +121,10 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cluster.TimeZone == nodeconfigs.DefaultTimeZoneLocation {
|
||||||
|
cluster.TimeZone = ""
|
||||||
|
}
|
||||||
|
|
||||||
clusterMaps = append(clusterMaps, maps.Map{
|
clusterMaps = append(clusterMaps, maps.Map{
|
||||||
"id": cluster.Id,
|
"id": cluster.Id,
|
||||||
"name": cluster.Name,
|
"name": cluster.Name,
|
||||||
@@ -132,6 +136,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
"dnsName": cluster.DnsName,
|
"dnsName": cluster.DnsName,
|
||||||
"dnsDomainName": dnsDomainName,
|
"dnsDomainName": dnsDomainName,
|
||||||
"countServers": countServersResp.Count,
|
"countServers": countServersResp.Count,
|
||||||
|
"timeZone": cluster.TimeZone,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ func init() {
|
|||||||
server.
|
server.
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
||||||
Helper(clusterutils.NewClustersHelper()).
|
Helper(clusterutils.NewClustersHelper()).
|
||||||
|
Data("teaMenu", "clusters").
|
||||||
Prefix("/clusters").
|
Prefix("/clusters").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
GetPost("/create", new(CreateAction)).
|
GetPost("/create", new(CreateAction)).
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package logs
|
|||||||
|
|
||||||
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"
|
||||||
@@ -12,6 +13,11 @@ type IndexAction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *IndexAction) Init() {
|
func (this *IndexAction) Init() {
|
||||||
|
if this.ParamString("type") == "unread" {
|
||||||
|
this.FirstMenu("unread")
|
||||||
|
} else {
|
||||||
|
this.FirstMenu("index")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
@@ -19,19 +25,34 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
DayTo string
|
DayTo string
|
||||||
Keyword string
|
Keyword string
|
||||||
Level string
|
Level string
|
||||||
|
Type string
|
||||||
}) {
|
}) {
|
||||||
this.Data["dayFrom"] = params.DayFrom
|
this.Data["dayFrom"] = params.DayFrom
|
||||||
this.Data["dayTo"] = params.DayTo
|
this.Data["dayTo"] = params.DayTo
|
||||||
this.Data["keyword"] = params.Keyword
|
this.Data["keyword"] = params.Keyword
|
||||||
this.Data["level"] = params.Level
|
this.Data["level"] = params.Level
|
||||||
|
this.Data["type"] = params.Type
|
||||||
|
|
||||||
|
// 未读数量
|
||||||
|
countUnreadResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||||
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
|
IsUnread: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["countUnreadLogs"] = countUnreadResp.Count
|
||||||
|
|
||||||
|
// 日志数量
|
||||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
Role: "node",
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
DayFrom: params.DayFrom,
|
DayFrom: params.DayFrom,
|
||||||
DayTo: params.DayTo,
|
DayTo: params.DayTo,
|
||||||
Keyword: params.Keyword,
|
Keyword: params.Keyword,
|
||||||
Level: params.Level,
|
Level: params.Level,
|
||||||
|
IsUnread: params.Type == "unread",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -42,14 +63,15 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["page"] = page.AsHTML()
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
Role: "node",
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
DayFrom: params.DayFrom,
|
DayFrom: params.DayFrom,
|
||||||
DayTo: params.DayTo,
|
DayTo: params.DayTo,
|
||||||
Keyword: params.Keyword,
|
Keyword: params.Keyword,
|
||||||
Level: params.Level,
|
Level: params.Level,
|
||||||
Offset: page.Offset,
|
IsUnread: params.Type == "unread",
|
||||||
Size: page.Size,
|
Offset: page.Offset,
|
||||||
|
Size: page.Size,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -68,13 +90,29 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 服务信息
|
||||||
|
var serverMap = maps.Map{"id": 0}
|
||||||
|
if log.ServerId > 0 {
|
||||||
|
serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: log.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var server = serverResp.Server
|
||||||
|
if server != nil {
|
||||||
|
serverMap = maps.Map{"id": server.Id, "name": server.Name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logs = append(logs, maps.Map{
|
logs = append(logs, maps.Map{
|
||||||
|
"id": log.Id,
|
||||||
"tag": log.Tag,
|
"tag": log.Tag,
|
||||||
"description": log.Description,
|
"description": log.Description,
|
||||||
"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,
|
"count": log.Count,
|
||||||
|
"isRead": log.IsRead,
|
||||||
"node": maps.Map{
|
"node": maps.Map{
|
||||||
"id": node.Id,
|
"id": node.Id,
|
||||||
"cluster": maps.Map{
|
"cluster": maps.Map{
|
||||||
@@ -83,6 +121,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
},
|
},
|
||||||
"name": node.Name,
|
"name": node.Name,
|
||||||
},
|
},
|
||||||
|
"server": serverMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["logs"] = logs
|
this.Data["logs"] = logs
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ func init() {
|
|||||||
Data("teaSubMenu", "log").
|
Data("teaSubMenu", "log").
|
||||||
Prefix("/clusters/logs").
|
Prefix("/clusters/logs").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
|
Post("/readLogs", new(ReadLogsAction)).
|
||||||
|
Post("/readAllLogs", new(ReadAllLogsAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
24
internal/web/actions/default/clusters/logs/readAllLogs.go
Normal file
24
internal/web/actions/default/clusters/logs/readAllLogs.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadAllLogsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ReadAllLogsAction) RunPost(params struct {
|
||||||
|
LogIds []int64
|
||||||
|
}) {
|
||||||
|
_, err := this.RPC().NodeLogRPC().UpdateAllNodeLogsRead(this.AdminContext(), &pb.UpdateAllNodeLogsReadRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
26
internal/web/actions/default/clusters/logs/readLogs.go
Normal file
26
internal/web/actions/default/clusters/logs/readLogs.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ReadLogsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ReadLogsAction) RunPost(params struct {
|
||||||
|
LogIds []int64
|
||||||
|
}) {
|
||||||
|
_, err := this.RPC().NodeLogRPC().UpdateNodeLogsRead(this.AdminContext(), &pb.UpdateNodeLogsReadRequest{
|
||||||
|
NodeLogIds: params.LogIds,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ func (this *SelectPopupAction) Init() {
|
|||||||
func (this *SelectPopupAction) RunGet(params struct {
|
func (this *SelectPopupAction) RunGet(params struct {
|
||||||
SelectedClusterIds string
|
SelectedClusterIds string
|
||||||
Keyword string
|
Keyword string
|
||||||
|
PageSize int64
|
||||||
}) {
|
}) {
|
||||||
this.Data["keyword"] = params.Keyword
|
this.Data["keyword"] = params.Keyword
|
||||||
|
|
||||||
@@ -36,6 +37,9 @@ func (this *SelectPopupAction) RunGet(params struct {
|
|||||||
var count = countResp.Count
|
var count = countResp.Count
|
||||||
var page = this.NewPage(count)
|
var page = this.NewPage(count)
|
||||||
page.Size = 6
|
page.Size = 6
|
||||||
|
if params.PageSize > 0 {
|
||||||
|
page.Size = params.PageSize
|
||||||
|
}
|
||||||
this.Data["page"] = page.AsHTML()
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
|
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ type CheckAction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *CheckAction) RunPost(params struct{}) {
|
func (this *CheckAction) RunPost(params struct{}) {
|
||||||
resp, err := this.RPC().NodeTaskRPC().ExistsNodeTasks(this.AdminContext(), &pb.ExistsNodeTasksRequest{})
|
resp, err := this.RPC().NodeTaskRPC().ExistsNodeTasks(this.AdminContext(), &pb.ExistsNodeTasksRequest{
|
||||||
|
ExcludeTypes: []string{"ipItemChanged"},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 域名列表选项
|
// DomainOptionsAction 域名列表选项
|
||||||
type DomainOptionsAction struct {
|
type DomainOptionsAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,8 @@ func (this *DomainOptionsAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
domainMaps := []maps.Map{}
|
domainMaps := []maps.Map{}
|
||||||
for _, domain := range domainsResp.DnsDomains {
|
for _, domain := range domainsResp.DnsDomains {
|
||||||
// 未开启的先跳过
|
// 未开启或者已删除的先跳过
|
||||||
if !domain.IsOn {
|
if !domain.IsOn || domain.IsDeleted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func ValidateRecordName(name string) bool {
|
|||||||
strings.HasSuffix(piece, "-") ||
|
strings.HasSuffix(piece, "-") ||
|
||||||
strings.Contains(piece, "--") ||
|
strings.Contains(piece, "--") ||
|
||||||
len(piece) > 63 ||
|
len(piece) > 63 ||
|
||||||
!regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(piece) {
|
!regexp.MustCompile(`^[_a-z0-9-]+$`).MatchString(piece) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
internal/web/actions/default/dns/domains/recover.go
Normal file
27
internal/web/actions/default/dns/domains/recover.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package domains
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RecoverAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RecoverAction) RunPost(params struct {
|
||||||
|
DomainId int64
|
||||||
|
}) {
|
||||||
|
// 记录日志
|
||||||
|
defer this.CreateLog(oplogs.LevelInfo, "从DNS服务商中恢复域名 %d", params.DomainId)
|
||||||
|
|
||||||
|
// 执行恢复
|
||||||
|
_, err := this.RPC().DNSDomainRPC().RecoverDNSDomain(this.AdminContext(), &pb.RecoverDNSDomainRequest{DnsDomainId: params.DomainId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
// TODO 检查DomainId
|
// TODO 检查DomainId
|
||||||
|
|
||||||
// 记录日志
|
// 记录日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "修改管理域名到DNS服务商 %d", params.DomainId)
|
defer this.CreateLog(oplogs.LevelInfo, "修改DNS服务商域名 %d", params.DomainId)
|
||||||
|
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func init() {
|
|||||||
GetPost("/createPopup", new(domains.CreatePopupAction)).
|
GetPost("/createPopup", new(domains.CreatePopupAction)).
|
||||||
GetPost("/updatePopup", new(domains.UpdatePopupAction)).
|
GetPost("/updatePopup", new(domains.UpdatePopupAction)).
|
||||||
Post("/delete", new(domains.DeleteAction)).
|
Post("/delete", new(domains.DeleteAction)).
|
||||||
|
Post("/recover", new(domains.RecoverAction)).
|
||||||
Post("/sync", new(domains.SyncAction)).
|
Post("/sync", new(domains.SyncAction)).
|
||||||
Get("/routesPopup", new(domains.RoutesPopupAction)).
|
Get("/routesPopup", new(domains.RoutesPopupAction)).
|
||||||
GetPost("/selectPopup", new(domains.SelectPopupAction)).
|
GetPost("/selectPopup", new(domains.SelectPopupAction)).
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func (this *ProviderAction) RunGet(params struct {
|
|||||||
"name": domain.Name,
|
"name": domain.Name,
|
||||||
"isOn": domain.IsOn,
|
"isOn": domain.IsOn,
|
||||||
"isUp": domain.IsUp,
|
"isUp": domain.IsUp,
|
||||||
|
"isDeleted": domain.IsDeleted,
|
||||||
"dataUpdatedTime": dataUpdatedTime,
|
"dataUpdatedTime": dataUpdatedTime,
|
||||||
"countRoutes": len(domain.Routes),
|
"countRoutes": len(domain.Routes),
|
||||||
"countServerRecords": domain.CountServerRecords,
|
"countServerRecords": domain.CountServerRecords,
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package bills
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/actions"
|
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GenerateAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *GenerateAction) Init() {
|
|
||||||
this.Nav("", "", "generate")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *GenerateAction) RunGet(params struct{}) {
|
|
||||||
this.Data["month"] = timeutil.Format("Ym", time.Now().AddDate(0, -1, 0))
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *GenerateAction) RunPost(params struct {
|
|
||||||
Month string
|
|
||||||
|
|
||||||
Must *actions.Must
|
|
||||||
}) {
|
|
||||||
defer this.CreateLogInfo("手动生成上个月(" + params.Month + ")账单")
|
|
||||||
|
|
||||||
_, err := this.RPC().UserBillRPC().GenerateAllUserBills(this.AdminContext(), &pb.GenerateAllUserBillsRequest{Month: params.Month})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package bills
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"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("", "", "index")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *IndexAction) RunGet(params struct {
|
|
||||||
PaidFlag int32 `default:"-1"`
|
|
||||||
UserId int64
|
|
||||||
Month string
|
|
||||||
}) {
|
|
||||||
countResp, err := this.RPC().UserBillRPC().CountAllUserBills(this.AdminContext(), &pb.CountAllUserBillsRequest{})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
page := this.NewPage(countResp.Count)
|
|
||||||
this.Data["page"] = page.AsHTML()
|
|
||||||
|
|
||||||
billsResp, err := this.RPC().UserBillRPC().ListUserBills(this.AdminContext(), &pb.ListUserBillsRequest{
|
|
||||||
PaidFlag: params.PaidFlag,
|
|
||||||
UserId: params.UserId,
|
|
||||||
Month: params.Month,
|
|
||||||
Offset: page.Offset,
|
|
||||||
Size: page.Size,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
billMaps := []maps.Map{}
|
|
||||||
for _, bill := range billsResp.UserBills {
|
|
||||||
var userMap maps.Map = nil
|
|
||||||
if bill.User != nil {
|
|
||||||
userMap = maps.Map{
|
|
||||||
"id": bill.User.Id,
|
|
||||||
"fullname": bill.User.Fullname,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
billMaps = append(billMaps, maps.Map{
|
|
||||||
"id": bill.Id,
|
|
||||||
"isPaid": bill.IsPaid,
|
|
||||||
"month": bill.Month,
|
|
||||||
"amount": fmt.Sprintf("%.2f", bill.Amount),
|
|
||||||
"typeName": bill.TypeName,
|
|
||||||
"user": userMap,
|
|
||||||
"description": bill.Description,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["bills"] = billMaps
|
|
||||||
|
|
||||||
this.Show()
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package bills
|
|
||||||
|
|
||||||
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.AdminModuleCodeFinance)).
|
|
||||||
Data("teaMenu", "finance").
|
|
||||||
|
|
||||||
// 财务管理
|
|
||||||
Prefix("/finance/bills").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
GetPost("/generate", new(GenerateAction)).
|
|
||||||
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package finance
|
|
||||||
|
|
||||||
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.AdminModuleCodeFinance)).
|
|
||||||
|
|
||||||
// 财务管理
|
|
||||||
Prefix("/finance").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -43,6 +43,12 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// 是否新安装
|
||||||
|
if setup.IsNewInstalled() {
|
||||||
|
this.RedirectURL("/setup/confirm")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 已登录跳转到dashboard
|
// 已登录跳转到dashboard
|
||||||
if params.Auth.IsUser() {
|
if params.Auth.IsUser() {
|
||||||
this.RedirectURL("/dashboard")
|
this.RedirectURL("/dashboard")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ipAddresses
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"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/nodeconfigs"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
@@ -39,9 +40,15 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Field("ip", params.IP).
|
Field("ip", params.IP).
|
||||||
Require("请输入IP地址")
|
Require("请输入IP地址")
|
||||||
|
|
||||||
ip := net.ParseIP(params.IP)
|
result, err := utils.ExtractIP(params.IP)
|
||||||
if len(ip) == 0 {
|
if err != nil {
|
||||||
this.FailField("ip", "请输入正确的IP")
|
this.Fail("IP格式错误'" + params.IP + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ip := range result {
|
||||||
|
if len(net.ParseIP(ip)) == 0 {
|
||||||
|
this.FailField("ip", "请输入正确的IP")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 阈值设置
|
// 阈值设置
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ipaddressutils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"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/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
@@ -16,8 +17,11 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, addr := range addresses {
|
for _, addr := range addresses {
|
||||||
|
var resultAddrIds = []int64{}
|
||||||
addrId := addr.GetInt64("id")
|
addrId := addr.GetInt64("id")
|
||||||
if addrId > 0 {
|
if addrId > 0 {
|
||||||
|
resultAddrIds = append(resultAddrIds, addrId)
|
||||||
|
|
||||||
var isOn = false
|
var isOn = false
|
||||||
if !addr.Has("isOn") { // 兼容老版本
|
if !addr.Has("isOn") { // 兼容老版本
|
||||||
isOn = true
|
isOn = true
|
||||||
@@ -37,18 +41,40 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddress(parentAction.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
var ipStrings = addr.GetString("ip")
|
||||||
NodeId: nodeId,
|
result, _ := utils.ExtractIP(ipStrings)
|
||||||
Role: role,
|
|
||||||
Name: addr.GetString("name"),
|
if len(result) == 1 {
|
||||||
Ip: addr.GetString("ip"),
|
// 单个创建
|
||||||
CanAccess: addr.GetBool("canAccess"),
|
createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddress(parentAction.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||||
IsUp: addr.GetBool("isUp"),
|
NodeId: nodeId,
|
||||||
})
|
Role: role,
|
||||||
if err != nil {
|
Name: addr.GetString("name"),
|
||||||
return err
|
Ip: result[0],
|
||||||
|
CanAccess: addr.GetBool("canAccess"),
|
||||||
|
IsUp: addr.GetBool("isUp"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
addrId = createResp.NodeIPAddressId
|
||||||
|
resultAddrIds = append(resultAddrIds, addrId)
|
||||||
|
} else if len(result) > 1 {
|
||||||
|
// 批量创建
|
||||||
|
createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(parentAction.AdminContext(), &pb.CreateNodeIPAddressesRequest{
|
||||||
|
NodeId: nodeId,
|
||||||
|
Role: role,
|
||||||
|
Name: addr.GetString("name"),
|
||||||
|
IpList: result,
|
||||||
|
CanAccess: addr.GetBool("canAccess"),
|
||||||
|
IsUp: addr.GetBool("isUp"),
|
||||||
|
GroupValue: ipStrings,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resultAddrIds = append(resultAddrIds, createResp.NodeIPAddressIds...)
|
||||||
}
|
}
|
||||||
addrId = createResp.NodeIPAddressId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存阈值
|
// 保存阈值
|
||||||
@@ -58,12 +84,25 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = parentAction.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(parentAction.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
|
||||||
NodeIPAddressId: addrId,
|
for _, addrId := range resultAddrIds {
|
||||||
NodeIPAddressThresholdsJSON: thresholdsJSON,
|
_, err = parentAction.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(parentAction.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
||||||
})
|
NodeIPAddressId: addrId,
|
||||||
if err != nil {
|
NodeIPAddressThresholdsJSON: thresholdsJSON,
|
||||||
return err
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, addrId := range resultAddrIds {
|
||||||
|
_, err = parentAction.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(parentAction.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
||||||
|
NodeIPAddressId: addrId,
|
||||||
|
NodeIPAddressThresholdsJSON: []byte("[]"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ipAddresses
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"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/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
@@ -57,9 +58,22 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(params.IP)
|
if params.AddressId > 0 {
|
||||||
if len(ip) == 0 {
|
ip := net.ParseIP(params.IP)
|
||||||
this.Fail("请输入正确的IP")
|
if len(ip) == 0 {
|
||||||
|
this.Fail("请输入正确的IP")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result, err := utils.ExtractIP(params.IP)
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("IP格式错误'" + params.IP + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ip := range result {
|
||||||
|
if len(net.ParseIP(ip)) == 0 {
|
||||||
|
this.FailField("ip", "请输入正确的IP")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var thresholds = []*nodeconfigs.IPAddressThresholdConfig{}
|
var thresholds = []*nodeconfigs.IPAddressThresholdConfig{}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(len(nodes))
|
wg.Add(len(nodes))
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// TODO 检查是否在线
|
// TODO 检查是否在线
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
apiNodeId := node.ConnectedAPINodeIds[0]
|
apiNodeId := node.ConnectedAPINodeIds[0]
|
||||||
rpcClient, ok := rpcMap[apiNodeId]
|
rpcClient, ok := rpcMap[apiNodeId]
|
||||||
if !ok {
|
if !ok {
|
||||||
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{NodeId: apiNodeId})
|
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{ApiNodeId: apiNodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -82,7 +83,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiNodeResp.Node == nil {
|
if apiNodeResp.ApiNode == nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
NodeId: node.Id,
|
NodeId: node.Id,
|
||||||
@@ -94,7 +95,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
apiNode := apiNodeResp.Node
|
apiNode := apiNodeResp.ApiNode
|
||||||
|
|
||||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
@@ -104,7 +105,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
},
|
},
|
||||||
NodeId: apiNode.UniqueId,
|
NodeId: apiNode.UniqueId,
|
||||||
Secret: apiNode.Secret,
|
Secret: apiNode.Secret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -162,6 +163,11 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭RPC
|
||||||
|
for _, rpcClient := range rpcMap {
|
||||||
|
_ = rpcClient.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +249,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
apiNodeId := node.ConnectedAPINodeIds[0]
|
apiNodeId := node.ConnectedAPINodeIds[0]
|
||||||
rpcClient, ok := rpcMap[apiNodeId]
|
rpcClient, ok := rpcMap[apiNodeId]
|
||||||
if !ok {
|
if !ok {
|
||||||
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{NodeId: apiNodeId})
|
apiNodeResp, err := defaultRPCClient.APINodeRPC().FindEnabledAPINode(ctx, &pb.FindEnabledAPINodeRequest{ApiNodeId: apiNodeId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -257,7 +263,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiNodeResp.Node == nil {
|
if apiNodeResp.ApiNode == nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
NodeId: node.Id,
|
NodeId: node.Id,
|
||||||
@@ -269,7 +275,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
apiNode := apiNodeResp.Node
|
apiNode := apiNodeResp.ApiNode
|
||||||
|
|
||||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPC: struct {
|
||||||
@@ -279,7 +285,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
},
|
},
|
||||||
NodeId: apiNode.UniqueId,
|
NodeId: apiNode.UniqueId,
|
||||||
Secret: apiNode.Secret,
|
Secret: apiNode.Secret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
results = append(results, &MessageResult{
|
results = append(results, &MessageResult{
|
||||||
@@ -337,5 +343,10 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭RPC
|
||||||
|
for _, rpcClient := range rpcMap {
|
||||||
|
_ = rpcClient.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
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.AdminModuleCodeNS)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "accessLog").
|
|
||||||
Prefix("/ns/clusters/accessLogs").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package cluster
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
"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/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
@@ -87,14 +88,31 @@ func (this *CreateNodeAction) RunPost(params struct {
|
|||||||
NodeId: nodeId,
|
NodeId: nodeId,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
var ipStrings = addrMap.GetString("ip")
|
||||||
NodeId: nodeId,
|
result, _ := utils.ExtractIP(ipStrings)
|
||||||
Role: nodeconfigs.NodeRoleDNS,
|
|
||||||
Name: addrMap.GetString("name"),
|
if len(result) == 1 {
|
||||||
Ip: addrMap.GetString("ip"),
|
// 单个创建
|
||||||
CanAccess: addrMap.GetBool("canAccess"),
|
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||||
IsUp: addrMap.GetBool("isUp"),
|
NodeId: nodeId,
|
||||||
})
|
Role: nodeconfigs.NodeRoleDNS,
|
||||||
|
Name: addrMap.GetString("name"),
|
||||||
|
Ip: result[0],
|
||||||
|
CanAccess: addrMap.GetBool("canAccess"),
|
||||||
|
IsUp: addrMap.GetBool("isUp"),
|
||||||
|
})
|
||||||
|
} else if len(result) > 1 {
|
||||||
|
// 批量创建
|
||||||
|
_, err = this.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(this.AdminContext(), &pb.CreateNodeIPAddressesRequest{
|
||||||
|
NodeId: nodeId,
|
||||||
|
Role: nodeconfigs.NodeRoleDNS,
|
||||||
|
Name: addrMap.GetString("name"),
|
||||||
|
IpList: result,
|
||||||
|
CanAccess: addrMap.GetBool("canAccess"),
|
||||||
|
IsUp: addrMap.GetBool("isUp"),
|
||||||
|
GroupValue: ipStrings,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/cluster/node"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/clusterutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
|
||||||
Helper(new(clusterutils.ClusterHelper)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "cluster").
|
|
||||||
Prefix("/ns/clusters/cluster").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
GetPost("/delete", new(DeleteAction)).
|
|
||||||
GetPost("/createNode", new(CreateNodeAction)).
|
|
||||||
Post("/deleteNode", new(DeleteNodeAction)).
|
|
||||||
Get("/upgradeRemote", new(UpgradeRemoteAction)).
|
|
||||||
GetPost("/updateNodeSSH", new(UpdateNodeSSHAction)).
|
|
||||||
|
|
||||||
// 节点相关
|
|
||||||
Prefix("/ns/clusters/cluster/node").
|
|
||||||
Get("", new(node.IndexAction)).
|
|
||||||
Get("/logs", new(node.LogsAction)).
|
|
||||||
GetPost("/update", new(node.UpdateAction)).
|
|
||||||
GetPost("/install", new(node.InstallAction)).
|
|
||||||
Post("/status", new(node.StatusAction)).
|
|
||||||
Post("/updateInstallStatus", new(node.UpdateInstallStatusAction)).
|
|
||||||
Post("/start", new(node.StartAction)).
|
|
||||||
Post("/stop", new(node.StopAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -73,7 +73,7 @@ func (this *InstallAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNodes := apiNodesResp.Nodes
|
apiNodes := apiNodesResp.ApiNodes
|
||||||
apiEndpoints := []string{}
|
apiEndpoints := []string{}
|
||||||
for _, apiNode := range apiNodes {
|
for _, apiNode := range apiNodes {
|
||||||
if !apiNode.IsOn {
|
if !apiNode.IsOn {
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package accessLog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/clusterutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
|
||||||
Helper(new(clusterutils.ClusterHelper)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "cluster").
|
|
||||||
Prefix("/ns/clusters/cluster/settings/accessLog").
|
|
||||||
GetPost("", new(IndexAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package cluster
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/clusterutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
|
||||||
Helper(new(clusterutils.ClusterHelper)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "cluster").
|
|
||||||
Prefix("/ns/clusters/cluster/settings").
|
|
||||||
GetPost("", new(IndexAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package recursion
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/clusterutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
|
||||||
Helper(new(clusterutils.ClusterHelper)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "cluster").
|
|
||||||
Prefix("/ns/clusters/cluster/settings/recursion").
|
|
||||||
GetPost("", new(IndexAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package clusters
|
|
||||||
|
|
||||||
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.AdminModuleCodeNS)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "cluster").
|
|
||||||
Prefix("/ns/clusters").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
GetPost("/create", new(CreateAction)).
|
|
||||||
Post("/options", new(OptionsAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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.AdminModuleCodeNS)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "log").
|
|
||||||
Prefix("/ns/clusters/logs").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package clusters
|
|
||||||
|
|
||||||
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.AdminModuleCodeNS)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "route").
|
|
||||||
Prefix("/ns/routes").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
Get("/route", new(RouteAction)).
|
|
||||||
GetPost("/createPopup", new(CreatePopupAction)).
|
|
||||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
|
||||||
Post("/delete", new(DeleteAction)).
|
|
||||||
Post("/sort", new(SortAction)).
|
|
||||||
Post("/options", new(OptionsAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package accesslogs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/settings/settingutils"
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
|
||||||
"github.com/iwind/TeaGo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
|
||||||
server.
|
|
||||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
|
||||||
Helper(new(settingutils.Helper)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "setting").
|
|
||||||
Prefix("/ns/settings/accesslogs").
|
|
||||||
GetPost("", new(IndexAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package users
|
|
||||||
|
|
||||||
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.AdminModuleCodeNS)).
|
|
||||||
Data("teaMenu", "ns").
|
|
||||||
Data("teaSubMenu", "domain").
|
|
||||||
Prefix("/ns/users").
|
|
||||||
Post("/options", new(OptionsAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -42,7 +42,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
},
|
},
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Secret: params.NodeSecret,
|
Secret: params.NodeSecret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,10 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
// 获取管理员节点信息
|
// 获取管理员节点信息
|
||||||
apiTokensResp, err := client.APITokenRPC().FindAllEnabledAPITokens(client.APIContext(0), &pb.FindAllEnabledAPITokensRequest{Role: "admin"})
|
apiTokensResp, err := client.APITokenRPC().FindAllEnabledAPITokens(client.APIContext(0), &pb.FindAllEnabledAPITokensRequest{Role: "admin"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -69,7 +73,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
||||||
}
|
}
|
||||||
var endpoints = []string{}
|
var endpoints = []string{}
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.ApiNodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -144,7 +148,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
_, err = client.APINodeRPC().UpdateAPINode(client.Context(0), &pb.UpdateAPINodeRequest{
|
_, err = client.APINodeRPC().UpdateAPINode(client.Context(0), &pb.UpdateAPINodeRequest{
|
||||||
NodeId: node.Id,
|
ApiNodeId: node.Id,
|
||||||
Name: node.Name,
|
Name: node.Name,
|
||||||
Description: node.Description,
|
Description: node.Description,
|
||||||
HttpJSON: node.HttpJSON,
|
HttpJSON: node.HttpJSON,
|
||||||
|
|||||||
@@ -49,10 +49,15 @@ func (this *ValidateApiAction) RunPost(params struct {
|
|||||||
},
|
},
|
||||||
NodeId: params.NodeId,
|
NodeId: params.NodeId,
|
||||||
Secret: params.NodeSecret,
|
Secret: params.NodeSecret,
|
||||||
})
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_ = client.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
_, err = client.APINodeRPC().FindCurrentAPINodeVersion(client.APIContext(0), &pb.FindCurrentAPINodeVersionRequest{})
|
_, err = client.APINodeRPC().FindCurrentAPINodeVersion(client.APIContext(0), &pb.FindCurrentAPINodeVersionRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
this.FailField("host", "无法连接此API节点,错误信息:"+err.Error())
|
||||||
@@ -64,7 +69,7 @@ func (this *ValidateApiAction) RunPost(params struct {
|
|||||||
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
this.Fail("获取API节点列表失败,错误信息:" + err.Error())
|
||||||
}
|
}
|
||||||
var hosts = []string{}
|
var hosts = []string{}
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.ApiNodes {
|
||||||
if !node.IsOn {
|
if !node.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
||||||
|
|
||||||
package ipbox
|
|
||||||
|
|
||||||
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.AdminModuleCodeServer)).
|
|
||||||
Prefix("/servers/accesslogs").
|
|
||||||
Data("teaMenu", "servers").
|
|
||||||
Data("teaSubMenu", "accesslog").
|
|
||||||
Get("", new(IndexAction)).
|
|
||||||
GetPost("/createPopup", new(CreatePopupAction)).
|
|
||||||
Get("/policy", new(PolicyAction)).
|
|
||||||
GetPost("/test", new(TestAction)).
|
|
||||||
GetPost("/update", new(UpdateAction)).
|
|
||||||
Post("/delete", new(DeleteAction)).
|
|
||||||
EndAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,7 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "删除SSL证书 %d", params.CertId)
|
defer this.CreateLog(oplogs.LevelInfo, "删除SSL证书 %d", params.CertId)
|
||||||
|
|
||||||
// 是否正在被使用
|
// 是否正在被服务使用
|
||||||
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledServersWithSSLCertIdRequest{SslCertId: params.CertId})
|
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledServersWithSSLCertIdRequest{SslCertId: params.CertId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -26,6 +26,26 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
this.Fail("此证书正在被某些服务引用,请先修改服务后再删除。")
|
this.Fail("此证书正在被某些服务引用,请先修改服务后再删除。")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否正在被API节点使用
|
||||||
|
countResp, err = this.RPC().APINodeRPC().CountAllEnabledAPINodesWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledAPINodesWithSSLCertIdRequest{SslCertId: params.CertId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if countResp.Count > 0 {
|
||||||
|
this.Fail("此证书正在被某些API节点引用,请先修改API节点后再删除")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否正在被用户节点使用
|
||||||
|
countResp, err = this.RPC().UserNodeRPC().CountAllEnabledUserNodesWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledUserNodesWithSSLCertIdRequest{SslCertId: params.CertId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if countResp.Count > 0 {
|
||||||
|
this.Fail("此证书正在被某些用户节点引用,请先修改用户节点后再删除")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = this.RPC().SSLCertRPC().DeleteSSLCert(this.AdminContext(), &pb.DeleteSSLCertRequest{SslCertId: params.CertId})
|
_, err = this.RPC().SSLCertRPC().DeleteSSLCert(this.AdminContext(), &pb.DeleteSSLCertRequest{SslCertId: params.CertId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
globalConfig := &serverconfigs.GlobalConfig{}
|
globalConfig := &serverconfigs.GlobalConfig{}
|
||||||
|
|
||||||
// 默认值
|
// 默认值
|
||||||
globalConfig.HTTPAll.DomainAuditingIsOn = true
|
globalConfig.HTTPAll.DomainAuditingIsOn = false
|
||||||
|
|
||||||
if len(valueJSON) > 0 {
|
if len(valueJSON) > 0 {
|
||||||
err = json.Unmarshal(valueJSON, globalConfig)
|
err = json.Unmarshal(valueJSON, globalConfig)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func (this *CreateGroupPopupAction) RunPost(params struct {
|
|||||||
Type string
|
Type string
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
|
Code string
|
||||||
Description string
|
Description string
|
||||||
IsOn bool
|
IsOn bool
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ func (this *CreateGroupPopupAction) RunPost(params struct {
|
|||||||
createResp, err := this.RPC().HTTPFirewallRuleGroupRPC().CreateHTTPFirewallRuleGroup(this.AdminContext(), &pb.CreateHTTPFirewallRuleGroupRequest{
|
createResp, err := this.RPC().HTTPFirewallRuleGroupRPC().CreateHTTPFirewallRuleGroup(this.AdminContext(), &pb.CreateHTTPFirewallRuleGroupRequest{
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
|
Code: params.Code,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ func (this *CreateSetPopupAction) RunPost(params struct {
|
|||||||
RulesJSON []byte
|
RulesJSON []byte
|
||||||
Connector string
|
Connector string
|
||||||
ActionsJSON []byte
|
ActionsJSON []byte
|
||||||
|
IgnoreLocal bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -124,6 +125,7 @@ func (this *CreateSetPopupAction) RunPost(params struct {
|
|||||||
RuleRefs: nil,
|
RuleRefs: nil,
|
||||||
Rules: rules,
|
Rules: rules,
|
||||||
Actions: actionConfigs,
|
Actions: actionConfigs,
|
||||||
|
IgnoreLocal: params.IgnoreLocal,
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfigJSON, err := json.Marshal(setConfig)
|
setConfigJSON, err := json.Marshal(setConfig)
|
||||||
|
|||||||
@@ -32,24 +32,36 @@ func (this *ExportAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
inboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
enabledInboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||||
outboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
enabledOutboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||||
|
|
||||||
|
disabledInboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||||
|
disabledOutboundGroups := []*firewallconfigs.HTTPFirewallRuleGroup{}
|
||||||
|
|
||||||
if policy.Inbound != nil {
|
if policy.Inbound != nil {
|
||||||
for _, g := range policy.Inbound.Groups {
|
for _, g := range policy.Inbound.Groups {
|
||||||
if g.IsOn {
|
if g.IsOn {
|
||||||
inboundGroups = append(inboundGroups, g)
|
enabledInboundGroups = append(enabledInboundGroups, g)
|
||||||
|
} else {
|
||||||
|
disabledInboundGroups = append(disabledInboundGroups, g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if policy.Outbound != nil {
|
if policy.Outbound != nil {
|
||||||
for _, g := range policy.Outbound.Groups {
|
for _, g := range policy.Outbound.Groups {
|
||||||
if g.IsOn {
|
if g.IsOn {
|
||||||
outboundGroups = append(outboundGroups, g)
|
enabledOutboundGroups = append(enabledOutboundGroups, g)
|
||||||
|
} else {
|
||||||
|
disabledOutboundGroups = append(disabledOutboundGroups, g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Data["inboundGroups"] = inboundGroups
|
|
||||||
this.Data["outboundGroups"] = outboundGroups
|
this.Data["enabledInboundGroups"] = enabledInboundGroups
|
||||||
|
this.Data["enabledOutboundGroups"] = enabledOutboundGroups
|
||||||
|
|
||||||
|
this.Data["disabledInboundGroups"] = disabledInboundGroups
|
||||||
|
this.Data["disabledOutboundGroups"] = disabledOutboundGroups
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
@@ -116,5 +128,6 @@ func (this *ExportAction) RunPost(params struct {
|
|||||||
ttlcache.DefaultCache.Write(key, configJSON, time.Now().Unix()+600)
|
ttlcache.DefaultCache.Write(key, configJSON, time.Now().Unix()+600)
|
||||||
|
|
||||||
this.Data["key"] = key
|
this.Data["key"] = key
|
||||||
|
this.Data["id"] = params.FirewallPolicyId
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package waf
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/ttlcache"
|
"github.com/TeaOSLab/EdgeAdmin/internal/ttlcache"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ func (this *ExportDownloadAction) Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *ExportDownloadAction) RunGet(params struct {
|
func (this *ExportDownloadAction) RunGet(params struct {
|
||||||
Key string
|
Key string
|
||||||
|
PolicyId int64
|
||||||
}) {
|
}) {
|
||||||
item := ttlcache.DefaultCache.Read(params.Key)
|
item := ttlcache.DefaultCache.Read(params.Key)
|
||||||
if item == nil || item.Value == nil {
|
if item == nil || item.Value == nil {
|
||||||
@@ -27,7 +29,7 @@ func (this *ExportDownloadAction) RunGet(params struct {
|
|||||||
|
|
||||||
data, ok := item.Value.([]byte)
|
data, ok := item.Value.([]byte)
|
||||||
if ok {
|
if ok {
|
||||||
this.AddHeader("Content-Disposition", "attachment; filename=\"WAF.json\";")
|
this.AddHeader("Content-Disposition", "attachment; filename=\"WAF-"+types.String(params.PolicyId)+".json\";")
|
||||||
this.AddHeader("Content-Length", strconv.Itoa(len(data)))
|
this.AddHeader("Content-Length", strconv.Itoa(len(data)))
|
||||||
this.Write(data)
|
this.Write(data)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ func (this *GroupsAction) RunGet(params struct {
|
|||||||
"isOn": g.IsOn,
|
"isOn": g.IsOn,
|
||||||
"description": g.Description,
|
"description": g.Description,
|
||||||
"countSets": len(g.Sets),
|
"countSets": len(g.Sets),
|
||||||
"canDelete": len(g.Code) == 0,
|
"isTemplate": g.IsTemplate,
|
||||||
|
"canDelete": !g.IsTemplate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +61,8 @@ func (this *GroupsAction) RunGet(params struct {
|
|||||||
"isOn": g.IsOn,
|
"isOn": g.IsOn,
|
||||||
"description": g.Description,
|
"description": g.Description,
|
||||||
"countSets": len(g.Sets),
|
"countSets": len(g.Sets),
|
||||||
"canDelete": len(g.Code) == 0,
|
"isTemplate": g.IsTemplate,
|
||||||
|
"canDelete": !g.IsTemplate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func init() {
|
|||||||
GetPost("/createPopup", new(CreatePopupAction)).
|
GetPost("/createPopup", new(CreatePopupAction)).
|
||||||
Post("/delete", new(DeleteAction)).
|
Post("/delete", new(DeleteAction)).
|
||||||
Get("/policy", new(PolicyAction)).
|
Get("/policy", new(PolicyAction)).
|
||||||
|
Post("/upgradeTemplate", new(UpgradeTemplateAction)).
|
||||||
Get("/groups", new(GroupsAction)).
|
Get("/groups", new(GroupsAction)).
|
||||||
Get("/group", new(GroupAction)).
|
Get("/group", new(GroupAction)).
|
||||||
Get("/log", new(LogAction)).
|
Get("/log", new(LogAction)).
|
||||||
@@ -40,6 +41,7 @@ func init() {
|
|||||||
GetPost("/updateSetPopup", new(UpdateSetPopupAction)).
|
GetPost("/updateSetPopup", new(UpdateSetPopupAction)).
|
||||||
Post("/count", new(CountAction)).
|
Post("/count", new(CountAction)).
|
||||||
Get("/selectPopup", new(SelectPopupAction)).
|
Get("/selectPopup", new(SelectPopupAction)).
|
||||||
|
Post("/testRegexp", new(TestRegexpAction)).
|
||||||
|
|
||||||
// IP管理
|
// IP管理
|
||||||
GetPost("/ipadmin", new(ipadmin.IndexAction)).
|
GetPost("/ipadmin", new(ipadmin.IndexAction)).
|
||||||
|
|||||||
@@ -59,14 +59,56 @@ func (this *ListsAction) RunGet(params struct {
|
|||||||
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// policy
|
||||||
|
var sourcePolicyMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallPolicy != nil {
|
||||||
|
sourcePolicyMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallPolicy.Id,
|
||||||
|
"name": item.SourceHTTPFirewallPolicy.Name,
|
||||||
|
"serverId": item.SourceHTTPFirewallPolicy.ServerId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group
|
||||||
|
var sourceGroupMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleGroup != nil {
|
||||||
|
sourceGroupMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleGroup.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleGroup.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set
|
||||||
|
var sourceSetMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceHTTPFirewallRuleSet != nil {
|
||||||
|
sourceSetMap = maps.Map{
|
||||||
|
"id": item.SourceHTTPFirewallRuleSet.Id,
|
||||||
|
"name": item.SourceHTTPFirewallRuleSet.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// server
|
||||||
|
var sourceServerMap = maps.Map{"id": 0}
|
||||||
|
if item.SourceServer != nil {
|
||||||
|
sourceServerMap = maps.Map{
|
||||||
|
"id": item.SourceServer.Id,
|
||||||
|
"name": item.SourceServer.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
itemMaps = append(itemMaps, maps.Map{
|
itemMaps = append(itemMaps, maps.Map{
|
||||||
"id": item.Id,
|
"id": item.Id,
|
||||||
"ipFrom": item.IpFrom,
|
"ipFrom": item.IpFrom,
|
||||||
"ipTo": item.IpTo,
|
"ipTo": item.IpTo,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", item.CreatedAt),
|
||||||
"expiredTime": expiredTime,
|
"expiredTime": expiredTime,
|
||||||
"reason": item.Reason,
|
"reason": item.Reason,
|
||||||
"type": item.Type,
|
"type": item.Type,
|
||||||
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
"eventLevelName": firewallconfigs.FindFirewallEventLevelName(item.EventLevel),
|
||||||
|
"sourcePolicy": sourcePolicyMap,
|
||||||
|
"sourceGroup": sourceGroupMap,
|
||||||
|
"sourceSet": sourceSetMap,
|
||||||
|
"sourceServer": sourceServerMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["items"] = itemMaps
|
this.Data["items"] = itemMaps
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func (this *TestAction) RunPost(params struct {
|
|||||||
"ipFrom": resp.IpItem.IpFrom,
|
"ipFrom": resp.IpItem.IpFrom,
|
||||||
"ipTo": resp.IpItem.IpTo,
|
"ipTo": resp.IpItem.IpTo,
|
||||||
"reason": resp.IpItem.Reason,
|
"reason": resp.IpItem.Reason,
|
||||||
|
"createdTime": timeutil.FormatTime("Y-m-d", resp.IpItem.CreatedAt),
|
||||||
"expiredAt": resp.IpItem.ExpiredAt,
|
"expiredAt": resp.IpItem.ExpiredAt,
|
||||||
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
"expiredTime": timeutil.FormatTime("Y-m-d H:i:s", resp.IpItem.ExpiredAt),
|
||||||
"type": resp.IpItem.Type,
|
"type": resp.IpItem.Type,
|
||||||
|
|||||||
@@ -47,6 +47,33 @@ func (this *PolicyAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否有升级
|
||||||
|
var templatePolicy = firewallconfigs.HTTPFirewallTemplate()
|
||||||
|
var upgradeItems = []string{}
|
||||||
|
if templatePolicy.Inbound != nil {
|
||||||
|
for _, group := range templatePolicy.Inbound.Groups {
|
||||||
|
if len(group.Code) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var oldGroup = firewallPolicy.FindRuleGroupWithCode(group.Code)
|
||||||
|
if oldGroup == nil {
|
||||||
|
upgradeItems = append(upgradeItems, group.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, set := range group.Sets {
|
||||||
|
if len(set.Code) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var oldSet = oldGroup.FindRuleSetWithCode(set.Code)
|
||||||
|
if oldSet == nil {
|
||||||
|
upgradeItems = append(upgradeItems, group.Name+" -- "+set.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Data["upgradeItems"] = upgradeItems
|
||||||
|
|
||||||
// 模式
|
// 模式
|
||||||
if len(firewallPolicy.Mode) == 0 {
|
if len(firewallPolicy.Mode) == 0 {
|
||||||
firewallPolicy.Mode = firewallconfigs.FirewallModeDefend
|
firewallPolicy.Mode = firewallconfigs.FirewallModeDefend
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package waf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestRegexpAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *TestRegexpAction) RunPost(params struct {
|
||||||
|
Regexp string
|
||||||
|
IsCaseInsensitive bool
|
||||||
|
Body string
|
||||||
|
}) {
|
||||||
|
var exp = params.Regexp
|
||||||
|
if params.IsCaseInsensitive && !strings.HasPrefix(params.Regexp, "(?i)") {
|
||||||
|
exp = "(?i)" + exp
|
||||||
|
}
|
||||||
|
reg, err := regexp.Compile(exp)
|
||||||
|
if err != nil {
|
||||||
|
this.Data["result"] = maps.Map{
|
||||||
|
"isOk": false,
|
||||||
|
"message": "解析正则出错:" + err.Error(),
|
||||||
|
}
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
if reg.MatchString(params.Body) {
|
||||||
|
this.Data["result"] = maps.Map{
|
||||||
|
"isOk": true,
|
||||||
|
"message": "匹配成功",
|
||||||
|
}
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["result"] = maps.Map{
|
||||||
|
"isOk": false,
|
||||||
|
"message": "匹配失败",
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ func (this *UpdateGroupPopupAction) RunGet(params struct {
|
|||||||
"name": groupConfig.Name,
|
"name": groupConfig.Name,
|
||||||
"description": groupConfig.Description,
|
"description": groupConfig.Description,
|
||||||
"isOn": groupConfig.IsOn,
|
"isOn": groupConfig.IsOn,
|
||||||
|
"code": groupConfig.Code,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
@@ -43,6 +44,7 @@ func (this *UpdateGroupPopupAction) RunGet(params struct {
|
|||||||
func (this *UpdateGroupPopupAction) RunPost(params struct {
|
func (this *UpdateGroupPopupAction) RunPost(params struct {
|
||||||
GroupId int64
|
GroupId int64
|
||||||
Name string
|
Name string
|
||||||
|
Code string
|
||||||
Description string
|
Description string
|
||||||
IsOn bool
|
IsOn bool
|
||||||
|
|
||||||
@@ -59,6 +61,7 @@ func (this *UpdateGroupPopupAction) RunPost(params struct {
|
|||||||
FirewallRuleGroupId: params.GroupId,
|
FirewallRuleGroupId: params.GroupId,
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
|
Code: params.Code,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ func (this *UpdateSetPopupAction) RunPost(params struct {
|
|||||||
RulesJSON []byte
|
RulesJSON []byte
|
||||||
Connector string
|
Connector string
|
||||||
ActionsJSON []byte
|
ActionsJSON []byte
|
||||||
|
IgnoreLocal bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -144,6 +145,7 @@ func (this *UpdateSetPopupAction) RunPost(params struct {
|
|||||||
setConfig.Connector = params.Connector
|
setConfig.Connector = params.Connector
|
||||||
setConfig.Rules = rules
|
setConfig.Rules = rules
|
||||||
setConfig.Actions = actionConfigs
|
setConfig.Actions = actionConfigs
|
||||||
|
setConfig.IgnoreLocal = params.IgnoreLocal
|
||||||
|
|
||||||
setConfigJSON, err := json.Marshal(setConfig)
|
setConfigJSON, err := json.Marshal(setConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package waf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpgradeTemplateAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *UpgradeTemplateAction) RunPost(params struct {
|
||||||
|
PolicyId int64
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("升级WAF %d 内置规则", params.PolicyId)
|
||||||
|
|
||||||
|
policy, err := dao.SharedHTTPFirewallPolicyDAO.FindEnabledHTTPFirewallPolicyConfig(this.AdminContext(), params.PolicyId)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if policy == nil {
|
||||||
|
this.NotFound("firewallPolicy", params.PolicyId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否有升级
|
||||||
|
var templatePolicy = firewallconfigs.HTTPFirewallTemplate()
|
||||||
|
if templatePolicy.Inbound != nil {
|
||||||
|
for _, group := range templatePolicy.Inbound.Groups {
|
||||||
|
if len(group.Code) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var oldGroup = policy.FindRuleGroupWithCode(group.Code)
|
||||||
|
if oldGroup == nil {
|
||||||
|
createGroupResp, err := this.RPC().HTTPFirewallRuleGroupRPC().CreateHTTPFirewallRuleGroup(this.AdminContext(), &pb.CreateHTTPFirewallRuleGroupRequest{
|
||||||
|
IsOn: true,
|
||||||
|
Name: group.Name,
|
||||||
|
Code: group.Code,
|
||||||
|
Description: group.Description,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var groupId = createGroupResp.FirewallRuleGroupId
|
||||||
|
policy.Inbound.GroupRefs = append(policy.Inbound.GroupRefs, &firewallconfigs.HTTPFirewallRuleGroupRef{
|
||||||
|
IsOn: true,
|
||||||
|
GroupId: groupId,
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, set := range group.Sets {
|
||||||
|
setJSON, err := json.Marshal(set)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().HTTPFirewallRuleGroupRPC().AddHTTPFirewallRuleGroupSet(this.AdminContext(), &pb.AddHTTPFirewallRuleGroupSetRequest{
|
||||||
|
FirewallRuleGroupId: groupId,
|
||||||
|
FirewallRuleSetConfigJSON: setJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, set := range group.Sets {
|
||||||
|
if len(set.Code) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var oldSet = oldGroup.FindRuleSetWithCode(set.Code)
|
||||||
|
if oldSet == nil {
|
||||||
|
setJSON, err := json.Marshal(set)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().HTTPFirewallRuleGroupRPC().AddHTTPFirewallRuleGroupSet(this.AdminContext(), &pb.AddHTTPFirewallRuleGroupSetRequest{
|
||||||
|
FirewallRuleGroupId: oldGroup.Id,
|
||||||
|
FirewallRuleSetConfigJSON: setJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存inbound
|
||||||
|
inboundJSON, err := policy.InboundJSON()
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
outboundJSON, err := policy.OutboundJSON()
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.RPC().HTTPFirewallPolicyRPC().UpdateHTTPFirewallPolicyGroups(this.AdminContext(), &pb.UpdateHTTPFirewallPolicyGroupsRequest{
|
||||||
|
HttpFirewallPolicyId: params.PolicyId,
|
||||||
|
InboundJSON: inboundJSON,
|
||||||
|
OutboundJSON: outboundJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"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/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
@@ -56,14 +57,26 @@ func (this *CreateAction) RunGet(params struct{}) {
|
|||||||
// 服务类型
|
// 服务类型
|
||||||
this.Data["serverTypes"] = serverconfigs.AllServerTypes()
|
this.Data["serverTypes"] = serverconfigs.AllServerTypes()
|
||||||
|
|
||||||
|
// 检查是否有用户
|
||||||
|
countUsersResp, err := this.RPC().UserRPC().CountAllEnabledUsers(this.AdminContext(), &pb.CountAllEnabledUsersRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.Data["hasUsers"] = countUsersResp.Count > 0
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *CreateAction) RunPost(params struct {
|
func (this *CreateAction) RunPost(params struct {
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
ClusterId int64
|
|
||||||
GroupIds []int64
|
UserId int64
|
||||||
|
UserPlanId int64
|
||||||
|
ClusterId int64
|
||||||
|
|
||||||
|
GroupIds []int64
|
||||||
|
|
||||||
ServerType string
|
ServerType string
|
||||||
Addresses string
|
Addresses string
|
||||||
@@ -71,8 +84,12 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
CertIdsJSON []byte
|
CertIdsJSON []byte
|
||||||
Origins string
|
Origins string
|
||||||
|
|
||||||
AccessLogIsOn bool
|
AccessLogIsOn bool
|
||||||
WebsocketIsOn bool
|
WebsocketIsOn bool
|
||||||
|
CacheIsOn bool
|
||||||
|
WafIsOn bool
|
||||||
|
RemoteAddrIsOn bool
|
||||||
|
StatIsOn bool
|
||||||
|
|
||||||
WebRoot string
|
WebRoot string
|
||||||
|
|
||||||
@@ -82,11 +99,24 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入服务名称")
|
Require("请输入服务名称")
|
||||||
|
|
||||||
if params.ClusterId <= 0 {
|
var clusterId = params.ClusterId
|
||||||
this.Fail("请选择部署的集群")
|
|
||||||
|
// 用户
|
||||||
|
var userId = params.UserId
|
||||||
|
if userId > 0 {
|
||||||
|
clusterIdResp, err := this.RPC().UserRPC().FindUserNodeClusterId(this.AdminContext(), &pb.FindUserNodeClusterIdRequest{UserId: userId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clusterId = clusterIdResp.NodeClusterId
|
||||||
|
if clusterId <= 0 {
|
||||||
|
this.Fail("请选择部署的集群")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 验证集群ID
|
// 套餐
|
||||||
|
var userPlanId = params.UserPlanId
|
||||||
|
|
||||||
// 端口地址
|
// 端口地址
|
||||||
var httpConfig *serverconfigs.HTTPProtocolConfig = nil
|
var httpConfig *serverconfigs.HTTPProtocolConfig = nil
|
||||||
@@ -256,7 +286,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
if len(allServerNames) > 0 {
|
if len(allServerNames) > 0 {
|
||||||
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
||||||
ServerNames: allServerNames,
|
ServerNames: allServerNames,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: clusterId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -335,7 +365,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
webId = webResp.WebId
|
webId = webResp.HttpWebId
|
||||||
}
|
}
|
||||||
|
|
||||||
// 包含条件
|
// 包含条件
|
||||||
@@ -355,13 +385,14 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req := &pb.CreateServerRequest{
|
req := &pb.CreateServerRequest{
|
||||||
UserId: 0,
|
UserId: userId,
|
||||||
|
UserPlanId: userPlanId,
|
||||||
AdminId: this.AdminId(),
|
AdminId: this.AdminId(),
|
||||||
Type: params.ServerType,
|
Type: params.ServerType,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
ServerNamesJON: []byte(params.ServerNames),
|
ServerNamesJON: []byte(params.ServerNames),
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
NodeClusterId: params.ClusterId,
|
NodeClusterId: clusterId,
|
||||||
IncludeNodesJSON: includeNodesJSON,
|
IncludeNodesJSON: includeNodesJSON,
|
||||||
ExcludeNodesJSON: excludeNodesJSON,
|
ExcludeNodesJSON: excludeNodesJSON,
|
||||||
WebId: webId,
|
WebId: webId,
|
||||||
@@ -432,11 +463,11 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
// 访问日志
|
// 访问日志
|
||||||
if params.AccessLogIsOn {
|
if params.AccessLogIsOn {
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
||||||
WebId: webConfig.Id,
|
HttpWebId: webConfig.Id,
|
||||||
AccessLogJSON: []byte(`{
|
AccessLogJSON: []byte(`{
|
||||||
"isPrior": false,
|
"isPrior": false,
|
||||||
"isOn": true,
|
"isOn": true,
|
||||||
"fields": [],
|
"fields": [1, 2, 6, 7],
|
||||||
"status1": true,
|
"status1": true,
|
||||||
"status2": true,
|
"status2": true,
|
||||||
"status3": true,
|
"status3": true,
|
||||||
@@ -471,7 +502,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
} else {
|
} else {
|
||||||
websocketId := createWebSocketResp.WebsocketId
|
websocketId := createWebSocketResp.WebsocketId
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{
|
||||||
WebId: webConfig.Id,
|
HttpWebId: webConfig.Id,
|
||||||
WebsocketJSON: []byte(` {
|
WebsocketJSON: []byte(` {
|
||||||
"isPrior": false,
|
"isPrior": false,
|
||||||
"isOn": true,
|
"isOn": true,
|
||||||
@@ -483,6 +514,96 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache
|
||||||
|
if params.CacheIsOn {
|
||||||
|
var cacheConfig = &serverconfigs.HTTPCacheConfig{
|
||||||
|
IsPrior: false,
|
||||||
|
IsOn: true,
|
||||||
|
AddStatusHeader: true,
|
||||||
|
PurgeIsOn: false,
|
||||||
|
PurgeKey: "",
|
||||||
|
CacheRefs: []*serverconfigs.HTTPCacheRef{},
|
||||||
|
}
|
||||||
|
cacheConfigJSON, err := json.Marshal(cacheConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
||||||
|
HttpWebId: webConfig.Id,
|
||||||
|
CacheJSON: cacheConfigJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// waf
|
||||||
|
if params.WafIsOn {
|
||||||
|
var firewallRef = &firewallconfigs.HTTPFirewallRef{
|
||||||
|
IsPrior: false,
|
||||||
|
IsOn: true,
|
||||||
|
FirewallPolicyId: 0,
|
||||||
|
}
|
||||||
|
firewallRefJSON, err := json.Marshal(firewallRef)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
||||||
|
HttpWebId: webConfig.Id,
|
||||||
|
FirewallJSON: firewallRefJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remoteAddr
|
||||||
|
var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{
|
||||||
|
IsOn: true,
|
||||||
|
Value: "${rawRemoteAddr}",
|
||||||
|
}
|
||||||
|
if params.RemoteAddrIsOn {
|
||||||
|
remoteAddrConfig.Value = "${remoteAddr}"
|
||||||
|
}
|
||||||
|
remoteAddrConfigJSON, err := json.Marshal(remoteAddrConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
||||||
|
HttpWebId: webConfig.Id,
|
||||||
|
RemoteAddrJSON: remoteAddrConfigJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计
|
||||||
|
if params.StatIsOn {
|
||||||
|
var statConfig = &serverconfigs.HTTPStatRef{
|
||||||
|
IsPrior: false,
|
||||||
|
IsOn: true,
|
||||||
|
}
|
||||||
|
statJSON, err := json.Marshal(statConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{
|
||||||
|
HttpWebId: webConfig.Id,
|
||||||
|
StatJSON: statJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user