Remove escaped_fragment snapshot rendering.
This commit is contained in:
parent
fea47bdaed
commit
746728ba24
5 changed files with 0 additions and 64 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,5 @@
|
|||
*.pyc
|
||||
venv
|
||||
static/snapshots/
|
||||
screenshots/screenshots/
|
||||
stack
|
||||
grunt/node_modules
|
||||
|
|
|
@ -29,7 +29,6 @@ RUN apt-get install -y \
|
|||
libsasl2-modules \
|
||||
nodejs \
|
||||
npm \
|
||||
phantomjs \
|
||||
python-dev \
|
||||
python-pip \
|
||||
python-virtualenv
|
||||
|
|
|
@ -8,10 +8,6 @@ if ($host = "www.quay.io") {
|
|||
return 301 $proper_scheme://quay.io$request_uri;
|
||||
}
|
||||
|
||||
if ($args ~ "_escaped_fragment_") {
|
||||
rewrite ^ /snapshot$uri;
|
||||
}
|
||||
|
||||
# Disable the ability to be embedded into iframes
|
||||
add_header X-Frame-Options DENY;
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ from health.healthcheck import get_healthchecker
|
|||
from util.cache import no_cache
|
||||
from util.headers import parse_basic_auth
|
||||
from util.invoice import renderInvoiceToPdf
|
||||
from util.seo import render_snapshot
|
||||
from util.systemlogs import build_logs_archive
|
||||
from util.useremails import send_email_changed
|
||||
|
||||
|
@ -84,19 +83,6 @@ def user_view(path):
|
|||
return index('')
|
||||
|
||||
|
||||
@web.route('/snapshot', methods=['GET'])
|
||||
@web.route('/snapshot/', methods=['GET'])
|
||||
@web.route('/snapshot/<path:path>', methods=['GET'])
|
||||
def snapshot(path = ''):
|
||||
parsed = urlparse(request.url)
|
||||
final_url = '%s://%s/%s' % (parsed.scheme, 'localhost', path)
|
||||
result = render_snapshot(final_url)
|
||||
if result:
|
||||
return result
|
||||
|
||||
abort(404)
|
||||
|
||||
|
||||
@route_show_if(features.ACI_CONVERSION)
|
||||
@web.route('/aci-signing-key')
|
||||
@no_cache
|
||||
|
|
44
util/seo.py
44
util/seo.py
|
@ -1,44 +0,0 @@
|
|||
import subprocess
|
||||
import logging
|
||||
|
||||
from urllib import urlencode
|
||||
from urlparse import parse_qs, urlsplit, urlunsplit
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def set_query_parameter(url, param_name, param_value):
|
||||
# From: http://stackoverflow.com/questions/4293460/how-to-add-custom-parameters-to-an-url-query-string-with-python
|
||||
scheme, netloc, path, query_string, fragment = urlsplit(url)
|
||||
query_params = parse_qs(query_string)
|
||||
|
||||
query_params[param_name] = [param_value]
|
||||
new_query_string = urlencode(query_params, doseq=True)
|
||||
|
||||
return urlunsplit((scheme, netloc, path, new_query_string, fragment))
|
||||
|
||||
|
||||
def render_snapshot(url):
|
||||
logger.info('Snapshotting url: %s' % url)
|
||||
|
||||
url = set_query_parameter(url, 'use_cdn', False)
|
||||
out_html = subprocess.check_output(['phantomjs', '--ignore-ssl-errors=yes',
|
||||
'--disk-cache=yes', '--ssl-protocol=tlsv1',
|
||||
'util/phantomjs-runner.js', url])
|
||||
|
||||
if not out_html or out_html.strip() == 'Not Found':
|
||||
return None
|
||||
|
||||
# Remove script tags
|
||||
logger.info('Removing script tags: %s' % url)
|
||||
|
||||
try:
|
||||
soup = BeautifulSoup(out_html.decode('utf8'), 'html.parser')
|
||||
to_extract = soup.findAll('script')
|
||||
for item in to_extract:
|
||||
item.extract()
|
||||
except:
|
||||
logger.exception('Exception when trying to parse served HTML')
|
||||
return out_html
|
||||
|
||||
return str(soup)
|
Reference in a new issue