connect_errno) die("Could not connect to db: " . $db->connect_error . "\n"); $db->set_charset("utf8"); if ($argc > 2) { $url = $argv[2]; } else { $url = 'https://www.aai.dfn.de/fileadmin/metadata/DFN-AAI-metadata.xml'; } echo "Using $url...\n"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 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('##s', $data, $out); foreach ($out[0] as $data) { $data = preg_replace('#<(/?)[a-zA-Z0-9]+:#', '<\1', $data); $xml = json_decode(json_encode(simplexml_load_string('' . $data)), true); //if (!isset($xml["Extensions"]["EntityAttributes"]["Attribute"]["AttributeValue"])) { // echo "no EntityAttributes.Attribute.AttributeValue!\n"; // continue; //} //if ($xml["Extensions"]["EntityAttributes"]["Attribute"]["AttributeValue"] !== 'http://aai.dfn.de/category/bwidm-member') continue; if (!isset($xml["IDPSSODescriptor"]["Extensions"]["Scope"])) { echo "No Extensions.Scope!\n"; continue; } $scope = $xml["IDPSSODescriptor"]["Extensions"]["Scope"]; if (!is_array($scope)) $scope = array($scope); $name = $xml["IDPSSODescriptor"]["Extensions"]["UIInfo"]["DisplayName"]; $ecp = false; if (is_array($name)) $name = $name[0]; foreach ($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)) { $eid = $db->escape_string($scope[0]); $ename = $db->escape_string($name); $eecp = $db->escape_string($ecp); $db->query("INSERT INTO satellite (organizationid, address, name, authmethod, publickey) VALUES ('$eid', '', '$ename', '$eecp', '') ON DUPLICATE KEY UPDATE authmethod = VALUES(authmethod), name = VALUES(name)"); foreach ($scope as $alias) { $ealias = $db->escape_string($alias); $db->query("INSERT IGNORE INTO satellite_suffix (organizationid, suffix) VALUES ('$eid', '$ealias')"); } } }