Beispiel #1
0
def init_geogig_repo(payload, store_name):
    username = ogc_server_settings.credentials.username
    password = ogc_server_settings.credentials.password
    url = ogc_server_settings.rest
    http = httplib2.Http(disable_ssl_certificate_validation=False)
    http.add_credentials(username, password)
    netloc = urlparse(url).netloc
    http.authorizations.append(
        httplib2.BasicAuthentication(
            (username, password),
            netloc,
            url,
            {},
            None,
            None,
            http
        ))
    rest_url = ogc_server_settings.LOCATION + "geogig/repos/" \
        + store_name + "/init.json"
    headers = {
        "Content-type": "application/json",
        "Accept": "application/json"
    }
    return http.request(rest_url, 'PUT',
                        json.dumps(payload), headers)
Beispiel #2
0
 def setup_connection(self):
     self.http = httplib2.Http(disable_ssl_certificate_validation=self.
                               disable_ssl_cert_validation)
     self.http.add_credentials(self.username, self.password)
     netloc = urlparse(self.service_url).netloc
     self.http.authorizations.append(
         httplib2.BasicAuthentication((self.username, self.password),
                                      netloc, self.service_url, {}, None,
                                      None, self.http))
Beispiel #3
0
def _gwc_client():
    http = httplib2.Http()
    http.add_credentials(*settings.GEOSERVER_CREDENTIALS)
    netloc = urlparse(settings.INTERNAL_GEOSERVER_BASE_URL).netloc
    http.authorizations.append(
        httplib2.BasicAuthentication(settings.GEOSERVER_CREDENTIALS, netloc,
                                     settings.INTERNAL_GEOSERVER_BASE_URL, {},
                                     None, None, http))
    return http
Beispiel #4
0
 def _setHttp(self):
     self.h = httplib2.Http()
     self.url = self.config.get("GeoServer", "url")
     username = self.config.get("GeoServer", "user")
     password = self.config.get("GeoServer", "password")
     self.h.add_credentials(username, password)
     netloc = urlparse(self.url).netloc
     self.h.authorizations.append(
         httplib2.BasicAuthentication((username, password), netloc,
                                      self.url, {}, None, None, self.h))
Beispiel #5
0
 def __init__(self, catalog):
     self.catalog = catalog
     http = httplib2.Http()
     http.add_credentials(catalog.username, catalog.password)
     netloc = urlparse(self.catalog.service_url).netloc
     http.authorizations.append(
         httplib2.BasicAuthentication((catalog.username, catalog.password),
                                      netloc, self.catalog.service_url, {},
                                      None, None, http))
     self.http = http
Beispiel #6
0
def get_wms():
    wms_url = ogc_server_settings.internal_ows + "?service=WMS&request=GetCapabilities&version=1.1.0"
    netloc = urlparse(wms_url).netloc
    http = httplib2.Http()
    http.add_credentials(_user, _password)
    http.authorizations.append(
        httplib2.BasicAuthentication((_user, _password), netloc, wms_url, {},
                                     None, None, http))
    body = http.request(wms_url)[1]
    _wms = WebMapService(wms_url, xml=body)
    return _wms
Beispiel #7
0
 def __init__(self, url, username, password):
     self.service_url = url
     if self.service_url.endswith("/"):
         self.service_url = self.service_url.strip("/")
     self.http = httplib2.Http()
     self.username = username
     self.password = password
     self.http.add_credentials(self.username, self.password)
     netloc = urlparse(url).netloc
     self.http.authorizations.append(
         httplib2.BasicAuthentication((username, password), netloc, url, {},
                                      None, None, self.http))
Beispiel #8
0
def get_wms():
    global _wms
    wms_url = settings.GEOSERVER_BASE_URL + "wms?request=GetCapabilities&version=1.1.0"
    netloc = urlparse(wms_url).netloc
    http = httplib2.Http()
    http.add_credentials(_user, _password)
    http.authorizations.append(
        httplib2.BasicAuthentication((_user, _password), netloc, wms_url, {},
                                     None, None, http))
    body = http.request(wms_url)[1]
    _wms = WebMapService(wms_url, xml=body)
    return _wms
