@ -9,8 +9,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/url"
"regexp"
"strings"
"strings"
"time"
"time"
@ -20,6 +18,7 @@ import (
auth "code.gitea.io/gitea/modules/forms"
auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/structs"
@ -30,8 +29,6 @@ import (
"code.gitea.io/gitea/services/mailer"
"code.gitea.io/gitea/services/mailer"
mirror_service "code.gitea.io/gitea/services/mirror"
mirror_service "code.gitea.io/gitea/services/mirror"
repo_service "code.gitea.io/gitea/services/repository"
repo_service "code.gitea.io/gitea/services/repository"
"mvdan.cc/xurls/v2"
)
)
const (
const (
@ -44,8 +41,6 @@ const (
tplProtectedBranch base . TplName = "repo/settings/protected_branch"
tplProtectedBranch base . TplName = "repo/settings/protected_branch"
)
)
var validFormAddress * regexp . Regexp
// Settings show a repository's settings page
// Settings show a repository's settings page
func Settings ( ctx * context . Context ) {
func Settings ( ctx * context . Context ) {
ctx . Data [ "Title" ] = ctx . Tr ( "repo.settings" )
ctx . Data [ "Title" ] = ctx . Tr ( "repo.settings" )
@ -169,40 +164,38 @@ func SettingsPost(ctx *context.Context) {
}
}
}
}
// Validate the form.MirrorAddress
address , err := auth . ParseRemoteAddr ( form . MirrorAddress , form . MirrorUsername , form . MirrorPassword )
u , err := url . Parse ( form . MirrorAddress )
if err == nil {
if err != nil {
err = migrations . IsMigrateURLAllowed ( address , ctx . User )
ctx . Data [ "Err_MirrorAddress" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.mirror_address_url_invalid" ) , tplSettingsOptions , & form )
return
}
}
if err != nil {
if u . Opaque != "" || ! ( u . Scheme == "http" || u . Scheme == "https" || u . Scheme == "git" ) {
if models . IsErrInvalidCloneAddr ( err ) {
ctx . Data [ "Err_MirrorAddress" ] = true
ctx . Data [ "Err_MirrorAddress" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.mirror_address_protocol_invalid" ) , tplSettingsOptions , & form )
addrErr := err . ( * models . ErrInvalidCloneAddr )
return
switch {
}
case addrErr . IsProtocolInvalid :
ctx . RenderWithErr ( ctx . Tr ( "repo.mirror_address_protocol_invalid" ) , tplSettingsOptions , & form )
if form . MirrorUsername != "" || form . MirrorPassword != "" {
case addrErr . IsURLError :
u . User = url . UserPassword ( form . MirrorUsername , form . MirrorPassword )
ctx . RenderWithErr ( ctx . Tr ( "form.url_error" ) , tplSettingsOptions , & form )
}
case addrErr . IsPermissionDenied :
if len ( addrErr . PrivateNet ) == 0 {
// Now use xurls
ctx . RenderWithErr ( ctx . Tr ( "repo.migrate.permission_denied_private_ip" ) , tplSettingsOptions , & form )
address := validFormAddress . FindString ( form . MirrorAddress )
} else if ! addrErr . LocalPath {
if address != form . MirrorAddress && form . MirrorAddress != "" {
ctx . RenderWithErr ( ctx . Tr ( "repo.migrate.permission_denied_blocked" ) , tplSettingsOptions , & form )
ctx . Data [ "Err_MirrorAddress" ] = true
} else {
ctx . RenderWithErr ( ctx . Tr ( "repo.mirror_address_url_invalid" ) , tplSettingsOptions , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.migrate.permission_denied" ) , tplSettingsOptions , & form )
return
}
}
case addrErr . IsInvalidPath :
ctx . RenderWithErr ( ctx . Tr ( "repo.migrate.invalid_local_path" ) , tplSettingsOptions , & form )
if u . EscapedPath ( ) == "" || u . Host == "" || ! u . IsAbs ( ) {
default :
ctx . ServerError ( "Unknown error" , err )
}
}
ctx . Data [ "Err_MirrorAddress" ] = true
ctx . Data [ "Err_MirrorAddress" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.mirror_address_url_invalid" ) , tplSettingsOptions , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.mirror_address_url_invalid" ) , tplSettingsOptions , & form )
return
return
}
}
address = u . String ( )
if err := mirror_service . UpdateAddress ( ctx . Repo . Mirror , address ) ; err != nil {
if err := mirror_service . UpdateAddress ( ctx . Repo . Mirror , address ) ; err != nil {
ctx . ServerError ( "UpdateAddress" , err )
ctx . ServerError ( "UpdateAddress" , err )
return
return
@ -951,14 +944,6 @@ func DeleteDeployKey(ctx *context.Context) {
} )
} )
}
}
func init ( ) {
var err error
validFormAddress , err = xurls . StrictMatchingScheme ( ` (https?)|(git):// ` )
if err != nil {
panic ( err )
}
}
// UpdateAvatarSetting update repo's avatar
// UpdateAvatarSetting update repo's avatar
func UpdateAvatarSetting ( ctx * context . Context , form auth . AvatarForm ) error {
func UpdateAvatarSetting ( ctx * context . Context , form auth . AvatarForm ) error {
ctxRepo := ctx . Repo . Repository
ctxRepo := ctx . Repo . Repository