mirror of https://github.com/jumpserver/jumpserver
Merge remote-tracking branch 'origin/master'
commit
9652460ba5
|
@ -1,3 +1,4 @@
|
|||
import datetime
|
||||
from django.db import models
|
||||
from juser.models import Group, User
|
||||
|
||||
|
@ -9,6 +10,13 @@ class IDC(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
class Group(models.Model):
|
||||
name = models.CharField(max_length=80, unique=True)
|
||||
comment = models.CharField(max_length=160, blank=True, null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Asset(models.Model):
|
||||
LOGIN_TYPE_CHOICES = (
|
||||
|
@ -26,7 +34,7 @@ class Asset(models.Model):
|
|||
password_common = models.CharField(max_length=80, blank=True, null=True)
|
||||
username_super = models.CharField(max_length=20, blank=True, null=True)
|
||||
password_super = models.CharField(max_length=80, blank=True, null=True)
|
||||
date_added = models.IntegerField(max_length=12)
|
||||
date_added = models.DateTimeField(auto_now=True,default=datetime.datetime.now(), null=True)
|
||||
is_active = models.BooleanField(default=True)
|
||||
comment = models.CharField(max_length=100, blank=True, null=True)
|
||||
|
||||
|
|
|
@ -5,4 +5,7 @@ from jasset.views import *
|
|||
urlpatterns = patterns('',
|
||||
url(r'^$', index),
|
||||
url(r'jadd', jadd),
|
||||
url(r'jlist', jlist),
|
||||
url(r'jadd_idc', jadd_idc),
|
||||
url(r'jlist_idc', jlist_idc),
|
||||
)
|
102
jasset/views.py
102
jasset/views.py
|
@ -1,16 +1,110 @@
|
|||
#coding:utf-8
|
||||
# coding:utf-8
|
||||
import datetime
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
|
||||
from models import IDC, Asset, Group
|
||||
from connect import PyCrypt, KEY
|
||||
|
||||
|
||||
def index(request):
|
||||
return render_to_response('jasset/jasset.html',)
|
||||
return render_to_response('jasset/jasset.html', )
|
||||
|
||||
|
||||
def jadd(request):
|
||||
global j_passwd
|
||||
groups = []
|
||||
cryptor = PyCrypt(KEY)
|
||||
eidc = IDC.objects.all()
|
||||
egroup = Group.objects.all()
|
||||
is_actived = {'active': 1, 'no_active': 0}
|
||||
login_typed = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
|
||||
|
||||
if request.method == 'POST':
|
||||
pass
|
||||
return render_to_response('jasset/jadd.html',)
|
||||
j_ip = request.POST.get('j_ip')
|
||||
j_idc = request.POST.get('j_idc')
|
||||
j_port = request.POST.get('j_port')
|
||||
j_type = request.POST.get('j_type')
|
||||
j_group = request.POST.getlist('j_group')
|
||||
j_active = request.POST.get('j_active')
|
||||
j_comment = request.POST.get('j_comment')
|
||||
if j_type == 'MAP':
|
||||
j_user = request.POST.get('j_user')
|
||||
j_password = cryptor.encrypt(request.POST.get('j_password'))
|
||||
j_root = request.POST.get('j_root')
|
||||
j_passwd = cryptor.encrypt(request.POST.get('j_passwd'))
|
||||
|
||||
j_idc = IDC.objects.get(name=j_idc)
|
||||
for group in j_group:
|
||||
c = Group.objects.get(name=group)
|
||||
groups.append(c)
|
||||
|
||||
if Asset.objects.filter(ip=str(j_ip)):
|
||||
emg = u'该IP已存在!'
|
||||
return render_to_response('jasset/jadd.html', {'emg': emg, 'j_ip': j_ip})
|
||||
|
||||
elif j_type == 'MAP':
|
||||
a = Asset(ip=j_ip,
|
||||
port=j_port,
|
||||
login_type=login_typed[j_type],
|
||||
idc=j_idc,
|
||||
is_active=int(is_actived[j_active]),
|
||||
comment=j_comment,
|
||||
username_common=j_user,
|
||||
password_common=j_password,
|
||||
username_super=j_root,
|
||||
password_super=j_passwd,)
|
||||
else:
|
||||
a = Asset(ip=j_ip,
|
||||
port=j_port,
|
||||
login_type=login_typed[j_type],
|
||||
idc=j_idc,
|
||||
is_active=int(is_actived[j_active]),
|
||||
comment=j_comment)
|
||||
a.save()
|
||||
a.group = groups
|
||||
a.save()
|
||||
|
||||
return render_to_response('jasset/jadd.html',
|
||||
{'header_title': u'添加主机 | Add Host',
|
||||
'path1': '资产管理',
|
||||
'path2': '添加主机',
|
||||
'eidc': eidc,
|
||||
'egroup': egroup, }
|
||||
)
|
||||
|
||||
|
||||
def jlist(request):
|
||||
posts = contact_list = Asset.objects.all().order_by('ip')
|
||||
print posts
|
||||
paginator = Paginator(contact_list, 5)
|
||||
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)
|
||||
|
||||
return render_to_response('jasset/jlist.html',
|
||||
{"contacts": contacts,
|
||||
'p': paginator,
|
||||
'posts': posts,
|
||||
'header_title': u'查看主机 | List Host',
|
||||
'path1': '资产管理',
|
||||
'path2': '查看主机', },
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def jadd_idc(request):
|
||||
pass
|
||||
|
||||
|
||||
def jlist_idc(request):
|
||||
pass
|
|
@ -111,7 +111,7 @@ USE_I18N = True
|
|||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
USE_TZ = False
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
|
|
|
@ -1,94 +1,122 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
<h1>添加主机</h1>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5>请在以下填写主机详细信息</h5>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<form method="get" class="form-horizontal">
|
||||
<div class="form-group"><label class="col-sm-2 control-label">IP地址</label>
|
||||
<div class="col-sm-10"><input type="text" placeholder="192.168.1.1" class="form-control"></div>
|
||||
{% 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> 填写主机基本信息 </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="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label">端口号</label>
|
||||
<div class="col-sm-10"><input type="text" placeholder="22" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 登录方式 </label>
|
||||
<div class="col-sm-10">
|
||||
<div class="radio i-checks"><label> <input type="radio" checked="" value="option1" name="a" onclick="show(this)"> <i> LDAP </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="option2" name="a" onclick="show(this)"> <i> SSH_KEY </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="option3" name="a" onclick="show(this)"> <i> SSH_PASSWORD </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="option4" name="a" onclick="show(this)"> <i> JUMPSER_MAP </i></label></div>
|
||||
<div class="ibox-content">
|
||||
{% if emg %}
|
||||
<div class="alert alert-warning text-center">{{ emg }}</div>
|
||||
{% endif %}
|
||||
<form method="post" class="form-horizontal">
|
||||
<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>
|
||||
|
||||
<div name="a1" id=a1 style="display:none;">
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户名 </label>
|
||||
<div class="col-sm-8"><input type="text" placeholder="lilei" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户密码 </label>
|
||||
<div class="col-sm-8"><input type="password" placeholder="Password" class="form-control" name="password"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 超管用户名 </label>
|
||||
<div class="col-sm-8"><input type="text" placeholder="root" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 超管用户密码 </label>
|
||||
<div class="col-sm-8"><input type="password" placeholder="Password" class="form-control" name="password"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 端口号 </label>
|
||||
<div class="col-sm-8"><input type="text" value="{{ s_port }}" placeholder="22" name="j_port" class="form-control"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 登录方式 </label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio i-checks"><label> <input type="radio" checked="" value="LDAP" name="j_type" onclick="show(this)"> <i> LDAP </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="SSH_KEY" name="j_type" onclick="show(this)"> <i> SSH_KEY </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="PASSWORD" name="j_type" onclick="show(this)"> <i> PASSWORD </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="MAP" name="j_type" onclick="show(this)"> <i> MAP </i></label></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 所属IDC </label>
|
||||
<div class="col-sm-10"><input type="text" placeholder="北京联通" class="form-control"></div>
|
||||
</div>
|
||||
<div name="a1" id=a1 style="display:none;">
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户名 </label>
|
||||
<div class="col-sm-6"><input type="text" value="{{ j_user }}" name="j_user" placeholder="lilei" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 所属业务组 </label>
|
||||
<div class="col-sm-10"><input type="text" placeholder="数据库" class="form-control"></div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户密码 </label>
|
||||
<div class="col-sm-6"><input type="password" value="{{ j_password }}" name="j_password" placeholder="Password" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活 </label>
|
||||
<div class="col-sm-10">
|
||||
<div class="radio i-checks"><label> <input type="radio" checked="" value="o1" name="b"> <i> 激活 </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="o2" name="b"> <i> 禁用 </i></label></div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 超管用户名 </label>
|
||||
<div class="col-sm-6"><input type="text" value="{{ j_root }}" name="j_root" placeholder="root" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 超管用户密码 </label>
|
||||
<div class="col-sm-6"><input type="password" value="{{ j_passwd }}" name="j_passwd" placeholder="Password" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 密码 </label>
|
||||
<div class="col-sm-10"><input type="password" placeholder="Password" class="form-control" name="password"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
|
||||
<div class="col-sm-10"><input type="text" placeholder="hadoop01" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-5">
|
||||
<button class="btn btn-white" type="submit"> 重置 </button>
|
||||
<button class="btn btn-primary" type="submit"> 提交 </button>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_idc" class="col-lg-2 control-label"> 所属IDC </label>
|
||||
<div class="col-sm-8">
|
||||
<select id="j_idc" name="j_idc" class="form-control m-b">
|
||||
{% for i in eidc %}
|
||||
<option> {{ i }} </option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_group" class="col-sm-2 control-label"> 所属业务组 </label>
|
||||
<div class="col-sm-8">
|
||||
{% for g in egroup %}
|
||||
<label class="checkbox-inline"><input type="checkbox" id="j_group" value="{{ g }}" name="j_group"> {{ g }} </label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活 </label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio i-checks"><label> <input type="radio" checked="" value="active" name="j_active"> <i> 激活 </i></label></div>
|
||||
<div class="radio i-checks"><label> <input type="radio" value="no_active" name="j_active"> <i> 禁用 </i></label></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
|
||||
<div class="col-sm-8"><input type="text" placeholder="hadoop01" name="j_comment" class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-5">
|
||||
<button class="btn btn-white" type="submit"> 重置 </button>
|
||||
<button class="btn btn-primary" type="submit"> 提交 </button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -101,7 +129,7 @@
|
|||
var showFlag={};
|
||||
function show(o){
|
||||
showFlag[o.name]=o.value;
|
||||
if(showFlag.a=="option4"){
|
||||
if(showFlag.j_type=="MAP"){
|
||||
document.getElementById("a1").style.display="";
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
{% extends 'base.html' %}
|
||||
{% 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> 主机详细信息列表 </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">
|
||||
<div class="">
|
||||
<a onclick="fnClickAddRow();" href="javascript:void(0);" class="btn btn-primary "> 添加 </a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-bordered table-hover " id="editable" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th> IP地址 </th>
|
||||
<th> 端口号 </th>
|
||||
<th> 登录方式 </th>
|
||||
<th> 所属IDC </th>
|
||||
<th> 所属业务组 </th>
|
||||
<th> 添加时间 </th>
|
||||
<th> 备注 </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for post in contacts.object_list %}
|
||||
<tr class="gradeX">
|
||||
<td> {{ post.ip }} </td>
|
||||
<td> {{ post.port }} </td>
|
||||
<td> {{ post.login_type}} </td>
|
||||
<td class="center"> {{ post.idc.name }} </td>
|
||||
<td class="center">
|
||||
{% for group in post.group.all %}
|
||||
{{ group }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="center"> {{ post.date_added }} </td>
|
||||
<td class="center"> {{ post.comment }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<ul class="pagination">
|
||||
{% if contacts.has_previous %}
|
||||
<li><a href="?page={{ contacts.previous_page_number }}">«</a></li>
|
||||
{% endif %}
|
||||
|
||||
{% for page in p.page_range %}
|
||||
{% ifequal offset1 page %}
|
||||
<li class="active"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
|
||||
{% else %}
|
||||
<li><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
{% if contacts.has_next %}
|
||||
<li><a href="?page={{ contacts.next_page_number }}">»</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -101,7 +101,7 @@
|
|||
<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">确认保存</button>
|
||||
<button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -110,4 +110,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -23,7 +23,7 @@
|
|||
<li>
|
||||
<a href="mailbox.html"><i class="fa fa-cube"></i> <span class="nav-label">资产管理</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li><a href="/asset/showlist/">查看资产</a></li>
|
||||
<li><a href="/jasset/jlist/">查看资产</a></li>
|
||||
<li><a href="/jasset/jadd/">添加资产</a></li>
|
||||
<li><a href="/idc/showlist/">查看机房</a></li>
|
||||
<li><a href="/idc/add/">添加机房</a></li>
|
||||
|
|
Loading…
Reference in New Issue