Beispiel #9
0
    def request_geoserver_with_credentials(url):
        user = settings.OGC_SERVER['default']["USER"]
        password = settings.OGC_SERVER['default']["PASSWORD"]

        http_client = httplib2.Http()
        http_client.add_credentials(user, password)

        _netloc = urlparse(url).netloc
        http_client.authorizations.append(
            httplib2.BasicAuthentication((user, password), _netloc, url, {},
                                         None, None, http_client))
        resp, content = http_client.request(url)
        return content
Beispiel #10
0
 def __init__(self, catalog):
     self.catalog = catalog
     if isinstance(catalog, PKICatalog):
         http = httplib2.Http(ca_certs=catalog.ca_cert,
                              disable_ssl_certificate_validation=False)
         http.add_certificate(catalog.key, catalog.cert, '')
     else:
         http = httplib2.Http()
         http.add_credentials(catalog.username, catalog.password)
         netloc = urlparse(self.catalog.service_url).netloc
         http.authorizations.append(
             httplib2.BasicAuthentication(
                 (catalog.username, catalog.password), netloc,
                 self.catalog.service_url, {}, None, None, http))
     self.http = http
Beispiel #11
0
 def remove_geogig_repo(self, ref_name):
     username = ogc_server_settings.credentials.username
     password = ogc_server_settings.credentials.password
     url = ogc_server_settings.rest
     http = httplib2.Http(disable_ssl_certificate_validation=False)
     http.add_credentials(username, password)
     netloc = urlparse(url).netloc
     http.authorizations.append(
         httplib2.BasicAuthentication((username, password), netloc, url, {},
                                      None, None, http))
     rest_url = ogc_server_settings.LOCATION + "geogig/repos/" + ref_name + "/delete.json"
     resp, content = http.request(rest_url, 'GET')
     response = json.loads(content)
     token = response["response"]["token"]
     rest_url = ogc_server_settings.LOCATION + "geogig/repos/" + ref_name + "?token=" + token
     resp, content = http.request(rest_url, 'DELETE')
Beispiel #12
0
 def __init__(self,
              service_url,
              username="******",
              password="******",
              disable_ssl_certificate_validation=False):
     self.service_url = service_url
     if self.service_url.endswith("/"):
         self.service_url = self.service_url.strip("/")
     self.http = httplib2.Http(disable_ssl_certificate_validation=
                               disable_ssl_certificate_validation)
     self.username = username
     self.password = password
     self.http.add_credentials(self.username, self.password)
     netloc = urlparse(service_url).netloc
     self.http.authorizations.append(
         httplib2.BasicAuthentication((username, password), netloc,
                                      service_url, {}, None, None,
                                      self.http))
     self._cache = dict()
Beispiel #13
0
 def _render_thumbnail(self, spec):
     http = httplib2.Http()
     url = "%srest/printng/render.png" % settings.OGC_SERVER['default'][
         'LOCATION']
     hostname = urlparse(settings.SITEURL).hostname
     params = dict(width=198,
                   height=98,
                   auth="%s,%s,%s" % (hostname, _user, _password))
     url = url + "?" + urllib.urlencode(params)
     http.add_credentials(_user, _password)
     netloc = urlparse(url).netloc
     http.authorizations.append(
         httplib2.BasicAuthentication((_user, _password), netloc, url, {},
                                      None, None, http))
     # @todo annoying but not critical
     # openlayers controls posted back contain a bad character. this seems
     # to come from a − entity in the html, but it gets converted
     # to a unicode en-dash but is not uncoded properly during transmission
     # 'ignore' the error for now as controls are not being rendered...
     data = spec
     if type(data) == unicode:
         # make sure any stored bad values are wiped out
         # don't use keyword for errors - 2.6 compat
         # though unicode accepts them (as seen below)
         data = data.encode('ASCII', 'ignore')
     data = unicode(data, errors='ignore').encode('UTF-8')
     try:
         resp, content = http.request(url, "POST", data,
                                      {'Content-type': 'text/html'})
     except Exception:
         logging.warning('Error generating thumbnail')
         return
     if resp.status < 200 or resp.status > 299:
         logging.warning('Error generating thumbnail %s', content)
         return
     if len(content) == 0:
         logging.warning('Empty thumb content %s', content)
         return
     return content
