mirror of https://github.com/jumpserver/jumpserver
web 批量执行命令
parent
88fbcabcbb
commit
4959073a33
|
@ -9,5 +9,5 @@ urlpatterns = patterns('',
|
|||
url(r'^log_kill/', log_kill),
|
||||
url(r'^record/$', log_record),
|
||||
url(r'^web_terminal/$', web_terminal),
|
||||
url(r'^get_role_name/$', get_role_name),
|
||||
|
||||
)
|
|
@ -107,16 +107,6 @@ def log_record(request):
|
|||
return HttpResponse('无日志记录!')
|
||||
|
||||
|
||||
@require_role('user')
|
||||
def get_role_name(request):
|
||||
asset_id = request.GET.get('id', 9999)
|
||||
asset = get_object(Asset, id=asset_id)
|
||||
if asset:
|
||||
role = user_have_perm(request.user, asset=asset)
|
||||
return HttpResponse(','.join([i.name for i in role]))
|
||||
return HttpResponse('error')
|
||||
|
||||
|
||||
@require_role('user')
|
||||
def web_terminal(request):
|
||||
asset_id = request.GET.get('id')
|
||||
|
|
|
@ -300,6 +300,21 @@ def get_role_push_host(role):
|
|||
asset_no_push = set(asset_all) - set(asset_pushed.keys())
|
||||
return asset_pushed, asset_no_push
|
||||
|
||||
|
||||
@require_role('user')
|
||||
def perm_role_get(request):
|
||||
asset_id = request.GET.get('id', 0)
|
||||
if asset_id:
|
||||
asset = get_object(Asset, id=asset_id)
|
||||
if asset:
|
||||
role = user_have_perm(request.user, asset=asset)
|
||||
return HttpResponse(','.join([i.name for i in role]))
|
||||
else:
|
||||
roles = get_group_user_perm(request.user).get('role').keys()
|
||||
return HttpResponse(','.join(i.name for i in roles))
|
||||
return HttpResponse('error')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print get_role_info(1)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ urlpatterns = patterns('jperm.views',
|
|||
(r'^role/perm_role_edit/$', perm_role_edit),
|
||||
(r'^role/push/$', perm_role_push),
|
||||
(r'^role/recycle/$', perm_role_recycle),
|
||||
(r'^role/get/$', perm_role_get),
|
||||
(r'^sudo/$', perm_sudo_list),
|
||||
(r'^sudo/perm_sudo_add/$', perm_sudo_add),
|
||||
(r'^sudo/perm_sudo_delete/$', perm_sudo_delete),
|
||||
|
|
|
@ -362,6 +362,6 @@ def download(request):
|
|||
|
||||
@login_required(login_url='/login')
|
||||
def exec_cmd(request):
|
||||
role_name = request.GET.get('role_name')
|
||||
web_terminal_uri = 'ws://%s/exec?role=%s' % (WEB_SOCKET_HOST, role_name)
|
||||
role = request.GET.get('role')
|
||||
web_terminal_uri = 'ws://%s/exec?role=%s' % (WEB_SOCKET_HOST, role)
|
||||
return my_render('exec_cmd.html', locals(), request)
|
||||
|
|
|
@ -229,7 +229,8 @@ class ExecHandler(tornado.websocket.WebSocketHandler):
|
|||
@require_auth('user')
|
||||
def open(self):
|
||||
logger.debug('Websocket: Open exec request')
|
||||
role_name = self.get_argument('role', 'dev')
|
||||
role_name = self.get_argument('role', 'sb')
|
||||
logger.debug('Web执行命令: 请求角色 %s' % role_name)
|
||||
self.role = get_object(PermRole, name=role_name)
|
||||
self.perm = get_group_user_perm(self.user)
|
||||
roles = self.perm.get('role').keys()
|
||||
|
@ -262,7 +263,7 @@ class ExecHandler(tornado.websocket.WebSocketHandler):
|
|||
header = "<span style='color: red'>[ %s => %s]</span>\n" % (host, 'failed')
|
||||
self.write_message(header)
|
||||
self.write_message(output)
|
||||
self.write_message('\n\n')
|
||||
self.write_message('\n~o~ Task finished ~o~\n')
|
||||
|
||||
|
||||
class WebTerminalHandler(tornado.websocket.WebSocketHandler):
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
<script type="text/javascript">
|
||||
var wsUri = "{{ web_terminal_uri }}"+"&role=dev";
|
||||
var wsUri = "{{ web_terminal_uri }}"; //请求的websocket url
|
||||
var ws = new WebSocket(wsUri);
|
||||
|
||||
function createSystemMessage(message) {
|
||||
|
@ -92,7 +92,7 @@
|
|||
{# background-color: #ecf0f1;#}
|
||||
{# border: #000 solid 5px;#}
|
||||
background: #000;
|
||||
width: 600px;
|
||||
width: 800px;
|
||||
box-shadow: rgba(0, 0, 0, 0.8) 2px 2px 20px;
|
||||
color: #fff;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@
|
|||
position: fixed;
|
||||
bottom: 0;
|
||||
height: 50px;
|
||||
width: 600px;
|
||||
width: 800px;
|
||||
{# border: #000 solid -10px;#}
|
||||
background-color: #2980b9;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@
|
|||
}
|
||||
|
||||
.content {
|
||||
width: 600px;
|
||||
width: 800px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,8 +177,8 @@
|
|||
});
|
||||
|
||||
$('#exec_cmd').click(function(){
|
||||
var url='/jlog/get_role_name/?id={{ user.id }}';
|
||||
var href = $(this).attr('href');
|
||||
var url = '/jperm/role/get/';
|
||||
var new_url = '/exec_cmd/?role=';
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
|
@ -192,7 +192,7 @@
|
|||
title: title,
|
||||
maxmin: true,
|
||||
shade: false,
|
||||
area: ['628px', '452px'],
|
||||
area: ['800px', '700px'],
|
||||
content: new_url+data
|
||||
});
|
||||
//window.open(new_url + data, '', 'location=no, resizeable=no, height=410, width=625, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,status=no');
|
||||
|
@ -201,7 +201,7 @@
|
|||
} else {
|
||||
aUrl = '';
|
||||
$.each(dataArray, function(index, value){
|
||||
aUrl += '<a onclick="windowOpen(this); return false" class="btn btn-xs btn-primary newa" href=' + new_url + value + ' value=' + hostname + '>' + value + '</a> '
|
||||
aUrl += '<a onclick="windowOpenExec(this); return false" class="btn btn-xs btn-primary newa" href=' + new_url + value + '>' + value + '</a> '
|
||||
});
|
||||
layer.alert(aUrl, {
|
||||
skin: 'layui-layer-molv',
|
||||
|
@ -217,7 +217,7 @@
|
|||
});
|
||||
|
||||
$('.conn').click(function(){
|
||||
var url='/jlog/get_role_name/?id=' + $(this).attr('value');
|
||||
var url='/jperm/role/get/?id=' + $(this).attr('value');
|
||||
var href = $(this).attr('href');
|
||||
var new_url = '/jlog/web_terminal/?id=' + $(this).attr('value') + '&role=';
|
||||
var hostname = $(this).closest('tr').find('.hostname')[0].innerHTML;
|
||||
|
@ -270,7 +270,21 @@
|
|||
shade: false,
|
||||
content: new_url
|
||||
});
|
||||
//window.open(new_url, '', 'height=410, width=625, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
|
||||
return false
|
||||
}
|
||||
|
||||
function windowOpenExec(a){
|
||||
var new_url = $(a).attr('href');
|
||||
var title = 'Jumpserver Exec Terminal';
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: title,
|
||||
maxmin: true,
|
||||
area: ['800px', '700px'],
|
||||
shade: false,
|
||||
content: new_url
|
||||
});
|
||||
console.log(new_url);
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue