[Update] 修改ldap和command

pull/3317/head
ibuler 2019-10-09 16:49:36 +08:00
parent dc5598f8dc
commit 74ab311d3e
4 changed files with 37 additions and 24 deletions

View File

@ -102,6 +102,7 @@ class LDAPUserListApi(generics.ListAPIView):
if hasattr(self, 'swagger_fake_view'):
return []
util = LDAPUtil()
try:
users = util.search_user_items()
except Exception as e:
@ -112,20 +113,6 @@ class LDAPUserListApi(generics.ListAPIView):
user['id'] = user['username']
return users
def filter_queryset(self, queryset):
search = self.request.query_params.get('search')
if not search:
return queryset
search = search.lower()
queryset = [
q for q in queryset
if
search in q['username'].lower()
or search in q['name'].lower()
or search in q['email'].lower()
]
return queryset
def sort_queryset(self, queryset):
order_by = self.request.query_params.get('order')
if not order_by:
@ -139,7 +126,7 @@ class LDAPUserListApi(generics.ListAPIView):
return queryset
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
queryset = self.get_queryset()
queryset = self.sort_queryset(queryset)
page = self.paginate_queryset(queryset)
if page is not None:

View File

@ -81,9 +81,12 @@ class LDAPUtil:
user_item[attr] = value
return user_item
def _search_user_items_ou(self, search_ou, cookie=None):
def _search_user_items_ou(self, search_ou, extra_filter=None, cookie=None):
search_filter = self.search_filter % {"user": "*"}
if extra_filter:
search_filter = '(&({})({}))'.format(search_filter, extra_filter)
ok = self.connection.search(
search_ou, self.search_filter % ({"user": "*"}),
search_ou, search_filter,
attributes=list(self.attr_map.values()),
paged_size=self.paged_size, paged_cookie=cookie
)
@ -108,16 +111,21 @@ class LDAPUtil:
cookie = self.connection.result['controls']['1.2.840.113556.1.4.319']['value']['cookie']
return cookie
def search_user_items(self):
def search_user_items(self, q=None):
user_items = []
logger.info("Search user items")
extra_filter = ''
if q:
for attr in self.attr_map.values():
extra_filter += '({}={})'.format(attr, q)
extra_filter = '(|{})'.format(extra_filter)
for search_ou in str(self.search_ougroup).split("|"):
logger.info("Search user search ou: {}".format(search_ou))
_user_items = self._search_user_items_ou(search_ou)
_user_items = self._search_user_items_ou(search_ou, extra_filter=extra_filter)
user_items.extend(_user_items)
while self._cookie():
logger.info("Page Search user search ou: {}".format(search_ou))
_user_items = self._search_user_items_ou(search_ou, self._cookie())
_user_items = self._search_user_items_ou(search_ou, extra_filter, self._cookie())
user_items.extend(_user_items)
logger.info("Search user items end")
return user_items

View File

@ -164,11 +164,14 @@ $(document).ready(function () {
detailRows.push(tr.attr('id'));
}
}
})
});
function format(d) {
var output = $("<pre style='border: none; background: none'></pre>");
output.append('$ ', d.input);
output.append('\r\n\r\n');
output.append(d.output);
return output
}
@ -187,6 +190,17 @@ function initTable() {
$(td).addClass("toggle");
$(td).html("<i class='fa fa-angle-right'></i>");
}},
{targets: 1, createdCell: function (td, cellData) {
var data = htmlEscape(cellData);
var interHtml = $("<span></span>");
if (data.length > 40) {
interHtml.attr('title', data);
data = data.slice(0, 40);
data += ' ...';
}
interHtml.html(data);
$(td).html(interHtml);
}},
{targets: 5, createdCell: function (td, cellData) {
var data = '<a href="{% url "terminal:session-detail" pk=DEFAULT_PK %}">{% trans "Goto" %}</a>'
.replace('{{ DEFAULT_PK }}', cellData);
@ -200,7 +214,7 @@ function initTable() {
toggle: true,
ajax_url: commandListUrl,
columns: [
{data: "id"}, {data: "input", orderable: false}, {data: "user", orderable: false},
{data: "id"}, {data: "input", orderable: false, width: "40%"}, {data: "user", orderable: false},
{data: "asset", orderable: false}, {data: "system_user", orderable: false},
{data: "session", orderable: false}, {data: "timestamp", width: "160px", orderable: false},
],

View File

@ -54,8 +54,12 @@
{% for command in object_list %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ command.input }}</td>
<td><pre style="border: none;background: none">{{ command.output }}</pre></td>
<td>{{ command.input | truncatechars:40 }}</td>
<td><pre style="border: none;background: none">
$ {{ command.input }}
<br>
{{ command.output }}
</pre></td>
<td>{{ command.timestamp|ts_to_date}}</td>
</tr>
{% empty %}