Beispiel #14
0
from django.http import HttpResponse

from geonode.security.enumerations import AUTHENTICATED_USERS, ANONYMOUS_USERS, INVALID_PERMISSION_MESSAGE

_wms = None
_csw = None
_user, _password = settings.OGC_SERVER['default']['USER'], settings.OGC_SERVER[
    'default']['PASSWORD']

http_client = httplib2.Http()
http_client.add_credentials(_user, _password)
http_client.add_credentials(_user, _password)
_netloc = urlparse(settings.OGC_SERVER['default']['LOCATION']).netloc
http_client.authorizations.append(
    httplib2.BasicAuthentication((_user, _password), _netloc,
                                 settings.OGC_SERVER['default']['LOCATION'],
                                 {}, None, None, http_client))

DEFAULT_TITLE = ""
DEFAULT_ABSTRACT = ""


def check_geonode_is_up():
    """Verifies all geoserver is running,
       this is needed to be able to upload.
    """
    url = "%sweb/" % settings.OGC_SERVER['default']['LOCATION']
    resp, content = http_client.request(url, "GET")
    msg = ('Cannot connect to the GeoServer at %s\nPlease make sure you '
           'have started it.' % settings.OGC_SERVER['default']['LOCATION'])
    assert resp['status'] == '200', msg
Beispiel #15
0
ALPHABET = string.ascii_uppercase + string.ascii_lowercase + \
    string.digits + '-_'
ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
BASE = len(ALPHABET)
SIGN_CHARACTER = '$'
SQL_PARAMS_RE = re.compile(r'%\(([\w_\-]+)\)s')

http_client = httplib2.Http()
_user = settings.OGC_SERVER_DEFAULT_USER
_password = settings.OGC_SERVER_DEFAULT_PASSWORD
http_client.add_credentials(_user, _password)
http_client.add_credentials(_user, _password)
_netloc = urlparse.urlparse(settings.GEOSERVER_LOCATION).netloc
http_client.authorizations.append(
    httplib2.BasicAuthentication((_user, _password), _netloc,
                                 settings.GEOSERVER_LOCATION, {}, None, None,
                                 http_client))
custom_slugify = Slugify(separator='_')

signalnames = [
    'class_prepared', 'm2m_changed', 'post_delete', 'post_init', 'post_save',
    'post_syncdb', 'pre_delete', 'pre_init', 'pre_save'
]
signals_store = {}

id_none = id(None)

logger = logging.getLogger("geonode.utils")


def _get_basic_auth_info(request):
Beispiel #16
0
        return [self[alias] for alias in self]


ogc_server_settings = OGC_Servers_Handler(settings.OGC_SERVER)['default']

_wms = None
_csw = None
_user, _password = ogc_server_settings.credentials

http_client = httplib2.Http()
http_client.add_credentials(_user, _password)
http_client.add_credentials(_user, _password)
_netloc = urlparse(ogc_server_settings.LOCATION).netloc
http_client.authorizations.append(
    httplib2.BasicAuthentication((_user, _password), _netloc,
                                 ogc_server_settings.LOCATION, {}, None, None,
                                 http_client))

DEFAULT_TITLE = ""
DEFAULT_ABSTRACT = ""


def check_geonode_is_up():
    """Verifies all geoserver is running,
       this is needed to be able to upload.
    """
    url = "%sweb/" % ogc_server_settings.LOCATION
    resp, content = http_client.request(url, "GET")
    msg = ('Cannot connect to the GeoServer at %s\nPlease make sure you '
           'have started it.' % ogc_server_settings.LOCATION)
    assert resp['status'] == '200', msg
Beispiel #17
0
from xml.etree.ElementTree import XML, ParseError
import re

logger = logging.getLogger("geonode.proxy.views")

HGL_URL = 'http://hgl.harvard.edu:8080/HGL'

_valid_tags = "\{http\:\/\/www\.opengis\.net\/wms\}WMS_Capabilities|WMT_MS_Capabilities|WMS_DescribeLayerResponse|\{http\:\/\/www\.opengis\.net\/gml\}FeatureCollection|msGMLOutput|\{http\:\/\/www.opengis\.net\/wfs\}FeatureCollection"

