mirror of
https://github.com/house-of-vanity/v2-uri-parser.git
synced 2025-12-17 23:37:52 +00:00
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "v2parser"
|
name = "v2parser"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "v2parser"
|
name = "v2parser"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Arguments:
|
|||||||
Options:
|
Options:
|
||||||
--socksport <PORT> Optional SOCKS5 proxy port for inbound
|
--socksport <PORT> Optional SOCKS5 proxy port for inbound
|
||||||
--httpport <PORT> Optional HTTP proxy port for inbound
|
--httpport <PORT> Optional HTTP proxy port for inbound
|
||||||
--get-name Only print the config name
|
--get-metadata Only print config meta data
|
||||||
-h, --help Print help
|
-h, --help Print help
|
||||||
-V, --version Print version
|
-V, --version Print version
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -265,3 +265,10 @@ pub struct RawData {
|
|||||||
pub server_method: Option<String>,
|
pub server_method: Option<String>,
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub struct ConfigMetaData {
|
||||||
|
pub name: String,
|
||||||
|
pub protocol: String,
|
||||||
|
}
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@@ -5,7 +5,7 @@ pub mod utils;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = Command::new("v2parser")
|
let matches = Command::new("v2parser")
|
||||||
.version("0.2.0")
|
.version("0.3.0")
|
||||||
.about("Parses V2ray URI and generates JSON config for xray")
|
.about("Parses V2ray URI and generates JSON config for xray")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("uri")
|
Arg::new("uri")
|
||||||
@@ -28,9 +28,9 @@ fn main() {
|
|||||||
.value_parser(value_parser!(u16)),
|
.value_parser(value_parser!(u16)),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("get_name")
|
Arg::new("get_metadata")
|
||||||
.long("get-name")
|
.long("get-metadata")
|
||||||
.help("Only print the config name")
|
.help("Only print config meta data")
|
||||||
.action(clap::ArgAction::SetTrue),
|
.action(clap::ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
@@ -38,10 +38,10 @@ fn main() {
|
|||||||
let uri = matches.get_one::<String>("uri").unwrap();
|
let uri = matches.get_one::<String>("uri").unwrap();
|
||||||
let socksport = matches.get_one::<u16>("socksport").copied();
|
let socksport = matches.get_one::<u16>("socksport").copied();
|
||||||
let httpport = matches.get_one::<u16>("httpport").copied();
|
let httpport = matches.get_one::<u16>("httpport").copied();
|
||||||
let get_name = matches.get_flag("get_name");
|
let get_metadata = matches.get_flag("get_metadata");
|
||||||
|
|
||||||
if get_name {
|
if get_metadata {
|
||||||
print!("{}", parser::get_name(uri));
|
print!("{}", parser::get_metadata(uri));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::config_models::{
|
use crate::config_models::{
|
||||||
self, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings, QuicSettings,
|
self, ConfigMetaData, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings,
|
||||||
RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings, WsSettings,
|
QuicSettings, RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings,
|
||||||
XHTTPSettings,
|
WsSettings, XHTTPSettings,
|
||||||
};
|
};
|
||||||
use crate::utils::{inbound_generator, parse_raw_json};
|
use crate::utils::{inbound_generator, parse_raw_json};
|
||||||
|
|
||||||
@@ -12,9 +12,14 @@ mod uri_identifier;
|
|||||||
mod vless;
|
mod vless;
|
||||||
mod vmess;
|
mod vmess;
|
||||||
|
|
||||||
pub fn get_name(uri: &str) -> String {
|
pub fn get_metadata(uri: &str) -> String {
|
||||||
let (_, data, _) = get_uri_data(uri);
|
let (protocol, data, _) = get_uri_data(uri);
|
||||||
return data.remarks;
|
let meta_data = ConfigMetaData {
|
||||||
|
name: data.remarks,
|
||||||
|
protocol,
|
||||||
|
};
|
||||||
|
let serialized = serde_json::to_string(&meta_data).unwrap();
|
||||||
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {
|
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
pub struct Outboud {
|
|
||||||
vnext: Option<Vec<ServerObject>>,
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
use regex::Regex;
|
|
||||||
|
|
||||||
pub enum Protocols {
|
pub enum Protocols {
|
||||||
Vmess,
|
Vmess,
|
||||||
Vless,
|
Vless,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub mod data;
|
pub mod data;
|
||||||
mod models;
|
mod models;
|
||||||
use crate::{config_models::*, utils::parse_raw_json};
|
use crate::config_models::*;
|
||||||
|
|
||||||
pub fn create_outbound_settings(data: &RawData) -> OutboundSettings {
|
pub fn create_outbound_settings(data: &RawData) -> OutboundSettings {
|
||||||
return OutboundSettings::Vless(VlessOutboundSettings {
|
return OutboundSettings::Vless(VlessOutboundSettings {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ fn get_raw_data_from_uri(data: &str) -> RawData {
|
|||||||
let query: Vec<(&str, &str)> = querystring::querify(raw_query);
|
let query: Vec<(&str, &str)> = querystring::querify(raw_query);
|
||||||
|
|
||||||
return RawData {
|
return RawData {
|
||||||
remarks: String::from(name),
|
remarks: url_decode(Some(String::from(name))).unwrap_or(String::from("")),
|
||||||
uuid: Some(parsed_address.uuid),
|
uuid: Some(parsed_address.uuid),
|
||||||
port: Some(parsed_address.port),
|
port: Some(parsed_address.port),
|
||||||
address: Some(parsed_address.address),
|
address: Some(parsed_address.address),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub mod data;
|
pub mod data;
|
||||||
mod models;
|
mod models;
|
||||||
use crate::{config_models::*, utils::parse_raw_json};
|
use crate::config_models::*;
|
||||||
|
|
||||||
pub fn create_outbound_settings(data: &RawData) -> OutboundSettings {
|
pub fn create_outbound_settings(data: &RawData) -> OutboundSettings {
|
||||||
return OutboundSettings::Vmess(VmessOutboundSettings {
|
return OutboundSettings::Vmess(VmessOutboundSettings {
|
||||||
|
|||||||
Reference in New Issue
Block a user