Commit 7294bbb2 authored by BaiJiangJie's avatar BaiJiangJie

[Update] Session online/offline 添加remote_addr搜索功能

parent 35f64674
......@@ -43,7 +43,7 @@ class Gateway(AssetUser):
ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'), db_index=True)
port = models.IntegerField(default=22, verbose_name=_('Port'))
protocol = models.CharField(choices=PROTOCOL_CHOICES, max_length=16, default=SSH_PROTOCOL, verbose_name=_("Protocol"))
domain = models.ForeignKey(Domain, verbose_name=_("Domain"))
domain = models.ForeignKey(Domain, on_delete=models.DO_NOTHING, verbose_name=_("Domain"))
comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=_("Comment"))
is_active = models.BooleanField(default=True, verbose_name=_("Is active"))
......
......@@ -52,6 +52,14 @@
{% endfor %}
</select>
</div>
<div class="input-group">
<select class="select2 form-control" name="remote_addr">
<option value="">{% trans 'Remote addr' %}</option>
{% for ra in remote_addr_list %}
<option value="{{ ra }}" {% if ra == remote_addr %} selected {% endif %}>{{ ra }}</option>
{% endfor %}
</select>
</div>
{# <div class="input-group">#}
{# <input type="text" class="form-control input-sm" name="keyword" placeholder="Keyword" value="{{ keyword }}">#}
{# </div>#}
......
......@@ -18,6 +18,10 @@ def get_session_system_user_list():
return set(list(Session.objects.values_list('system_user', flat=True)))
def get_session_remote_addr_list():
return set(list(Session.objects.values_list('remote_addr', flat=True)))
def get_user_list_from_cache():
return cache.get(USERS_CACHE_KEY)
......
......@@ -27,7 +27,7 @@ class SessionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
template_name = 'terminal/session_list.html'
context_object_name = 'session_list'
paginate_by = settings.DISPLAY_PER_PAGE
user = asset = system_user = ''
user = asset = system_user = remote_addr = ''
date_from = date_to = None
def get_queryset(self):
......@@ -35,6 +35,7 @@ class SessionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
self.user = self.request.GET.get('user')
self.asset = self.request.GET.get('asset')
self.system_user = self.request.GET.get('system_user')
self.remote_addr = self.request.GET.get('remote_addr')
filter_kwargs = dict()
filter_kwargs['date_start__gt'] = self.date_from
......@@ -45,6 +46,8 @@ class SessionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
filter_kwargs['asset'] = self.asset
if self.system_user:
filter_kwargs['system_user'] = self.system_user
if self.remote_addr:
filter_kwargs['remote_addr'] = self.remote_addr
if filter_kwargs:
self.queryset = self.queryset.filter(**filter_kwargs)
return self.queryset
......@@ -54,11 +57,13 @@ class SessionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
'user_list': utils.get_session_user_list(),
'asset_list': utils.get_session_asset_list(),
'system_user_list': utils.get_session_system_user_list(),
'remote_addr_list': utils.get_session_remote_addr_list(),
'date_from': self.date_from,
'date_to': self.date_to,
'user': self.user,
'asset': self.asset,
'system_user': self.system_user,
'remote_addr': self.remote_addr,
}
kwargs.update(context)
return super().get_context_data(**kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment