Compare commits
86 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 |
@@ -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/
|
||||||
|
|||||||
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()
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -11,7 +11,7 @@ require (
|
|||||||
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-20211026123858-7de7a21cad24
|
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/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/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -68,6 +68,8 @@ github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24 h1:1cGulkD2SNJJRok5OKw
|
|||||||
github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
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 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
|||||||
@@ -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.5"
|
Version = "0.3.7"
|
||||||
|
|
||||||
APINodeVersion = "0.3.5"
|
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")
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -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))
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
@@ -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",
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"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 {
|
||||||
@@ -65,22 +66,32 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(cluster.TimeZone)
|
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(cluster.TimeZone)
|
||||||
|
|
||||||
this.Data["cluster"] = maps.Map{
|
this.Data["cluster"] = maps.Map{
|
||||||
"id": cluster.Id,
|
"id": cluster.Id,
|
||||||
"name": cluster.Name,
|
"name": cluster.Name,
|
||||||
"installDir": cluster.InstallDir,
|
"installDir": cluster.InstallDir,
|
||||||
"timeZone": cluster.TimeZone,
|
"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
|
TimeZone string
|
||||||
|
NodeMaxThreads int32
|
||||||
|
NodeTCPMaxConnections int32
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -91,12 +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,
|
TimeZone: params.TimeZone,
|
||||||
|
NodeMaxThreads: params.NodeMaxThreads,
|
||||||
|
NodeTCPMaxConnections: params.NodeTCPMaxConnections,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
PrivateKey string
|
PrivateKey string
|
||||||
Passphrase string
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -61,6 +62,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
Passphrase: params.Passphrase,
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
Su: params.Su,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
PrivateKey string
|
PrivateKey string
|
||||||
Passphrase string
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -62,6 +63,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
Passphrase: params.Passphrase,
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
Su: params.Su,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -74,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,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
PrivateKey string
|
PrivateKey string
|
||||||
Passphrase string
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -97,6 +98,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
PrivateKey: params.PrivateKey,
|
PrivateKey: params.PrivateKey,
|
||||||
Passphrase: params.Passphrase,
|
Passphrase: params.Passphrase,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
Su: params.Su,
|
||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
|||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": grant.PrivateKey,
|
||||||
"passphrase": grant.Passphrase,
|
"passphrase": grant.Passphrase,
|
||||||
|
"su": grant.Su,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
@@ -59,6 +60,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
PrivateKey string
|
PrivateKey string
|
||||||
Passphrase string
|
Passphrase string
|
||||||
Description string
|
Description string
|
||||||
|
Su bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
@@ -96,6 +98,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Passphrase: params.Passphrase,
|
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)
|
||||||
@@ -108,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()
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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{}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,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)).
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ 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()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +89,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
CacheIsOn bool
|
CacheIsOn bool
|
||||||
WafIsOn bool
|
WafIsOn bool
|
||||||
RemoteAddrIsOn bool
|
RemoteAddrIsOn bool
|
||||||
|
StatIsOn bool
|
||||||
|
|
||||||
WebRoot string
|
WebRoot string
|
||||||
|
|
||||||
@@ -94,14 +103,16 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
|
|
||||||
// 用户
|
// 用户
|
||||||
var userId = params.UserId
|
var userId = params.UserId
|
||||||
clusterIdResp, err := this.RPC().UserRPC().FindUserNodeClusterId(this.AdminContext(), &pb.FindUserNodeClusterIdRequest{UserId: userId})
|
if userId > 0 {
|
||||||
if err != nil {
|
clusterIdResp, err := this.RPC().UserRPC().FindUserNodeClusterId(this.AdminContext(), &pb.FindUserNodeClusterIdRequest{UserId: userId})
|
||||||
this.ErrorPage(err)
|
if err != nil {
|
||||||
return
|
this.ErrorPage(err)
|
||||||
}
|
return
|
||||||
clusterId = clusterIdResp.NodeClusterId
|
}
|
||||||
if clusterId <= 0 {
|
clusterId = clusterIdResp.NodeClusterId
|
||||||
this.Fail("请选择部署的集群")
|
if clusterId <= 0 {
|
||||||
|
this.Fail("请选择部署的集群")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 套餐
|
// 套餐
|
||||||
@@ -354,7 +365,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
webId = webResp.WebId
|
webId = webResp.HttpWebId
|
||||||
}
|
}
|
||||||
|
|
||||||
// 包含条件
|
// 包含条件
|
||||||
@@ -452,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,
|
||||||
@@ -491,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,
|
||||||
@@ -520,7 +531,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
||||||
WebId: webConfig.Id,
|
HttpWebId: webConfig.Id,
|
||||||
CacheJSON: cacheConfigJSON,
|
CacheJSON: cacheConfigJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -542,7 +553,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
||||||
WebId: webConfig.Id,
|
HttpWebId: webConfig.Id,
|
||||||
FirewallJSON: firewallRefJSON,
|
FirewallJSON: firewallRefJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -565,13 +576,34 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
||||||
WebId: webConfig.Id,
|
HttpWebId: webConfig.Id,
|
||||||
RemoteAddrJSON: remoteAddrConfigJSON,
|
RemoteAddrJSON: remoteAddrConfigJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ type FixLogAction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *FixLogAction) RunPost(params struct {
|
func (this *FixLogAction) RunPost(params struct {
|
||||||
LogId int64
|
LogIds []int64
|
||||||
}) {
|
}) {
|
||||||
_, err := this.RPC().NodeLogRPC().FixNodeLog(this.AdminContext(), &pb.FixNodeLogRequest{NodeLogId: params.LogId})
|
_, err := this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: params.LogIds})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -144,6 +144,15 @@ func InitGroup(parent *actionutils.ParentAction, groupId int64, menuItem string)
|
|||||||
"isActive": menuItem == "remoteAddr",
|
"isActive": menuItem == "remoteAddr",
|
||||||
"isOn": configInfoResp.HasRemoteAddrConfig,
|
"isOn": configInfoResp.HasRemoteAddrConfig,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if teaconst.IsPlus {
|
||||||
|
leftMenuItems = append(leftMenuItems, maps.Map{
|
||||||
|
"name": "请求限制",
|
||||||
|
"url": urlPrefix + "/requestLimit?groupId=" + types.String(groupId),
|
||||||
|
"isActive": menuItem == "requestLimit",
|
||||||
|
"isOn": configInfoResp.HasRequestLimitConfig,
|
||||||
|
})
|
||||||
|
}
|
||||||
parent.Data["leftMenuItems"] = leftMenuItems
|
parent.Data["leftMenuItems"] = leftMenuItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查参数
|
// TODO 检查参数
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
AccessLogJSON: params.AccessLogJSON,
|
AccessLogJSON: params.AccessLogJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CacheJSON: cacheJSON,
|
CacheJSON: cacheJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的字符集设置", params.WebId)
|
defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的字符集设置", params.WebId)
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CharsetJSON: params.CharsetJSON,
|
CharsetJSON: params.CharsetJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CompressionJSON: params.CompressionJSON,
|
CompressionJSON: params.CompressionJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
||||||
WebId: webId,
|
HttpWebId: webId,
|
||||||
HeaderJSON: refJSON,
|
HeaderJSON: refJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,7 +82,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
||||||
WebId: webId,
|
HttpWebId: webId,
|
||||||
HeaderJSON: refJSON,
|
HeaderJSON: refJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -129,7 +129,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
HeaderJSON: params.RequestHeaderJSON,
|
HeaderJSON: params.RequestHeaderJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -145,7 +145,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
HeaderJSON: params.ResponseHeaderJSON,
|
HeaderJSON: params.ResponseHeaderJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查配置
|
// TODO 检查配置
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
PagesJSON: []byte(params.PagesJSON),
|
PagesJSON: []byte(params.PagesJSON),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -61,7 +61,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
ShutdownJSON: []byte(params.ShutdownJSON),
|
ShutdownJSON: []byte(params.ShutdownJSON),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
RemoteAddrJSON: params.RemoteAddrJSON,
|
RemoteAddrJSON: params.RemoteAddrJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package requestlimit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "setting", "index")
|
||||||
|
this.SecondMenu("requestLimit")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
GroupId int64
|
||||||
|
}) {
|
||||||
|
_, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "requestLimit")
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["webId"] = webConfig.Id
|
||||||
|
this.Data["requestLimitConfig"] = webConfig.RequestLimit
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
WebId int64
|
||||||
|
RequestLimitJSON []byte
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改Web %d 请求限制", params.WebId)
|
||||||
|
|
||||||
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRequestLimit(this.AdminContext(), &pb.UpdateHTTPWebRequestLimitRequest{
|
||||||
|
HttpWebId: params.WebId,
|
||||||
|
RequestLimitJSON: params.RequestLimitJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package requestlimit
|
||||||
|
|
||||||
|
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)).
|
||||||
|
Data("teaMenu", "servers").
|
||||||
|
Data("teaSubMenu", "group").
|
||||||
|
Prefix("/servers/groups/group/settings/requestLimit").
|
||||||
|
GetPost("", new(IndexAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -49,8 +49,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 校验配置
|
// TODO 校验配置
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
StatJSON: params.StatJSON,
|
StatJSON: params.StatJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查配置
|
// TODO 检查配置
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
FirewallJSON: params.FirewallJSON,
|
FirewallJSON: params.FirewallJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
defer this.CreateLogInfo("修改Web %d 的首页文件名", params.WebId)
|
defer this.CreateLogInfo("修改Web %d 的首页文件名", params.WebId)
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWeb(this.AdminContext(), &pb.UpdateHTTPWebRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWeb(this.AdminContext(), &pb.UpdateHTTPWebRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
RootJSON: params.RootJSON,
|
RootJSON: params.RootJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebP(this.AdminContext(), &pb.UpdateHTTPWebWebPRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebP(this.AdminContext(), &pb.UpdateHTTPWebWebPRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
WebpJSON: params.WebpJSON,
|
WebpJSON: params.WebpJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
WebsocketJSON: websocketRefJSON,
|
WebsocketJSON: websocketRefJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -199,6 +199,12 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提交审核时间
|
||||||
|
var auditingTime = ""
|
||||||
|
if server.AuditingAt > 0 {
|
||||||
|
auditingTime = timeutil.FormatTime("Y-m-d", server.AuditingAt)
|
||||||
|
}
|
||||||
|
|
||||||
serverMaps = append(serverMaps, maps.Map{
|
serverMaps = append(serverMaps, maps.Map{
|
||||||
"id": server.Id,
|
"id": server.Id,
|
||||||
"isOn": server.IsOn,
|
"isOn": server.IsOn,
|
||||||
@@ -215,6 +221,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
"isAuditing": server.IsAuditing,
|
"isAuditing": server.IsAuditing,
|
||||||
"auditingIsOk": auditingIsOk,
|
"auditingIsOk": auditingIsOk,
|
||||||
"user": userMap,
|
"user": userMap,
|
||||||
|
"auditingTime": auditingTime,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["servers"] = serverMaps
|
this.Data["servers"] = serverMaps
|
||||||
@@ -258,7 +265,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
NodeId: 0,
|
NodeId: 0,
|
||||||
Role: nodeconfigs.NodeRoleNode,
|
Role: nodeconfigs.NodeRoleNode,
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
Size: 10,
|
Size: 20,
|
||||||
Level: "",
|
Level: "",
|
||||||
FixedState: int32(configutils.BoolStateNo),
|
FixedState: int32(configutils.BoolStateNo),
|
||||||
AllServers: true,
|
AllServers: true,
|
||||||
@@ -279,7 +286,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
var server = serverResp.Server
|
var server = serverResp.Server
|
||||||
if server == nil {
|
if server == nil {
|
||||||
// 设置为已修复
|
// 设置为已修复
|
||||||
_, err = this.RPC().NodeLogRPC().FixNodeLog(this.AdminContext(), &pb.FixNodeLogRequest{NodeLogId: errorLog.Id})
|
_, err = this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: []int64{errorLog.Id}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
@@ -297,7 +304,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
var node = nodeResp.Node
|
var node = nodeResp.Node
|
||||||
if node == nil || node.NodeCluster == nil {
|
if node == nil || node.NodeCluster == nil {
|
||||||
// 设置为已修复
|
// 设置为已修复
|
||||||
_, err = this.RPC().NodeLogRPC().FixNodeLog(this.AdminContext(), &pb.FixNodeLogRequest{NodeLogId: errorLog.Id})
|
_, err = this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: []int64{errorLog.Id}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -14,19 +14,30 @@ type AddIPAction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *AddIPAction) RunPost(params struct {
|
func (this *AddIPAction) RunPost(params struct {
|
||||||
ListId int64
|
ListId int64
|
||||||
Ip string
|
Ip string
|
||||||
|
ExpiredAt int64
|
||||||
}) {
|
}) {
|
||||||
|
var itemId int64 = 0
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
this.CreateLogInfo("在名单 %d 中创建IP %d", params.ListId, itemId)
|
||||||
|
}()
|
||||||
|
|
||||||
var ipType = "ipv4"
|
var ipType = "ipv4"
|
||||||
if strings.Contains(params.Ip, ":") {
|
if strings.Contains(params.Ip, ":") {
|
||||||
ipType = "ipv6"
|
ipType = "ipv6"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
|
if params.ExpiredAt <= 0 {
|
||||||
|
params.ExpiredAt = time.Now().Unix() + 86400
|
||||||
|
}
|
||||||
|
|
||||||
|
createResp, err := this.RPC().IPItemRPC().CreateIPItem(this.AdminContext(), &pb.CreateIPItemRequest{
|
||||||
IpListId: params.ListId,
|
IpListId: params.ListId,
|
||||||
IpFrom: params.Ip,
|
IpFrom: params.Ip,
|
||||||
IpTo: "",
|
IpTo: "",
|
||||||
ExpiredAt: time.Now().Unix() + 86400, // TODO 可以自定义时间
|
ExpiredAt: params.ExpiredAt,
|
||||||
Reason: "从IPBox中加入名单",
|
Reason: "从IPBox中加入名单",
|
||||||
Type: ipType,
|
Type: ipType,
|
||||||
EventLevel: "critical",
|
EventLevel: "critical",
|
||||||
@@ -36,5 +47,7 @@ func (this *AddIPAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemId = createResp.IpItemId
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
27
internal/web/actions/default/servers/ipbox/deleteFromList.go
Normal file
27
internal/web/actions/default/servers/ipbox/deleteFromList.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package ipbox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteFromListAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DeleteFromListAction) RunPost(params struct {
|
||||||
|
ListId int64
|
||||||
|
ItemId int64
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("从IP名单 %d 中删除IP %d", params.ListId, params.ItemId)
|
||||||
|
|
||||||
|
_, err := this.RPC().IPItemRPC().DeleteIPItem(this.AdminContext(), &pb.DeleteIPItemRequest{IpItemId: params.ItemId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -37,17 +37,44 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["isp"] = regionResp.IpRegion.Isp
|
this.Data["isp"] = regionResp.IpRegion.Isp
|
||||||
|
|
||||||
// IP列表
|
// IP列表
|
||||||
ipListResp, err := this.RPC().IPListRPC().FindEnabledIPListContainsIP(this.AdminContext(), &pb.FindEnabledIPListContainsIPRequest{Ip: params.Ip})
|
ipListResp, err := this.RPC().IPListRPC().FindEnabledIPListContainsIP(this.AdminContext(), &pb.FindEnabledIPListContainsIPRequest{
|
||||||
|
Ip: params.Ip,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var ipListMaps = []maps.Map{}
|
var ipListMaps = []maps.Map{}
|
||||||
for _, ipList := range ipListResp.IpLists {
|
for _, ipList := range ipListResp.IpLists {
|
||||||
|
itemsResp, err := this.RPC().IPItemRPC().ListIPItemsWithListId(this.AdminContext(), &pb.ListIPItemsWithListIdRequest{
|
||||||
|
IpListId: ipList.Id,
|
||||||
|
Keyword: "",
|
||||||
|
IpFrom: params.Ip,
|
||||||
|
IpTo: "",
|
||||||
|
Offset: 0,
|
||||||
|
Size: 1,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var items = itemsResp.IpItems
|
||||||
|
if len(items) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var item = items[0]
|
||||||
|
|
||||||
|
var expiredTime = ""
|
||||||
|
if item.ExpiredAt > 0 {
|
||||||
|
expiredTime = timeutil.FormatTime("Y-m-d H:i:s", item.ExpiredAt)
|
||||||
|
}
|
||||||
|
|
||||||
ipListMaps = append(ipListMaps, maps.Map{
|
ipListMaps = append(ipListMaps, maps.Map{
|
||||||
"id": ipList.Id,
|
"id": ipList.Id,
|
||||||
"name": ipList.Name,
|
"name": ipList.Name,
|
||||||
"type": ipList.Type,
|
"type": ipList.Type,
|
||||||
|
"itemExpiredTime": expiredTime,
|
||||||
|
"itemId": item.Id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["ipLists"] = ipListMaps
|
this.Data["ipLists"] = ipListMaps
|
||||||
@@ -58,7 +85,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
IsPublic: true,
|
IsPublic: true,
|
||||||
Keyword: "",
|
Keyword: "",
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
Size: 10, // TODO 将来考虑到支持更多的黑名单
|
Size: 20, // TODO 将来考虑到支持更多的黑名单
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ func init() {
|
|||||||
Prefix("/servers/ipbox").
|
Prefix("/servers/ipbox").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
Post("/addIP", new(AddIPAction)).
|
Post("/addIP", new(AddIPAction)).
|
||||||
|
Post("/deleteFromList", new(DeleteFromListAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package logs
|
package logs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -29,6 +31,8 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
|
|
||||||
RequestId string
|
RequestId string
|
||||||
ServerId int64
|
ServerId int64
|
||||||
|
|
||||||
|
PageSize int64
|
||||||
}) {
|
}) {
|
||||||
if len(params.Day) == 0 {
|
if len(params.Day) == 0 {
|
||||||
params.Day = timeutil.Format("Y-m-d")
|
params.Day = timeutil.Format("Y-m-d")
|
||||||
@@ -43,16 +47,23 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["accessLogs"] = []interface{}{}
|
this.Data["accessLogs"] = []interface{}{}
|
||||||
this.Data["hasError"] = params.HasError
|
this.Data["hasError"] = params.HasError
|
||||||
this.Data["hasWAF"] = params.HasWAF
|
this.Data["hasWAF"] = params.HasWAF
|
||||||
|
this.Data["pageSize"] = params.PageSize
|
||||||
|
this.Data["isSlowQuery"] = false
|
||||||
|
this.Data["slowQueryCost"] = ""
|
||||||
|
|
||||||
day := params.Day
|
day := params.Day
|
||||||
ipList := []string{}
|
ipList := []string{}
|
||||||
|
|
||||||
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||||||
day = strings.ReplaceAll(day, "-", "")
|
day = strings.ReplaceAll(day, "-", "")
|
||||||
size := int64(10)
|
size := params.PageSize
|
||||||
|
if size < 1 {
|
||||||
|
size = 20
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["hasError"] = params.HasError
|
this.Data["hasError"] = params.HasError
|
||||||
|
|
||||||
|
var before = time.Now()
|
||||||
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||||||
RequestId: params.RequestId,
|
RequestId: params.RequestId,
|
||||||
ServerId: params.ServerId,
|
ServerId: params.ServerId,
|
||||||
@@ -69,6 +80,12 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cost = time.Since(before).Seconds()
|
||||||
|
if cost > 5 {
|
||||||
|
this.Data["slowQueryCost"] = fmt.Sprintf("%.2f", cost)
|
||||||
|
this.Data["isSlowQuery"] = true
|
||||||
|
}
|
||||||
|
|
||||||
if len(resp.HttpAccessLogs) == 0 {
|
if len(resp.HttpAccessLogs) == 0 {
|
||||||
this.Data["accessLogs"] = []interface{}{}
|
this.Data["accessLogs"] = []interface{}{}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ func init() {
|
|||||||
Data("teaSubMenu", "log").
|
Data("teaSubMenu", "log").
|
||||||
Prefix("/servers/logs").
|
Prefix("/servers/logs").
|
||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
|
GetPost("/settings", new(SettingsAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
94
internal/web/actions/default/servers/logs/settings.go
Normal file
94
internal/web/actions/default/servers/logs/settings.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package logs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SettingsAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SettingsAction) Init() {
|
||||||
|
this.Nav("", "", "settings")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SettingsAction) RunGet(params struct{}) {
|
||||||
|
settingsResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeAccessLogQueue})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = &serverconfigs.AccessLogQueueConfig{
|
||||||
|
MaxLength: 0,
|
||||||
|
CountPerSecond: 0,
|
||||||
|
Percent: 100,
|
||||||
|
}
|
||||||
|
if len(settingsResp.ValueJSON) > 0 {
|
||||||
|
err = json.Unmarshal(settingsResp.ValueJSON, config)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
configJSON, err := json.Marshal(config)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||||
|
Code: systemconfigs.SettingCodeAccessLogQueue,
|
||||||
|
ValueJSON: configJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["config"] = config
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *SettingsAction) RunPost(params struct {
|
||||||
|
Percent int
|
||||||
|
CountPerSecond int
|
||||||
|
MaxLength int
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
params.Must.
|
||||||
|
Field("percent", params.Percent).
|
||||||
|
Gte(0, "请输入大于0的整数").
|
||||||
|
Lte(100, "请输入小于100的整数")
|
||||||
|
|
||||||
|
var config = &serverconfigs.AccessLogQueueConfig{
|
||||||
|
MaxLength: params.MaxLength,
|
||||||
|
CountPerSecond: params.CountPerSecond,
|
||||||
|
Percent: params.Percent,
|
||||||
|
}
|
||||||
|
configJSON, err := json.Marshal(config)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||||
|
Code: systemconfigs.SettingCodeAccessLogQueue,
|
||||||
|
ValueJSON: configJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package boards
|
package boards
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
@@ -120,6 +122,22 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
this.Data["topDomainStats"] = statMaps
|
this.Data["topDomainStats"] = statMaps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 地区排行
|
||||||
|
{
|
||||||
|
var countryMaps = []maps.Map{}
|
||||||
|
for _, stat := range resp.TopCountryStats {
|
||||||
|
countryMaps = append(countryMaps, maps.Map{
|
||||||
|
"name": stat.CountryName,
|
||||||
|
"bytes": stat.Bytes,
|
||||||
|
"formattedBytes": numberutils.FormatBytes(stat.Bytes),
|
||||||
|
"countRequests": stat.CountRequests,
|
||||||
|
"countAttackRequests": stat.CountAttackRequests,
|
||||||
|
"percent": fmt.Sprintf("%.2f", stat.Percent),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["topCountryStats"] = countryMaps
|
||||||
|
}
|
||||||
|
|
||||||
// 指标
|
// 指标
|
||||||
{
|
{
|
||||||
var chartMaps = []maps.Map{}
|
var chartMaps = []maps.Map{}
|
||||||
@@ -157,5 +175,6 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
this.Data["metricCharts"] = chartMaps
|
this.Data["metricCharts"] = chartMaps
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ func (this *HistoryAction) RunGet(params struct {
|
|||||||
|
|
||||||
RequestId string
|
RequestId string
|
||||||
HasError int
|
HasError int
|
||||||
|
|
||||||
|
PageSize int
|
||||||
}) {
|
}) {
|
||||||
if len(params.Day) == 0 {
|
if len(params.Day) == 0 {
|
||||||
params.Day = timeutil.Format("Y-m-d")
|
params.Day = timeutil.Format("Y-m-d")
|
||||||
@@ -41,13 +43,17 @@ func (this *HistoryAction) RunGet(params struct {
|
|||||||
this.Data["accessLogs"] = []interface{}{}
|
this.Data["accessLogs"] = []interface{}{}
|
||||||
this.Data["hasError"] = params.HasError
|
this.Data["hasError"] = params.HasError
|
||||||
this.Data["hasWAF"] = params.HasWAF
|
this.Data["hasWAF"] = params.HasWAF
|
||||||
|
this.Data["pageSize"] = params.PageSize
|
||||||
|
|
||||||
day := params.Day
|
day := params.Day
|
||||||
ipList := []string{}
|
ipList := []string{}
|
||||||
|
|
||||||
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||||||
day = strings.ReplaceAll(day, "-", "")
|
day = strings.ReplaceAll(day, "-", "")
|
||||||
size := int64(10)
|
size := int64(params.PageSize)
|
||||||
|
if size < 1 {
|
||||||
|
size = 20
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["hasError"] = params.HasError
|
this.Data["hasError"] = params.HasError
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,15 @@ func (this *TodayAction) RunGet(params struct {
|
|||||||
Keyword string
|
Keyword string
|
||||||
Ip string
|
Ip string
|
||||||
Domain string
|
Domain string
|
||||||
|
|
||||||
|
PageSize int
|
||||||
}) {
|
}) {
|
||||||
size := int64(10)
|
this.Data["pageSize"] = params.PageSize
|
||||||
|
|
||||||
|
size := int64(params.PageSize)
|
||||||
|
if size < 1 {
|
||||||
|
size = 20
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["path"] = this.Request.URL.Path
|
this.Data["path"] = this.Request.URL.Path
|
||||||
this.Data["hasError"] = params.HasError
|
this.Data["hasError"] = params.HasError
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ViewPopupAction struct {
|
type ViewPopupAction struct {
|
||||||
@@ -98,5 +99,19 @@ func (this *ViewPopupAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
this.Data["region"] = regionMap
|
this.Data["region"] = regionMap
|
||||||
|
|
||||||
|
// 请求内容
|
||||||
|
this.Data["requestBody"] = string(accessLog.RequestBody)
|
||||||
|
this.Data["requestContentType"] = "text/plain"
|
||||||
|
|
||||||
|
requestContentType, ok := accessLog.Header["Content-Type"]
|
||||||
|
if ok {
|
||||||
|
if len(requestContentType.Values) > 0 {
|
||||||
|
var contentType = requestContentType.Values[0]
|
||||||
|
if strings.HasSuffix(contentType, "/json") || strings.Contains(contentType, "/json;") {
|
||||||
|
this.Data["requestContentType"] = "application/json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAuth(this.AdminContext(), &pb.UpdateHTTPWebAuthRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAuth(this.AdminContext(), &pb.UpdateHTTPWebAuthRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
AuthJSON: configJSON,
|
AuthJSON: configJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查参数
|
// TODO 检查参数
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
AccessLogJSON: params.AccessLogJSON,
|
AccessLogJSON: params.AccessLogJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CacheJSON: cacheJSON,
|
CacheJSON: cacheJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的字符集设置", params.WebId)
|
defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的字符集设置", params.WebId)
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CharsetJSON: params.CharsetJSON,
|
CharsetJSON: params.CharsetJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IndexAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) Init() {
|
||||||
|
this.Nav("", "setting", "index")
|
||||||
|
this.SecondMenu("common")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunGet(params struct {
|
||||||
|
ServerId int64
|
||||||
|
}) {
|
||||||
|
this.Data["hasGroupConfig"] = false
|
||||||
|
|
||||||
|
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["webId"] = webConfig.Id
|
||||||
|
|
||||||
|
this.Data["commonConfig"] = maps.Map{
|
||||||
|
"mergeSlashes": webConfig.MergeSlashes,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
WebId int64
|
||||||
|
MergeSlashes bool
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
CSRF *actionutils.CSRF
|
||||||
|
}) {
|
||||||
|
defer this.CreateLogInfo("修改服务Web %d 设置的其他设置", params.WebId)
|
||||||
|
|
||||||
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCommon(this.AdminContext(), &pb.UpdateHTTPWebCommonRequest{
|
||||||
|
HttpWebId: params.WebId,
|
||||||
|
MergeSlashes: params.MergeSlashes,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||||
|
"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)).
|
||||||
|
Helper(serverutils.NewServerHelper()).
|
||||||
|
Prefix("/servers/server/settings/common").
|
||||||
|
GetPost("", new(IndexAction)).
|
||||||
|
EndAll()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -71,7 +71,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CompressionJSON: params.CompressionJSON,
|
CompressionJSON: params.CompressionJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CondJSComponent struct {
|
type CondJSComponent struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Component string `json:"component"`
|
Component string `json:"component"`
|
||||||
ParamsTitle string `json:"paramsTitle"`
|
ParamsTitle string `json:"paramsTitle"`
|
||||||
IsRequest bool `json:"isRequest"`
|
IsRequest bool `json:"isRequest"`
|
||||||
|
CaseInsensitive bool `json:"caseInsensitive"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadAllAvailableCondTypes 读取所有可用的条件
|
// ReadAllAvailableCondTypes 读取所有可用的条件
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFastcgi(this.AdminContext(), &pb.UpdateHTTPWebFastcgiRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFastcgi(this.AdminContext(), &pb.UpdateHTTPWebFastcgiRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
FastcgiJSON: fastcgiRefJSON,
|
FastcgiJSON: fastcgiRefJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ func (this *CreateSetPopupAction) Init() {
|
|||||||
|
|
||||||
func (this *CreateSetPopupAction) RunGet(params struct {
|
func (this *CreateSetPopupAction) RunGet(params struct {
|
||||||
HeaderPolicyId int64
|
HeaderPolicyId int64
|
||||||
|
Type string
|
||||||
}) {
|
}) {
|
||||||
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
||||||
|
this.Data["type"] = params.Type
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
@@ -30,6 +32,14 @@ func (this *CreateSetPopupAction) RunPost(params struct {
|
|||||||
Name string
|
Name string
|
||||||
Value string
|
Value string
|
||||||
|
|
||||||
|
StatusListJSON []byte
|
||||||
|
MethodsJSON []byte
|
||||||
|
DomainsJSON []byte
|
||||||
|
ShouldAppend bool
|
||||||
|
DisableRedirect bool
|
||||||
|
ShouldReplace bool
|
||||||
|
ReplaceValuesJSON []byte
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
// 日志
|
// 日志
|
||||||
@@ -51,10 +61,57 @@ func (this *CreateSetPopupAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// status list
|
||||||
|
var statusList = []int32{}
|
||||||
|
if len(params.StatusListJSON) > 0 {
|
||||||
|
err = json.Unmarshal(params.StatusListJSON, &statusList)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// methods
|
||||||
|
var methods = []string{}
|
||||||
|
if len(params.MethodsJSON) > 0 {
|
||||||
|
err = json.Unmarshal(params.MethodsJSON, &methods)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// domains
|
||||||
|
var domains = []string{}
|
||||||
|
if len(params.DomainsJSON) > 0 {
|
||||||
|
err = json.Unmarshal(params.DomainsJSON, &domains)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace values
|
||||||
|
var replaceValues = []*shared.HTTPHeaderReplaceValue{}
|
||||||
|
if len(params.ReplaceValuesJSON) > 0 {
|
||||||
|
err = json.Unmarshal(params.ReplaceValuesJSON, &replaceValues)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建Header
|
// 创建Header
|
||||||
createHeaderResp, err := this.RPC().HTTPHeaderRPC().CreateHTTPHeader(this.AdminContext(), &pb.CreateHTTPHeaderRequest{
|
createHeaderResp, err := this.RPC().HTTPHeaderRPC().CreateHTTPHeader(this.AdminContext(), &pb.CreateHTTPHeaderRequest{
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Value: params.Value,
|
Value: params.Value,
|
||||||
|
Status: statusList,
|
||||||
|
Methods: methods,
|
||||||
|
Domains: domains,
|
||||||
|
ShouldAppend: params.ShouldAppend,
|
||||||
|
DisableRedirect: params.DisableRedirect,
|
||||||
|
ShouldReplace: params.ShouldReplace,
|
||||||
|
ReplaceValuesJSON: params.ReplaceValuesJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -35,26 +35,6 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch params.Type {
|
switch params.Type {
|
||||||
case "addHeader":
|
|
||||||
result := []*shared.HTTPHeaderRef{}
|
|
||||||
for _, h := range policyConfig.AddHeaderRefs {
|
|
||||||
if h.HeaderId != params.HeaderId {
|
|
||||||
result = append(result, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultJSON, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyAddingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyAddingHeadersRequest{
|
|
||||||
HeaderPolicyId: params.HeaderPolicyId,
|
|
||||||
HeadersJSON: resultJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case "setHeader":
|
case "setHeader":
|
||||||
result := []*shared.HTTPHeaderRef{}
|
result := []*shared.HTTPHeaderRef{}
|
||||||
for _, h := range policyConfig.SetHeaderRefs {
|
for _, h := range policyConfig.SetHeaderRefs {
|
||||||
@@ -75,46 +55,6 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case "replace":
|
|
||||||
result := []*shared.HTTPHeaderRef{}
|
|
||||||
for _, h := range policyConfig.ReplaceHeaderRefs {
|
|
||||||
if h.HeaderId != params.HeaderId {
|
|
||||||
result = append(result, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultJSON, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyReplacingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyReplacingHeadersRequest{
|
|
||||||
HeaderPolicyId: params.HeaderPolicyId,
|
|
||||||
HeadersJSON: resultJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case "addTrailer":
|
|
||||||
result := []*shared.HTTPHeaderRef{}
|
|
||||||
for _, h := range policyConfig.AddTrailerRefs {
|
|
||||||
if h.HeaderId != params.HeaderId {
|
|
||||||
result = append(result, h)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultJSON, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyAddingTrailers(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyAddingTrailersRequest{
|
|
||||||
HeaderPolicyId: params.HeaderPolicyId,
|
|
||||||
HeadersJSON: resultJSON,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
||||||
WebId: webId,
|
HttpWebId: webId,
|
||||||
HeaderJSON: refJSON,
|
HeaderJSON: refJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -86,7 +86,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
||||||
WebId: webId,
|
HttpWebId: webId,
|
||||||
HeaderJSON: refJSON,
|
HeaderJSON: refJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ func (this *UpdateSetPopupAction) Init() {
|
|||||||
func (this *UpdateSetPopupAction) RunGet(params struct {
|
func (this *UpdateSetPopupAction) RunGet(params struct {
|
||||||
HeaderPolicyId int64
|
HeaderPolicyId int64
|
||||||
HeaderId int64
|
HeaderId int64
|
||||||
|
Type string
|
||||||
}) {
|
}) {
|
||||||
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
||||||
this.Data["headerId"] = params.HeaderId
|
this.Data["headerId"] = params.HeaderId
|
||||||
|
this.Data["type"] = params.Type
|
||||||
|
|
||||||
headerResp, err := this.RPC().HTTPHeaderRPC().FindEnabledHTTPHeaderConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderConfigRequest{HeaderId: params.HeaderId})
|
headerResp, err := this.RPC().HTTPHeaderRPC().FindEnabledHTTPHeaderConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderConfigRequest{HeaderId: params.HeaderId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -45,6 +47,14 @@ func (this *UpdateSetPopupAction) RunPost(params struct {
|
|||||||
Name string
|
Name string
|
||||||
Value string
|
Value string
|
||||||
|
|
||||||
|
StatusListJSON []byte
|
||||||
|
MethodsJSON []byte
|
||||||
|
DomainsJSON []byte
|
||||||
|
ShouldAppend bool
|
||||||
|
DisableRedirect bool
|
||||||
|
ShouldReplace bool
|
||||||
|
ReplaceValuesJSON []byte
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
// 日志
|
// 日志
|
||||||
@@ -54,10 +64,57 @@ func (this *UpdateSetPopupAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入Header名称")
|
Require("请输入Header名称")
|
||||||
|
|
||||||
|
// status list
|
||||||
|
var statusList = []int32{}
|
||||||
|
if len(params.StatusListJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.StatusListJSON, &statusList)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// methods
|
||||||
|
var methods = []string{}
|
||||||
|
if len(params.MethodsJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.MethodsJSON, &methods)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// domains
|
||||||
|
var domains = []string{}
|
||||||
|
if len(params.DomainsJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.DomainsJSON, &domains)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace values
|
||||||
|
var replaceValues = []*shared.HTTPHeaderReplaceValue{}
|
||||||
|
if len(params.ReplaceValuesJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.ReplaceValuesJSON, &replaceValues)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err := this.RPC().HTTPHeaderRPC().UpdateHTTPHeader(this.AdminContext(), &pb.UpdateHTTPHeaderRequest{
|
_, err := this.RPC().HTTPHeaderRPC().UpdateHTTPHeader(this.AdminContext(), &pb.UpdateHTTPHeaderRequest{
|
||||||
HeaderId: params.HeaderId,
|
HeaderId: params.HeaderId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Value: params.Value,
|
Value: params.Value,
|
||||||
|
Status: statusList,
|
||||||
|
Methods: methods,
|
||||||
|
Domains: domains,
|
||||||
|
ShouldAppend: params.ShouldAppend,
|
||||||
|
DisableRedirect: params.DisableRedirect,
|
||||||
|
ShouldReplace: params.ShouldReplace,
|
||||||
|
ReplaceValuesJSON: params.ReplaceValuesJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// 设置跳转到HTTPS
|
// 设置跳转到HTTPS
|
||||||
// TODO 校验设置
|
// TODO 校验设置
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRedirectToHTTPS(this.AdminContext(), &pb.UpdateHTTPWebRedirectToHTTPSRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRedirectToHTTPS(this.AdminContext(), &pb.UpdateHTTPWebRedirectToHTTPSRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
RedirectToHTTPSJSON: params.RedirectToHTTPSJSON,
|
RedirectToHTTPSJSON: params.RedirectToHTTPSJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAuth(this.AdminContext(), &pb.UpdateHTTPWebAuthRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebAuth(this.AdminContext(), &pb.UpdateHTTPWebAuthRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
AuthJSON: configJSON,
|
AuthJSON: configJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查参数
|
// TODO 检查参数
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
AccessLogJSON: params.AccessLogJSON,
|
AccessLogJSON: params.AccessLogJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CacheJSON: cacheJSON,
|
CacheJSON: cacheJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
defer this.CreateLogInfo("修改Web %d 的字符集设置", params.WebId)
|
defer this.CreateLogInfo("修改Web %d 的字符集设置", params.WebId)
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CharsetJSON: params.CharsetJSON,
|
CharsetJSON: params.CharsetJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCompression(this.AdminContext(), &pb.UpdateHTTPWebCompressionRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
CompressionJSON: params.CompressionJSON,
|
CompressionJSON: params.CompressionJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -51,8 +51,12 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
IsReverse bool
|
IsReverse bool
|
||||||
CondsJSON []byte
|
CondsJSON []byte
|
||||||
|
|
||||||
|
DomainsJSON []byte
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
|
defer this.CreateLogInfo("创建路由规则:%s", params.Pattern)
|
||||||
|
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("pattern", params.Pattern).
|
Field("pattern", params.Pattern).
|
||||||
Require("请输入路径匹配规则")
|
Require("请输入路径匹配规则")
|
||||||
@@ -85,6 +89,21 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
params.Pattern = "/" + strings.TrimLeft(params.Pattern, "/")
|
params.Pattern = "/" + strings.TrimLeft(params.Pattern, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 域名
|
||||||
|
var domains = []string{}
|
||||||
|
if len(params.DomainsJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.DomainsJSON, &domains)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去除可能误加的斜杠
|
||||||
|
for index, domain := range domains {
|
||||||
|
domains[index] = strings.TrimSuffix(domain, "/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
location := &serverconfigs.HTTPLocationConfig{}
|
location := &serverconfigs.HTTPLocationConfig{}
|
||||||
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
|
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
|
||||||
resultPattern := location.Pattern
|
resultPattern := location.Pattern
|
||||||
@@ -96,6 +115,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Pattern: resultPattern,
|
Pattern: resultPattern,
|
||||||
IsBreak: params.IsBreak,
|
IsBreak: params.IsBreak,
|
||||||
CondsJSON: params.CondsJSON,
|
CondsJSON: params.CondsJSON,
|
||||||
|
Domains: domains,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -123,7 +143,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
LocationsJSON: refJSON,
|
LocationsJSON: refJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
LocationsJSON: refJSON,
|
LocationsJSON: refJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFastcgi(this.AdminContext(), &pb.UpdateHTTPWebFastcgiRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebFastcgi(this.AdminContext(), &pb.UpdateHTTPWebFastcgiRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
FastcgiJSON: fastcgiRefJSON,
|
FastcgiJSON: fastcgiRefJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
||||||
WebId: webId,
|
HttpWebId: webId,
|
||||||
HeaderJSON: refJSON,
|
HeaderJSON: refJSON,
|
||||||
})
|
})
|
||||||
isChanged = true
|
isChanged = true
|
||||||
@@ -71,7 +71,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
||||||
WebId: webId,
|
HttpWebId: webId,
|
||||||
HeaderJSON: refJSON,
|
HeaderJSON: refJSON,
|
||||||
})
|
})
|
||||||
isChanged = true
|
isChanged = true
|
||||||
@@ -109,7 +109,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
switch params.Type {
|
switch params.Type {
|
||||||
case "request":
|
case "request":
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
HeaderJSON: params.RequestHeaderJSON,
|
HeaderJSON: params.RequestHeaderJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,7 +118,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
case "response":
|
case "response":
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
HeaderJSON: params.ResponseHeaderJSON,
|
HeaderJSON: params.ResponseHeaderJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// 设置跳转到HTTPS
|
// 设置跳转到HTTPS
|
||||||
// TODO 校验设置
|
// TODO 校验设置
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRedirectToHTTPS(this.AdminContext(), &pb.UpdateHTTPWebRedirectToHTTPSRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRedirectToHTTPS(this.AdminContext(), &pb.UpdateHTTPWebRedirectToHTTPSRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
RedirectToHTTPSJSON: params.RedirectToHTTPSJSON,
|
RedirectToHTTPSJSON: params.RedirectToHTTPSJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["isReverse"] = locationConfig.IsReverse()
|
this.Data["isReverse"] = locationConfig.IsReverse()
|
||||||
this.Data["isCaseInsensitive"] = locationConfig.IsCaseInsensitive()
|
this.Data["isCaseInsensitive"] = locationConfig.IsCaseInsensitive()
|
||||||
this.Data["conds"] = locationConfig.Conds
|
this.Data["conds"] = locationConfig.Conds
|
||||||
|
this.Data["domains"] = locationConfig.Domains
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
@@ -50,6 +51,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
|
|
||||||
CondsJSON []byte
|
CondsJSON []byte
|
||||||
|
|
||||||
|
DomainsJSON []byte
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
defer this.CreateLogInfo("修改路由规则 %d 设置", params.LocationId)
|
defer this.CreateLogInfo("修改路由规则 %d 设置", params.LocationId)
|
||||||
@@ -86,6 +89,21 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 域名
|
||||||
|
var domains = []string{}
|
||||||
|
if len(params.DomainsJSON) > 0 {
|
||||||
|
err := json.Unmarshal(params.DomainsJSON, &domains)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去除可能误加的斜杠
|
||||||
|
for index, domain := range domains {
|
||||||
|
domains[index] = strings.TrimSuffix(domain, "/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
location := &serverconfigs.HTTPLocationConfig{}
|
location := &serverconfigs.HTTPLocationConfig{}
|
||||||
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
|
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
|
||||||
resultPattern := location.Pattern
|
resultPattern := location.Pattern
|
||||||
@@ -98,6 +116,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
IsBreak: params.IsBreak,
|
IsBreak: params.IsBreak,
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
CondsJSON: params.CondsJSON,
|
CondsJSON: params.CondsJSON,
|
||||||
|
Domains: domains,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查配置
|
// TODO 检查配置
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
PagesJSON: []byte(params.PagesJSON),
|
PagesJSON: []byte(params.PagesJSON),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -50,7 +50,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
ShutdownJSON: []byte(params.ShutdownJSON),
|
ShutdownJSON: []byte(params.ShutdownJSON),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRemoteAddr(this.AdminContext(), &pb.UpdateHTTPWebRemoteAddrRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
RemoteAddrJSON: params.RemoteAddrJSON,
|
RemoteAddrJSON: params.RemoteAddrJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (this *SortAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
LocationsJSON: newRefsJSON,
|
LocationsJSON: newRefsJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 校验配置
|
// TODO 校验配置
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
StatJSON: params.StatJSON,
|
StatJSON: params.StatJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
// TODO 检查配置
|
// TODO 检查配置
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
FirewallJSON: params.FirewallJSON,
|
FirewallJSON: params.FirewallJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
defer this.CreateLogInfo("修改Web %d 的根目录等设置", params.WebId)
|
defer this.CreateLogInfo("修改Web %d 的根目录等设置", params.WebId)
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWeb(this.AdminContext(), &pb.UpdateHTTPWebRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWeb(this.AdminContext(), &pb.UpdateHTTPWebRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
RootJSON: params.RootJSON,
|
RootJSON: params.RootJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebP(this.AdminContext(), &pb.UpdateHTTPWebWebPRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebP(this.AdminContext(), &pb.UpdateHTTPWebWebPRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
WebpJSON: params.WebpJSON,
|
WebpJSON: params.WebpJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebWebsocket(this.AdminContext(), &pb.UpdateHTTPWebWebsocketRequest{
|
||||||
WebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
WebsocketJSON: websocketRefJSON,
|
WebsocketJSON: websocketRefJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user