11//extern crate base64;
22use reqwest:: Result ;
3+ use serde_json:: Value ;
34pub fn ascii_to_char ( code : u8 ) -> char {
45 std:: char:: from_u32 ( code as u32 ) . unwrap_or ( '_' )
56}
@@ -22,6 +23,14 @@ fn ascii_to_string(code: Vec<u8>) -> Vec<String> {
2223 }
2324 test
2425}
26+
27+ fn ascii_to_string2 ( code : Vec < u8 > ) -> String {
28+ let mut test: String = String :: new ( ) ;
29+ for cor in code. into_iter ( ) {
30+ test. push ( ascii_to_char ( cor) ) ;
31+ }
32+ test
33+ }
2534pub fn get_the_key ( paths : Vec < String > ) -> Result < Vec < Vec < String > > > {
2635 let mut output: Vec < Vec < String > > = vec ! [ ] ;
2736 for apath in paths {
@@ -38,3 +47,144 @@ pub fn get_the_key(paths: Vec<String>) -> Result<Vec<Vec<String>>> {
3847 }
3948 Ok ( output)
4049}
50+ fn remove_quotation ( input : String ) -> String {
51+ let length = input. len ( ) ;
52+ ( & input[ 1 ..length - 1 ] ) . to_string ( )
53+ }
54+ enum Tcp {
55+ Ss ,
56+ V2 ,
57+ }
58+ #[ derive( Clone ) ]
59+ pub struct Information {
60+ pub func : String ,
61+ pub urls : String ,
62+ pub add : String ,
63+ pub aid : String ,
64+ pub host : String ,
65+ pub id : String ,
66+ pub net : String ,
67+ pub path : String ,
68+ pub port : String ,
69+ pub ps : String ,
70+ pub tls : String ,
71+ pub typpe : String ,
72+ }
73+ impl Information {
74+ pub fn information_to_list ( & self ) -> Vec < String > {
75+ let mut output = vec ! [ ] ;
76+ output. push ( format ! ( "link: {}" , self . get_the_link( ) ) ) ;
77+ output. push ( format ! ( "func: {}" , self . func) ) ;
78+ output. push ( format ! ( "urls: {}" , self . urls) ) ;
79+ output. push ( format ! ( "add: {}" , self . add) ) ;
80+ output. push ( format ! ( "aid: {}" , self . aid) ) ;
81+ output. push ( format ! ( "tls: {}" , self . tls) ) ;
82+ output. push ( format ! ( "type: {}" , self . typpe) ) ;
83+ output
84+ }
85+ fn get_the_link ( & self ) -> String {
86+ let mut temp = String :: new ( ) ;
87+ if self . func == * "\" vmess\" " {
88+ temp. push_str ( & format ! (
89+ "vmess://{}:{}-{}@{}:{}/#{}" ,
90+ & remove_quotation( self . net. clone( ) ) ,
91+ & remove_quotation( self . id. clone( ) ) ,
92+ & remove_quotation( self . aid. clone( ) ) ,
93+ & remove_quotation( self . add. clone( ) ) ,
94+ & remove_quotation( self . port. clone( ) ) ,
95+ & remove_quotation( self . ps. clone( ) )
96+ ) )
97+ } else {
98+ temp = self . urls . clone ( ) ;
99+ }
100+ temp
101+ }
102+ pub fn new ( url : String ) -> Self {
103+ let aurl: Vec < char > = url. chars ( ) . collect ( ) ;
104+ let url_type = {
105+ if aurl[ 0 ] == 's' {
106+ Tcp :: Ss
107+ } else {
108+ Tcp :: V2
109+ }
110+ } ;
111+ match url_type {
112+ Tcp :: Ss => {
113+ // 预处理,去除ss://
114+ let newurl = ( & url[ 5 ..] ) . to_string ( ) ;
115+ // 用@分割字符串
116+ let first: Vec < & str > = newurl. split ( '@' ) . collect ( ) ;
117+ // 传来的节点补全最后一位解析
118+ let header = first[ 0 ] . to_string ( ) + "=" ;
119+ // 解析,解析结果会返回一个function和密码,中间通过分号分割
120+ let header2 = ascii_to_string2 ( base64:: decode ( header. as_bytes ( ) ) . unwrap ( ) ) ;
121+ // 通过分号切开两个内容
122+ let header3: Vec < & str > = header2. split ( ':' ) . collect ( ) ;
123+ let net = format ! ( "\" {}\" " , header3[ 0 ] ) ;
124+ let id = format ! ( "\" {}\" " , header3[ 1 ] ) ;
125+
126+ let first_temp = first[ 1 ] . to_string ( ) ;
127+ let second: Vec < & str > = first_temp. split ( '#' ) . collect ( ) ;
128+ let ps0 = urlencoding:: decode ( second[ 1 ] ) . unwrap ( ) ;
129+ let ps = format ! ( "\" {}\" " , ps0) ;
130+
131+ let second_temp = second[ 0 ] . to_string ( ) ;
132+ let third: Vec < & str > = second_temp. split ( ':' ) . collect ( ) ;
133+ let add = format ! ( "\" {}\" " , third[ 0 ] ) ;
134+ let port = format ! ( "\" {}\" " , third[ 1 ] ) ;
135+ Information {
136+ urls : url,
137+ func : "\" ss\" " . to_string ( ) ,
138+ add,
139+ aid : "\" unknown\" " . to_string ( ) ,
140+ host : "\" \" " . to_string ( ) ,
141+ id,
142+ net,
143+ path : "\" unknown\" " . to_string ( ) ,
144+ port,
145+ ps,
146+ tls : "\" unknown\" " . to_string ( ) ,
147+ typpe : "\" unknown\" " . to_string ( ) ,
148+ }
149+ }
150+ Tcp :: V2 => {
151+ let newurl = & url[ 8 ..] ;
152+ let json = ascii_to_string2 ( base64:: decode ( newurl. to_string ( ) . as_bytes ( ) ) . unwrap ( ) ) ;
153+ let v: serde_json:: Result < Value > = serde_json:: from_str ( json. as_str ( ) ) ;
154+ match v {
155+ Ok ( input) => {
156+ Information {
157+ //company : input["add"].to_string(),
158+ urls : url,
159+ func : "\" vmess\" " . to_string ( ) ,
160+ add : input[ "add" ] . to_string ( ) ,
161+ aid : input[ "aid" ] . to_string ( ) ,
162+ host : input[ "host" ] . to_string ( ) ,
163+ id : input[ "id" ] . to_string ( ) ,
164+ net : input[ "net" ] . to_string ( ) ,
165+ path : input[ "path" ] . to_string ( ) ,
166+ port : input[ "port" ] . to_string ( ) ,
167+ ps : input[ "ps" ] . to_string ( ) ,
168+ tls : input[ "tls" ] . to_string ( ) ,
169+ typpe : input[ "type" ] . to_string ( ) ,
170+ }
171+ }
172+ Err ( _) => Information {
173+ urls : url,
174+ func : "\" vmess\" " . to_string ( ) ,
175+ add : "\" unknown\" " . to_string ( ) ,
176+ aid : "\" unknown\" " . to_string ( ) ,
177+ host : "\" unknown\" " . to_string ( ) ,
178+ id : "\" unknown\" " . to_string ( ) ,
179+ net : "\" unknown\" " . to_string ( ) ,
180+ path : "\" unknown\" " . to_string ( ) ,
181+ port : "\" unknown\" " . to_string ( ) ,
182+ ps : "\" unknown\" " . to_string ( ) ,
183+ tls : "\" unknown\" " . to_string ( ) ,
184+ typpe : "\" unknown\" " . to_string ( ) ,
185+ } ,
186+ }
187+ }
188+ }
189+ }
190+ }
0 commit comments