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,32 +32,56 @@ 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 => {
|
||||
turn_proxy_off();
|
||||
}
|
||||
Commands::Update => {
|
||||
update_proxy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_proxy() {
|
||||
// TODO ...
|
||||
// check file exists and digest: __proxy__.pac
|
||||
// &digest=1 // get digest
|
||||
}
|
||||
|
||||
fn turn_proxy_off() {
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setautoproxystate", "Wi-Fi", "off"],
|
||||
NET_WORK_SETUP,
|
||||
&["-setautoproxystate", WIFI, "off"],
|
||||
"setautoproxystate off",
|
||||
);
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setsocksfirewallproxystate", "Wi-Fi", "off"],
|
||||
NET_WORK_SETUP,
|
||||
&["-setsocksfirewallproxystate", WIFI, "off"],
|
||||
"setsocksfirewallproxystate off",
|
||||
);
|
||||
}
|
||||
Commands::Update => {
|
||||
// TODO ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_command(program: &str, args: &[&str], message: &str) {
|
||||
@@ -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
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"connect.rs": {
|
||||
"script_name": "connect.rs",
|
||||
"script_length": 2154,
|
||||
"script_sha256": "c9dcb02c10b672bcf1e8462215e7d9d217aa27977aa26841b3ee5f102bfb125c",
|
||||
"script_length": 2550,
|
||||
"script_sha256": "24eb0ddbb67964cfc59ce192270d348ef0fdd646bd24f52eccefc83eb26f023b",
|
||||
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/connect-rs/src/main.rs",
|
||||
"publish_time": 1760367513436,
|
||||
"update_time": 1760367513436
|
||||
"update_time": 1760368415211
|
||||
},
|
||||
"current-time.rs": {
|
||||
"script_name": "current-time.rs",
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
},
|
||||
"connect-rs": {
|
||||
"script_name": "connect-rs",
|
||||
"script_length": 2154,
|
||||
"script_sha256": "c9dcb02c10b672bcf1e8462215e7d9d217aa27977aa26841b3ee5f102bfb125c"
|
||||
"script_length": 2550,
|
||||
"script_sha256": "24eb0ddbb67964cfc59ce192270d348ef0fdd646bd24f52eccefc83eb26f023b"
|
||||
},
|
||||
"current-time-rs": {
|
||||
"script_name": "current-time-rs",
|
||||
|
||||
Reference in New Issue
Block a user