Skip to content

Commit f167c48

Browse files
committed
--generate-url parameter
1 parent 2ad9fdf commit f167c48

File tree

9 files changed

+28
-40
lines changed

9 files changed

+28
-40
lines changed

install/overtls-install-musl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ function print_qrcode() {
701701
check_file_exists "${ot_exe_path}"
702702
check_file_exists "${ot_cfg_path}"
703703

704-
local qrcode="$( ${ot_exe_path} -q -c ${ot_cfg_path} )"
704+
local qrcode="$( ${ot_exe_path} -g -c ${ot_cfg_path} )"
705705
echo "${qrcode}"
706706
qrencode -t UTF8 "${qrcode}" | cat
707707
}

install/overtls-install-selfsign.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ function print_url() {
495495
check_file_exists "${ot_exe_path}"
496496
check_file_exists "${ot_cfg_path}"
497497

498-
local qrcode="$( ${ot_exe_path} -q --qrcode-cert -c ${ot_cfg_path} )"
498+
local qrcode="$( ${ot_exe_path} -g -c ${ot_cfg_path} )"
499499
echo "${qrcode}"
500500
}
501501

install/overtls-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ function print_qrcode() {
771771
check_file_exists "${ot_exe_path}"
772772
check_file_exists "${ot_cfg_path}"
773773

774-
local qrcode="$( ${ot_exe_path} -q -c ${ot_cfg_path} )"
774+
local qrcode="$( ${ot_exe_path} -g -c ${ot_cfg_path} )"
775775
echo "${qrcode}"
776776
qrencode -t UTF8 "${qrcode}" | cat
777777
}

readme-cn.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ overtls -r client -c config.json
137137
如果你確實沒有 `域名`, 可以使用 `openssl` 生成自簽證書 來臨時連接服務端,以便你能處理你的緊急事務。
138138
139139
```bash
140-
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/selfsign.sh
141-
head selfsign.sh -n 25
142-
chmod +x selfsign.sh
143-
./selfsign.sh CN JiangSu ChangZhou MyGreatOrg Root_CA Server1 [email protected] example.com 123.45.67.89
140+
sudo apt install -y wget # Debian/Ubuntu
141+
sudo yum install -y wget # CentOS
142+
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/overtls-install-selfsign.sh
143+
bash ./overtls-install-selfsign.sh
144144
```
145145
> 注意:`GFW` 可能會因爲你使用了自簽證書而封鎖你的服務器。所以請不要長期用於正式場合。

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ and apply for a certificate.
8484
8585
Currently only 3 `CPU` architectures of `Linux` machines are supported: `x86_64`, `armv7` and `arm64`.
8686
87-
```
87+
```bash
8888
sudo apt install -y wget # Debian/Ubuntu
8989
sudo yum install -y wget # CentOS
9090
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/overtls-install-musl.sh
@@ -155,10 +155,10 @@ If you have not owned a `domain name`, you can use the `openssl` command to gene
155155
for testing purposes.
156156
157157
```bash
158-
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/selfsign.sh
159-
head selfsign.sh -n 25
160-
chmod +x selfsign.sh
161-
./selfsign.sh CN JiangSu ChangZhou MyGreatOrg Root_CA Server1 [email protected] example.com 123.45.67.89
158+
sudo apt install -y wget # Debian/Ubuntu
159+
sudo yum install -y wget # CentOS
160+
wget https://raw.githubusercontent.com/shadowsocksr-live/overtls/master/install/overtls-install-selfsign.sh
161+
bash ./overtls-install-selfsign.sh
162162
```
163163
> Note: The `GFW` maybe block your server since you are using a self-signed certificate.
164164
> So please do not use it for long-term production purposes.

