sudo授权完成

pull/6/head
guanghongwei 2015-02-10 21:52:59 +08:00
parent 50208c0088
commit 97038aab37
7 changed files with 119 additions and 34 deletions

View File

@ -1,6 +1,6 @@
from django.db import models
from juser.models import User, UserGroup
from jasset.models import Asset, BisGroup
from juser.models import UserGroup
from jasset.models import BisGroup
class Perm(models.Model):

View File

@ -19,4 +19,6 @@ urlpatterns = patterns('jperm.views',
(r'^sudo_detail/$', 'sudo_detail'),
(r'^cmd_add/$', 'cmd_add'),
(r'^cmd_list/$', 'cmd_list'),
(r'^cmd_del/$', 'cmd_del'),
(r'^cmd_edit/$', 'cmd_edit'),
)

View File

@ -55,7 +55,7 @@ def perm_user_asset(user_id=None, username=None):
def perm_list(request):
header_title, path1, path2 = u'涓绘満鎺堟潈 | Perm Host Detail.', u'jperm', u'perm_list'
header_title, path1, path2 = u'涓绘満鎺堟潈 | Perm Host Detail.', u'鎺堟潈绠$悊', u'鎺堟潈璇︽儏'
groups = contact_list = UserGroup.objects.all().order_by('type')
users = contact_list2 = User.objects.all().order_by('id')
p = paginator = Paginator(contact_list, 10)
@ -111,7 +111,7 @@ def perm_list_ajax(request):
def perm_edit(request):
if request.method == 'GET':
header_title, path1, path2 = u'缂栬緫鎺堟潈 | Perm Host Edit.', u'jperm', u'perm_edit'
header_title, path1, path2 = u'缂栬緫鎺堟潈 | Perm Host Edit.', u'鎺堟潈绠$悊', u'鎺堟潈缂栬緫'
user_group_id = request.GET.get('id')
user_group = UserGroup.objects.get(id=user_group_id)
asset_groups = BisGroup.objects.all()
@ -254,11 +254,12 @@ def sudo_add(request):
sudo_ldap_add(name, users_runas, user_groups_select, asset_groups_select, cmd_groups_select)
msg = '娣诲姞鎴愬姛'
return HttpResponseRedirect('/jperm/sudo_list/')
return render_to_response('jperm/sudo_add.html', locals())
def sudo_list(request):
header_title, path1, path2 = u'Sudo鎺堟潈 | Perm Sudo Detail.', u'jperm', u'sudo_list'
header_title, path1, path2 = u'Sudo鎺堟潈 | Perm Sudo Detail.', u'鏉冮檺绠$悊', u'Sudo鏉冮檺璇︽儏'
sudo_perms = contact_list = SudoPerm.objects.all()
p1 = paginator1 = Paginator(contact_list, 10)
user_groups = UserGroup.objects.filter(Q(type='A') | Q(type='P'))
@ -278,7 +279,7 @@ def sudo_list(request):
def sudo_edit(request):
header_title, path1, path2 = u'Sudo鎺堟潈 | Perm Sudo Detail.', u'jperm', u'sudo_list'
header_title, path1, path2 = u'Sudo鎺堟潈 | Perm Sudo Detail.', u'鎺堟潈绠$悊', u'Sudo淇敼'
if request.method == 'GET':
sudo_perm_id = request.GET.get('id', '0')
@ -359,7 +360,7 @@ def sudo_del(request):
def cmd_add(request):
header_title, path1, path2 = u'sudo鍛戒护娣诲姞 | Sudo Cmd Add.', u'jperm', u'sudo_cmd_add'
header_title, path1, path2 = u'sudo鍛戒护娣诲姞 | Sudo Cmd Add.', u'鎺堟潈绠$悊绠$悊', u'鍛戒护缁勬坊鍔'
if request.method == 'POST':
name = request.POST.get('name')
@ -369,11 +370,39 @@ def cmd_add(request):
CmdGroup.objects.create(name=name, cmd=cmd, comment=comment)
msg = u'鍛戒护缁勬坊鍔犳垚鍔'
return HttpResponseRedirect('/jperm/cmd_list/')
return render_to_response('jperm/sudo_cmd_add.html', locals())
def cmd_edit(request):
header_title, path1, path2 = u'sudo鍛戒护淇敼 | Sudo Cmd Edit.', u'鎺堟潈绠$悊绠$悊', u'鍛戒护缁勪慨鏀'
cmd_group_id = request.GET.get('id')
cmd_group = CmdGroup.objects.filter(id=cmd_group_id)
if cmd_group:
cmd_group = cmd_group[0]
cmd_group_id = cmd_group.id
name = cmd_group.name
cmd = cmd_group.cmd
comment = cmd_group.comment
if request.method == 'POST':
cmd_group_id = request.POST.get('cmd_group_id')
name = request.POST.get('name')
cmd = ','.join(request.POST.get('cmd').split())
comment = request.POST.get('comment')
cmd_group = CmdGroup.objects.filter(id=cmd_group_id)
if cmd_group:
cmd_group.update(name=name, cmd=cmd, comment=comment)
return HttpResponseRedirect('/jperm/cmd_list/')
return render_to_response('jperm/sudo_cmd_add.html', locals())
def cmd_list(request):
header_title, path1, path2 = u'sudo鍛戒护鏌ョ湅 | Sudo Cmd List.', u'jperm', u'sudo_cmd_list'
header_title, path1, path2 = u'sudo鍛戒护鏌ョ湅 | Sudo Cmd List.', u'鏉冮檺绠$悊', u'Sudo鍛戒护娣诲姞'
cmd_groups = contact_list = CmdGroup.objects.all()
p = paginator = Paginator(contact_list, 10)
@ -389,3 +418,11 @@ def cmd_list(request):
contacts = paginator.page(paginator.num_pages)
return render_to_response('jperm/sudo_cmd_list.html', locals())
def cmd_del(request):
cmd_group_id = request.GET.get('id')
cmd_group = CmdGroup.objects.filter(id=cmd_group_id)
if cmd_group:
cmd_group[0].delete()
return HttpResponseRedirect('/jperm/cmd_list/')

