1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-24 06:59:52 +01:00

proxy mode: cookie based selector using session to coll

ui: add proxy_selector html, add switch link to error and banner
This commit is contained in:
Ilya Kreymer 2014-07-30 10:38:13 -07:00
parent fc6ffc6c11
commit 96d9f4dcad
8 changed files with 54 additions and 10 deletions

View File

@ -65,8 +65,8 @@ class ProxyRouter(object):
if proxy_options: if proxy_options:
proxy_options = proxy_options.get('proxy_options', {}) proxy_options = proxy_options.get('proxy_options', {})
self.resolver = ProxyAuthResolver(routes, proxy_options) #self.resolver = ProxyAuthResolver(routes, proxy_options)
#self.resolver = CookieResolver(routes, proxy_options) self.resolver = CookieResolver(routes, proxy_options)
self.magic_name = proxy_options.get('magic_name', 'pywb-proxy.com') self.magic_name = proxy_options.get('magic_name', 'pywb-proxy.com')

View File

@ -124,7 +124,6 @@ class CookieResolver(BaseCollResolver): # pragma: no cover
self.proxy_select_view = config.get('proxy_select_view') self.proxy_select_view = config.get('proxy_select_view')
if uwsgi_cache: if uwsgi_cache:
print 'UWSGI CACHE'
self.cache = UwsgiCache() self.cache = UwsgiCache()
else: else:
self.cache = {} self.cache = {}

View File

@ -135,11 +135,14 @@ class WSGIApp(object):
logging.info(err_msg) logging.info(err_msg)
err_details = None err_details = None
is_proxy_mode = env.get('pywb.proxy_host') is not None
if error_view: if error_view:
return error_view.render_response(exc_type=type(exc).__name__, return error_view.render_response(exc_type=type(exc).__name__,
err_msg=err_msg, err_msg=err_msg,
err_details=err_details, err_details=err_details,
status=status, status=status,
is_proxy_mode=is_proxy_mode,
err_url=err_url) err_url=err_url)
else: else:
return WbResponse.text_response(status + ' Error: ' + err_msg, return WbResponse.text_response(status + ' Error: ' + err_msg,

View File

@ -69,6 +69,10 @@ function init_banner() {
var capture_str = (wbinfo ? wbinfo.capture_str : ""); var capture_str = (wbinfo ? wbinfo.capture_str : "");
text += "<b id='_wb_capture_info'>" + capture_str + "</b>"; text += "<b id='_wb_capture_info'>" + capture_str + "</b>";
if (wbinfo.is_proxy_mode && wbinfo.url) {
text += '<br/><a href="//select.pywb-proxy.com/' + wbinfo.url + '">Switch Collection</a>';
}
banner.innerHTML = text; banner.innerHTML = text;

View File

@ -9,3 +9,10 @@
</pre> </pre>
</p> </p>
{% endif %} {% endif %}
{% if is_proxy_mode and err_url and status == '404 Not Found' %}
<p>
<a href="//select.pywb-proxy.com/{{ err_url }}">Try Different Collections</a>
</p>
{% endif %}

View File

@ -2,7 +2,7 @@
{% if rule.js_rewrite_location and include_wombat %} {% if rule.js_rewrite_location and include_wombat %}
<script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wombat.js'> </script> <script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wombat.js'> </script>
<script> <script>
{% set urlsplit = cdx['original'] | urlsplit %} {% set urlsplit = cdx.original | urlsplit %}
WB_wombat_init("{{ wbrequest.wb_prefix}}", WB_wombat_init("{{ wbrequest.wb_prefix}}",
"{{ cdx['timestamp'] if include_ts else ''}}", "{{ cdx['timestamp'] if include_ts else ''}}",
"{{ urlsplit.scheme }}", "{{ urlsplit.scheme }}",
@ -12,6 +12,7 @@
{% endif %} {% endif %}
<script> <script>
wbinfo = {} wbinfo = {}
wbinfo.url = "{{ cdx.original }}";
wbinfo.timestamp = "{{ cdx.timestamp }}"; wbinfo.timestamp = "{{ cdx.timestamp }}";
wbinfo.capture_str = "{{ cdx.timestamp | format_ts }}"; wbinfo.capture_str = "{{ cdx.timestamp | format_ts }}";
wbinfo.prefix = "{{ wbrequest.wb_prefix }}"; wbinfo.prefix = "{{ wbrequest.wb_prefix }}";

25
pywb/ui/proxy_select.html Normal file
View File

@ -0,0 +1,25 @@
<html>
<body>
<h2>Pywb Proxy Collection Selector</h1>
{% if coll %}
<p>
Current collection is: <b>{{ coll }}</b>
</p>
{% else %}
<p>You have attempted to load the url <b>{{ url }}</b>, but there are multiple collections available.</p>
{% endif %}
<p>Please select which collection you would like to use (You will be redirected back to <b>{{ url }}</b>):
</p>
<ul>
{% for route in routes %}
{% if route | is_wb_handler %}
<li><a href="{{ route_temp | format(route.path) }}">{{ route.path }}</a></li>
{% endif %}
{% endfor %}
</ul>
<p>(Once selected, you will not be prompted again, however you can return to this page to switch collections.)</p>
</body>
</html>

View File

@ -33,6 +33,7 @@ DEFAULTS = {
'search_html': 'ui/search.html', 'search_html': 'ui/search.html',
'home_html': 'ui/index.html', 'home_html': 'ui/index.html',
'error_html': 'ui/error.html', 'error_html': 'ui/error.html',
'proxy_select_html': 'ui/proxy_select.html',
'template_globals': {'static_path': 'static/default'}, 'template_globals': {'static_path': 'static/default'},
@ -218,14 +219,19 @@ def create_wb_router(passed_config={}):
# Check for new proxy mode! # Check for new proxy mode!
if config.get('enable_http_proxy', False): if config.get('enable_http_proxy', False):
router = ProxyArchivalRouter router = ProxyArchivalRouter
view = J2TemplateView.create_template(
config.get('proxy_select_html'),
'Proxy Coll Selector')
if not 'proxy_options' in passed_config:
passed_config['proxy_options'] = {}
passed_config['proxy_options']['proxy_select_view'] = view
else: else:
router = ArchivalRouter router = ArchivalRouter
if config.get('proxy_select_html'):
temp = J2TemplateView.create_template(config.get('proxy_select_html'),
'Proxy Coll Selector')
config.get('proxy_options')['proxy_select_view'] = temp
# Finally, create wb router # Finally, create wb router
return router( return router(
routes, routes,
@ -243,6 +249,5 @@ def create_wb_router(passed_config={}):
error_view=J2TemplateView.create_template(config.get('error_html'), error_view=J2TemplateView.create_template(config.get('error_html'),
'Error Page'), 'Error Page'),
config=config config=config
) )