mirror of
https://github.com/go-gitea/gitea.git
synced 2024-10-30 05:52:42 +00:00
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>
This commit is contained in:
parent
415fc8288f
commit
4609eba2e7
@ -7,6 +7,7 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof" // Used for debugging if enabled and a web server is running
|
||||
"os"
|
||||
@ -156,7 +157,7 @@ func runWeb(ctx *cli.Context) error {
|
||||
|
||||
listenAddr := setting.HTTPAddr
|
||||
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)
|
||||
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
_ "image/jpeg"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
@ -969,12 +970,21 @@ func (repo *Repository) cloneLink(isWiki bool) *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 {
|
||||
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 {
|
||||
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 {
|
||||
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)
|
||||
return cl
|
||||
|
@ -626,8 +626,10 @@ func NewContext() {
|
||||
StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/")
|
||||
AppSubURLDepth = strings.Count(AppSubURL, "/")
|
||||
// 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 := strings.SplitN(appURL.Host, ":", 2)[0]
|
||||
urlHostname, _, err := net.SplitHostPort(appURL.Host)
|
||||
if err != nil {
|
||||
log.Fatal("Invalid host in ROOT_URL '%s': %s", appURL.Host, err)
|
||||
}
|
||||
if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
|
||||
Domain = urlHostname
|
||||
}
|
||||
@ -643,11 +645,10 @@ func NewContext() {
|
||||
default:
|
||||
defaultLocalURL = string(Protocol) + "://"
|
||||
if HTTPAddr == "0.0.0.0" {
|
||||
defaultLocalURL += "localhost"
|
||||
defaultLocalURL += net.JoinHostPort("localhost", HTTPPort) + "/"
|
||||
} else {
|
||||
defaultLocalURL += HTTPAddr
|
||||
defaultLocalURL += net.JoinHostPort(HTTPAddr, HTTPPort) + "/"
|
||||
}
|
||||
defaultLocalURL += ":" + HTTPPort + "/"
|
||||
}
|
||||
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
|
||||
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
|
||||
|
Loading…
Reference in New Issue
Block a user