Files
rengine/shared/models/proxy.py
T
Yogesh Ojha a548afffa2 feat(settings): tables that save on change, Users, sheets on their pages
Settings has six tabs: General, API keys, Proxies, Notifications, AI and
Users. Each tab is one card whose controls save on change; list tabs are
tables with a row menu and their Add action in the tab row. A non-admin
sees General and AI, read-only.

Out-of-band testing is the Callback server sheet on the Arsenal Nuclei
tab, with a Need a callback count that filters the library to the same
rows. Bounty Hub settings are a sheet on the Bounty Hub page. The old
settings routes redirect to both.

- API keys store the last test result on the row and clear it when the
  key changes. Providers report whether a test exists. The usage count
  is gone: only ViewDNS ever incremented it.
- Notification channels store the last delivery, written by the
  notifier on its own connection. A channel offers the seven event
  types the product emits, program changes on by default, and levels
  named All events, Warning and critical, Critical only.
- A default proxy applies to a scan launched without a context and is
  preselected for new contexts. A pool hands each scan one endpoint,
  proxy URLs bracket IPv6 hosts, and deleting a proxy clears it from
  its contexts.
- Users can be added with a role, disabled and promoted. An account
  cannot change itself, and one that owns records answers 409.
- Retention windows are validated and include keep forever. The
  instance name cannot be blank and names every page title.
- The AI list drops the two switches nothing read; each feature states
  what it sends. The out-of-band Off help says the checks are skipped.

Connectors, Bounty Hub and Remote control lose their extra page
padding. Migration 5d2e9a8c1b47 adds the test and delivery columns and
drops proxies.mode.

Claude-Session: https://claude.ai/code/session_01RVAHQxZ7JAkoEiTCDiHYue
2026-09-27 10:01:19 +05:30

92 lines
2.5 KiB
Python

import uuid
from datetime import datetime
from functools import partial
from pydantic import BaseModel, field_validator
from sqlmodel import Field, SQLModel
from shared.enums.proxy import ProxyProtocol
from shared.utils.datetime import utc_now
from shared.utils.validation import clean_name, clean_optional_name
PROXY_SCHEMES = tuple(p.value for p in ProxyProtocol)
class ProxyEndpoint(BaseModel):
scheme: str
host: str
port: int
username: str | None = None
password: str | None = None
class Proxy(SQLModel, table=True):
__tablename__ = "proxies"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
name: str = Field(max_length=120)
description: str | None = Field(default=None, max_length=500)
is_active: bool = Field(default=True)
is_default: bool = Field(default=False)
endpoints_encrypted: str
endpoint_count: int = Field(default=0)
created_by: uuid.UUID = Field(foreign_key="users.id")
created_at: datetime = Field(default_factory=utc_now)
updated_at: datetime = Field(default_factory=utc_now)
last_test_at: datetime | None = Field(default=None)
last_test_ok: bool | None = Field(default=None)
last_test_message: str | None = Field(default=None)
class ProxyEndpointRead(BaseModel):
scheme: str
host: str
port: int
username: str | None = None
has_password: bool
url_masked: str
class ProxyCreate(BaseModel):
name: str
description: str | None = None
is_active: bool = True
is_default: bool = False
endpoints: list[ProxyEndpoint] = Field(min_length=1)
_validate_name = field_validator("name")(clean_name)
class ProxyUpdate(BaseModel):
name: str | None = None
description: str | None = None
is_active: bool | None = None
is_default: bool | None = None
endpoints: list[ProxyEndpoint] | None = None
_validate_name = field_validator("name")(partial(clean_optional_name, max_len=120))
class ProxyRead(BaseModel):
id: uuid.UUID
name: str
description: str | None
is_active: bool
is_default: bool
endpoints: list[ProxyEndpointRead]
endpoint_count: int
contexts: int = 0
created_at: datetime
updated_at: datetime
last_test_at: datetime | None
last_test_ok: bool | None
last_test_message: str | None
class ProxyTestResult(BaseModel):
success: bool
message: str
latency_ms: int | None = None
# false when the port answered but the proxy did not carry the request
reachable: bool = False