View File

@ -38,7 +38,7 @@
{% endif %}
<div class="row">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">鎺堟潈鍚</label>
<label for="name" class="col-sm-2 control-label">鎺堟潈鍚<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="name" name="name" placeholder="OnlyForEnglish" type="text" class="form-control">
<span class="help-block m-b-none">鍙栦釜鍚嶅瓧鏂逛究杈ㄨ瘑锛屽彧鏀寔鑻辨枃</span>
@ -47,7 +47,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="runas" class="col-sm-2 control-label">RunAsUser</label>
<label for="runas" class="col-sm-2 control-label">RunAsUser<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="runas" name="runas" placeholder="RunAsUser" type="text" class="form-control">
<span class="help-block m-b-none">
@ -58,7 +58,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">鐢ㄦ埛缁</label>
<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="5" multiple>
@ -88,7 +88,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">涓绘満缁</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="5" multiple>
@ -117,7 +117,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">鍛戒护缁</label>
<label for="" class="col-sm-2 control-label">鍛戒护缁<span class="red-fonts">*</span></label>
<div class="col-sm-4">
<div>
<select id="cmd_groups" name="cmd_groups" class="form-control m-b" size="5" multiple>
@ -158,7 +158,7 @@
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-white" type="reset">鍙栨秷</button>
<button class="btn btn-primary" type="submit" onclick="javascript: (function(){$('#sudoPerm option').each(function(){$(this).prop('selected', true)})})()">纭淇濆瓨</button>
<button id="submit_button" class="btn btn-primary" type="submit">纭淇濆瓨</button>
</div>
</div>
</div>
@ -171,4 +171,56 @@
</div>
<script>
$('#sudoPerm').validator({
timely: 2,
theme: "yellow_right_effect",
fields: {
"name": {
rule: "required",
tip: "杈撳叆鎺堟潈鍚",
ok: "",
msg: {required: "蹇呴』濉啓!"}
},
"runas": {
rule: "required",
tip: "杈撳叆sudoas鐢ㄦ埛",
ok: "",
msg: {required: "蹇呴』濉啓!"}
},
"user_groups_select": {
rule: "required",
tip: "閫夋嫨鐢ㄦ埛缁",
ok: "",
msg: {checked: "鑷冲皯閫夋嫨涓涓敤鎴风粍"}
},
"asset_groups_select": {
rule: "required",
tip: "閫夋嫨涓绘満缁",
ok: "",
msg: {checked: "鑷冲皯閫夋嫨涓涓富鏈虹粍"}
},
"cmd_groups_select": {
rule: "required",
tip: "閫夋嫨鍛戒护缁",
ok: "",
msg: {checked: "鑷冲皯閫夋嫨涓涓懡浠ょ粍"}
}
},
valid: function(form) {
form.submit();
}
});
$(document).ready(function(){
$("#submit_button").click(function(){
$('#users_selected option').each(function(){
$(this).prop('selected', true)
})
})
})
</script>
{% endblock %}

