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