2025-07-27 16:27:11 +03:30
|
|
|
use clap::{value_parser, Arg, Command};
|
2023-11-07 16:36:30 +03:30
|
|
|
pub mod config_models;
|
2025-07-27 16:27:11 +03:30
|
|
|
mod parser;
|
2023-11-09 12:38:26 +03:30
|
|
|
pub mod utils;
|
2023-10-24 17:00:00 +03:30
|
|
|
|
2023-10-06 18:16:44 +03:30
|
|
|
fn main() {
|
2025-07-27 22:24:57 +03:30
|
|
|
let matches = Command::new("v2parser")
|
2025-07-28 18:12:48 +03:30
|
|
|
.version("0.3.0")
|
2025-07-27 16:27:11 +03:30
|
|
|
.about("Parses V2ray URI and generates JSON config for xray")
|
|
|
|
|
.arg(
|
|
|
|
|
Arg::new("uri")
|
|
|
|
|
.help("V2ray URI to parse")
|
|
|
|
|
.required(true)
|
|
|
|
|
.index(1),
|
|
|
|
|
)
|
|
|
|
|
.arg(
|
|
|
|
|
Arg::new("socksport")
|
|
|
|
|
.long("socksport")
|
2025-07-27 17:28:51 +03:30
|
|
|
.help("Optional SOCKS5 proxy port for inbound")
|
2025-07-27 16:27:11 +03:30
|
|
|
.value_name("PORT")
|
|
|
|
|
.value_parser(value_parser!(u16)),
|
|
|
|
|
)
|
|
|
|
|
.arg(
|
|
|
|
|
Arg::new("httpport")
|
|
|
|
|
.long("httpport")
|
|
|
|
|
.help("Optional HTTP proxy port for inbound")
|
|
|
|
|
.value_name("PORT")
|
|
|
|
|
.value_parser(value_parser!(u16)),
|
|
|
|
|
)
|
|
|
|
|
.arg(
|
2025-07-28 18:09:14 +03:30
|
|
|
Arg::new("get_metadata")
|
|
|
|
|
.long("get-metadata")
|
|
|
|
|
.help("Only print config meta data")
|
2025-07-27 16:27:11 +03:30
|
|
|
.action(clap::ArgAction::SetTrue),
|
|
|
|
|
)
|
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
|
|
let uri = matches.get_one::<String>("uri").unwrap();
|
|
|
|
|
let socksport = matches.get_one::<u16>("socksport").copied();
|
|
|
|
|
let httpport = matches.get_one::<u16>("httpport").copied();
|
2025-07-28 18:09:14 +03:30
|
|
|
let get_metadata = matches.get_flag("get_metadata");
|
2025-07-27 16:27:11 +03:30
|
|
|
|
2025-07-28 18:09:14 +03:30
|
|
|
if get_metadata {
|
|
|
|
|
print!("{}", parser::get_metadata(uri));
|
2025-07-27 16:15:04 +03:30
|
|
|
return;
|
|
|
|
|
}
|
2025-07-27 16:27:11 +03:30
|
|
|
|
|
|
|
|
let json_config = parser::create_json_config(uri, socksport, httpport);
|
2023-11-09 12:41:09 +03:30
|
|
|
println!("{}", json_config);
|
2023-10-06 18:16:44 +03:30
|
|
|
}
|