feat: update connect-rs

This commit is contained in:
2025-10-13 23:13:48 +08:00
parent c9928c65fe
commit 5d215d3ca3
3 changed files with 47 additions and 23 deletions

View File

@@ -7,7 +7,7 @@
//! rust_util = "0.6.50" //! rust_util = "0.6.50"
//! ``` //! ```
use clap::{Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use rust_util::{failure, success, util_cmd}; use rust_util::{failure, success, util_cmd};
use std::process::Command; use std::process::Command;
@@ -23,7 +23,7 @@ struct ConnectArgs {
enum Commands { enum Commands {
/// Connect /// Connect
#[command(short_flag = 'c')] #[command(short_flag = 'c')]
Connect, Connect(CmdConnect),
/// Disconnect /// Disconnect
#[command(short_flag = 'd')] #[command(short_flag = 'd')]
Disconnect, Disconnect,
@@ -32,34 +32,58 @@ enum Commands {
Update, 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() { fn main() {
let args = ConnectArgs::parse(); let args = ConnectArgs::parse();
match args.command { match args.command {
Commands::Connect => { Commands::Connect(cmd) => {
if cmd.update {
update_proxy();
}
turn_proxy_off();
run_command( run_command(
"networksetup", NET_WORK_SETUP,
&["-setautoproxyurl", "Wi-Fi", "http://localhost:8888/pac"], &["-setautoproxyurl", WIFI, "http://localhost:8888/pac"],
"setautoproxyurl proxy", "setautoproxyurl proxy",
); );
} }
Commands::Disconnect => { Commands::Disconnect => {
run_command( turn_proxy_off();
"networksetup",
&["-setautoproxystate", "Wi-Fi", "off"],
"setautoproxystate off",
);
run_command(
"networksetup",
&["-setsocksfirewallproxystate", "Wi-Fi", "off"],
"setsocksfirewallproxystate off",
);
} }
Commands::Update => { 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) { fn run_command(program: &str, args: &[&str], message: &str) {
let mut c2 = Command::new(program); let mut c2 = Command::new(program);
c2.args(args); 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 // @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251013T231311+08:00.MEYCIQCuJnrPEuafEEzqTyyW
// VJBdG8FJwZzLSBGVQV1du3s4AiA7FJSyMmtQsq3Wxb8pDYmie8zc1m+r6AuUWJBAn8Pf8A== // TkvJvXUUg9c2+OiVtcr1owBkEwIhALCq8vFJyJTb2ftplPN1Q3PzRZFNkfdWovo8DMiyaEc5

View File

@@ -17,11 +17,11 @@
}, },
"connect.rs": { "connect.rs": {
"script_name": "connect.rs", "script_name": "connect.rs",
"script_length": 2154, "script_length": 2550,
"script_sha256": "c9dcb02c10b672bcf1e8462215e7d9d217aa27977aa26841b3ee5f102bfb125c", "script_sha256": "24eb0ddbb67964cfc59ce192270d348ef0fdd646bd24f52eccefc83eb26f023b",
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/connect-rs/src/main.rs", "script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/connect-rs/src/main.rs",
"publish_time": 1760367513436, "publish_time": 1760367513436,
"update_time": 1760367513436 "update_time": 1760368415211
}, },
"current-time.rs": { "current-time.rs": {
"script_name": "current-time.rs", "script_name": "current-time.rs",

View File

@@ -11,8 +11,8 @@
}, },
"connect-rs": { "connect-rs": {
"script_name": "connect-rs", "script_name": "connect-rs",
"script_length": 2154, "script_length": 2550,
"script_sha256": "c9dcb02c10b672bcf1e8462215e7d9d217aa27977aa26841b3ee5f102bfb125c" "script_sha256": "24eb0ddbb67964cfc59ce192270d348ef0fdd646bd24f52eccefc83eb26f023b"
}, },
"current-time-rs": { "current-time-rs": {
"script_name": "current-time-rs", "script_name": "current-time-rs",