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