models.ufw

class models.ufw.Action(*values)[source]

Bases: str, Enum

Enum для действий UFW.

Attributes:

ALLOW: Разрешить трафик DENY: Запретить трафик без уведомления REJECT: Запретить трафик с уведомлением отправителю

ALLOW = 'allow'
DENY = 'deny'
REJECT = 'reject'
class models.ufw.Direction(*values)[source]

Bases: str, Enum

Enum для направления трафика UFW.

Attributes:

IN: Входящий трафик OUT: Исходящий трафик

IN = 'in'
OUT = 'out'
class models.ufw.Protocol(*values)[source]

Bases: str, Enum

Enum для сетевых протоколов UFW.

BOTH = 'both'
TCP = 'tcp'
UDP = 'udp'
property protocols: List[str]

Возвращает список протоколов для использования в команде UFW.

class models.ufw.UFWRule(*, action: Action, direction: Direction, from_ip: str, to_ip: str, port: int | str, protocol: Protocol, comment: str | None = None)[source]

Bases: BaseModel

Модель правила UFW

action: Action
comment: str | None
direction: Direction
from_ip: str
classmethod from_ufw_output(line: str) → UFWRule[source]

Создает экземпляр UFWRule из строки вывода команды ‘ufw status numbered’.

Args:

line: Строка вывода UFW (например, “[1] 80/tcp ALLOW IN 192.168.1.0/24 # Web Server”)

Returns:

UFWRule: Новый экземпляр правила

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

port: int | str
protocol: Protocol
to_ip: str
to_ufw_command() → str[source]

Преобразует правило в команду UFW.

classmethod validate_action(v)[source]

Приводит значение action к нижнему регистру перед валидацией

classmethod validate_ip(v)[source]

Проверяет корректность IP адреса

classmethod validate_ip_version_compatibility(v, values)[source]

Проверяет совместимость версий IP адресов

classmethod validate_port(v)[source]

Проверяет корректность порта или диапазона портов.

Args:

v: Порт (число) или диапазон портов (строка вида “3000:3999”)

Returns:

Union[int, str]: Валидированное значение порта

Raises:

ValueError: Если порт или диапазон портов некорректен

classmethod validate_protocol(v)[source]

Приводит значение protocol к нижнему регистру перед валидацией

class models.ufw.UFWRulesResponse(*, enabled: bool, rules: ~typing.List[~models.ufw.UFWRule] = <factory>)[source]

Bases: BaseModel

Модель для представления списка правил UFW.

Attributes:

enabled: Включен ли UFW rules: Список правил UFW total_rules: Общее количество правил

enabled: bool
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

rules: List[UFWRule]
property total_rules: int

Возвращает общее количество правил.

class models.ufw.UFWStatus(*, enabled: bool, message: str)[source]

Bases: BaseModel

Модель для представления статуса UFW.

Attributes:

enabled: Включен ли UFW message: Сообщение о статусе last_checked: Время последней проверки статуса

enabled: bool
message: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].