mirror of https://github.com/jumpserver/jumpserver
[Update] 修改ldap和command
parent
dc5598f8dc
commit
74ab311d3e
|
@ -102,6 +102,7 @@ class LDAPUserListApi(generics.ListAPIView):
|
||||||
if hasattr(self, 'swagger_fake_view'):
|
if hasattr(self, 'swagger_fake_view'):
|
||||||
return []
|
return []
|
||||||
util = LDAPUtil()
|
util = LDAPUtil()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
users = util.search_user_items()
|
users = util.search_user_items()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -112,20 +113,6 @@ class LDAPUserListApi(generics.ListAPIView):
|
||||||
user['id'] = user['username']
|
user['id'] = user['username']
|
||||||
return users
|
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):
|
def sort_queryset(self, queryset):
|
||||||
order_by = self.request.query_params.get('order')
|
order_by = self.request.query_params.get('order')
|
||||||
if not order_by:
|
if not order_by:
|
||||||
|
@ -139,7 +126,7 @@ class LDAPUserListApi(generics.ListAPIView):
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.get_queryset()
|
||||||
queryset = self.sort_queryset(queryset)
|
queryset = self.sort_queryset(queryset)
|
||||||
page = self.paginate_queryset(queryset)
|
page = self.paginate_queryset(queryset)
|
||||||
if page is not None:
|
if page is not None:
|
||||||
|
|
|
@ -81,9 +81,12 @@ class LDAPUtil:
|
||||||
user_item[attr] = value
|
user_item[attr] = value
|
||||||
return user_item
|
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(
|
ok = self.connection.search(
|
||||||
search_ou, self.search_filter % ({"user": "*"}),
|
search_ou, search_filter,
|
||||||
attributes=list(self.attr_map.values()),
|
attributes=list(self.attr_map.values()),
|
||||||
paged_size=self.paged_size, paged_cookie=cookie
|
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']
|
cookie = self.connection.result['controls']['1.2.840.113556.1.4.319']['value']['cookie']
|
||||||
return cookie
|
return cookie
|
||||||
|
|
||||||
def search_user_items(self):
|
def search_user_items(self, q=None):
|
||||||
user_items = []
|
user_items = []
|
||||||
logger.info("Search 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("|"):
|
for search_ou in str(self.search_ougroup).split("|"):
|
||||||
logger.info("Search user search ou: {}".format(search_ou))
|
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)
|
user_items.extend(_user_items)
|
||||||
while self._cookie():
|
while self._cookie():
|
||||||
logger.info("Page Search user search ou: {}".format(search_ou))
|
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)
|
user_items.extend(_user_items)
|
||||||
logger.info("Search user items end")
|
logger.info("Search user items end")
|
||||||
return user_items
|
return user_items
|
||||||
|
|
|
@ -164,11 +164,14 @@ $(document).ready(function () {
|
||||||
detailRows.push(tr.attr('id'));
|
detailRows.push(tr.attr('id'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
function format(d) {
|
function format(d) {
|
||||||
var output = $("<pre style='border: none; background: none'></pre>");
|
var output = $("<pre style='border: none; background: none'></pre>");
|
||||||
|
|
||||||
|
output.append('$ ', d.input);
|
||||||
|
output.append('\r\n\r\n');
|
||||||
output.append(d.output);
|
output.append(d.output);
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
@ -187,6 +190,17 @@ function initTable() {
|
||||||
$(td).addClass("toggle");
|
$(td).addClass("toggle");
|
||||||
$(td).html("<i class='fa fa-angle-right'></i>");
|
$(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) {
|
{targets: 5, createdCell: function (td, cellData) {
|
||||||
var data = '<a href="{% url "terminal:session-detail" pk=DEFAULT_PK %}">{% trans "Goto" %}</a>'
|
var data = '<a href="{% url "terminal:session-detail" pk=DEFAULT_PK %}">{% trans "Goto" %}</a>'
|
||||||
.replace('{{ DEFAULT_PK }}', cellData);
|
.replace('{{ DEFAULT_PK }}', cellData);
|
||||||
|
@ -200,7 +214,7 @@ function initTable() {
|
||||||
toggle: true,
|
toggle: true,
|
||||||
ajax_url: commandListUrl,
|
ajax_url: commandListUrl,
|
||||||
columns: [
|
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: "asset", orderable: false}, {data: "system_user", orderable: false},
|
||||||
{data: "session", orderable: false}, {data: "timestamp", width: "160px", orderable: false},
|
{data: "session", orderable: false}, {data: "timestamp", width: "160px", orderable: false},
|
||||||
],
|
],
|
||||||
|
|
|
@ -54,8 +54,12 @@
|
||||||
{% for command in object_list %}
|
{% for command in object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ forloop.counter }}</td>
|
<td>{{ forloop.counter }}</td>
|
||||||
<td>{{ command.input }}</td>
|
<td>{{ command.input | truncatechars:40 }}</td>
|
||||||
<td><pre style="border: none;background: none">{{ command.output }}</pre></td>
|
<td><pre style="border: none;background: none">
|
||||||
|
$ {{ command.input }}
|
||||||
|
<br>
|
||||||
|
{{ command.output }}
|
||||||
|
</pre></td>
|
||||||
<td>{{ command.timestamp|ts_to_date}}</td>
|
<td>{{ command.timestamp|ts_to_date}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
|
|
Loading…
Reference in New Issue