mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-09-07 18:31:10 +00:00
Update wayback.py
This commit is contained in:
parent
51dbfe2eb5
commit
f1b587e6d3
|
@ -19,8 +19,27 @@ try:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print ("[*] Invaild configration: %s" % (str(e)))
|
print ("[*] Invaild configration: %s" % (str(e)))
|
||||||
|
|
||||||
|
def get_cached_page_from_google(url):
|
||||||
|
status_code, text = (0, '')
|
||||||
|
|
||||||
|
# Google Cache URL
|
||||||
|
google_cache_url = "https://webcache.googleusercontent.com/search?q=cache:" + url
|
||||||
|
|
||||||
|
# Send a GET request to Google Cache URL
|
||||||
|
response = requests.get(google_cache_url)
|
||||||
|
|
||||||
|
# Check if the request was successful (status code 200)
|
||||||
|
if response.status_code == 200:
|
||||||
|
text = response.text # Extract content from response
|
||||||
|
else:
|
||||||
|
status_code = response.status_code
|
||||||
|
|
||||||
|
return status_code, text
|
||||||
|
|
||||||
# API documentation: https://archive.org/help/wayback_api.php
|
# API documentation: https://archive.org/help/wayback_api.php
|
||||||
def get_previous_page_content(url):
|
def get_cached_page_from_wayback(url):
|
||||||
|
status_code, text = (0, '')
|
||||||
|
|
||||||
# Wayback Machine API URL
|
# Wayback Machine API URL
|
||||||
wayback_api_url = "http://archive.org/wayback/available?url=" + url
|
wayback_api_url = "http://archive.org/wayback/available?url=" + url
|
||||||
|
|
||||||
|
@ -42,18 +61,19 @@ def get_previous_page_content(url):
|
||||||
# If URL is available, fetch the content of the archived page
|
# If URL is available, fetch the content of the archived page
|
||||||
if archived_url:
|
if archived_url:
|
||||||
archived_page_response = requests.get(archived_url)
|
archived_page_response = requests.get(archived_url)
|
||||||
if archived_page_response.status_code == 200:
|
status_code = archived_page_response.status_code;
|
||||||
return archived_page_response.text
|
if status_code == 200:
|
||||||
|
text = archived_page_response.text
|
||||||
else:
|
else:
|
||||||
return "Error fetching archived page content. Status code: " + str(archived_page_response.status_code)
|
status_code = 404
|
||||||
else:
|
else:
|
||||||
return "No archived URL found."
|
status_code = 404
|
||||||
|
except:
|
||||||
|
status_code = 502
|
||||||
else:
|
else:
|
||||||
return "URL is not available in the archive."
|
status_code = response.status_code
|
||||||
except Exception as e:
|
|
||||||
return "Error processing response: " + str(e)
|
return status_code, text
|
||||||
else:
|
|
||||||
return "Error accessing Wayback Machine API. Status code: " + str(response.status_code)
|
|
||||||
|
|
||||||
class Wayback(Extension):
|
class Wayback(Extension):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -61,5 +81,20 @@ class Wayback(Extension):
|
||||||
self.connection_type = "wayback"
|
self.connection_type = "wayback"
|
||||||
|
|
||||||
def connect(self, conn, data, webserver, port, scheme, method, url):
|
def connect(self, conn, data, webserver, port, scheme, method, url):
|
||||||
previous_page_content = get_previous_page_content(url.decode(client_encoding))
|
connected = False
|
||||||
conn.send(previous_page_content.encode(client_encoding)
|
|
||||||
|
target_url = url.decode(client_encoding)
|
||||||
|
|
||||||
|
if not connected:
|
||||||
|
status_code, text = get_cached_page_from_google(target_url)
|
||||||
|
if status_code == 200:
|
||||||
|
conn.send(text.encode(client_encoding))
|
||||||
|
connected = True
|
||||||
|
|
||||||
|
if not connected:
|
||||||
|
status_code, text = get_cached_page_from_wayback(target_url)
|
||||||
|
if status_code == 200:
|
||||||
|
conn.send(text.encode(client_encoding))
|
||||||
|
connected = True
|
||||||
|
|
||||||
|
return connected
|
||||||
|
|
Loading…
Reference in New Issue
Block a user