_user, _password = settings.GEOSERVER_CREDENTIALS
h = httplib2.Http()
h.add_credentials(_user, _password)
_netloc = urlparse(settings.GEOSERVER_BASE_URL).netloc
h.authorizations.append(
    httplib2.BasicAuthentication((_user, _password), _netloc,
                                 settings.GEOSERVER_BASE_URL, {}, None, None,
                                 h))


@csrf_exempt
def proxy(request):
    if 'url' not in request.GET:
        return HttpResponse(
            "The proxy service requires a URL-encoded URL as a parameter.",
            status=400,
            content_type="text/plain")

    url = urlsplit(request.GET['url'])

    # Don't allow localhost connections unless in DEBUG mode
    if not settings.DEBUG and re.search('localhost|127.0.0.1', url.hostname):
Beispiel #18
0
tmpl = '<?xml version="1.0"?>\
<coverageStore>\
  <url>file://{file}</url>\
  <type>GeoTIFF</type>\
  <enabled>true</enabled>\
  <name>{store}</name>\
  <workspace>\
    <name>{workspace}</name>\
  </workspace>\
</coverageStore>'

http = httplib2.Http(disable_ssl_certificate_validation=True)
http.add_credentials(USERNAME, PASSWORD)
netloc = urlparse(REST_URL).netloc
http.authorizations.append(
    httplib2.BasicAuthentication((USERNAME, PASSWORD), netloc, REST_URL, {},
                                 None, None, http))
headers = {"Content-type": "text/xml", "Accept": "application/xml"}


def geoserver_datastores(rows):
    for row in rows:
        ws = row[1]
        store_name = row[3]
        file_name = row[0]
        print('Creating %s datastore' % store_name).ljust(70, ' '),
        # does not work due to https://github.com/boundlessgeo/gsconfig/issues/95 !
        #~ ds = cat.create_coveragestore2(store_name, ws)
        #~ ds.data_url = "file:///var/cache/sig/data/"+file_name
        #~ ds.type = "GeoTIFF"
        #~ ds.dirty.update(url = ds.data_url)
        #~ cat.save(ds)
Beispiel #19
0
def set_attributes(layer, overwrite=False):
    """
    Retrieve layer attribute names & types from Geoserver,
    then store in GeoNode database using Attribute model
    """

    #Appending authorizations seems necessary to avoid 'layer not found' from GeoServer
    http = httplib2.Http()
    http.add_credentials(_user, _password)
    _netloc = urlparse(ogc_server_settings.LOCATION).netloc
    http.authorizations.append(
        httplib2.BasicAuthentication(
            (_user, _password),
            _netloc,
            ogc_server_settings.LOCATION,
                {},
            None,
            None,
            http
        )
    )

    attribute_map = []
    if layer.storeType == "dataStore":
        dft_url = ogc_server_settings.LOCATION + "wfs?" + urllib.urlencode({
            "service": "wfs",
            "version": "1.0.0",
            "request": "DescribeFeatureType",
            "typename": layer.typename.encode('utf-8'),
            })
        try:
            body = http.request(dft_url)[1]
            doc = etree.fromstring(body)
            path = ".//{xsd}extension/{xsd}sequence/{xsd}element".format(xsd="{http://www.w3.org/2001/XMLSchema}")
            attribute_map = [[n.attrib["name"],n.attrib["type"]] for n in doc.findall(path)]
        except Exception:
            attribute_map = []
    elif layer.storeType == "coverageStore":
        dc_url = ogc_server_settings.LOCATION + "wcs?" + urllib.urlencode({
            "service": "wcs",
            "version": "1.1.0",
            "request": "DescribeCoverage",
            "identifiers": layer.typename.encode('utf-8')
        })
        try:
            response, body = http.request(dc_url)
            doc = etree.fromstring(body)
            path = ".//{wcs}Axis/{wcs}AvailableKeys/{wcs}Key".format(wcs="{http://www.opengis.net/wcs/1.1.1}")
            attribute_map = [[n.text,"raster"] for n in doc.findall(path)]
        except Exception:
            attribute_map = []

    attributes = layer.attribute_set.all()
    # Delete existing attributes if they no longer exist in an updated layer
    for la in attributes:
        lafound = False
        for field, ftype in attribute_map:
            if field == la.attribute:
                lafound = True
        if overwrite or not lafound:
            logger.debug("Going to delete [%s] for [%s]", la.attribute, layer.name.encode('utf-8'))
            la.delete()

    # Add new layer attributes if they don't already exist
    if attribute_map is not None:
        iter = len(Attribute.objects.filter(layer=layer)) + 1
        for field, ftype in attribute_map:
            if field is not None:
                la, created = Attribute.objects.get_or_create(layer=layer, attribute=field, attribute_type=ftype)
                if created:
                    if is_layer_attribute_aggregable(layer.storeType, field, ftype):
                        logger.debug("Generating layer attribute statistics")
                        result = get_attribute_statistics(layer.name, field)
                        if result is not None:
                            la.count = result['Count']
                            la.min = result['Min']
                            la.max = result['Max']
                            la.average = result['Average']
                            la.median = result['Median']
                            la.stddev = result['StandardDeviation']
                            la.sum = result['Sum']
                            la.unique_values = result['unique_values']
                            la.last_stats_updated = datetime.now()
                    la.attribute_label = field.title()
                    la.visible = ftype.find("gml:") != 0
                    la.display_order = iter
                    la.save()
                    iter += 1
                    logger.debug("Created [%s] attribute for [%s]", field, layer.name.encode('utf-8'))
    else:
        logger.debug("No attributes found")
