diff --git a/apps/i18n/zh/LC_MESSAGES/django.mo b/apps/i18n/zh/LC_MESSAGES/django.mo index 161c337a8..61378222c 100644 Binary files a/apps/i18n/zh/LC_MESSAGES/django.mo and b/apps/i18n/zh/LC_MESSAGES/django.mo differ diff --git a/apps/i18n/zh/LC_MESSAGES/django.po b/apps/i18n/zh/LC_MESSAGES/django.po index fe6da5ca0..b5167eab5 100644 --- a/apps/i18n/zh/LC_MESSAGES/django.po +++ b/apps/i18n/zh/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Jumpserver 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-03-14 19:07+0800\n" +"POT-Creation-Date: 2018-03-21 15:15+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: ibuler \n" "Language-Team: Jumpserver team\n" @@ -29,9 +29,8 @@ msgstr "" msgid "测试节点下资产是否可连接: {}" msgstr "" -#: assets/forms/asset.py:23 assets/forms/asset.py:54 assets/forms/user.py:125 -#: assets/models/asset.py:53 assets/models/user.py:218 -#: assets/templates/assets/asset_detail.html:183 +#: assets/forms/asset.py:23 assets/forms/asset.py:54 assets/models/asset.py:53 +#: assets/models/user.py:218 assets/templates/assets/asset_detail.html:183 #: assets/templates/assets/asset_detail.html:191 #: assets/templates/assets/system_user_detail.html:166 msgid "Nodes" @@ -64,7 +63,7 @@ msgid "* required Must set exact system platform, Windows, Linux ..." msgstr "* required 必须准确设置操作系统平台,如Windows, Linux ..." #: assets/forms/asset.py:80 assets/forms/asset.py:84 assets/forms/label.py:15 -#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:244 +#: perms/templates/perms/asset_permission_asset.html:88 users/forms.py:270 msgid "Select assets" msgstr "选择资产" @@ -162,15 +161,11 @@ msgstr "名称" msgid "Username" msgstr "用户名" -#: assets/forms/user.py:132 -msgid "If auto push checked, system user will be create at node assets" -msgstr "如果选择了自动推送,系统用户将会创建在节点资产上" - -#: assets/forms/user.py:133 +#: assets/forms/user.py:126 msgid "Auto push system user to asset" msgstr "自动推送系统用户到资产" -#: assets/forms/user.py:134 +#: assets/forms/user.py:127 msgid "" "High level will be using login asset as default, if user was granted more " "than 2 system user" @@ -370,10 +365,10 @@ msgstr "默认资产组" #: terminal/templates/terminal/command_list.html:32 #: terminal/templates/terminal/command_list.html:72 #: terminal/templates/terminal/session_list.html:33 -#: terminal/templates/terminal/session_list.html:71 users/forms.py:192 +#: terminal/templates/terminal/session_list.html:71 users/forms.py:218 #: users/models/user.py:30 users/models/user.py:254 #: users/templates/users/user_group_detail.html:78 -#: users/templates/users/user_group_list.html:13 users/views/user.py:333 +#: users/templates/users/user_group_list.html:13 users/views/user.py:334 msgid "User" msgstr "用户" @@ -627,7 +622,7 @@ msgstr "激活所选" #: users/templates/users/user_list.html:44 #: users/templates/users/user_password_update.html:59 #: users/templates/users/user_profile_update.html:64 -#: users/templates/users/user_pubkey_update.html:71 +#: users/templates/users/user_pubkey_update.html:77 msgid "Submit" msgstr "提交" @@ -647,6 +642,8 @@ msgstr "提交" #: users/templates/users/user_group_detail.html:28 #: users/templates/users/user_group_list.html:43 #: users/templates/users/user_list.html:76 +#: users/templates/users/user_profile.html:135 +#: users/templates/users/user_profile.html:143 msgid "Update" msgstr "更新" @@ -713,10 +710,10 @@ msgstr "其它" #: users/templates/users/_user.html:43 #: users/templates/users/user_bulk_update.html:23 #: users/templates/users/user_password_update.html:58 -#: users/templates/users/user_profile.html:135 -#: users/templates/users/user_profile.html:143 +#: users/templates/users/user_profile.html:151 #: users/templates/users/user_profile_update.html:63 #: users/templates/users/user_pubkey_update.html:70 +#: users/templates/users/user_pubkey_update.html:76 msgid "Reset" msgstr "重置" @@ -782,7 +779,7 @@ msgstr "替换资产的管理员" #: users/templates/users/user_group_create_update.html:32 #: users/templates/users/user_group_list.html:86 #: users/templates/users/user_list.html:196 -#: users/templates/users/user_profile.html:177 +#: users/templates/users/user_profile.html:185 msgid "Confirm" msgstr "确认" @@ -1175,6 +1172,7 @@ msgid "User search filter" msgstr "用户过滤器" #: common/forms.py:121 +#, python-format msgid "Choice may be (cn|uid|sAMAccountName)=%(user)s)" msgstr "可能的选项是(cn或uid或sAMAccountName=%(user)s)" @@ -1613,7 +1611,7 @@ msgstr "添加" msgid "Add asset group to this permission" msgstr "添加资产组" -#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:247 +#: perms/templates/perms/asset_permission_asset.html:116 users/forms.py:273 msgid "Select asset groups" msgstr "选择资产组" @@ -1642,7 +1640,7 @@ msgstr "资产组数量" msgid "System user count" msgstr "系统用户数量" -#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:250 +#: perms/templates/perms/asset_permission_detail.html:144 users/forms.py:276 msgid "Select system users" msgstr "选择系统用户" @@ -1695,13 +1693,13 @@ msgstr "商业支持" msgid "Docs" msgstr "文档" -#: templates/_header_bar.html:37 templates/_nav_user.html:9 +#: templates/_header_bar.html:37 templates/_nav_user.html:9 users/forms.py:92 #: users/templates/users/_user.html:36 #: users/templates/users/user_password_update.html:37 #: users/templates/users/user_profile.html:17 #: users/templates/users/user_profile_update.html:37 #: users/templates/users/user_profile_update.html:57 -#: users/templates/users/user_pubkey_update.html:37 users/views/user.py:316 +#: users/templates/users/user_pubkey_update.html:37 users/views/user.py:317 msgid "Profile" msgstr "个人信息" @@ -1758,13 +1756,13 @@ msgstr "关闭" #: templates/_nav.html:10 users/views/group.py:28 users/views/group.py:44 #: users/views/group.py:62 users/views/group.py:79 users/views/group.py:95 -#: users/views/login.py:209 users/views/login.py:258 users/views/user.py:59 -#: users/views/user.py:74 users/views/user.py:93 users/views/user.py:149 -#: users/views/user.py:304 users/views/user.py:351 users/views/user.py:373 +#: users/views/login.py:209 users/views/login.py:258 users/views/user.py:60 +#: users/views/user.py:75 users/views/user.py:94 users/views/user.py:150 +#: users/views/user.py:305 users/views/user.py:352 users/views/user.py:374 msgid "Users" msgstr "用户管理" -#: templates/_nav.html:13 users/views/user.py:60 +#: templates/_nav.html:13 users/views/user.py:61 msgid "User list" msgstr "用户列表" @@ -2087,51 +2085,63 @@ msgstr "" msgid "Role" msgstr "角色" -#: users/forms.py:45 users/templates/users/user_detail.html:187 -msgid "Join user groups" -msgstr "添加到用户组" - -#: users/forms.py:76 -msgid "Old password" -msgstr "原来密码" - -#: users/forms.py:81 -msgid "New password" -msgstr "新密码" - -#: users/forms.py:86 -msgid "Confirm password" -msgstr "确认密码" - -#: users/forms.py:96 -msgid "Old password error" -msgstr "原来密码错误" - -#: users/forms.py:104 -msgid "Password does not match" -msgstr "密码不一致" - -#: users/forms.py:116 +#: users/forms.py:30 users/forms.py:138 msgid "ssh public key" msgstr "ssh公钥" -#: users/forms.py:117 +#: users/forms.py:31 users/forms.py:139 msgid "ssh-rsa AAAA..." msgstr "" -#: users/forms.py:118 -msgid "Paste your id_rsa.pub here." -msgstr "复制你的公钥到这里" +#: users/forms.py:32 +msgid "Paste user id_rsa.pub here." +msgstr "复制用户公钥到这里" -#: users/forms.py:131 +#: users/forms.py:50 users/templates/users/user_detail.html:187 +msgid "Join user groups" +msgstr "添加到用户组" + +#: users/forms.py:58 users/forms.py:153 msgid "Public key should not be the same as your old one." msgstr "不能和原来的密钥相同" -#: users/forms.py:135 users/serializers.py:42 +#: users/forms.py:62 users/forms.py:157 users/serializers.py:42 msgid "Not a valid ssh public key" msgstr "ssh密钥不合法" -#: users/forms.py:149 users/forms.py:154 users/forms.py:166 users/forms.py:196 +#: users/forms.py:98 +msgid "Old password" +msgstr "原来密码" + +#: users/forms.py:103 +msgid "New password" +msgstr "新密码" + +#: users/forms.py:108 +msgid "Confirm password" +msgstr "确认密码" + +#: users/forms.py:118 +msgid "Old password error" +msgstr "原来密码错误" + +#: users/forms.py:126 +msgid "Password does not match" +msgstr "密码不一致" + +#: users/forms.py:140 +msgid "Paste your id_rsa.pub here." +msgstr "复制你的公钥到这里" + +#: users/forms.py:168 users/models/user.py:46 +#: users/templates/users/user_password_update.html:43 +#: users/templates/users/user_profile.html:71 +#: users/templates/users/user_profile_update.html:43 +#: users/templates/users/user_pubkey_update.html:43 +msgid "Public key" +msgstr "ssh公钥" + +#: users/forms.py:175 users/forms.py:180 users/forms.py:192 users/forms.py:222 msgid "Select users" msgstr "选择用户" @@ -2184,13 +2194,6 @@ msgstr "微信" msgid "Enable OTP" msgstr "二次验证" -#: users/models/user.py:46 users/templates/users/user_password_update.html:43 -#: users/templates/users/user_profile.html:71 -#: users/templates/users/user_profile_update.html:43 -#: users/templates/users/user_pubkey_update.html:43 -msgid "Public key" -msgstr "ssh公钥" - #: users/models/user.py:265 msgid "Administrator is the super user of system" msgstr "Administrator是初始的超级管理员" @@ -2241,13 +2244,13 @@ msgstr "首次登陆" msgid "Step" msgstr "Step" -#: users/templates/users/first_login.html:59 -msgid "First step" -msgstr "第一步" +#: users/templates/users/first_login.html:57 +msgid "Previous" +msgstr "" #: users/templates/users/first_login.html:60 -msgid "Prev step" -msgstr "上一步" +msgid "Next" +msgstr "" #: users/templates/users/first_login_done.html:30 msgid "Welcome to use jumpserver, visit " @@ -2283,8 +2286,7 @@ msgid "City" msgstr "城市" #: users/templates/users/reset_password.html:45 -#: users/templates/users/user_detail.html:325 -#: users/templates/users/user_profile.html:132 users/utils.py:71 +#: users/templates/users/user_detail.html:325 users/utils.py:71 msgid "Reset password" msgstr "重置密码" @@ -2298,7 +2300,7 @@ msgid "Setting" msgstr "设置" #: users/templates/users/user_create.html:4 -#: users/templates/users/user_list.html:16 users/views/user.py:74 +#: users/templates/users/user_list.html:16 users/views/user.py:75 msgid "Create user" msgstr "创建用户" @@ -2307,7 +2309,7 @@ msgid "Reset link will be generated and sent to the user. " msgstr "生成重置密码连接,通过邮件发送给用户" #: users/templates/users/user_detail.html:19 -#: users/templates/users/user_granted_asset.html:18 users/views/user.py:150 +#: users/templates/users/user_granted_asset.html:18 users/views/user.py:151 msgid "User detail" msgstr "用户详情" @@ -2351,7 +2353,6 @@ msgid "" msgstr "重设密钥邮件将会发送到用户邮箱" #: users/templates/users/user_detail.html:350 -#: users/templates/users/user_profile.html:140 msgid "Reset SSH public key" msgstr "重置SSH密钥" @@ -2360,14 +2361,14 @@ msgid "This will reset the user public key and send a reset mail" msgstr "将会失效用户当前密钥,并发送重置邮件到用户邮箱" #: users/templates/users/user_detail.html:377 -#: users/templates/users/user_profile.html:166 +#: users/templates/users/user_profile.html:174 msgid "Successfully updated the SSH public key." msgstr "更新ssh密钥成功" #: users/templates/users/user_detail.html:378 #: users/templates/users/user_detail.html:382 -#: users/templates/users/user_profile.html:167 -#: users/templates/users/user_profile.html:172 +#: users/templates/users/user_profile.html:175 +#: users/templates/users/user_profile.html:180 msgid "User SSH public key update" msgstr "ssh密钥" @@ -2427,12 +2428,24 @@ msgstr "用户删除失败" msgid "OTP" msgstr "" -#: users/templates/users/user_profile.html:100 users/views/user.py:179 -#: users/views/user.py:233 +#: users/templates/users/user_profile.html:100 users/views/user.py:180 +#: users/views/user.py:234 msgid "User groups" msgstr "用户组" -#: users/templates/users/user_profile.html:170 +#: users/templates/users/user_profile.html:132 +msgid "Update password" +msgstr "更改密码" + +#: users/templates/users/user_profile.html:140 +msgid "Update SSH public key" +msgstr "更改SSH密钥" + +#: users/templates/users/user_profile.html:148 +msgid "Reset public key and download" +msgstr "重置并下载SSH密钥" + +#: users/templates/users/user_profile.html:178 msgid "Failed to update SSH public key." msgstr "更新密钥失败" @@ -2448,7 +2461,11 @@ msgstr "指纹" msgid "Update public key" msgstr "更新密钥" -#: users/templates/users/user_update.html:4 users/views/user.py:93 +#: users/templates/users/user_pubkey_update.html:68 +msgid "Or reset by server" +msgstr "或者重置并下载密钥" + +#: users/templates/users/user_update.html:4 users/views/user.py:94 msgid "Update user" msgstr "更新用户" @@ -2643,30 +2660,39 @@ msgstr "首次登陆" msgid "Login log list" msgstr "登录日志" -#: users/views/user.py:103 +#: users/views/user.py:104 msgid "Bulk update user success" msgstr "批量更新用户成功" -#: users/views/user.py:208 +#: users/views/user.py:209 msgid "Invalid file." msgstr "文件不合法" -#: users/views/user.py:305 +#: users/views/user.py:306 msgid "User granted assets" msgstr "用户授权资产" -#: users/views/user.py:334 +#: users/views/user.py:335 msgid "Profile setting" msgstr "个人信息设置" -#: users/views/user.py:352 +#: users/views/user.py:353 msgid "Password update" msgstr "密码更新" -#: users/views/user.py:374 +#: users/views/user.py:375 msgid "Public key update" msgstr "密钥更新" +#~ msgid "If auto push checked, system user will be create at node assets" +#~ msgstr "如果选择了自动推送,系统用户将会创建在节点资产上" + +#~ msgid "First step" +#~ msgstr "第一步" + +#~ msgid "Prev step" +#~ msgstr "上一步" + #~ msgid "Test node assets connective: {}" #~ msgstr "测试节点资产可连接性" diff --git a/apps/users/forms.py b/apps/users/forms.py index 58b78de71..8d223b627 100644 --- a/apps/users/forms.py +++ b/apps/users/forms.py @@ -26,6 +26,11 @@ class UserCreateUpdateForm(forms.ModelForm): max_length=128, strip=False, required=False, ) role = forms.ChoiceField(choices=role_choices, required=True, initial=User.ROLE_USER, label=_("Role")) + public_key = forms.CharField( + label=_('ssh public key'), max_length=5000, + widget=forms.Textarea(attrs={'placeholder': _('ssh-rsa AAAA...')}), + help_text=_('Paste user id_rsa.pub here.') + ) class Meta: model = User @@ -47,12 +52,26 @@ class UserCreateUpdateForm(forms.ModelForm): ), } + def clean_public_key(self): + public_key = self.cleaned_data['public_key'] + if self.instance.public_key and public_key == self.instance.public_key: + msg = _('Public key should not be the same as your old one.') + raise forms.ValidationError(msg) + + if not validate_ssh_public_key(public_key): + raise forms.ValidationError(_('Not a valid ssh public key')) + return public_key + def save(self, commit=True): password = self.cleaned_data.get('password') + public_key = self.cleaned_data.get('public_key') user = super().save(commit=commit) if password: user.set_password(password) user.save() + if public_key: + user.public_key = public_key + user.save() return user @@ -70,6 +89,9 @@ class UserProfileForm(forms.ModelForm): } +UserProfileForm.verbose_name = _("Profile") + + class UserPasswordForm(forms.Form): old_password = forms.CharField( max_length=128, widget=forms.PasswordInput, @@ -113,7 +135,7 @@ class UserPasswordForm(forms.Form): class UserPublicKeyForm(forms.Form): public_key = forms.CharField( - label=_('ssh public key'), max_length=5000, + label=_('ssh public key'), max_length=5000, required=False, widget=forms.Textarea(attrs={'placeholder': _('ssh-rsa AAAA...')}), help_text=_('Paste your id_rsa.pub here.') ) @@ -131,17 +153,21 @@ class UserPublicKeyForm(forms.Form): msg = _('Public key should not be the same as your old one.') raise forms.ValidationError(msg) - if not validate_ssh_public_key(public_key): + if public_key and not validate_ssh_public_key(public_key): raise forms.ValidationError(_('Not a valid ssh public key')) return public_key def save(self): public_key = self.cleaned_data['public_key'] - self.instance.public_key = public_key - self.instance.save() + if public_key: + self.instance.public_key = public_key + self.instance.save() return self.instance +UserPublicKeyForm.verbose_name = _("Public key") + + class UserBulkUpdateForm(forms.ModelForm): users = forms.ModelMultipleChoiceField( required=True, diff --git a/apps/users/models/user.py b/apps/users/models/user.py index 4c051db22..0e2e06f39 100644 --- a/apps/users/models/user.py +++ b/apps/users/models/user.py @@ -115,7 +115,7 @@ class User(AbstractUser): import sshpubkeys try: return sshpubkeys.SSHKey(self.public_key) - except TabError: + except (TabError, TypeError): pass return PubKey() diff --git a/apps/users/templates/users/first_login.html b/apps/users/templates/users/first_login.html index 99aff6ccf..b670caf60 100644 --- a/apps/users/templates/users/first_login.html +++ b/apps/users/templates/users/first_login.html @@ -45,10 +45,8 @@ {{ wizard.form.management_form }} {% for form in wizard.form.forms %} {% bootstrap_form form %} -{# {{ form|bootstrap }}#} {% endfor %} {% else %} -{# {{ wizard.form|bootstrap }}#} {% bootstrap_form wizard.form %} {% endif %} @@ -56,8 +54,10 @@
diff --git a/apps/users/templates/users/user_profile.html b/apps/users/templates/users/user_profile.html index e7e8640f9..88d963595 100644 --- a/apps/users/templates/users/user_profile.html +++ b/apps/users/templates/users/user_profile.html @@ -22,7 +22,7 @@
-
+
{{ user.name }} @@ -120,7 +120,7 @@
-
+
{% trans 'Quick modify' %} @@ -129,18 +129,26 @@ - + - + + + + + @@ -180,8 +188,11 @@ $(document).on('click', '#btn_update_pk', function() { $('#txt_pk').focus(); } ); - } + }; APIUpdateAttr({ url: the_url, body: JSON.stringify(body), success: success, error: fail}); +}).on('click', '.btn-reset-pubkey', function () { + var the_url = '{% url "users:user-pubkey-generate" %}'; + window.open(the_url, "_blank") }) {% endblock %} diff --git a/apps/users/templates/users/user_pubkey_update.html b/apps/users/templates/users/user_pubkey_update.html index ee621eb8d..82c4a3590 100644 --- a/apps/users/templates/users/user_pubkey_update.html +++ b/apps/users/templates/users/user_pubkey_update.html @@ -64,6 +64,12 @@

