diff --git a/app/db/crud.py b/app/db/crud.py
@@ -166,6 +166,7 @@ def add_host(db: Session, inbound: Inbound, host: InboundHostModify):
fingerprint=host.fingerprint,
fragment=host.fragment.model_dump() if host.fragment else None,
mux=host.mux,
+ allowinsecure=host.allowinsecure,
)
inbound.hosts.append(host)
db.commit()
@@ -186,6 +187,7 @@ def update_host(db: Session, db_host: InboundHost, host: InboundHostModify):
db_host.fragment = host.fragment.model_dump() if host.fragment else None
db_host.mux = host.mux
db_host.is_disabled = host.is_disabled
+ db_host.allowinsecure = host.allowinsecure
db.commit()
db.refresh(db_host)
return db_host
diff --git a/app/db/migrations/versions/c4fb5f6423a8_add_hysteria2_protocol_for_inbounds.py b/app/db/migrations/versions/c4fb5f6423a8_add_hysteria2_protocol_for_inbounds.py
@@ -0,0 +1,74 @@
+"""add hysteria2 protocol for inbounds
+
+Revision ID: c4fb5f6423a8
+Revises: 5410d8ec78ff
+Create Date: 2024-07-28 13:07:18.388141
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+enum_name = "proxytypes"
+temp_enum_name = f"temp_{enum_name}"
+old_values = ("VMess", "VLESS", "Trojan", "Shadowsocks")
+new_values = ("Hysteria2", *old_values)
+# on downgrade convert [0] to [1]
+downgrade_from = ["Hysteria2"]
+downgrade_to = "VLess"
+old_type = sa.Enum(*old_values, name=enum_name)
+new_type = sa.Enum(*new_values, name=enum_name)
+temp_type = sa.Enum(*new_values, name=temp_enum_name)
+
+
+# Describing of table
+table_name = "inbounds"
+column_name = "protocol"
+temp_table = sa.sql.table(
+ table_name, sa.Column(column_name, new_type, nullable=False)
+)
+
+
+# revision identifiers, used by Alembic.
+revision = "c4fb5f6423a8"
+down_revision = "5410d8ec78ff"
+branch_labels = None
+depends_on = None
+
+
+def upgrade() -> None:
+ # temp type to use instead of old one
+ temp_type.create(op.get_bind())
+
+ # changing of column type from old enum to new one.
+ # SQLite will create temp table for this
+ with op.batch_alter_table(table_name) as batch_op:
+ batch_op.alter_column(
+ column_name,
+ existing_type=old_type,
+ type_=temp_type,
+ existing_nullable=False,
+ postgresql_using=f"{column_name}::text::{temp_enum_name}",
+ )
+
+ # remove old enum, create new enum
+ old_type.drop(op.get_bind())
+ new_type.create(op.get_bind())
+
+ # changing of column type from temp enum to new one.
+ # SQLite will create temp table for this
+ with op.batch_alter_table(table_name) as batch_op:
+ batch_op.alter_column(
+ column_name,
+ existing_type=temp_type,
+ type_=new_type,
+ existing_nullable=False,
+ postgresql_using=f"{column_name}::text::{enum_name}",
+ )
+
+ # remove temp enum
+ temp_type.drop(op.get_bind())
+
+
+def downgrade() -> None:
+ pass
diff --git a/app/models/proxy.py b/app/models/proxy.py
@@ -11,6 +11,7 @@ class ProxyTypes(str, Enum):
VLESS = "vless"
Trojan = "trojan"
Shadowsocks = "shadowsocks"
+ Hysteria2 = "hysteria2"
class InboundHostSecurity(str, Enum):
diff --git a/app/utils/share.py b/app/utils/share.py
@@ -229,7 +229,9 @@ def generate_user_configs(
if not inbound:
continue
- format_variables.update({"TRANSPORT": inbound["network"]})
+ format_variables.update(
+ {"TRANSPORT": inbound.get("network", "<missing>")}
+ )
with GetDB() as db:
hosts = crud.get_inbound_hosts(db, inb_id)
@@ -237,14 +239,14 @@ def generate_user_configs(
if host.is_disabled:
continue
host_snis = host.sni.split(",") if host.sni else []
- sni_list = host_snis or inbound["sni"]
+ sni_list = host_snis or inbound.get("sni", [])
if sni_list:
sni = random.choice(sni_list).replace("*", salt)
else:
sni = ""
host_hosts = host.host.split(",") if host.host else []
- req_host_list = host_hosts or inbound["host"]
+ req_host_list = host_hosts or inbound.get("host", [])
if req_host_list:
req_host = random.choice(req_host_list).replace("*", salt)
else:
@@ -260,10 +262,10 @@ def generate_user_configs(
host.remark.format_map(format_variables),
host.address.format_map(format_variables),
host.port or inbound["port"],
- transport_type=inbound["network"],
+ transport_type=inbound.get("network"),
sni=sni,
host=req_host,
- tls=host_tls or inbound["tls"],
+ tls=host_tls or inbound.get("tls"),
header_type=inbound.get("header_type"),
alpn=host.alpn if host.alpn != "none" else None,
path=(
diff --git a/requirements.txt b/requirements.txt
@@ -34,5 +34,5 @@ python-multipart==0.0.7
xxhash==3.4.1
grpcio==1.60.0
psycopg==3.1.18
-v2share==0.1.0b10
+v2share==0.1.0b12
PyJWT~=2.8.0
\ No newline at end of file