Beispiel #20
0
def set_attributes(layer):
    """
    Retrieve layer attribute names & types from Geoserver,
    then store in GeoNode database using Attribute model
    """

    #Appending authorizations seems necessary to avoid 'layer not found' from GeoServer
    http = httplib2.Http()
    http.add_credentials(_user, _password)
    _netloc = urlparse(settings.GEOSERVER_BASE_URL).netloc
    http.authorizations.append(
        httplib2.BasicAuthentication(
            (_user, _password),
            _netloc,
            settings.GEOSERVER_BASE_URL,
                {},
            None,
            None,
            http
        )
    )

    attribute_map = []
    if layer.storeType == "dataStore":
        dft_url = settings.GEOSERVER_BASE_URL + "wfs?" + urllib.urlencode({
            "service": "wfs",
            "version": "1.0.0",
            "request": "DescribeFeatureType",
            "typename": layer.typename,
            })
        try:
            body = http.request(dft_url)[1]
            doc = etree.fromstring(body)
            path = ".//{xsd}extension/{xsd}sequence/{xsd}element".format(xsd="{http://www.w3.org/2001/XMLSchema}")
            attribute_map = [[n.attrib["name"],n.attrib["type"]] for n in doc.findall(path)]
        except Exception:
            attribute_map = []
    elif layer.storeType == "coverageStore":
        dc_url = settings.GEOSERVER_BASE_URL + "wcs?" + urllib.urlencode({
            "service": "wcs",
            "version": "1.1.0",
            "request": "DescribeCoverage",
            "identifiers": layer.typename
        })
        try:
            response, body = http.request(dc_url)
            doc = etree.fromstring(body)
            path = ".//{wcs}Axis/{wcs}AvailableKeys/{wcs}Key".format(wcs="{http://www.opengis.net/wcs/1.1.1}")
            attribute_map = [[n.text,"raster"] for n in doc.findall(path)]
        except Exception:
            attribute_map = []

    attributes = layer.attribute_set.all()
    # Delete existing attributes if they no longer exist in an updated layer
    for la in attributes:
        lafound = False
        for field, ftype in attribute_map:
            if field == la.attribute:
                lafound = True
        if not lafound:
            logger.debug("Going to delete [%s] for [%s]", la.attribute, layer.name)
            la.delete()

    # Add new layer attributes if they don't already exist
    if attribute_map is not None:
        iter = len(Attribute.objects.filter(layer=layer)) + 1
        for field, ftype in attribute_map:
            if field is not None:
                la, created = Attribute.objects.get_or_create(layer=layer, attribute=field, attribute_type=ftype)
                if created:
                    la.attribute_label = field.title()
                    la.visible = ftype.find("gml:") != 0
                    la.display_order = iter
                    la.save()
                    iter += 1
                    logger.debug("Created [%s] attribute for [%s]", field, layer.name)
    else:
        logger.debug("No attributes found")