View File

@ -37,14 +37,15 @@
<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="name" name="name" placeholder="Group name" type="text" class="form-control">
<input id="name" name="name" placeholder="Group name" type="text" class="form-control" value="{{ name }}" required="">
<input id="cmd_group_id" name="cmd_group_id" type="text" class="form-control" value="{{ cmd_group_id }}" style="display: none">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="group_type" class="col-sm-2 control-label">鍛戒护<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<textarea id='cmd' name='cmd' class="form-control" rows="10" placeholder="鍛戒护"></textarea>
<textarea id='cmd' name='cmd' class="form-control" rows="10" placeholder="鍛戒护">{{ cmd }}</textarea>
<span class="help-block m-b-none">
杈撳叆鍛戒护涓琛屼竴涓
</span>
@ -52,9 +53,9 @@
</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>
<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">
<input id="comment" name="comment" placeholder="澶囨敞璇存槑" type="text" class="form-control" value="{{ comment }}">
</div>
</div>
@ -74,21 +75,21 @@
</div>
<script>
$('#groupForm').validator({
$('#cmdForm').validator({
timely: 2,
theme: "yellow_right_effect",
fields: {
"group_name": {
"name": {
rule: "required",
tip: "杈撳叆缁勫悕",
ok: "",
msg: {required: "蹇呴』濉啓!"}
},
"group_type": {
rule: "checked",
tip: "閫夋嫨缁勭被鍨",
"cmd": {
rule: "required",
tip: "杈撳叆缁勫悕",
ok: "",
msg: {required: "鑷冲皯閫夋嫨涓涓粍!"}
msg: {required: "蹇呴』濉啓!"}
}
},
valid: function(form) {
@ -96,13 +97,6 @@ $('#groupForm').validator({
}
});
function change_type(type){
$.post('/juser/group_add_ajax/',
{'type': type},
function(data){
$('#users').html(data)
})
}
$(document).ready(function(){
$("#submit_button").click(function(){

View File

@ -49,9 +49,8 @@
<td class="text-center"> {{ group.cmd }} </td>
<td class="text-center"> {{ group.comment }} </td>
<td class="text-center">
<a title="[ {{ group.name }} ] 鎴愬憳淇℃伅" href="../group_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">鎴愬憳</a>
<a href="../group_edit/?id={{ group.id }}" class="btn btn-xs btn-info">缂栬緫</a>
<a href="../group_del/?id={{ group.id }}" class="btn btn-xs btn-danger">鍒犻櫎</a>
<a href="../cmd_edit/?id={{ group.id }}" class="btn btn-xs btn-info">缂栬緫</a>
<a href="../cmd_del/?id={{ group.id }}" class="btn btn-xs btn-danger">鍒犻櫎</a>
</td>
</tr>
{% endfor %}

View File

@ -32,6 +32,7 @@
<div class="" style="margin-left: 15px;">
<a target="_blank" href="/jperm/cmd_add/" class="btn btn-sm btn-primary "> 娣诲姞鍛戒护缁 </a>
<a target="_blank" href="/jperm/cmd_list/" class="btn btn-sm btn-warning "> 鏌ョ湅鍛戒护缁 </a>
<a target="_blank" href="/jperm/sudo_add/" class="btn btn-sm btn-danger "> Sudo鎺堟潈娣诲姞 </a>
</div>
<div class="panel blank-panel">