Add bind address in config (IPv4 and IPv6)
This commit is contained in:
parent
a1cd475788
commit
0b0611fc45
|
|
@ -41,9 +41,13 @@ HTTP
|
||||||
* https_cert_path : Path to the certificate file (default: ./cert.pem)
|
* https_cert_path : Path to the certificate file (default: ./cert.pem)
|
||||||
* https_key_path : Path to the key file (default: ./key.pem)
|
* https_key_path : Path to the key file (default: ./key.pem)
|
||||||
* http_timeout_sec : Define a timeout if user did not give an answer to the request (default: 60)
|
* http_timeout_sec : Define a timeout if user did not give an answer to the request (default: 60)
|
||||||
|
* http_bind_address_ipv4 : Bind address on IPv4 (default: 127.0.0.1)
|
||||||
|
* http_bind_address_ipv6 : Bind address on IPv6 (default: [::1])
|
||||||
|
|
||||||
__Bold config__ are mandatory.
|
__Bold config__ are mandatory.
|
||||||
|
|
||||||
|
If ``http_bind_address_ipv4`` is set to ``0.0.0.0``, it will bind all address on IPv4 __AND__ IPv6.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
To ask authorization, just send an HTTP request to the path ``/auth`` with parameters:
|
To ask authorization, just send an HTTP request to the path ``/auth`` with parameters:
|
||||||
* __jid__ : JID of the user (user@host/resource or user@host)
|
* __jid__ : JID of the user (user@host/resource or user@host)
|
||||||
|
|
|
||||||
35
http/http.go
35
http/http.go
|
|
@ -44,6 +44,9 @@ var (
|
||||||
ChanRequest = make(chan interface{}, 5)
|
ChanRequest = make(chan interface{}, 5)
|
||||||
TimeoutSec = 60 // 1 min
|
TimeoutSec = 60 // 1 min
|
||||||
MaxTimeout = 300 // 5 min
|
MaxTimeout = 300 // 5 min
|
||||||
|
|
||||||
|
BindAddressIPv4 = "127.0.0.1"
|
||||||
|
BindAddressIPv6 = "[::1]"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -125,32 +128,44 @@ func Run() {
|
||||||
http.HandleFunc(ROUTE_AUTH, authHandler)
|
http.HandleFunc(ROUTE_AUTH, authHandler)
|
||||||
|
|
||||||
if HttpPortBind > 0 {
|
if HttpPortBind > 0 {
|
||||||
go runHttp()
|
go runHttp(BindAddressIPv4)
|
||||||
|
if BindAddressIPv4 != "0.0.0.0" {
|
||||||
|
go runHttp(BindAddressIPv6)
|
||||||
|
}
|
||||||
} else if HttpPortBind == 0 {
|
} else if HttpPortBind == 0 {
|
||||||
HttpPortBind = rand.Intn(MAX_PORT_VAL)
|
HttpPortBind = rand.Intn(MAX_PORT_VAL)
|
||||||
go runHttp()
|
go runHttp(BindAddressIPv4)
|
||||||
|
if BindAddressIPv4 != "0.0.0.0" {
|
||||||
|
go runHttp(BindAddressIPv6)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if HttpsPortBind > 0 {
|
if HttpsPortBind > 0 {
|
||||||
go runHttps()
|
go runHttps(BindAddressIPv4)
|
||||||
|
if BindAddressIPv6 != "0.0.0.0" {
|
||||||
|
go runHttps(BindAddressIPv6)
|
||||||
|
}
|
||||||
} else if HttpsPortBind == 0 {
|
} else if HttpsPortBind == 0 {
|
||||||
HttpsPortBind = rand.Intn(MAX_PORT_VAL)
|
HttpsPortBind = rand.Intn(MAX_PORT_VAL)
|
||||||
go runHttps()
|
go runHttps(BindAddressIPv4)
|
||||||
|
if BindAddressIPv6 != "0.0.0.0" {
|
||||||
|
go runHttps(BindAddressIPv6)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runHttp() {
|
func runHttp(bindAddress string) {
|
||||||
port := strconv.Itoa(HttpPortBind)
|
port := strconv.Itoa(HttpPortBind)
|
||||||
log.Printf("%sHTTP listenning on port %s", LogInfo, port)
|
log.Printf("%sHTTP listenning on %s:%s", LogInfo, bindAddress, port)
|
||||||
err := http.ListenAndServe(":"+port, nil)
|
err := http.ListenAndServe(bindAddress+":"+port, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("%sListenAndServe: ", LogError, err)
|
log.Fatal("%sListenAndServe: ", LogError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runHttps() {
|
func runHttps(bindAddress string) {
|
||||||
port := strconv.Itoa(HttpsPortBind)
|
port := strconv.Itoa(HttpsPortBind)
|
||||||
log.Printf("%sHTTPS listenning on port %s", LogInfo, port)
|
log.Printf("%sHTTPS listenning on %s:%s", LogInfo, bindAddress, port)
|
||||||
err := http.ListenAndServeTLS(":"+port, CertPath, KeyPath, nil)
|
err := http.ListenAndServeTLS(bindAddress+":"+port, CertPath, KeyPath, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("%sListenAndServe: ", LogError, err)
|
log.Fatal("%sListenAndServe: ", LogError, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ xmpp_debug=true
|
||||||
xmpp_verify_cert_validity=true
|
xmpp_verify_cert_validity=true
|
||||||
|
|
||||||
# HTTP informations
|
# HTTP informations
|
||||||
|
http_bind_address_ipv4=192.168.1.143
|
||||||
|
http_bind_address_ipv6=[2001:41d0:fe26:eb00:a8c0:6a57:f3d4:d07c]
|
||||||
http_port=9090
|
http_port=9090
|
||||||
https_port=9093
|
https_port=9093
|
||||||
https_cert_path=./cert.pem
|
https_cert_path=./cert.pem
|
||||||
|
|
|
||||||
8
main.go
8
main.go
|
|
@ -49,6 +49,14 @@ func init() {
|
||||||
http.CertPath = mapConfig["https_cert_path"]
|
http.CertPath = mapConfig["https_cert_path"]
|
||||||
http.KeyPath = mapConfig["https_key_path"]
|
http.KeyPath = mapConfig["https_key_path"]
|
||||||
}
|
}
|
||||||
|
bindAddressIPv4 := mapConfig["http_bind_address_ipv4"]
|
||||||
|
if bindAddressIPv4 != "" {
|
||||||
|
http.BindAddressIPv4 = bindAddressIPv4
|
||||||
|
}
|
||||||
|
bindAddressIPv6 := mapConfig["http_bind_address_ipv6"]
|
||||||
|
if bindAddressIPv6 != "" {
|
||||||
|
http.BindAddressIPv6 = bindAddressIPv6
|
||||||
|
}
|
||||||
|
|
||||||
// XMPP config
|
// XMPP config
|
||||||
xmpp_server_address := mapConfig["xmpp_server_address"]
|
xmpp_server_address := mapConfig["xmpp_server_address"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue