Skip to content

Commit

Permalink
Merge pull request #4546 from GeoNode/ISSUE_4545
Browse files Browse the repository at this point in the history
[Fixes #4545] MapStore2 print button broken with 1.1 client release
  • Loading branch information
Alessio Fabiani authored Jun 24, 2019
2 parents 95e4829 + dc27440 commit 706469e
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 354 deletions.
1 change: 1 addition & 0 deletions geonode/geoserver/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def geoserver_urls(request):
"""Global values to pass to templates"""
defaults = dict(
GEOSERVER_LOCAL_URL=ogc_server_settings.LOCATION,
GEOSERVER_PUBLIC_LOCATION=ogc_server_settings.public_url,
GEOSERVER_BASE_URL=ogc_server_settings.public_url,
UPLOADER_URL=reverse('data_upload') if getattr(
settings,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ django-basic-authentication-decorator==0.9
# GeoNode org maintained apps.
django-geoexplorer==4.0.43
django-mapstore-adapter==1.0.2
django-geonode-mapstore-client==1.1
django-geonode-mapstore-client==1.3.1
geonode-user-messages==0.1.14
geonode-avatar==2.1.8
geonode-announcements==1.0.13
Expand Down
352 changes: 176 additions & 176 deletions scripts/spcgeonode/django/initialize.py
Original file line number Diff line number Diff line change
@@ -1,176 +1,176 @@
"""
This script initializes Geonode
"""

#########################################################
# Setting up the context
#########################################################

import os, requests, json, uuid, django, time
django.setup()

#########################################################
# Imports
#########################################################

from django.core.management import call_command
from django.db import connection
from django.db.utils import OperationalError
from requests.exceptions import ConnectionError
from geonode.people.models import Profile
from oauth2_provider.models import Application
from django.conf import settings

# Getting the secrets
admin_username = os.getenv('ADMIN_USERNAME')
admin_password = os.getenv('ADMIN_PASSWORD')
admin_email = os.getenv('ADMIN_EMAIL')


#########################################################
# 1. Waiting for PostgreSQL
#########################################################

print("-----------------------------------------------------")
print("1. Waiting for PostgreSQL")
for _ in range(60):
try:
connection.ensure_connection()
break
except OperationalError:
time.sleep(1)
else:
connection.ensure_connection()
connection.close()

#########################################################
# 2. Running the migrations
#########################################################

print("-----------------------------------------------------")
print("2. Running the migrations")
call_command('migrate', '--noinput')


#########################################################
# 3. Creating superuser if it doesn't exist
#########################################################

print("-----------------------------------------------------")
print("3. Creating/updating superuser")
try:
superuser = Profile.objects.get(username=admin_username)
superuser.set_password(admin_password)
superuser.is_active = True
superuser.email = admin_email
superuser.save()
print('superuser successfully updated')
except Profile.DoesNotExist:
superuser = Profile.objects.create_superuser(
admin_username,
admin_email,
admin_password
)
print('superuser successfully created')


#########################################################
# 4. Create an OAuth2 provider to use authorisations keys
#########################################################

print("-----------------------------------------------------")
print("4. Create/update an OAuth2 provider to use authorisations keys")
app, created = Application.objects.get_or_create(
pk=1,
name='GeoServer',
client_type='confidential',
authorization_grant_type='authorization-code',
skip_authorization=True
)
_host = os.getenv('HTTPS_HOST',"") if os.getenv('HTTPS_HOST',"") != "" else os.getenv('HTTP_HOST')
_port = os.getenv('HTTPS_PORT') if os.getenv('HTTPS_HOST',"") != "" else os.getenv('HTTP_PORT')
if _port and _port not in ("80", "443"):
redirect_uris = [
'http://{}:{}/geoserver'.format(_host, _port),
'http://{}:{}/geoserver/index.html'.format(_host, _port),
]
else:
redirect_uris = [
'http://{}/geoserver'.format(_host),
'http://{}/geoserver/index.html'.format(_host),
]

app.redirect_uris = "\n".join(redirect_uris)
app.save()
if created:
print('oauth2 provider successfully created')
else:
print('oauth2 provider successfully updated')


#########################################################
# 5. Loading fixtures
#########################################################

print("-----------------------------------------------------")
print("5. Loading fixtures")
call_command('loaddata', 'initial_data')


#########################################################
# 6. Running updatemaplayerip
#########################################################

print("-----------------------------------------------------")
print("6. Running updatemaplayerip")
# call_command('updatelayers') # TODO CRITICAL : this overrides the layer thumbnail of existing layers even if unchanged !!!
call_command('updatemaplayerip')


#########################################################
# 7. Collecting static files
#########################################################

print("-----------------------------------------------------")
print("7. Collecting static files")
call_command('collectstatic', '--noinput', verbosity=0)

#########################################################
# 8. Waiting for GeoServer
#########################################################

print("-----------------------------------------------------")
print("8. Waiting for GeoServer")
for _ in range(60*5):
try:
requests.head("http://geoserver:8080/geoserver")
break
except ConnectionError:
time.sleep(1)
else:
requests.head("http://geoserver:8080/geoserver")

#########################################################
# 9. Securing GeoServer
#########################################################

print("-----------------------------------------------------")
print("9. Securing GeoServer")

# Getting the old password
try:
r1 = requests.get('http://geoserver:8080/geoserver/rest/security/masterpw.json', auth=(admin_username, admin_password))
except requests.exceptions.ConnectionError as e:
print("Unable to connect to GeoServer. Make sure GeoServer is started and accessible.")
exit(1)
r1.raise_for_status()
old_password = json.loads(r1.text)["oldMasterPassword"]

if old_password=='M(cqp{V1':
print("Randomizing master password")
new_password = uuid.uuid4().hex
data = json.dumps({"oldMasterPassword":old_password,"newMasterPassword":new_password})
r2 = requests.put('http://geoserver:8080/geoserver/rest/security/masterpw.json', data=data, headers={'Content-Type': 'application/json'}, auth=(admin_username, admin_password))
r2.raise_for_status()
else:
print("Master password was already changed. No changes made.")
"""
This script initializes Geonode
"""

#########################################################
# Setting up the context
#########################################################

import os, requests, json, uuid, django, time
django.setup()

#########################################################
# Imports
#########################################################

from django.core.management import call_command
from django.db import connection
from django.db.utils import OperationalError
from requests.exceptions import ConnectionError
from geonode.people.models import Profile
from oauth2_provider.models import Application
from django.conf import settings

# Getting the secrets
admin_username = os.getenv('ADMIN_USERNAME')
admin_password = os.getenv('ADMIN_PASSWORD')
admin_email = os.getenv('ADMIN_EMAIL')


#########################################################
# 1. Waiting for PostgreSQL
#########################################################

print("-----------------------------------------------------")
print("1. Waiting for PostgreSQL")
for _ in range(60):
try:
connection.ensure_connection()
break
except OperationalError:
time.sleep(1)
else:
connection.ensure_connection()
connection.close()

#########################################################
# 2. Running the migrations
#########################################################

print("-----------------------------------------------------")
print("2. Running the migrations")
call_command('migrate', '--noinput')


#########################################################
# 3. Creating superuser if it doesn't exist
#########################################################

print("-----------------------------------------------------")
print("3. Creating/updating superuser")
try:
superuser = Profile.objects.get(username=admin_username)
superuser.set_password(admin_password)
superuser.is_active = True
superuser.email = admin_email
superuser.save()
print('superuser successfully updated')
except Profile.DoesNotExist:
superuser = Profile.objects.create_superuser(
admin_username,
admin_email,
admin_password
)
print('superuser successfully created')


#########################################################
# 4. Create an OAuth2 provider to use authorisations keys
#########################################################

print("-----------------------------------------------------")
print("4. Create/update an OAuth2 provider to use authorisations keys")
app, created = Application.objects.get_or_create(
pk=1,
name='GeoServer',
client_type='confidential',
authorization_grant_type='authorization-code',
skip_authorization=True
)
_host = os.getenv('HTTPS_HOST',"") if os.getenv('HTTPS_HOST',"") != "" else os.getenv('HTTP_HOST')
_port = os.getenv('HTTPS_PORT') if os.getenv('HTTPS_HOST',"") != "" else os.getenv('HTTP_PORT')
if _port and _port not in ("80", "443"):
redirect_uris = [
'http://{}:{}/geoserver'.format(_host, _port),
'http://{}:{}/geoserver/index.html'.format(_host, _port),
]
else:
redirect_uris = [
'http://{}/geoserver'.format(_host),
'http://{}/geoserver/index.html'.format(_host),
]

app.redirect_uris = "\n".join(redirect_uris)
app.save()
if created:
print('oauth2 provider successfully created')
else:
print('oauth2 provider successfully updated')


#########################################################
# 5. Loading fixtures
#########################################################

print("-----------------------------------------------------")
print("5. Loading fixtures")
call_command('loaddata', 'initial_data')


#########################################################
# 6. Running updatemaplayerip
#########################################################

print("-----------------------------------------------------")
print("6. Running updatemaplayerip")
# call_command('updatelayers') # TODO CRITICAL : this overrides the layer thumbnail of existing layers even if unchanged !!!
call_command('updatemaplayerip')


#########################################################
# 7. Collecting static files
#########################################################

print("-----------------------------------------------------")
print("7. Collecting static files")
call_command('collectstatic', '--noinput', verbosity=0)

#########################################################
# 8. Waiting for GeoServer
#########################################################

print("-----------------------------------------------------")
print("8. Waiting for GeoServer")
for _ in range(60*5):
try:
requests.head("http://geoserver:8080/geoserver")
break
except ConnectionError:
time.sleep(1)
else:
requests.head("http://geoserver:8080/geoserver")

#########################################################
# 9. Securing GeoServer
#########################################################

print("-----------------------------------------------------")
print("9. Securing GeoServer")

# Getting the old password
try:
r1 = requests.get('http://geoserver:8080/geoserver/rest/security/masterpw.json', auth=(admin_username, admin_password))
except requests.exceptions.ConnectionError as e:
print("Unable to connect to GeoServer. Make sure GeoServer is started and accessible.")
exit(1)
r1.raise_for_status()
old_password = json.loads(r1.text)["oldMasterPassword"]

if old_password=='M(cqp{V1':
print("Randomizing master password")
new_password = uuid.uuid4().hex
data = json.dumps({"oldMasterPassword":old_password,"newMasterPassword":new_password})
r2 = requests.put('http://geoserver:8080/geoserver/rest/security/masterpw.json', data=data, headers={'Content-Type': 'application/json'}, auth=(admin_username, admin_password))
r2.raise_for_status()
else:
print("Master password was already changed. No changes made.")
Loading

0 comments on commit 706469e

Please sign in to comment.