mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-05 00:34:01 +08:00
优化代码
This commit is contained in:
@@ -5,7 +5,7 @@ package caches
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PartialRanges 内容分区范围定义
|
// PartialRanges 内容分区范围定义
|
||||||
@@ -30,7 +30,7 @@ func NewPartialRangesFromJSON(data []byte) (*PartialRanges, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewPartialRangesFromFile(path string) (*PartialRanges, error) {
|
func NewPartialRangesFromFile(path string) (*PartialRanges, error) {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -116,12 +116,12 @@ func (this *PartialRanges) WriteToFile(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("convert to json failed: " + err.Error())
|
return errors.New("convert to json failed: " + err.Error())
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(path, data, 0666)
|
return os.WriteFile(path, data, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFromFile 从文件中读取
|
// ReadFromFile 从文件中读取
|
||||||
func (this *PartialRanges) ReadFromFile(path string) (*PartialRanges, error) {
|
func (this *PartialRanges) ReadFromFile(path string) (*PartialRanges, error) {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -152,7 +152,7 @@ func TestFileStorage_OpenWriter_HTTP(t *testing.T) {
|
|||||||
"Last-Modified": []string{"Wed, 06 Jan 2021 10:03:29 GMT"},
|
"Last-Modified": []string{"Wed, 06 Jan 2021 10:03:29 GMT"},
|
||||||
"Server": []string{"CDN-Server"},
|
"Server": []string{"CDN-Server"},
|
||||||
},
|
},
|
||||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte("THIS IS HTTP BODY"))),
|
Body: io.NopCloser(bytes.NewBuffer([]byte("THIS IS HTTP BODY"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range resp.Header {
|
for k, v := range resp.Header {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package caches_test
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -16,7 +15,7 @@ func TestPartialFileWriter_Write(t *testing.T) {
|
|||||||
_ = os.Remove(path)
|
_ = os.Remove(path)
|
||||||
|
|
||||||
var reader = func() {
|
var reader = func() {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package configs
|
|||||||
import (
|
import (
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIConfig 节点API配置
|
// APIConfig 节点API配置
|
||||||
@@ -17,7 +17,7 @@ type APIConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LoadAPIConfig() (*APIConfig, error) {
|
func LoadAPIConfig() (*APIConfig, error) {
|
||||||
data, err := ioutil.ReadFile(Tea.ConfigFile("api.yaml"))
|
data, err := os.ReadFile(Tea.ConfigFile("api.yaml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,6 @@ func (this *APIConfig) WriteFile(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(path, data, 0666)
|
err = os.WriteFile(path, data, 0666)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package iplibrary
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -62,7 +62,7 @@ func getIpInfo(cityId int64, line []byte) *IpInfo {
|
|||||||
|
|
||||||
func NewIP2Region(path string) (*IP2Region, error) {
|
func NewIP2Region(path string) (*IP2Region, error) {
|
||||||
var region = &IP2Region{}
|
var region = &IP2Region{}
|
||||||
region.dbData, err = ioutil.ReadFile(path)
|
region.dbData, err = os.ReadFile(path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -90,7 +89,7 @@ func (this *CityManager) Lookup(provinceId int64, cityName string) (cityId int64
|
|||||||
|
|
||||||
// 从缓存中读取
|
// 从缓存中读取
|
||||||
func (this *CityManager) load() error {
|
func (this *CityManager) load() error {
|
||||||
data, err := ioutil.ReadFile(this.cacheFile)
|
data, err := os.ReadFile(this.cacheFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -151,6 +150,6 @@ func (this *CityManager) loop() error {
|
|||||||
|
|
||||||
// 保存到本地缓存
|
// 保存到本地缓存
|
||||||
|
|
||||||
err = ioutil.WriteFile(this.cacheFile, data, 0666)
|
err = os.WriteFile(this.cacheFile, data, 0666)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -89,7 +88,7 @@ func (this *CountryManager) Lookup(countryName string) (countryId int64) {
|
|||||||
|
|
||||||
// 从缓存中读取
|
// 从缓存中读取
|
||||||
func (this *CountryManager) load() error {
|
func (this *CountryManager) load() error {
|
||||||
data, err := ioutil.ReadFile(this.cacheFile)
|
data, err := os.ReadFile(this.cacheFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -149,6 +148,6 @@ func (this *CountryManager) loop() error {
|
|||||||
this.locker.Unlock()
|
this.locker.Unlock()
|
||||||
|
|
||||||
// 保存到本地缓存
|
// 保存到本地缓存
|
||||||
err = ioutil.WriteFile(this.cacheFile, data, 0666)
|
err = os.WriteFile(this.cacheFile, data, 0666)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -89,7 +88,7 @@ func (this *ProviderManager) Lookup(providerName string) (providerId int64) {
|
|||||||
|
|
||||||
// 从缓存中读取
|
// 从缓存中读取
|
||||||
func (this *ProviderManager) load() error {
|
func (this *ProviderManager) load() error {
|
||||||
data, err := ioutil.ReadFile(this.cacheFile)
|
data, err := os.ReadFile(this.cacheFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -150,6 +149,6 @@ func (this *ProviderManager) loop() error {
|
|||||||
|
|
||||||
// 保存到本地缓存
|
// 保存到本地缓存
|
||||||
|
|
||||||
err = ioutil.WriteFile(this.cacheFile, data, 0666)
|
err = os.WriteFile(this.cacheFile, data, 0666)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -93,7 +92,7 @@ func (this *ProvinceManager) Lookup(provinceName string) (provinceId int64) {
|
|||||||
|
|
||||||
// 从缓存中读取
|
// 从缓存中读取
|
||||||
func (this *ProvinceManager) load() error {
|
func (this *ProvinceManager) load() error {
|
||||||
data, err := ioutil.ReadFile(this.cacheFile)
|
data, err := os.ReadFile(this.cacheFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -156,6 +155,6 @@ func (this *ProvinceManager) loop() error {
|
|||||||
|
|
||||||
// 保存到本地缓存
|
// 保存到本地缓存
|
||||||
|
|
||||||
err = ioutil.WriteFile(this.cacheFile, data, 0666)
|
err = os.WriteFile(this.cacheFile, data, 0666)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -236,7 +235,7 @@ func (this *HTTPCacheTaskManager) fetchKey(key *pb.HTTPCacheTaskKey) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// 读取内容,以便于生成缓存
|
// 读取内容,以便于生成缓存
|
||||||
_, _ = io.Copy(ioutil.Discard, resp.Body)
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
|
|
||||||
// 处理502
|
// 处理502
|
||||||
if resp.StatusCode == http.StatusBadGateway {
|
if resp.StatusCode == http.StatusBadGateway {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -284,12 +283,12 @@ func (this *HTTPRequest) doBegin() {
|
|||||||
this.web.AccessLogRef.IsOn &&
|
this.web.AccessLogRef.IsOn &&
|
||||||
this.web.AccessLogRef.ContainsField(serverconfigs.HTTPAccessLogFieldRequestBody) {
|
this.web.AccessLogRef.ContainsField(serverconfigs.HTTPAccessLogFieldRequestBody) {
|
||||||
var err error
|
var err error
|
||||||
this.requestBodyData, err = ioutil.ReadAll(io.LimitReader(this.RawReq.Body, AccessLogMaxRequestBodySize))
|
this.requestBodyData, err = io.ReadAll(io.LimitReader(this.RawReq.Body, AccessLogMaxRequestBodySize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.write50x(err, http.StatusBadGateway, "Failed to read request body for access log", "为访问日志读取请求Body失败", false)
|
this.write50x(err, http.StatusBadGateway, "Failed to read request body for access log", "为访问日志读取请求Body失败", false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.RawReq.Body = ioutil.NopCloser(io.MultiReader(bytes.NewBuffer(this.requestBodyData), this.RawReq.Body))
|
this.RawReq.Body = io.NopCloser(io.MultiReader(bytes.NewBuffer(this.requestBodyData), this.RawReq.Body))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 跳转
|
// 跳转
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package nodes
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ func (this *HTTPRequest) doAuth() (shouldStop bool) {
|
|||||||
subReq.Proto = this.RawReq.Proto
|
subReq.Proto = this.RawReq.Proto
|
||||||
subReq.ProtoMinor = this.RawReq.ProtoMinor
|
subReq.ProtoMinor = this.RawReq.ProtoMinor
|
||||||
subReq.ProtoMajor = this.RawReq.ProtoMajor
|
subReq.ProtoMajor = this.RawReq.ProtoMajor
|
||||||
subReq.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
subReq.Body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||||
subReq.Header.Set("Referer", this.URL())
|
subReq.Header.Set("Referer", this.URL())
|
||||||
var writer = NewEmptyResponseWriter(this.writer)
|
var writer = NewEmptyResponseWriter(this.writer)
|
||||||
this.doSubRequest(writer, subReq)
|
this.doSubRequest(writer, subReq)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -359,7 +358,7 @@ func (this *HTTPRequest) WAFSetCacheBody(body []byte) {
|
|||||||
// WAFReadBody 读取Body
|
// WAFReadBody 读取Body
|
||||||
func (this *HTTPRequest) WAFReadBody(max int64) (data []byte, err error) {
|
func (this *HTTPRequest) WAFReadBody(max int64) (data []byte, err error) {
|
||||||
if this.RawReq.ContentLength > 0 {
|
if this.RawReq.ContentLength > 0 {
|
||||||
data, err = ioutil.ReadAll(io.LimitReader(this.RawReq.Body, max))
|
data, err = io.ReadAll(io.LimitReader(this.RawReq.Body, max))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -368,7 +367,7 @@ func (this *HTTPRequest) WAFReadBody(max int64) (data []byte, err error) {
|
|||||||
// WAFRestoreBody 恢复Body
|
// WAFRestoreBody 恢复Body
|
||||||
func (this *HTTPRequest) WAFRestoreBody(data []byte) {
|
func (this *HTTPRequest) WAFRestoreBody(data []byte) {
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
this.RawReq.Body = ioutil.NopCloser(io.MultiReader(bytes.NewBuffer(data), this.RawReq.Body))
|
this.RawReq.Body = io.NopCloser(io.MultiReader(bytes.NewBuffer(data), this.RawReq.Body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import (
|
|||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
@@ -524,7 +523,7 @@ func (this *HTTPWriter) PrepareWebP(resp *http.Response, size int64) {
|
|||||||
|
|
||||||
this.webpOriginContentType = contentType
|
this.webpOriginContentType = contentType
|
||||||
this.webpIsEncoding = true
|
this.webpIsEncoding = true
|
||||||
resp.Body = ioutil.NopCloser(&bytes.Buffer{})
|
resp.Body = io.NopCloser(&bytes.Buffer{})
|
||||||
this.delayRead = true
|
this.delayRead = true
|
||||||
|
|
||||||
this.Header().Del("Content-Length")
|
this.Header().Del("Content-Length")
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"github.com/iwind/gosock/pkg/gosock"
|
"github.com/iwind/gosock/pkg/gosock"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -612,7 +611,7 @@ func (this *Node) startSyncTimer() {
|
|||||||
// 检查集群设置
|
// 检查集群设置
|
||||||
func (this *Node) checkClusterConfig() error {
|
func (this *Node) checkClusterConfig() error {
|
||||||
configFile := Tea.ConfigFile("cluster.yaml")
|
configFile := Tea.ConfigFile("cluster.yaml")
|
||||||
data, err := ioutil.ReadFile(configFile)
|
data, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1008,7 +1007,7 @@ func (this *Node) checkDisk() {
|
|||||||
"/sys/block/vda/queue/rotational",
|
"/sys/block/vda/queue/rotational",
|
||||||
"/sys/block/sda/queue/rotational",
|
"/sys/block/sda/queue/rotational",
|
||||||
} {
|
} {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
@@ -25,7 +24,7 @@ func (this *Node) handlePanic() {
|
|||||||
var panicFile = Tea.Root + "/logs/panic.log"
|
var panicFile = Tea.Root + "/logs/panic.log"
|
||||||
|
|
||||||
// 分析panic
|
// 分析panic
|
||||||
data, err := ioutil.ReadFile(panicFile)
|
data, err := os.ReadFile(panicFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var index = bytes.Index(data, []byte("panic:"))
|
var index = bytes.Index(data, []byte("panic:"))
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -104,7 +103,7 @@ func (this *SystemServiceManager) setupSystemd(params maps.Map) error {
|
|||||||
|
|
||||||
if output == "enabled" {
|
if output == "enabled" {
|
||||||
// 检查文件路径是否变化
|
// 检查文件路径是否变化
|
||||||
data, err := ioutil.ReadFile("/etc/systemd/system/" + teaconst.SystemdServiceName + ".service")
|
data, err := os.ReadFile("/etc/systemd/system/" + teaconst.SystemdServiceName + ".service")
|
||||||
if err == nil && bytes.Index(data, []byte(exe)) > 0 {
|
if err == nil && bytes.Index(data, []byte(exe)) > 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -19,7 +19,7 @@ func DumpResponse(resp *http.Response) (header []byte, body []byte, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = io.ReadAll(resp.Body)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils/readers"
|
"github.com/TeaOSLab/EdgeNode/internal/utils/readers"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -17,7 +16,7 @@ func TestNewByteRangesReader(t *testing.T) {
|
|||||||
var dashBoundary = "--" + boundary
|
var dashBoundary = "--" + boundary
|
||||||
var b = bytes.NewReader([]byte(dashBoundary + "\r\nContent-Range: bytes 0-4/36\r\nContent-Type: text/plain\r\n\r\n01234\r\n" + dashBoundary + "\r\nContent-Range: bytes 5-9/36\r\nContent-Type: text/plain\r\n\r\n56789\r\n--" + boundary + "\r\nContent-Range: bytes 10-12/36\r\nContent-Type: text/plain\r\n\r\nabc\r\n" + dashBoundary + "--\r\n"))
|
var b = bytes.NewReader([]byte(dashBoundary + "\r\nContent-Range: bytes 0-4/36\r\nContent-Type: text/plain\r\n\r\n01234\r\n" + dashBoundary + "\r\nContent-Range: bytes 5-9/36\r\nContent-Type: text/plain\r\n\r\n56789\r\n--" + boundary + "\r\nContent-Range: bytes 10-12/36\r\nContent-Type: text/plain\r\n\r\nabc\r\n" + dashBoundary + "--\r\n"))
|
||||||
|
|
||||||
var reader = readers.NewByteRangesReaderCloser(ioutil.NopCloser(b), boundary)
|
var reader = readers.NewByteRangesReaderCloser(io.NopCloser(b), boundary)
|
||||||
var p = make([]byte, 16)
|
var p = make([]byte, 16)
|
||||||
for {
|
for {
|
||||||
n, err := reader.Read(p)
|
n, err := reader.Read(p)
|
||||||
@@ -38,7 +37,7 @@ func TestByteRangesReader_OnPartRead(t *testing.T) {
|
|||||||
var dashBoundary = "--" + boundary
|
var dashBoundary = "--" + boundary
|
||||||
var b = bytes.NewReader([]byte(dashBoundary + "\r\nContent-Range: bytes 0-4/36\r\nContent-Type: text/plain\r\n\r\n01234\r\n" + dashBoundary + "\r\nContent-Range: bytes 5-9/36\r\nContent-Type: text/plain\r\n\r\n56789\r\n--" + boundary + "\r\nContent-Range: bytes 10-12/36\r\nContent-Type: text/plain\r\n\r\nabc\r\n" + dashBoundary + "--\r\n"))
|
var b = bytes.NewReader([]byte(dashBoundary + "\r\nContent-Range: bytes 0-4/36\r\nContent-Type: text/plain\r\n\r\n01234\r\n" + dashBoundary + "\r\nContent-Range: bytes 5-9/36\r\nContent-Type: text/plain\r\n\r\n56789\r\n--" + boundary + "\r\nContent-Range: bytes 10-12/36\r\nContent-Type: text/plain\r\n\r\nabc\r\n" + dashBoundary + "--\r\n"))
|
||||||
|
|
||||||
var reader = readers.NewByteRangesReaderCloser(ioutil.NopCloser(b), boundary)
|
var reader = readers.NewByteRangesReaderCloser(io.NopCloser(b), boundary)
|
||||||
reader.OnPartRead(func(start int64, end int64, total int64, data []byte, header textproto.MIMEHeader) {
|
reader.OnPartRead(func(start int64, end int64, total int64, data []byte, header textproto.MIMEHeader) {
|
||||||
t.Log(start, "-", end, "/", total, string(data))
|
t.Log(start, "-", end, "/", total, string(data))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/files"
|
"github.com/iwind/TeaGo/files"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -83,13 +82,13 @@ func (this *ServiceManager) installInitService(exePath string, args []string) er
|
|||||||
return errors.New("'scripts/" + shortName + "' file not exists")
|
return errors.New("'scripts/" + shortName + "' file not exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(scriptFile)
|
data, err := os.ReadFile(scriptFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data = regexp.MustCompile("INSTALL_DIR=.+").ReplaceAll(data, []byte("INSTALL_DIR="+Tea.Root))
|
data = regexp.MustCompile("INSTALL_DIR=.+").ReplaceAll(data, []byte("INSTALL_DIR="+Tea.Root))
|
||||||
err = ioutil.WriteFile(initServiceFile, data, 0777)
|
err = os.WriteFile(initServiceFile, data, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -137,7 +136,7 @@ ExecReload=` + exePath + ` reload
|
|||||||
WantedBy=multi-user.target`
|
WantedBy=multi-user.target`
|
||||||
|
|
||||||
// write file
|
// write file
|
||||||
err := ioutil.WriteFile(systemdServiceFile, []byte(desc), 0777)
|
err := os.WriteFile(systemdServiceFile, []byte(desc), 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -111,7 +110,7 @@ func (this *BlockAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, reque
|
|||||||
path = Tea.Root + string(os.PathSeparator) + path
|
path = Tea.Root + string(os.PathSeparator) + path
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err)
|
logs.Error(err)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -28,7 +28,7 @@ func TestRequestAllCheckpoint_RequestValue(t *testing.T) {
|
|||||||
t.Log(v)
|
t.Log(v)
|
||||||
t.Log(types.String(v))
|
t.Log(types.String(v))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func TestRequestAllCheckpoint_RequestValue_Max(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log("value bytes:", len(types.String(value)))
|
t.Log("value bytes:", len(types.String(value)))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -19,7 +19,7 @@ func TestRequestBodyCheckpoint_RequestValue(t *testing.T) {
|
|||||||
checkpoint := new(RequestBodyCheckpoint)
|
checkpoint := new(RequestBodyCheckpoint)
|
||||||
t.Log(checkpoint.RequestValue(req, "", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "", nil, 1))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(rawReq.Body)
|
body, err := io.ReadAll(rawReq.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ func TestRequestBodyCheckpoint_RequestValue_Max(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log("value bytes:", len(types.String(value)))
|
t.Log("value bytes:", len(types.String(value)))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -24,7 +24,7 @@ func TestRequestFormArgCheckpoint_RequestValue(t *testing.T) {
|
|||||||
t.Log(checkpoint.RequestValue(req, "Hello", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "Hello", nil, 1))
|
||||||
t.Log(checkpoint.RequestValue(req, "encoded", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "encoded", nil, 1))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -31,7 +31,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Map(t *testing.T) {
|
|||||||
t.Log(checkpoint.RequestValue(req, "books", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "books", nil, 1))
|
||||||
t.Log(checkpoint.RequestValue(req, "books.1", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "books.1", nil, 1))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Array(t *testing.T) {
|
|||||||
t.Log(checkpoint.RequestValue(req, "0.books", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "0.books", nil, 1))
|
||||||
t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Error(t *testing.T) {
|
|||||||
t.Log(checkpoint.RequestValue(req, "0.books", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "0.books", nil, 1))
|
||||||
t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1))
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -51,7 +51,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st
|
|||||||
defer req.WAFRestoreBody(data)
|
defer req.WAFRestoreBody(data)
|
||||||
}
|
}
|
||||||
oldBody := req.WAFRaw().Body
|
oldBody := req.WAFRaw().Body
|
||||||
req.WAFRaw().Body = ioutil.NopCloser(bytes.NewBuffer(bodyData))
|
req.WAFRaw().Body = io.NopCloser(bytes.NewBuffer(bodyData))
|
||||||
|
|
||||||
err := req.WAFRaw().ParseMultipartForm(utils.MaxBodySize)
|
err := req.WAFRaw().ParseMultipartForm(utils.MaxBodySize)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -94,7 +94,7 @@ func TestRequestUploadCheckpoint_RequestValue(t *testing.T) {
|
|||||||
t.Log(checkpoint.RequestValue(req, "name", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "name", nil, 1))
|
||||||
t.Log(checkpoint.RequestValue(req, "ext", nil, 1))
|
t.Log(checkpoint.RequestValue(req, "ext", nil, 1))
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(req.WAFRaw().Body)
|
data, err := io.ReadAll(req.WAFRaw().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResponseBodyCheckpoint ${responseBody}
|
// ResponseBodyCheckpoint ${responseBody}
|
||||||
@@ -33,7 +33,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re
|
|||||||
value = string(resp.BodyData)
|
value = string(resp.BodyData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sysErr = err
|
sysErr = err
|
||||||
return
|
return
|
||||||
@@ -41,7 +41,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re
|
|||||||
resp.BodyData = body
|
resp.BodyData = body
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
value = body
|
value = body
|
||||||
resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
resp.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package checkpoints
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -13,7 +13,7 @@ func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) {
|
|||||||
resp.StatusCode = 200
|
resp.StatusCode = 200
|
||||||
resp.Header = http.Header{}
|
resp.Header = http.Header{}
|
||||||
resp.Header.Set("Hello", "World")
|
resp.Header.Set("Hello", "World")
|
||||||
resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte("Hello, World")))
|
resp.Body = io.NopCloser(bytes.NewBuffer([]byte("Hello, World")))
|
||||||
|
|
||||||
checkpoint := new(ResponseBodyCheckpoint)
|
checkpoint := new(ResponseBodyCheckpoint)
|
||||||
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
||||||
@@ -21,7 +21,7 @@ func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) {
|
|||||||
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
||||||
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package requests
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -48,7 +47,7 @@ func (this *TestRequest) WAFRemoteIP() string {
|
|||||||
|
|
||||||
func (this *TestRequest) WAFReadBody(max int64) (data []byte, err error) {
|
func (this *TestRequest) WAFReadBody(max int64) (data []byte, err error) {
|
||||||
if this.req.ContentLength > 0 {
|
if this.req.ContentLength > 0 {
|
||||||
data, err = ioutil.ReadAll(io.LimitReader(this.req.Body, max))
|
data, err = io.ReadAll(io.LimitReader(this.req.Body, max))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -58,7 +57,7 @@ func (this *TestRequest) WAFRestoreBody(data []byte) {
|
|||||||
rawReader := bytes.NewBuffer(data)
|
rawReader := bytes.NewBuffer(data)
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
_, _ = io.CopyBuffer(rawReader, this.req.Body, buf)
|
_, _ = io.CopyBuffer(rawReader, this.req.Body, buf)
|
||||||
this.req.Body = ioutil.NopCloser(rawReader)
|
this.req.Body = io.NopCloser(rawReader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/iwind/TeaGo/files"
|
"github.com/iwind/TeaGo/files"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ func (this *WAF) Save(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(path, data, 0644)
|
return os.WriteFile(path, data, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *WAF) ContainsGroupCode(code string) bool {
|
func (this *WAF) ContainsGroupCode(code string) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user