mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 14:50:25 +08:00
在各个地方支持IPv6
This commit is contained in:
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/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
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-20210628135026-38575a4ab060
|
github.com/iwind/TeaGo v0.0.0-20210720011303-fc255c995afa
|
||||||
github.com/miekg/dns v1.1.35
|
github.com/miekg/dns v1.1.35
|
||||||
github.com/shirou/gopsutil v3.21.5+incompatible // indirect
|
github.com/shirou/gopsutil v3.21.5+incompatible // indirect
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -67,6 +67,8 @@ github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f h1:r2O8PONj/KiuZjJHVHn
|
|||||||
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/iwind/TeaGo v0.0.0-20210628135026-38575a4ab060 h1:qdLtK4PDXxk2vMKkTWl5Fl9xqYuRCukzWAgJbLHdfOo=
|
github.com/iwind/TeaGo v0.0.0-20210628135026-38575a4ab060 h1:qdLtK4PDXxk2vMKkTWl5Fl9xqYuRCukzWAgJbLHdfOo=
|
||||||
github.com/iwind/TeaGo v0.0.0-20210628135026-38575a4ab060/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20210628135026-38575a4ab060/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
|
github.com/iwind/TeaGo v0.0.0-20210720011303-fc255c995afa h1:woN88uEmRRUNFD7pRZEtX9heDcjFn0ClMxjF5ButKow=
|
||||||
|
github.com/iwind/TeaGo v0.0.0-20210720011303-fc255c995afa/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
|
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package database
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
@@ -10,6 +11,8 @@ import (
|
|||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -101,7 +104,20 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
params.Must.
|
params.Must.
|
||||||
Field("host", params.Host).
|
Field("host", params.Host).
|
||||||
Require("请输入主机地址").
|
Require("请输入主机地址").
|
||||||
Match(`^[\w\.-]+$`, "主机地址中不能包含特殊字符").
|
Expect(func() (message string, success bool) {
|
||||||
|
// 是否为IP
|
||||||
|
if net.ParseIP(params.Host) != nil {
|
||||||
|
success = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !regexp.MustCompile(`^[\w.-]+$`).MatchString(params.Host) {
|
||||||
|
message = "主机地址中不能包含特殊字符"
|
||||||
|
success = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
success = true
|
||||||
|
return
|
||||||
|
}).
|
||||||
Field("port", params.Port).
|
Field("port", params.Port).
|
||||||
Gt(0, "端口需要大于0").
|
Gt(0, "端口需要大于0").
|
||||||
Lt(65535, "端口需要小于65535").
|
Lt(65535, "端口需要小于65535").
|
||||||
@@ -113,7 +129,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
Match(`^[\w\.-]+$`, "用户名中不能包含特殊字符")
|
Match(`^[\w\.-]+$`, "用户名中不能包含特殊字符")
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
dsn := params.Username + ":" + params.Password + "@tcp(" + params.Host + ":" + fmt.Sprintf("%d", params.Port) + ")/" + params.Database
|
dsn := params.Username + ":" + params.Password + "@tcp(" + configutils.QuoteIP(params.Host) + ":" + fmt.Sprintf("%d", params.Port) + ")/" + params.Database
|
||||||
|
|
||||||
configFile := Tea.ConfigFile("api_db.yaml")
|
configFile := Tea.ConfigFile("api_db.yaml")
|
||||||
template := `default:
|
template := `default:
|
||||||
|
|||||||
@@ -54,14 +54,18 @@ func checkIPWithoutCache(config *systemconfigs.SecurityConfig, ipAddr string) bo
|
|||||||
// 本地IP
|
// 本地IP
|
||||||
ipObj := net.ParseIP(ipAddr)
|
ipObj := net.ParseIP(ipAddr)
|
||||||
if ipObj == nil {
|
if ipObj == nil {
|
||||||
logs.Println("[USER_MUST_AUTH]invalid client address: " + ipAddr)
|
logs.Println("[USER_MUST_AUTH]parse ip: invalid client address: " + ipAddr)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
ip := ipObj.To4()
|
ip := ipObj.To4()
|
||||||
|
if ip == nil {
|
||||||
|
// IPv6
|
||||||
|
ip = ipObj.To16()
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
logs.Println("[USER_MUST_AUTH]invalid client address: " + ipAddr)
|
logs.Println("[USER_MUST_AUTH]invalid client address: " + ipAddr)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if config.AllowLocal && isLocalIP(ip) {
|
if config.AllowLocal && isLocalIP(ip) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -104,8 +108,15 @@ func checkIPWithoutCache(config *systemconfigs.SecurityConfig, ipAddr string) bo
|
|||||||
|
|
||||||
// 判断是否为本地IP
|
// 判断是否为本地IP
|
||||||
func isLocalIP(ip net.IP) bool {
|
func isLocalIP(ip net.IP) bool {
|
||||||
return ip[0] == 127 ||
|
if ip[0] == 127 ||
|
||||||
ip[0] == 10 ||
|
ip[0] == 10 ||
|
||||||
(ip[0] == 172 && ip[1]&0xf0 == 16) ||
|
(ip[0] == 172 && ip[1]&0xf0 == 16) ||
|
||||||
(ip[0] == 192 && ip[1] == 168)
|
(ip[0] == 192 && ip[1] == 168) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ip.String() == "::1" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Vue.component("api-node-addresses-box", {
|
|||||||
<div v-if="addrs.length > 0">
|
<div v-if="addrs.length > 0">
|
||||||
<div>
|
<div>
|
||||||
<div v-for="(addr, index) in addrs" class="ui label small">
|
<div v-for="(addr, index) in addrs" class="ui label small">
|
||||||
{{addr.protocol}}://{{addr.host}}:{{addr.portRange}}</span>
|
{{addr.protocol}}://{{addr.host.quoteIP()}}:{{addr.portRange}}</span>
|
||||||
<a href="" title="修改" @click.prevent="updateAddr(index, addr)"><i class="icon pencil small"></i></a>
|
<a href="" title="修改" @click.prevent="updateAddr(index, addr)"><i class="icon pencil small"></i></a>
|
||||||
<a href="" title="删除" @click.prevent="removeAddr(index)"><i class="icon remove"></i></a>
|
<a href="" title="删除" @click.prevent="removeAddr(index)"><i class="icon remove"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ Vue.component("network-addresses-box", {
|
|||||||
<input type="hidden" :name="name" :value="JSON.stringify(addresses)"/>
|
<input type="hidden" :name="name" :value="JSON.stringify(addresses)"/>
|
||||||
<div v-if="addresses.length > 0">
|
<div v-if="addresses.length > 0">
|
||||||
<div class="ui label small basic" v-for="(addr, index) in addresses">
|
<div class="ui label small basic" v-for="(addr, index) in addresses">
|
||||||
{{addr.protocol}}://<span v-if="addr.host.length > 0">{{addr.host}}</span><span v-if="addr.host.length == 0">*</span>:{{addr.portRange}}
|
{{addr.protocol}}://<span v-if="addr.host.length > 0">{{addr.host.quoteIP()}}</span><span v-if="addr.host.length == 0">*</span>:{{addr.portRange}}
|
||||||
<a href="" @click.prevent="updateAddr(index, addr)" title="修改"><i class="icon pencil small"></i></a>
|
<a href="" @click.prevent="updateAddr(index, addr)" title="修改"><i class="icon pencil small"></i></a>
|
||||||
<a href="" @click.prevent="removeAddr(index)" title="删除"><i class="icon remove"></i></a> </div>
|
<a href="" @click.prevent="removeAddr(index)" title="删除"><i class="icon remove"></i></a> </div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Vue.component("network-addresses-view", {
|
|||||||
props: ["v-addresses"],
|
props: ["v-addresses"],
|
||||||
template: `<div>
|
template: `<div>
|
||||||
<div class="ui label tiny basic" v-if="vAddresses != null" v-for="addr in vAddresses">
|
<div class="ui label tiny basic" v-if="vAddresses != null" v-for="addr in vAddresses">
|
||||||
{{addr.protocol}}://<span v-if="addr.host.length > 0">{{addr.host}}</span><span v-else>*</span>:{{addr.portRange}}
|
{{addr.protocol}}://<span v-if="addr.host.length > 0">{{addr.host.quoteIP()}}</span><span v-else>*</span>:{{addr.portRange}}
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
})
|
})
|
||||||
@@ -524,3 +524,17 @@ window.teaweb = {
|
|||||||
chart.resize()
|
chart.resize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String.prototype.quoteIP = function () {
|
||||||
|
let ip = this.toString()
|
||||||
|
if (ip.length == 0) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if (ip.indexOf(":") < 0) {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
if (ip.substring(0, 1) == "[") {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
return "[" + ip + "]"
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
Tea.context(function () {
|
Tea.context(function () {
|
||||||
let addr = window.parent.UPDATING_ADDR
|
let addr = window.parent.UPDATING_ADDR
|
||||||
this.protocol = addr.protocol
|
this.protocol = addr.protocol
|
||||||
this.addr = addr.host + ":" + addr.portRange
|
this.addr = addr.host.quoteIP() + ":" + addr.portRange
|
||||||
})
|
})
|
||||||
@@ -23,7 +23,7 @@ Tea.context(function () {
|
|||||||
if (addr.host.length == 0) {
|
if (addr.host.length == 0) {
|
||||||
this.address = addr.portRange
|
this.address = addr.portRange
|
||||||
} else {
|
} else {
|
||||||
this.address = addr.host + ":" + addr.portRange
|
this.address = addr.host.quoteIP() + ":" + addr.portRange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@
|
|||||||
<td>区域</td>
|
<td>区域</td>
|
||||||
<td>{{region.full}}</td>
|
<td>{{region.full}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="region.isp.length > 0">
|
<tr v-if="region != null && region.isp != null && region.isp.length > 0">
|
||||||
<td>ISP</td>
|
<td>ISP</td>
|
||||||
<td>{{region.isp}}</td>
|
<td>{{region.isp}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Tea.context(function () {
|
Tea.context(function () {
|
||||||
let addr = window.parent.UPDATING_ADDR
|
let addr = window.parent.UPDATING_ADDR
|
||||||
this.protocol = addr.protocol
|
this.protocol = addr.protocol
|
||||||
this.addr = addr.host + ":" + addr.portRange
|
this.addr = addr.host.quoteIP() + ":" + addr.portRange
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user