mirror of
https://github.com/house-of-vanity/v2-uri-parser.git
synced 2025-12-16 15:07:53 +00:00
@@ -165,7 +165,7 @@ pub struct Inbound {
|
|||||||
pub listen: String,
|
pub listen: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub protocol: String,
|
pub protocol: String,
|
||||||
pub settings: InboundSettings,
|
pub settings: Option<InboundSettings>,
|
||||||
pub sniffing: Option<SniffingSettings>,
|
pub sniffing: Option<SniffingSettings>,
|
||||||
pub tag: String,
|
pub tag: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ struct Cli {
|
|||||||
uri: String,
|
uri: String,
|
||||||
#[arg(short, long, value_name = "socksport")]
|
#[arg(short, long, value_name = "socksport")]
|
||||||
socksport: Option<u16>,
|
socksport: Option<u16>,
|
||||||
|
#[arg(long, value_name = "httpport")]
|
||||||
|
httpport: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let json_config = parser::create_json_config(&cli.uri, cli.socksport);
|
let json_config = parser::create_json_config(&cli.uri, cli.socksport, cli.httpport);
|
||||||
println!("{}", json_config);
|
println!("{}", json_config);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,22 @@ use std::process::exit;
|
|||||||
mod uri_identifier;
|
mod uri_identifier;
|
||||||
mod vless;
|
mod vless;
|
||||||
|
|
||||||
pub fn create_json_config(uri: &str, socks_port: Option<u16>) -> String {
|
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {
|
||||||
let config = create_config(uri, socks_port);
|
let config = create_config(uri, socks_port, http_port);
|
||||||
let serialized = serde_json::to_string(&config).unwrap();
|
let serialized = serde_json::to_string(&config).unwrap();
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_config(uri: &str, socks_port: Option<u16>) -> config_models::Config {
|
pub fn create_config(
|
||||||
|
uri: &str,
|
||||||
|
socks_port: Option<u16>,
|
||||||
|
http_port: Option<u16>,
|
||||||
|
) -> config_models::Config {
|
||||||
let outbound_object = create_outbound_object(uri);
|
let outbound_object = create_outbound_object(uri);
|
||||||
let inbound_config =
|
let inbound_config =
|
||||||
inbound_generator::generate_inbound_config(inbound_generator::InboundGenerationOptions {
|
inbound_generator::generate_inbound_config(inbound_generator::InboundGenerationOptions {
|
||||||
socks_port,
|
socks_port,
|
||||||
|
http_port,
|
||||||
});
|
});
|
||||||
let config = config_models::Config {
|
let config = config_models::Config {
|
||||||
outbounds: vec![outbound_object],
|
outbounds: vec![outbound_object],
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::config_models;
|
|||||||
|
|
||||||
pub struct InboundGenerationOptions {
|
pub struct InboundGenerationOptions {
|
||||||
pub socks_port: Option<u16>,
|
pub socks_port: Option<u16>,
|
||||||
|
pub http_port: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_inbound_config(options: InboundGenerationOptions) -> Vec<config_models::Inbound> {
|
pub fn generate_inbound_config(options: InboundGenerationOptions) -> Vec<config_models::Inbound> {
|
||||||
@@ -12,16 +13,24 @@ pub fn generate_inbound_config(options: InboundGenerationOptions) -> Vec<config_
|
|||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match options.http_port {
|
||||||
|
Some(port) => {
|
||||||
|
inbounds.push(generate_http_inbound(port));
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
return inbounds;
|
return inbounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_socks_inbound(socks_port: u16) -> config_models::Inbound {
|
pub fn generate_http_inbound(http_port: u16) -> config_models::Inbound {
|
||||||
return config_models::Inbound {
|
return config_models::Inbound {
|
||||||
protocol: String::from("socks"),
|
protocol: String::from("http"),
|
||||||
port: socks_port,
|
port: http_port,
|
||||||
tag: String::from("socks-in"),
|
tag: String::from("http-in"),
|
||||||
|
settings: None,
|
||||||
listen: String::from("127.0.0.1"),
|
listen: String::from("127.0.0.1"),
|
||||||
settings: config_models::InboundSettings { udp: true },
|
|
||||||
sniffing: Some(config_models::SniffingSettings {
|
sniffing: Some(config_models::SniffingSettings {
|
||||||
enabled: Some(true),
|
enabled: Some(true),
|
||||||
routeOnly: Some(true),
|
routeOnly: Some(true),
|
||||||
@@ -36,29 +45,23 @@ pub fn generate_socks_inbound(socks_port: u16) -> config_models::Inbound {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
pub fn generate_socks_inbound(socks_port: u16) -> config_models::Inbound {
|
||||||
mod test {
|
return config_models::Inbound {
|
||||||
use super::*;
|
protocol: String::from("socks"),
|
||||||
#[test]
|
port: socks_port,
|
||||||
fn test_generate_socks_inboud() {
|
tag: String::from("socks-in"),
|
||||||
let socks_inbound = generate_socks_inbound(2080);
|
listen: String::from("127.0.0.1"),
|
||||||
assert_eq!(socks_inbound.protocol, String::from("socks"));
|
settings: Some(config_models::InboundSettings { udp: true }),
|
||||||
assert_eq!(socks_inbound.listen, String::from("127.0.0.1"));
|
sniffing: Some(config_models::SniffingSettings {
|
||||||
assert_eq!(socks_inbound.tag, String::from("socks-in"));
|
enabled: Some(true),
|
||||||
assert_eq!(socks_inbound.port, 2080);
|
routeOnly: Some(true),
|
||||||
assert_eq!(socks_inbound.settings.udp, true);
|
metadataOnly: Some(false),
|
||||||
|
domainsExcluded: None,
|
||||||
let sniffing_obj = socks_inbound.sniffing.unwrap();
|
destOverride: Some(vec![
|
||||||
assert_eq!(sniffing_obj.enabled, Some(true));
|
|
||||||
assert_eq!(sniffing_obj.routeOnly, Some(true));
|
|
||||||
assert_eq!(sniffing_obj.domainsExcluded, None);
|
|
||||||
assert_eq!(
|
|
||||||
sniffing_obj.destOverride,
|
|
||||||
Some(vec![
|
|
||||||
String::from("http"),
|
String::from("http"),
|
||||||
String::from("tls"),
|
String::from("tls"),
|
||||||
String::from("quic"),
|
String::from("quic"),
|
||||||
])
|
]),
|
||||||
);
|
}),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user