diff options
author | Simon Rettberg | 2020-06-25 10:50:47 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-06-25 10:50:47 +0200 |
commit | 5f44db09acc0e3cb747ee11797639504e72be20b (patch) | |
tree | cb07cbc5d0b741fe4865157cc8b97efb8457c982 /extras/import-idp.php | |
parent | Update DFN-AAI URL (diff) | |
download | masterserver-5f44db09acc0e3cb747ee11797639504e72be20b.tar.gz masterserver-5f44db09acc0e3cb747ee11797639504e72be20b.tar.xz masterserver-5f44db09acc0e3cb747ee11797639504e72be20b.zip |
Add --debug option
Diffstat (limited to 'extras/import-idp.php')
-rw-r--r-- | extras/import-idp.php | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/extras/import-idp.php b/extras/import-idp.php index aecafe8..b18b923 100644 --- a/extras/import-idp.php +++ b/extras/import-idp.php @@ -2,6 +2,19 @@ error_reporting(E_ALL); +function pdebug($text) +{ + if (DEBUG) echo "$text\n"; +} + +if ($argc < 2) die("To few arguments. Pass config file!\n"); +if ($argv[1] === '--debug') { + $argc--; + array_shift($argv); + define('DEBUG', true); +} else { + define('DEBUG', false); +} if ($argc < 2) die("To few arguments. Pass config file!\n"); $handle = fopen($argv[1], 'r') or die("Cannot open mysql config given on command line\n"); $settings = array(); @@ -29,9 +42,8 @@ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); if ($data === false) die("Could not download DFN-AAI meta data\n"); -preg_match_all('#<EntityDescriptor.*?</EntityDescriptor>#s', $data, $out); - - +$count = preg_match_all('#<EntityDescriptor.*?</EntityDescriptor>#s', $data, $out); +pdebug("Found $count EntityDescriptors"); function getAttributes($array, $path) { @@ -98,20 +110,35 @@ foreach ($out[0] as $data) { $xml = json_decode(json_encode(simplexml_load_string('<?xml version="1.0" encoding="utf-8" standalone="yes" ?'.'>' . $data )), true); - if (!in_array('http://aai.dfn.de/category/bwidm-member', getAttributes($xml, 'Extensions/EntityAttributes/Attribute/AttributeValue'))) continue; - $scope = getAttributes($xml, "IDPSSODescriptor/Extensions/Scope"); - if (empty($scope)) continue; $name = getAttributes($xml, "IDPSSODescriptor/Extensions/UIInfo/DisplayName"); + if (is_array($name) && !empty($name)) { + $name = $name[0]; + pdebug(" *** Found $name"); + } else { + pdebug(" *** Entry without DisplayName..."); + continue; + } + if (!in_array('http://aai.dfn.de/category/bwidm-member', getAttributes($xml, 'Extensions/EntityAttributes/Attribute/AttributeValue'))) { + pdebug("Not bwIDM member..."); + continue; + } + $scope = getAttributes($xml, "IDPSSODescriptor/Extensions/Scope"); + if (empty($scope)) { + pdebug("No list of scopes..."); + continue; + } $ecp = false; - if (is_array($name)) $name = $name[0]; foreach (getAttributes($xml, "IDPSSODescriptor/SingleSignOnService") as $sso) { if (isset($sso['@attributes']['Binding']) && $sso['@attributes']['Binding'] === 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP') { $ecp = $sso['@attributes']['Location']; break; } } - // Now usable: $scope (kind of, arrayize), $name, $ecp (if known, false otherwise) - if ($ecp && !empty($scope)) { + // Now usable: $scope, $name, $ecp (if known, false otherwise) + if ($ecp === false) { + pdebug("No ECP end-point..."); + } else { + pdebug("Adding/Updating with ECP URL $ecp, suffixes: " . implode(', ', $scope)); wipeDb(); $eid = $db->escape_string($scope[0]); $ename = $db->escape_string($name); |