Commit 1925cf40 authored by halcyon's avatar halcyon

增加js判断

parents 6b95c7ed 7435d602
...@@ -34,12 +34,12 @@ except ImportError: ...@@ -34,12 +34,12 @@ except ImportError:
time.sleep(3) time.sleep(3)
sys.exit() sys.exit()
CURRENT_DIR = os.path.dirname(__file__) BASE_DIR = os.path.dirname(__file__)
CONF = ConfigParser() CONF = ConfigParser()
CONF.read(os.path.join(CURRENT_DIR, 'jumpserver.conf')) CONF.read(os.path.join(BASE_DIR, 'jumpserver.conf'))
LOG_DIR = os.path.join(CURRENT_DIR, 'logs') LOG_DIR = os.path.join(BASE_DIR, 'logs')
# Web generate user ssh_key dir. # Web generate user ssh_key dir.
SSH_KEY_DIR = os.path.join(CURRENT_DIR, 'keys') SSH_KEY_DIR = os.path.join(BASE_DIR, 'keys')
# User upload the server key to this dir. # User upload the server key to this dir.
SERVER_KEY_DIR = os.path.join(SSH_KEY_DIR, 'server') SERVER_KEY_DIR = os.path.join(SSH_KEY_DIR, 'server')
# The key of decryptor. # The key of decryptor.
......
...@@ -4,6 +4,7 @@ from django.shortcuts import render_to_response ...@@ -4,6 +4,7 @@ from django.shortcuts import render_to_response
from django.core.paginator import Paginator, EmptyPage from django.core.paginator import Paginator, EmptyPage
from models import IDC, Asset, BisGroup from models import IDC, Asset, BisGroup
from models import IDC, Asset, UserGroup
from connect import PyCrypt, KEY from connect import PyCrypt, KEY
...@@ -17,6 +18,9 @@ def jadd_host(request): ...@@ -17,6 +18,9 @@ def jadd_host(request):
cryptor = PyCrypt(KEY) cryptor = PyCrypt(KEY)
eidc = IDC.objects.all() eidc = IDC.objects.all()
egroup = BisGroup.objects.all() egroup = BisGroup.objects.all()
egroup = UserGroup.objects.all()
is_actived = {'active': 1, 'no_active': 0}
login_typed = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
if request.method == 'POST': if request.method == 'POST':
j_ip = request.POST.get('j_ip') j_ip = request.POST.get('j_ip')
...@@ -30,6 +34,7 @@ def jadd_host(request): ...@@ -30,6 +34,7 @@ def jadd_host(request):
j_idc = IDC.objects.get(name=j_idc) j_idc = IDC.objects.get(name=j_idc)
for group in j_group: for group in j_group:
c = BisGroup.objects.get(name=group) c = BisGroup.objects.get(name=group)
c = UserGroup.objects.get(name=group)
groups.append(c) groups.append(c)
if Asset.objects.filter(ip=str(j_ip)): if Asset.objects.filter(ip=str(j_ip)):
...@@ -130,4 +135,4 @@ def jadd_group(request): ...@@ -130,4 +135,4 @@ def jadd_group(request):
def jlist_group(request): def jlist_group(request):
header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '查看业务组' header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '查看业务组'
posts = BisGroup.objects.all().order_by('id') posts = BisGroup.objects.all().order_by('id')
return render_to_response('jasset/jlist_group.html', locals(), context_instance=RequestContext(request)) return render_to_response('jasset/jlist_group.html', locals(), context_instance=RequestContext(request))
\ No newline at end of file
...@@ -12,6 +12,11 @@ host_url = ldap://192.168.8.60:389 ...@@ -12,6 +12,11 @@ host_url = ldap://192.168.8.60:389
base_dn = dc=fengxing,dc=org base_dn = dc=fengxing,dc=org
root_dn = cn=admin,dc=fengxing,dc=org root_dn = cn=admin,dc=fengxing,dc=org
root_pw = 123456 root_pw = 123456
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
root_pw = secret234
[web] [web]
key = 88aaaf7ffe3c6c04 key = 88aaaf7ffe3c6c04
......
...@@ -46,6 +46,7 @@ INSTALLED_APPS = ( ...@@ -46,6 +46,7 @@ INSTALLED_APPS = (
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'jumpserver',
'juser', 'juser',
'jasset', 'jasset',
'jpermission', 'jpermission',
......
import time
from django import template
register = template.Library()
@register.filter(name='stamp2str')
def stamp2str(value):
try:
return time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(value))
except AttributeError:
return '0000/00/00 00:00:00'
@register.filter(name='int2str')
def int2str(value):
return str(value)
...@@ -10,3 +10,5 @@ def base(request): ...@@ -10,3 +10,5 @@ def base(request):
def skin_config(request): def skin_config(request):
return render_to_response('skin_config.html') return render_to_response('skin_config.html')
This diff is collapsed.
/*@import url("//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&lang=en");*/ @import url("//fonts.useso.com/css?family=Open+Sans:300,400,600,700&lang=en");
/*
*
* INSPINIA - Responsive Admin Theme
* Copyright 2014 Webapplayers.com
*
*/
h1, h1,
h2, h2,
h3, h3,
......
/*! nice Validator 0.7.3
* (c) 2012-2014 Jony Zhang <zj86@live.cn>, MIT Licensed
* http://niceue.com/validator/
*/
.n-inline-block,.nice-validator input,.nice-validator select,.nice-validator textarea,.msg-wrap,.n-icon,.n-msg{display:inline-block;*display:inline;*zoom:1}
.msg-box{position:relative;*zoom:1}
.msg-wrap{position:relative;white-space:nowrap}
.msg-wrap,.n-icon,.n-msg{vertical-align:top}
.n-arrow{position:absolute;overflow:hidden;}
.n-arrow b,.n-arrow i{position:absolute;left:0;top:0;border:0;margin:0;padding:0;overflow:hidden;font-weight:400;font-style:normal;font-size:12px;font-family:serif;line-height:14px;_line-height:15px}
.n-arrow i{text-shadow:none}
.n-icon{width:16px;height:16px;overflow:hidden;background-repeat:no-repeat}
.n-msg{display:inline-block;line-height:15px;margin-left:2px;*margin-top:-1px;_margin-top:0;font-size:12px;font-family:simsun}
.n-error{color:#c33}
.n-ok{color:#390}
.n-tip,.n-loading{color:#808080}
.n-error .n-icon{background-position:0 0}
.n-ok .n-icon{background-position:-16px 0}
.n-tip .n-icon{background-position:-32px 0}
.n-loading .n-icon{background:url("images/loading.gif") 0 center no-repeat !important}
.n-top,.n-right,.n-bottom,.n-left{display:inline-block;line-height:0;vertical-align:top;outline:0}
.n-top .n-arrow,.n-bottom .n-arrow{height:6px;width:12px;left:8px}
.n-left .n-arrow,.n-right .n-arrow{width:6px;height:12px;top:6px}
.n-top{vertical-align:top;}
.n-top .msg-wrap{margin-bottom:6px}
.n-top .n-arrow{bottom:-6px;}
.n-top .n-arrow b{top:-6px}
.n-top .n-arrow i{top:-7px}
.n-bottom{vertical-align:bottom;}
.n-bottom .msg-wrap{margin-top:6px}
.n-bottom .n-arrow{top:-6px;}
.n-bottom .n-arrow b{top:-1px}
.n-bottom .n-arrow i{top:0}
.n-left .msg-wrap{right:100%;margin-right:6px}
.n-left .n-arrow{right:-6px;}
.n-left .n-arrow b{left:-6px}
.n-left .n-arrow i{left:-7px}
.n-right .msg-wrap{margin-left:6px}
.n-right .n-arrow{left:-6px;}
.n-right .n-arrow b{left:1px}
.n-right .n-arrow i{left:2px}
.n-default .n-left,.n-default .n-right{margin-top:5px}
.n-default .n-top .msg-wrap{bottom:100%}
.n-default .n-bottom .msg-wrap{top:100%}
.n-default .msg-wrap{position:absolute;z-index:1;}
.n-default .msg-wrap .n-icon{background-image:url("images/validator_default.png")}
.n-default .n-tip .n-icon{display:none}
.n-simple .msg-wrap{position:absolute;z-index:1;}
.n-simple .msg-wrap .n-icon{background-image:url("images/validator_simple.png")}
.n-simple .n-top .msg-wrap{bottom:100%}
.n-simple .n-bottom .msg-wrap{top:100%}
.n-simple .n-left,.n-simple .n-right{margin-top:5px}
.n-simple .n-bottom .msg-wrap{margin-top:3px}
.n-simple .n-tip .n-icon{display:none}
.n-yellow .msg-wrap{position:absolute;z-index:1;padding:4px 6px;font-size:12px;border:1px solid transparent;background-color:#fffcef;border-color:#ffbb76;color:#db7c22;box-shadow:0 1px 3px #ccc;border-radius:2px;}
.n-yellow .msg-wrap .n-arrow b{color:#ffbb76;text-shadow:0 0 2px #ccc}
.n-yellow .msg-wrap .n-arrow i{color:#fffcef}
.n-yellow .msg-wrap .n-icon{background-image:url("images/validator_simple.png")}
.n-yellow .n-top .msg-wrap{bottom:100%}
.n-yellow .n-bottom .msg-wrap{top:100%}
.n-yellow .n-tip,.n-yellow .n-ok,.n-yellow .n-loading{background-color:#f8fdff;border-color:#ddd;color:#333;box-shadow:0 1px 3px #ccc;}
.n-yellow .n-tip .n-arrow b,.n-yellow .n-ok .n-arrow b,.n-yellow .n-loading .n-arrow b{color:#ddd;text-shadow:0 0 2px #ccc}
.n-yellow .n-tip .n-arrow i,.n-yellow .n-ok .n-arrow i,.n-yellow .n-loading .n-arrow i{color:#f8fdff}
.n-yellow .n-tip .n-icon{display:none}
This diff is collapsed.
/*********************************
* Themes, rules, and i18n support
* Locale: Chinese; 中文
*********************************/
(function(factory) {
if (typeof define === 'function') {
define(function(require, exports, module){
var $ = require('jquery');
$._VALIDATOR_URI = module.uri;
require('../src/jquery.validator')($);
factory($);
});
} else {
factory(jQuery);
}
}(function($) {
/* Global configuration
*/
$.validator.config({
//stopOnError: false,
//theme: 'yellow_right',
defaultMsg: "{0}格式不正确",
loadingMsg: "正在验证...",
// Custom rules
rules: {
digits: [/^\d+$/, "请输入数字"]
,letters: [/^[a-z]+$/i, "{0}只能输入字母"]
,tel: [/^(?:(?:0\d{2,3}[\- ]?[1-9]\d{6,7})|(?:[48]00[\- ]?[1-9]\d{6}))$/, "电话格式不正确"]
,mobile: [/^1[3-9]\d{9}$/, "手机号格式不正确"]
,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "邮箱格式不正确"]
,qq: [/^[1-9]\d{4,}$/, "QQ号格式不正确"]
,date: [/^\d{4}-\d{1,2}-\d{1,2}$/, "请输入正确的日期,例:yyyy-mm-dd"]
,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "请输入正确的时间,例:14:30或14:30:00"]
,ID_card: [/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/, "请输入正确的身份证号码"]
,url: [/^(https?|ftp):\/\/[^\s]+$/i, "网址格式不正确"]
,postcode: [/^[1-9]\d{5}$/, "邮政编码格式不正确"]
,chinese: [/^[\u0391-\uFFE5]+$/, "请输入中文"]
,username: [/^\w{3,12}$/, "请输入3-12位数字、字母、下划线"]
,password: [/^[0-9a-zA-Z]{6,16}$/, "密码由6-16位数字、字母组成"]
,accept: function (element, params){
if (!params) return true;
var ext = params[0];
return (ext === '*') ||
(new RegExp(".(?:" + (ext || "png|jpg|jpeg|gif") + ")$", "i")).test(element.value) ||
this.renderMsg("只接受{1}后缀", ext.replace('|', ','));
}
}
});
/* Default error messages
*/
$.validator.config({
messages: {
required: "{0}不能为空",
remote: "{0}已被使用",
integer: {
'*': "请输入整数",
'+': "请输入正整数",
'+0': "请输入正整数或0",
'-': "请输入负整数",
'-0': "请输入负整数或0"
},
match: {
eq: "{0}与{1}不一致",
neq: "{0}与{1}不能相同",
lt: "{0}必须小于{1}",
gt: "{0}必须大于{1}",
lte: "{0}必须小于或等于{1}",
gte: "{0}必须大于或等于{1}"
},
range: {
rg: "请输入{1}到{2}的数",
gte: "请输入大于或等于{1}的数",
lte: "请输入小于或等于{1}的数"
},
checked: {
eq: "请选择{1}项",
rg: "请选择{1}到{2}项",
gte: "请至少选择{1}项",
lte: "请最多选择{1}项"
},
length: {
eq: "请输入{1}个字符",
rg: "请输入{1}到{2}个字符",
gte: "请至少输入{1}个字符",
lte: "请最多输入{1}个字符",
eq_2: "",
rg_2: "",
gte_2: "",
lte_2: ""
}
}
});
/* Themes
*/
var TPL_ARROW = '<span class="n-arrow"><b>◆</b><i>◆</i></span>';
$.validator.setTheme({
'simple_right': {
formClass: 'n-simple',
msgClass: 'n-right'
},
'simple_bottom': {
formClass: 'n-simple',
msgClass: 'n-bottom'
},
'yellow_top': {
formClass: 'n-yellow',
msgClass: 'n-top',
msgArrow: TPL_ARROW
},
'yellow_right': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW
},
'yellow_right_effect': {
formClass: 'n-yellow',
msgClass: 'n-right',
msgArrow: TPL_ARROW,
msgShow: function($msgbox, type){
var $el = $msgbox.children();
if ($el.is(':animated')) return;
if (type === 'error') {
$el.css({
left: '20px',
opacity: 0
}).delay(100).show().stop().animate({
left: '-4px',
opacity: 1
}, 150).animate({
left: '3px'
}, 80).animate({
left: 0
}, 80);
} else {
$el.css({
left: 0,
opacity: 1
}).fadeIn(200);
}
},
msgHide: function($msgbox, type){
var $el = $msgbox.children();
$el.stop().delay(100).show().animate({
left: '20px',
opacity: 0
}, 300, function(){
$msgbox.hide();
});
}
}
});
}));
\ No newline at end of file
...@@ -31,17 +31,14 @@ ...@@ -31,17 +31,14 @@
</a> </a>
</div> </div>
</div> </div>
<div class="ibox-content" name="addidc" id="addidc" onclick="show(this)">
addidc
</div>
<div class="ibox-content" id="addhost"> <div class="ibox-content" id="addhost">
{% if emg %} {% if emg %}
<div class="alert alert-warning text-center">{{ emg }}</div> <div class="alert alert-warning text-center">{{ emg }}</div>
{% endif %} {% endif %}
<form method="post" class="form-horizontal"> <form method="post" id="jasset_add" class="form-horizontal">
<div class="form-group"><label class="col-sm-2 control-label"> IP地址 </label> <div class="form-group"><label class="col-sm-2 control-label"> IP地址 </label>
<div class="col-sm-8"><input type="text" value="{{ j_ip }}" placeholder="192.168.1.1" name="j_ip" class="form-control"></div> <div class="col-sm-8"><input type="text" value="{{ j_ip }}" name="j_ip" class="form-control"></div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
...@@ -131,17 +128,6 @@ ...@@ -131,17 +128,6 @@
</div> </div>
</div> </div>
<!-- Peity -->
<script src="static/js/plugins/peity/jquery.peity.min.js"></script>
<!-- Custom and plugin javascript -->
<script src="static/js/inspinia.js"></script>
<script src="static/js/plugins/pace/pace.min.js"></script>
<!-- Peity -->
<script src="static/js/demo/peity-demo.js"></script>
<script> <script>
var showFlag={}; var showFlag={};
function show(o){ function show(o){
...@@ -149,12 +135,76 @@ var showFlag={}; ...@@ -149,12 +135,76 @@ var showFlag={};
if(showFlag.j_type=="MAP"){ if(showFlag.j_type=="MAP"){
document.getElementById("a1").style.display=""; document.getElementById("a1").style.display="";
} }
else if(showFlag.addidc=="addidc"){
document.getElementById("addidc").style.display="";
}
else{ else{
document.getElementById("a1").style.display="none"; document.getElementById("a1").style.display="none";
}}; }};
//验证初始化
$('#jasset_add').validator({
focusCleanup: true,
stopOnError:false,
//debug: true,
timely: 2,
theme: "yellow_right_effect",
//自定义规则(PS:建议尽量在全局配置中定义规则,统一管理)
rules: {
username: [/^[a-zA-Z0-9]+$/, '用户名无效! 仅支持字母与数字。'],
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip不正确'],
check_port: [/^\d{1,5}$/, '端口号不正确']
},
fields: {
"j_ip": {
rule: "required;check_ip",
tip: "请输入IP",
ok: "ok",
msg: {required: "必须填写!"}
},
"j_port": {
rule: "required;check_port",
tip: "请输入端口号",
ok: "ok",
msg: {required: "必须填写!"}
},
"user[user_password]": {
rule: "required;length[6~];password;strength",
tip: "6个或更多字符! 要复杂些。",
ok: "",
msg: {
required: "密码不能为空!",
length: "密码最少为6位。"
}
},
"user[screen_name]": {
rule: "required;username;remote[check/user.php]",
tip: "别担心,你可以稍后进行修改。",
ok: "用户名可以使用。<br>你可以稍后进行修改。",
msg: {required: "用户名必填!<br>你可以稍后进行修改。"}
}
},
//验证成功
valid: function(form) {
$.ajax({
url: 'results.php',
type: 'POST',
data: $(form).serialize(),
success: function(d){
$('#result').fadeIn(300).delay(2000).fadeOut(500);
}
});
},
//验证失败
invalid: function(form) {
//按钮动画效果
$('#btn-submit').stop().delay(100)
.animate({left:-5}, 100)
.animate({left:5}, 100)
.animate({left:-4}, 100)
.animate({left:4}, 100)
.animate({left:-3}, 100)
.animate({left:0}, 100);
}
});
</script> </script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -35,16 +35,16 @@ ...@@ -35,16 +35,16 @@
<div class="alert alert-success text-center">{{ msg }}</div> <div class="alert alert-success text-center">{{ msg }}</div>
{% endif %} {% endif %}
<div class="form-group"> <div class="form-group">
<label for="j_group_name" class="col-sm-2 control-label">组名<span class="red-fonts">*</span></label> <label for="group_name" class="col-sm-2 control-label">组名<span class="red-fonts">*</span></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="j_group_name" name="j_group_name" placeholder="Group name" type="text" class="form-control"> <input id="group_name" name="group_name" placeholder="Group name" type="text" class="form-control">
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="j_comment" class="col-sm-2 control-label">备注</label> <label for="comment" class="col-sm-2 control-label">备注</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input id="j_comment" name="j_comment" placeholder="Comment" type="text" class="form-control"> <input id="comment" name="comment" placeholder="Comment" type="text" class="form-control">
</div> </div>
</div> </div>
......
This diff is collapsed.
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
<link href="/static/css/plugins/iCheck/custom.css" rel="stylesheet"> <link href="/static/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="/static/css/animate.css" rel="stylesheet"> <link href="/static/css/animate.css" rel="stylesheet">
<link href="/static/css/style.css" rel="stylesheet"> <link href="/static/css/style.css" rel="stylesheet">
<link href="/static/css/colorbox.css" rel="stylesheet"> <link href="/static/css/colorbox.css" rel="stylesheet">
\ No newline at end of file <link href="/static/css/vaildator/jquery.validator.css" rel="stylesheet">
\ No newline at end of file
...@@ -29,3 +29,7 @@ ...@@ -29,3 +29,7 @@
<!-- pop windows --> <!-- pop windows -->
<script src="/static/js/jquery.colorbox.js"></script> <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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment