diff --git a/manage.py b/manage.py new file mode 100755 index 0000000000000000000000000000000000000000..503d3b6680d286f09e29a8d5044a3173322dbe40 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'safeguard.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/safeguard/__init__.py b/safeguard/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/safeguard/__pycache__/__init__.cpython-39.pyc b/safeguard/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2619fd534d69489d8717205311b848ba9f0de605 Binary files /dev/null and b/safeguard/__pycache__/__init__.cpython-39.pyc differ diff --git a/safeguard/__pycache__/settings.cpython-39.pyc b/safeguard/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7ca23c85ada335f02d1b301f7014cdf7664e82b9 Binary files /dev/null and b/safeguard/__pycache__/settings.cpython-39.pyc differ diff --git a/safeguard/__pycache__/urls.cpython-39.pyc b/safeguard/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d1f3e500601ecfb67b7ed1020527ff078919536d Binary files /dev/null and b/safeguard/__pycache__/urls.cpython-39.pyc differ diff --git a/safeguard/__pycache__/wsgi.cpython-39.pyc b/safeguard/__pycache__/wsgi.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f77405ee7dbc0a719722587f71bd63298cac37a6 Binary files /dev/null and b/safeguard/__pycache__/wsgi.cpython-39.pyc differ diff --git a/safeguard/asgi.py b/safeguard/asgi.py new file mode 100644 index 0000000000000000000000000000000000000000..6ae2f91c641a625d08046d704f2e267edaeb554d --- /dev/null +++ b/safeguard/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for safeguard project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'safeguard.settings') + +application = get_asgi_application() diff --git a/safeguard/settings.py b/safeguard/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..e6e759ea05d90eb14174f7d4ec85491381d8ce88 --- /dev/null +++ b/safeguard/settings.py @@ -0,0 +1,132 @@ +""" +Django settings for safeguard project. + +Generated by 'django-admin startproject' using Django 4.2.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-x3g^h4d6zkgilav5*%5f%)36_y*z5*34n2)!7*unj-&w1y(w#j' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ['*'] + + +# Application definition + +INSTALLED_APPS = [ + 'safeguard_web.apps.SafeguardWebConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'safeguard.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'safeguard_web/templates')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'safeguard.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': "safeguard", + 'USER':'root', + 'PASSWORD':'safeguard', + 'HOST':'localhost', + 'PORT':'3306', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' +STATICFILES_DIRS = [ + BASE_DIR / "safeguard_web/static", +] + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/safeguard/urls.py b/safeguard/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..6020ce6f7fa4ddf38c70fff91f7b87194836d35e --- /dev/null +++ b/safeguard/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for safeguard project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path,include + +urlpatterns = [ + path('safeguard/', include('safeguard_web.urls')), + path('admin/', admin.site.urls), +] diff --git a/safeguard/wsgi.py b/safeguard/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..ccdf1c8b8f0cd6f155b06ff7eb6d8caa64dfd069 --- /dev/null +++ b/safeguard/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for safeguard project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'safeguard.settings') + +application = get_wsgi_application() diff --git a/safeguard_web/__init__.py b/safeguard_web/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/safeguard_web/__pycache__/__init__.cpython-39.pyc b/safeguard_web/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..70ef7a0213aa1078ad27c86a032cd731823c6feb Binary files /dev/null and b/safeguard_web/__pycache__/__init__.cpython-39.pyc differ diff --git a/safeguard_web/__pycache__/admin.cpython-39.pyc b/safeguard_web/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8903ab8132e5b66d4f5a317c40d87b35b10f09da Binary files /dev/null and b/safeguard_web/__pycache__/admin.cpython-39.pyc differ diff --git a/safeguard_web/__pycache__/apps.cpython-39.pyc b/safeguard_web/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2948456ad6aa8152279d937c39bf1ea5cba23062 Binary files /dev/null and b/safeguard_web/__pycache__/apps.cpython-39.pyc differ diff --git a/safeguard_web/__pycache__/models.cpython-39.pyc b/safeguard_web/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..08c7f6bb54e06d11c707f359745adfb78aba2a89 Binary files /dev/null and b/safeguard_web/__pycache__/models.cpython-39.pyc differ diff --git a/safeguard_web/__pycache__/urls.cpython-39.pyc b/safeguard_web/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..06bfa9c929aa1591cbac5fd10c8b6288331ac173 Binary files /dev/null and b/safeguard_web/__pycache__/urls.cpython-39.pyc differ diff --git a/safeguard_web/__pycache__/views.cpython-39.pyc b/safeguard_web/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..610ed785cee8e00a2e21aee843bf93e68fef2991 Binary files /dev/null and b/safeguard_web/__pycache__/views.cpython-39.pyc differ diff --git a/safeguard_web/admin.py b/safeguard_web/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/safeguard_web/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/safeguard_web/apps.py b/safeguard_web/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..0e98202c357eca8732c8c7845fab4ee777a648a6 --- /dev/null +++ b/safeguard_web/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SafeguardWebConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'safeguard_web' diff --git a/safeguard_web/migrations/__init__.py b/safeguard_web/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/safeguard_web/migrations/__pycache__/__init__.cpython-39.pyc b/safeguard_web/migrations/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c42420bad1bbf77b90dc40b663e01e7462330e6 Binary files /dev/null and b/safeguard_web/migrations/__pycache__/__init__.cpython-39.pyc differ diff --git a/safeguard_web/models.py b/safeguard_web/models.py new file mode 100644 index 0000000000000000000000000000000000000000..d41195c57ffee012eb55dd21e41cf17fa058e0e4 --- /dev/null +++ b/safeguard_web/models.py @@ -0,0 +1,9 @@ +from django.db import models + +# Create your models here. +class Host(models.Model): + hostname = models.CharField(max_length=100, primary_key=True) + ip = models.CharField(max_length=16) + + def __str__(self): + return self.hostname \ No newline at end of file diff --git a/safeguard_web/static/css/base.css b/safeguard_web/static/css/base.css new file mode 100644 index 0000000000000000000000000000000000000000..57dd12996a7dffd7ea0f2022b17b11c7fe047c28 --- /dev/null +++ b/safeguard_web/static/css/base.css @@ -0,0 +1,46 @@ +.pagetop { + display: flex; + align-items: center; + background-color: #f2f2f2; + padding: 10px; +} + +.pagetop-logo img { + height: 50px; +} + +.pagetop-dropdown { + position: relative; + margin-left: 20px; +} + +.pagetop-item a { + color: #333; + text-decoration: none; + padding: 5px 10px; +} + +.dropdown-content { + display: none; + position: absolute; + background-color: #fff; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); + padding: 10px; + z-index: 1; + white-space: nowrap; +} + +.pagetop-dropdown:hover .dropdown-content { + display: block; +} + +.dropdown-content a { + display: block; + color: #333; + padding: 5px 0; + text-decoration: none; +} + +.dropdown-content a:hover { + background-color: #f9f9f9; +} \ No newline at end of file diff --git a/safeguard_web/static/css/hosts.css b/safeguard_web/static/css/hosts.css new file mode 100644 index 0000000000000000000000000000000000000000..f8938ce38f96c69d4e3bf9e50f7aaaf258ced305 --- /dev/null +++ b/safeguard_web/static/css/hosts.css @@ -0,0 +1,57 @@ +.host-header { + display: flex; + align-items: center; + justify-content: flex-start; + margin-bottom: 50px; + margin-top: 40px; + } + + .host-header-item { + display: flex; + align-items: center; + margin-right: 10px; + } + + .host-header-item label { + margin-right: 5px; + } + + .host-header-item input[type="text"] { + padding: 5px; + } + + .host-header-item button { + padding: 5px 10px; + margin-left: 10px; + } + + .host-list { + width: 100%; + margin: 0 auto; + background-color: #f9f9f9; + border: 1px solid #ccc; + padding: 10px; + box-sizing: border-box; + } + + .host-list table { + width: 100%; + border-collapse: collapse; + } + + .host-list th, + .host-list td { + padding: 10px; + border: 1px solid #ccc; + } + + .pagination { + display: flex; + justify-content: center; + margin-top: 20px; + } + + .pagination button { + padding: 5px 10px; + margin: 0 5px; + } \ No newline at end of file diff --git a/safeguard_web/static/img/safeguard.ico b/safeguard_web/static/img/safeguard.ico new file mode 100644 index 0000000000000000000000000000000000000000..d217295ddcbf660f6398eb1197e24a2d78d0109b Binary files /dev/null and b/safeguard_web/static/img/safeguard.ico differ diff --git a/safeguard_web/static/img/safeguard.png b/safeguard_web/static/img/safeguard.png new file mode 100644 index 0000000000000000000000000000000000000000..e674d8c4ea7dae84165a8a381db559ba13256a70 Binary files /dev/null and b/safeguard_web/static/img/safeguard.png differ diff --git a/safeguard_web/static/safeguard.ico b/safeguard_web/static/safeguard.ico new file mode 100644 index 0000000000000000000000000000000000000000..e674d8c4ea7dae84165a8a381db559ba13256a70 Binary files /dev/null and b/safeguard_web/static/safeguard.ico differ diff --git a/safeguard_web/templates/base.html b/safeguard_web/templates/base.html new file mode 100644 index 0000000000000000000000000000000000000000..da9495361be4b98f85ed7c008cc3bc0799c1879d --- /dev/null +++ b/safeguard_web/templates/base.html @@ -0,0 +1,82 @@ + + +{% load static %} + + + + + + + {% block css %} + {% endblock %} + safeguard-web + + +
+ +
+
+ 首页 +
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+ + {% block page %} + {% endblock %} +
+ + diff --git a/safeguard_web/templates/hosts.html b/safeguard_web/templates/hosts.html new file mode 100644 index 0000000000000000000000000000000000000000..5665e4a96a75aa8c7d92320cb03bda916629773a --- /dev/null +++ b/safeguard_web/templates/hosts.html @@ -0,0 +1,46 @@ + +{% extends 'base.html' %} +{% load static %} + +{% block css %} + +{% endblock %} + +{% block page %} +
+
+ + +
+
+ + +
+
+ + + +
+
+ +
+ + + + + + + + + + + +
主机名称主机IP
+
+ + + + +{% endblock %} diff --git a/safeguard_web/tests.py b/safeguard_web/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/safeguard_web/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/safeguard_web/urls.py b/safeguard_web/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..f5ff4174f874aeaaa9cfa04079a48234874d7c2b --- /dev/null +++ b/safeguard_web/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.index, name="index"), + path("hosts", views.hosts, name="hosts"), +] diff --git a/safeguard_web/views.py b/safeguard_web/views.py new file mode 100644 index 0000000000000000000000000000000000000000..92c4498459d088e356aea247c1d429aec347e439 --- /dev/null +++ b/safeguard_web/views.py @@ -0,0 +1,12 @@ +from django.shortcuts import render +from django.http import HttpResponse +from .models import Host + +# Create your views here. + +def index(request): + return render(request, "base.html") + + +def hosts(request): + return render(request, "hosts.html") \ No newline at end of file