mirror of https://github.com/jumpserver/jumpserver
Merge branch 'dev' of git.coding.net:jumpserver/jumpserver into dev
commit
60166ac008
|
@ -16,7 +16,7 @@ from jumpserver.models import Setting
|
|||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from jlog.models import Log
|
||||
|
||||
from jperm.perm_api import get_group_user_perm
|
||||
|
||||
def getDaysByNum(num):
|
||||
"""
|
||||
|
@ -72,7 +72,7 @@ def get_count_by_date(date_li, item):
|
|||
|
||||
return len(set(data_count_tmp))
|
||||
|
||||
|
||||
from jasset.models import Asset, IDC
|
||||
@require_role(role='user')
|
||||
def index_cu(request):
|
||||
# user_id = request.user.id
|
||||
|
@ -80,6 +80,21 @@ def index_cu(request):
|
|||
login_types = {'L': 'LDAP', 'M': 'MAP'}
|
||||
username = request.user.username
|
||||
# TODO: need fix,liuzheng need Asset help
|
||||
GUP = get_group_user_perm(request.user)
|
||||
print GUP
|
||||
assets = GUP.get('asset')
|
||||
idcs = []
|
||||
for i in assets:
|
||||
if i.idc_id:
|
||||
idcs.append(i.idc_id)
|
||||
idc_all = IDC.objects.filter(id__in=idcs)
|
||||
for i in idc_all:
|
||||
print i.name
|
||||
# idc_all = []
|
||||
# for i in assets:
|
||||
# idc_all.append(i.idc)
|
||||
# print i.idc.name
|
||||
asset_group_all = GUP.get('asset_group')
|
||||
# posts = Asset.object.all()
|
||||
# host_count = len(posts)
|
||||
#
|
||||
|
|
|
@ -28,4 +28,6 @@ urlpatterns = patterns('juser.views',
|
|||
(r'^change_role/$', 'chg_role'),
|
||||
(r'^regen_ssh_key/$', 'regen_ssh_key'),
|
||||
(r'^down_key/$', 'down_key'),
|
||||
|
||||
(r'runcommand/$', 'RunCommand'),
|
||||
)
|
||||
|
|
|
@ -12,7 +12,7 @@ from juser.user_api import *
|
|||
|
||||
MAIL_FROM = EMAIL_HOST_USER
|
||||
|
||||
|
||||
@login_required(login_url='/login')
|
||||
def chg_role(request):
|
||||
role = {'SU': 2, 'GA': 1, 'CU': 0}
|
||||
if request.session['role_id'] > 0:
|
||||
|
@ -238,10 +238,10 @@ def user_detail(request):
|
|||
# user, dept = get_session_user_dept(request)
|
||||
# if not validate(request, user=[user_id]):
|
||||
# return HttpResponseRedirect('/')
|
||||
# if not user_id:
|
||||
# return HttpResponseRedirect('/juser/user_list/')
|
||||
|
||||
# user = get_object(User, id=user_id)
|
||||
user_id = request.GET.get('id', '')
|
||||
if not user_id:
|
||||
return HttpResponseRedirect('/juser/user_list/')
|
||||
user = User.objects.get(id=user_id)
|
||||
# if user:
|
||||
# pass
|
||||
# asset_group_permed = user.get_asset_group()
|
||||
|
@ -488,3 +488,11 @@ def down_key(request):
|
|||
return response
|
||||
|
||||
return HttpResponse('No Key File. Contact Admin.')
|
||||
from jperm.perm_api import get_group_user_perm
|
||||
@require_role(role='user')
|
||||
def RunCommand(request):
|
||||
if request.method == 'GET':
|
||||
GUP = get_group_user_perm(request.user)
|
||||
print GUP
|
||||
assets = GUP.get('asset')
|
||||
return render_to_response('juser/run_command.html', locals(), context_instance=RequestContext(request))
|
|
@ -53,18 +53,147 @@
|
|||
</div>
|
||||
|
||||
<div class="ibox-content">
|
||||
<table class="table table-striped">
|
||||
{% for host_five in new_posts %}
|
||||
<tr>
|
||||
{% for host in host_five %}
|
||||
<td>{{ host.ip }}</td>
|
||||
<form id="asset_form">
|
||||
<div class="col-sm-2" style="padding-left: 0px">
|
||||
<label>
|
||||
<select name="idc" class="form-control m-b" onchange="change_info()">
|
||||
<option value="">IDC机房</option>
|
||||
{% for idc in idc_all %}
|
||||
{% ifequal idc.name idc_name %}
|
||||
<option value="{{ idc.name }}" selected> {{ idc.name }}</option>
|
||||
{% else %}
|
||||
<option value="{{ idc.name }}"> {{ idc.name }}</option>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
<select name="group" class="form-control m-b" onchange="change_info()">
|
||||
<option value="">主机组</option>
|
||||
{% for asset_group in asset_group_all %}
|
||||
{% ifequal asset_group.name group_name %}
|
||||
<option value="{{ asset_group.name }}"
|
||||
selected> {{ asset_group.name }} </option>
|
||||
{% else %}
|
||||
<option value="{{ asset_group.name }}"> {{ asset_group.name }} </option>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
<select name="asset_type" class="form-control m-b" onchange="change_info()">
|
||||
<option value="">所有类型</option>
|
||||
{% for type in asset_types %}
|
||||
{% ifequal type.0|int2str asset_type %}
|
||||
<option value="{{ type.0 }}" selected> {{ type.1 }}</option>
|
||||
{% else %}
|
||||
<option value="{{ type.0 }}"> {{ type.1 }}</option>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
<select name="status" class="form-control m-b" onchange="change_info()">
|
||||
<option value="">所有状态</option>
|
||||
{% for s in asset_status %}
|
||||
{% ifequal s.0|int2str status %}
|
||||
<option value="{{ s.0 }}" selected> {{ s.1 }}</option>
|
||||
{% else %}
|
||||
<option value="{{ s.0 }}"> {{ s.1 }}</option>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control m-b" id="search_input" name="keyword"
|
||||
value="{{ keyword }}" placeholder="Search">
|
||||
<input type="text" style="display: none">
|
||||
|
||||
<div class="input-group-btn">
|
||||
<button id='search_btn' href="/jasset/asset_list/?search=true" type="button"
|
||||
class="btn btn-xm btn-primary search-btn" onclick="change_info()">
|
||||
- 搜索 -
|
||||
</button>
|
||||
<button type="button" href="/jasset/asset_list/?export=true" name="export"
|
||||
class="btn btn-xm btn-success search-btn-excel" onclick="return false">
|
||||
- 导出 -
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="export"></div>
|
||||
<table class="table table-striped table-bordered table-hover " id="editable" name="editable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">
|
||||
<input id="checkall" type="checkbox" class="i-checks" name="checkall"
|
||||
value="checkall" data-editable='false' onclick="check_all('asset_form')">
|
||||
</th>
|
||||
<th class="text-center"> 主机名</th>
|
||||
<th class="text-center" name="ip"> IP地址</th>
|
||||
<th class="text-center"> IDC</th>
|
||||
<th class="text-center"> 所属主机组</th>
|
||||
{# <th class="text-center"> 配置信息 </th>#}
|
||||
<th class="text-center"> 操作系统</th>
|
||||
<th class="text-center"> 使用默认管理</th>
|
||||
<th class="text-center"> 操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for asset in assets %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'>
|
||||
<input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks">
|
||||
</td>
|
||||
<td class="text-center"> {{ asset.hostname|default_if_none:"" }} </td>
|
||||
<td class="text-center"> {{ asset.ip|default_if_none:"" }} </td>
|
||||
<td class="text-center"> {{ asset.idc.name|default_if_none:"" }} </td>
|
||||
<td class="text-center">{{ asset.group.all|group_str2 }}</td>
|
||||
{# <td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>#}
|
||||
<td class="text-center">
|
||||
{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}</td>
|
||||
<td class="text-center"> {{ asset.use_default_auth|bool2str }} </td>
|
||||
<td class="text-center" data-editable='false'>
|
||||
<a href="/jasset/asset_detail/?id={{ asset.id }}"
|
||||
class="btn btn-xs btn-primary">详情</a>
|
||||
{% ifnotequal session_role_id 0 %}
|
||||
{% if user.role == 'admin' %}
|
||||
|
||||
<a href="/jasset/asset_edit/?id={{ asset.id }}"
|
||||
class="btn btn-xs btn-info">编辑</a>
|
||||
<a href="/jasset/asset_update/?id={{ asset.id }}"
|
||||
class="btn btn-xs btn-info">更新</a>
|
||||
<a value="/jasset/asset_del/?id={{ asset.id }}"
|
||||
class="btn btn-xs btn-danger asset_del">删除</a>
|
||||
{% endif %}
|
||||
{% endifnotequal %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% ifequal host_count 0 %}
|
||||
(空)
|
||||
{% endifequal %}
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% if user.role == 'admin' %}
|
||||
<input type="button" id="asset_del" class="btn btn-danger btn-sm" name="del_button"
|
||||
value="删除"/>
|
||||
<a value="/jasset/asset_edit_batch/" type="button"
|
||||
class="btn btn-sm btn-warning iframe">修改</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% include 'paginator.html' %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% load mytags %}
|
||||
{% block content %}
|
||||
{% include 'nav_cat_bar.html' %}
|
||||
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5> 命令批量执行 </h5>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapise-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
</a>
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="fa fa-wrench"></i>
|
||||
</a>
|
||||
<a class="close-link">
|
||||
<i class="fa fa-times"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ibox-content">
|
||||
<form method="post" id="ruleForm" class="form-horizontal" action="">
|
||||
{% if error %}
|
||||
<div class="alert alert-warning text-center">{{ error }}</div>
|
||||
{% endif %}
|
||||
{% if msg %}
|
||||
<div class="alert alert-success text-center">{{ msg }}</div>
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="asset" class="col-sm-2 control-label">资产<span class="red-fonts">*</span></label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
<select name="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b"
|
||||
multiple tabindex="2">
|
||||
{% for asset in assets %}
|
||||
<option value="{{ asset.ip }}">{{ asset.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">命令<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input class="form-control" name="cmd" placeholder="请输入要执行的命令">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-white" type="clean">清除</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit">运行</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
{% block self_head_css_js %}
|
||||
{% load staticfiles %}
|
||||
<script src="{% static 'js/jquery.shiftcheckbox.js' %}"></script>
|
||||
<link href="/static/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
|
||||
<link href="/static/css/plugins/chosen/chosen.css" rel="stylesheet">
|
||||
<script src="/static/js/plugins/chosen/chosen.jquery.js"></script>
|
||||
{% endblock %}
|
||||
{% block self_footer_js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
|
||||
var config = {
|
||||
'.chosen-select': {},
|
||||
'.chosen-select-deselect': {allow_single_deselect: true},
|
||||
'.chosen-select-no-single': {disable_search_threshold: 10},
|
||||
'.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},
|
||||
'.chosen-select-width': {width: "95%"}
|
||||
};
|
||||
|
||||
for (var selector in config) {
|
||||
$(selector).chosen(config[selector]);
|
||||
}
|
||||
|
||||
$('.del').click(function(){
|
||||
var row = $(this).closest('tr');
|
||||
if (confirm("确定删除")) {
|
||||
$.get(
|
||||
$(this).attr('value'),
|
||||
{},
|
||||
function(data){
|
||||
row.remove();
|
||||
alert(data);
|
||||
}
|
||||
)}
|
||||
});
|
||||
|
||||
$('#del_btn').click(function(){
|
||||
var check_array = [];
|
||||
if (confirm("确定删除")) {
|
||||
$(".gradeX input:checked").each(function() {
|
||||
check_array.push($(this).attr("value"))
|
||||
});
|
||||
$.post("/juser/user_del/",
|
||||
{id: check_array.join(",")},
|
||||
function(data){
|
||||
$(".gradeX input:checked").closest("tr").remove();
|
||||
alert(data);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('.email').click(function(){
|
||||
$.get('/juser/send_mail_retry/?uuid=' + $(this).attr('value'),
|
||||
{},
|
||||
function(data){
|
||||
alert(data)
|
||||
}
|
||||
)
|
||||
});
|
||||
$("tbody tr").shiftcheckbox({
|
||||
checkboxSelector: 'input:checkbox',
|
||||
selectAll: $('#select_all'),
|
||||
ignoreClick: 'a'
|
||||
});
|
||||
$('.shiftCheckbox').shiftcheckbox();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -126,6 +126,9 @@
|
|||
<li class="apply_show online"><a href="/jperm/apply_show/online/">申请记录</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li id="command">
|
||||
<a href="/juser/runcommand/"><span>批量执行命令</span></a>
|
||||
</li>
|
||||
<li id="jlog">
|
||||
<a href="/jlog/log_list/online/"><i class="fa fa-files-o"></i> <span class="nav-label">登录历史</span><span class="label label-info pull-right"></span></a>
|
||||
</li>
|
||||
|
|
|
@ -73,6 +73,11 @@
|
|||
<div class="dropzone-previews">
|
||||
<input id="hosts" name="hosts" type="text" class="form-control" required="不能为空"
|
||||
placeholder="输入主机地址,逗号隔开,确保你有输入主机地址的权限" size="80%">
|
||||
<select name="assetgroup" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2">
|
||||
{% for asset_group in asset_groups %}
|
||||
<option value="{{ asset_group.name }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
{# <div id="hosts_list" style="position:absolute;display: none;z-index:999;">#}
|
||||
{# TODO: by liuzheng#}
|
||||
|
|
Loading…
Reference in New Issue