mirror of https://github.com/jumpserver/jumpserver
命令搜素完成
parent
53e4dc7acb
commit
d5bd2143e2
|
@ -22,10 +22,7 @@ class Alert(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class TtyLog(models.Model):
|
class TtyLog(models.Model):
|
||||||
log_id = models.IntegerField(max_length=50)
|
log = models.ForeignKey(Log)
|
||||||
username = models.CharField(max_length=100)
|
|
||||||
host = models.CharField(max_length=100)
|
|
||||||
remote_ip = models.CharField(max_length=100)
|
|
||||||
datetime = models.DateTimeField()
|
datetime = models.DateTimeField()
|
||||||
cmd = models.CharField(max_length=200)
|
cmd = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
|
|
@ -43,23 +43,38 @@ from jlog.log_api import renderTemplate
|
||||||
def log_list(request, offset):
|
def log_list(request, offset):
|
||||||
""" 显示日志 """
|
""" 显示日志 """
|
||||||
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
|
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
|
||||||
keyword = request.GET.get('keyword', None)
|
|
||||||
# posts = get_user_log(get_user_info(request, offset))
|
# 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':
|
if offset == 'online':
|
||||||
web_socket_host = CONF.get('websocket', 'web_socket_host')
|
web_socket_host = CONF.get('websocket', 'web_socket_host')
|
||||||
posts = Log.objects.filter(is_finished=False).order_by('-start_time')
|
posts = Log.objects.filter(is_finished=False).order_by('-start_time')
|
||||||
else:
|
else:
|
||||||
posts = Log.objects.filter(is_finished=True).order_by('-start_time')
|
posts = Log.objects.filter(is_finished=True).order_by('-start_time')
|
||||||
if keyword is not None:
|
username_all = set([log.user for log in Log.objects.all()])
|
||||||
date_seven_day = request.GET.get('start')
|
ip_all = set([log.host for log in Log.objects.all()])
|
||||||
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))
|
|
||||||
|
|
||||||
|
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:
|
else:
|
||||||
date_now = datetime.datetime.now()
|
date_now = datetime.datetime.now()
|
||||||
date_now_str = date_now.strftime('%m/%d/%Y')
|
date_now_str = date_now.strftime('%m/%d/%Y')
|
||||||
|
@ -92,14 +107,18 @@ def log_list(request, offset):
|
||||||
def log_history(request):
|
def log_history(request):
|
||||||
""" 命令历史记录 """
|
""" 命令历史记录 """
|
||||||
log_id = request.GET.get('id', 0)
|
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 tty_logs:
|
if log:
|
||||||
content = ''
|
log = log[0]
|
||||||
for tty_log in tty_logs:
|
tty_logs = log.ttylog_set.all()
|
||||||
content += '%s: %s\n' % (tty_log.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), tty_log.cmd)
|
|
||||||
return HttpResponse(content)
|
if tty_logs:
|
||||||
else:
|
content = ''
|
||||||
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
for tty_log in tty_logs:
|
||||||
|
content += '%s: %s\n' % (tty_log.datetime.strftime('%Y-%m-%d %H:%M:%S'), tty_log.cmd)
|
||||||
|
return HttpResponse(content)
|
||||||
|
|
||||||
|
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
||||||
|
|
||||||
|
|
||||||
def log_record(request):
|
def log_record(request):
|
||||||
|
|
|
@ -260,7 +260,7 @@ class Jtty(object):
|
||||||
|
|
||||||
if str(x) in ['\r', '\n', '\r\n']:
|
if str(x) in ['\r', '\n', '\r\n']:
|
||||||
input_r = remove_control_char(input_r)
|
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_r = ''
|
||||||
input_mode = False
|
input_mode = False
|
||||||
|
|
||||||
|
|
|
@ -72,38 +72,24 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select name="single" data-placeholder="用户名" class="chosen-select" multiple style="width:200px;" tabindex="2">
|
<select name="username" data-placeholder="用户名" class="chosen-select" multiple style="width:200px;" tabindex="2">
|
||||||
<option value="用户">用户名</option>
|
{% for username in username_all %}
|
||||||
<option value="Bolivia, Plurinational State of">hongweiguang</option>
|
<option value="{{ username }}"{% if username in username_list %}selected{% endif %}>{{ username }}</option>
|
||||||
<option value="Bonaire, Sint Eustatius and Saba">wangyong</option>
|
{% endfor %}
|
||||||
<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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select name="multi" data-placeholder="主机" class="chosen-select" multiple style="width:200px;" tabindex="4">
|
<select name="host" data-placeholder="主机" class="chosen-select" multiple style="width:200px;" tabindex="4">
|
||||||
<option value="主机">主机</option>
|
{% for ip in ip_all %}
|
||||||
<option value="United States">172.16.1.1</option>
|
<option value="{{ ip }}" {% if ip in host_list %}selected{% endif %}>{{ ip }}</option>
|
||||||
<option value="Afghanistan">172.16.1.1</option>
|
{% endfor %}
|
||||||
<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>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
|
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
<ul class="nav nav-tabs">
|
<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 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/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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
Loading…
Reference in New Issue