pull/6/head
halcyon 10 years ago
parent 6816f941d9
commit e3b2be0261

@ -3,7 +3,6 @@ from django.conf.urls import patterns, include, url
from jasset.views import *
urlpatterns = patterns('',
url(r'^$', index),
url(r'^host_add/$', add_host),
url(r"^host_add_multi/$", add_host_multi),
url(r'^host_list/$', list_host),

@ -8,19 +8,19 @@ from django.template import RequestContext
from django.shortcuts import render_to_response
from models import IDC, Asset, BisGroup
from juser.models import UserGroup, DEPT
from juser.models import UserGroup, DEPT, User
from connect import PyCrypt, KEY
from jlog.models import Log
from jumpserver.views import jasset_host_edit, pages
from jumpserver.api import asset_perm_api
from jumpserver.api import user_perm_group_api, require_login, require_super_user, \
from jumpserver.api import asset_perm_api, validate
from jumpserver.api import require_login, require_super_user, \
require_admin, is_group_admin, is_super_user, is_common_user, get_user_dept
cryptor = PyCrypt(KEY)
def index(request):
return render_to_response('jasset/jasset.html', )
class RaiseError(Exception):
pass
def f_add_host(ip, port, idc, jtype, group, dept, active, comment, username='', password=''):
@ -70,6 +70,7 @@ def add_host(request):
user_id = request.session.get('user_id')
edept = DEPT.objects.get(id=dept_id)
egroup = edept.bisgroup_set.all()
if request.method == 'POST':
j_ip = request.POST.get('j_ip')
j_idc = request.POST.get('j_idc')
@ -80,6 +81,14 @@ def add_host(request):
j_comment = request.POST.get('j_comment')
j_dept = request.POST.getlist('j_dept')
try:
if is_group_admin(request) and not validate(request, asset_group=j_group):
print validate(request, asset_group=j_group), 'hello'
emg = u'滚Y'
raise RaiseError(emg)
except RaiseError:
pass
if Asset.objects.filter(ip=str(j_ip)):
emg = u'该IP %s 已存在!' % j_ip
return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request))

@ -321,10 +321,15 @@ def validate(request, user_group=None, user=None, asset_group=None, asset=None):
if asset_group:
dept_asset_groups = dept.bisgroup_set.all()
asset_groups = []
for asset_group_id in asset_group:
asset_groups.extend(BisGroup.objects.filter(id=asset_group_id))
for asset_group_name in asset_group:
asset_groups.extend(BisGroup.objects.filter(name=asset_group_name))
if len(asset_groups) == 0:
print 'hehe'
return False
if not set(asset_groups).issubset(set(dept_asset_groups)):
print 'not in'
return False
if asset:

@ -44,7 +44,7 @@
{% endif %}
<h4>按照文本框内主机信息格式填写, 多台主机回车换行</h4>
<form id="assetMulti" method="post" class="form-horizontal">
<div><textarea id="j_multi" name="j_multi" type="text" placeholder="192.168.1.1 22 LDAP 北京联通 [网站,数据库] 运维部 1 网站服务器" class="form-control" style="width:700px;height:500px">192.168.1.1 22 LDAP 北京联通 ['网站','数据库'] ['运维部','测试部'] 1 网站服务器</textarea></div>
<div><textarea id="j_multi" name="j_multi" type="text" placeholder="192.168.1.1 22 LDAP 北京联通 [网站,数据库] 运维部 1 网站服务器" class="form-control" style="width:700px;height:500px">192.168.1.1 22 LDAP 北京联通 ['网站','数据库'] ['运维部'] 1 网站服务器</textarea></div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-4">

Loading…
Cancel
Save