mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-21 07:41:28 +02:00
- Implemented TargetEnrichmentStage for enriching targets with DNS, WHOIS, and BGP context. - Added VhostStage for virtual host discovery using host-header fuzzing. - Introduced WafDetectStage for fingerprinting web application firewalls. - Created configuration files for each new stage with relevant parameters. - Updated Dockerfile to copy stages instead of engines. - Enhanced existing tools and services for better integration with new stages. - Refactored task management in Celery to accommodate new stages and improve error handling.
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
|
from sqlalchemy import Text
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlmodel import Column, SQLModel
|
|
from sqlmodel import Field as SQLField
|
|
|
|
from shared.enums.notification import NotificationSeverity, NotificationType
|
|
from shared.utils.datetime import utc_now
|
|
|
|
MAX_URL_LENGTH = 500
|
|
|
|
|
|
class NotificationMetadata(BaseModel):
|
|
url: str | None = None
|
|
open_new_tab: bool = False
|
|
scan_id: str | None = None
|
|
target_id: str | None = None
|
|
action_label: str | None = Field(default=None, max_length=50)
|
|
|
|
@field_validator("url")
|
|
@classmethod
|
|
def validate_url(cls, v: str | None) -> str | None:
|
|
if v is None:
|
|
return v
|
|
if (
|
|
not v.startswith("/")
|
|
and not v.startswith("http://")
|
|
and not v.startswith("https://")
|
|
):
|
|
msg = "URL must be relative (start with /) or absolute (http/https)"
|
|
raise ValueError(msg)
|
|
if len(v) > MAX_URL_LENGTH:
|
|
msg = f"URL too long (max {MAX_URL_LENGTH} characters)"
|
|
raise ValueError(msg)
|
|
return v
|
|
|
|
|
|
class NotificationBase(SQLModel):
|
|
type: NotificationType
|
|
severity: NotificationSeverity
|
|
title: str = SQLField(max_length=200)
|
|
message: str = SQLField(sa_column=Column(Text))
|
|
|
|
|
|
class Notification(NotificationBase, table=True):
|
|
__tablename__ = "notifications"
|
|
|
|
id: int = SQLField(default=None, primary_key=True, index=True)
|
|
notification_metadata: dict = SQLField(
|
|
default_factory=dict, sa_column=Column(JSONB)
|
|
)
|
|
is_read: bool = SQLField(default=False, index=True)
|
|
created_at: datetime = SQLField(default_factory=utc_now, index=True)
|
|
expires_at: datetime = SQLField(
|
|
default_factory=lambda: utc_now() + timedelta(days=7),
|
|
index=True,
|
|
)
|
|
|
|
|
|
class NotificationCreate(NotificationBase):
|
|
notification_metadata: NotificationMetadata | None = None
|
|
|
|
|
|
class NotificationRead(NotificationBase):
|
|
id: int
|
|
notification_metadata: dict
|
|
is_read: bool
|
|
created_at: datetime
|
|
expires_at: datetime
|
|
|
|
|
|
class NotificationStats(BaseModel):
|
|
total: int
|
|
unread: int
|