Files
xray-proxy/src/utils/inbound_generator.rs

62 lines
1.8 KiB
Rust
Raw Normal View History

2023-11-08 19:51:21 +03:30
use crate::config_models;
pub struct InboundGenerationOptions {
pub socks_port: Option<u16>,
2025-07-26 19:25:55 +03:30
pub http_port: Option<u16>,
2023-11-08 19:51:21 +03:30
}
pub fn generate_inbound_config(options: InboundGenerationOptions) -> Vec<config_models::Inbound> {
let mut inbounds: Vec<config_models::Inbound> = vec![];
2025-12-01 01:48:36 +02:00
if let Some(port) = options.socks_port {
inbounds.push(generate_socks_inbound(port));
2023-11-08 19:51:21 +03:30
}
2025-07-26 19:25:55 +03:30
2025-12-01 01:48:36 +02:00
if let Some(port) = options.http_port {
inbounds.push(generate_http_inbound(port));
2025-07-26 19:25:55 +03:30
}
2025-12-01 01:48:36 +02:00
inbounds
2023-11-08 19:51:21 +03:30
}
2025-07-26 19:25:55 +03:30
pub fn generate_http_inbound(http_port: u16) -> config_models::Inbound {
2025-12-01 01:48:36 +02:00
config_models::Inbound {
2025-07-26 19:25:55 +03:30
protocol: String::from("http"),
port: http_port,
tag: String::from("http-in"),
settings: None,
2023-11-08 19:51:21 +03:30
listen: String::from("127.0.0.1"),
sniffing: Some(config_models::SniffingSettings {
enabled: Some(true),
routeOnly: Some(true),
metadataOnly: Some(false),
domainsExcluded: None,
destOverride: Some(vec![
String::from("http"),
String::from("tls"),
String::from("quic"),
]),
}),
2025-12-01 01:48:36 +02:00
}
2023-11-08 19:51:21 +03:30
}
2025-07-26 19:25:55 +03:30
pub fn generate_socks_inbound(socks_port: u16) -> config_models::Inbound {
2025-12-01 01:48:36 +02:00
config_models::Inbound {
2025-07-26 19:25:55 +03:30
protocol: String::from("socks"),
port: socks_port,
tag: String::from("socks-in"),
listen: String::from("127.0.0.1"),
settings: Some(config_models::InboundSettings { udp: true }),
sniffing: Some(config_models::SniffingSettings {
enabled: Some(true),
routeOnly: Some(true),
metadataOnly: Some(false),
domainsExcluded: None,
destOverride: Some(vec![
2023-11-08 19:51:21 +03:30
String::from("http"),
String::from("tls"),
String::from("quic"),
2025-07-26 19:25:55 +03:30
]),
}),
2025-12-01 01:48:36 +02:00
}
2023-11-08 19:51:21 +03:30
}