Инициализация в новом репозитории
This commit is contained in:
commit
eb1f18f53e
374 changed files with 226678 additions and 0 deletions
29
SRV/config/cors.py
Normal file
29
SRV/config/cors.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from fastapi import FastAPI
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
|
||||
|
||||
class CORSMiddlewareConfig:
|
||||
"""
|
||||
Класс для настройки CORS политики в FastAPI
|
||||
"""
|
||||
def __init__(self, app: FastAPI) -> None:
|
||||
""" Инициализируем приложение FastAPI и список допустимых CORS-оригинов """
|
||||
self.app = app
|
||||
self.origins = [
|
||||
"http://localhost.tiangolo.com",
|
||||
"https://localhost.tiangolo.com",
|
||||
"http://localhost",
|
||||
"http://localhost:8080",
|
||||
"http://localhost:5174",
|
||||
"http://localhost:5173",
|
||||
]
|
||||
|
||||
def add_cors_middleware(self) -> None:
|
||||
""" Добавляем CORS в приложение FastAPI """
|
||||
self.app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=self.origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
35
SRV/config/init_config.py
Normal file
35
SRV/config/init_config.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# init_config.py
|
||||
import configparser
|
||||
import os
|
||||
import secrets
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def init_config():
|
||||
"""Создаёт конфигурационный файл с SECRET_KEY"""
|
||||
config_path = "/etc/gonets/config.ini"
|
||||
config_dir = os.path.dirname(config_path)
|
||||
|
||||
if os.path.exists(config_path):
|
||||
logger.info(f"Конфигурационный файл {config_path} уже существует, пропускаем инициализацию")
|
||||
return
|
||||
|
||||
try:
|
||||
secret_key = secrets.token_urlsafe(32)
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
config = configparser.ConfigParser()
|
||||
config["JWT"] = {
|
||||
"secret_key": secret_key
|
||||
}
|
||||
with open(config_path, "w") as config_file:
|
||||
config.write(config_file)
|
||||
os.chmod(config_path, 0o600)
|
||||
logger.info(f"Создан конфигурационный файл {config_path}")
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка при создании конфигурационного файла: {type(e).__name__} - {str(e)}")
|
||||
raise
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_config()
|
||||
107
SRV/config/ports.py
Normal file
107
SRV/config/ports.py
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
from typing import Dict, List
|
||||
|
||||
|
||||
class PortConfig:
|
||||
"""Конфигурация портов для сетевого сканирования."""
|
||||
|
||||
_DEFAULT_PORTS: Dict[int, str] = {
|
||||
20: "FTP (Data)",
|
||||
21: "FTP (Control)",
|
||||
22: "SSH",
|
||||
23: "Telnet",
|
||||
25: "SMTP",
|
||||
53: "DNS",
|
||||
67: "DHCP (Server)",
|
||||
68: "DHCP (Client)",
|
||||
69: "TFTP",
|
||||
80: "HTTP",
|
||||
110: "POP3",
|
||||
123: "NTP (Network Time Protocol)",
|
||||
137: "NetBIOS Name Service",
|
||||
138: "NetBIOS Datagram Service",
|
||||
139: "NetBIOS Session Service",
|
||||
143: "IMAP",
|
||||
161: "SNMP",
|
||||
162: "SNMP Trap",
|
||||
179: "BGP (Border Gateway Protocol)",
|
||||
443: "HTTPS",
|
||||
445: "SMB (Microsoft-DS)",
|
||||
465: "SMTPS",
|
||||
514: "Syslog (UDP)",
|
||||
515: "LPD (Printer)",
|
||||
587: "SMTP Submission",
|
||||
631: "IPP (Printing)",
|
||||
993: "IMAPS",
|
||||
995: "POP3S",
|
||||
|
||||
# --- Базы данных ---
|
||||
1433: "Microsoft SQL Server",
|
||||
1521: "Oracle DB",
|
||||
3306: "MySQL/MariaDB",
|
||||
5432: "PostgreSQL",
|
||||
6379: "Redis",
|
||||
27017: "MongoDB",
|
||||
|
||||
# --- VPN и удалённый доступ ---
|
||||
1723: "PPTP VPN",
|
||||
1701: "L2TP",
|
||||
500: "IPSec",
|
||||
4500: "IPSec NAT-T",
|
||||
1194: "OpenVPN",
|
||||
3389: "RDP (Remote Desktop Protocol)",
|
||||
5900: "VNC",
|
||||
|
||||
# --- Прокси / Веб ---
|
||||
1080: "SOCKS Proxy",
|
||||
8000: "HTTP-Alt",
|
||||
8080: "HTTP Proxy",
|
||||
8443: "HTTPS-Alt",
|
||||
|
||||
# --- DevOps / Monitoring / Tools ---
|
||||
9000: "SonarQube / PHP-FPM",
|
||||
9100: "Prometheus Node Exporter",
|
||||
9200: "Elasticsearch HTTP",
|
||||
9300: "Elasticsearch Cluster",
|
||||
11211: "Memcached",
|
||||
|
||||
# --- Прочее ---
|
||||
6667: "IRC",
|
||||
4000: "ICQ / Custom apps",
|
||||
25565: "Minecraft Server",
|
||||
53: "DNS (UDP & TCP)",
|
||||
}
|
||||
|
||||
def __init__(self, custom_ports: Dict[int, str] = None):
|
||||
"""
|
||||
Инициализирует конфигурацию портов.
|
||||
|
||||
Args:
|
||||
custom_ports: Пользовательский словарь портов для добавления или переопределения.
|
||||
"""
|
||||
self._ports = self._DEFAULT_PORTS.copy()
|
||||
if custom_ports:
|
||||
self._ports.update(custom_ports)
|
||||
|
||||
def get_port_name(self, port: int) -> str:
|
||||
"""
|
||||
Возвращает название сервиса для указанного порта.
|
||||
|
||||
Args:
|
||||
port: Номер порта.
|
||||
|
||||
Returns:
|
||||
Название сервиса или строка вида 'Port-<port>'.
|
||||
"""
|
||||
return self._ports.get(port, f"Port-{port}")
|
||||
|
||||
def get_ports(self) -> List[int]:
|
||||
"""
|
||||
Возвращает список всех номеров портов.
|
||||
|
||||
Returns:
|
||||
Список номеров портов.
|
||||
"""
|
||||
return list(self._ports.keys())
|
||||
|
||||
|
||||
port_config = PortConfig()
|
||||
Loading…
Add table
Add a link
Reference in a new issue