mirror of
https://github.com/RobbieHan/sandboxMP.git
synced 2026-04-08 21:31:30 +08:00
natrule
This commit is contained in:
986
.idea/workspace.xml
generated
986
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@
|
||||
|
||||
from django import forms
|
||||
|
||||
from .models import Code, DeviceInfo, ConnectionInfo, DeviceFile, NetworkAsset
|
||||
from .models import Code, DeviceInfo, ConnectionInfo, DeviceFile, NetworkAsset, NatRule
|
||||
|
||||
|
||||
class CodeCreateForm(forms.ModelForm):
|
||||
@@ -127,4 +127,16 @@ class NetworkAssetUpdateForm(NetworkAssetCreateForm):
|
||||
if self.instance:
|
||||
matching_asset = NetworkAsset.objects.exclude(pk=self.instance.pk)
|
||||
if matching_asset.filter(ip_address=ip_address).exists():
|
||||
raise forms.ValidationError('资产地址已存在:{}已存在'.format(ip_address))
|
||||
raise forms.ValidationError('资产地址已存在:{}已存在'.format(ip_address))
|
||||
|
||||
|
||||
class NatRuleForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = NatRule
|
||||
fields = '__all__'
|
||||
error_messages = {
|
||||
'internet_ip': {'required': '请填写公网IP'},
|
||||
'src_port': {'required': '请填写公网端口'},
|
||||
'lan_ip': {'required': '请填写内网地址'},
|
||||
'dest_port': {'required': '请填写内网端口'}
|
||||
}
|
||||
|
||||
@@ -148,12 +148,13 @@ class NetworkAsset(models.Model):
|
||||
|
||||
|
||||
class NatRule(models.Model):
|
||||
internet_ip = models.CharField(max_length=80, blank=True, default='', verbose_name='互联网IP')
|
||||
src_port = models.IntegerField(blank=True, default='', verbose_name='源端口')
|
||||
lan_ip = models.CharField(max_length=80, blank=True, default='', verbose_name='内网IP')
|
||||
dest_port = models.IntegerField(blank=True, default='', verbose_name='目的端口')
|
||||
internet_ip = models.CharField(max_length=80, verbose_name='互联网IP')
|
||||
src_port = models.IntegerField(verbose_name='源端口')
|
||||
lan_ip = models.CharField(max_length=80, verbose_name='内网IP')
|
||||
dest_port = models.IntegerField(verbose_name='目的端口')
|
||||
state = models.BooleanField(default=True, verbose_name='状态')
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
dev_cabinet = models.ForeignKey('Cabinet', blank=True, default='', on_delete=models.SET_DEFAULT, verbose_name='机柜信息')
|
||||
desc = models.CharField(max_length=100, verbose_name='规则说明')
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'NAT规则'
|
||||
@@ -164,14 +165,12 @@ class DomainName(AbstractMode):
|
||||
dn_type_choices = (('1', '主域名'),('2', '二级域名'))
|
||||
domain = models.CharField(max_length=200, verbose_name='域名')
|
||||
dn_type = models.CharField(max_length=20, choices=dn_type_choices, default='1')
|
||||
addr_resolution = models.ForeignKey('NatRule', blank=True, null=True,
|
||||
on_delete=models.SET_NULL, verbose_name='解析地址')
|
||||
resolution_server = models.ForeignKey('Supplier', related_name='res_server',
|
||||
blank=True, null=True, on_delete=models.SET_NULL, verbose_name='解析服务')
|
||||
domain_provider = models.ForeignKey('Supplier', related_name='do_provider',
|
||||
blank=True, null=True, on_delete=models.SET_NULL, verbose_name='解析服务')
|
||||
blank=True, null=True, on_delete=models.SET_NULL, verbose_name='域名服务')
|
||||
state = models.BooleanField(default=True, verbose_name='状态')
|
||||
ssl = models.FileField(upload_to="ssl_file/%Y/%m", null=True, blank=True, verbose_name="SSL证书")
|
||||
ssl_cert = models.FileField(upload_to="ssl_cert/%Y/%m", null=True, blank=True, verbose_name="SSL证书")
|
||||
buyDate = models.DateField(default=datetime.now, blank=True, null=True, verbose_name='购买日期')
|
||||
warrantyDate = models.DateField(default=datetime.now, blank=True, null=True, verbose_name='到保日期')
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
@@ -181,3 +180,5 @@ class DomainName(AbstractMode):
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,4 +50,10 @@ urlpatterns = [
|
||||
path('eam/network_asset/update/', views_eam.NetworkAssetUpdateView.as_view(), name='eam-network_asset-update'),
|
||||
path('eam/network_asset/list/', views_eam.NetworkAssetListView.as_view(), name='eam-network_asset-list'),
|
||||
path('eam/network_asset/delete/', views_eam.NetworkAssetDeleteView.as_view(), name='eam-network_asset-delete'),
|
||||
|
||||
path('eam/natrule/', views_eam.NatRuleView.as_view(), name='eam-natrule'),
|
||||
path('eam/natrule/create/', views_eam.NatRuleCreateView.as_view(), name='eam-natrule-create'),
|
||||
path('eam/natrule/update/', views_eam.NatRuleUpdateView.as_view(), name='eam-natrule-update'),
|
||||
path('eam/natrule/list/', views_eam.NatRuleListView.as_view(), name='eam-natrule-list'),
|
||||
path('eam/natrule/delete/', views_eam.NatRuleDeleteView.as_view(), name='eam-natrule-delete'),
|
||||
]
|
||||
|
||||
@@ -11,9 +11,10 @@ from system.mixin import LoginRequiredMixin
|
||||
from custom import (BreadcrumbMixin, SandboxDeleteView,
|
||||
SandboxListView, SandboxUpdateView, SandboxCreateView)
|
||||
from .models import (Cabinet, DeviceInfo, Code, ConnectionInfo, DeviceFile,
|
||||
Supplier, NetworkAsset)
|
||||
Supplier, NetworkAsset, NatRule, DomainName)
|
||||
from .forms import (DeviceCreateForm, DeviceUpdateForm, ConnectionInfoForm,
|
||||
DeviceFileUploadForm, NetworkAssetCreateForm, NetworkAssetUpdateForm)
|
||||
DeviceFileUploadForm, NetworkAssetCreateForm,
|
||||
NetworkAssetUpdateForm,NatRuleForm)
|
||||
from utils.db_utils import MongodbDriver
|
||||
from utils.sandbox_utils import LoginExecution
|
||||
|
||||
@@ -314,3 +315,97 @@ class NetworkAssetListView(SandboxListView):
|
||||
class NetworkAssetDeleteView(SandboxDeleteView):
|
||||
model = NetworkAsset
|
||||
|
||||
|
||||
class NatRuleView(LoginRequiredMixin, BreadcrumbMixin, TemplateView):
|
||||
template_name = 'cmdb/natrule.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['all_cabinet'] = Cabinet.objects.all()
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class NatRuleCreateView(SandboxCreateView):
|
||||
model = NatRule
|
||||
form_class = NatRuleForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['all_cabinet'] = Cabinet.objects.all()
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class NatRuleUpdateView(SandboxUpdateView):
|
||||
model = NatRule
|
||||
form_class = NatRuleForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['all_cabinet'] = Cabinet.objects.all()
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class NatRuleListView(SandboxListView):
|
||||
model = NatRule
|
||||
fields = ['id', 'internet_ip', 'src_port', 'lan_ip', 'dest_port', 'state', 'dev_cabinet__number', 'desc']
|
||||
|
||||
def get_filters(self):
|
||||
data = self.request.GET
|
||||
filters = {}
|
||||
if 'internet_ip' in data and data['internet_ip']:
|
||||
filters['internet_ip__icontains'] = data['internet_ip']
|
||||
if 'src_port' in data and data['src_port']:
|
||||
filters['src_port'] = data['src_port']
|
||||
if 'lan_ip' in data and data['lan_ip']:
|
||||
filters['lan_ip__icontains'] = data['lan_ip']
|
||||
if 'dest_port' in data and data['dest_port']:
|
||||
filters['dest_port'] = data['dest_port']
|
||||
if 'dev_cabinet' in data and data['dev_cabinet']:
|
||||
filters['dev_cabinet'] = data['dev_cabinet']
|
||||
if 'desc' in data and data['desc']:
|
||||
filters['desc__icontains'] = data['desc']
|
||||
return filters
|
||||
|
||||
|
||||
class NatRuleDeleteView(SandboxDeleteView):
|
||||
model = NatRule
|
||||
|
||||
|
||||
# class DomainNameView(LoginRequiredMixin, BreadcrumbMixin, TemplateView):
|
||||
# template_name = 'cmdb/domainname.html'
|
||||
#
|
||||
#
|
||||
# class DomainNameCreateView(SandboxCreateView):
|
||||
# model = DomainName
|
||||
# form_class = NetworkAssetCreateForm
|
||||
#
|
||||
# def get_context_data(self, **kwargs):
|
||||
# kwargs['all_supplier'] = Supplier.objects.all()
|
||||
# return super().get_context_data(**kwargs)
|
||||
#
|
||||
#
|
||||
# class DomainNameUpdateView(SandboxUpdateView):
|
||||
# model = NetworkAsset
|
||||
# form_class = NetworkAssetUpdateForm
|
||||
#
|
||||
# def get_context_data(self, **kwargs):
|
||||
# kwargs['all_provider'] = Supplier.objects.all()
|
||||
# return super().get_context_data(**kwargs)
|
||||
#
|
||||
#
|
||||
# class DomainNameListView(SandboxListView):
|
||||
# model = NetworkAsset
|
||||
# fields = ['id', 'domain', 'resolution_server', 'domain_provider', 'state', 'buyDate', 'warrantyDate', 'desc']
|
||||
#
|
||||
# def get_filters(self):
|
||||
# data = self.request.GET
|
||||
# filters = {'dn_type': '1'}
|
||||
# if 'domain' in data and data['domain']:
|
||||
# filters['domain__icontains'] = data['domain']
|
||||
# if 'resolution_server' in data and data['resolution_server']:
|
||||
# filters['resolution_server'] = data['resolution_server']
|
||||
# if 'domain_provider' in data and data['domain_provider']:
|
||||
# filters['domain_provider'] = data['domain_provider']
|
||||
#
|
||||
# return filters
|
||||
#
|
||||
#
|
||||
# class DomainNameDeleteView(SandboxDeleteView):
|
||||
# model = DomainName
|
||||
359
templates/cmdb/domainname.html
Normal file
359
templates/cmdb/domainname.html
Normal file
@@ -0,0 +1,359 @@
|
||||
{% extends "base-left.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/datatables/jquery.dataTables.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div id="devlist">
|
||||
<div class="box box-primary" id="liebiao">
|
||||
<div class="box-header">
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnRefresh" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-repeat"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnCreate" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-plus"></i>新增
|
||||
</button>
|
||||
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnDelete" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-trash"></i>删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-header">
|
||||
<form class="form-inline" id="queryForm">
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>主机名:</label>
|
||||
<input type="text" name="sys_hostname" class="form-control inputText" id="sys_hostname">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>设备地址:</label>
|
||||
<input type="text" name="hostname" class="form-control inputText" id="hostname">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>网络类型:</label>
|
||||
<select class="form-control inputText select2" name="network_type" id="network_type">
|
||||
<option></option>
|
||||
{% for code in all_code %}
|
||||
{% ifequal code.parent.key 'NETWORK_TYPE' %}
|
||||
<option value="{{ code.id }}">{{ code.value }}</option>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>服务类型:</label>
|
||||
<select class="form-control inputText select2" name="service_type" , id="service_type">
|
||||
<option></option>
|
||||
{% for code in all_code %}
|
||||
{% if code.parent.key == 'SERVICE_TYPE' %}
|
||||
<option value="{{ code.id }}">{{ code.value }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>所属项目:</label>
|
||||
<select class="form-control inputText select2" name="operation_type" , id="operation_type">
|
||||
<option></option>
|
||||
{% for code in all_code %}
|
||||
{% if code.parent.key == 'OPERATION_TYPE' %}
|
||||
<option value="{{ code.id }}">{{ code.value }}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>机柜信息:</label>
|
||||
<select class="form-control inputText select2" name="dev_cabinet" , id="dev_cabinet">
|
||||
<option></option>
|
||||
{% for cabinet in all_cabinet %}
|
||||
|
||||
<option value="{{ cabinet.id }}">{{ cabinet.number }}</option>
|
||||
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button type="button" id="btnSearch" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-search"></i>查询
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<table id="dtbList" class="display" cellspacing="0" width="100%">
|
||||
<thead>
|
||||
<tr valign="middle">
|
||||
<th><input type="checkbox" id="checkAll"></th>
|
||||
<th>ID</th>
|
||||
<th>主机名</th>
|
||||
<th>IP地址</th>
|
||||
<th>服务类型</th>
|
||||
<th>所属项目</th>
|
||||
<th>配置信息</th>
|
||||
<th>机柜信息</th>
|
||||
<th>网络类型</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<br> <br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- /.content -->
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block javascripts %}
|
||||
|
||||
<script src="{% static 'plugins/datatables/jquery.dataTables.min.js' %}"></script>
|
||||
<script src="{% static 'plugins/datatables/dataTables.const-1.js' %}"></script>
|
||||
<script src="{% static 'js/plugins/layer/layer.js' %}"></script>
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
// 菜单选中高亮
|
||||
$(function () {
|
||||
$('#CMDB-EAM').addClass('active');
|
||||
$('#CMDB-EAM-DEVICE').addClass('active');
|
||||
|
||||
});
|
||||
|
||||
// datatables 初始化配置
|
||||
var oDataTable = null;
|
||||
$(function () {
|
||||
oDataTable = initTable();
|
||||
|
||||
function initTable() {
|
||||
var oTable = $('#dtbList').DataTable($.extend(true, {},
|
||||
DATATABLES_CONSTANT.DATA_TABLES.SERVER_SIDE_OPTION,
|
||||
|
||||
{
|
||||
ajax: {
|
||||
"url": "{% url 'cmdb:eam-device-list' %}",
|
||||
"data": function (d) {
|
||||
d.sys_hostname = $("#sys_hostname").val();
|
||||
d.hostname = $("#hostname").val();
|
||||
d.network_type = $("#network_type").val();
|
||||
d.service_type = $("#service_type").val();
|
||||
d.operation_type = $("#operation_type").val();
|
||||
d.dev_cabinet = $("#dev_cabinet").val();
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
DATATABLES_CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
|
||||
|
||||
{
|
||||
data: "id",
|
||||
},
|
||||
{
|
||||
data: "sys_hostname",
|
||||
},
|
||||
{
|
||||
data: "hostname",
|
||||
},
|
||||
{
|
||||
data: "service_type",
|
||||
},
|
||||
{
|
||||
data: "operation_type",
|
||||
},
|
||||
{
|
||||
data: "config",
|
||||
},
|
||||
{
|
||||
data: "dev_cabinet",
|
||||
},
|
||||
{
|
||||
data: "network_type",
|
||||
},
|
||||
{
|
||||
data: "id",
|
||||
bSortable: "false",
|
||||
render: function (data, type, row, meta) {
|
||||
var ret = "<button title='详情' onclick='doDetail("
|
||||
+ data + ")'><i class='glyphicon glyphicon-list-alt'></i></button>";
|
||||
ret = ret + "<button title='修改' onclick='doUpdate("
|
||||
+ data + ")'><i class='glyphicon glyphicon-pencil'></i></button>";
|
||||
ret = ret + "<button title='认证管理' onclick='doDevice2Connection("
|
||||
+ data + ")'><i class='glyphicon glyphicon-user'></i></button>";
|
||||
ret = ret + "<button title='删除' onclick='doDelete("
|
||||
+ data + ")'><i class='glyphicon glyphicon-trash'></i></button>";
|
||||
return ret;
|
||||
}
|
||||
}],
|
||||
}));
|
||||
return oTable;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 刷新数据
|
||||
$("#btnRefresh").click(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
//新建数据
|
||||
$("#btnCreate").click(function () {
|
||||
var div=layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: "{% url 'cmdb:eam-device-create' %}",
|
||||
end: function () {
|
||||
//关闭时做的事情
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
layer.full(div )
|
||||
});
|
||||
|
||||
//修改数据
|
||||
function doUpdate(id) {
|
||||
var div=layer.open({
|
||||
type: 2,
|
||||
title: '编辑',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: ["{% url 'cmdb:eam-device-update' %}" + '?id=' + id, 'no'],
|
||||
end: function () {
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
layer.full(div )
|
||||
}
|
||||
|
||||
//checkbox全选
|
||||
$("#checkAll").on("click", function () {
|
||||
if ($(this).prop("checked") === true) {
|
||||
$("input[name='checkList']").prop("checked", $(this).prop("checked"));
|
||||
$('#example tbody tr').addClass('selected');
|
||||
} else {
|
||||
$("input[name='checkList']").prop("checked", false);
|
||||
$('#example tbody tr').removeClass('selected');
|
||||
}
|
||||
});
|
||||
|
||||
//批量删除
|
||||
$("#btnDelete").click(function () {
|
||||
if ($("input[name='checkList']:checked").length == 0) {
|
||||
layer.msg("请选择要删除的记录");
|
||||
return;
|
||||
}
|
||||
|
||||
var arrId = new Array();
|
||||
$("input[name='checkList']:checked").each(function () {
|
||||
//alert($(this).val());
|
||||
arrId.push($(this).val());
|
||||
});
|
||||
|
||||
sId = arrId.join(',');
|
||||
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-device-delete' %}",
|
||||
data: {"id": sId, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert("操作成功", {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert("操作失败", {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//删除单个数据
|
||||
function doDelete(id) {
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-device-delete' %}",
|
||||
data: {"id": id, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('删除成功', {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert('删除失败', {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
$("#btnSearch").click(function(){
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
|
||||
|
||||
function doDevice2Connection(id) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '认证管理',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: ["{% url 'cmdb:eam-device-device2connection' %}" + '?id=' + id, 'no'],
|
||||
end: function () {
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function doDetail(id){
|
||||
window.location.href="{% url 'cmdb:eam-device-detail' %}?id="+id;
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
325
templates/cmdb/natrule.html
Normal file
325
templates/cmdb/natrule.html
Normal file
@@ -0,0 +1,325 @@
|
||||
{% extends "base-left.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/datatables/jquery.dataTables.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div id="devlist">
|
||||
<div class="box box-primary" id="liebiao">
|
||||
<div class="box-header">
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnRefresh" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-repeat"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnCreate" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-plus"></i>新增
|
||||
</button>
|
||||
|
||||
</div>
|
||||
<div class="btn-group pull-left"> </div>
|
||||
<div class="btn-group pull-left">
|
||||
<button type="button" id="btnDelete" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-trash"></i>删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-header">
|
||||
<form class="form-inline" id="queryForm">
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>公网IP:</label>
|
||||
<input type="text" name="internet_ip" class="form-control inputText" id="internet_ip">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>源端口:</label>
|
||||
<input type="text" name="src_port" class="form-control inputText" id="src_port">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>内网IP:</label>
|
||||
<input type="text" name="lan_ip" class="form-control inputText" id="lan_ip">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>目的端口:</label>
|
||||
<input type="text" name="dest_port" class="form-control inputText" id="dest_port">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>规则说明:</label>
|
||||
<input type="text" name="desc" class="form-control inputText" id="desc">
|
||||
</div>
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>机柜信息:</label>
|
||||
<select class="form-control inputText select2" name="dev_cabinet" , id="dev_cabinet">
|
||||
<option></option>
|
||||
{% for cabinet in all_cabinet %}
|
||||
|
||||
<option value="{{ cabinet.id }}">{{ cabinet.number }}</option>
|
||||
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button type="button" id="btnSearch" class="btn btn-default">
|
||||
<i class="glyphicon glyphicon-search"></i>查询
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="box-body">
|
||||
<table id="dtbList" class="display" cellspacing="0" width="100%">
|
||||
<thead>
|
||||
<tr valign="middle">
|
||||
<th><input type="checkbox" id="checkAll"></th>
|
||||
<th>ID</th>
|
||||
<th>互联网IP</th>
|
||||
<th>源端口</th>
|
||||
<th>内网IP</th>
|
||||
<th>目的端口</th>
|
||||
<th>状态</th>
|
||||
<th>机柜信息</th>
|
||||
<th>规则说明</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
<br> <br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- /.content -->
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block javascripts %}
|
||||
|
||||
<script src="{% static 'plugins/datatables/jquery.dataTables.min.js' %}"></script>
|
||||
<script src="{% static 'plugins/datatables/dataTables.const-1.js' %}"></script>
|
||||
<script src="{% static 'js/plugins/layer/layer.js' %}"></script>
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
// 菜单选中高亮
|
||||
$(function () {
|
||||
$('#CMDB-EAM').addClass('active');
|
||||
$('#CMDB-EAM-NATRULE').addClass('active');
|
||||
|
||||
});
|
||||
|
||||
// datatables 初始化配置
|
||||
var oDataTable = null;
|
||||
$(function () {
|
||||
oDataTable = initTable();
|
||||
|
||||
function initTable() {
|
||||
var oTable = $('#dtbList').DataTable($.extend(true, {},
|
||||
DATATABLES_CONSTANT.DATA_TABLES.SERVER_SIDE_OPTION,
|
||||
|
||||
{
|
||||
ajax: {
|
||||
"url": "{% url 'cmdb:eam-natrule-list' %}",
|
||||
"data": function (d) {
|
||||
d.internet_ip = $("#internet_ip").val();
|
||||
d.src_port = $("#src_port").val();
|
||||
d.lan_ip = $("#lan_ip").val();
|
||||
d.dest_port = $("#dest_port").val();
|
||||
d.dev_cabinet = $("#dev_cabinet").val();
|
||||
d.desc = $("#desc").val();
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
DATATABLES_CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
|
||||
|
||||
{
|
||||
data: "id",
|
||||
},
|
||||
{
|
||||
data: "internet_ip",
|
||||
},
|
||||
{
|
||||
data: "src_port",
|
||||
},
|
||||
{
|
||||
data: "lan_ip",
|
||||
},
|
||||
{
|
||||
data: "dest_port",
|
||||
},
|
||||
{
|
||||
data: "state",
|
||||
render : function(data, type, row, meta) {
|
||||
if (data==1) {
|
||||
var ret="<button class='btn btn-success btn-xs'>在用</button>";
|
||||
return ret;
|
||||
}if (data==0) {
|
||||
var ret="<button class='btn btn-warning btn-xs'>停用</button>";
|
||||
return ret;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
data: "dev_cabinet__number",
|
||||
},
|
||||
{
|
||||
data: "desc",
|
||||
},
|
||||
{
|
||||
data: "id",
|
||||
bSortable: "false",
|
||||
render: function (data, type, row, meta) {
|
||||
var ret = "<button title='详情-修改' onclick='doUpdate("
|
||||
+ data + ")'><i class='glyphicon glyphicon-pencil'></i></button>";
|
||||
ret = ret + "<button title='删除' onclick='doDelete("
|
||||
+ data + ")'><i class='glyphicon glyphicon-trash'></i></button>";
|
||||
return ret;
|
||||
}
|
||||
}],
|
||||
}));
|
||||
return oTable;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 刷新数据
|
||||
$("#btnRefresh").click(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
//新建数据
|
||||
$("#btnCreate").click(function () {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '500px'],
|
||||
content: "{% url 'cmdb:eam-natrule-create' %}",
|
||||
end: function () {
|
||||
//关闭时做的事情
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//修改数据
|
||||
function doUpdate(id) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '500px'],
|
||||
content: ["{% url 'cmdb:eam-natrule-update' %}" + '?id=' + id, 'no'],
|
||||
end: function () {
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//checkbox全选
|
||||
$("#checkAll").on("click", function () {
|
||||
if ($(this).prop("checked") === true) {
|
||||
$("input[name='checkList']").prop("checked", $(this).prop("checked"));
|
||||
$('#example tbody tr').addClass('selected');
|
||||
} else {
|
||||
$("input[name='checkList']").prop("checked", false);
|
||||
$('#example tbody tr').removeClass('selected');
|
||||
}
|
||||
});
|
||||
|
||||
//批量删除
|
||||
$("#btnDelete").click(function () {
|
||||
if ($("input[name='checkList']:checked").length == 0) {
|
||||
layer.msg("请选择要删除的记录");
|
||||
return;
|
||||
}
|
||||
|
||||
var arrId = new Array();
|
||||
$("input[name='checkList']:checked").each(function () {
|
||||
//alert($(this).val());
|
||||
arrId.push($(this).val());
|
||||
});
|
||||
|
||||
sId = arrId.join(',');
|
||||
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-natrule-delete' %}",
|
||||
data: {"id": sId, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert("操作成功", {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert("操作失败", {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//删除单个数据
|
||||
function doDelete(id) {
|
||||
layer.alert('确定删除吗?', {
|
||||
title: '提示'
|
||||
, icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸
|
||||
, time: 0 //不自动关闭
|
||||
, btn: ['YES', 'NO']
|
||||
, yes: function (index) {
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "{% url 'cmdb:eam-natrule-delete' %}",
|
||||
data: {"id": id, csrfmiddlewaretoken: '{{ csrf_token }}'},
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('删除成功', {icon: 1});
|
||||
oDataTable.ajax.reload();
|
||||
} else {
|
||||
//alert(msg.message);
|
||||
layer.alert('删除失败', {icon: 2});
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
$("#btnSearch").click(function(){
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
152
templates/cmdb/natrule_form.html
Normal file
152
templates/cmdb/natrule_form.html
Normal file
@@ -0,0 +1,152 @@
|
||||
{% extends 'base-layer.html' %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{%static 'plugins/select2/select2.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap-datetimepicker.min.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div class="box box-danger">
|
||||
<form class="form-horizontal" id="addForm" method="post">
|
||||
<input type="hidden" name='id' value="{{ natrule.id }}" />
|
||||
{% csrf_token %}
|
||||
<div class="box-body">
|
||||
<fieldset>
|
||||
<legend>
|
||||
</legend>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">互联网IP</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="internet_ip" type="text" value="{{ natrule.internet_ip }}" />
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">源端口</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="src_port" type="text" value="{{ natrule.src_port }}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">内网地址</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="lan_ip" type="text" value="{{ natrule.lan_ip}}" />
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">目的端口</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="dest_port" type="text" value="{{ natrule.dest_port }}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">机柜信息</label>
|
||||
<div class="col-sm-3">
|
||||
<select class="form-control select2" style="width:100%;" name="dev_cabinet">
|
||||
<option {% ifequal deviceinfo.dev_cabinet '' %}selected="selected"{% endifequal %}></option>
|
||||
{% for cabinet in all_cabinet %}
|
||||
<option value="{{ cabinet.id }}" {% ifequal natrule.dev_cabinet.id cabinet.id %}selected="selected"{% endifequal %}>
|
||||
{{ cabinet.number }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">状态</label>
|
||||
<div class="col-sm-3">
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="state" value="True"
|
||||
{% ifequal natrule.state 1 %}checked{% endifequal %}
|
||||
{% if not natrule %}checked{% endif %}> 在用
|
||||
</label>
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="state" value="False"
|
||||
{% ifequal natrule.state 0 %}checked{% endifequal %}> 停用
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">规则说明</label>
|
||||
<div class="col-sm-8">
|
||||
<textarea class="form-control" name="desc" rows="5" >{{ natrule.desc }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="box-footer ">
|
||||
<div class="row span7 text-center ">
|
||||
<button type="button" id="btnCancel" class="btn btn-default margin-right " >重置</button>
|
||||
<button type="button" id="btnSave" class="btn btn-info margin-right " >保存</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
<script src="{% static 'plugins/select2/select2.full.min.js' %}"></script>
|
||||
<script src="{% static 'bootstrap/js/bootstrap-datetimepicker.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function getUrl() {
|
||||
if ($("input[name='id']").val()) {
|
||||
var url = "{% url 'cmdb:eam-natrule-update' %}";
|
||||
} else {
|
||||
var url = "{% url 'cmdb:eam-natrule-create' %}";
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
$("#btnSave").click(function () {
|
||||
var data = $("#addForm").serialize();
|
||||
$.ajax({
|
||||
type: $("#addForm").attr('method'),
|
||||
url: getUrl(),
|
||||
data: data,
|
||||
cache: false,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('数据保存成功!', {icon: 1}, function (index) {
|
||||
parent.layer.closeAll(); //关闭所有弹窗
|
||||
});
|
||||
} else {
|
||||
layer.alert(msg.error, {icon: 5});
|
||||
//$('errorMessage').html(msg.message)
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*点取消刷新新页面*/
|
||||
$("#btnCancel").click(function () {
|
||||
window.location.reload();
|
||||
|
||||
})
|
||||
|
||||
|
||||
/*input 时间输入选择*/
|
||||
$(".form_datetime").datetimepicker({
|
||||
language: 'zh',
|
||||
minView: 'month', //选择范围知道日期,不选择时分
|
||||
//weekStart: 1,
|
||||
//todayBtn: 1,
|
||||
autoclose: 1,
|
||||
todayHighlight: 1,
|
||||
//startView: 2,
|
||||
forceParse: 0,
|
||||
showMeridian: 1,
|
||||
format: 'yyyy-mm-dd'
|
||||
}).on('changeDate', function (ev) {
|
||||
$(this).datetimepicker('hide');
|
||||
});
|
||||
|
||||
// select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
@@ -145,10 +145,10 @@
|
||||
{
|
||||
data: "state",
|
||||
render : function(data, type, row, meta) {
|
||||
if (data=true) {
|
||||
if (data==1) {
|
||||
var ret="<button class='btn btn-success btn-xs'>在用</button>";
|
||||
return ret;
|
||||
}if (data=false) {
|
||||
}if (data==0) {
|
||||
var ret="<button class='btn btn-warning btn-xs'>停用</button>";
|
||||
return ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user