mirror of https://github.com/jumpserver/jumpserver
merge
commit
56df1f6963
|
@ -12,12 +12,31 @@ django.setup()
|
|||
|
||||
from juser.views import db_add_user, md5_crypt, CRYPTOR, db_add_group
|
||||
from jasset.models import Asset, IDC, BisGroup
|
||||
from juser.models import UserGroup, DEPT
|
||||
from juser.models import UserGroup, DEPT, User
|
||||
from jasset.views import jasset_group_add
|
||||
from jperm.models import CmdGroup
|
||||
from jlog.models import Log
|
||||
|
||||
|
||||
def install():
|
||||
IDC.objects.create(name='ALL', comment='ALL')
|
||||
IDC.objects.create(name='默认', comment='默认')
|
||||
DEPT.objects.create(name="默认", comment="默认部门")
|
||||
DEPT.objects.create(name="超管部", comment="超级管理员部门")
|
||||
dept = DEPT.objects.get(name='超管部')
|
||||
dept2 = DEPT.objects.get(name='默认')
|
||||
UserGroup.objects.create(name='ALL', dept=dept, comment='ALL')
|
||||
UserGroup.objects.create(name='默认', dept=dept, comment='默认')
|
||||
|
||||
BisGroup.objects.create(name='ALL', dept=dept, comment='ALL')
|
||||
BisGroup.objects.create(name='默认', dept=dept, comment='默认')
|
||||
|
||||
User(id=5000, username="admin", password=md5_crypt('admin'),
|
||||
name='admin', email='admin@jumpserver.org', role='SU', is_active=True, dept=dept).save()
|
||||
User(id=5001, username="group_admin", password=md5_crypt('group_admin'),
|
||||
name='group_admin', email='group_admin@jumpserver.org', role='DA', is_active=True, dept=dept2).save()
|
||||
|
||||
|
||||
def test_add_idc():
|
||||
for i in range(1, 20):
|
||||
name = 'IDC' + str(i)
|
||||
|
@ -67,11 +86,10 @@ def test_add_user():
|
|||
|
||||
|
||||
def test_add_asset_group():
|
||||
BisGroup.objects.create(name='ALL', type='A', comment='ALL')
|
||||
user_all = Asset.objects.all()
|
||||
dept = DEPT.objects.get(name='默认')
|
||||
for i in range(1, 20):
|
||||
name = 'AssetGroup' + str(i)
|
||||
group = BisGroup(name=name, type='A', comment=name)
|
||||
group = BisGroup(name=name, dept=dept, comment=name)
|
||||
group.save()
|
||||
print 'Add: %s' % name
|
||||
|
||||
|
@ -80,11 +98,13 @@ def test_add_asset():
|
|||
idc_all = IDC.objects.all()
|
||||
test_idc = random.choice(idc_all)
|
||||
bis_group_all = BisGroup.objects.all()
|
||||
dept_all = DEPT.objects.all()
|
||||
for i in range(1, 500):
|
||||
ip = '192.168.1.' + str(i)
|
||||
asset = Asset(ip=ip, port=22, login_type='L', idc=test_idc, is_active=True, comment='test')
|
||||
asset.save()
|
||||
asset.bis_group = [random.choice(bis_group_all) for i in range(2)]
|
||||
asset.dept = [random.choice(dept_all) for i in range(2)]
|
||||
print "Add: %s" % ip
|
||||
|
||||
|
||||
|
@ -108,6 +128,7 @@ def test_add_log():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
install()
|
||||
test_add_dept()
|
||||
test_add_group()
|
||||
test_add_user()
|
||||
|
|
|
@ -17,6 +17,7 @@ class BisGroup(models.Model):
|
|||
('A', 'ASSET'),
|
||||
)
|
||||
name = models.CharField(max_length=80, unique=True)
|
||||
dept = models.ForeignKey(DEPT)
|
||||
comment = models.CharField(max_length=160, blank=True, null=True)
|
||||
type = models.CharField(max_length=1, choices=GROUP_TYPE, default='P')
|
||||
|
||||
|
@ -27,8 +28,6 @@ class BisGroup(models.Model):
|
|||
class Asset(models.Model):
|
||||
LOGIN_TYPE_CHOICES = (
|
||||
('L', 'LDAP'),
|
||||
('S', 'SSH_KEY'),
|
||||
('P', 'PASSWORD'),
|
||||
('M', 'MAP'),
|
||||
)
|
||||
ip = models.IPAddressField(unique=True)
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.template import RequestContext
|
|||
from django.shortcuts import render_to_response
|
||||
|
||||
from models import IDC, Asset, BisGroup
|
||||
from juser.models import UserGroup
|
||||
from juser.models import UserGroup, DEPT
|
||||
from connect import PyCrypt, KEY
|
||||
from jlog.models import Log
|
||||
from jumpserver.views import jasset_group_add, jasset_host_edit, pages
|
||||
|
@ -19,8 +19,8 @@ def index(request):
|
|||
return render_to_response('jasset/jasset.html', )
|
||||
|
||||
|
||||
def f_add_host(ip, port, idc, jtype, group, active, comment, username='', password=''):
|
||||
groups = []
|
||||
def f_add_host(ip, port, idc, jtype, group, dept, active, comment, username='', password=''):
|
||||
groups, depts = [], []
|
||||
idc = IDC.objects.get(name=idc)
|
||||
if jtype == 'M':
|
||||
print username, password
|
||||
|
@ -45,7 +45,14 @@ def f_add_host(ip, port, idc, jtype, group, active, comment, username='', passwo
|
|||
groups.append(c)
|
||||
groups.extend([all_group, private_group])
|
||||
|
||||
print dept
|
||||
for d in dept:
|
||||
print d
|
||||
p = DEPT.objects.get(name=d)
|
||||
depts.append(p)
|
||||
|
||||
a.bis_group = groups
|
||||
a.dept = depts
|
||||
a.save()
|
||||
|
||||
|
||||
|
@ -53,6 +60,7 @@ def add_host(request):
|
|||
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
|
||||
header_title, path1, path2 = u'添加主机', u'资产管理', u'添加主机'
|
||||
eidc = IDC.objects.all()
|
||||
edept = DEPT.objects.all()
|
||||
egroup = BisGroup.objects.filter(type='A')
|
||||
eusergroup = UserGroup.objects.all()
|
||||
|
||||
|
@ -64,6 +72,7 @@ def add_host(request):
|
|||
j_group = request.POST.getlist('j_group')
|
||||
j_active = request.POST.get('j_active')
|
||||
j_comment = request.POST.get('j_comment')
|
||||
j_dept = request.POST.getlist('j_dept')
|
||||
|
||||
if Asset.objects.filter(ip=str(j_ip)):
|
||||
emg = u'该IP %s 已存在!' % j_ip
|
||||
|
@ -72,9 +81,9 @@ def add_host(request):
|
|||
if j_type == 'M':
|
||||
j_user = request.POST.get('j_user')
|
||||
j_password = cryptor.encrypt(request.POST.get('j_password'))
|
||||
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_active, j_comment, j_user, j_password)
|
||||
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_dept, j_active, j_comment, j_user, j_password)
|
||||
else:
|
||||
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_active, j_comment)
|
||||
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_dept, j_active, j_comment)
|
||||
smg = u'主机 %s 添加成功' % j_ip
|
||||
|
||||
return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request))
|
||||
|
@ -184,28 +193,37 @@ def host_del(request, offset):
|
|||
|
||||
def host_edit(request):
|
||||
actives = {1: u'激活', 0: u'禁用'}
|
||||
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
|
||||
login_types = {'L': 'LDAP', 'M': 'MAP'}
|
||||
header_title, path1, path2 = u'修改主机', u'资产管理', u'修改主机'
|
||||
groups, e_group = [], []
|
||||
groups, e_group, e_dept, depts = [], [], [], []
|
||||
eidc = IDC.objects.all()
|
||||
egroup = BisGroup.objects.filter(type='A')
|
||||
edept = DEPT.objects.all()
|
||||
offset = request.GET.get('id')
|
||||
for g in Asset.objects.get(id=int(offset)).bis_group.all():
|
||||
e_group.append(g)
|
||||
for d in Asset.objects.get(id=int(offset)).dept.all():
|
||||
e_dept.append(d)
|
||||
post = Asset.objects.get(id=int(offset))
|
||||
if request.method == 'POST':
|
||||
j_ip = request.POST.get('j_ip')
|
||||
j_idc = request.POST.get('j_idc')
|
||||
j_port = request.POST.get('j_port')
|
||||
j_type = request.POST.get('j_type')
|
||||
j_dept = request.POST.getlist('j_dept')
|
||||
j_group = request.POST.getlist('j_group')
|
||||
j_active = request.POST.get('j_active')
|
||||
j_comment = request.POST.get('j_comment')
|
||||
j_idc = IDC.objects.get(name=j_idc)
|
||||
for group in j_group:
|
||||
print group
|
||||
c = BisGroup.objects.get(name=group)
|
||||
groups.append(c)
|
||||
|
||||
for dept in j_dept:
|
||||
d = DEPT.objects.get(name=dept)
|
||||
depts.append(d)
|
||||
|
||||
a = Asset.objects.get(id=int(offset))
|
||||
if j_type == 'M':
|
||||
if post.password == request.POST.get('j_password'):
|
||||
|
@ -231,6 +249,7 @@ def host_edit(request):
|
|||
|
||||
a.save()
|
||||
a.bis_group = groups
|
||||
a.dept = depts
|
||||
a.save()
|
||||
smg = u'主机 %s 修改成功' % j_ip
|
||||
return HttpResponseRedirect('/jasset/host_list')
|
||||
|
@ -317,10 +336,13 @@ def del_idc(request, offset):
|
|||
def add_group(request):
|
||||
header_title, path1, path2 = u'添加主机组', u'资产管理', u'添加主机组'
|
||||
posts = Asset.objects.all()
|
||||
edept = DEPT.objects.all()
|
||||
if request.method == 'POST':
|
||||
j_group = request.POST.get('j_group')
|
||||
j_dept = request.POST.get('j_dept')
|
||||
j_hosts = request.POST.getlist('j_hosts')
|
||||
j_comment = request.POST.get('j_comment')
|
||||
j_dept = DEPT.objects.get(name=j_dept)
|
||||
|
||||
if BisGroup.objects.filter(name=j_group):
|
||||
emg = u'该主机组已存在!'
|
||||
|
@ -328,6 +350,7 @@ def add_group(request):
|
|||
else:
|
||||
BisGroup.objects.create(name=j_group, comment=j_comment, type='A')
|
||||
group = BisGroup.objects.get(name=j_group)
|
||||
group.dept = j_dept
|
||||
for host in j_hosts:
|
||||
g = Asset.objects.get(id=host)
|
||||
group.asset_set.add(g)
|
||||
|
@ -342,7 +365,7 @@ def list_group(request):
|
|||
if keyword:
|
||||
posts = BisGroup.objects.filter(Q(name__contains=keyword) | Q(comment__contains=keyword))
|
||||
else:
|
||||
posts = BisGroup.objects.filter(type='A').order_by('id')
|
||||
posts = BisGroup.objects.all().order_by('id')
|
||||
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
|
||||
|
||||
return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request))
|
||||
|
|
|
@ -8,7 +8,7 @@ password = mysql234
|
|||
database = jumpserver
|
||||
|
||||
[ldap]
|
||||
ldap_enable = 1
|
||||
ldap_enable = 0
|
||||
host_url = ldap://127.0.0.1:389
|
||||
base_dn = dc=jumpserver, dc=org
|
||||
root_dn = cn=admin,dc=jumpserver,dc=org
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
var str = document.location.pathname.split("/")[1];
|
||||
var str1 = document.location.pathname.split("/")[2];
|
||||
$("#"+str).addClass('active');
|
||||
if($("#"+str1).length>0) {
|
||||
$("#"+str1).addClass('active');
|
||||
if($("."+str1).length>0) {
|
||||
$("."+str1).addClass('active');
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -16,13 +16,25 @@
|
|||
<div class="alert alert-success text-center">{{ smg }}</div>
|
||||
{% endif %}
|
||||
<form id="assetForm" method="post" class="form-horizontal">
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 主机组名 </label>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 主机组名<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8" name="group_id" value="{{ post.id }}"><input type="text" value="{{ group.name }}" placeholder="网站" name="j_group" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="groups" class="col-lg-2 control-label">主机</label>
|
||||
<label for="j_dept" class="col-lg-2 control-label">所属部门<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<select id="j_dept" name="j_dept" class="form-control m-b">
|
||||
{% for d in edept %}
|
||||
<option type="checkbox" value="{{ d.name }}">{{ d.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="groups" class="col-lg-2 control-label">主机<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-3">
|
||||
<select id="groups" size="12" class="form-control m-b" multiple>
|
||||
{% for post in posts %}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<tr>
|
||||
<th class="text-center"><input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')"></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>
|
||||
|
@ -38,6 +39,7 @@
|
|||
<tr class="gradeX">
|
||||
<td class="text-center" name="j_id" value="{{ post.id }}" data-editable='false'><input name="id" value="{{ post.id }}" type="checkbox" class="i-checks"></td>
|
||||
<td class="text-center"> {{ post.name }} </td>
|
||||
<td class="text-center"> {{ post.dept.name }} </td>
|
||||
<td class="text-center"> <a href="/jasset/group_detail/?id={{ post.id }}">{{ post.asset_set.count }}</a> </td>
|
||||
<td class="text-center"> {{ post.comment }} </td>
|
||||
<td class="text-center">
|
||||
|
|
|
@ -57,8 +57,6 @@
|
|||
<div class="form-group"><label class="col-sm-2 control-label"> 登录方式<span class="red-fonts">*</span> </label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio i-checks"><label> <input type="radio" id="L" checked="" value="L" name="j_type" onclick="show(this)"> <i> LDAP </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" id="S" value="S" name="j_type" onclick="show(this)"> <i> SSH_KEY </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" id="P" value="P" name="j_type" onclick="show(this)"> <i> PASSWORD </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" id="M" value="M" name="j_type" onclick="show(this)"> <i> MAP </i></label></div>
|
||||
</div>
|
||||
|
||||
|
@ -86,6 +84,18 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_dept" class="col-lg-2 control-label">所属部门<span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-8">
|
||||
<select id="j_dept" name="j_dept" class="form-control m-b" multiple size="10">
|
||||
{% for d in edept %}
|
||||
<option type="checkbox" value="{{ d.name }}">{{ d.name }} {% if d.comment %} --- {{ d.comment }} {% endif %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_group" class="col-lg-2 control-label">所属主机组<span class="red-fonts">*</span></label>
|
||||
|
|
|
@ -93,6 +93,22 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_dept" class="col-lg-2 control-label"> 所属部门<span class="red-fonts">*</span> </label>
|
||||
<div class="col-sm-8">
|
||||
<select id="j_dept" name="j_dept" class="form-control m-b" multiple size="10">
|
||||
{% for g in edept %}
|
||||
{% if g in e_dept %}
|
||||
<option type="checkbox" value="{{ g.name }}" selected>{{ g.name }} --- {{ g.comment }}</option>
|
||||
{% else %}
|
||||
<option type="checkbox" value="{{ g.name }}" >{{ g.name }} --- {{ g.comment }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_group" class="col-lg-2 control-label"> 所属主机组<span class="red-fonts">*</span> </label>
|
||||
|
|
|
@ -53,9 +53,10 @@
|
|||
<th class="text-center"> 端口号 </th>
|
||||
<th class="text-center" name="j_type"> 登录方式 </th>
|
||||
<th class="text-center" name="j_idc"> 所属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" name="j_time"> 添加时间 </th>
|
||||
<!--<th class="text-center" name="j_time"> 添加时间 </th>-->
|
||||
<th class="text-center" name="j_comment"> 备注 </th>
|
||||
<th class="text-center"> 操作 </th>
|
||||
</tr>
|
||||
|
@ -68,9 +69,10 @@
|
|||
<td class="text-center" name="j_port"> {{ post.port }} </td>
|
||||
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
|
||||
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
|
||||
<td class="text-center" name="j_group">{{ post.dept.all | group_str2 }}</td>
|
||||
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2 }}</td>
|
||||
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
|
||||
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
|
||||
<!--<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>-->
|
||||
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
|
||||
<td class="text-center" data-editable='false'>
|
||||
<a value="/jasset/{{ post.ip }}/" class="iframe btn btn-xs btn-primary">详情</a>
|
||||
|
|
|
@ -15,23 +15,23 @@
|
|||
<li id="juser">
|
||||
<a href="#"><i class="fa fa-rebel"></i> <span class="nav-label">用户管理</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li id="dept_list"><a href="/juser/dept_list/">查看部门</a></li>
|
||||
<li id="dept_add"><a href="/juser/dept_add/">添加部门</a></li>
|
||||
<li id="group_list"><a href="/juser/group_list/">查看小组</a></li>
|
||||
<li id="group_add"><a href="/juser/group_add/">添加小组</a></li>
|
||||
<li id="user_list"><a href="/juser/user_list/">查看用户<span class="label {% ifequal user_active_num user_total_num %}label-primary {% else %}label-warning {% endifequal %}pull-right">{{ user_active_num }}/{{ user_total_num }}</span></a></li>
|
||||
<li id="user_add"><a href="/juser/user_add/">添加用户</a></li>
|
||||
<li class="dept_list"><a href="/juser/dept_list/">查看部门</a></li>
|
||||
<li class="dept_add"><a href="/juser/dept_add/">添加部门</a></li>
|
||||
<li class="group_list"><a href="/juser/group_list/">查看小组</a></li>
|
||||
<li class="group_add"><a href="/juser/group_add/">添加小组</a></li>
|
||||
<li class="user_list user_edit"><a href="/juser/user_list/">查看用户<span class="label {% ifequal user_active_num user_total_num %}label-primary {% else %}label-warning {% endifequal %}pull-right">{{ user_active_num }}/{{ user_total_num }}</span></a></li>
|
||||
<li class="user_add"><a href="/juser/user_add/">添加用户</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li id="jasset">
|
||||
<a><i class="fa fa-cube"></i> <span class="nav-label">资产管理</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li id="host_add"><a href="/jasset/host_add/">添加资产</a></li>
|
||||
<li id="host_list"><a href="/jasset/host_list/">查看资产  </span><span class="label label-info pull-right">16/18</span></a></li>
|
||||
<li id="jgroup_add"><a href="/jasset/jgroup_add/">添加主机组</a></li>
|
||||
<li id="jgroup_list"><a href="/jasset/jgroup_list/">查看主机组</a></li>
|
||||
<li id="idc_add"><a href="/jasset/idc_add/">添加IDC</a></li>
|
||||
<li id="idc_list"><a href="/jasset/idc_list/">查看IDC</a></li>
|
||||
<li class="host_add host_add_multi"><a href="/jasset/host_add/">添加资产</a></li>
|
||||
<li class="host_list"><a href="/jasset/host_list/">查看资产  </span><span class="label label-info pull-right">16/18</span></a></li>
|
||||
<li class="jgroup_add"><a href="/jasset/jgroup_add/">添加主机组</a></li>
|
||||
<li class="jgroup_list group_detail"><a href="/jasset/jgroup_list/">查看主机组</a></li>
|
||||
<li class="idc_add"><a href="/jasset/idc_add/">添加IDC</a></li>
|
||||
<li class="idc_list idc_detail"><a href="/jasset/idc_list/">查看IDC</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li id="jperm">
|
||||
|
|
Loading…
Reference in New Issue