Skip to content

Commit

Permalink
Merge pull request #1 from parhawm/tmp
Browse files Browse the repository at this point in the history
added path to host settings, in db, front and backend
  • Loading branch information
parhawm authored Dec 15, 2023
2 parents ef04e53 + 5e6ebaf commit 0a04f02
Show file tree
Hide file tree
Showing 9 changed files with 729 additions and 585 deletions.
4 changes: 3 additions & 1 deletion app/dashboard/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@
"hostsDialog.security": "Security Layer",
"hostsDialog.host": "Request Host",
"hostsDialog.port": "Port",
"hostsDialog.path": "Path",
"hostsDialog.sni": "SNI",
"hostsDialog.advancedOptions": "Advanced options",
"hostsDialog.addHost": "Add host",
"hostsDialog.savedSuccess": "Hosts saved successfully",
"hostsDialog.loading": "loading...",
"hostsDialog.apply": "Apply",
"hostsDialog.port.info": "By default, a host uses the default port of the inbound. You can set a custom port in case this host is a server that forwards traffic from a port that differs from your server's port. For example, the server may forward traffic from port 8443 to the default port of your inbound server.",
"hostsDialog.path.info": "Set a path for host users, useful behind a reverse proxy.",
"hostsDialog.sni.info": "By default, a host uses the default SNI of the inbound. You can set a custom SNI in case this host is a server that has a different SNI. For example, the server may receive traffic with a different SSL certificate, perform SSL termination, and forward it to your inbound server.",
"hostsDialog.host.info": "By default, if a request host is set in the Xray config, this host is used. However, you can set a custom request host here if needed.",
"hostsDialog.security.info": "If the middleware server of this host uses a different security layer than the inbound's default, you can set a custom security layer here.",
Expand Down Expand Up @@ -157,4 +159,4 @@
"core.configuration": "Configuration",
"core.generalErrorMessage": "Something went wrong, please check the configuration",
"core.successMessage": "Core settings updated successfully"
}
}
198 changes: 121 additions & 77 deletions app/dashboard/src/components/HostsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ const hostsSchema = z.record(
return Number(parseInt(value));
return null;
}),
path: z.string().nullable(),
sni: z.string().nullable(),
host: z.string().nullable(),
security: z.string(),
alpn: z.string(),
fingerprint: z.string(),
})
)
}),
),
);

