Browse Source

修改chgSudo的view

pull/2/head
guanghongwei 10 years ago
parent
commit
9020c11bd2
  1. 13
      webroot/AutoSa/AutoSa/views.py
  2. 14
      webroot/AutoSa/templates/chgSudo.html

13
webroot/AutoSa/AutoSa/views.py

@ -635,12 +635,13 @@ def chgSudo(request):
username = request.POST.get('username') username = request.POST.get('username')
user_dn = 'cn=%s,ou=Sudoers,%s' % (str(username), ldap_base_dn) user_dn = 'cn=%s,ou=Sudoers,%s' % (str(username), ldap_base_dn)
msg = '' msg = ''
if request.POST.get('addHost') or request.POST.get('delHost'): if request.POST.get('add_host') or request.POST.get('del_host'):
host = request.POST.get('host') host = request.POST.get('add_host') if request.POST.get('add_host') else request.POST.get('del_host')
hosts = host.split(',') hosts = host.split(',')
ori_hosts = l.list('entryDN=cn=%s,ou=Sudoers,%s' % ori_hosts = l.list('entryDN=cn=%s,ou=Sudoers,%s' %
(str(username), ldap_base_dn), attr=['sudoHost']).get('sudoHost') (str(username), ldap_base_dn), attr=['sudoHost']).get('sudoHost')
if request.POST.get('addHost'):
if request.POST.get('add_host'):
new_hosts = list(set(ori_hosts.extend(hosts))) new_hosts = list(set(ori_hosts.extend(hosts)))
else: else:
new_hosts = list(set(ori_hosts) - set(hosts)) new_hosts = list(set(ori_hosts) - set(hosts))
@ -648,12 +649,12 @@ def chgSudo(request):
msg = '修改sudo主机成功' % hosts msg = '修改sudo主机成功' % hosts
if request.POST.get('addCMD') or request.POST.get('delCMD'): if request.POST.get('add_cmd') or request.POST.get('del_cmd'):
cmd = request.POST.get('cmd') cmd = request.POST.get('add_cmd') if request.POST.get('add_cmd') else request.POST.get('del_cmd')
cmds = cmd.split(',') cmds = cmd.split(',')
ori_cmds = l.list('entryDN=cn=%s,ou=Sudoers,%s' % ori_cmds = l.list('entryDN=cn=%s,ou=Sudoers,%s' %
(str(username), ldap_base_dn), attr=['sudoCommand']).get('sudoCommand') (str(username), ldap_base_dn), attr=['sudoCommand']).get('sudoCommand')
if request.POST.get('addCMD'): if request.POST.get('add_cmd'):
new_cmds = list(set(ori_cmds.extend(cmds))) new_cmds = list(set(ori_cmds.extend(cmds)))
else: else:
new_cmds = list(set(ori_hosts) - cmds) new_cmds = list(set(ori_hosts) - cmds)

14
webroot/AutoSa/templates/chgSudo.html

@ -2,12 +2,12 @@
{% block content %} {% block content %}
<fieldset > <fieldset >
<legend>{{ username }}--修改sudo</legend> <legend>{{ username }}--修改sudo</legend>
<form class="form-horizontal" role="form" method="post" action="/chgSudo/?addHost=1" > <form class="form-horizontal" role="form" method="post" action="/chgSudo/" >
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="input-group"> <div class="input-group">
<input type="text" name="username" value="{{ username }}" hidden="hidden"> <input type="text" name="username" value="{{ username }}" hidden="hidden">
<input type="text" class="form-control" name="host" placeholder="主机IP,多个逗号分隔"> <input type="text" class="form-control" name="add_host" placeholder="主机IP,多个逗号分隔">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-success" type="submit">新增主机</button> <button class="btn btn-success" type="submit">新增主机</button>
</span> </span>
@ -17,12 +17,12 @@
</form> </form>
<br> <br>
<form class="form-horizontal" role="form" method="post" action="/chgSudo/?delHost=1" > <form class="form-horizontal" role="form" method="post" action="/chgSudo/" >
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="input-group"> <div class="input-group">
<input type="text" name="username" value="{{ username }}" hidden="hidden"> <input type="text" name="username" value="{{ username }}" hidden="hidden">
<input type="text" class="form-control" name="host" placeholder="主机IP,多个逗号分隔"> <input type="text" class="form-control" name="del_host" placeholder="主机IP,多个逗号分隔">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-primary" type="submit">删除主机</button> <button class="btn btn-primary" type="submit">删除主机</button>
</span> </span>
@ -32,12 +32,12 @@
</form> </form>
<br> <br>
<form class="form-horizontal" role="form" method="post" action="/chgSudo/?addCMD=1" > <form class="form-horizontal" role="form" method="post" action="/chgSudo/" >
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="input-group"> <div class="input-group">
<input type="text" name="username" value="{{ username }}" hidden="hidden"> <input type="text" name="username" value="{{ username }}" hidden="hidden">
<input type="text" class="form-control" name="cmd" placeholder="添加命令,多个逗号分隔"> <input type="text" class="form-control" name="add_cmd" placeholder="添加命令,多个逗号分隔">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-info" type="submit">添加命令</button> <button class="btn btn-info" type="submit">添加命令</button>
</span> </span>
@ -52,7 +52,7 @@
<div class="col-lg-6"> <div class="col-lg-6">
<div class="input-group"> <div class="input-group">
<input type="text" name="username" value="{{ username }}" hidden="hidden"> <input type="text" name="username" value="{{ username }}" hidden="hidden">
<input type="text" class="form-control" name="cmd" placeholder="删除命令,多个逗号分隔"> <input type="text" class="form-control" name="del_cmd" placeholder="删除命令,多个逗号分隔">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-danger" type="submit">删除命令</button> <button class="btn btn-danger" type="submit">删除命令</button>
</span> </span>

Loading…
Cancel
Save