-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use clap::{Parser, Subcommand}; | ||
use miette::Result; | ||
|
||
use super::Context; | ||
|
||
pub mod serve; | ||
pub mod scan; | ||
pub mod connect; | ||
pub mod forget; | ||
|
||
/// Configure wifi (using NetowrkManager). | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct WifisetupArgs { | ||
/// Wifisetup subcommand | ||
#[command(subcommand)] | ||
pub action: WifisetupAction, | ||
} | ||
|
||
#[derive(Debug, Clone, Subcommand)] | ||
pub enum WifisetupAction { | ||
Serve(serve::ServeArgs), | ||
Scan(scan::ScanArgs), | ||
Connect(connect::ConnectArgs), | ||
Forget(forget::ForgetArgs), | ||
} | ||
|
||
pub async fn run(ctx: Context<WifisetupArgs>) -> Result<()> { | ||
match ctx.args_top.action.clone() { | ||
WifisetupAction::Serve(subargs) => serve::run(ctx.with_sub(subargs)).await, | ||
WifisetupAction::Scan(subargs) => scan::run(ctx.with_sub(subargs)).await, | ||
WifisetupAction::Connect(subargs) => connect::run(ctx.with_sub(subargs)).await, | ||
WifisetupAction::Forget(subargs) => forget::run(ctx.with_sub(subargs)).await, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use clap::Parser; | ||
use miette::Result; | ||
use tracing::instrument; | ||
|
||
use crate::actions::Context; | ||
|
||
use super::WifisetupArgs; | ||
|
||
/// Create a wifi connection. | ||
/// | ||
/// This creates a new connection profile. The wifi network doesn't need to be currently | ||
/// broadcasting; it will be used the next time the device is in range. | ||
/// | ||
/// If either `--name` or `--id` is provided, and a matching connection profile already exists, it | ||
/// will be updated with the new settings. Otherwise, a new profile will be created. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct ConnectArgs { | ||
/// SSID of the wifi network. | ||
/// | ||
/// Obtain it using `bestool wifisetup scan`. | ||
#[arg(long, value_name = "SSID")] | ||
pub ssid: String, | ||
|
||
/// Password for the wifi network. | ||
/// | ||
/// Connecting to open wifi networks is not supported as these are insecure. | ||
#[arg(long, value_name = "PASSWORD")] | ||
pub password: String, | ||
|
||
/// Name of the connection profile. | ||
/// | ||
/// If a profile with this name already exists, it will be updated with the new settings. | ||
#[arg(long, value_name = "NAME")] | ||
pub name: Option<String>, | ||
|
||
/// UUID of the connection profile. | ||
/// | ||
/// If a profile with this UUID already exists, it will be updated with the new settings. | ||
#[arg(long, value_name = "UUID")] | ||
pub id: Option<String>, | ||
} | ||
|
||
#[instrument(skip(ctx))] | ||
pub async fn run(ctx: Context<WifisetupArgs, ConnectArgs>) -> Result<()> { | ||
drop(ctx); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use clap::Parser; | ||
use miette::Result; | ||
use tracing::instrument; | ||
|
||
use crate::actions::Context; | ||
|
||
use super::WifisetupArgs; | ||
|
||
/// Forget a wifi connection. | ||
/// | ||
/// This deletes the connection profile and reloads the network configuration. Be careful if you're | ||
/// connected over wifi, as this may disconnect you. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct ForgetArgs { | ||
/// Name of the connection profile. | ||
/// | ||
/// Either this or `--id` must be provided. | ||
#[arg(long, value_name = "NAME", required_unless_present = "id")] | ||
pub name: Option<String>, | ||
|
||
/// UUID of the connection profile. | ||
/// | ||
/// Either this or `--name` must be provided. | ||
#[arg(long, value_name = "UUID", required_unless_present = "name")] | ||
pub id: Option<String>, | ||
} | ||
|
||
#[instrument(skip(ctx))] | ||
pub async fn run(ctx: Context<WifisetupArgs, ForgetArgs>) -> Result<()> { | ||
drop(ctx); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use clap::Parser; | ||
use miette::Result; | ||
use tracing::instrument; | ||
|
||
use crate::actions::Context; | ||
|
||
use super::WifisetupArgs; | ||
|
||
/// Scan for wifi networks. | ||
/// | ||
/// This scans for wifi networks and prints the results to stdout. Use `--json` for machine-readable | ||
/// output. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct ScanArgs { | ||
/// How long to wait for the scan to complete. | ||
/// | ||
/// Will wait for the scan to complete, or until this timeout is reached, whichever comes first, | ||
/// then exit. | ||
#[arg(long, value_name = "DURATION", default_value = "10s")] | ||
pub timeout: humantime::Duration, | ||
|
||
/// Print output in JSON format. | ||
/// | ||
/// Like the human-friendly output, one line is printed per network, as soon as it's detected. | ||
/// | ||
/// {"ssid": "MyNetwork", "aps": [{"bssid":"00:11:22:33:44:55", "signal": -50}], "generation": 5, "security": "wpa2", "profile": "uuid"} | ||
/// | ||
/// The "profile" field is only present if the network is already configured, and is the UUID of | ||
/// the connection profile. | ||
#[arg(long)] | ||
pub json: bool, | ||
|
||
/// Print insecure networks. | ||
/// | ||
/// By default, insecure networks are not printed. This is because connecting to open wifi is | ||
/// not supported. Adds a "secure": false field to the JSON output. | ||
#[arg(long)] | ||
pub insecure: bool, | ||
|
||
/// Which interface to scan. | ||
/// | ||
/// By default, the interface is autodetected. | ||
#[arg(long)] | ||
pub interface: Option<String>, | ||
} | ||
|
||
#[instrument(skip(ctx))] | ||
pub async fn run(ctx: Context<WifisetupArgs, ScanArgs>) -> Result<()> { | ||
drop(ctx); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use clap::Parser; | ||
use miette::Result; | ||
use tracing::instrument; | ||
|
||
use crate::actions::Context; | ||
|
||
use super::WifisetupArgs; | ||
|
||
/// Serve a web interface for wifi setup. | ||
/// | ||
/// By convention, this is expected to be available at http://hostip/wifisetup. | ||
/// | ||
/// This is a simple web interface for configuring wifi. It's intended to be used on devices that | ||
/// don't have a screen or keyboard, and is designed to be used on a phone. It's essentially the | ||
/// same as this CLI, but with a web interface. It's recommended to set a `--password`, otherwise | ||
/// anyone on the same network can reconfigure the device. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct ServeArgs { | ||
/// Port to listen on. | ||
#[arg(long, value_name = "PORT", default_value = "9209")] | ||
pub port: u16, | ||
|
||
/// Password for the web interface. | ||
#[arg(long, value_name = "PASSWORD")] | ||
pub password: Option<String>, | ||
} | ||
|
||
#[instrument(skip(ctx))] | ||
pub async fn run(ctx: Context<WifisetupArgs, ServeArgs>) -> Result<()> { | ||
drop(ctx); | ||
Ok(()) | ||
} |