{% trans 'Update public key' %}

{% bootstrap_field form.public_key layout="horizontal" %} +
+ + +
diff --git a/apps/users/templates/users/user_update.html b/apps/users/templates/users/user_update.html index a83d89859..88ec01c5c 100644 --- a/apps/users/templates/users/user_update.html +++ b/apps/users/templates/users/user_update.html @@ -5,4 +5,5 @@ {% block password %}

{% trans 'Auth' %}

{% bootstrap_field form.password layout="horizontal" %} + {% bootstrap_field form.public_key layout="horizontal" %} {% endblock %} diff --git a/apps/users/urls/views_urls.py b/apps/users/urls/views_urls.py index 5d23976ae..b9d6788ee 100644 --- a/apps/users/urls/views_urls.py +++ b/apps/users/urls/views_urls.py @@ -20,6 +20,7 @@ urlpatterns = [ url(r'^profile/update/$', views.UserProfileUpdateView.as_view(), name='user-profile-update'), url(r'^profile/password/update/$', views.UserPasswordUpdateView.as_view(), name='user-password-update'), url(r'^profile/pubkey/update/$', views.UserPublicKeyUpdateView.as_view(), name='user-pubkey-update'), + url(r'^profile/pubkey/generate/$', views.UserPublicKeyGenerateView.as_view(), name='user-pubkey-generate'), # User view url(r'^user$', views.UserListView.as_view(), name='user-list'), diff --git a/apps/users/views/user.py b/apps/users/views/user.py index bf2ecca57..84c670370 100644 --- a/apps/users/views/user.py +++ b/apps/users/views/user.py @@ -31,7 +31,7 @@ from django.contrib.auth import logout as auth_logout from common.const import create_success_msg, update_success_msg from common.mixins import JSONResponseMixin -from common.utils import get_logger, get_object_or_none, is_uuid +from common.utils import get_logger, get_object_or_none, is_uuid, ssh_key_gen from .. import forms from ..models import User, UserGroup from ..utils import AdminUserRequiredMixin @@ -45,6 +45,7 @@ __all__ = [ 'UserExportView', 'UserBulkImportView', 'UserProfileView', 'UserProfileUpdateView', 'UserPasswordUpdateView', 'UserPublicKeyUpdateView', 'UserBulkUpdateView', + 'UserPublicKeyGenerateView', ] logger = get_logger(__name__) @@ -375,3 +376,15 @@ class UserPublicKeyUpdateView(LoginRequiredMixin, UpdateView): } kwargs.update(context) return super().get_context_data(**kwargs) + + +class UserPublicKeyGenerateView(LoginRequiredMixin, View): + def get(self, request, *args, **kwargs): + private, public = ssh_key_gen(username=request.user.username, hostname='jumpserver') + request.user.public_key = public + request.user.save() + response = HttpResponse(private, content_type='text/plain') + filename = "{0}-jumpserver.pem".format(request.user.username) + response['Content-Disposition'] = 'attachment; filename={}'.format(filename) + return response +
{% trans 'Reset password' %}:{% trans 'Update password' %}: - {% trans 'Reset' %} + {% trans 'Update' %}
{% trans 'Reset SSH public key' %}:{% trans 'Update SSH public key' %}: - {% trans 'Reset' %} + {% trans 'Update' %} + +
{% trans 'Reset public key and download' %}: + + {% trans 'Reset' %}