mirror of https://github.com/jumpserver/jumpserver
shouquanxiugai
parent
d32ea9f9a1
commit
9f7b066ca6
|
@ -5,22 +5,37 @@ from juser.models import User, UserGroup
|
|||
from jasset.models import Asset, AssetGroup
|
||||
|
||||
|
||||
class UserPerm(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
asset = models.ForeignKey(Asset, null=True)
|
||||
asset_group = models.ForeignKey(AssetGroup, null=True)
|
||||
# class PermUserAsset(models.Model):
|
||||
# user = models.ForeignKey(User)
|
||||
# asset = models.ForeignKey(Asset)
|
||||
#
|
||||
# def __unicode__(self):
|
||||
# return self.user.username
|
||||
#
|
||||
#
|
||||
# class PermUserAssetGroup(models.Model):
|
||||
# user = models.ForeignKey(User)
|
||||
# asset_group = models.ForeignKey(AssetGroup)
|
||||
#
|
||||
# def __unicode__(self):
|
||||
# return self.user.username
|
||||
#
|
||||
#
|
||||
# class PermUserGroupAsset(models.Model):
|
||||
# user_group = models.ForeignKey(UserGroup)
|
||||
# asset = models.ForeignKey(Asset)
|
||||
#
|
||||
# def __unicode__(self):
|
||||
# return self.user_group.name
|
||||
#
|
||||
#
|
||||
# class PermUserGroupAssetGroup(models.Model):
|
||||
# user_group = models.ForeignKey(UserGroup)
|
||||
# asset_group = models.ForeignKey(AssetGroup)
|
||||
#
|
||||
# def __unicode__(self):
|
||||
# return self.user_group.name
|
||||
|
||||
def __unicode__(self):
|
||||
return self.user.name
|
||||
|
||||
|
||||
class GroupPerm(models.Model):
|
||||
user_group = models.ForeignKey(UserGroup)
|
||||
asset = models.ForeignKey(Asset, null=True)
|
||||
asset_group = models.ForeignKey(AssetGroup, null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.user.name
|
||||
|
||||
|
||||
# class CmdGroup(models.Model):
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
# coding: utf-8
|
||||
|
||||
from jasset.models import *
|
||||
from jumpserver.api import *
|
||||
import uuid
|
||||
import re
|
||||
from ansible.playbook import PlayBook
|
||||
from ansible import callbacks, utils
|
||||
|
||||
|
||||
def get_object_list(model, id_list):
|
||||
object_list = []
|
||||
for object_id in id_list:
|
||||
if object_id:
|
||||
object_list.extend(model.objects.filter(id=int(object_id)))
|
||||
|
||||
return object_list
|
||||
|
||||
|
||||
def perm_user_handle(user, asset_new, asset_del, group_new, group_del):
|
||||
username = user.name
|
||||
asset_group_new = get_object_list(AssetGroup, group_new)
|
||||
asset_group_del = get_object_list(AssetGroup, group_del)
|
||||
for asset_group in asset_group_new:
|
||||
asset_new.extend([asset.ip for asset in asset_group.asset_set.all()])
|
||||
|
||||
for asset_group in asset_group_del:
|
||||
asset_del.extend(asset.ip for asset in asset_group.asset_set.all())
|
||||
|
||||
|
||||
def get_rand_file_path(base_dir=os.path.join(BASE_DIR, 'tmp')):
|
||||
filename = uuid.uuid1().hex
|
||||
return os.path.join(base_dir, filename)
|
||||
|
||||
|
||||
def get_inventory(host_group):
|
||||
path = get_rand_file_path()
|
||||
f = open(path, 'w')
|
||||
for group, host_list in host_group.items():
|
||||
f.write('[%s]\n' % group)
|
||||
for ip in host_list:
|
||||
asset = get_object(Asset, ip=ip)
|
||||
if asset.use_default_auth:
|
||||
f.write('%s ansbile_ssh_port=%s\n' % (ip, asset.port))
|
||||
else:
|
||||
f.write('%s ansible_ssh_port=%s ansible_ssh_user=%s ansbile_ssh_pass=%s\n'
|
||||
% (ip, asset.port, asset.username, CRYPTOR.decrypt(asset.password)))
|
||||
f.close()
|
||||
return path
|
||||
|
||||
|
||||
def get_playbook(tempate, var):
|
||||
str_playbook = open(tempate).read()
|
||||
for k, v in var.items():
|
||||
str_playbook = re.sub(r'%s' % k, v, str_playbook)
|
||||
path = get_rand_file_path()
|
||||
f = open(path, 'w')
|
||||
f.write(str_playbook)
|
||||
return path
|
||||
|
||||
|
||||
def perm_user_api(user, asset_new, asset_del, asset_group_new, asset_group_del):
|
||||
asset_new_ip = []
|
||||
asset_del_ip = []
|
||||
|
||||
if '' in asset_group_new:
|
||||
asset_group_new.remove('')
|
||||
|
||||
if '' in asset_group_del:
|
||||
asset_group_del.remove('')
|
||||
|
||||
asset_new_ip.extend([asset.ip for asset in get_object_list(Asset, asset_new)])
|
||||
|
||||
for asset_group_id in asset_group_new:
|
||||
asset_new_ip.extend([asset.ip for asset in get_object(AssetGroup, id=asset_group_id).asset_set.all()])
|
||||
|
||||
asset_del_ip.extend([asset.ip for asset in get_object_list(Asset, asset_del)])
|
||||
|
||||
for asset_group_id in asset_group_del:
|
||||
asset_del_ip.extend([asset.ip for asset in get_object(AssetGroup, id=asset_group_id).asset_set.all()])
|
||||
|
||||
print asset_new_ip
|
||||
print asset_del_ip
|
||||
|
||||
stats = callbacks.AggregateStats()
|
||||
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
|
||||
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
|
||||
|
||||
if asset_new_ip or asset_del_ip:
|
||||
host_group = {'new': asset_new_ip, 'del': asset_del_ip}
|
||||
host_list = get_inventory(host_group)
|
||||
playbook = get_playbook(os.path.join(BASE_DIR, 'playbook', 'user_perm.yaml'),
|
||||
{'the_new_group': 'new', 'the_del_group': 'del',
|
||||
'the_user': user.username, 'the_pub_key': '/tmp/id_rsa.pub'})
|
||||
print host_list, playbook
|
||||
results = PlayBook(host_list=host_list,
|
||||
playbook=playbook,
|
||||
forks=5,
|
||||
remote_user='web',
|
||||
remote_pass='redhat',
|
||||
callbacks=playbook_cb,
|
||||
runner_callbacks=runner_cb,
|
||||
stats=stats,
|
||||
become=True,
|
||||
become_user='root').run()
|
||||
|
||||
for hostname, result in results.items():
|
||||
if result.get('failures', 2):
|
||||
print "%s >>> Failed" % hostname
|
||||
else:
|
||||
print "%s >>> Success" % hostname
|
|
@ -3,7 +3,8 @@ from jperm.views import *
|
|||
|
||||
urlpatterns = patterns('jperm.views',
|
||||
# Examples:
|
||||
(r'^user/$', user_perm),
|
||||
(r'^user/$', perm_user_list),
|
||||
(r'^perm_user_edit/$', perm_user_edit),
|
||||
# (r'^dept_perm_edit/$', 'dept_perm_edit'),
|
||||
# (r'^perm_list/$', view_splitter, {'su': perm_list, 'adm': perm_list_adm}),
|
||||
# (r'^dept_perm_list/$', 'dept_perm_list'),
|
||||
|
|
|
@ -8,12 +8,58 @@
|
|||
# from django.template import RequestContext
|
||||
# from jperm.models import Perm, SudoPerm, CmdGroup, Apply
|
||||
from django.db.models import Q
|
||||
from jperm.models import *
|
||||
from jumpserver.api import *
|
||||
from jperm.perm_api import *
|
||||
|
||||
|
||||
def user_perm(request):
|
||||
@require_role('admin')
|
||||
def perm_user_list(request):
|
||||
header_title, path1, path2 = '用户授权', '授权管理', '用户授权'
|
||||
return my_render('jperm/user_perm.html', locals(), request)
|
||||
keyword = request.GET.get('search', '')
|
||||
users_list = User.objects.all()
|
||||
|
||||
if keyword:
|
||||
users_list = users_list.filter(Q(name=keyword) | Q(username=keyword))
|
||||
users_list, p, users, page_range, current_page, show_first, show_end = pages(users_list, request)
|
||||
|
||||
return my_render('jperm/perm_user_list.html', locals(), request)
|
||||
|
||||
|
||||
@require_role('admin')
|
||||
def perm_user_edit(request):
|
||||
header_title, path1, path2 = '用户授权', '授权管理', '授权更改'
|
||||
user_id = request.GET.get('id', '')
|
||||
user = get_object(User, id=user_id)
|
||||
asset_all = Asset.objects.all()
|
||||
asset_group_all = AssetGroup.objects.all()
|
||||
|
||||
asset_id_list = user.assets.split(',')
|
||||
asset_group_id_list = user.asset_groups.split(',')
|
||||
if request.method == 'GET' and user:
|
||||
asset_permed = get_object_list(Asset, asset_id_list)
|
||||
asset_group_permed = get_object_list(AssetGroup, asset_group_id_list)
|
||||
assets = [asset for asset in asset_all if asset not in asset_permed]
|
||||
asset_groups = [asset_group for asset_group in asset_group_all if asset_group not in asset_group_permed]
|
||||
return my_render('jperm/perm_user_edit.html', locals(), request)
|
||||
|
||||
elif request.method == 'POST' and user:
|
||||
asset_select = request.POST.getlist('asset_select', [])
|
||||
asset_group_select = request.POST.getlist('asset_groups_select', [])
|
||||
asset_new = list(set(asset_select) - set(asset_id_list))
|
||||
asset_del = list(set(asset_id_list) - set(asset_select))
|
||||
asset_group_new = list(set(asset_group_select) - set(asset_group_id_list))
|
||||
asset_group_del = list(set(asset_group_id_list) - set(asset_group_select))
|
||||
user.assets = ','.join(asset_select)
|
||||
user.asset_groups = ','.join(asset_group_select)
|
||||
user.save()
|
||||
|
||||
perm_user_api(user, asset_new, asset_del, asset_group_new, asset_group_del)
|
||||
|
||||
return HttpResponseRedirect('/jperm/user/')
|
||||
|
||||
else:
|
||||
return HttpResponse('输入错误')
|
||||
|
||||
|
||||
# def asset_cmd_groups_get(asset_groups_select='', cmd_groups_select=''):
|
||||
|
@ -51,7 +97,7 @@ def user_perm(request):
|
|||
# perm.user_group = user_groups
|
||||
# perm.asset_group = asset_groups
|
||||
# msg = '添加成功'
|
||||
# return render_to_response('jperm/user_perm.html', locals(), context_instance=RequestContext(request))
|
||||
# return render_to_response('jperm/perm_user_edit.html', locals(), context_instance=RequestContext(request))
|
||||
#
|
||||
#
|
||||
# def dept_add_asset(dept_id, asset_list):
|
||||
|
@ -115,7 +161,7 @@ def user_perm(request):
|
|||
# contact_list = contact_list_confirm
|
||||
#
|
||||
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
|
||||
# return render_to_response('jperm/perm_list.html', locals(), context_instance=RequestContext(request))
|
||||
# return render_to_response('jperm/perm_user_list.html', locals(), context_instance=RequestContext(request))
|
||||
#
|
||||
#
|
||||
# @require_admin
|
||||
|
@ -147,7 +193,7 @@ def user_perm(request):
|
|||
# contact_list = contact_list_confirm
|
||||
#
|
||||
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(contact_list, request)
|
||||
# return render_to_response('jperm/perm_list.html', locals(), context_instance=RequestContext(request))
|
||||
# return render_to_response('jperm/perm_user_list.html', locals(), context_instance=RequestContext(request))
|
||||
#
|
||||
#
|
||||
# @require_super_user
|
||||
|
|
|
@ -476,6 +476,10 @@ def get_object(model, **kwargs):
|
|||
use this function for query
|
||||
使用改封装函数查询数据库
|
||||
"""
|
||||
for value in kwargs.values():
|
||||
if not value:
|
||||
return None
|
||||
|
||||
the_object = model.objects.filter(**kwargs)
|
||||
if len(the_object) == 1:
|
||||
the_object = the_object[0]
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# coding: utf-8
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Setting(models.Model):
|
||||
default_user = models.CharField(max_length=100, null=True, blank=True)
|
||||
default_password = models.CharField(max_length=100, null=True, blank=True)
|
||||
default_pri_key_path = models.CharField(max_length=100, null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
db_table = u'setting'
|
|
@ -12,6 +12,7 @@ urlpatterns = patterns('',
|
|||
(r'^logout/$', 'jumpserver.views.logout'),
|
||||
(r'^file/upload/$', 'jumpserver.views.upload'),
|
||||
(r'^file/download/$', 'jumpserver.views.download'),
|
||||
(r'^setting', 'jumpserver.views.setting'),
|
||||
(r'^error/$', 'jumpserver.views.httperror'),
|
||||
(r'^juser/', include('juser.urls')),
|
||||
(r'^jasset/', include('jasset.urls')),
|
||||
|
|
|
@ -229,6 +229,9 @@ def logout(request):
|
|||
request.session.delete()
|
||||
return HttpResponseRedirect('/login/')
|
||||
|
||||
|
||||
def setting(request):
|
||||
return my_render('setting.html', locals(), request)
|
||||
#
|
||||
# def filter_ajax_api(request):
|
||||
# attr = request.GET.get('attr', 'user')
|
||||
|
|
|
@ -32,6 +32,8 @@ class User(models.Model):
|
|||
role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU')
|
||||
uuid = models.CharField(max_length=100)
|
||||
group = models.ManyToManyField(UserGroup)
|
||||
assets = models.TextField(max_length=1000, verbose_name="Assets", default='')
|
||||
asset_groups = models.CharField(max_length=1000, verbose_name="Asset Groups", default='')
|
||||
ssh_key_pwd = models.CharField(max_length=200)
|
||||
is_active = models.BooleanField(default=True)
|
||||
last_login = models.DateTimeField(null=True)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: the_new_group
|
||||
vars:
|
||||
user: the_user
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=the_pub_key dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: the_del_group
|
||||
vars:
|
||||
user: the_user
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent remove=yes
|
|
@ -89,7 +89,7 @@ function move(from, to, from_o, to_o) {
|
|||
//}
|
||||
//
|
||||
|
||||
function selectAll(){
|
||||
function selectAllOption(){
|
||||
var checklist = document.getElementsByName ("selected");
|
||||
if(document.getElementById("select_all").checked)
|
||||
{
|
||||
|
@ -106,6 +106,12 @@ function selectAll(){
|
|||
|
||||
}
|
||||
|
||||
function checkAll(formID){
|
||||
$('#'+formID+'option').each(function(){
|
||||
$(this).attr('checked', true)
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
//function move_all(from, to){
|
||||
// $("#"+from).children().each(function(){
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-white" type="reset">取消</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit" onclick="checkAll('userForm')">确认保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<div class="col-lg-10">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5> 主机授权添加 </h5>
|
||||
<h5> {{ user.name }}授权修改</h5>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-link">
|
||||
<i class="fa fa-chevron-up"></i>
|
||||
|
@ -23,7 +23,7 @@
|
|||
</div>
|
||||
|
||||
<div class="ibox-content">
|
||||
<form id="sudoPerm" method="post" class="form-horizontal" action="">
|
||||
<form id="userPerm" method="post" class="form-horizontal" action="../perm_user_edit/?id={{ user.id }}">
|
||||
{% if error %}
|
||||
<div class="alert alert-warning text-center">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
@ -33,41 +33,48 @@
|
|||
<div class="row">
|
||||
<div class="form-group">
|
||||
<label for="" class="col-sm-2 control-label">用户<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-4">
|
||||
<input id="user_group_id" name="user_group_id"type="text" value="{{ user.id }}" style="display: none">
|
||||
<input id="user_group_name" name="user_group_name" type="text" class="form-control" value="{{ user.name }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="" class="col-sm-2 control-label">资产<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-4">
|
||||
<div>
|
||||
<select id="user_groups" name="user_groups" class="form-control" size="12" multiple>
|
||||
{% for user_group in user_groups %}
|
||||
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
|
||||
<select id="assets" name="assets" class="form-control m-b" size="12" multiple>
|
||||
{% for asset in assets %}
|
||||
<option value="{{ asset.id }}">{{ asset.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 12px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('user_groups', 'user_groups_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('user_groups_select', 'user_groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
<div class="btn-group" style="margin-top: 42px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('assets', 'asset_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_select', 'assets')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="user_groups_select" name="user_groups_select" class="form-control m-b" size="12" multiple>
|
||||
<select id="asset_select" name="asset_select" class="form-control m-b" size="12" multiple>
|
||||
{% for asset in asset_permed %}
|
||||
<option value="{{ asset.id }}">{{ asset.ip }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="group_name" class="col-sm-2 control-label">类型<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input id="comment" name="comment" placeholder="备注说明" type="text" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="" class="col-sm-2 control-label">主机组<span class="red-fonts">*</span></label>
|
||||
<label for="" class="col-sm-2 control-label">资产组<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-4">
|
||||
<div>
|
||||
<select id="asset_groups" name="asset_groups" class="form-control m-b" size="12" multiple>
|
||||
|
@ -79,7 +86,7 @@
|
|||
</div>
|
||||
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 12px;">
|
||||
<div class="btn-group" style="margin-top: 42px;">
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_groups', 'asset_groups_select')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move('asset_groups_select', 'asset_groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
|
@ -88,26 +95,20 @@
|
|||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="12" multiple>
|
||||
{% for asset_group in asset_group_permed %}
|
||||
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="group_name" class="col-sm-2 control-label">备注</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="comment" name="comment" placeholder="备注说明" type="text" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-white" type="reset">取消</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit" onclick="selectAllOption('userForm')">确认保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -130,18 +131,6 @@ $('#sudoPerm').validator({
|
|||
tip: "输入授权名",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
},
|
||||
"user_groups_select": {
|
||||
rule: "required",
|
||||
tip: "选择用户组",
|
||||
ok: "",
|
||||
msg: {checked: "至少选择一个用户组"}
|
||||
},
|
||||
"asset_groups_select": {
|
||||
rule: "required",
|
||||
tip: "选择主机组",
|
||||
ok: "",
|
||||
msg: {checked: "至少选择一个主机组"}
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -156,6 +145,7 @@ $(document).ready(function(){
|
|||
$('#user_groups_select option').each(function(){
|
||||
$(this).prop('selected', true)
|
||||
})
|
||||
|
||||
$('#asset_groups_select option').each(function(){
|
||||
$(this).prop('selected', true)
|
||||
})
|
|
@ -16,12 +16,6 @@
|
|||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
<i class="fa fa-wrench"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-user">
|
||||
<li><a href="#">未启用 1</a>
|
||||
</li>
|
||||
<li><a href="#">未启用 2</a>
|
||||
</li>
|
||||
</ul>
|
||||
<a class="close-link">
|
||||
<i class="fa fa-times"></i>
|
||||
</a>
|
||||
|
@ -30,13 +24,13 @@
|
|||
|
||||
<div class="ibox-content">
|
||||
<div class="">
|
||||
<a target="_blank" href="/juser/group_add/" class="btn btn-sm btn-primary "> 添加小组 </a>
|
||||
<a target="_blank" href="/juser/user_add/" class="btn btn-sm btn-primary "> 添加用户 </a>
|
||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">
|
||||
<div class="input-group-btn">
|
||||
<button id='search_btn' type="submit" class="btn btn-sm btn-primary">
|
||||
Search
|
||||
- 搜索 -
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -46,27 +40,23 @@
|
|||
<table class="table table-striped table-bordered table-hover " id="editable" >
|
||||
<thead>
|
||||
<tr>
|
||||
<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>
|
||||
<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>
|
||||
<th class="text-center">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for group in contacts.object_list %}
|
||||
{% for user in users.object_list %}
|
||||
<tr class="gradeX">
|
||||
<td class="text-center"> {{ group.name }} </td>
|
||||
<td class="text-center"> {{ group.dept.name }} </td>
|
||||
<td class="text-center"> <a href="/juser/user_list/?gid={{ group.id }}">{{ group.id | member_count }} </a> </td>
|
||||
<td class="text-center"> <a href="/jasset/group_list/?gid={{ group.id }}"> {{ group.id | ugrp_perm_agrp_count }} </a> </td>
|
||||
<td class="text-center"> <a href="/jasset/host_list/?gid={{ group.id }}">{{ group.id | ugrp_perm_asset_count }} </a> </td>
|
||||
<td class="text-center"> {{ group.comment }} </td>
|
||||
<td class="text-center"> {{ user.name }} </td>
|
||||
<td class="text-center"> <a href="/juser/user_list/?gid={{ user.id }}">{{ user.id }} </a> </td>
|
||||
<td class="text-center"> <a href="/jasset/host_list/?gid={{ user.id }}">{{ user.id }} </a> </td>
|
||||
<td class="text-center"> {{ user.comment }} </td>
|
||||
<td class="text-center">
|
||||
<a href="../perm_detail/?id={{ group.id }}" class="btn btn-xs btn-primary">详情</a>
|
||||
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-danger">授权编辑</a>
|
||||
<a href="../perm_user_detail/?id={{ user.id }}" class="btn btn-xs btn-primary">详情</a>
|
||||
<a href="../perm_user_edit/?id={{ user.id }}" class="btn btn-xs btn-danger">编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -75,7 +65,7 @@
|
|||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
|
||||
Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
|
||||
Showing {{ users.start_index }} to {{ users.end_index }} of {{ p.count }} entries
|
||||
</div>
|
||||
</div>
|
||||
{% include 'paginator.html' %}
|
||||
|
@ -86,23 +76,4 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
|
||||
var check_array = []
|
||||
$('#del_btn').click(function(){
|
||||
$(".gradeX input:checked").each(function() {check_array.push($(this).attr("value")) })
|
||||
$(".gradeX input:checked").closest("tr").remove()
|
||||
$.post("/juser/group_del_ajax/",
|
||||
{group_ids: check_array.join(",")},
|
||||
function(data){
|
||||
alert(data)
|
||||
}
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -44,6 +44,9 @@
|
|||
<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>
|
||||
<li id="setting">
|
||||
<a href="/setting/"><i class="fa fa-files-o"></i> <span class="nav-label">设置</span><span class="label label-info pull-right"></span></a>
|
||||
</li>
|
||||
<li class="special_link">
|
||||
<a href="http://www.jumpserver.org" target="_blank"><i class="fa fa-database"></i> <span class="nav-label">访问官网</span></a>
|
||||
</li>
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
{% 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-10">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5> 项目设置 </h5>
|
||||
<div class="ibox-tools">
|
||||
<a class="collapse-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">
|
||||
<div class="panel blank-panel">
|
||||
<div class="panel-heading">
|
||||
<div class="panel-options">
|
||||
<ul class="nav nav-tabs">
|
||||
<li id="tab1" class="active"><a data-toggle="tab" href="#tab-default" aria-expanded="true">默认设置</a></li>
|
||||
<li id="tab2" class=""><a data-toggle="tab" href="#tab-email" aria-expanded="true">邮箱设置</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div class="tab-content">
|
||||
<div id="tab-default" class="tab-pane active">
|
||||
<form method="post" id="userForm" 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="username" class="col-sm-2 control-label">默认用户名<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<input id="username" name="username" placeholder="Username" type="text" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="groups" class="col-sm-2 control-label">默认密码</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="password" name="password" placeholder="Password" type="password" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="email" class="col-sm-2 control-label">默认密钥<span class="red-fonts"></span></label>
|
||||
<div class="col-sm-8">
|
||||
<textarea class="form-control" placeholder="" rows="5"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2">
|
||||
<button class="btn btn-white" type="reset">取消</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="tab-email" class="tab-pane">
|
||||
<table class="table table-striped table-bordered table-hover " id="editable" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">组名</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
});
|
||||
$("#refresh").click(function(){
|
||||
$.get('/jperm/sudo_refresh/',
|
||||
{'test':''},
|
||||
function(data){
|
||||
alert(data)
|
||||
}
|
||||
)
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
||||
[del]
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent remove=yes
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
[del]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent remove=yes
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
||||
[del]
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
[del]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent
|
|
@ -0,0 +1,4 @@
|
|||
[new]
|
||||
[del]
|
||||
127.0.0.1 ansbile_ssh_port=22
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
|
@ -0,0 +1,10 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: testfd
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
|
@ -0,0 +1,4 @@
|
|||
[new]
|
||||
127.0.0.1 ansbile_ssh_port=22
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
||||
[del]
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: testfd
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: testfd
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent
|
|
@ -0,0 +1,5 @@
|
|||
[new]
|
||||
127.0.0.1 ansbile_ssh_port=22
|
||||
[del]
|
||||
127.0.0.1 ansbile_ssh_port=22
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: testfd
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: testfd
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent
|
|
@ -0,0 +1,4 @@
|
|||
[new]
|
||||
127.0.0.1 ansbile_ssh_port=22
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
||||
[del]
|
|
@ -0,0 +1,10 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: testfd
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
||||
[del]
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent remove=yes
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
[del]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent remove=yes
|
|
@ -0,0 +1,11 @@
|
|||
- hosts: hello world
|
||||
vars:
|
||||
user: testuserssss
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[world]
|
||||
125.39.8.222 ansbile_ssh_port=2234
|
||||
202.106.0.20 ansbile_ssh_port=22
|
||||
[hello]
|
||||
125.39.8.222 ansbile_ssh_port=2234
|
||||
202.106.0.20 ansbile_ssh_port=22
|
|
@ -0,0 +1,3 @@
|
|||
[new]
|
||||
192.168.244.129 ansible_ssh_port=22 ansible_ssh_user=root ansbile_ssh_pass=redhat
|
||||
[del]
|
|
@ -0,0 +1,17 @@
|
|||
- hosts: new
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: add user
|
||||
user: name={{ user }} state=present
|
||||
- name: .ssh direcotory
|
||||
file: name=/home/{{ user }}/.ssh mode=700 owner={{ user }} group={{ user }} state=directory
|
||||
- name: set authorizied_file
|
||||
copy: src=/tmp/id_rsa.pub dest=/home/{{ user }}/.ssh/authorizied_keys owner={{ user }} group={{ user }} mode=600
|
||||
|
||||
- hosts: del
|
||||
vars:
|
||||
user: admin
|
||||
tasks:
|
||||
- name: del user
|
||||
user: name={{ user }} state=absent
|
Loading…
Reference in New Issue