pull/6/head
halcyon 2015-02-05 18:53:57 +08:00
commit 433974d77d
26 changed files with 762 additions and 154 deletions

View File

@ -47,7 +47,8 @@ SERVER_KEY_DIR = os.path.join(SSH_KEY_DIR, 'server')
# The key of decryptor.
KEY = CONF.get('web', 'key')
# Login user.
LOGIN_NAME = getpass.getuser()
#LOGIN_NAME = getpass.getuser()
LOGIN_NAME = 'halcyon'
#LOGIN_NAME = os.getlogin()
USER_KEY_FILE = os.path.join(SERVER_KEY_DIR, LOGIN_NAME)
@ -259,6 +260,7 @@ def verify_connect(username, part_ip):
color_print('No Permission or No host.', 'red')
else:
username, password, host, port = get_connect_item(username, ip_matched[0])
print username, password, host, port
connect(username, password, host, port, LOGIN_NAME)

View File

@ -4,18 +4,18 @@ from jasset.views import *
urlpatterns = patterns('',
url(r'^$', index),
url(r'^host_add/$', jadd_host),
url(r'^host_add_multi/$', jadd_host_multi),
url(r'^host_list/$', jlist_host),
url(r"^(\d+.\d+.\d+.\d+)/$",jlist_ip),
url(r'^idc_add/$', jadd_idc),
url(r'^idc_list/$', jlist_idc),
url(r'^idc_detail/(\d+)$', idc_detail),
url(r'^idc_del/(\d+)/$', idc_del),
url(r'^group_add/$', jadd_group),
url(r'^group_edit/(\d+)/$', group_edit),
url(r'^group_list/$', jlist_group),
url(r'^group_detail/(\d+)/$', group_detail),
url(r'^host_add/$', add_host),
url(r"^host_add_multi/$", add_host_multi),
url(r'^host_list/$', list_host),
url(r"^(\d+.\d+.\d+.\d+)/$", jlist_ip),
url(r'^idc_add/$', add_idc),
url(r'^idc_list/$', list_idc),
url(r'^idc_detail/(\d+)$', detail_idc),
url(r'^idc_del/(\d+)/$', del_idc),
url(r'^group_add/$', add_group),
url(r'^group_edit/(\d+)/$', edit_group),
url(r'^group_list/$', list_group),
url(r'^group_detail/(\d+)/$', detail_group),
url(r'^group_del_host/(\w+)/$', group_del_host),
url(r'^group_del/(\d+)/$', group_del),
url(r'^host_del/(\w+)/$', host_del),

View File

@ -16,10 +16,38 @@ def index(request):
return render_to_response('jasset/jasset.html', )
def jadd_host(request):
def f_add_host(ip, port, idc, jtype, group, active, comment, username='', password=''):
groups = []
idc = IDC.objects.get(name=idc)
if type == 'M':
a = Asset(ip=ip, port=port,
login_type=jtype, idc=idc,
is_active=int(active),
comment=comment,
username=username,
password=password)
else:
a = Asset(ip=ip, port=port,
login_type=jtype, idc=idc,
is_active=int(active),
comment=comment)
a.save()
jasset_group_add(ip, ip, 'P')
all_group = BisGroup.objects.get(name='ALL')
private_group = BisGroup.objects.get(name=ip.strip())
for g in group:
c = BisGroup.objects.get(name=g)
groups.append(c)
groups.extend([all_group, private_group])
a.bis_group = groups
a.save()
def add_host(request):
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
header_title, path1, path2 = u'添加主机 | Add Host', u'资产管理', u'添加主机'
groups = []
eidc = IDC.objects.all()
egroup = BisGroup.objects.filter(type='A')
eusergroup = UserGroup.objects.all()
@ -32,13 +60,6 @@ def jadd_host(request):
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)
all_group = BisGroup.objects.get(name='ALL')
for group in j_group:
c = BisGroup.objects.get(name=group)
groups.append(c)
groups.append(all_group)
if Asset.objects.filter(ip=str(j_ip)):
emg = u'该IP %s 已存在!' %j_ip
@ -47,47 +68,31 @@ def jadd_host(request):
if j_type == 'M':
j_user = request.POST.get('j_user')
j_password = cryptor.encrypt(request.POST.get('j_password'))
a = Asset(ip=j_ip, port=j_port,
login_type=j_type, idc=j_idc,
is_active=int(j_active),
comment=j_comment,
username_common=j_user,
password_common=j_password)
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_active, j_comment, j_user, j_password)
else:
a = Asset(ip=j_ip, port=j_port,
login_type=j_type, idc=j_idc,
is_active=int(j_active),
comment=j_comment)
jasset_group_add(j_ip, j_ip, 'P')
a.save()
a.bis_group = groups
a.save()
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_active, j_comment)
smg = u'主机 %s 添加成功' %j_ip
return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request))
def jadd_host_multi(request):
def add_host_multi(request):
header_title, path1, path2 = u'批量添加主机 | Add Hosts', u'资产管理', u'批量添加主机'
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
j_group = []
if request.method == 'POST':
multi_hosts = request.POST.get('j_multi').split('\n')
for host in multi_hosts:
if host == '':
break
groups = []
j_ip, j_port, j_type, j_idc, j_group, j_user_group, j_active, j_comment = host.split()
j_idc = IDC.objects.get(name=j_idc)
j_ip, j_port, j_type, j_idc, j_groups, j_user_group, j_active, j_comment = host.split()
j_type = login_types[j_type]
all_group = BisGroup.objects.get(name='ALL')
j_group = j_group.split(',')
for group in j_group:
g = group.strip('[]')
print g
c = BisGroup.objects.get(name=g)
groups.append(c)
groups.append(all_group)
j_groups = j_groups.split(',')
for group in j_groups:
g = group.strip('[]').encode('utf-8').strip()
j_group.append(g)
print j_group,type(j_group)
if Asset.objects.filter(ip=str(j_ip)):
emg = u'该IP %s 已存在!' %j_ip
return render_to_response('jasset/host_add_multi.html', locals(), context_instance=RequestContext(request))
@ -95,23 +100,13 @@ def jadd_host_multi(request):
if j_type == 'M':
j_user = request.POST.get('j_user')
j_password = cryptor.encrypt(request.POST.get('j_password'))
a = Asset(ip=j_ip, port=j_port,
login_type=j_type, idc=j_idc,
is_active=int(j_active),
comment=j_comment,
username_common=j_user,
password_common=j_password)
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_active, j_comment, j_user, j_password)
else:
a = Asset(ip=j_ip, port=j_port,
login_type=j_type, idc=j_idc,
is_active=int(j_active),
comment=j_comment)
jasset_group_add(j_ip, j_ip, 'P')
a.save()
a.bis_group = groups
a.save()
f_add_host(j_ip, j_port, j_idc, j_type, j_group, j_active, j_comment)
smg = u'批量添加添加成功'
return HttpResponseRedirect('/jasset/host_list/')
return render_to_response('jasset/host_add_multi.html', locals(), context_instance=RequestContext(request))
@ -136,14 +131,13 @@ def batch_host_edit(request):
j_group = request.POST.getlist(j_group)
j_active = request.POST.get(j_active).strip()
j_comment = request.POST.get(j_comment).strip()
print j_ip
jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment)
return render_to_response('jasset/host_list.html')
def jlist_host(request):
def list_host(request):
header_title, path1, path2 = u'查看主机 | List Host', u'资产管理', u'查看主机'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
posts = contact_list = Asset.objects.all().order_by('ip')
@ -167,12 +161,14 @@ def host_del(request, offset):
len_list = request.POST.get("len_list")
for i in range(int(len_list)):
key = "id_list["+str(i)+"]"
print key
jid = request.POST.get(key)
print jid
a = Asset.objects.get(id=jid).ip
Asset.objects.filter(id=jid).delete()
BisGroup.objects.filter(name=a).delete()
else:
jid = int(offset)
a = Asset.objects.get(id=jid).ip
BisGroup.objects.filter(name=a).delete()
Asset.objects.filter(id=jid).delete()
return HttpResponseRedirect('/jasset/host_list/')
@ -235,7 +231,7 @@ def jlist_ip(request, offset):
return render_to_response('jasset/jlist_ip.html', locals(), context_instance=RequestContext(request))
def jadd_idc(request):
def add_idc(request):
header_title, path1, path2 = u'添加IDC | Add IDC', u'资产管理', u'添加IDC'
if request.method == 'POST':
j_idc = request.POST.get('j_idc')
@ -250,18 +246,18 @@ def jadd_idc(request):
return render_to_response('jasset/idc_add.html', locals(), context_instance=RequestContext(request))
def jlist_idc(request):
def list_idc(request):
header_title, path1, path2 = u'查看IDC | List IDC', u'资产管理', u'查看IDC'
posts = IDC.objects.all().order_by('id')
return render_to_response('jasset/idc_list.html', locals(), context_instance=RequestContext(request))
def idc_del(request, offset):
def del_idc(request, offset):
IDC.objects.filter(id=offset).delete()
return HttpResponseRedirect('/jasset/idc_list/')
def jadd_group(request):
def add_group(request):
header_title, path1, path2 = u'添加主机组 | Add Group', u'资产管理', u'添加主机组'
posts = Asset.objects.all()
if request.method == 'POST':
@ -283,13 +279,13 @@ def jadd_group(request):
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
def jlist_group(request):
def list_group(request):
header_title, path1, path2 = u'查看主机组 | List Group', u'资产管理', u'查看主机组'
posts = BisGroup.objects.filter(type='A').order_by('id')
return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request))
def group_edit(request, offset):
def edit_group(request, offset):
header_title, path1, path2 = u'编辑主机组 | Edit Group', u'资产管理', u'编辑主机组'
group = BisGroup.objects.get(id=offset)
all = Asset.objects.all()
@ -311,7 +307,7 @@ def group_edit(request, offset):
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
def group_detail(request, offset):
def detail_group(request, offset):
header_title, path1, path2 = u'主机组详情 | Group Detail', u'资产管理', u'主机组详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
group_name = BisGroup.objects.get(id=offset).name
@ -330,7 +326,7 @@ def group_detail(request, offset):
return render_to_response('jasset/group_detail.html', locals(), context_instance=RequestContext(request))
def idc_detail(request, offset):
def detail_idc(request, offset):
header_title, path1, path2 = u'主机组详情 | Group Detail', u'资产管理', u'主机组详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
idc_name = IDC.objects.get(id=offset).name

