diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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<AllowedIpsFieldProps> = () => {
+ const { t } = useTranslation();
+ const form = useFormContext();
+ return (
+ <FormField
+ control={form.control}
+ name="allowed_ips"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>{t("page.hosts.allowed-ips")}</FormLabel>
+ <FormControl>
+ <Textarea
+ placeholder={t("page.hosts.allowed-ips-placeholder")}
+ className="resize-none"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ );
+};
diff --git a/dashboard/src/modules/hosts/dialogs/mutation/fields/index.ts b/dashboard/src/modules/hosts/dialogs/mutation/fields/index.ts
@@ -14,3 +14,4 @@ export * from './weight'
export * from './common-fields'
export * from './mtu'
export * from './dns-servers'
+export * from './allowed-ips'
diff --git a/dashboard/src/modules/hosts/dialogs/mutation/profiles/wireguard/index.tsx b/dashboard/src/modules/hosts/dialogs/mutation/profiles/wireguard/index.tsx
@@ -2,6 +2,7 @@ import {
CommonFields,
MtuField,
DNSServersField,
+ AllowedIpsField,
PathField,
} from "../../fields";
import {
@@ -23,6 +24,7 @@ export const WireguardProfileFields = () => {
<MtuField />
</HStack>
<DNSServersField />
+ <AllowedIpsField />
</SettingSection>
</Accordion>
</>
diff --git a/dashboard/src/modules/hosts/dialogs/mutation/profiles/wireguard/schema.ts b/dashboard/src/modules/hosts/dialogs/mutation/profiles/wireguard/schema.ts
@@ -3,6 +3,7 @@ import { HostSchema } from "@marzneshin/modules/hosts";
export const WireguardSchema = HostSchema.extend({
path: z.string().nullable().optional(),
+ allowed_ips: z.string().nullable().optional(),
mtu: z.coerce
.number()
.or(z.string())
diff --git a/requirements.txt b/requirements.txt
@@ -23,7 +23,7 @@ aiohttp==3.10.2
xxhash==3.4.1
grpcio==1.65.4
psycopg==3.1.18
-v2share==0.1.0b23
+v2share==0.1.0b24
PyJWT~=2.8.0
PyNaCl==1.5.0
starlette==0.40.0