This commit is contained in:
Khanh Ngo 2018-08-13 10:47:45 +07:00
commit 56381e766f
3 changed files with 44 additions and 2 deletions

View File

@ -19,7 +19,10 @@ if app.config['SAML_ENABLED']:
from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser
idp_timestamp = datetime(1970, 1, 1) idp_timestamp = datetime(1970, 1, 1)
idp_data = None idp_data = None
idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(app.config['SAML_METADATA_URL'], entity_id=app.config.get('SAML_IDP_ENTITY_ID', None)) if 'SAML_IDP_ENTITY_ID' in app.config:
idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(app.config['SAML_METADATA_URL'], entity_id=app.config.get('SAML_IDP_ENTITY_ID', None), required_sso_binding=app.config['SAML_IDP_SSO_BINDING'])
else:
idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(app.config['SAML_METADATA_URL'], entity_id=app.config.get('SAML_IDP_ENTITY_ID', None))
if idp_data is None: if idp_data is None:
print('SAML: IDP Metadata initial load failed') print('SAML: IDP Metadata initial load failed')
exit(-1) exit(-1)
@ -37,7 +40,10 @@ def get_idp_data():
def retreive_idp_data(): def retreive_idp_data():
global idp_data, idp_timestamp global idp_data, idp_timestamp
new_idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(app.config['SAML_METADATA_URL'], entity_id=app.config.get('SAML_IDP_ENTITY_ID', None)) if 'SAML_IDP_SSO_BINDING' in app.config:
new_idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(app.config['SAML_METADATA_URL'], entity_id=app.config.get('SAML_IDP_ENTITY_ID', None), required_sso_binding=app.config['SAML_IDP_SSO_BINDING'])
else:
new_idp_data = OneLogin_Saml2_IdPMetadataParser.parse_remote(app.config['SAML_METADATA_URL'], entity_id=app.config.get('SAML_IDP_ENTITY_ID', None))
if new_idp_data is not None: if new_idp_data is not None:
idp_data = new_idp_data idp_data = new_idp_data
idp_timestamp = datetime.now() idp_timestamp = datetime.now()

View File

@ -94,6 +94,10 @@ SAML_METADATA_URL = 'https://<hostname>/FederationMetadata/2007-06/FederationMet
#Cache Lifetime in Seconds #Cache Lifetime in Seconds
SAML_METADATA_CACHE_LIFETIME = 1 SAML_METADATA_CACHE_LIFETIME = 1
# SAML SSO binding format to use
## Default: library default (urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect)
#SAML_IDP_SSO_BINDING = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
## EntityID of the IdP to use. Only needed if more than one IdP is ## EntityID of the IdP to use. Only needed if more than one IdP is
## in the SAML_METADATA_URL ## in the SAML_METADATA_URL
### Default: First (only) IdP in the SAML_METADATA_URL ### Default: First (only) IdP in the SAML_METADATA_URL

32
update_zones.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
####################################################################################################################################
# A CLI Script to update list of domains instead from the UI. Can be usefull for people who want to execute updates from a cronjob
#
# Tip:
# When running from a cron, use flock (you might need to install it) to be sure only one process is running a time. eg:
# */5 * * * * flock -xn "/tmp/pdns-update-zones.lock" python /var/www/html/apps/poweradmin/update_zones.py >/dev/null 2>&1
#
##############################################################
### Imports
from app import app
from app.lib import log
from app.models import Domain
from config import BG_DOMAIN_UPDATES
import sys
import logging as logger
### Define logging
logging = logger.getLogger(__name__)
### Check if BG_DOMAIN_UPDATES is set to true
if not BG_DOMAIN_UPDATES:
logging.error('Set BG_DOMAIN_UPDATES to True in config.py')
sys.exit(1)
### Start the update process
logging.info('Update zones from nameserver API')
d = Domain().update()