merge wpactrl and golgi api updates
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
glyph 2022-05-13 13:15:12 +02:00
commit dc79833e2b
3 changed files with 38 additions and 37 deletions

40
Cargo.lock generated
View File

@ -48,7 +48,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5"
dependencies = [
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -203,7 +203,7 @@ checksum = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -214,7 +214,7 @@ checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -625,7 +625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c"
dependencies = [
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -648,7 +648,7 @@ dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"rustc_version 0.4.0",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -805,7 +805,7 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
"synstructure",
]
@ -972,7 +972,7 @@ checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -1111,7 +1111,7 @@ dependencies = [
[[package]]
name = "golgi"
version = "0.1.1"
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#0aa616d92b005b38359aa34bf448f3f1f47e8e6a"
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#0aa616d92b005b38359aa34bf448f3f1f47e8e6a"
dependencies = [
"async-std",
"async-stream 0.3.3",
@ -1872,7 +1872,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -1920,7 +1920,7 @@ checksum = "60bbf2d78a45808eba478a0660f050bbce70dafc011e275cf00f6f8500a8be88"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -2581,7 +2581,7 @@ dependencies = [
"proc-macro-error-attr",
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
"version_check 0.9.4",
]
@ -3082,7 +3082,7 @@ checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -3279,7 +3279,7 @@ checksum = "1508efa03c362e23817f96cde18abed596a25219a8b2c66e8db33c03543d315b"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -3355,7 +3355,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -3371,9 +3371,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.93"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2"
checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
@ -3388,7 +3388,7 @@ checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
"unicode-xid 0.2.3",
]
@ -3489,7 +3489,7 @@ checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
]
[[package]]
@ -4104,7 +4104,7 @@ dependencies = [
"log 0.4.17",
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
"wasm-bindgen-shared",
]
@ -4138,7 +4138,7 @@ checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b"
dependencies = [
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
"syn 1.0.94",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@ -6,7 +6,7 @@ use std::num::ParseIntError;
use io::Error as IoError;
use probes::ProbeError;
use regex::Error as RegexError;
use wpactrl::WpaError;
use wpactrl::Error as WpaError;
/// Custom error type encapsulating all possible errors when querying
/// network interfaces and modifying their state.

View File

@ -22,6 +22,7 @@ use std::{
};
use probes::network;
use wpactrl::Client as WpaClient;
#[cfg(feature = "miniserde_support")]
use miniserde::{Deserialize, Serialize};
@ -121,7 +122,7 @@ pub struct Traffic {
/// In the event of an error, a `NetworkError` is returned in the `Result`.
pub fn available_networks(iface: &str) -> Result<Option<Vec<Scan>>, NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
wpa.request("SCAN")?;
let networks = wpa.request("SCAN_RESULTS")?;
let mut scan = Vec::new();
@ -173,7 +174,7 @@ pub fn available_networks(iface: &str) -> Result<Option<Vec<Scan>>, NetworkError
/// event of an error, a `NetworkError` is returned in the `Result`.
pub fn id(iface: &str, ssid: &str) -> Result<Option<String>, NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let networks = wpa.request("LIST_NETWORKS")?;
let mut id = Vec::new();
for network in networks.lines() {
@ -232,7 +233,7 @@ pub fn ip(iface: &str) -> Result<Option<String>, NetworkError> {
/// `Result`.
pub fn rssi(iface: &str) -> Result<Option<String>, NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let status = wpa.request("SIGNAL_POLL")?;
let rssi = utils::regex_finder(r"RSSI=(.*)\n", &status)?;
@ -259,7 +260,7 @@ pub fn rssi(iface: &str) -> Result<Option<String>, NetworkError> {
/// the `Result`.
pub fn rssi_percent(iface: &str) -> Result<Option<String>, NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let status = wpa.request("SIGNAL_POLL")?;
let rssi = utils::regex_finder(r"RSSI=(.*)\n", &status)?;
@ -291,7 +292,7 @@ pub fn rssi_percent(iface: &str) -> Result<Option<String>, NetworkError> {
/// is returned in the `Result`. In the event of an error, a `NetworkError` is
/// returned in the `Result`.
pub fn saved_networks() -> Result<Option<Vec<String>>, NetworkError> {
let mut wpa = wpactrl::WpaCtrl::builder().open()?;
let mut wpa = WpaClient::builder().open()?;
let networks = wpa.request("LIST_NETWORKS")?;
let mut ssids = Vec::new();
for network in networks.lines() {
@ -323,7 +324,7 @@ pub fn saved_networks() -> Result<Option<Vec<String>>, NetworkError> {
/// returned in the `Result`.
pub fn ssid(iface: &str) -> Result<Option<String>, NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let status = wpa.request("STATUS")?;
// pass the regex pattern and status output to the regex finder
@ -379,7 +380,7 @@ pub fn state(iface: &str) -> Result<Option<String>, NetworkError> {
/// a `NetworkError` is returned in the `Result`.
pub fn status(iface: &str) -> Result<Option<Status>, NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let wpa_status = wpa.request("STATUS")?;
// pass the regex pattern and status output to the regex finder
@ -579,7 +580,7 @@ pub fn check_iface(wlan_iface: &str, ap_iface: &str) -> Result<(), NetworkError>
/// is returned in the `Result`.
pub fn connect(id: &str, iface: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let select = format!("SELECT {}", id);
wpa.request(&select)?;
Ok(())
@ -598,7 +599,7 @@ pub fn connect(id: &str, iface: &str) -> Result<(), NetworkError> {
/// returned in the `Result`.
pub fn delete(id: &str, iface: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let remove = format!("REMOVE_NETWORK {}", id);
wpa.request(&remove)?;
Ok(())
@ -617,7 +618,7 @@ pub fn delete(id: &str, iface: &str) -> Result<(), NetworkError> {
/// `Result`.
pub fn disable(id: &str, iface: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let disable = format!("DISABLE_NETWORK {}", id);
wpa.request(&disable)?;
Ok(())
@ -634,7 +635,7 @@ pub fn disable(id: &str, iface: &str) -> Result<(), NetworkError> {
/// error, a `NetworkError` is returned in the `Result`.
pub fn disconnect(iface: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let disconnect = "DISCONNECT".to_string();
wpa.request(&disconnect)?;
Ok(())
@ -685,7 +686,7 @@ pub fn forget(iface: &str, ssid: &str) -> Result<(), NetworkError> {
/// event of an error, a `NetworkError` is returned in the `Result`.
pub fn modify(id: &str, iface: &str, pass: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
let new_pass = format!("NEW_PASSWORD {} {}", id, pass);
wpa.request(&new_pass)?;
Ok(())
@ -702,7 +703,7 @@ pub fn modify(id: &str, iface: &str, pass: &str) -> Result<(), NetworkError> {
/// error, a `NetworkError` is returned in the `Result`.
pub fn reassociate(iface: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
wpa.request("REASSOCIATE")?;
Ok(())
}
@ -714,7 +715,7 @@ pub fn reassociate(iface: &str) -> Result<(), NetworkError> {
/// `Result` type is returned. In the event of an error, a `NetworkError` is
/// returned in the `Result`.
pub fn reconfigure() -> Result<(), NetworkError> {
let mut wpa = wpactrl::WpaCtrl::builder().open()?;
let mut wpa = WpaClient::builder().open()?;
wpa.request("RECONFIGURE")?;
Ok(())
}
@ -730,7 +731,7 @@ pub fn reconfigure() -> Result<(), NetworkError> {
/// event of an error, a `NetworkError` is returned in the `Result`.
pub fn reconnect(iface: &str) -> Result<(), NetworkError> {
let wpa_path: String = format!("/var/run/wpa_supplicant/{}", iface);
let mut wpa = wpactrl::WpaCtrl::builder().ctrl_path(wpa_path).open()?;
let mut wpa = WpaClient::builder().ctrl_path(wpa_path).open()?;
wpa.request("DISCONNECT")?;
wpa.request("RECONNECT")?;
Ok(())
@ -742,7 +743,7 @@ pub fn reconnect(iface: &str) -> Result<(), NetworkError> {
/// `wpa_supplicant.conf` file, an `Ok` `Result` type is returned. In the
/// event of an error, a `NetworkError` is returned in the `Result`.
pub fn save() -> Result<(), NetworkError> {
let mut wpa = wpactrl::WpaCtrl::builder().open()?;
let mut wpa = WpaClient::builder().open()?;
wpa.request("SAVE_CONFIG")?;
Ok(())
}