View File

@ -8,6 +8,7 @@ urlpatterns = patterns('jperm.views',
(r'^perm_edit/$', 'perm_edit'),
(r'^perm_list/$', 'perm_list'),
(r'^perm_list_ajax/$', 'perm_list_ajax'),
(r'^perm_detail/$', 'perm_detail'),
(r'^perm_del/$', 'perm_del'),
(r'^perm_asset_detail/$', 'perm_asset_detail'),

View File

@ -65,6 +65,41 @@ def perm_list(request):
return render_to_response('jperm/perm_list.html', locals())
def perm_list_ajax(request):
tab = request.POST.get('tab', 'tab1')
search = request.POST.get('search', '')
if tab == 'tab1':
groups = contact_list = UserGroup.objects.filter(name__icontains=search).order_by('type')
p = paginator = Paginator(contact_list, 10)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
else:
users = contact_list2 = User.objects.filter(name__icontains=search).order_by('id')
p2 = paginator2 = Paginator(contact_list2, 10)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts2 = paginator2.page(page)
except (EmptyPage, InvalidPage):
contacts2 = paginator2.page(paginator2.num_pages)
return render_to_response('jperm/perm_list_ajax.html', locals())
def perm_edit(request):
if request.method == 'GET':
header_title, path1, path2 = u'编辑授权 | Perm Host Edit.', u'jperm', u'perm_edit'

View File

@ -1,6 +1,7 @@
# coding: utf-8
import time
import re
from django import template
from django.db.models import Q
from juser.models import User, UserGroup
@ -34,7 +35,7 @@ def get_role(user_id):
def groups_str(username):
groups = []
user = User.objects.get(username=username)
for group in user.user_group.filter(Q(type='A') | Q(type='M')):
for group in user.user_group.filter(type='A'):
groups.append(group.name)
if len(groups) < 4:
return ' '.join(groups)
@ -42,6 +43,16 @@ def groups_str(username):
return "%s ..." % ' '.join(groups[0:3])
@register.filter(name='group_manage_str')
def group_manage_str(username):
user = User.objects.get(username=username)
group = user.user_group.filter(type='M')
if group:
return group[0].name
else:
return ''
@register.filter(name='get_item')
def get_item(dictionary, key):
return dictionary.get(key)
@ -70,9 +81,9 @@ def perm_count(group_id):
@register.filter(name='group_type_to_str')
def group_type_to_str(type_name):
group_types = {
'P': '私有组',
'M': '管理组',
'A': '授权',
'P': '用户',
'M': '部门',
'A': '用户',
}
return group_types.get(type_name)
@ -85,6 +96,10 @@ def perm_asset_count(user_id):
@register.filter(name='filter_private')
def filter_private(group):
agroup = []
pattern = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
p = BisGroup.objects.get(name='ALL')
[agroup.append(g) for g in group if g != p]
return agroup
for g in group:
if not pattern.match(g.name):
agroup.append(g)
agroup.remove(p)
return agroup

View File

@ -14,4 +14,5 @@ urlpatterns = patterns('',
(r'^jasset/', include('jasset.urls')),
(r'^jlog/', include('jlog.urls')),
(r'^jperm/', include('jperm.urls')),
)

View File

@ -23,11 +23,11 @@ def skin_config(request):
return render_to_response('skin_config.html')
def jasset_group_add(name, comment, type):
def jasset_group_add(name, comment, jtype):
if BisGroup.objects.filter(name=name):
emg = u'该业务组已存在!'
else:
BisGroup.objects.create(name=name, comment=comment, type=type)
BisGroup.objects.create(name=name, comment=comment, type=jtype)
smg = u'业务组%s添加成功' %name

View File

@ -9,6 +9,7 @@ urlpatterns = patterns('juser.views',
(r'^user_add/$', 'user_add'),
(r'^user_list/$', 'user_list'),
(r'^group_add/$', 'group_add'),
(r'^group_add_ajax/$', 'group_add_ajax'),
(r'^group_list/$', 'group_list'),
(r'^user_detail/$', 'user_detail'),
(r'^user_del/$', 'user_del'),

View File

@ -4,7 +4,6 @@
import time
import os
import hashlib
import random
import subprocess
import ldap
@ -17,12 +16,14 @@ from django.shortcuts import render_to_response
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from django.http import HttpResponse
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from juser.models import UserGroup, User
from connect import PyCrypt, KEY
from connect import BASE_DIR
from connect import CONF
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from jumpserver.views import md5_crypt
CRYPTOR = PyCrypt(KEY)
LDAP_ENABLE = CONF.getint('ldap', 'ldap_enable')
@ -253,16 +254,21 @@ def ldap_del_user(username):
ldap_conn.delete(sudo_dn)
def group_add(request):
def group_add(request, group_type_select='A'):
error = ''
msg = ''
header_title, path1, path2 = '添加属组 | Add Group', 'juser', 'group_add'
group_types = {
# 'P': '私有组',
'M': '管理组',
'A': '授权组',
'M': '部门',
'A': '用户组',
}
users = User.objects.all()
users_all = User.objects.all()
if group_type_select == 'M':
users = [user for user in users_all if not user.user_group.filter(type='M')]
else:
users = users_all
if request.method == 'POST':
group_name = request.POST.get('group_name', '')
group_type = request.POST.get('group_type', 'A')
@ -287,9 +293,20 @@ def group_add(request):
return render_to_response('juser/group_add.html', locals())
def group_add_ajax(request):
group_type = request.POST.get('type', 'A')
users_all = User.objects.all()
if group_type == 'A':
users = users_all
else:
users = [user for user in users_all if not user.user_group.filter(type='M')]
return render_to_response('juser/group_add_ajax.html', locals())
def group_list(request):
header_title, path1, path2 = '查看属组 | Show Group', 'juser', 'group_list'
groups = contact_list = UserGroup.objects.filter(Q(type='M') | Q(type='A')).order_by('id')
groups = contact_list = UserGroup.objects.filter(Q(type='M') | Q(type='A')).order_by('type')
p = paginator = Paginator(contact_list, 10)
try:
@ -327,9 +344,8 @@ def group_edit(request):
msg = ''
header_title, path1, path2 = '修改属组 | Edit Group', 'juser', 'group_edit'
group_types = {
# 'P': '私有组',
'M': '管理组',
'A': '授权组',
'M': '部门',
'A': '用户组',
}
if request.method == 'GET':
group_id = request.GET.get('id', None)
@ -341,7 +357,7 @@ def group_edit(request):
users_selected = group.user_set.all()
users = [user for user in users_all if user not in users_selected]
return render_to_response('juser/group_add.html', locals())
return render_to_response('juser/group_edit.html', locals())
else:
group_id = request.POST.get('group_id', None)
group_name = request.POST.get('group_name', None)
@ -349,7 +365,6 @@ def group_edit(request):
users_selected = request.POST.getlist('users_selected')
group_type = request.POST.get('group_type')
group = UserGroup.objects.filter(id=group_id)
# return HttpResponse(group_type)
group.update(name=group_name, comment=comment, type=group_type)
group_update_user(group_id, users_selected)
@ -407,9 +422,10 @@ def user_edit(request):
password = user.password
ssh_key_pwd = user.ssh_key_pwd
name = user.name
all_group = UserGroup.objects.filter(Q(type='M') | Q(type='A'))
groups = user.user_group.filter(Q(type='M') | Q(type='A'))
groups_str = ' '.join([str(group.id) for group in groups])
manage_groups = UserGroup.objects.filter(type='M')
auth_groups = UserGroup.objects.filter(type='A')
manage_group_id = user.user_group.get(type='M').id
groups_str = ' '.join([str(group.id) for group in auth_groups])
user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
role_post = user.role
ssh_pwd = user.ssh_pwd
@ -420,8 +436,11 @@ def user_edit(request):
password = request.POST.get('password', None)
name = request.POST.get('name', None)
email = request.POST.get('email', '')
groups = request.POST.getlist('groups', None)
groups_str = ' '.join(groups)
manage_group_id = request.POST.get('manage_group', '')
auth_groups = request.POST.getlist('groups', None)
groups = auth_groups
groups.append(manage_group_id)
groups_str = ' '.join(auth_groups)
role_post = request.POST.get('role', None)
ssh_pwd = request.POST.get('ssh_pwd', None)
ssh_key_pwd = request.POST.get('ssh_key_pwd', None)
@ -464,14 +483,18 @@ def user_add(request):
msg = ''
header_title, path1, path2 = '添加用户 | Add User', 'juser', 'user_add'
user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
all_group = UserGroup.objects.filter(Q(type='M') | Q(type='A')).order_by('-type')
manage_groups = UserGroup.objects.filter(type='M')
auth_groups = UserGroup.objects.filter(type='A')
if request.method == 'POST':
username = request.POST.get('username', None)
password = request.POST.get('password', '')
name = request.POST.get('name', None)
email = request.POST.get('email', '')
groups = request.POST.getlist('groups', None)
groups_str = ' '.join(groups)
manage_group_id = request.POST.get('manage_group')
auth_groups = request.POST.getlist('groups', None)
groups = auth_groups
groups.append(manage_group_id)
groups_str = ' '.join(auth_groups)
role_post = request.POST.get('role', 'CU')
ssh_pwd = request.POST.get('ssh_pwd', '')
ssh_key_pwd = request.POST.get('ssh_key_pwd', '')

96
log_handler.py Executable file
View File

@ -0,0 +1,96 @@
#!/usr/bin/python
#coding: utf-8
import os
import sys
import time
cur_dir = os.path.dirname(__file__)
sys.path.append('%s/webroot/AutoSa/' % cur_dir)
os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings'
import django
django.setup()
from jlog.models import Log
def log_hanler(pid):
log = Log.objects.filter(id=pid)
if log:
log = log[0]
filename = log.logfile
if os.path.isfile(filename):
ret1 = os.system('cat %s | grep "DateTime" > %s.his' % (filename, filename))
ret2 = os.system('cat %s | grep "\[.*@.*\][\$\#]" >> %s.his' % (filename, filename))
ret3 = os.system('cat %s | grep "EndTime" >> %s.his' % (filename, filename))
if (ret1 + ret2 + ret3) == 0:
print 'Handler %s ok.' % filename
def set_finish(id):
logs = Log.objects.filter(id=id, finish=0)
if logs:
structtime_start = time.localtime()
timestamp_end = int(time.mktime(structtime_start))
log = logs[0]
log.finish = 1
log.end_time = timestamp_end
log.save()
def kill_pid(pid):
try:
os.kill(pid, 9)
except OSError:
pass
def pid_exist(pid):
pid_dir = "/proc/%s" % pid
if os.path.isdir(pid_dir):
return True
else:
return False
def del_pid(pid_id):
pid = Pid.objects.filter(id=pid_id)
if pid:
pid[0].delete()
def get_pids():
pids = []
pids_obj = Pid.objects.all()
for pid_obj in pids_obj:
pids.append((pid_obj.id, pid_obj.ppid, pid_obj.cpid, pid_obj.pid, pid_obj.start_time))
return pids
def run():
for pid_id, ppid, cpid, pid, start_time in get_pids():
if pid_exist(cpid):
if pid_exist(ppid):
structtime_start = time.localtime()
timestamp_end = int(time.mktime(structtime_start))
if timestamp_end - start_time > 7200:
kill_pid(ppid)
kill_pid(cpid)
del_pid(pid_id)
set_finish(pid)
log_hanler(pid)
else:
kill_pid(cpid)
del_pid(pid_id)
set_finish(pid)
log_hanler(pid)
else:
del_pid(pid_id)
set_finish(pid)
log_hanler(pid)
if __name__ == '__main__':
while True:
run()
time.sleep(0.5)

View File

@ -59,7 +59,6 @@ function GetTableDataBox() {
return returnData;
}
function move(from, to) {
$("#" + from + " option").each(function () {
if ($(this).prop("selected") == true) {
@ -73,3 +72,34 @@ function move_all(from, to) {
$("#" + to).append(this);
});
}
function selectAll(){
var checklist = document.getElementsByName ("selected");
if(document.getElementById("select_all").checked)
{
for(var i=0;i<checklist.length;i++)
{
checklist[i].checked = 1;
}
}else{
for(var j=0;j<checklist.length;j++)
{
checklist[j].checked = 0;
}
}
}
function move(from, to) {
$("#"+from+" option").each(function(){
if ( $(this).prop("selected") == true ) {
$("#"+to).append(this);
}
});
}
function move_all(from, to){
$("#"+from).children().each(function(){
$("#"+to).append(this);
});
}

View File

@ -28,7 +28,7 @@
maxHeight: false,
scalePhotos: true,
scrolling: true,
opacity: 0.9,
opacity: 0.3,
preloading: true,
className: false,
overlayClose: true,
@ -418,7 +418,8 @@
$overlay.css({
opacity: opacity === opacity ? opacity : '',
cursor: settings.get('overlayClose') ? 'pointer' : '',
visibility: 'visible'
visibility: 'visible',
// 'background-color': 'black'
}).show();
if (settings.get('closeButton')) {

View File

@ -1,5 +1,4 @@
<!-- Mainly scripts -->
<script src="/static/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/static/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/static/js/bootstrap-dialog.js"></script>
@ -10,7 +9,6 @@
<script src="/static/js/plugins/pace/pace.min.js"></script>
<!-- iCheck box -->
{#<script src="/static/js/plugins/iCheck/icheck.min.js"></script>#}
<!-- Peity -->
<script src="/static/js/plugins/peity/jquery.peity.min.js"></script>
@ -18,10 +16,21 @@
<!-- Peity -->
<script src="/static/js/demo/peity-demo.js"></script>
<script src="/static/js/base.js"></script>
<!-- pop windows -->
<script src="/static/js/jquery.colorbox.js"></script>
<!-- active menu -->
<script>
var str = document.location.pathname.split("/")[1];
var str1 = document.location.pathname.split("/")[2];
$("#"+str).addClass('active');
$("#"+str1).addClass('active');
</script>
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"80%"});
});
</script>

View File

@ -2,9 +2,6 @@
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/base.js"></script>
<!-- pop windows -->
<script src="/static/js/jquery.colorbox.js"></script>
<!-- validator js -->
<script src="/static/js/validator/jquery.validator.js"></script>
<script src="/static/js/validator/zh_CN.js"></script>

View File

@ -102,7 +102,7 @@
<tr class="gradeX">
<td class="text-center"> {{ post.user.name }} </td>
<td class="text-center"> {{ post.asset.ip }} </td>
<td class="text-center"> 命令统计 </td>
<td class="text-center"> <a href="/logHistory/?id={{ log.id }}" class="log_command">命令统计</a></td>
<td class="text-center"> {{ post.start_time|date:"Y-m-d H:i:s"}} </td>
<td class="text-center"> {{ post.end_time|date:"Y-m-d H:i:s" }} </td>
</tr>

View File

@ -33,8 +33,20 @@
<div class="panel-heading">
<div class="panel-options">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab-1">授权编辑</a></li>
<li class=""><a data-toggle="tab" href="#tab-2">查看授权</a></li>
<li id="tab1" class="active"><a data-toggle="tab" href="#tab-1">授权编辑</a></li>
<li id="tab2" class=""><a data-toggle="tab" href="#tab-2">查看授权</a></li>
<li style="float: right">
<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="button" class="btn btn-sm btn-primary">
Search
</button>
</div>
</div>
</form>
</li>
</ul>
</div>
</div>
@ -47,13 +59,15 @@
<thead>
<tr>
<th class="text-center">组名</th>
<th class="text-center">类型</th>
<th class="text-center">
<span class="text-muted text-xs block">类型</span>
</th>
<th class="text-center">成员数量</th>
<th class="text-center">授权数量</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tbody id="perm_edit">
{% for group in contacts.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ group.name }} </td>
@ -61,7 +75,7 @@
<td class="text-center"> {{ group.id|member_count }} </td>
<td class="text-center"> {{ group.id|perm_count }} </td>
<td class="text-center">
<a href="../perm_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a title="[ {{ group.name }} 授权详情 ]" href="../perm_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="../perm_del/?id={{ group.id }}" class="btn btn-xs btn-danger">删除</a>
</td>
@ -120,7 +134,7 @@
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tbody id="perm_list">
{% for user in contacts2.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ user.name }} </td>
@ -128,7 +142,7 @@
<td class="text-center"> {{ user.username | groups_str }} </td>
<td class="text-center"> {{ user.id | perm_asset_count }} </td>
<td class="text-center">
<a href="../perm_asset_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a title="[ {{ user.name }} ] 授权详情" href="../perm_asset_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">详情</a>
</td>
</tr>
{% endfor %}
@ -192,6 +206,29 @@
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
});
$(document).ready(function(){
$('#search_btn').click(function(){
if ($('#tab2').attr('class') == 'active'){
var tab='tab2'
} else {
var tab='tab1'
}
var search=$('#search_input').val()
$.post('/jperm/perm_list_ajax/',
{'tab': tab, 'search': search},
function(data){
if ($('#tab2').attr('class') == 'active'){
$('#tab-2').html(data)
} else {
$('#tab-1').html(data)
}
})
})
})
</script>
{% endblock %}

