summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/error.go14
-rw-r--r--models/ssh_key.go2
-rw-r--r--options/locale/locale_en-US.ini1
-rw-r--r--routers/api/v1/repo/key.go4
-rw-r--r--routers/repo/setting.go9
-rw-r--r--routers/user/setting.go9
-rw-r--r--templates/repo/settings/deploy_keys.tmpl4
-rw-r--r--templates/user/settings/keys_ssh.tmpl4
8 files changed, 39 insertions, 8 deletions
diff --git a/models/error.go b/models/error.go
index aa9db7abef..9df419aee8 100644
--- a/models/error.go
+++ b/models/error.go
@@ -37,6 +37,20 @@ func (err ErrNamePatternNotAllowed) Error() string {
return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
}
+// ErrSSHDisabled represents an "SSH disabled" error.
+type ErrSSHDisabled struct {
+}
+
+// IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
+func IsErrSSHDisabled(err error) bool {
+ _, ok := err.(ErrSSHDisabled)
+ return ok
+}
+
+func (err ErrSSHDisabled) Error() string {
+ return "SSH is disabled"
+}
+
// ____ ___
// | | \______ ___________
// | | / ___// __ \_ __ \
diff --git a/models/ssh_key.go b/models/ssh_key.go
index 15544efbc6..2d9f521fd4 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -260,7 +260,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
// It returns the actual public key line on success.
func CheckPublicKeyString(content string) (_ string, err error) {
if setting.SSH.Disabled {
- return "", errors.New("SSH is disabled")
+ return "", ErrSSHDisabled{}
}
content, err = parseKeyString(content)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 87c14e302d..834ec49e53 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -405,6 +405,7 @@ key_state_desc = This key has been used in the last 7 days
token_state_desc = This token has been used in the last 7 days
show_openid = Show on profile
hide_openid = Hide from profile
+ssh_disabled = SSH is disabled
manage_social = Manage Associated Social Accounts
social_desc = This is a list of associated social accounts. For security reasons, please make sure you recognize all of these entries, as they can be used to log in to your account.
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index a20f4c829e..42082c3561 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.go
@@ -106,7 +106,9 @@ func GetDeployKey(ctx *context.APIContext) {
// HandleCheckKeyStringError handle check key error
func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
- if models.IsErrKeyUnableVerify(err) {
+ if models.IsErrSSHDisabled(err) {
+ ctx.Error(422, "", "SSH is disabled")
+ } else if models.IsErrKeyUnableVerify(err) {
ctx.Error(422, "", "Unable to verify key content")
} else {
ctx.Error(422, "", fmt.Errorf("Invalid key content: %v", err))
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index ebe1c7cd9e..5586e81f05 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -515,6 +515,7 @@ func GitHooksEditPost(ctx *context.Context) {
func DeployKeys(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true
+ ctx.Data["DisableSSH"] = setting.SSH.Disabled
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
if err != nil {
@@ -545,15 +546,17 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) {
content, err := models.CheckPublicKeyString(form.Content)
if err != nil {
- if models.IsErrKeyUnableVerify(err) {
+ if models.IsErrSSHDisabled(err) {
+ ctx.Flash.Info(ctx.Tr("settings.ssh_disabled"))
+ } else if models.IsErrKeyUnableVerify(err) {
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
} else {
ctx.Data["HasError"] = true
ctx.Data["Err_Content"] = true
ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error()))
- ctx.Redirect(ctx.Repo.RepoLink + "/settings/keys")
- return
}
+ ctx.Redirect(ctx.Repo.RepoLink + "/settings/keys")
+ return
}
key, err := models.AddDeployKey(ctx.Repo.Repository.ID, form.Title, content)
diff --git a/routers/user/setting.go b/routers/user/setting.go
index a00f3f287a..eae97e9aff 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -339,6 +339,7 @@ func DeleteEmail(ctx *context.Context) {
func SettingsKeys(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsKeys"] = true
+ ctx.Data["DisableSSH"] = setting.SSH.Disabled
keys, err := models.ListPublicKeys(ctx.User.ID)
if err != nil {
@@ -405,13 +406,15 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) {
case "ssh":
content, err := models.CheckPublicKeyString(form.Content)
if err != nil {
- if models.IsErrKeyUnableVerify(err) {
+ if models.IsErrSSHDisabled(err) {
+ ctx.Flash.Info(ctx.Tr("settings.ssh_disabled"))
+ } else if models.IsErrKeyUnableVerify(err) {
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
} else {
ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error()))
- ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
- return
}
+ ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
+ return
}
if _, err = models.AddPublicKey(ctx.User.ID, form.Title, content); err != nil {
diff --git a/templates/repo/settings/deploy_keys.tmpl b/templates/repo/settings/deploy_keys.tmpl
index f082fde86b..caf9f29ce5 100644
--- a/templates/repo/settings/deploy_keys.tmpl
+++ b/templates/repo/settings/deploy_keys.tmpl
@@ -7,7 +7,11 @@
<h4 class="ui top attached header">
{{.i18n.Tr "repo.settings.deploy_keys"}}
<div class="ui right">
+ {{if not .DisableSSH}}
<div class="ui blue tiny show-panel button" data-panel="#add-deploy-key-panel">{{.i18n.Tr "repo.settings.add_deploy_key"}}</div>
+ {{else}}
+ <div class="ui blue tiny button disabled">{{.i18n.Tr "settings.ssh_disabled"}}</div>
+ {{end}}
</div>
</h4>
<div class="ui attached segment">
diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl
index 1bdf0b15b1..18fd918012 100644
--- a/templates/user/settings/keys_ssh.tmpl
+++ b/templates/user/settings/keys_ssh.tmpl
@@ -1,7 +1,11 @@
<h4 class="ui top attached header">
{{.i18n.Tr "settings.manage_ssh_keys"}}
<div class="ui right">
+ {{if not .DisableSSH}}
<div class="ui blue tiny show-panel button" data-panel="#add-ssh-key-panel">{{.i18n.Tr "settings.add_key"}}</div>
+ {{else}}
+ <div class="ui blue tiny button disabled">{{.i18n.Tr "settings.ssh_disabled"}}</div>
+ {{end}}
</div>
</h4>
<div class="ui attached segment">