From e62d2b3546314f52dc373aaf9554961140bd51ae Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Wed, 31 Oct 2018 00:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=9A=E5=88=97=E5=87=BALD?= =?UTF-8?q?AP=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=8A=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=B1=9E=E6=80=A7=EF=BC=8C=E6=96=B9=E4=BE=BF=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E8=AE=BE=E7=BD=AELDAP=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE=E9=A1=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/www/teleport/static/js/tp-const.js | 2 +- .../www/teleport/static/js/user/user-list.js | 107 +++++++++++++- server/www/teleport/view/user/user-list.mako | 54 ++++++- .../webroot/app/controller/__init__.py | 2 + .../teleport/webroot/app/controller/user.py | 35 ++++- .../teleport/webroot/app/logic/auth/ldap.py | 133 ++++++++++++------ 6 files changed, 274 insertions(+), 59 deletions(-) diff --git a/server/www/teleport/static/js/tp-const.js b/server/www/teleport/static/js/tp-const.js index fe32258..9d520d2 100755 --- a/server/www/teleport/static/js/tp-const.js +++ b/server/www/teleport/static/js/tp-const.js @@ -257,7 +257,7 @@ function tp_error_msg(error_code, message) { var msg = ''; switch (error_code) { case TPE_NEED_LOGIN: - msg = '需要登录'; + msg = '需要刷新页面,重新登录'; break; case TPE_PRIVILEGE: msg = '没有此操作权限'; diff --git a/server/www/teleport/static/js/user/user-list.js b/server/www/teleport/static/js/user/user-list.js index 90ef730..d7d48b6 100755 --- a/server/www/teleport/static/js/user/user-list.js +++ b/server/www/teleport/static/js/user/user-list.js @@ -192,6 +192,9 @@ $app.create_controls = function (cb_stack) { $app.dlg_ldap_config.show(); }); + $app.dlg_ldap_list_attr_result = $app.create_dlg_ldap_list_attr_result(); + cb_stack.add($app.dlg_ldap_list_attr_result.init); + $app.dlg_ldap_test_result = $app.create_dlg_ldap_test_result(); cb_stack.add($app.dlg_ldap_test_result.init); @@ -1245,11 +1248,13 @@ $app.create_dlg_ldap_config = function () { btn_switch_password: $('#btn-switch-ldap-password'), btn_switch_password_icon: $('#btn-switch-ldap-password i'), + btn_list_attr: $('#btn-ldap-config-list-attr'), btn_test: $('#btn-ldap-config-test'), btn_save: $('#btn-ldap-config-save') }; dlg.init = function (cb_stack) { + dlg.dom.btn_list_attr.click(dlg.do_list_attr); dlg.dom.btn_test.click(dlg.do_test); dlg.dom.btn_save.click(dlg.do_save); @@ -1361,6 +1366,32 @@ $app.create_dlg_ldap_config = function () { return true; }; + dlg.do_list_attr = function () { + if (!dlg.check_fields()) + return; + dlg.dom.btn_test.attr('disabled', 'disabled'); + $tp.ajax_post_json('/user/do-ldap-config-list-attr', { + c: dlg.ldap_config, + p: dlg.ldap_config_password + }, + function (ret) { + dlg.dom.btn_test.removeAttr('disabled'); + if (ret.code === TPE_OK) { + $tp.notify_success('列举LDAP用户属性成功!'); + console.log(ret.data); + $app.dlg_ldap_list_attr_result.show(ret.data.attributes); + } else { + $tp.notify_error('列举LDAP用户属性失败:' + tp_error_msg(ret.code, ret.message)); + } + }, + function () { + dlg.dom.btn_test.removeAttr('disabled'); + $tp.notify_error('网络故障,列举LDAP用户属性失败!'); + }, + 15000 + ); + }; + dlg.do_test = function () { if (!dlg.check_fields()) return; @@ -1372,6 +1403,7 @@ $app.create_dlg_ldap_config = function () { function (ret) { dlg.dom.btn_test.removeAttr('disabled'); if (ret.code === TPE_OK) { + console.log(ret.data); $tp.notify_success('LDAP连接测试成功!'); $app.dlg_ldap_test_result.show(ret.data); } else { @@ -1420,6 +1452,41 @@ $app.create_dlg_ldap_config = function () { return dlg; }; +$app.create_dlg_ldap_list_attr_result = function () { + var dlg = {}; + dlg.dom_id = 'dlg-ldap-list-attr-result'; + + dlg.dom = { + dialog: $('#' + dlg.dom_id), + msg_ret: $('#msg-ldap-list-attr-ret') + }; + + dlg.init = function (cb_stack) { + cb_stack.exec(); + }; + + dlg.show = function (data) { + dlg.dom.msg_ret.html(''); + + var h = []; + + var attr_name; + for (attr_name in data) { + h.push('
' + attr_name + ': '); + // h.push(''+data[attr_name]+'
'); + h.push(''); + h.push(data[attr_name].join(', ')); + h.push(''); + } + + dlg.dom.msg_ret.html($(h.join(''))); + + dlg.dom.dialog.modal(); + }; + + return dlg; +}; + $app.create_dlg_ldap_test_result = function () { var dlg = {}; dlg.dom_id = 'dlg-ldap-test-result'; @@ -1437,13 +1504,40 @@ $app.create_dlg_ldap_test_result = function () { dlg.show = function (data) { dlg.dom.table.empty(); + // var h = []; + // var i, x; + // var th_created = false; + // for (i = 0; i < data.length; ++i) { + // if (!th_created) { + // h.push(''); + // for (x in data[i]) { + // h.push(''); + // h.push(x); + // h.push(''); + // } + // h.push(''); + // th_created = true; + // } + // + // h.push(''); + // for (x in data[i]) { + // h.push(''); + // if (!_.isEmpty(data[i][x])) + // h.push(data[i][x]); + // else + // h.push(''); + // h.push(''); + // } + // h.push(''); + // } + var h = []; - var i, x; + var dn, x; var th_created = false; - for (i = 0; i < data.length; ++i) { + for (dn in data) { if (!th_created) { h.push(''); - for (x in data[i]) { + for (x in data[dn]) { h.push(''); h.push(x); h.push(''); @@ -1453,10 +1547,10 @@ $app.create_dlg_ldap_test_result = function () { } h.push(''); - for (x in data[i]) { + for (x in data[dn]) { h.push(''); - if (!_.isEmpty(data[i][x])) - h.push(data[i][x]); + if (!_.isEmpty(data[dn][x])) + h.push(data[dn][x]); else h.push(''); h.push(''); @@ -1464,6 +1558,7 @@ $app.create_dlg_ldap_test_result = function () { h.push(''); } + dlg.dom.table.append($(h.join(''))); dlg.dom.dialog.modal(); }; diff --git a/server/www/teleport/view/user/user-list.mako b/server/www/teleport/view/user/user-list.mako index 421480c..6269b5f 100644 --- a/server/www/teleport/view/user/user-list.mako +++ b/server/www/teleport/view/user/user-list.mako @@ -389,7 +389,7 @@
- +
@@ -408,17 +408,17 @@
-
teleport将会用 用户名@域 来访问此LDAP服务器。
+
LDAP的账号使用 用户名@域 来登录teleport。
- +
-
LDAP服务的管理员账号,用于列举用户、同步账号。
+
LDAP服务的管理员账号,用于列举用户、同步账号。
@@ -430,6 +430,9 @@ +
+
LDAP服务的管理员密码。
+
@@ -457,10 +460,10 @@
- -
将LDAP的属性映射到 teleport 的用户属性,例如 LDAP中的用户sAMAccountName 映射到teleport的登录账号
+
将LDAP的属性映射到 teleport 的用户属性,例如 LDAP中的用户属性 sAMAccountName 映射为teleport的登录账号。如果不清楚此LDAP服务的用户属性,可使用下方的“列举属性”按钮进行查询。
@@ -474,7 +477,8 @@ tp.email = mail
- + +
@@ -484,6 +488,42 @@ tp.email = mail + +