View File

@ -0,0 +1,132 @@
{% load mytags %}
{% ifequal tab 'tab1' %}
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th class="text-center">组名</th>
<th class="text-center">
<span class="text-muted text-xs block">类型</span>
</th>
<th class="text-center">成员数量</th>
<th class="text-center">授权数量</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody id="perm_edit">
{% for group in contacts.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ group.name }} </td>
<td class="text-center"> {{ group.type|group_type_to_str }} </td>
<td class="text-center"> {{ group.id|member_count }} </td>
<td class="text-center"> {{ group.id|perm_count }} </td>
<td class="text-center">
<a title="[ {{ group.name }} ] 授权详情" href="../perm_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a href="../perm_edit/?id={{ group.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="../perm_del/?id={{ group.id }}" class="btn btn-xs btn-danger">删除</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<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
</div>
</div>
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="editable_paginate">
<ul class="pagination" style="margin-top: 0; float: right">
{% if contacts.has_previous %}
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?page={{ contacts.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="#">Previous</a>
</li>
{% endif %}
{% for page in p.page_range %}
{% ifequal offset1 page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?page={{ contacts.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
<a href="#">Next</a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
{% else %}
<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>
</tr>
</thead>
<tbody id="perm_list">
{% for user in contacts2.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ user.name }} </td>
<td class="text-center"> {{ user.id | get_role }} </td>
<td class="text-center"> {{ user.username | groups_str }} </td>
<td class="text-center"> {{ user.id | perm_asset_count }} </td>
<td class="text-center">
<a title="{{ user.name }} ] 授权详情" href="../perm_asset_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">详情</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ contacts2.start_index }} to {{ contacts2.end_index }} of {{ p2.count }} entries
</div>
</div>
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="editable_paginate">
<ul class="pagination" style="margin-top: 0; float: right">
{% if contacts2.has_previous %}
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?page={{ contacts2.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="#">Previous</a>
</li>
{% endif %}
{% for page in p2.page_range %}
{% ifequal offset1 page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts2.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?page={{ contacts2.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
<a href="#">Next</a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
{% endifequal %}

View File

@ -34,12 +34,6 @@
{% if msg %}
<div class="alert alert-success text-center">{{ msg }}</div>
{% endif %}
<div class="form-group hidden">
<label for="group_id" class="col-sm-2 control-label">ID<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="group_id" name="group_id" placeholder="Group name" type="text" class="form-control" value="{{ group_id }}">
</div>
</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">
@ -50,9 +44,9 @@
<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">
<select id="group_type" name="group_type" class="form-control m-b">
<select id="group_type" name="group_type" class="form-control m-b" onchange="change_type(this.value)">
{% for t, type_name in group_types.items %}
{% ifequal t group_type %}
{% ifequal t group_type_select %}
<option value="{{ t }}" selected>{{ type_name }}</option>
{% else %}
<option value="{{ t }}">{{ type_name }}</option>
@ -63,7 +57,7 @@
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="groups" class="col-lg-2 control-label">用户</label>
<label for="users" class="col-lg-2 control-label">用户</label>
<div class="col-sm-3">
<select id="users" name="users" size="12" class="form-control m-b" multiple>
{% for user in users %}
@ -80,9 +74,6 @@
<div class="col-sm-3">
<div>
<select id="users_selected" name="users_selected" class="form-control m-b" size="12" multiple>
{% for user in users_selected %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
</div>
@ -98,8 +89,8 @@
<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="submit">取消</button>
<button class="btn btn-primary" type="submit" onclick="javascript: (function(){$('#users_selected option').each(function(){$(this).prop('selected', true)})})()">确认保存</button>
<button class="btn btn-white" type="reset">取消</button>
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
</div>
</div>
</form>
@ -131,5 +122,23 @@ $('#groupForm').validator({
form.submit();
}
});
function change_type(type){
$.post('/juser/group_add_ajax/',
{'type': type},
function(data){
$('#users').html(data)
})
}
$(document).ready(function(){
$("#submit_button").click(function(){
$('#users_selected option').each(function(){
$(this).prop('selected', true)
})
})
})
</script>
{% endblock %}

View File

@ -0,0 +1,4 @@
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}

View File

@ -0,0 +1,133 @@
{% 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>填写基本信息 <small> Fill group info.</small></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>
<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>
</div>
</div>
<div class="ibox-content">
<form id="groupForm" method="post" 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="group_name" class="col-sm-2 control-label">组名<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="group_name" name="group_name" placeholder="Group name" type="text" class="form-control" value="{{ group_name }}">
<input id="group_id" name="group_id" type="text" class="form-control" value="{{ 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">
<input class="form-control" value="{{ group_type|group_type_to_str }}" readonly>
<input name="group_type" class="form-control" id="group_type" value="{{ group_type }}" style="display: none">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="users" class="col-lg-2 control-label">用户</label>
<div class="col-sm-3">
<select id="users" name="users" size="12" class="form-control m-b" multiple>
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-sm-1">
<div class="btn-group" style="margin-top: 50px;">
<button type="button" class="btn btn-white" onclick="move('users', 'users_selected')"><i class="fa fa-chevron-right"></i></button>
<button type="button" class="btn btn-white" onclick="move('users_selected', 'users')"><i class="fa fa-chevron-left"></i> </button>
</div>
</div>
<div class="col-sm-3">
<div>
<select id="users_selected" name="users_selected" class="form-control m-b" size="12" multiple>
{% for user in users_selected %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="comment" class="col-sm-2 control-label">备注</label>
<div class="col-sm-8">
<input id="comment" name="comment" placeholder="Comment" type="text" class="form-control" value="{{ comment }}">
</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>
</div>
</div>
</div>
<script>
$('#groupForm').validator({
timely: 2,
theme: "yellow_right_effect",
fields: {
"group_name": {
rule: "required",
tip: "输入组名",
ok: "",
msg: {required: "必须填写!"}
},
"group_type": {
rule: "checked",
tip: "选择组类型",
ok: "",
msg: {required: "至少选择一个组!"}
}
},
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

@ -53,7 +53,7 @@
<td class="text-center"> {{ group.id|member_count }} </td>
<td class="text-center"> {{ group.comment }} </td>
<td class="text-center">
<a href="../group_detail/?id={{ group.id }}" class="iframe btn btn-xs btn-primary">成员</a>
<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>
</td>

View File

@ -71,21 +71,36 @@
</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>
<label for="manage_group" class="col-lg-2 control-label">部门<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<select id="groups" name="groups" class="form-control m-b" multiple size="10">
{% for group in all_group %}
<select id="manage_group" name="manage_group" class="form-control m-b">
{% for group in manage_groups %}
{% ifequal group.id manage_group_id %}
<option value="{{ group.id }}" selected>{{ group.name }}</option>
{% else %}
<option value="{{ group.id }}">{{ group.name }}</option>
{% endifequal %}
{% endfor %}
</select>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="groups" class="col-lg-2 control-label">用户组</label>
<div class="col-sm-8">
<select id="groups" name="groups" class="form-control m-b" multiple size="12">
{% for group in auth_groups %}
{% if groups_str %}
{% if group.id|int2str in groups_str %}
<option value="{{ group.id }}" selected>{{ group.name }} --- {{ group.type|group_type_to_str }}</option>
<option value="{{ group.id }}" selected>{{ group.name }}</option>
{% else %}
<option value="{{ group.id }}">{{ group.name }} --- {{ group.type|group_type_to_str }}</option>
<option value="{{ group.id }}">{{ group.name }}</option>
{% endif %}
{% else %}
{% if forloop.first %}
<option value="{{ group.id }}" selected>{{ group.name }} --- {{ group.type|group_type_to_str }}</option>
<option value="{{ group.id }}" selected>{{ group.name }}</option>
{% else %}
<option value="{{ group.id }}">{{ group.name }} --- {{ group.type|group_type_to_str }}</option>
<option value="{{ group.id }}">{{ group.name }}</option>
{% endif %}
{% endif %}
{% endfor %}
@ -179,11 +194,11 @@ $('#userForm').validator({
ok: "",
msg: {required: "必须填写"}
},
"groups": {
"manage_group": {
rule: "checked",
tip: "选择用户组",
tip: "选择部门",
ok: "",
msg: {checked: "至少选择一个"}
msg: {checked: "至少选择一个部门"}
},
"name": {
rule: "required",

View File

@ -42,7 +42,8 @@
<th class="text-center">ID</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>
@ -57,11 +58,12 @@
<td class="text-center"> {{ user.id }} </td>
<td class="text-center"> {{ user.username }} </td>
<td class="text-center"> {{ user.name }} </td>
<td class="text-center"> {{ user.username|group_manage_str }} </td>
<td class="text-center"> {{ user.username|groups_str }}</td>
<td class="text-center">{{ user.id|get_role }}</td>
<td class="text-center">{{ user.is_active|bool2str }}</td>
<td class="text-center">
<a href="../user_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a title="[ {{ user.name }} ] 详情" href="../user_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">详情</a>
<a href="../user_edit/?id={{ user.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="../user_del/?id={{ user.id }}" class="btn btn-xs btn-danger">删除</a>
</td>
@ -113,10 +115,5 @@
</div>
</div>
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
});
</script>
{% endblock %}

View File

@ -14,7 +14,7 @@
<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="user_list"><a href="/juser/user_list/">查看用户</a></li>
<li id="user_list"><a href="/juser/user_list/">查看用户<span class="label label-primary pull-right">16/24</span></a></li>
<li id="user_add"><a href="/juser/user_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>
@ -39,7 +39,7 @@
<li id="jlog">
<a href="#"><i class="fa fa-files-o"></i> <span class="nav-label">日志审计</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li id="log_list"><a href="/jlogb/">查看日志</a></li>
<li id="log_list"><a href="/jlog/">查看日志</a></li>
<li id="log_detail"><a href="/jlog/log_detail/">日志分析</a></li>
</ul>
</li>

74
templates/test.html Normal file
View File

@ -0,0 +1,74 @@
<html>
<head>
<meta charset='utf8'>
<script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<style type="text/css">
.blue
{
color: blue;
}
</style>
{#<script>#}
{#$('html').ajaxSend(function(event, xhr, settings) {#}
{# function getCookie(name) {#}
{# var cookieValue = null;#}
{# if (document.cookie && document.cookie != '') {#}
{# var cookies = document.cookie.split(';');#}
{# for (var i = 0; i < cookies.length; i++) {#}
{# var cookie = jQuery.trim(cookies[i]);#}
{# // Does this cookie string begin with the name we want?#}
{# if (cookie.substring(0, name.length + 1) == (name + '=')) {#}
{# cookieValue = decodeURIComponent(cookie.substring(name.length + 1));#}
{# break;#}
{# }#}
{# }#}
{# }#}
{# return cookieValue;#}
{# }#}
{# if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {#}
{# // Only send the token to relative URLs i.e. locally.#}
{# xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));#}
{# }#}
{#});#}
{#</script>#}
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#test").text(function(i,origText){
return "Old text: " + origText + "New text: Hllo" + i
})
});
$("#btn2").click(function(){
$.post('/test_ajax/',
{'name': 'join', 'age': 10},
function(data, status){
$('#btn1').text(data)
})
});
$("#btn3").click(function(){
$("p").toggleClass('blue')
// $("p").addClass('blue')
// $("p").before("Some thine")
});
})
</script>
</head>
<body>
<p id="test" class="blue">
这是段落中的<b>粗体</b>文本。
<p><span>hello</span></p>
</p>
<!-- <input type="text" id="test2" name="nameaaaaaaaaaa" value="米老鼠"> -->
<button id="btn1">显示文本</button>
<button id="btn2">显示 HTML</button>
<button id="btn3">显示 value</button>
</body>
</html>