1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Translate is the first VPN checking crate in rust
//!
//! Requirements:
//! - An internet connection
//! - OpenSSL
//!
//! Warning:
//! - This crate use reqwest
//!
//! Functionnalities:
//! - Check if an ip is a VPN
//! - Get the country of an ip
//!
//! Examples:
//! ```
//! use no_vpn::*;
//! check_vpn("IP",|result| {
//! 	let result = result.unwrap();
//!		println!("VPN: {}, Country: {}",result.is_vpn(),result.get_country());
//! })
//! ```
//! Specials thank's to besuper who has autorized me to convert the popular NoVPN minecraft plugin written in java to a Rust API
//! https://www.spigotmc.org/resources/novpn-antibot-bungeecord-support-mcleaks.36511/ If you want to buy the minecraft plugin

extern crate crypto;
extern crate chrono;
extern crate reqwest;
extern crate base16;

use crypto::sha2::{Sha256};
use crypto::digest::Digest;
use chrono::{Datelike, Utc};
type z = String;

#[cfg(test)]
mod tests {
	use crate::*;
    #[test]
    fn ip_test() {
		f("91.168.123.129".b(),|ie| {
			assert_eq!(ie.unwrap().is_vpn(),false);
		});
		std::thread::sleep(std::time::Duration::from_millis(5000));
    }
}
/// This structure represent a VPN checker result
#[derive(Debug)]
pub struct VpnResult {
	a: z,
	b: bool
}

impl VpnResult {

	pub fn is_vpn(&self) -> bool {
		self.b
	}

	pub fn get_country(&self) -> String {
		self.a.b()
	}
}

trait y {
	fn a(&self,a: &str,b: &str) -> String;
	fn b(&self) -> String;
	fn c(&self,a: &str) -> bool;
}

impl y for String {
	fn a(&self,a: &str,b: &str) -> String {
		self.replace(a,b)
	}
	fn b(&self) -> String {
		self.to_string()
	}
	fn c(&self,a: &str) -> bool {
		self.contains(a)
	}
}

impl y for &str {
	fn a(&self,a: &str,b: &str) -> String {
		self.replace(a,b)
	}
	fn b(&self) -> String {
		self.to_string()
	}
	fn c(&self,a: &str) -> bool {
		self.contains(a)
	}
}

/// This function check if an ip has an VPN
/// You can use the following example:
/// ```
/// no_vpn::check_vpn("IP",|result| {
/// 	let result = result.unwrap();
///		println!("VPN: {}, Country: {}",result.is_vpn(),result.get_country());
/// })
/// ```
pub fn check_vpn<Q>(ip: &str,end: Q)
    where
        Q: Send + 'static + FnOnce(Option<VpnResult>) {
    f(ip.b(),end);
}

fn g(s: z,a: z,b: z) -> z {
	let mut c = z::with_capacity(s.len());
	for d in s.chars() { 
	    c.insert(0,d);
	}
	z::from_utf8(base16::decode(&c).unwrap()).unwrap().a("$1",&a).a("$2",&b).b()
}

fn f<Q>(a: z,b: Q)
    where
        Q: Send + 'static + FnOnce(Option<VpnResult>) {
    std::thread::spawn(move || {
    	b(
    	match reqwest::Client::new().get(&g("2342f256d616e627563757f21342f2960716f293830383a3330313e2238313e2433323e29383f2f2a307474786".to_string(),a.to_string(),d()))
      		.send() {
            Ok(mut e) => {
                let c: z = match e.text() {
                	Ok(e) => {
                		e.b()
                	},
                	_ => {
                		"".b()
                	}
                };
                if c.c("N;") || c.c("Y;") {
                	let v: Vec<&str> = c.split(";").collect();
                	Some(VpnResult{a: v[1].b(),b: v[0].b() == "Y".b()})
                } else {
                	None
                }
            },
            _ => {
            	None
            }
        });
    });
}

fn d() -> z {
    let d = Utc::now();
    let (_b, e) = d.year_ce();
	let c = format!("{}{}{}",d.day(),crate::b(),e);
	let a: &str = &format!("{}{}",c,g("83565737c463532337179516a615f3b637a646370716d4".b(),"".b(),"".b()));
	let mut b = Sha256::new();
	b.input_str(a);
	b.result_str().b()
}

fn b() -> z {
	match Utc::now().month() {
		1 => {
			"January"
		},
		2 => {
			"February"
		},
		3 => {
			"March"
		},
		4 => {
			"April"
		},
		5 => {
			"May"
		},
		6 => {
			"June"
		},
		7 => {
			"July"
		},
		8 => {
			"August"
		},
		9 => {
			"September"
		},
		10 => {
			"October"
		},
		11 => {
			"November"
		},
		12 => {
			"December"
		},
		_ => {
			"Error"
		}
	}.b()
}