Add unbreak option for dealing with Cloudflare.

This commit is contained in:
0x80 2021-12-30 00:00:00 +00:00
parent cfebf73510
commit 57e2a92532
Signed by: 0x80
GPG Key ID: 68368BCBC000EF51
4 changed files with 23 additions and 11 deletions

View File

@ -15,11 +15,10 @@ def download (platform, url, args, verbosity, return_http_code=False, follow_loc
c.setopt(c.FOLLOWLOCATION, follow_location) c.setopt(c.FOLLOWLOCATION, follow_location)
# TODO: handle possible arguments # TODO: handle possible arguments
# if args["user_agent"]: if "user_agent" in args:
# c.setopt(pycurl.USERAGENT, args["user_agent"] c.setopt(pycurl.USERAGENT, args["user_agent"])
# if args["ciphers"]: if "header" in args:
# c.setopt(pycurl.CIPHERS, args["ciphers"] c.setopt(pycurl.HTTPHEADER, args["header"])
notify ("Downloading " + url + "...", verbosity, platform) notify ("Downloading " + url + "...", verbosity, platform)
try: try:
c.perform() c.perform()

View File

@ -69,7 +69,6 @@ def options(params):
opts, args = getopt.getopt(params,"A:c:H:hno:p:qtUVv", [ opts, args = getopt.getopt(params,"A:c:H:hno:p:qtUVv", [
"user-agent=", "user-agent=",
"ciphers=", "ciphers=",
"compressed",
"header=", "header=",
"help", "help",
"license", "license",
@ -82,6 +81,7 @@ def options(params):
"suppress-errors", "suppress-errors",
"tls-max=", "tls-max=",
"tls13-ciphers=", "tls13-ciphers=",
"unbreak",
"verbose", "verbose",
"verbosity=", "verbosity=",
"version" "version"
@ -96,9 +96,6 @@ def options(params):
elif opt == "--ciphers": elif opt == "--ciphers":
d["ciphers"] = arg d["ciphers"] = arg
arg_count += 2 arg_count += 2
elif opt == "--compressed":
d["compressed"] = True
arg_count += 1
elif opt in ("-h", "--help"): elif opt in ("-h", "--help"):
print ("Usage: rsstube [OPTIONS] URL") print ("Usage: rsstube [OPTIONS] URL")
# not available yet # not available yet
@ -149,6 +146,22 @@ def options(params):
elif opt == "--tls13-ciphers": elif opt == "--tls13-ciphers":
d["tls13_ciphers"] = arg d["tls13_ciphers"] = arg
arg_count += 2 arg_count += 2
elif opt == "--unbreak":
# attempt to unbreak hostile websites (e.g., Cloudflare)
# based on Tor Browser cURL request
d["user_agent"] = 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0'
header = [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.5',
'Connection: keep-alive',
'Upgrade-Insecure-Requests: 1',
'Sec-Fetch-Dest: document',
'Sec-Fetch-Mode: navigate',
'Sec-Fetch-Site: none',
'Sec-Fetch-User: ?1',
'Cache-Control: max-age=0'
]
arg_count += 1
elif opt in ("-U", "--update"): elif opt in ("-U", "--update"):
update() update()
arg_count += 1 arg_count += 1

View File

@ -1,4 +1,4 @@
https://usersnap.com/blog/hands-on-experience-with-hugo-static-site-generator/ https://usersnap.com/blog/feed/ https://usersnap.com/blog/hands-on-experience-with-hugo-static-site-generator/ https://usersnap.com/blog/feed/
# uses Cloudflare # uses Cloudflare
#https://thenewstack.io/tutorial-use-hugo-to-generate-a-static-website/ https://thenewstack.io/feed/ https://thenewstack.io/tutorial-use-hugo-to-generate-a-static-website/ https://thenewstack.io/feed/

View File

@ -33,7 +33,7 @@ function test_site {
echo "Goal:" echo "Goal:"
echo "${links[1]}" echo "${links[1]}"
output=$(/usr/bin/python3 ../rsstube -o "" --output-format url "${links[0]}" | tail -1) output=$(/usr/bin/python3 ../rsstube --unbreak -o "" --output-format url "${links[0]}" | tail -1)
echo "Output:" echo "Output:"
echo "${output}" echo "${output}"