Skip to content

Commit

Permalink
Updates needed to make this work in production.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklholub committed Aug 16, 2023
1 parent 50ab23e commit 048ac77
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 45 deletions.
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ aenum==3.1.15
asgiref==3.7.2
backports.zoneinfo==0.2.1
beautifulsoup4==4.12.2
boto3==1.26.163
botocore==1.29.163
boto3
botocore
bs4==0.0.1
certifi==2023.5.7
cffi==1.15.1
Expand Down Expand Up @@ -32,7 +32,7 @@ mysqlclient==2.2.0
networkx==3.1
numpy==1.25.0
oauthlib==3.2.2
onelogin==3.1.5
onelogin
packaging==23.1
Pillow==9.5.0
protobuf==3.20.3
Expand All @@ -54,6 +54,6 @@ soupsieve==2.4.1
sqlparse==0.4.4
typed-ast==1.5.4
typing_extensions==4.6.3
urllib3==1.26.16
xmlsec==1.3.13
urllib3
xmlsec
zipp==3.15.0
4 changes: 2 additions & 2 deletions sites/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def formfield_for_manytomany(self, db_field, request, **kwargs):
form = super(ProjectAdmin, self).form
if str(db_field) == 'sites.Project.userlist':
kwargs['queryset'] = Contact.objects.all().order_by('firstname')
ncontact = Contact.objects.filter(firstname=settings.NONE_NAME)
if ncontact.count() > 0:
ncontact = Contact.objects.filter(email=settings.NONE_EMAIL)
if ncontact.count() > int(0):
ncontact = ncontact[0]
form = super(ProjectAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
form.initial = {ncontact.id: True}
Expand Down
17 changes: 17 additions & 0 deletions sites/management/commands/add_none_contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Add the NONE email Contact if it does not exits. This placeholder is required to make the GUI happy.
"""
from __future__ import unicode_literals


# https://stackoverflow.com/questions/19475955/using-django-models-in-external-python-script
from django.core.management.base import BaseCommand

from sites.models import add_none_contact


class Command(BaseCommand):
help = "add the NONE email Contact if needed"

def handle(self, *args, **options):
add_none_contact()
6 changes: 6 additions & 0 deletions sites/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def add_groups_and_permissions():
msg = str(now) + ":GroupobjectAddedPerms:" + groupname
logger.info(msg)

def add_none_contact():
contacts = Contact.objects.filter(email=settings.NONE_EMAIL)
if contacts.count() == int(0):
newcontact = Contact.objects.create(email=settings.NONE_EMAIL)
newcontact.save()

def hash_to_fingerprint(data):
dkeys = []
for k in data.keys():
Expand Down
76 changes: 44 additions & 32 deletions sites/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ def ldg(request, project_name = None):

if 'ldg' in str(request):

login = 'https://idp.int.identitysandbox.gov/openid_connect/authorize?'
login = login + "acr_values=" + settings.LOGINDOTGOV_ACR + "&"
login = login + "client_id=" + settings.LOGINDOTGOV_CLIENT_ID + "&"
#login = 'https://idp.int.identitysandbox.gov/openid_connect/authorize?'
login = settings.LOGINDOTGOV_IDP_SERVER + '/openid_connect/authorize?'
login = login + "acr_values=" + settings.LOGINDOTGOV_ACR
login = login + "&client_id=" + settings.LOGINDOTGOV_CLIENT_ID + "&"
login = login + "nonce=" + str(secrets.token_urlsafe(30)) + "&"
login = login + "prompt=select_account&"
login = login + "redirect_uri=" + settings.LOGINDOTGOV_RETURN_TO + "&"
Expand All @@ -117,7 +118,7 @@ def ldg(request, project_name = None):

return HttpResponseRedirect(login)
else:
HttpResponseRedirect(settings.LOGINDOTGOV_ERROR_REDIRECT)
HttpResponseRedirect(settings.LOGINDOTGOV_ERROR_REDIRECT)

def uuFromFp(fingerprint, nameattrsgroup, connattrsgroup):
qs = Uniqueuser.objects.filter(fingerprint=fingerprint)
Expand Down Expand Up @@ -355,7 +356,11 @@ def ldg_authenticated(request):
msg = " tokenresponse: " + tokenresponse.text
logger.info(msg)

ale = ast.literal_eval(tokenresponse.text)
try:
ale = ast.literal_eval(tokenresponse.text)
except SyntaxError:
ale = {}

if settings.VERBOSE:
msg = " ale: " + str(ale)
logger.info(msg)
Expand All @@ -364,6 +369,7 @@ def ldg_authenticated(request):
accesstoken = ale['access_token']
except KeyError:
accesstoken = None

if settings.VERBOSE:
msg = " accesstoken: " + str(accesstoken)
logger.info(msg)
Expand All @@ -389,33 +395,36 @@ def ldg_authenticated(request):
logger.info(msg)

uu = {}
for attr in attstr.split(','):
attr = attr.replace('{', '')
attr = attr.replace('}', '')
#msg = " attr = " + str(attr)
#logger.info(msg)

v = str(attr).split(':')
#msg = " v = " + str(v)
#logger.info(msg)

key = str(v[0]).replace('"', '', 10)
value = str(v[1]).replace('"', '', 10)
if len(v) > int(2):
value = value + ':' + str(v[2]).replace('"', '', 10)
attributes.append((key, str(value)))
attrs[key] = value

if 'sub' in str(key) or 'email' in str(key):
uu[key] = value

data = {}
data[key] = value
data = str(data).encode()
fingerprint = md5(data).hexdigest()
encrypted_attrs = fernet.encrypt(data)
thisattr = attributesFromDecodedFp(fingerprint, encrypted_attrs)
uuattrslist.append(thisattr)
if '(404)' not in attstr:
for attr in attstr.split(','):
attr = attr.replace('{', '')
attr = attr.replace('}', '')
msg = " attr = " + str(attr)
logger.info(msg)

v = str(attr).split(':')
msg = " v = " + str(v)
logger.info(msg)

try:
key = str(v[0]).replace('"', '', 10)
value = str(v[1]).replace('"', '', 10)
if len(v) > int(2):
value = value + ':' + str(v[2]).replace('"', '', 10)
attributes.append((key, str(value)))
attrs[key] = value
if 'sub' in str(key) or 'email' in str(key):
uu[key] = value
except KeyError:
pass

data = {}
data[key] = value
data = str(data).encode()
fingerprint = md5(data).hexdigest()
encrypted_attrs = fernet.encrypt(data)
thisattr = attributesFromDecodedFp(fingerprint, encrypted_attrs)
uuattrslist.append(thisattr)

nameattrsgroup = attributeGroupFromAttributes(namegrouptype, uuattrslist)

Expand Down Expand Up @@ -1254,6 +1263,9 @@ def make_connections_by_project_img():
allconnections = Connection.objects.all()
numconnections = allconnections.count()
debugprint['allconnections'] = str(allconnections)
#if numconnections == int(0):
# imageattributes = []
# return (imageattributes, debugprint)

all_connections_verbose = []
for c in allconnections:
Expand Down
6 changes: 4 additions & 2 deletions ssop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def get_secret(key):

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG_SAML_DEBUG = False
VERBOSE = False
DEBUG_SAML_DEBUG = True
VERBOSE = True


# Organization structure
ALL_ORGS_BY_ID = {
Expand Down Expand Up @@ -121,6 +122,7 @@ def get_secret(key):
NONE_NAME = "#none"
NONE_EMAIL = "#[email protected]"


# Expire the session after an hour
SESSION_COOKIE_AGE = 3600
LOGOUT_EXPIRY = 2
Expand Down
9 changes: 5 additions & 4 deletions uploads/ncocwd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,19 @@
<!--***CWD Outlook***-->
<div class="hd-opt-d">Outlook

<div class="hd-opt-e">Updated 0844Z Wed Jul 12 2023</div>
<div class="hd-opt-e">Updated 0901Z Tue Aug 15 2023</div>

</div>

<div class="row-opt-e-d">
<div class="col-opt-l-d-Normal">12Z Wed Jul 12 - 12Z Thu Jul 13</div><div class="col-opt-l-d-Normal">12Z Thu Jul 13 - 12Z Fri Jul 14</div><div class="col-opt-l-d-Normal">12Z Fri Jul 14 - 12Z Sat Jul 15</div> </div>
<div class="col-opt-l-d-Normal">12Z Tue Aug 15 - 12Z Wed Aug 16</div><div class="col-opt-l-d-Normal">12Z Wed Aug 16 - 12Z Thu Aug 17</div><div class="col-opt-l-d-Normal">12Z Thu Aug 17 - 12Z Fri Aug 18</div> </div>
<div class="row-opt-e">
<div class="col-opt-l-Normal"><div class="row-opt-d"><div class="col-opt-w">Normal</div><div class="col-opt-x"></div></div></div><div class="col-opt-l-Normal"><div class="row-opt-d"><div class="col-opt-w">Normal</div><div class="col-opt-x"></div></div></div><div class="col-opt-l-Normal"><div class="row-opt-d"><div class="col-opt-w">Normal</div><div class="col-opt-x"></div></div></div> </div>

<div class="row-opt-e-di">

Critical Weather Day is not scheduled for the next 3 days. However, NCEP will be monitoring the need for CWD with the threat of severe weather over the Middle Mississippi Valley on Wednesday.
Critical Weather Day is not expected in the next 3 days.

</div>

<div class="hd-opt-d">Hazards</div>
Expand Down Expand Up @@ -475,7 +476,7 @@ Critical Weather Day is not scheduled for the next 3 days. However, NCEP will be

<!--Display times page was loaded-->
<div class="loadtime">
Page loaded: 17:12 UTC &nbsp; | &nbsp; 10:12 am Pacific &nbsp; | &nbsp; 11:12 am Mountain &nbsp; | &nbsp; 12:12 pm Central &nbsp; | &nbsp; 1:12 pm Eastern </div>
Page loaded: 22:16 UTC &nbsp; | &nbsp; 3:16 pm Pacific &nbsp; | &nbsp; 4:16 pm Mountain &nbsp; | &nbsp; 5:16 pm Central &nbsp; | &nbsp; 6:16 pm Eastern </div>



Expand Down

0 comments on commit 048ac77

Please sign in to comment.