Merge pull request #49 from Y2Z/ignore-ca
Add flag to ignore errors related to TLS certificates
This commit is contained in:
commit
31c88061cd
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "monolith"
|
name = "monolith"
|
||||||
version = "2.0.15"
|
version = "2.0.16"
|
||||||
authors = [
|
authors = [
|
||||||
"Sunshine <sunshine@uberspace.net>",
|
"Sunshine <sunshine@uberspace.net>",
|
||||||
"Mahdi Robatipoor <mahdi.robatipoor@gmail.com>",
|
"Mahdi Robatipoor <mahdi.robatipoor@gmail.com>",
|
||||||
|
@ -23,6 +23,7 @@ If compared to saving websites with `wget -mpk`, this tool embeds all assets as
|
|||||||
### Options
|
### Options
|
||||||
- `-i`: Remove images
|
- `-i`: Remove images
|
||||||
- `-j`: Exclude JavaScript
|
- `-j`: Exclude JavaScript
|
||||||
|
- `-k`: Accept invalid X.509 (TLS) certificates
|
||||||
- `-s`: Silent mode
|
- `-s`: Silent mode
|
||||||
- `-u`: Specify custom User-Agent
|
- `-u`: Specify custom User-Agent
|
||||||
|
|
||||||
|
28
src/html.rs
28
src/html.rs
@ -70,6 +70,7 @@ pub fn walk_and_embed_assets(
|
|||||||
opt_no_images: bool,
|
opt_no_images: bool,
|
||||||
opt_user_agent: &str,
|
opt_user_agent: &str,
|
||||||
opt_silent: bool,
|
opt_silent: bool,
|
||||||
|
opt_insecure: bool,
|
||||||
) {
|
) {
|
||||||
match node.data {
|
match node.data {
|
||||||
NodeData::Document => {
|
NodeData::Document => {
|
||||||
@ -81,6 +82,7 @@ pub fn walk_and_embed_assets(
|
|||||||
opt_no_images,
|
opt_no_images,
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +135,9 @@ pub fn walk_and_embed_assets(
|
|||||||
"",
|
"",
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
).unwrap_or(EMPTY_STRING.clone());
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(favicon_datauri.as_str());
|
attr.value.push_slice(favicon_datauri.as_str());
|
||||||
}
|
}
|
||||||
@ -153,7 +157,9 @@ pub fn walk_and_embed_assets(
|
|||||||
"text/css",
|
"text/css",
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
).unwrap_or(EMPTY_STRING.clone());
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(css_datauri.as_str());
|
attr.value.push_slice(css_datauri.as_str());
|
||||||
}
|
}
|
||||||
@ -190,7 +196,9 @@ pub fn walk_and_embed_assets(
|
|||||||
"",
|
"",
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
).unwrap_or(EMPTY_STRING.clone());
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(img_datauri.as_str());
|
attr.value.push_slice(img_datauri.as_str());
|
||||||
}
|
}
|
||||||
@ -216,7 +224,9 @@ pub fn walk_and_embed_assets(
|
|||||||
"",
|
"",
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
).unwrap_or(EMPTY_STRING.clone());
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(source_datauri.as_str());
|
attr.value.push_slice(source_datauri.as_str());
|
||||||
}
|
}
|
||||||
@ -262,7 +272,9 @@ pub fn walk_and_embed_assets(
|
|||||||
"application/javascript",
|
"application/javascript",
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
).unwrap_or(EMPTY_STRING.clone());
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
attr.value.clear();
|
attr.value.clear();
|
||||||
attr.value.push_slice(js_datauri.as_str());
|
attr.value.push_slice(js_datauri.as_str());
|
||||||
}
|
}
|
||||||
@ -302,7 +314,9 @@ pub fn walk_and_embed_assets(
|
|||||||
"text/html",
|
"text/html",
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
).unwrap_or(EMPTY_STRING.clone());
|
opt_insecure,
|
||||||
|
)
|
||||||
|
.unwrap_or(EMPTY_STRING.clone());
|
||||||
let dom = html_to_dom(&iframe_data);
|
let dom = html_to_dom(&iframe_data);
|
||||||
walk_and_embed_assets(
|
walk_and_embed_assets(
|
||||||
&src_full_url,
|
&src_full_url,
|
||||||
@ -311,6 +325,7 @@ pub fn walk_and_embed_assets(
|
|||||||
opt_no_images,
|
opt_no_images,
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
);
|
);
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap();
|
serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap();
|
||||||
@ -341,6 +356,7 @@ pub fn walk_and_embed_assets(
|
|||||||
opt_no_images,
|
opt_no_images,
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,15 @@ pub fn retrieve_asset(
|
|||||||
as_dataurl: bool,
|
as_dataurl: bool,
|
||||||
as_mime: &str,
|
as_mime: &str,
|
||||||
opt_user_agent: &str,
|
opt_user_agent: &str,
|
||||||
opt_silent: bool
|
opt_silent: bool,
|
||||||
|
opt_insecure: bool,
|
||||||
) -> Result<String, reqwest::Error> {
|
) -> Result<String, reqwest::Error> {
|
||||||
if is_data_url(&url).unwrap() {
|
if is_data_url(&url).unwrap() {
|
||||||
Ok(url.to_string())
|
Ok(url.to_string())
|
||||||
} else {
|
} else {
|
||||||
let client = Client::builder()
|
let client = Client::builder()
|
||||||
.timeout(Duration::from_secs(10))
|
.timeout(Duration::from_secs(10))
|
||||||
|
.danger_accept_invalid_certs(opt_insecure)
|
||||||
.build()?;
|
.build()?;
|
||||||
let mut response = client
|
let mut response = client
|
||||||
.get(url)
|
.get(url)
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -23,6 +23,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.args_from_usage("-i, --no-images 'Removes images'")
|
.args_from_usage("-i, --no-images 'Removes images'")
|
||||||
.args_from_usage("-j, --no-js 'Excludes JavaScript'")
|
.args_from_usage("-j, --no-js 'Excludes JavaScript'")
|
||||||
|
.args_from_usage("-k, --insecure 'Accept invalid X.509 (TLS) certificates'")
|
||||||
.args_from_usage("-s, --silent 'Suppress verbosity'")
|
.args_from_usage("-s, --silent 'Suppress verbosity'")
|
||||||
.args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
|
.args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
|
||||||
.get_matches();
|
.get_matches();
|
||||||
@ -31,11 +32,19 @@ fn main() {
|
|||||||
let arg_target = command.value_of("url").unwrap();
|
let arg_target = command.value_of("url").unwrap();
|
||||||
let opt_no_images = command.is_present("no-images");
|
let opt_no_images = command.is_present("no-images");
|
||||||
let opt_no_js = command.is_present("no-js");
|
let opt_no_js = command.is_present("no-js");
|
||||||
|
let opt_insecure = command.is_present("insecure");
|
||||||
let opt_silent = command.is_present("silent");
|
let opt_silent = command.is_present("silent");
|
||||||
let opt_user_agent = command.value_of("user-agent").unwrap_or(DEFAULT_USER_AGENT);
|
let opt_user_agent = command.value_of("user-agent").unwrap_or(DEFAULT_USER_AGENT);
|
||||||
|
|
||||||
if is_valid_url(arg_target) {
|
if is_valid_url(arg_target) {
|
||||||
let data = retrieve_asset(&arg_target, false, "", opt_user_agent, opt_silent).unwrap();
|
let data = retrieve_asset(
|
||||||
|
&arg_target,
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
opt_user_agent,
|
||||||
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
|
).unwrap();
|
||||||
let dom = html_to_dom(&data);
|
let dom = html_to_dom(&data);
|
||||||
|
|
||||||
walk_and_embed_assets(
|
walk_and_embed_assets(
|
||||||
@ -45,6 +54,7 @@ fn main() {
|
|||||||
opt_no_images,
|
opt_no_images,
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
);
|
);
|
||||||
|
|
||||||
print_dom(&dom.document);
|
print_dom(&dom.document);
|
||||||
|
Loading…
Reference in New Issue
Block a user