Fix ipv6 parsing (#12321)
* Fix ipv6 parsing * Update modules/setting/setting.go Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>release/v1.15
parent
415fc8288f
commit
4609eba2e7
|
@ -7,6 +7,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof" // Used for debugging if enabled and a web server is running
|
_ "net/http/pprof" // Used for debugging if enabled and a web server is running
|
||||||
"os"
|
"os"
|
||||||
|
@ -156,7 +157,7 @@ func runWeb(ctx *cli.Context) error {
|
||||||
|
|
||||||
listenAddr := setting.HTTPAddr
|
listenAddr := setting.HTTPAddr
|
||||||
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
|
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
|
||||||
listenAddr += ":" + setting.HTTPPort
|
listenAddr = net.JoinHostPort(listenAddr, setting.HTTPPort)
|
||||||
}
|
}
|
||||||
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
|
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -969,12 +970,21 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
cl := new(CloneLink)
|
cl := new(CloneLink)
|
||||||
|
|
||||||
|
// if we have a ipv6 literal we need to put brackets around it
|
||||||
|
// for the git cloning to work.
|
||||||
|
sshDomain := setting.SSH.Domain
|
||||||
|
ip := net.ParseIP(setting.SSH.Domain)
|
||||||
|
if ip != nil && ip.To4() == nil {
|
||||||
|
sshDomain = "[" + setting.SSH.Domain + "]"
|
||||||
|
}
|
||||||
|
|
||||||
if setting.SSH.Port != 22 {
|
if setting.SSH.Port != 22 {
|
||||||
cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.OwnerName, repoName)
|
cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, net.JoinHostPort(setting.SSH.Domain, strconv.Itoa(setting.SSH.Port)), repo.OwnerName, repoName)
|
||||||
} else if setting.Repository.UseCompatSSHURI {
|
} else if setting.Repository.UseCompatSSHURI {
|
||||||
cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName)
|
cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName)
|
||||||
} else {
|
} else {
|
||||||
cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName)
|
cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName)
|
||||||
}
|
}
|
||||||
cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName)
|
cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName)
|
||||||
return cl
|
return cl
|
||||||
|
|
|
@ -626,8 +626,10 @@ func NewContext() {
|
||||||
StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/")
|
StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/")
|
||||||
AppSubURLDepth = strings.Count(AppSubURL, "/")
|
AppSubURLDepth = strings.Count(AppSubURL, "/")
|
||||||
// Check if Domain differs from AppURL domain than update it to AppURL's domain
|
// Check if Domain differs from AppURL domain than update it to AppURL's domain
|
||||||
// TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8
|
urlHostname, _, err := net.SplitHostPort(appURL.Host)
|
||||||
urlHostname := strings.SplitN(appURL.Host, ":", 2)[0]
|
if err != nil {
|
||||||
|
log.Fatal("Invalid host in ROOT_URL '%s': %s", appURL.Host, err)
|
||||||
|
}
|
||||||
if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
|
if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
|
||||||
Domain = urlHostname
|
Domain = urlHostname
|
||||||
}
|
}
|
||||||
|
@ -643,11 +645,10 @@ func NewContext() {
|
||||||
default:
|
default:
|
||||||
defaultLocalURL = string(Protocol) + "://"
|
defaultLocalURL = string(Protocol) + "://"
|
||||||
if HTTPAddr == "0.0.0.0" {
|
if HTTPAddr == "0.0.0.0" {
|
||||||
defaultLocalURL += "localhost"
|
defaultLocalURL += net.JoinHostPort("localhost", HTTPPort) + "/"
|
||||||
} else {
|
} else {
|
||||||
defaultLocalURL += HTTPAddr
|
defaultLocalURL += net.JoinHostPort(HTTPAddr, HTTPPort) + "/"
|
||||||
}
|
}
|
||||||
defaultLocalURL += ":" + HTTPPort + "/"
|
|
||||||
}
|
}
|
||||||
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
|
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
|
||||||
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
|
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
|
||||||
|
|
Loading…
Reference in New Issue