Skip to content

Commit c0ba7f0

Browse files
committed
fix(ssurl): make outline url optional
ref #1287
1 parent e8ea40c commit c0ba7f0

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ server = ["shadowsocks-service/server"]
7272
# Enable manager server
7373
manager = ["shadowsocks-service/manager"]
7474
# Enable utility
75-
utility = ["qrcode", "reqwest"]
75+
utility = ["qrcode"]
7676
# Enable service
7777
service = ["local", "server", "manager"]
7878

@@ -114,6 +114,9 @@ local-socks4 = ["local", "shadowsocks-service/local-socks4"]
114114
# Enable Tun interface protocol for sslocal
115115
local-tun = ["local", "shadowsocks-service/local-tun", "ipnet"]
116116

117+
# ssurl support outline (ssconf) URL
118+
utility-url-outline = ["reqwest"]
119+
117120
# Enable jemalloc for binaries
118121
jemalloc = ["jemallocator"]
119122
# Enable bundled tcmalloc

bin/ssurl.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! SS-URI = "ss://" userinfo "@" hostname ":" port [ "/" ] [ "?" plugin ] [ "#" tag ]
44
//! userinfo = websafe-base64-encode-utf8(method ":" password)
55
6+
use std::process::ExitCode;
7+
68
use clap::{Arg, ArgAction, Command, ValueHint};
79
use qrcode::{types::Color, QrCode};
810

@@ -72,6 +74,7 @@ fn decode(encoded: &str, need_qrcode: bool) {
7274
}
7375
}
7476

77+
#[cfg(feature = "utility-url-outline")]
7578
fn decode_outline(remote: &str, need_qrcode: bool) {
7679
// Protect from using http and other non-ssconf links in reqwest call
7780
if !remote.starts_with("ssconf") {
@@ -92,8 +95,8 @@ fn decode_outline(remote: &str, need_qrcode: bool) {
9295
}
9396
}
9497

95-
fn main() {
96-
let app = Command::new("ssurl")
98+
fn main() -> ExitCode {
99+
let mut app = Command::new("ssurl")
97100
.version(VERSION)
98101
.about("Encode and decode ShadowSocks URL")
99102
.arg(
@@ -116,31 +119,44 @@ fn main() {
116119
.help("Decode the server configuration from the provided ShadowSocks URL"),
117120
)
118121
.arg(
122+
Arg::new("QRCODE")
123+
.short('c')
124+
.long("qrcode")
125+
.action(ArgAction::SetTrue)
126+
.help("Generate the QRCode with the provided configuration"),
127+
);
128+
129+
if cfg!(feature = "utility-url-outline") {
130+
app = app.arg(
119131
Arg::new("OUTLINE_CONFIG_URL")
120132
.short('o')
121133
.long("outline")
122134
.value_hint(ValueHint::Url)
123135
.required_unless_present_any(["ENCODE_CONFIG_PATH", "DECODE_CONFIG_PATH"])
124136
.help("Fetch and decode config from ssconf URL used by Outline"),
125-
)
126-
.arg(
127-
Arg::new("QRCODE")
128-
.short('c')
129-
.long("qrcode")
130-
.action(ArgAction::SetTrue)
131-
.help("Generate the QRCode with the provided configuration"),
132137
);
138+
}
139+
133140
let matches = app.get_matches();
134141

135142
let need_qrcode = matches.get_flag("QRCODE");
136143

137144
if let Some(file) = matches.get_one::<String>("ENCODE_CONFIG_PATH") {
138145
encode(file, need_qrcode);
139-
} else if let Some(encoded) = matches.get_one::<String>("DECODE_CONFIG_PATH") {
146+
return ExitCode::SUCCESS;
147+
}
148+
149+
if let Some(encoded) = matches.get_one::<String>("DECODE_CONFIG_PATH") {
140150
decode(encoded, need_qrcode);
141-
} else if let Some(remote) = matches.get_one::<String>("OUTLINE_CONFIG_URL") {
151+
return ExitCode::SUCCESS;
152+
}
153+
154+
#[cfg(feature = "utility-url-outline")]
155+
if let Some(remote) = matches.get_one::<String>("OUTLINE_CONFIG_URL") {
142156
decode_outline(remote, need_qrcode);
143-
} else {
144-
println!("Use -h for more detail");
157+
return ExitCode::SUCCESS;
145158
}
159+
160+
println!("Use -h for more detail");
161+
return ExitCode::FAILURE;
146162
}

0 commit comments

Comments
 (0)