Fix(Connectivity/Windows): Modify Profile Creation Args
This commit is contained in:
@@ -13,37 +13,44 @@ pub(crate) struct Windows {
|
||||
|
||||
impl Windows {
|
||||
pub fn new(name: &str) -> Result<Self, io::Error> {
|
||||
let profile_file_name = format!("netsh wlan add profile filename=\"{}\"", name);
|
||||
|
||||
Command::new("cmd")
|
||||
.args(&["/C", &profile_file_name[..]])
|
||||
.output()?;
|
||||
|
||||
Ok(Windows {
|
||||
name: String::from(name),
|
||||
output_xml_path: OUTPUT_XML_FILE_PATH.into(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn add_profile(&self, password: &str) -> bool {
|
||||
let mut handler = NetworkXmlProfileHandler::new();
|
||||
handler.content = handler
|
||||
.content
|
||||
.replace("{SSID}", &self.name)
|
||||
.replace("{password}", password);
|
||||
|
||||
// Write details to new xml file
|
||||
if let Err(_) = handler.to_file(&self.output_xml_path).map_err(|_err| false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add the network profile
|
||||
if let Err(_) = Command::new("netsh")
|
||||
.args(&["wlan", "add", "profile", &format!("filename={}", self.output_xml_path)])
|
||||
.output()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Network for Windows {
|
||||
fn connect(&self, password: &str) -> bool {
|
||||
{
|
||||
let mut handler = NetworkXmlProfileHandler::new();
|
||||
|
||||
handler.content = handler
|
||||
.content
|
||||
.replace("{SSID}", &self.name)
|
||||
.replace("{password}", password);
|
||||
|
||||
// Write details to new xml file
|
||||
if let Err(err) = handler.to_file(&self.output_xml_path).map_err(|_err| false) {
|
||||
return err;
|
||||
}
|
||||
if self.add_profile(password) == false {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
let output = Command::new("netsh")
|
||||
.args(&["wlan", "connect", &format!("name = \"{}\"", self.name)])
|
||||
.args(&["wlan", "connect", &format!("name={}", self.name)])
|
||||
.output();
|
||||
|
||||
match output {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
pub fn get_wifi_profile() -> String {
|
||||
String::from(
|
||||
r#"
|
||||
<?xml version="1.0"?>
|
||||
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
|
||||
String::from(r#"<?xml version="1.0"?>
|
||||
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
|
||||
<name>{SSID}</name>
|
||||
<SSIDConfig>
|
||||
<SSID>
|
||||
@@ -25,11 +23,9 @@ pub fn get_wifi_profile() -> String {
|
||||
</sharedKey>
|
||||
</security>
|
||||
</MSM>
|
||||
<MacRandomization
|
||||
xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
|
||||
<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
|
||||
<enableRandomization>false</enableRandomization>
|
||||
</MacRandomization>
|
||||
</WLANProfile>
|
||||
"#,
|
||||
</WLANProfile>"#,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user