diff --git a/app/db/crud.py b/app/db/crud.py index 417106e..8c7d946 100644 --- a/app/db/crud.py +++ b/app/db/crud.py @@ -188,6 +188,7 @@ def add_host(db: Session, inbound: Inbound, host: InboundHostModify): http_headers=host.http_headers, mtu=host.mtu, dns_servers=host.dns_servers, + allowed_ips=host.allowed_ips, mux=host.mux, allowinsecure=host.allowinsecure, weight=host.weight, @@ -216,6 +217,7 @@ def update_host(db: Session, db_host: InboundHost, host: InboundHostModify): db_host.http_headers = host.http_headers db_host.mtu = host.mtu db_host.dns_servers = host.dns_servers + db_host.allowed_ips = host.allowed_ips db_host.weight = host.weight db.commit() db.refresh(db_host) diff --git a/app/db/migrations/versions/be0032100c07_add_allowed_ips_to_hosts.py b/app/db/migrations/versions/be0032100c07_add_allowed_ips_to_hosts.py new file mode 100644 index 0000000..dab0690 --- /dev/null +++ b/app/db/migrations/versions/be0032100c07_add_allowed_ips_to_hosts.py @@ -0,0 +1,31 @@ +"""add allowed_ips to hosts + +Revision ID: be0032100c07 +Revises: c97bd32e6e12 +Create Date: 2024-11-11 08:27:05.882157 + +""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "be0032100c07" +down_revision = "c97bd32e6e12" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "hosts", + sa.Column("allowed_ips", sa.String(length=16384), nullable=True), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("hosts", "allowed_ips") + # ### end Alembic commands ### diff --git a/app/db/models.py b/app/db/models.py index ebe261c..fbdc7f7 100644 --- a/app/db/models.py +++ b/app/db/models.py @@ -350,6 +350,7 @@ class InboundHost(Base): http_headers = Column(JSON()) dns_servers = Column(String(128)) mtu = Column(Integer) + allowed_ips = Column(String(16384)) inbound_id = Column(Integer, ForeignKey("inbounds.id"), nullable=False) inbound = relationship("Inbound", back_populates="hosts", lazy="joined") allowinsecure = Column(Boolean, default=False) diff --git a/app/models/proxy.py b/app/models/proxy.py index 6649181..8dfee0d 100644 --- a/app/models/proxy.py +++ b/app/models/proxy.py @@ -90,6 +90,7 @@ class InboundHost(BaseModel): http_headers: dict[str, list[str]] | None = {} mtu: int | None = None dns_servers: str | None = None + allowed_ips: str | None = None weight: int = 1 protocol: ProxyTypes | None = None inbound_id: int | None = None diff --git a/app/utils/share.py b/app/utils/share.py index c7538e7..ec546a7 100644 --- a/app/utils/share.py +++ b/app/utils/share.py @@ -303,6 +303,11 @@ def generate_user_configs( host.dns_servers.split(",") if host.dns_servers else [] ), mtu=host.mtu, + allowed_ips=( + list(map(str.strip, host.allowed_ips.split(","))) + if host.allowed_ips + else None + ), allow_insecure=host.allowinsecure, uuid=UUID(gen_uuid(key)), password=gen_password(key), diff --git a/dashboard/public/locales/en.json b/dashboard/public/locales/en.json index aeb9462..88ba371 100644 --- a/dashboard/public/locales/en.json +++ b/dashboard/public/locales/en.json @@ -272,6 +272,8 @@ "tls-config": "TLS Config", "network-settings": "Network Settings", "security-settings": "Security Settings", + "allowed-ips": "Allowed Ips", + "allowed-ips-placeholder": "127.0.0.1,...", "camouflage-settings": "Camouflage Settings", "fragment": { "interval": "Interval", diff --git a/dashboard/src/modules/hosts/dialogs/mutation/fields/allowed-ips.tsx b/dashboard/src/modules/hosts/dialogs/mutation/fields/allowed-ips.tsx new file mode 100644 index 0000000..67c816e --- /dev/null +++ b/dashboard/src/modules/hosts/dialogs/mutation/fields/allowed-ips.tsx @@ -0,0 +1,37 @@ +import { + FormControl, + FormField, + FormItem, + Textarea, + FormLabel, + FormMessage, +} from "@marzneshin/common/components"; +import { FC } from "react"; +import { useFormContext } from "react-hook-form"; +import { useTranslation } from "react-i18next"; + +interface AllowedIpsFieldProps { } + +export const AllowedIpsField: FC = () => { + const { t } = useTranslation(); + const form = useFormContext(); + return ( + ( + + {t("page.hosts.allowed-ips")} + +