mirror of https://github.com/jumpserver/jumpserver
命令搜素完成
parent
53e4dc7acb
commit
d5bd2143e2
|
@ -22,10 +22,7 @@ class Alert(models.Model):
|
|||
|
||||
|
||||
class TtyLog(models.Model):
|
||||
log_id = models.IntegerField(max_length=50)
|
||||
username = models.CharField(max_length=100)
|
||||
host = models.CharField(max_length=100)
|
||||
remote_ip = models.CharField(max_length=100)
|
||||
log = models.ForeignKey(Log)
|
||||
datetime = models.DateTimeField()
|
||||
cmd = models.CharField(max_length=200)
|
||||
|
||||
|
|
|
@ -43,23 +43,38 @@ from jlog.log_api import renderTemplate
|
|||
def log_list(request, offset):
|
||||
""" 显示日志 """
|
||||
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
|
||||
keyword = request.GET.get('keyword', None)
|
||||
# posts = get_user_log(get_user_info(request, offset))
|
||||
|
||||
date_seven_day = request.GET.get('start', '')
|
||||
date_now_str = request.GET.get('end', '')
|
||||
username_list = request.GET.getlist('username', [])
|
||||
host_list = request.GET.getlist('host', [])
|
||||
cmd = request.GET.get('cmd', '')
|
||||
print date_seven_day, date_now_str
|
||||
if offset == 'online':
|
||||
web_socket_host = CONF.get('websocket', 'web_socket_host')
|
||||
posts = Log.objects.filter(is_finished=False).order_by('-start_time')
|
||||
else:
|
||||
posts = Log.objects.filter(is_finished=True).order_by('-start_time')
|
||||
if keyword is not None:
|
||||
date_seven_day = request.GET.get('start')
|
||||
date_now_str = request.GET.get('end')
|
||||
datetime_start = datetime.datetime.strptime(date_seven_day, '%m/%d/%Y')
|
||||
datetime_end = datetime.datetime.strptime(date_now_str, '%m/%d/%Y')
|
||||
print datetime_start, datetime_end
|
||||
posts = posts.filter(start_time__gte=datetime_start).filter(start_time__lte=datetime_end).filter(
|
||||
Q(user__icontains=keyword) | Q(host__icontains=keyword) | Q(remote_ip__icontains=keyword))
|
||||
username_all = set([log.user for log in Log.objects.all()])
|
||||
ip_all = set([log.host for log in Log.objects.all()])
|
||||
|
||||
if date_seven_day and date_now_str:
|
||||
datetime_start = datetime.datetime.strptime(date_seven_day, '%m/%d/%Y %H:%M:%S')
|
||||
datetime_end = datetime.datetime.strptime(date_now_str, '%m/%d/%Y %H:%M:%S')
|
||||
posts = posts.filter(start_time__gte=datetime_start).filter(start_time__lte=datetime_end)
|
||||
|
||||
if username_list:
|
||||
print username_list
|
||||
posts = posts.filter(user__in=username_list)
|
||||
|
||||
if host_list:
|
||||
posts = posts.filter(host__in=host_list)
|
||||
print posts
|
||||
if cmd:
|
||||
log_id_list = set([log.log_id for log in TtyLog.objects.filter(cmd__contains=cmd)])
|
||||
print [post.id for post in posts]
|
||||
posts = posts.filter(id__in=log_id_list)
|
||||
print posts
|
||||
else:
|
||||
date_now = datetime.datetime.now()
|
||||
date_now_str = date_now.strftime('%m/%d/%Y')
|
||||
|
@ -92,13 +107,17 @@ def log_list(request, offset):
|
|||
def log_history(request):
|
||||
""" 命令历史记录 """
|
||||
log_id = request.GET.get('id', 0)
|
||||
tty_logs = TtyLog.objects.filter(log_id=int(log_id)).order_by('datetime')
|
||||
log = Log.objects.filter(id=log_id)
|
||||
if log:
|
||||
log = log[0]
|
||||
tty_logs = log.ttylog_set.all()
|
||||
|
||||
if tty_logs:
|
||||
content = ''
|
||||
for tty_log in tty_logs:
|
||||
content += '%s: %s\n' % (tty_log.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), tty_log.cmd)
|
||||
content += '%s: %s\n' % (tty_log.datetime.strftime('%Y-%m-%d %H:%M:%S'), tty_log.cmd)
|
||||
return HttpResponse(content)
|
||||
else:
|
||||
|
||||
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
||||
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ class Jtty(object):
|
|||
|
||||
if str(x) in ['\r', '\n', '\r\n']:
|
||||
input_r = remove_control_char(input_r)
|
||||
TtyLog(log_id=log.id, username=self.username, host=self.ip, remote_ip=ip_list, datetime=datetime.datetime.now(), cmd=input_r).save()
|
||||
TtyLog(log=log, datetime=datetime.datetime.now(), cmd=input_r).save()
|
||||
input_r = ''
|
||||
input_mode = False
|
||||
|
||||
|
|
|
@ -72,38 +72,24 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<select name="single" data-placeholder="用户名" class="chosen-select" multiple style="width:200px;" tabindex="2">
|
||||
<option value="用户">用户名</option>
|
||||
<option value="Bolivia, Plurinational State of">hongweiguang</option>
|
||||
<option value="Bonaire, Sint Eustatius and Saba">wangyong</option>
|
||||
<option value="Bosnia and Herzegovina">hehe</option>
|
||||
<option value="Botswana">wangyong</option>
|
||||
<option value="Bouvet Island">wangyongd</option>
|
||||
<option value="Romania">Romania</option>
|
||||
<option value="Zambia">Zambia</option>
|
||||
<option value="Zimbabwe">Zimbabwe</option>
|
||||
<select name="username" data-placeholder="用户名" class="chosen-select" multiple style="width:200px;" tabindex="2">
|
||||
{% for username in username_all %}
|
||||
<option value="{{ username }}"{% if username in username_list %}selected{% endif %}>{{ username }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<select name="multi" data-placeholder="主机" class="chosen-select" multiple style="width:200px;" tabindex="4">
|
||||
<option value="主机">主机</option>
|
||||
<option value="United States">172.16.1.1</option>
|
||||
<option value="Afghanistan">172.16.1.1</option>
|
||||
<option value="Aland Islands">172.16.1.1</option>
|
||||
<option value="Albania">172.16.1.1</option>
|
||||
<option value="Algeria">172.16.1.1</option>
|
||||
<option value="American Samoa">172.16.1.1</option>
|
||||
<option value="Andorra">172.16.1.1</option>
|
||||
<option value="Angola">172.16.1.1</option>
|
||||
<option value="Anguilla">172.16.1.1</option>
|
||||
<option value="Antarctica">172.16.1.1</option>
|
||||
<select name="host" data-placeholder="主机" class="chosen-select" multiple style="width:200px;" tabindex="4">
|
||||
{% for ip in ip_all %}
|
||||
<option value="{{ ip }}" {% if ip in host_list %}selected{% endif %}>{{ ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input id="cmd" name="cmd" placeholder="命令" type="text" class="form-control" style="width: 200px;">
|
||||
<input id="cmd" name="cmd" placeholder="命令" type="text" class="form-control" value="{{ cmd }}" style="width: 200px;">
|
||||
</div>
|
||||
</div>
|
||||
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="/jlog/log_list/online/" class="text-center"><i class="fa fa-laptop"></i> 在线 </a></li>
|
||||
<li><a href="/jlog/log_list/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 历史记录 </a></li>
|
||||
<li><a href="/jlog/search/" class="text-center"><i class="fa fa-bar-chart-o"></i> 详细搜索 </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<br/>
|
||||
|
|
Loading…
Reference in New Issue