Merge pull request #20 from Keivan-sf/19-get-protocol

19 get meta data
This commit is contained in:
Keivan
2025-07-28 18:13:41 +03:30
committed by GitHub
11 changed files with 31 additions and 26 deletions

2
Cargo.lock generated
View File

@@ -279,7 +279,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "v2parser"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"base64",
"clap",

View File

@@ -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

View File

@@ -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
```

View File

@@ -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,
}

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -1,5 +0,0 @@
pub struct Outboud {
vnext: Option<Vec<ServerObject>>,
}

View File

@@ -1,5 +1,3 @@
use regex::Regex;
pub enum Protocols {
Vmess,
Vless,

View File

@@ -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 {

View File

@@ -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),

View File

@@ -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 {