mirror of
https://github.com/RobbieHan/sandboxMP.git
synced 2026-02-03 10:53:15 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
371b1ebbe3 | ||
|
|
9d0bd95b69 | ||
|
|
4fbdc88743 | ||
|
|
860ae14d4c |
@@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class CmdbConfig(AppConfig):
|
||||
name = 'cmdb'
|
||||
name = 'cmdb'
|
||||
46
apps/cmdb/forms.py
Normal file
46
apps/cmdb/forms.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# @Time : 2018/12/19 16:13
|
||||
# @Author : RobbieHan
|
||||
# @File : forms.py
|
||||
|
||||
from django import forms
|
||||
|
||||
from .models import Code
|
||||
|
||||
|
||||
class CodeCreateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Code
|
||||
fields = '__all__'
|
||||
|
||||
error_messages = {
|
||||
'key': {'required': 'key不能为空'},
|
||||
'value': {'required': 'value不能为空'}
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(CodeCreateForm, self).clean()
|
||||
key = cleaned_data.get('key')
|
||||
value = cleaned_data.get('value')
|
||||
|
||||
if Code.objects.filter(key=key).count():
|
||||
raise forms.ValidationError('key:{}已存在'.format(key))
|
||||
|
||||
if Code.objects.filter(value=value).count():
|
||||
raise forms.ValidationError('value: {}已存在'.format(value))
|
||||
|
||||
|
||||
class CodeUpdateForm(CodeCreateForm):
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = self.cleaned_data
|
||||
key = cleaned_data.get('key')
|
||||
value = cleaned_data.get('value')
|
||||
|
||||
if self.instance:
|
||||
matching_code = Code.objects.exclude(pk=self.instance.pk)
|
||||
if matching_code.filter(key=key).exists():
|
||||
msg = 'key:{} 已经存在'.format(key)
|
||||
raise forms.ValidationError(msg)
|
||||
if matching_code.filter(value=value).exists():
|
||||
msg = 'value:{} 已经存在'.format(value)
|
||||
raise forms.ValidationError(msg)
|
||||
@@ -1,6 +1,11 @@
|
||||
from django.db import models
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# Create your models here.
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.dispatch import receiver
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class AbstractMode(models.Model):
|
||||
@@ -20,3 +25,94 @@ class Code(AbstractMode):
|
||||
class Meta:
|
||||
verbose_name = '字典'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class TimeAbstract(models.Model):
|
||||
add_time = models.DateTimeField(auto_now_add=True, verbose_name="添加时间")
|
||||
modify_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class ConnectionAbstract(models.Model):
|
||||
auth_method_choices = (
|
||||
('private_key', '密钥认证'),
|
||||
('password', '密码认证')
|
||||
)
|
||||
hostname = models.CharField(max_length=50, verbose_name='设备地址(IP或域名)')
|
||||
port = models.IntegerField(default=22, verbose_name='SSH端口')
|
||||
username = models.CharField(max_length=15, blank=True, default='', verbose_name='SSH用户名')
|
||||
password = models.CharField(max_length=80, blank=True, default='', verbose_name='SSH密码')
|
||||
private_key = models.CharField(max_length=100, blank=True, default='', verbose_name='密钥路径')
|
||||
auth_type = models.CharField(max_length=30, choices=auth_method_choices, default='')
|
||||
status = models.CharField(max_length=10, blank=True, default='')
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class DeviceAbstract(models.Model):
|
||||
sys_hostname = models.CharField(max_length=50, blank=True, default='', verbose_name='主机名')
|
||||
mac_address = models.CharField(max_length=50, blank=True, default='', verbose_name='MAC地址')
|
||||
sn_number = models.CharField(max_length=50, blank=True, default='', verbose_name='SN号码')
|
||||
os_type = models.CharField(max_length=50, blank=True, default='', verbose_name='系统类型')
|
||||
device_type = models.CharField(max_length=50, blank=True, default='', verbose_name='设备类型')
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class DeviceScanInfo(ConnectionAbstract, DeviceAbstract, TimeAbstract):
|
||||
error_message = models.CharField(max_length=80, blank=True, default='', verbose_name='错误信息')
|
||||
|
||||
class Meta:
|
||||
verbose_name = '扫描信息'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class ConnectionInfo(ConnectionAbstract, TimeAbstract):
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'SSH连接信息'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class Cabinet(models.Model):
|
||||
number = models.CharField(max_length=50, verbose_name='机柜编号')
|
||||
position = models.CharField(max_length=80, verbose_name='机柜位置')
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
|
||||
class Meta:
|
||||
verbose_name = '机柜信息'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class DeviceInfo(AbstractMode, DeviceAbstract, TimeAbstract):
|
||||
hostname = models.CharField(max_length=50, verbose_name='设备地址(IP或域名)')
|
||||
network_type = models.IntegerField(blank=True, null=True, verbose_name='网络类型')
|
||||
service_type = models.IntegerField(blank=True, null=True, verbose_name='服务类型')
|
||||
operation_type = models.IntegerField(blank=True, null=True, verbose_name='业务类型')
|
||||
leader = models.IntegerField(blank=True, null=True, verbose_name='责任人')
|
||||
dev_cabinet = models.IntegerField(blank=True, null=True, verbose_name='机柜信息')
|
||||
dev_connection = models.IntegerField(blank=True, null=True, verbose_name='连接信息')
|
||||
buyDate = models.DateField(default=datetime.now, verbose_name="购买日期")
|
||||
warrantyDate = models.DateField(default=datetime.now, verbose_name="到保日期")
|
||||
desc = models.TextField(blank=True, default='', verbose_name='备注信息')
|
||||
|
||||
class Meta:
|
||||
verbose_name = '设备信息'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
class DeviceFile(TimeAbstract):
|
||||
device = models.ForeignKey('DeviceInfo', blank=True, null=True, on_delete=models.SET_NULL, verbose_name='设备')
|
||||
file_content = models.FileField(upload_to="asset_file/%Y/%m", null=True, blank=True, verbose_name="资产文件")
|
||||
upload_user = models.CharField(max_length=20, verbose_name="上传人")
|
||||
|
||||
|
||||
@receiver(models.signals.post_delete, sender=DeviceFile)
|
||||
def auto_delete_file(sender, instance, **kwargs):
|
||||
if instance.file_content:
|
||||
if os.path.isfile(instance.file_content.path):
|
||||
os.remove(instance.file_content.path)
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import CmdbView
|
||||
from . import views_code, views_scan
|
||||
|
||||
app_name = 'cmdb'
|
||||
|
||||
urlpatterns = [
|
||||
path('', CmdbView.as_view(), name='index'),
|
||||
path('portal/code/', views_code.CodeView.as_view(), name='portal-code'),
|
||||
path('portal/code/create/', views_code.CodeCreateView.as_view(), name='portal-code-create'),
|
||||
path('portal/code/list/', views_code.CodeListView.as_view(), name='portal-code-list'),
|
||||
path('portal/code/update/', views_code.CodeUpdateView.as_view(), name='portal-code-update'),
|
||||
path('portal/code/delete/', views_code.CodeDeleteView.as_view(), name='portal-code-delete'),
|
||||
|
||||
path('portal/scan_config/', views_scan.ScanConfigView.as_view(), name='portal-scan_config'),
|
||||
]
|
||||
|
||||
53
apps/cmdb/views_code.py
Normal file
53
apps/cmdb/views_code.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# @Time : 2018/12/19 13:31
|
||||
# @Author : RobbieHan
|
||||
# @File : views_code.py.py
|
||||
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from system.mixin import LoginRequiredMixin
|
||||
from custom import (BreadcrumbMixin, SandboxCreateView,
|
||||
SandboxListView, SandboxUpdateView, SandboxDeleteView)
|
||||
from .models import Code
|
||||
from .forms import CodeCreateForm, CodeUpdateForm
|
||||
|
||||
|
||||
class CodeView(LoginRequiredMixin, BreadcrumbMixin, TemplateView):
|
||||
template_name = 'cmdb/code.html'
|
||||
|
||||
def get_context_data(self):
|
||||
self.kwargs['code_parent'] = Code.objects.filter(parent=None)
|
||||
return super().get_context_data(**self.kwargs)
|
||||
|
||||
|
||||
class CodeCreateView(SandboxCreateView):
|
||||
model = Code
|
||||
form_class = CodeCreateForm
|
||||
template_name_suffix = '_create'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['code_parent'] = Code.objects.filter(parent=None)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class CodeListView(SandboxListView):
|
||||
model = Code
|
||||
fields = ['id', 'key', 'value', 'parent__value']
|
||||
|
||||
def get(self, request):
|
||||
if 'parent' in request.GET and request.GET['parent']:
|
||||
self.filters = dict(parent__key=request.GET['parent'])
|
||||
return super().get(request)
|
||||
|
||||
|
||||
class CodeUpdateView(SandboxUpdateView):
|
||||
model = Code
|
||||
form_class = CodeUpdateForm
|
||||
template_name_suffix = '_update'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['code_parent'] = Code.objects.filter(parent=None)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class CodeDeleteView(SandboxDeleteView):
|
||||
model = Code
|
||||
54
apps/cmdb/views_scan.py
Normal file
54
apps/cmdb/views_scan.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# @Time : 2018/12/29 19:25
|
||||
# @Author : RobbieHan
|
||||
# @File : views_scan.py
|
||||
|
||||
import ast
|
||||
import logging
|
||||
from ruamel import yaml
|
||||
|
||||
from django.views.generic import View
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import render
|
||||
|
||||
|
||||
from system.mixin import LoginRequiredMixin
|
||||
from custom import BreadcrumbMixin
|
||||
from utils.sandbox_utils import ConfigFileMixin
|
||||
from system.models import Menu
|
||||
|
||||
error_logger = logging.getLogger('sandbox_error')
|
||||
|
||||
|
||||
class ScanConfigView(LoginRequiredMixin, BreadcrumbMixin, ConfigFileMixin, View):
|
||||
|
||||
def get(self, request):
|
||||
menu = Menu.get_menu_by_request_url(request.path_info)
|
||||
template_name = 'cmdb/scan_config.html'
|
||||
context = self.get_conf_content()
|
||||
context.update(menu)
|
||||
return render(request, template_name, context)
|
||||
|
||||
def post(self, request):
|
||||
ret = dict(result=False)
|
||||
config = dict()
|
||||
hosts = request.POST
|
||||
try:
|
||||
config['net_address'] = ast.literal_eval(hosts['net_address'])
|
||||
config['ssh_username'] = hosts['ssh_username']
|
||||
config['ssh_port'] = hosts['ssh_port']
|
||||
config['ssh_password'] = hosts['ssh_password']
|
||||
config['ssh_private_key'] = hosts['ssh_private_key']
|
||||
config['commands'] = ast.literal_eval(hosts['commands'])
|
||||
config['auth_type'] = hosts['auth_type']
|
||||
config['scan_type'] = hosts['scan_type']
|
||||
config['email'] = hosts['email']
|
||||
config['send_email'] = hosts['send_email']
|
||||
data = dict(hosts=config)
|
||||
config_file = self.get_config_file()
|
||||
with open(config_file, 'w', encoding='utf-8') as f:
|
||||
yaml.dump(data, f, Dumper=yaml.RoundTripDumper, indent=4)
|
||||
ret['result'] = True
|
||||
except Exception as e:
|
||||
error_logger.error(e)
|
||||
|
||||
return JsonResponse(ret)
|
||||
@@ -3,10 +3,13 @@
|
||||
# @File : custom.py
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from django.views.generic import CreateView, UpdateView
|
||||
from django.views.generic import CreateView, UpdateView, View
|
||||
from django.shortcuts import HttpResponse
|
||||
from django.http import Http404
|
||||
from django.http import Http404, JsonResponse
|
||||
from django.db.models.query import QuerySet
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from system.mixin import LoginRequiredMixin
|
||||
from system.models import Menu
|
||||
@@ -42,6 +45,69 @@ class SandboxGetObjectMixin:
|
||||
return obj
|
||||
|
||||
|
||||
class SandboxMultipleObjectMixin:
|
||||
|
||||
filters = {}
|
||||
fields = []
|
||||
queryset = None
|
||||
model = None
|
||||
|
||||
def get_queryset(self):
|
||||
if self.queryset is not None:
|
||||
queryset = self.queryset
|
||||
if isinstance(queryset, QuerySet):
|
||||
queryset = queryset.all()
|
||||
elif self.model is not None:
|
||||
queryset = self.model._default_manager.all()
|
||||
else:
|
||||
raise ImproperlyConfigured(
|
||||
"%(cls)s is missing a QuerySet. Define "
|
||||
"%(cls)s.model, %(cls)s.queryset."
|
||||
% {'cls': self.__class__.__name__}
|
||||
)
|
||||
return queryset
|
||||
|
||||
def get_datatables_paginator(self, request):
|
||||
datatables = request.GET
|
||||
draw = int(datatables.get('draw'))
|
||||
start = int(datatables.get('start'))
|
||||
length = int(datatables.get('length'))
|
||||
order_column = datatables.get('order[0][column]')
|
||||
order_dir = datatables.get('order[0][dir]')
|
||||
order_field = datatables.get('columns[{}][data]'.format(order_column))
|
||||
queryset = self.get_queryset()
|
||||
if order_dir == 'asc':
|
||||
queryset = queryset.order_by(order_field)
|
||||
else:
|
||||
queryset = queryset.order_by('-{0}'.format(order_field))
|
||||
record_total_count = queryset.count()
|
||||
filters = self.get_filters()
|
||||
fields = self.get_fields()
|
||||
if filters:
|
||||
queryset = queryset.filter(**self.filters)
|
||||
if fields:
|
||||
queryset = queryset.values(*self.fields)
|
||||
|
||||
record_filter_count = queryset.count()
|
||||
|
||||
object_list = queryset[start:(start + length)]
|
||||
|
||||
data = list(object_list)
|
||||
|
||||
return {
|
||||
'draw': draw,
|
||||
'recordsTotal': record_total_count,
|
||||
'recordsFiltered': record_filter_count,
|
||||
'data': data,
|
||||
}
|
||||
|
||||
def get_filters(self):
|
||||
return self.filters
|
||||
|
||||
def get_fields(self):
|
||||
return self.fields
|
||||
|
||||
|
||||
class SandboxEditViewMixin:
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@@ -50,6 +116,11 @@ class SandboxEditViewMixin:
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
res['result'] = True
|
||||
else:
|
||||
pattern = '<li>.*?<ul class=.*?><li>(.*?)</li>'
|
||||
form_errors = str(form.errors)
|
||||
errors = re.findall(pattern, form_errors)
|
||||
res['error'] = errors[0]
|
||||
return HttpResponse(json.dumps(res), content_type='application/json')
|
||||
|
||||
|
||||
@@ -65,3 +136,27 @@ class SandboxUpdateView(LoginRequiredMixin, SandboxEditViewMixin, SandboxGetObje
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
|
||||
class SandboxListView(LoginRequiredMixin, SandboxMultipleObjectMixin, View):
|
||||
"""
|
||||
JsonResponse some json of objects, set by `self.model` or `self.queryset`.
|
||||
"""
|
||||
def get(self, request):
|
||||
context = self.get_datatables_paginator(request)
|
||||
return JsonResponse(context)
|
||||
|
||||
|
||||
class SandboxDeleteView(LoginRequiredMixin, SandboxMultipleObjectMixin, View):
|
||||
|
||||
def post(self, request):
|
||||
context = dict(result=False)
|
||||
queryset = self.get_queryset()
|
||||
if 'id' in request.POST and request.POST['id']:
|
||||
id_list = map(int, request.POST['id'].split(','))
|
||||
queryset.filter(id__in=id_list).delete()
|
||||
context['result'] = True
|
||||
else:
|
||||
raise AttributeError("Sandbox delete view %s must be called with id. "
|
||||
% self.__class__.__name__)
|
||||
return JsonResponse(context)
|
||||
@@ -0,0 +1 @@
|
||||
default_app_config = 'system.apps.SystemConfig'
|
||||
|
||||
@@ -2,4 +2,10 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class SystemConfig(AppConfig):
|
||||
name = 'apps.system'
|
||||
name = 'system'
|
||||
|
||||
def ready(self):
|
||||
from .signals import create_menu
|
||||
from .signals import user_logged_in_handler
|
||||
from .signals import user_logged_out_handler
|
||||
from .signals import user_login_failed_handler
|
||||
|
||||
50
apps/system/signals.py
Normal file
50
apps/system/signals.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import logging
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.db.models.signals import post_save
|
||||
from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed
|
||||
|
||||
from .models import Role, Menu
|
||||
|
||||
error_logger = logging.getLogger('sandbox_error')
|
||||
info_logger = logging.getLogger('sandbox_info')
|
||||
|
||||
|
||||
@receiver(post_save, sender=Menu)
|
||||
def create_menu(sender, instance, **kwargs):
|
||||
queryset = Role.objects.filter(id=1)
|
||||
try:
|
||||
admin_role = queryset.get()
|
||||
admin_role.permissions.add(instance)
|
||||
except queryset.model.DoesNotExist as e:
|
||||
error_logger.error(e)
|
||||
|
||||
|
||||
@receiver(user_logged_in)
|
||||
def user_logged_in_handler(sender, request, user, **kwargs):
|
||||
ip = request.META.get('REMOTE_ADDR')
|
||||
msg = 'login user: {user}, remote ip: {ip}, action: login, status: successed'.format(
|
||||
user=user.username,
|
||||
ip=ip,
|
||||
)
|
||||
info_logger.info(msg)
|
||||
|
||||
|
||||
@receiver(user_logged_out)
|
||||
def user_logged_out_handler(sender, request, user, **kwargs):
|
||||
ip = request.META.get('REMOTE_ADDR')
|
||||
msg = 'login user: {user}, remote ip: {ip}, action: logout, status: successed'.format(
|
||||
user=user.username,
|
||||
ip=ip,
|
||||
)
|
||||
info_logger.info(msg)
|
||||
|
||||
|
||||
@receiver(user_login_failed)
|
||||
def user_login_failed_handler(sender, credentials, request, **kwargs):
|
||||
msg = 'logout failed for: {credentials}'.format(
|
||||
credentials=credentials,
|
||||
)
|
||||
|
||||
info_logger.info(msg)
|
||||
|
||||
@@ -40,6 +40,7 @@ class LoginView(View):
|
||||
redirect_to = request.GET.get('next', '/')
|
||||
login_form = LoginForm(request.POST)
|
||||
ret = dict(login_form=login_form)
|
||||
print(request.META.get('REMOTE_ADDR'))
|
||||
if login_form.is_valid():
|
||||
user_name = request.POST['username']
|
||||
pass_word = request.POST['password']
|
||||
|
||||
3
apps/utils/__init__.py
Normal file
3
apps/utils/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# @Time : 2018/12/29 16:26
|
||||
# @Author : RobbieHan
|
||||
# @File : __init__.py.py
|
||||
74
apps/utils/sandbox_utils.py
Normal file
74
apps/utils/sandbox_utils.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# @Time : 2018/12/29 19:22
|
||||
# @Author : RobbieHan
|
||||
# @File : sandbox_utils.py
|
||||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
import yaml
|
||||
import logging
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sandboxMP.settings')
|
||||
error_logger = logging.getLogger('sandbox_error')
|
||||
|
||||
|
||||
class ConfigFileMixin:
|
||||
config_file = None
|
||||
|
||||
def get_config_file(self):
|
||||
"""
|
||||
Return 'config_file' that will be used to look up the scan hosts IP,
|
||||
network, range of IP, or other config settings.
|
||||
This method is called by the default implementation of get_hosts(),
|
||||
"""
|
||||
|
||||
if self.config_file is None:
|
||||
config_file = os.path.join(os.path.join(settings.BASE_DIR, 'config'), 'scanhosts.yml')
|
||||
if os.path.exists(config_file):
|
||||
return config_file
|
||||
else:
|
||||
msg = ' %(cls)s is missing a config file. Define %(cls)s.config_file, ' \
|
||||
'or override %(cls)s.get_config_file().' % {'cls': self.__class__.__name__}
|
||||
error_logger.error(msg)
|
||||
raise ValueError(msg)
|
||||
|
||||
return self.config_file
|
||||
|
||||
def get_conf_content(self, *key):
|
||||
"""
|
||||
Get the configuration content from config file .
|
||||
Example ssh_password, commands, email which is in the config file.
|
||||
"""
|
||||
_config = self.get_config_file()
|
||||
with open(_config) as f:
|
||||
content = yaml.load(f)
|
||||
if key is not None:
|
||||
try:
|
||||
num = 0
|
||||
while num < len(key):
|
||||
content = content[key[num]]
|
||||
num += 1
|
||||
except Exception as e:
|
||||
msg = '%(exc)s is not in %(config)s.' % {
|
||||
'exc': e,
|
||||
'config': _config
|
||||
}
|
||||
error_logger.error(msg)
|
||||
raise ValueError(msg)
|
||||
return content
|
||||
|
||||
def get_commands(self):
|
||||
"""
|
||||
Get the commands from config file.
|
||||
"""
|
||||
key = ['hosts', 'commands']
|
||||
return self.get_conf_content(*key)
|
||||
|
||||
def get_net_address(self):
|
||||
"""
|
||||
Return the hosts that will be used to scan.
|
||||
Subclasses can override this to return any hosts.
|
||||
"""
|
||||
key = ['hosts', 'net_address']
|
||||
return self.get_conf_content(*key)
|
||||
18
config/scanhosts.yml
Normal file
18
config/scanhosts.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
hosts:
|
||||
net_address:
|
||||
- '172.16.3.0/24'
|
||||
- '172.16.2.100-105'
|
||||
ssh_username: 'root'
|
||||
ssh_port: '22'
|
||||
ssh_password: '1234@abcd.com'
|
||||
ssh_private_key: '/root/.ssh/id_rsa'
|
||||
commands:
|
||||
sys_hostname: 'hostname'
|
||||
mac_address: 'cat /sys/class/net/[^tsbvl]*/address'
|
||||
sn_number: 'dmidecode -s system-serial-number'
|
||||
os_type: 'cat /etc/redhat-release'
|
||||
device_type: 'echo `dmidecode -s system-manufacturer && dmidecode -s system-product-name`'
|
||||
email: 'robbie_han@outlook.com'
|
||||
send_email: 'false'
|
||||
scan_type: 'basic_scan'
|
||||
auth_type: 'private_key'
|
||||
@@ -1,2 +1 @@
|
||||
django==2.1.2
|
||||
pillow==5.3.0
|
||||
-r pro.txt
|
||||
@@ -1,2 +1,14 @@
|
||||
django==2.1.2
|
||||
pillow==5.3.0
|
||||
pillow==5.3.0
|
||||
mysqlclient==1.3.13
|
||||
ipython==7.1.1
|
||||
pyyaml==3.13
|
||||
ruamel.yaml==0.15.80
|
||||
python-nmap==0.6.1
|
||||
redis==3.0.1
|
||||
pymongo==3.7.1
|
||||
paramiko==2.4.2
|
||||
pycrypto==2.6.1
|
||||
celery==4.2.1
|
||||
celery-once==2.0.0
|
||||
flower==0.9.2
|
||||
|
||||
@@ -2,7 +2,7 @@ var DATATABLES_CONSTANT = {
|
||||
|
||||
// datatables常量
|
||||
DATA_TABLES : {
|
||||
DEFAULT_OPTION : { // DataTables初始化选项
|
||||
SERVER_SIDE_OPTION : { // DataTables初始化选项
|
||||
oLanguage : {
|
||||
sProcessing : "处理中...",
|
||||
sLengthMenu : "每页 _MENU_ 项",//"显示 _MENU_ 项结果,",
|
||||
|
||||
274
templates/cmdb/code.html
Normal file
274
templates/cmdb/code.html
Normal file
@@ -0,0 +1,274 @@
|
||||
{% 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 class="pull-right">
|
||||
<form class="form-inline" id="queryForm">
|
||||
<div class="form-group searchArea margin-r-5 margin-top-5">
|
||||
<label>字典分类:</label>
|
||||
<select class="form-control inputText select2" name="parent" id="parent">
|
||||
<option style='text-align:center' value="">---所有---</option>
|
||||
{% for code in code_parent %}
|
||||
<option value={{ code.key}}>{{ code.value }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</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>KEY</th>
|
||||
<th>VALUE</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-PORTAL').addClass('active');
|
||||
$('#CDMB-PORTAL-CODE').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:portal-code-list' %}",
|
||||
"data": function (d) {
|
||||
d.parent = $("#parent").val();
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
DATATABLES_CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,
|
||||
{
|
||||
data: "id",
|
||||
width: "5%",
|
||||
},
|
||||
{
|
||||
data: "key",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "value",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "parent__value",
|
||||
//width : "20%",
|
||||
},
|
||||
{
|
||||
data: "id",
|
||||
width: "10%",
|
||||
bSortable: "false",
|
||||
render: function (data, type, row, meta) {
|
||||
var ret = "";
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//select2
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
//过滤刷新接口获取新的数据
|
||||
$("#parent").change(function () {
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
|
||||
|
||||
// 刷新数据
|
||||
$("#btnRefresh").click(function () {
|
||||
oDataTable.ajax.reload();
|
||||
});
|
||||
//新建字典
|
||||
$("#btnCreate").click(function () {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: "{% url 'cmdb:portal-code-create' %}",
|
||||
end: function () {
|
||||
//关闭时做的事情
|
||||
oDataTable.ajax.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//修改字典
|
||||
function doUpdate(id) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑',
|
||||
shadeClose: false,
|
||||
maxmin: true,
|
||||
area: ['800px', '400px'],
|
||||
content: ["{% url 'cmdb:portal-code-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:portal-code-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:portal-code-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;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
97
templates/cmdb/code_create.html
Normal file
97
templates/cmdb/code_create.html
Normal file
@@ -0,0 +1,97 @@
|
||||
{% extends 'base-layer.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
<!-- iCheck for checkboxes and radio inputs -->
|
||||
{% endblock %}
|
||||
{% block main %}
|
||||
<div class="box box-danger">
|
||||
<form class="form-horizontal" id="addForm" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="box-body">
|
||||
<fieldset>
|
||||
<legend>
|
||||
<h4>新建字典</h4>
|
||||
</legend>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">KEY</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="key" type="text"/>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">VALUE</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="value" type="text" />
|
||||
</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" name="parent">
|
||||
<option value=""></option>
|
||||
{% for parent in code_parent %}
|
||||
<option value={{ parent.id }}> {{ parent.value }} </option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">描述信息</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" id="desc" name="desc" type="text" />
|
||||
</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 type="text/javascript">
|
||||
$("#btnSave").click(function () {
|
||||
var data = $("#addForm").serialize();
|
||||
$.ajax({
|
||||
type: $("#addForm").attr('method'),
|
||||
url: "{% url 'cmdb:portal-code-create' %}",
|
||||
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();
|
||||
|
||||
});
|
||||
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
99
templates/cmdb/code_update.html
Normal file
99
templates/cmdb/code_update.html
Normal file
@@ -0,0 +1,99 @@
|
||||
{% extends 'base-layer.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">
|
||||
<!-- iCheck for checkboxes and radio inputs -->
|
||||
{% endblock %}
|
||||
{% block main %}
|
||||
<div class="box box-danger">
|
||||
<form class="form-horizontal" id="addForm" method="post">
|
||||
<input type="hidden" name='id' type='text' value="{{ code.id }}"/>
|
||||
{% csrf_token %}
|
||||
<div class="box-body">
|
||||
<fieldset>
|
||||
<legend>
|
||||
<h4>修改字典</h4>
|
||||
</legend>
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">KEY</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="key" type="text" value="{{ code.key }}"/>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">VALUE</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" name="value" type="text" value="{{ code.value }}"/>
|
||||
</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" name="parent">
|
||||
<option value={{ code.parent.id }}> {{ code.parent.value }} </option>
|
||||
<option value=""></option>
|
||||
{% for parent in code_parent %}
|
||||
<option value={{ parent.id }}> {{ parent.value }} </option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">描述信息</label>
|
||||
<div class="col-sm-3">
|
||||
<input class="form-control" id="desc" name="desc" type="text" />
|
||||
</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 type="text/javascript">
|
||||
$("#btnSave").click(function () {
|
||||
var data = $("#addForm").serialize();
|
||||
$.ajax({
|
||||
type: $("#addForm").attr('method'),
|
||||
url: "{% url 'cmdb:portal-code-update' %}",
|
||||
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();
|
||||
|
||||
});
|
||||
|
||||
$(function () {
|
||||
//Initialize Select2 Elements
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
176
templates/cmdb/scan_config.html
Normal file
176
templates/cmdb/scan_config.html
Normal file
@@ -0,0 +1,176 @@
|
||||
{% extends "base-left.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'js/plugins/layer/skin/layer.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<!-- Horizontal Form -->
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">扫面参数配置</h3>
|
||||
</div>
|
||||
<!-- /.box-header -->
|
||||
<!-- form start -->
|
||||
<form class="form-horizontal" id="addForm" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="box-body">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">扫描网段</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="net_address" name="net_address" value="{{ hosts.net_address }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">登陆用户</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="ssh_username" name="ssh_username" value="{{ hosts.ssh_username }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">SSH端口</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="ssh_port" name="ssh_port" value="{{ hosts.ssh_port }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">登陆密码</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" type="password" id="ssh_password" name="ssh_password" value="{{ hosts.ssh_password }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">密钥路径</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="ssh_private_key" name="ssh_private_key" value="{{ hosts.ssh_private_key }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">运行命令</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea class="form-control" rows="5" id="commands" name="commands" readonly>{{ hosts.commands }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">认证方式</label>
|
||||
<div class="col-sm-4">
|
||||
<select class="form-control" name="auth_type">
|
||||
<option value="password" {% ifequal hosts.auth_type 'password' %}selected="selected"{% endifequal %}>密码认证</option>
|
||||
<option value="private_key" {% ifequal hosts.auth_type 'private_key' %}selected="selected"{% endifequal %}>私钥认证</option>
|
||||
</select>
|
||||
</div>
|
||||
<label class="col-sm-2 control-label">扫描方式</label>
|
||||
<div class="col-sm-4">
|
||||
<select class="form-control" name="scan_type">
|
||||
<option value="basic_scan" {% ifequal hosts.scan_type 'basic_scan' %}selected="selected"{% endifequal %}>基础扫描</option>
|
||||
<option value="enhanced_scan" {% ifequal hosts.scan_type 'enhanced_scan' %}selected="selected"{% endifequal %}>加强扫描</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">收件邮箱</label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control" id="email" name="email" value="{{ hosts.email }}">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label class="col-sm-2 control-label">发送邮件</label>
|
||||
<div class="col-sm-10">
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="send_email" value="true" {% ifequal hosts.send_email 'true' %}checked{% endifequal %}>是
|
||||
</label>
|
||||
<label class="control-label">
|
||||
<input type="radio" class="minimal" name="send_email" value="false" {% ifequal hosts.send_email 'false' %}checked{% endifequal %}>否
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
<div class="box-footer">
|
||||
<span class="pull-right">
|
||||
<button type="button" id="btnCancel" class="btn btn-default">取消</button>
|
||||
<button type="button" id="btnSave" class="btn btn-info">保存</button>
|
||||
</span>
|
||||
</div>
|
||||
<!-- /.box-footer -->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">参数配置说明</h3>
|
||||
</div><!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
<a class="product-title"><strong>扫描网段</strong><span class="label label-danger pull-right">必填参数</span></a>
|
||||
<p><small>网络扫描地址列表,列表中可以包含一个或多个网段,也可以是一个或多个地址区间,例如['192.168.100.0/24', '192.168.100.10-20']</small></p>
|
||||
<a class="product-title"><strong>登陆用户</strong><span class="label label-danger pull-right">必填参数</span></a>
|
||||
<p><small>系统登陆测试使用的用户名,默认root。</small></p>
|
||||
<a class="product-title"><strong>登陆密码</strong><span class="label label-danger pull-right">可选参数</span></a>
|
||||
<p><small>系统登陆测试使用的密码,如过认证方式为密码认证,必须填写密码信息。</small></p>
|
||||
<a class="product-title"><strong>密钥路径</strong><span class="label label-primary pull-right">可选参数</span></a>
|
||||
<p><small>系统登陆测试使用的密钥存放路径,如过认证方式为私钥认证,必须填写密钥路径。</small></p>
|
||||
<a class="product-title"><strong>运行命令</strong><span class="label label-default pull-right">预定义参数</span></a>
|
||||
<p><small>登陆系统后运行的基本命令,用来获取系统基本信息,当扫描方式为加强扫描时,才会执行运行命令,运行命令为预定义,禁止修改。</small></p>
|
||||
<a class="product-title"><strong>认证方式</strong><span class="label label-primary pull-right">可选参数</span></a>
|
||||
<p><small>系统登陆认证方式,包括密码认证和私钥认证两种方式,当扫描方式为加强扫描时,需要设定认证方式。</small></p>
|
||||
<a class="product-title"><strong>扫描方式</strong><span class="label label-primary pull-right">可选参数</span></a>
|
||||
<p><small>系统扫描方式,包括基本扫描和加强扫描,当设置为加强扫描时会登陆系统执行运行命令获取系统信息。</small></p>
|
||||
<a class="product-title"><strong>收件邮箱</strong><span class="label label-primary pull-right">可选参数</span></a>
|
||||
<p><small>用于接收扫描结果邮件,可以通过发送邮件选项设置是否发送通知邮件。</small></p>
|
||||
</div><!-- /.box-body -->
|
||||
</div><!-- /.box -->
|
||||
</div>
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- /.content -->
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
<script src="{% static 'js/plugins/layer/layer.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
// 菜单选中高亮
|
||||
$(function () {
|
||||
$('#CMDB-PORTAL').addClass('active');
|
||||
$('#CMDB-PORTAL-SCAN_CONFIG').addClass('active');
|
||||
|
||||
});
|
||||
|
||||
$("#btnSave").click(function () {
|
||||
var hosts = $("#addForm").serialize();
|
||||
$.ajax({
|
||||
type: $("#addForm").attr('method'),
|
||||
url: "{% url 'cmdb:portal-scan_config' %}",
|
||||
cache: false,
|
||||
data: hosts,
|
||||
success: function (msg) {
|
||||
if (msg.result) {
|
||||
layer.alert('数据保存成功!', {icon: 1});
|
||||
} else {
|
||||
layer.alert('数据保存失败', {icon: 5});
|
||||
//$('errorMessage').html(msg.message)
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/*点取消刷新新页面*/
|
||||
$("#btnCancel").click(function () {
|
||||
window.location.reload();
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user