Browse Source

Fix ipv6 parsing (#12321)

* Fix ipv6 parsing

* Update modules/setting/setting.go

Co-authored-by: 6543 <[email protected]>

Co-authored-by: Lauris BH <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: 6543 <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
pull/12335/head
Wim GitHub 1 week ago
parent
commit
4609eba2e7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 9 deletions
  1. +2
    -1
      cmd/web.go
  2. +13
    -3
      models/repo.go
  3. +6
    -5
      modules/setting/setting.go

+ 2
- 1
cmd/web.go View File

@@ -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)



+ 13
- 3
models/repo.go View File

@@ -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://%[email protected]%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.OwnerName, repoName)
cl.SSH = fmt.Sprintf("ssh://%[email protected]%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://%[email protected]%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName)
cl.SSH = fmt.Sprintf("ssh://%[email protected]%s/%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName)
} else {
cl.SSH = fmt.Sprintf("%[email protected]%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName)
cl.SSH = fmt.Sprintf("%[email protected]%s:%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName)
}
cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName)
return cl


+ 6
- 5
modules/setting/setting.go View File

@@ -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…
Cancel
Save