Skip to content

Commit

Permalink
Merge pull request #73 from CaninoDev/add_features_protonvpn
Browse files Browse the repository at this point in the history
add choice to pick certain features
  • Loading branch information
jamesmcm authored Apr 5, 2021
2 parents bb13a12 + 8e5304f commit e32bb00
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions src/providers/protonvpn/openvpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ impl ProtonVPN {
&self,
category: &ConfigType,
tier: &Tier,
feature: &Feature,
protocol: &OpenVpnProtocol,
) -> anyhow::Result<Url> {
let cat = if tier == &Tier::Free {
"Server".to_string()
} else {
category.url_part()
};
Ok(Url::parse(&format!("https://account.protonvpn.com/api/vpn/config?Category={}&Tier={}&Platform=Linux&Protocol={}", cat, tier.url_part(), protocol))?)
let fet = if tier == &Tier::Free {
"Normal".to_string()
} else {
feature.url_part()
};
Ok(Url::parse(&format!("https://account.protonvpn.com/api/vpn/config?Category={}&Tier={}&Feature={}&Platform=Linux&Protocol={}", cat, tier.url_part(), fet, protocol))?)
}
}
impl OpenVpnProvider for ProtonVPN {
Expand Down Expand Up @@ -85,8 +91,13 @@ impl OpenVpnProvider for ProtonVPN {
// Dummy as not used for Free
ConfigType::Standard
};
let feature_choice = if tier != Tier::Free {
Feature::choose_one()?
} else {
Feature::Normal
};
let protocol = OpenVpnProtocol::choose_one()?;
let url = self.build_url(&config_choice, &tier, &protocol)?;
let url = self.build_url(&config_choice, &tier, &feature_choice, &protocol)?;
let zipfile = reqwest::blocking::get(url)?;
let mut zip = ZipArchive::new(Cursor::new(zipfile.bytes()?))?;
let openvpn_dir = self.openvpn_dir()?;
Expand Down Expand Up @@ -215,6 +226,60 @@ impl ConfigurationChoice for Tier {
)
}
}
// {0: "Normal", 1: "Secure-Core", 2: "Tor", 4: "P2P"}
#[derive(EnumIter, PartialEq)]
enum Feature {
P2P,
Tor,
Normal,
}

impl Feature {
fn url_part(&self) -> String {
match self {
Self::P2P => "4".to_string(),
Self::Tor => "2".to_string(),
Self::Normal => "0".to_string(),
}
}
}

impl Display for Feature {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::P2P => "P2P",
Self::Tor => "Tor",
Self::Normal => "Normal",
};
write!(f, "{}", s)
}
}

impl Default for Feature {
fn default() -> Self {
Self::Normal
}
}

impl ConfigurationChoice for Feature {
fn prompt() -> String {
"Please choose a server feature".to_string()
}

fn variants() -> Vec<Self> {
Feature::iter().collect()
}
fn description(&self) -> Option<String> {
Some(
match self {
Self::P2P => "Connect via torrent optmized network (Plus accounts only)",
Self::Tor => "Connect via Tor network (Plus accounts only)",
Self::Normal => "Standard (available servers depend on account tier)",
}
.to_string(),
)
}
}

#[derive(EnumIter, PartialEq)]
enum ConfigType {
Expand Down

0 comments on commit e32bb00

Please sign in to comment.