src/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ pub unsafe extern "C" fn over_tls_client_stop() -> c_int {
156156
///
157157
/// Create a SSR URL from the config file.
158158
#[no_mangle]
159-
pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char, include_ca_file: bool) -> *mut c_char {
159+
pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char) -> *mut c_char {
160160
let cfg_path = std::ffi::CStr::from_ptr(cfg_path);
161161
let cfg_path = match cfg_path.to_str() {
162162
Ok(s) => s,
163163
Err(_) => return std::ptr::null_mut(),
164164
};
165-
let url = match crate::config::generate_ssr_url(cfg_path, include_ca_file) {
165+
let url = match crate::config::generate_ssr_url(cfg_path) {
166166
Ok(s) => s,
167167
Err(_) => return std::ptr::null_mut(),
168168
};

src/bin/overtls.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,9 @@ fn main() -> Result<(), BoxError> {
4343
let mut config = Config::from_config_file(&opt.config)?;
4444
config.set_cache_dns(opt.cache_dns);
4545

46-
if opt.qrcode {
47-
if let Some(ref ca) = config.certificate_content() {
48-
if !opt.qrcode_cert {
49-
eprintln!("Certificate content:");
50-
eprint!("{}", ca);
51-
}
52-
}
53-
let qrcode = config.generate_ssr_url(opt.qrcode_cert)?;
54-
println!("{}", qrcode);
46+
if opt.generate_url {
47+
let url = config.generate_ssr_url()?;
48+
println!("{}", url);
5549
return Ok(());
5650
}
5751

src/cmdopt.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,9 @@ pub struct CmdOpt {
9797
/// Daemonize for unix family.
9898
pub daemonize: bool,
9999

100-
/// Generate QR code for client.
100+
/// Generate URL of the server node for client.
101101
#[arg(short, long)]
102-
pub qrcode: bool,
103-
104-
/// QR code contains certificate content.
105-
#[arg(long)]
106-
pub qrcode_cert: bool,
102+
pub generate_url: bool,
107103

108104
/// Use C API for client.
109105
#[arg(long)]

src/config.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl Config {
449449
Ok(config)
450450
}
451451

452-
pub fn generate_ssr_url(&self, include_ca_file: bool) -> Result<String> {
452+
pub fn generate_ssr_url(&self) -> Result<String> {
453453
let client = self.client.as_ref().ok_or(Error::from("client is not set"))?;
454454
let engine = crate::Base64Engine::UrlSafeNoPad;
455455
let method = self.method.as_ref().map_or("none".to_string(), |m| m.clone());
@@ -467,26 +467,24 @@ impl Config {
467467
let mut url = format!("{host}:{port}:origin:{method}:plain:{password}/?remarks={remarks}&ot_enable=1");
468468
url.push_str(&format!("&ot_domain={domain}&ot_path={tunnel_path}"));
469469

470-
if include_ca_file {
471-
if let Some(ref ca) = client.certificate_content() {
472-
let ca = crate::base64_encode(ca.as_bytes(), engine);
473-
url.push_str(&format!("&ot_cert={}", ca));
474-
}
470+
if let Some(ref ca) = client.certificate_content() {
471+
let ca = crate::base64_encode(ca.as_bytes(), engine);
472+
url.push_str(&format!("&ot_cert={}", ca));
475473
}
476474

477475
Ok(format!("ssr://{}", crate::base64_encode(url.as_bytes(), engine)))
478476
}
479477
}
480478

481-
pub(crate) fn generate_ssr_url<P>(path: P, include_ca_file: bool) -> Result<String>
479+
pub(crate) fn generate_ssr_url<P>(path: P) -> Result<String>
482480
where
483481
P: AsRef<std::path::Path>,
484482
{
485483
let config = Config::from_config_file(path)?;
486-
if config.certificate_content().is_some() && !include_ca_file {
487-
log::warn!("Certificate content discarded");
484+
if config.certificate_content().is_some() {
485+
log::warn!("Certificate content exists!");
488486
}
489-
config.generate_ssr_url(include_ca_file)
487+
config.generate_ssr_url()
490488
}
491489

492490
#[test]
@@ -507,7 +505,7 @@ fn test_config() {
507505

508506
config.check_correctness(false).unwrap();
509507

510-
let qrcode = config.generate_ssr_url(true).unwrap();
508+
let qrcode = config.generate_ssr_url().unwrap();
511509
println!("{:?}", qrcode);
512510

513511
let config = Config::from_ssr_url(&qrcode).unwrap();

0 commit comments

Comments
 (0)