const Error = chakra(FormErrorMessage, {
Expand Down Expand Up @@ -159,6 +160,7 @@ const AccordionInbound: FC<AccordionInboundType> = ({
host: "",
sni: "",
port: null,
path: null,
address: "",
remark: "",
security: "inbound_default",
Expand Down Expand Up @@ -236,11 +238,11 @@ const AccordionInbound: FC<AccordionInboundType> = ({
<Box fontSize="xs">
<Text pr="20px">{t("hostsDialog.desc")}</Text>
<Text>
<Badge>
{"{"}SERVER_IP{"}"}
</Badge>{" "}
{t("hostsDialog.currentServer")}
</Text>
<Badge>
{"{"}SERVER_IP{"}"}
</Badge>{" "}
{t("hostsDialog.currentServer")}
</Text>
<Text mt={1}>
<Badge>
{"{"}USERNAME{"}"}
Expand Down Expand Up @@ -344,79 +346,79 @@ const AccordionInbound: FC<AccordionInboundType> = ({
<PopoverCloseButton />
<PopoverBody>
<Box fontSize="xs">
<Text pr="20px">{t("hostsDialog.desc")}</Text>
<Text>
<Text pr="20px">{t("hostsDialog.desc")}</Text>
<Text>
<Badge>
{"{"}SERVER_IP{"}"}
</Badge>{" "}
{t("hostsDialog.currentServer")}
</Text>
<Text mt={1}>
<Badge>
{"{"}USERNAME{"}"}
</Badge>{" "}
{t("hostsDialog.username")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DATA_USAGE{"}"}
</Badge>{" "}
{t("hostsDialog.dataUsage")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DATA_LEFT{"}"}
</Badge>{" "}
{t("hostsDialog.remainingData")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DATA_LIMIT{"}"}
</Badge>{" "}
{t("hostsDialog.dataLimit")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DAYS_LEFT{"}"}
</Badge>{" "}
{t("hostsDialog.remainingDays")}
</Text>
<Text mt={1}>
<Badge>
{"{"}EXPIRE_DATE{"}"}
</Badge>{" "}
{t("hostsDialog.expireDate")}
</Text>
<Text mt={1}>
<Badge>
{"{"}JALALI_EXPIRE_DATE{"}"}
</Badge>{" "}
{t("hostsDialog.jalaliExpireDate")}
</Text>
<Text mt={1}>
<Badge>
{"{"}TIME_LEFT{"}"}
</Badge>{" "}
{t("hostsDialog.remainingTime")}
</Text>
<Text mt={1}>
<Badge>
{"{"}STATUS_EMOJI{"}"}
</Badge>{" "}
{t("hostsDialog.statusEmoji")}
</Text>
<Text mt={1}>
<Badge>
{"{"}PROTOCOL{"}"}
</Badge>{" "}
{t("hostsDialog.proxyProtocol")}
</Text>
<Text mt={1}>
<Badge>
{"{"}TRANSPORT{"}"}
</Badge>{" "}
{t("hostsDialog.proxyMethod")}
</Text>
<Text mt={1}>
<Badge>
{"{"}USERNAME{"}"}
</Badge>{" "}
{t("hostsDialog.username")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DATA_USAGE{"}"}
</Badge>{" "}
{t("hostsDialog.dataUsage")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DATA_LEFT{"}"}
</Badge>{" "}
{t("hostsDialog.remainingData")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DATA_LIMIT{"}"}
</Badge>{" "}
{t("hostsDialog.dataLimit")}
</Text>
<Text mt={1}>
<Badge>
{"{"}DAYS_LEFT{"}"}
</Badge>{" "}
{t("hostsDialog.remainingDays")}
</Text>
<Text mt={1}>
<Badge>
{"{"}EXPIRE_DATE{"}"}
</Badge>{" "}
{t("hostsDialog.expireDate")}
</Text>
<Text mt={1}>
<Badge>
{"{"}JALALI_EXPIRE_DATE{"}"}
</Badge>{" "}
{t("hostsDialog.jalaliExpireDate")}
</Text>
<Text mt={1}>
<Badge>
{"{"}TIME_LEFT{"}"}
</Badge>{" "}
{t("hostsDialog.remainingTime")}
</Text>
<Text mt={1}>
<Badge>
{"{"}STATUS_EMOJI{"}"}
</Badge>{" "}
{t("hostsDialog.statusEmoji")}
</Text>
<Text mt={1}>
<Badge>
{"{"}PROTOCOL{"}"}
</Badge>{" "}
{t("hostsDialog.proxyProtocol")}
</Text>
<Text mt={1}>
<Badge>
{"{"}TRANSPORT{"}"}
</Badge>{" "}
{t("hostsDialog.proxyMethod")}
</Text>
</Box>
</PopoverBody>
</PopoverContent>
Expand Down Expand Up @@ -612,6 +614,48 @@ const AccordionInbound: FC<AccordionInboundType> = ({
<Error>{accordionErrors[index]?.host?.message}</Error>
)}
</FormControl>

<FormControl
isInvalid={
!!(accordionErrors && accordionErrors[index]?.path)
}
>
<FormLabel
display="flex"
pb={1}
alignItems="center"
gap={1}
justifyContent="space-between"
m="0"
>
<span>{t("hostsDialog.path")}</span>

<Popover isLazy placement="right">
<PopoverTrigger>
<InfoIcon />
</PopoverTrigger>
<Portal>
<PopoverContent p={2}>
<PopoverArrow />
<PopoverCloseButton />
<Text fontSize="xs" pr={5}>
{t("hostsDialog.path.info")}
</Text>
</PopoverContent>
</Portal>
</Popover>
</FormLabel>
<Input
size="sm"
borderRadius="4px"
placeholder="path (e.g. /vless)"
{...form.register(hostKey + "." + index + ".path")}
/>
{accordionErrors && accordionErrors[index]?.path && (
<Error>{accordionErrors[index]?.path?.message}</Error>
)}
</FormControl>

<FormControl height="66px">
<FormLabel
display="flex"
Expand Down Expand Up @@ -641,7 +685,7 @@ const AccordionInbound: FC<AccordionInboundType> = ({
<Select
size="sm"
{...form.register(
hostKey + "." + index + ".security"
hostKey + "." + index + ".security",
)}
>
{proxyHostSecurity.map((s) => {
Expand Down Expand Up @@ -693,7 +737,7 @@ const AccordionInbound: FC<AccordionInboundType> = ({
<Select
size="sm"
{...form.register(
hostKey + "." + index + ".fingerprint"
hostKey + "." + index + ".fingerprint",
)}
>
{proxyFingerprint.map((s) => {
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/src/contexts/HostsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type HostsSchema = Record<
remark: string;
address: string;
port: number | null;
path: string | null;
sni: string | null;
host: string | null;
}[]
Expand Down
6 changes: 4 additions & 2 deletions app/db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def add_host(db: Session, inbound_tag: str, host: ProxyHostModify):
remark=host.remark,
address=host.address,
port=host.port,
path=host.path,
sni=host.sni,
host=host.host,
inbound=inbound,
Expand All @@ -73,6 +74,7 @@ def update_hosts(db: Session, inbound_tag: str, modified_hosts: List[ProxyHostMo
remark=host.remark,
address=host.address,
port=host.port,
path=host.path,
sni=host.sni,
host=host.host,
inbound=inbound,
Expand Down Expand Up @@ -266,7 +268,7 @@ def update_user(db: Session, dbuser: User, modify: UserModify):
if not dbuser.data_limit or dbuser.used_traffic < dbuser.data_limit:
if dbuser.status != UserStatus.on_hold:
dbuser.status = UserStatus.active

if not dbuser.data_limit or (calculate_usage_percent(
dbuser.used_traffic, dbuser.data_limit) < NOTIFY_REACHED_USAGE_PERCENT):
delete_notification_reminder_by_type(db, dbuser.id, ReminderType.data_usage)
Expand Down Expand Up @@ -377,7 +379,7 @@ def set_owner(db: Session, dbuser: User, admin: Admin):

def start_user_expire(db: Session, dbuser: User):

expire = int(datetime.utcnow().timestamp()) + dbuser.on_hold_expire_duration
expire = int(datetime.utcnow().timestamp()) + dbuser.on_hold_expire_duration
dbuser.expire = expire
db.commit()
db.refresh(dbuser)
Expand Down
26 changes: 26 additions & 0 deletions app/db/migrations/versions/470465472326_add_path_to_hosts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""add path to hosts
Revision ID: 470465472326
Revises: e56f1c781e46
Create Date: 2023-12-15 05:46:43.493605
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '470465472326'
down_revision = 'e56f1c781e46'
branch_labels = None
depends_on = None


def upgrade() -> None:
with op.batch_alter_table('hosts') as batch_op:
batch_op.add_column(sa.Column('path', sa.String(256), nullable=True))


def downgrade() -> None:
with op.batch_alter_table('hosts') as batch_op:
batch_op.drop_column('path')
1 change: 1 addition & 0 deletions app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class ProxyHost(Base):
remark = Column(String(256), unique=False, nullable=False)
address = Column(String(256), unique=False, nullable=False)
port = Column(Integer, nullable=True)
path = Column(String(256), unique=False, nullable=True)
sni = Column(String(256), unique=False, nullable=True)
host = Column(String(256), unique=False, nullable=True)
security = Column(
Expand Down
1 change: 1 addition & 0 deletions app/models/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class ProxyHost(BaseModel):
port: Optional[int] = Field(None, nullable=True)
sni: Optional[str] = Field(None, nullable=True)
host: Optional[str] = Field(None, nullable=True)
path: Optional[str] = Field(None, nullable=True)
security: ProxyHostSecurity = ProxyHostSecurity.inbound_default
alpn: ProxyHostALPN = ProxyHostALPN.none
fingerprint: ProxyHostFingerprint = ProxyHostFingerprint.none
Expand Down
Loading

0 comments on commit 0a04f02

Please sign in to comment.