Files
v2ray-proxy/src/parser/mod.rs

50 lines
1.5 KiB
Rust
Raw Normal View History

2023-11-07 16:36:30 +03:30
use crate::config_models;
2023-11-09 12:41:09 +03:30
use crate::utils::inbound_generator;
use std::process::exit;
2023-10-26 17:31:33 +03:30
mod uri_identifier;
2023-10-10 16:21:20 +03:30
mod vless;
2023-10-26 17:31:33 +03:30
2025-07-26 19:25:55 +03:30
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {
let config = create_config(uri, socks_port, http_port);
2023-10-26 17:31:33 +03:30
let serialized = serde_json::to_string(&config).unwrap();
return serialized;
}
2025-07-26 19:25:55 +03:30
pub fn create_config(
uri: &str,
socks_port: Option<u16>,
http_port: Option<u16>,
) -> config_models::Config {
2023-10-26 17:31:33 +03:30
let outbound_object = create_outbound_object(uri);
2023-11-08 19:51:21 +03:30
let inbound_config =
2023-11-09 12:41:09 +03:30
inbound_generator::generate_inbound_config(inbound_generator::InboundGenerationOptions {
2023-11-08 19:51:21 +03:30
socks_port,
2025-07-26 19:25:55 +03:30
http_port,
2023-11-08 19:51:21 +03:30
});
2023-11-07 16:36:30 +03:30
let config = config_models::Config {
2023-10-26 17:31:33 +03:30
outbounds: vec![outbound_object],
2023-11-08 19:51:21 +03:30
inbounds: inbound_config,
2023-10-26 17:31:33 +03:30
};
return config;
}
2023-11-07 16:36:30 +03:30
pub fn create_outbound_object(uri: &str) -> config_models::Outbound {
let protocol = uri_identifier::get_uri_protocol(uri);
match protocol {
2023-10-20 17:14:56 +03:30
Some(uri_identifier::Protocols::Vless) => {
2025-07-26 16:49:47 +03:30
let vless_data = vless::data::get_data(uri);
2023-10-20 17:14:56 +03:30
let outbound_object = vless::create_outbound_object(vless_data);
2023-10-26 17:31:33 +03:30
return outbound_object;
2023-10-20 17:14:56 +03:30
}
Some(_) => {
2023-10-23 19:16:58 +03:30
println!("The protocol was recognized but is not supported yet");
exit(0);
}
None => {
println!("The protcol is not supported");
exit(0);
}
2023-10-09 17:59:25 +03:30
}
2023-10-08 21:11:49 +03:30
}