def can_view(self, data_dict): format_lower = data_dict['resource']['format'].lower() same_domain = datapreview.on_same_domain(data_dict) #guess from file extension if not format_lower: #mimetype = mimetypes.guess_type(data_dict['resource']['url']) parsedUrl = urlparse.urlparse(data_dict['resource']['url']) format_lower = os.path.splitext(parsedUrl.path)[1][1:].encode('ascii','ignore').lower() correct_format = format_lower in self.FORMATS can_preview_from_domain = self.proxy_enabled or same_domain quality = 2 if p.toolkit.check_ckan_version('2.3'): return {'can_preview': True, 'quality': quality} elif p.toolkit.check_ckan_version('2.1'): if correct_format: if can_preview_from_domain: return {'can_preview': True, 'quality': quality} else: return {'can_preview': False, 'fixable': 'Enable resource_proxy', 'quality': quality} else: return {'can_preview': False, 'quality': quality} else: return correct_format and can_preview_from_domain
def can_view(self, data_dict): format_lower = data_dict['resource'].get('format', '').lower() same_domain = on_same_domain(data_dict) # Guess from file extension if not format_lower and data_dict['resource'].get('url'): format_lower = self._guess_format_from_extension( data_dict['resource']['url']) if not format_lower: resource_locator_protocol = data_dict['resource'].get( 'resource_locator_protocol', '').lower() if resource_locator_protocol and resource_locator_protocol.startswith( 'ogc:'): format_lower = resource_locator_protocol.split(':')[1] data_dict['resource']['format'] = format_lower else: return False view_formats = toolkit.config.get('ckanext.geoview.ol_viewer.formats', '') if view_formats: view_formats = view_formats.split(' ') else: view_formats = GEOVIEW_FORMATS correct_format = format_lower in view_formats can_preview_from_domain = self.proxy_enabled or same_domain return correct_format and can_preview_from_domain
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy same_domain = on_same_domain(data_dict) if not data_dict['resource'].get('format'): data_dict['resource']['format'] = \ self._guess_format_from_extension(data_dict['resource']['url']) if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) proxy_service_url = get_proxified_service_url(data_dict) else: proxy_url = data_dict['resource']['url'] proxy_service_url = data_dict['resource']['url'] gapi_key = toolkit.config.get('ckanext.geoview.gapi_key') if not toolkit.check_ckan_version(min_version='2.3'): toolkit.c.resource['proxy_url'] = proxy_url toolkit.c.resource['proxy_service_url'] = proxy_service_url toolkit.c.resource['gapi_key'] = gapi_key return { 'resource_view_json': 'resource_view' in data_dict and json.dumps(data_dict['resource_view']), 'proxy_service_url': proxy_service_url, 'proxy_url': proxy_url, 'gapi_key': gapi_key, 'basemapsConfig': self.basemapsConfig }
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy same_domain = on_same_domain(data_dict) if not data_dict["resource"].get("format"): data_dict["resource"][ "format"] = self._guess_format_from_extension( data_dict["resource"]["url"]) if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) proxy_service_url = utils.get_proxified_service_url(data_dict) else: proxy_url = data_dict["resource"]["url"] proxy_service_url = data_dict["resource"]["url"] gapi_key = toolkit.config.get("ckanext.geoview.gapi_key") return { "resource_view_json": "resource_view" in data_dict and json.dumps(data_dict["resource_view"]), "proxy_service_url": proxy_service_url, "proxy_url": proxy_url, "gapi_key": gapi_key, "basemapsConfig": self.basemapsConfig, }
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy same_domain = on_same_domain(data_dict) if not data_dict['resource'].get('format'): data_dict['resource']['format'] = \ self._guess_format_from_extension(data_dict['resource']['url']) proxy_service_url = None if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) proxy_service_url = get_proxified_service_url(data_dict) else: proxy_url = data_dict['resource']['url'] proxy_service_url = '' gapi_key = config.get('ckanext.geoview.gapi_key') if isinstance(self, p.IResourcePreview): p.toolkit.c.resource['proxy_url'] = proxy_url p.toolkit.c.resource['proxy_service_url'] = proxy_service_url p.toolkit.c.resource['gapi_key'] = gapi_key return { 'proxy_service_url': proxy_service_url, 'proxy_url': proxy_url, 'gapi_key': gapi_key }
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy same_domain = on_same_domain(data_dict) if not data_dict['resource'].get('format'): data_dict['resource']['format'] = \ self._guess_format_from_extension(data_dict['resource']['url']) proxy_service_url = None if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) proxy_service_url = get_proxified_service_url(data_dict) else: proxy_url = data_dict['resource']['url'] proxy_service_url = '' gapi_key = config.get('ckanext.geoview.gapi_key') if isinstance(self, p.IResourcePreview): p.toolkit.c.resource['proxy_url'] = proxy_url p.toolkit.c.resource['proxy_service_url'] = proxy_service_url p.toolkit.c.resource['gapi_key'] = gapi_key return {'proxy_service_url': proxy_service_url, 'proxy_url': proxy_url, 'gapi_key': gapi_key}
def can_view_resource(resource): ''' Returns a boolean if the resource is able to be loaded / viewed. This is intended to add functionality beyond user view permissions. return True if the resource is viewable, False if not. ''' data_dict = {'resource': resource} format_lower = resource.get('format', '').lower() proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) ''' requirement - If the format is a PDF (uses pdfview), from a proxy thats smaller than the configuration proxy max size value. ''' if format_lower in ['pdf', 'x-pdf', 'acrobat', 'vnd.pdf']: try: usock = urllib2.urlopen(resource['url'], '') if same_domain: return same_domain elif proxy_enabled: size = usock.info().get('Content-Length') if size is None: size = 0 size = float(size) # in bytes if size > MAX_FILE_SIZE: return False else: return True except Exception, e: log.error('can_view_resource:') log.error(e) return True
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy same_domain = on_same_domain(data_dict) if not data_dict['resource'].get('format'): data_dict['resource']['format'] = \ self._guess_format_from_extension(data_dict['resource']['url']) if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) proxy_service_url = get_proxified_service_url(data_dict) else: proxy_url = data_dict['resource']['url'] proxy_service_url = data_dict['resource']['url'] gapi_key = config.get('ckanext.geoview.gapi_key') if not p.toolkit.check_ckan_version(min_version='2.3'): p.toolkit.c.resource['proxy_url'] = proxy_url p.toolkit.c.resource['proxy_service_url'] = proxy_service_url p.toolkit.c.resource['gapi_key'] = gapi_key return {'resource_view_json': 'resource_view' in data_dict and json.dumps(data_dict['resource_view']), 'proxy_service_url': proxy_service_url, 'proxy_url': proxy_url, 'gapi_key': gapi_key, 'basemapsConfig' : self.basemapsConfig}
def can_view(self, data_dict): resource = data_dict["resource"] format_lower = resource.get("format", "").lower() same_domain = on_same_domain(data_dict) if format_lower in self.WMTS: return same_domain or self.proxy_enabled return False
def can_view(self, data_dict): resource = data_dict['resource'] mtype = resource.get('mimetype', '') same_domain = datapreview.on_same_domain(data_dict) if mtype in DC_MIME_TYPES and same_domain: return True else: return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) if format_lower in self.PDF: return same_domain or proxy_enabled return False
def can_view(self, data_dict): resource = data_dict["resource"] format_lower = resource.get("format", "").lower() proxy_enabled = p.plugin_loaded("resource_proxy") same_domain = datapreview.on_same_domain(data_dict) if format_lower in self.jsonp_formats: return True if format_lower in self.no_jsonp_formats: return proxy_enabled or same_domain return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource['format'].lower() proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) if format_lower in self.jsonp_formats: return True if format_lower in self.no_jsonp_formats: return proxy_enabled or same_domain return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) if format_lower == NGSI_FORMAT and check_query(resource): return same_domain or proxy_enabled else: return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() same_domain = on_same_domain(data_dict) if format_lower in self.GeoJSON: return same_domain or self.proxy_enabled return False
def can_view(self, data_dict): resource = data_dict["resource"] format_lower = resource.get("format", "").lower() proxy_enabled = p.plugin_loaded("resource_proxy") same_domain = datapreview.on_same_domain(data_dict) if format_lower in self.PDF: return same_domain or proxy_enabled return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) if format_lower in self.jsonp_formats: return True if format_lower in self.no_jsonp_formats: return proxy_enabled or same_domain return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() same_domain = datapreview.on_same_domain(data_dict) if (format_lower == NGSI_FORMAT and check_query(resource)) or format_lower == NGSI_REG_FORMAT: return same_domain or self.proxy_is_enabled else: return False
def can_view(self, data_dict): resource = data_dict["resource"] format_lower = resource["format"].lower() name_lower = resource.get("name", "").lower() same_domain = on_same_domain(data_dict) if format_lower in self.SHP or any( [shp in name_lower for shp in self.SHP]): return same_domain or self.proxy_enabled return False
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) if format_lower in self.NGSI_FORMATS and check_query(resource): if check_query(resource): return not same_domain or proxy_enabled else: return False else: return False
def setup_template_variables(self, context, data_dict): resource = data_dict['resource'] proxy_enabled = p.plugin_loaded('resource_proxy') oauth2_enabled = p.plugin_loaded('oauth2') same_domain = datapreview.on_same_domain(data_dict) if 'oauth_req' not in resource: oauth_req = 'false' else: oauth_req = resource['oauth_req'] url = resource['url'] if not check_query(resource): details = "</br></br>This is not a ContextBroker query, please check <a href='https://forge.fiware.org/plugins/mediawiki/wiki/fiware/index.php/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_User_and_Programmers_Guide'>Orion Context Broker documentation</a></br></br></br>" f_details = "This is not a ContextBroker query, please check Orion Context Broker documentation." h.flash_error(f_details, allow_html=False) view_enable = [False, details] elif not same_domain and not proxy_enabled: details = "</br></br>Enable resource_proxy</br></br></br>" f_details = "Enable resource_proxy." h.flash_error(f_details, allow_html=False) view_enable = [False, details] url = '' else: if not same_domain: url = self.get_proxified_ngsi_url(data_dict) if oauth_req == 'true' and not p.toolkit.c.user: details = "</br></br>In order to see this resource properly, you need to be logged in.</br></br></br>" f_details = "In order to see this resource properly, you need to be logged in." h.flash_error(f_details, allow_html=False) view_enable = [False, details] elif oauth_req == 'true' and not oauth2_enabled: details = "</br></br>In order to see this resource properly, enable oauth2 extension</br></br></br>" f_details = "In order to see this resource properly, enable oauth2 extension." h.flash_error(f_details, allow_html=False) view_enable = [False, details] else: data_dict['resource']['url'] = url view_enable = [True, 'OK'] return { 'resource_json': json.dumps(data_dict['resource']), 'resource_url': json.dumps(url), 'view_enable': json.dumps(view_enable) }
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy same_domain = datapreview.on_same_domain(data_dict) p.toolkit.c.gapi_key = h.config.get('ckanext.geoview.gapi.key') if p.toolkit.check_ckan_version('2.3'): proxy_url = proxy.get_proxified_resource_url(data_dict) else: proxy_url = data_dict['resource']['url'] if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) return {'proxy_service_url': json.dumps(get_proxified_service_url(data_dict)), 'proxy_url': json.dumps(proxy_url)}
def setup_template_variables(self, context, data_dict): import ckanext.resourceproxy.plugin as proxy config['ckanext.geoview.layername'] = data_dict['resource'].get('name') log.info(' ---- data_dict[resource].get(name) ----') log.info(data_dict['resource'].get('name')) same_domain = on_same_domain(data_dict) if not data_dict['resource'].get('format'): data_dict['resource']['format'] = \ self._guess_format_from_extension(data_dict['resource']['url']) if self.proxy_enabled and not same_domain: proxy_url = proxy.get_proxified_resource_url(data_dict) proxy_service_url = get_proxified_service_url(data_dict) else: proxy_url = data_dict['resource']['url'] proxy_service_url = data_dict['resource']['url'] log.info(" -> self.proxy_enabled and not same_domain ") log.info(self.proxy_enabled and not same_domain) log.info(" proxy_url ") log.info(proxy_url) log.info(" proxy_service_url ") log.info(proxy_service_url) gapi_key = config.get('ckanext.geoview.gapi_key') if not p.toolkit.check_ckan_version(min_version='2.3'): p.toolkit.c.resource['proxy_url'] = proxy_url p.toolkit.c.resource['proxy_service_url'] = proxy_service_url p.toolkit.c.resource['gapi_key'] = gapi_key return { 'resource_view_json': 'resource_view' in data_dict and json.dumps(data_dict['resource_view']), 'proxy_service_url': proxy_service_url, 'proxy_url': proxy_url, 'gapi_key': gapi_key, 'resource_name': data_dict['resource']['name'] }
def can_view(self, data_dict): format_lower = data_dict['resource'].get('format', '').lower() same_domain = on_same_domain(data_dict) # Guess from file extension if not format_lower and data_dict['resource'].get('url'): format_lower = self._guess_format_from_extension( data_dict['resource']['url']) view_formats = config.get('ckanext.geoview.ol_viewer.formats', '') if view_formats: view_formats.split(' ') else: view_formats = GEOVIEW_FORMATS correct_format = format_lower in view_formats can_preview_from_domain = self.proxy_enabled or same_domain return correct_format and can_preview_from_domain
def can_view(self, data_dict): resource = data_dict['resource'] format_lower = resource.get('format', '').lower() same_domain = on_same_domain(data_dict) # Guess from file extension if not format_lower and resource.get('url'): format_lower = self._guess_format_from_extension(resource['url']) view_formats = config.get('ckanext.geoview.ol_viewer.formats', '') if view_formats: view_formats.split(' ') else: view_formats = GEOVIEW_FORMATS correct_format = format_lower in view_formats can_preview_from_domain = self.proxy_enabled or same_domain return correct_format and can_preview_from_domain
def setup_template_variables(self, context, data_dict): resource = data_dict['resource'] same_domain = datapreview.on_same_domain(data_dict) format_lower = resource.get('format', '').lower() resource.setdefault('auth_type', 'none') url = resource['url'] if format_lower == NGSI_FORMAT and not check_query(resource): details = "</br></br>This is not a ContextBroker query, please check <a href='https://forge.fiware.org/plugins/mediawiki/wiki/fiware/index.php/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_User_and_Programmers_Guide'>Orion Context Broker documentation</a></br></br></br>" f_details = "This is not a ContextBroker query, please check Orion Context Broker documentation." h.flash_error(f_details, allow_html=False) view_enable = [False, details] elif not same_domain and not self.proxy_is_enabled: details = "</br></br>Enable resource_proxy</br></br></br>" f_details = "Enable resource_proxy." h.flash_error(f_details, allow_html=False) view_enable = [False, details] url = '' else: url = self.get_proxified_ngsi_url(data_dict) if resource['auth_type'] != 'none' and not p.toolkit.c.user: details = "</br></br>In order to see this resource properly, you need to be logged in.</br></br></br>" f_details = "In order to see this resource properly, you need to be logged in." h.flash_error(f_details, allow_html=False) view_enable = [False, details] elif resource['auth_type'] != 'none' and not self.oauth2_is_enabled: details = "</br></br>In order to see this resource properly, enable oauth2 extension</br></br></br>" f_details = "In order to see this resource properly, enable oauth2 extension." h.flash_error(f_details, allow_html=False) view_enable = [False, details] else: data_dict['resource']['url'] = url view_enable = [True, 'OK'] return { 'resource_json': json.dumps(data_dict['resource']), 'resource_url': json.dumps(url), 'view_enable': json.dumps(view_enable) }
def can_view(self, data_dict): format_lower = data_dict["resource"].get("format", "").lower() same_domain = on_same_domain(data_dict) # Guess from file extension if not format_lower and data_dict["resource"].get("url"): format_lower = self._guess_format_from_extension( data_dict["resource"]["url"]) if not format_lower: return False view_formats = toolkit.config.get("ckanext.geoview.ol_viewer.formats", "") if view_formats: view_formats = view_formats.split(" ") else: view_formats = self.GEOVIEW_FORMATS correct_format = format_lower in view_formats can_preview_from_domain = self.proxy_enabled or same_domain return correct_format and can_preview_from_domain
def can_view(self, data_dict): format_lower = data_dict['resource'].get('format', '').lower() same_domain = on_same_domain(data_dict) # Guess from file extension if not format_lower and data_dict['resource'].get('url'): format_lower = self._guess_format_from_extension( data_dict['resource']['url']) ''' TODO implement format validation depending on supported formats server-side view_formats = config.get('ckanext.geoview.ol_viewer.formats', '') if view_formats: view_formats.split(' ') else: view_formats = MOSAICS_FORMATS correct_format = format_lower in view_formats ''' # TODO use local proxy to lower charge on mosaics server # for now simply redirect everything to mosaics server can_preview_from_domain = True # self.proxy_enabled or same_domain return can_preview_from_domain #and correct_format
def setup_template_variables(self, context, data_dict): if p.toolkit.check_ckan_version(min_version='2.3'): metadata = {'ngsi_formats': self.NGSI_FORMATS} resource = data_dict['resource'] proxy_enabled = p.plugin_loaded('resource_proxy') oauth2_enabled = p.plugin_loaded('oauth2') same_domain = datapreview.on_same_domain(data_dict) if 'oauth_req' not in resource: oauth_req = 'false' else: oauth_req = resource['oauth_req'] if proxy_enabled and not same_domain: if check_query(resource): if oauth_req == 'true' and not p.toolkit.c.user: details = "</br></br>In order to see this resource properly, you need to be logged in.</br></br></br>" f_details = "In order to see this resource properly, you need to be logged in." h.flash_error(f_details, allow_html=False) view_enable = [False, details] url = proxy.get_proxified_resource_url(data_dict) elif oauth_req == 'true' and not oauth2_enabled: details = "</br></br>In order to see this resource properly, enable oauth2 extension</br></br></br>" f_details = "In order to see this resource properly, enable oauth2 extension." h.flash_error(f_details, allow_html=False) view_enable = [False, details] url = proxy.get_proxified_resource_url(data_dict) else: url = self.get_proxified_ngsi_url(data_dict) data_dict['resource']['url'] = url view_enable = [True, 'OK'] else: details = "</br></br>This is not a ContextBroker query, please check <a href='https://forge.fiware.org/plugins/mediawiki/wiki/fiware/index.php/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_User_and_Programmers_Guide'>Orion Context Broker documentation</a></br></br></br>" f_details = "This is not a ContextBroker query, please check Orion Context Broker documentation." h.flash_error(f_details, allow_html=False) view_enable = [False, details] url = proxy.get_proxified_resource_url(data_dict) else: if proxy_enabled: details = "</br></br>Enable resource_proxy</br></br></br>" f_details = "Enable resource_proxy." else: details = "</br></br>This is not a ContextBroker query, please check <a href='https://forge.fiware.org/plugins/mediawiki/wiki/fiware/index.php/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_User_and_Programmers_Guide'>Orion Context Broker documentation</a></br></br></br>" f_details = "This is not a ContextBroker query, please check Orion Context Broker documentation." h.flash_error(f_details, allow_html=False) view_enable = [False, details] url = '' return {'preview_metadata': json.dumps(metadata), 'resource_json': json.dumps(data_dict['resource']), 'resource_url': json.dumps(url), 'view_enable': json.dumps(view_enable)} else: if self.proxy_is_enabled and not data_dict['resource']['on_same_domain']: if check_query(data_dict['resource']): url = self.get_proxified_ngsi_url(data_dict) p.toolkit.c.resource['url'] = url
def can_view(self, data_dict): resource = data_dict['package'] proxy_enabled = p.plugin_loaded('resource_proxy') same_domain = datapreview.on_same_domain(data_dict) return same_domain or proxy_enabled