feat: update connect-rs
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
//! rust_util = "0.6.50"
|
||||
//! ```
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use rust_util::{failure, success, util_cmd};
|
||||
use std::process::Command;
|
||||
|
||||
@@ -23,7 +23,7 @@ struct ConnectArgs {
|
||||
enum Commands {
|
||||
/// Connect
|
||||
#[command(short_flag = 'c')]
|
||||
Connect,
|
||||
Connect(CmdConnect),
|
||||
/// Disconnect
|
||||
#[command(short_flag = 'd')]
|
||||
Disconnect,
|
||||
@@ -32,34 +32,58 @@ enum Commands {
|
||||
Update,
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct CmdConnect {
|
||||
/// Update
|
||||
#[arg(long)]
|
||||
pub update: bool,
|
||||
}
|
||||
|
||||
const NET_WORK_SETUP: &str = "networksetup";
|
||||
const WIFI: &str = "Wi-Fi";
|
||||
|
||||
fn main() {
|
||||
let args = ConnectArgs::parse();
|
||||
match args.command {
|
||||
Commands::Connect => {
|
||||
Commands::Connect(cmd) => {
|
||||
if cmd.update {
|
||||
update_proxy();
|
||||
}
|
||||
turn_proxy_off();
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setautoproxyurl", "Wi-Fi", "http://localhost:8888/pac"],
|
||||
NET_WORK_SETUP,
|
||||
&["-setautoproxyurl", WIFI, "http://localhost:8888/pac"],
|
||||
"setautoproxyurl proxy",
|
||||
);
|
||||
}
|
||||
Commands::Disconnect => {
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setautoproxystate", "Wi-Fi", "off"],
|
||||
"setautoproxystate off",
|
||||
);
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setsocksfirewallproxystate", "Wi-Fi", "off"],
|
||||
"setsocksfirewallproxystate off",
|
||||
);
|
||||
turn_proxy_off();
|
||||
}
|
||||
Commands::Update => {
|
||||
// TODO ...
|
||||
update_proxy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_proxy() {
|
||||
// TODO ...
|
||||
// check file exists and digest: __proxy__.pac
|
||||
// &digest=1 // get digest
|
||||
}
|
||||
|
||||
fn turn_proxy_off() {
|
||||
run_command(
|
||||
NET_WORK_SETUP,
|
||||
&["-setautoproxystate", WIFI, "off"],
|
||||
"setautoproxystate off",
|
||||
);
|
||||
run_command(
|
||||
NET_WORK_SETUP,
|
||||
&["-setsocksfirewallproxystate", WIFI, "off"],
|
||||
"setsocksfirewallproxystate off",
|
||||
);
|
||||
}
|
||||
|
||||
fn run_command(program: &str, args: &[&str], message: &str) {
|
||||
let mut c2 = Command::new(program);
|
||||
c2.args(args);
|
||||
@@ -77,5 +101,5 @@ fn run_command(program: &str, args: &[&str], message: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251013T225739+08:00.MEQCIDuRTM7sRjskoHHFG0BT
|
||||
// VJBdG8FJwZzLSBGVQV1du3s4AiA7FJSyMmtQsq3Wxb8pDYmie8zc1m+r6AuUWJBAn8Pf8A==
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251013T231311+08:00.MEYCIQCuJnrPEuafEEzqTyyW
|
||||
// TkvJvXUUg9c2+OiVtcr1owBkEwIhALCq8vFJyJTb2ftplPN1Q3PzRZFNkfdWovo8DMiyaEc5
|
||||
|
||||
Reference in New Issue
Block a user