diff --git a/modules/discojuice/hooks/hook_cron.php b/modules/discojuice/hooks/hook_cron.php deleted file mode 100644 index 229c9190cce485d619eb0f535b4d7471fe046812..0000000000000000000000000000000000000000 --- a/modules/discojuice/hooks/hook_cron.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * Hook to run a cron job. - * - * @param array &$croninfo Output - */ -function discojuice_hook_cron(&$croninfo) { - assert('is_array($croninfo)'); - assert('array_key_exists("summary", $croninfo)'); - assert('array_key_exists("tag", $croninfo)'); - - if ($croninfo['tag'] !== 'hourly') return; - - SimpleSAML_Logger::info('cron [discojuice metadata caching]: Running cron in tag [' . $croninfo['tag'] . '] '); - - try { - - $feed = new sspmod_discojuice_Feed(); - $feed->store(); - - } catch (Exception $e) { - $croninfo['summary'][] = 'Error during discojuice metadata caching: ' . $e->getMessage(); - } -} -?> \ No newline at end of file diff --git a/modules/discojuice/hooks/hook_frontpage.php b/modules/discojuice/hooks/hook_frontpage.php deleted file mode 100644 index 798450d9aaceb471125058f8746372f2b1663957..0000000000000000000000000000000000000000 --- a/modules/discojuice/hooks/hook_frontpage.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -/** - * Hook to add links to the frontpage. - * - * @param array &$links The links on the frontpage, split into sections. - */ -function discojuice_hook_frontpage(&$links) { - assert('is_array($links)'); - assert('array_key_exists("links", $links)'); - - $links['federation'][] = array( - 'href' => SimpleSAML_Module::getModuleURL('discojuice/central.php'), - 'text' => array('en' => 'DiscoJuice: Discovery Service (not functional without IdP Discovery parameters)'), - ); - - $links['federation'][] = array( - 'href' => SimpleSAML_Module::getModuleURL('discojuice/feed.php'), - 'text' => array('en' => 'DiscoJuice: Metadata Feed (JSON)'), - ); - -} -?> \ No newline at end of file diff --git a/modules/discojuice/lib/CentralHelper.php b/modules/discojuice/lib/CentralHelper.php deleted file mode 100644 index 501d85626a71ec68b480398ee1a95cba070726c1..0000000000000000000000000000000000000000 --- a/modules/discojuice/lib/CentralHelper.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * ... - */ -class sspmod_discojuice_CentralHelper { - - public static function show($path = '/simplesaml/module.php/discojuice/discojuice/') { - - $djconfig = SimpleSAML_Configuration::getOptionalConfig('discojuicecentral.php'); - $config = SimpleSAML_Configuration::getInstance(); - - - $feed = new sspmod_discojuice_Feed(); - $metadata = json_decode($feed->read(), TRUE); - - $t = new SimpleSAML_XHTML_Template($config, 'discojuice:central.tpl.php'); - $t->data['metadata'] = $metadata; - $t->data['discojuice.options'] = $djconfig->getValue('discojuice.options'); - $t->data['discojuice.options']['discoPath'] = $path; - $t->data['acl'] = $djconfig->getValue('acl'); - $t->show(); - - } - -} - diff --git a/modules/discojuice/lib/Country.php b/modules/discojuice/lib/Country.php deleted file mode 100644 index 8de06f89bb227f44817272231f34bca366ab8c50..0000000000000000000000000000000000000000 --- a/modules/discojuice/lib/Country.php +++ /dev/null @@ -1,171 +0,0 @@ -<?php - -/** - * ... - */ -class sspmod_discojuice_Country { - - const CACHETIME = 86400; - - - /* Instance of sspmod_core_Storage_SQLPermanentStorage - * - * key1 calendar URL - * key2 NULL - * type 'calendar' - * - */ - public $store; - public $ip; - - public function __construct($ip = NULL) { - if (is_null($ip)) $ip = $_SERVER['REMOTE_ADDR']; - - if (empty($ip)) - throw new Exception('Trying to use the TimeZone class without specifying an IP address'); - $this->ip = $ip; - - $this->store = new sspmod_core_Storage_SQLPermanentStorage('iptimezone'); - - } - - public function lookupRegion($region) { - - if ($this->store->exists('region', $region, NULL)) { - SimpleSAML_Logger::debug('IP Geo location: Found region [' . $region . '] in cache.'); - return $this->store->getValue('region', $region, NULL); - } - - SimpleSAML_Logger::debug('Lookup region'); - $rawdata = file_get_contents('http://freegeoip.net/tz/json/' . $region); - - if (empty($rawdata)) throw new Exception('Error looking up IP geo location for [' . $ip . ']'); - $data = json_decode($rawdata, TRUE); - if (empty($data)) throw new Exception('Error decoding response from looking up IP geo location for [' . $ip . ']'); - - if (empty($data['timezone'])) throw new Exception('Could not get TimeZone from IP lookup'); - - $timezone = $data['timezone']; - - SimpleSAML_Logger::debug('IP Geo location: Store region [' . $region . '] in cache: ' . $timezone); - $this->store->set('region', $region, NULL, $timezone); - - return $timezone; - } - - public function getRegion() { - return $this->lookupIP($this->ip); - } - - public function getGeo() { - return $this->lookupGeo($this->ip); - } - - public function lookupGeo($ip) { - - if ($this->store->exists('geo', $ip, NULL)) { - SimpleSAML_Logger::debug('IP Geo location (geo): Found ip [' . $ip . '] in cache.'); - $stored = $this->store->getValue('geo', $ip, NULL); - if ($stored === NULL) throw new Exception('Got negative cache for this IP'); - return $stored; - } - - SimpleSAML_Logger::debug('Lookup IP'); - $rawdata = file_get_contents('http://freegeoip.net/json/' . $ip); - - if (empty($rawdata)) throw new Exception('Error looking up IP geo location for [' . $ip . ']'); - $data = json_decode($rawdata, TRUE); - if (empty($data)) throw new Exception('Error decoding response from looking up IP geo location for [' . $ip . ']'); - - if (empty($data['longitude'])) { - $this->store->set('geo', $ip, NULL, NULL); - } - - - if (empty($data['longitude'])) throw new Exception('Could not get longitude from IP lookup'); - if (empty($data['latitude'])) throw new Exception( 'Could not get latitude from IP lookup'); - - $geo = $data['latitude'] . ',' . $data['longitude']; - - SimpleSAML_Logger::debug('IP Geo location: Store ip [' . $ip . '] in cache: ' . $geo); - $this->store->set('geo', $ip, NULL, $geo); - - return $geo; - } - - public function lookupIP($ip) { - - if ($this->store->exists('ip', $ip, NULL)) { - SimpleSAML_Logger::debug('IP Geo location: Found ip [' . $ip . '] in cache.'); - return $this->store->getValue('ip', $ip, NULL); - } - - SimpleSAML_Logger::debug('Lookup IP [' . $ip. ']'); - $rawdata = file_get_contents('http://freegeoip.net/json/' . $ip); - - if (empty($rawdata)) throw new Exception('Error looking up IP geo location for [' . $ip . ']'); - $data = json_decode($rawdata, TRUE); - if (empty($data)) throw new Exception('Error decoding response from looking up IP geo location for [' . $ip . ']'); - - SimpleSAML_Logger::info('Country code: ' . $data['country_code']); - - if (empty($data['country_code'])) throw new Exception('Could not get Coutry Code from IP lookup : ' . var_export($data, TRUE)); - if (empty($data['region_code'])) $region = 'NA'; - - $region = $data['country_code'] . '/' . $data['region_code']; - - SimpleSAML_Logger::debug('IP Geo location: Store ip [' . $ip . '] in cache: ' . $region); - $this->store->set('ip', $ip, NULL, $region); - - return $region; - } - - public function getTimeZone() { - $tz = 'Europe/Amsterdam'; - - try { - $tz = $this->lookupRegion($this->lookupIP($this->ip)); - } catch(Exception $e) { - $tz = 'Europe/Amsterdam'; - } - - return $tz; - } - - - - public function getSelectedTimeZone() { - - - if (isset($_REQUEST['timezone'])) { - return $_REQUEST['timezone']; - } - return $this->getTimeZone(); - } - - public function getHTMLList($default = NULL, $autosubmit = FALSE) { - - $tzlist = DateTimeZone::listIdentifiers(); - $tzlist = array_reverse($tzlist); - $thiszone = $this->getTimeZone(); - - if (is_null($default)) $default = $thiszone; - - $a = ''; - if ($autosubmit) $a = "onchange='this.form.submit()' "; - - $html = '<select ' . $a . 'name="timezone">' . "\n"; - foreach($tzlist AS $tz) { - if ($tz == $default) { - $html .= ' <option selected="selected" value="' . htmlspecialchars($tz) . '">' . htmlspecialchars($tz) . '</option>' . "\n"; - } else { - $html .= ' <option value="' . htmlspecialchars($tz) . '">' . htmlspecialchars($tz) . '</option>' . "\n"; - } - - } - $html .= '</select>' . "\n"; - return $html; - } - - -} diff --git a/modules/discojuice/lib/EmbedHelper.php b/modules/discojuice/lib/EmbedHelper.php deleted file mode 100644 index c1819fb1c81490403ac98bd5db27e0efd6b6de79..0000000000000000000000000000000000000000 --- a/modules/discojuice/lib/EmbedHelper.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -/** - * ... - */ -class sspmod_discojuice_EmbedHelper { - - public static function head($includeJQuery = TRUE) { - - $version = '0.1-4'; - - $config = SimpleSAML_Configuration::getInstance(); - $djconfig = SimpleSAML_Configuration::getOptionalConfig('discojuiceembed.php'); - - - if ($includeJQuery) { - echo ' -<!-- JQuery (Required for DiscoJuice) --> - <script type="text/javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/jquery-1.6.min.js') . '"></script> - <script type="text/javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/jquery-ui-1.8.5.custom.min.js') . '"></script> - - <link rel="stylesheet" type="text/css" href="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/css/custom/jquery-ui-1.8.5.custom.css') . '" /> - -'; - - } - - - echo ' -<!-- DiscoJuice (version identifier: ' . $version . ' ) --> - <script type="text/javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuice.misc.js?v=' . $version) . '"></script> - <script type="text/javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuice.ui.js?v=' . $version) . '"></script> - <script type="text/javascript" src="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuice.control.js?v=' . $version) . '"></script> - - <link rel="stylesheet" type="text/css" href="' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/css/discojuice.css?v=' . $version) . '" /> - -'; - - - $options = $djconfig->getValue('discojuice.options'); - $target = $djconfig->getValue('target'); - - - echo '<script type="text/javascript">'; - echo 'var options = ' . json_encode($options) . ';' . "\n"; - echo 'var target = "' . $target . '";' . "\n\n"; - - echo 'options.countryAPI = "' . SimpleSAML_Module::getModuleURL('discojuice/country.php'). '"; ' . "\n"; - - if (empty($options['metadata'])) { - echo 'options.metadata = "' . SimpleSAML_Module::getModuleURL('discojuice/feed.php'). '"; ' . "\n"; - } - - if (!empty($options['disco'])) { - echo 'options.disco.url = "' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/discojuiceDiscoveryResponse.html?'). '"; ' . "\n"; - } - - - echo 'options.discoPath = "' . SimpleSAML_Module::getModuleURL('discojuice/discojuice/') . '"; ' . "\n"; - - - echo 'options.callback = ' . $djconfig->getValue('callback', 'null') . ';' . "\n\n"; - - - echo ' - $(document).ready(function() { - $(target).DiscoJuice(options); - }); - </script> - - '; - - - } - - - - - - -} - diff --git a/modules/discojuice/lib/Feed.php b/modules/discojuice/lib/Feed.php deleted file mode 100644 index 9ad90cab0e83e4cda92a29948fdd5478c8de7f22..0000000000000000000000000000000000000000 --- a/modules/discojuice/lib/Feed.php +++ /dev/null @@ -1,577 +0,0 @@ -<?php - - -/* -* File: SimpleImage.php -* Author: Simon Jarvis -* Copyright: 2006 Simon Jarvis -* Date: 08/11/06 -* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details: -* http://www.gnu.org/licenses/gpl.html -* -*/ - -class SimpleImage { - - var $image; - var $image_type; - - function load($filename) { - - $image_info = getimagesize($filename); - $this->image_type = $image_info[2]; - if( $this->image_type == IMAGETYPE_JPEG ) { - - $this->image = imagecreatefromjpeg($filename); - } elseif( $this->image_type == IMAGETYPE_GIF ) { - - $this->image = imagecreatefromgif($filename); - } elseif( $this->image_type == IMAGETYPE_PNG ) { - - $this->image = imagecreatefrompng($filename); - } - } - function save($filename, $image_type=IMAGETYPE_PNG, $compression=90, $permissions=null) { - - if( $image_type == IMAGETYPE_JPEG ) { - imagejpeg($this->image,$filename,$compression); - } elseif( $image_type == IMAGETYPE_GIF ) { - - imagegif($this->image,$filename); - } elseif( $image_type == IMAGETYPE_PNG ) { - - imagepng($this->image,$filename); - } - if( $permissions != null) { - - chmod($filename,$permissions); - } - } - function output($image_type=IMAGETYPE_JPEG) { - - if( $image_type == IMAGETYPE_JPEG ) { - imagejpeg($this->image); - } elseif( $image_type == IMAGETYPE_GIF ) { - - imagegif($this->image); - } elseif( $image_type == IMAGETYPE_PNG ) { - - imagepng($this->image); - } - } - function getWidth() { - - return imagesx($this->image); - } - function getHeight() { - - return imagesy($this->image); - } - function resizeToHeight($height) { - - $ratio = $height / $this->getHeight(); - $width = $this->getWidth() * $ratio; - $this->resize($width,$height); - } - - function resizeToWidth($width) { - $ratio = $width / $this->getWidth(); - $height = $this->getheight() * $ratio; - $this->resize($width,$height); - } - - function scale($scale) { - $width = $this->getWidth() * $scale/100; - $height = $this->getheight() * $scale/100; - $this->resize($width,$height); - } - - function resize($width,$height) { - $new_image = imagecreatetruecolor($width, $height); - - imagealphablending($new_image, false); - imagesavealpha($new_image,true); - $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); - imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent); - - - imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); - $this->image = $new_image; - } - -} - - - - - - -/** - * ... - */ -class sspmod_discojuice_Feed { - - protected $config, $djconfig; - - protected $excludes, $override, $insert, $idplist; - - protected $metadata; - protected $feed; - - protected $contrytags, $countryTLDs; - - function __construct() { - - $this->config = SimpleSAML_Configuration::getInstance(); - $this->djconfig = SimpleSAML_Configuration::getOptionalConfig('discojuicefeed.php'); - - $metadatah = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler(); - - $saml2 = $metadatah->getList('saml20-idp-remote'); - $shib = $metadatah->getList('shib13-idp-remote'); - - foreach($shib AS $s) { - $this->metadata[$s['entityid']] = $s; - } - foreach($saml2 AS $s) { - $this->metadata[$s['entityid']] = $s; - } - // $this->metadata = array_merge($this->metadata, $shib); - - - $this->idplist = $this->getIdPList(); - - SimpleSAML_Logger::info('IdP List contained : ' . count($this->idplist) . ' entries.'); - - $this->excludes = array_flip($this->djconfig->getValue('exclude')); - $this->insert = $this->djconfig->getValue('insert'); - $this->overrides = $this->djconfig->getValue('overrides'); - - $this->countrytags = array( - 'croatia' => 'HR', - 'czech' => 'CZ', - 'denmark' => 'DK', - 'finland' => 'FI', - 'france' => 'FR', - 'germany' => 'DE', - 'greece' => 'GR', - 'ireland' => 'IE', - 'italy' => 'IT', - 'luxembourg' => 'LU', - 'hungary' => 'HU', - 'netherlands' => 'NL', - 'norway' => 'NO', - 'portugal' => 'PT', - 'poland' => 'PL', - 'slovenia' => 'SI', - 'spain' => 'ES', - 'sweden' => 'SE', - 'switzerland' => 'CH', - 'turkey' => 'TR', - 'us' => 'US', - 'uk' => 'GB', - 'japan' => 'JP', - ); - - $this->countryTLDs = array( - 'lp.' => 'PL', - 'uh.' => 'HU', - 'es.' => 'SE', - 'ed.' => 'DE', - 'if.' => 'FI', - 'zc.' => 'CZ', - 'rt.' => 'TR', - 'kd.' => 'DK', - 'on.' => 'NO', - 'ude.' => 'US', - 'ku.oc.' => 'GB', - ); - } - - public function store() { - $datadir = $this->config->getPathValue('datadir', 'data/'); - - if (!is_dir($datadir)) - throw new Exception('Data directory [' . $datadir. '] does not exist'); - if (!is_writable($datadir)) - throw new Exception('Data directory [' . $datadir. '] is not writable'); - - $djdatadir = $datadir . 'discojuice/'; - if (!is_dir($djdatadir)) { - mkdir($djdatadir); - } - - $djdatafile = $djdatadir . 'discojuice.cache'; - - $data = $this->getJSON(); - - file_put_contents($djdatafile, json_encode($data)); - - } - - public function read() { - $djdatafile = $this->config->getPathValue('datadir', 'data/') . 'discojuice/' . 'discojuice.cache'; - - if (!file_exists($djdatafile)) { - error_log('Did not find cached version, generating content again...'); - return json_encode($this->getJSON()); - } - - return file_get_contents($djdatafile); - } - - private function exclude($e) { - if ($this->excludes === NULL) return FALSE; - return (array_key_exists($e, $this->excludes)); - } - - protected function getIdPList() { - $api = $this->djconfig->getValue('idplistapi', NULL); - if (empty($api)) return array(); - - $result = array(); - - $apiresult = json_decode(file_get_contents($api), TRUE); - if ($apiresult['status'] === 'ok') { - foreach($apiresult['data'] AS $idp) { - $result[$idp] = 1; - } - } - return $result; - } - - private function process() { - - $this->feed = array(); - $this->merge(); - - foreach($this->metadata AS $m) { - if ($this->exclude($m['entityid'])) continue; - - $nc = $this->processEntity($m); -// if (empty($nc['icon'])) continue; - $this->feed[] = $nc; - } - - if (!empty($this->insert)) { - foreach($this->insert AS $i) { - $this->feed[] = $i; - } - } - - } - - protected function merge() { - $mergeendpoints = $this->djconfig->getValue('mergeEndpoints', NULL); - SimpleSAML_Logger::info('Processing merge endpoint: ' . var_export($mergeendpoints, TRUE)); - - if ($mergeendpoints === NULL) return; - if (!is_array($mergeendpoints)) return; - foreach($mergeendpoints AS $me) { - SimpleSAML_Logger::info('Processing merge endpoint: ' . $me); - $newlist = json_decode(file_get_contents($me), TRUE); - $this->feed = array_merge($this->feed, $newlist); - } - } - - - private function processEntity($m) { - - $data = array('entityID' => $m['entityid']); - - $this->getCountry($data, $m); - $this->getTitle($data, $m); - $this->getOverrides($data, $m); - $this->getGeo($data, $m); - $this->getLogo($data, $m); - - if (!empty($this->idplist)) { - $this->islisted($data, $m); - } - return $data; - } - - public function getJSON() { - $this->process(); - return $this->feed; - } - - - protected function islisted(&$data, $m) { - $weight = 0; - if (array_key_exists('weight', $data)) $weight = $data['weight']; - - if (!array_key_exists($m['entityid'], $this->idplist)) { - #echo 'Match for ' . $m['entityid']; - $weight += 2; - } - $data['weight'] = $weight; - -# echo '<pre>'; -# print_r($this->idplist); exit; - } - - - protected static function getPreferredLogo($logos) { - - $current = array('height' => 0); - $found = false; - - foreach($logos AS $logo) { - if ( - $logo['height'] > 23 && - $logo['height'] < 41 && - $logo['height'] > $current['height'] - ) { - $current = $logo; - $found = true; - } - } - if ($found) return $current; - - foreach($logos AS $logo) { - if ( - $logo['height'] > $current['height'] - ) { - $current = $logo; - $found = true; - } - } - if ($found) return $current; - - return NULL; - - } - - protected static function getCachedLogo($logo) { - - $hash = sha1($logo['url']); - $relfile = 'cached/' . $hash; - $file = dirname(dirname(__FILE__)) . '/www/discojuice/logos/' . $relfile; - $fileorig = $file . '.orig'; - - if (file_exists($file)) { - return $relfile; - } - - //echo 'icon file: ' . $file; exit; - - $orgimg = file_get_contents($logo['url']); - if (empty($orgimg)) return null; - file_put_contents($fileorig, $orgimg); - - if ($logo['height'] > 40) { - $image = new SimpleImage(); - $image->load($fileorig); - $image->resizeToHeight(38); - $image->save($file); - - if (file_exists($file)) { - return $relfile; - } - } - - file_put_contents($file, $orgimg); - - if (file_exists($file)) { - return $relfile; - } - - } - - - protected function getLogo(&$data, $m) { - - if (!empty($m['mdui']) && !empty($m['mdui']['logos'])) { - - $cl = self::getPreferredLogo($m['mdui']['logos']); - - if (!empty($cl)) { - $cached = self::getCachedLogo($cl); - if (!empty($cached)) { - $data['icon'] = $cached; - } - } - -// echo '<pre>'; print_r($m); exit; - } - - - } - - protected function getGeo(&$data, $m) { - - if (!empty($m['disco']) && !empty($m['disco']['geo'])) { - - $data['geo'] = $m['disco']['geo']; - // $data['discogeo'] = 1; - - } - - // Do not lookup Geo locations from IP if geo location is already set. - if (array_key_exists('geo', $data)) return; - - - // Look for SingleSignOnService endpoint. - if (!empty($m['SingleSignOnService']) ) { - - $m['metadata-set'] = 'saml20-idp-remote'; - $mc = SimpleSAML_Configuration::loadFromArray($m); - $endpoint = $mc->getDefaultEndpoint('SingleSignOnService'); - - try { - $host = parse_url($endpoint['Location'], PHP_URL_HOST); if (empty($host)) return; - $ip = gethostbyname($host); - - if (empty($ip)) return; - if ($ip === $host) return; - - $capi = new sspmod_discojuice_Country($ip); - - if (empty($data['geo'])) { - $geo = $capi->getGeo(); - $geos = explode(',', $geo); - $data['geo'] = array('lat' => $geos[0], 'lon' => $geos[1]); - } - - } catch(Exception $e) { - error_log('Error looking up geo coordinates: ' . $e->getMessage()); - } - - } - - - } - - - protected function getCountry(&$data, $m) { - if (!empty($m['tags'])) { - - foreach($m['tags'] AS $tag) { - if (array_key_exists($tag, $this->countrytags)) { - $data['country'] = $this->countrytags[$tag]; - return; - } - } - } - - - $c = self::countryFromURL($m['entityid']); - if (!empty($c)) { $data['country'] = $c; return; } - - if (!empty($m['SingleSignOnService']) ) { - - SimpleSAML_Logger::debug('SingleSignOnService found'); - - $m['metadata-set'] = 'saml20-idp-remote'; - $mc = SimpleSAML_Configuration::loadFromArray($m); - - $endpoint = $mc->getDefaultEndpoint('SingleSignOnService'); - - error_log('Endpoint: ' . var_export($endpoint, TRUE)); - - $c = $this->countryFromURL($endpoint['Location']); - if (!empty($c)) { $data['country'] = $c; return; } - - try { - $host = parse_url($endpoint['Location'], PHP_URL_HOST); - $ip = gethostbyname($host); - $capi = new sspmod_discojuice_Country($ip); - - $region = $capi->getRegion(); - - if (preg_match('|^([A-Z][A-Z])/|', $region, $match)) { - $data['country'] = $match[1]; - - } - } catch(Exception $e) {} - - } - - - - return null; - } - - protected function getTitle(&$data, $m) { - if(isset($m['name']) && is_string($m['name'])) { - $data['title'] = $m['name']; - } else if(isset($m['name']) && array_key_exists('en', $m['name'])) { - $data['title'] = $m['name']['en']; - } else if(isset($m['name']) && is_array($m['name'])) { - $data['title'] = array_pop($m['name']); - } else if (isset($m['name']) && is_string($m['name'])) { - $data['title'] = $m['name']; - } else if (isset($m['OrganizationName']) && isset($m['OrganizationName']['en'])) { - $data['title'] = $m['OrganizationName']['en']; - } else if (isset($m['OrganizationName']) && is_array($m['OrganizationName'])) { - $data['title'] = array_pop($m['OrganizationName']); - } else { - $data['title'] = substr($m['entityid'], 0, 20); - $data['weight'] = 9; - } - } - - protected function getOverrides(&$data, $m) { - if (empty($this->overrides)) return; - if (empty($this->overrides[$m['entityid']])) return; - - $override = $this->overrides[$m['entityid']]; - - foreach($override AS $k => $v) { - $data[$k] = $v; - } - - } - - - protected static function prefix($word, $prefix) { - if ( strlen($word) < strlen($prefix)) { - $tmp = $prefix; - $prefix = $word; - $word = $tmp; - } - - $word = substr($word, 0, strlen($prefix)); - - if ($prefix == $word) { - return 1; - } - - return 0; - } - - - protected function countryFromURL($entityid) { - try { - $pu = parse_url($entityid, PHP_URL_HOST); - if (!empty($pu)) { - $rh = strrev($pu); - // error_log('Looking up TLD : ' . $rh); - - foreach($this->countryTLDs AS $domain => $country) { - if (self::prefix($domain, $rh)) { - error_log('Looking up TLD : ' . $rh . ' matched ' . $country); - return $country; - } - } - } - } catch(Exception $e) { - } - return null; - } - - - -} - diff --git a/modules/discojuice/templates/central.tpl.php b/modules/discojuice/templates/central.tpl.php index 5ca6e5684372f85597f0ca87ed021893fbe95bc1..8067e168041f104f291c21cba5600f5d9e0e2401 100644 --- a/modules/discojuice/templates/central.tpl.php +++ b/modules/discojuice/templates/central.tpl.php @@ -7,18 +7,13 @@ header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT <head> <meta charset="utf-8" /> <title>Select Your Login Provider</title> - - -<link rel="shortcut icon" href="http://discojuice.bridge.uninett.no/simplesaml/module.php/discojuice/favicon.png" /> - - -<!-- JQuery hosted by Google --> -<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> -<!-- DiscoJuice hosted by UNINETT at discojuice.org --> -<script type="text/javascript" src="https://engine.discojuice.org/discojuice-stable.min.js"></script> -<link rel="stylesheet" type="text/css" href="https://static.discojuice.org/css/discojuice.css" /> + <!-- JQuery hosted by Google --> + <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> + <!-- DiscoJuice hosted by UNINETT at discojuice.org --> + <script type="text/javascript" src="https://engine.discojuice.org/discojuice-stable.min.js"></script> + <link rel="stylesheet" type="text/css" href="https://static.discojuice.org/css/discojuice.css" /> <style type="text/css"> body { @@ -47,8 +42,8 @@ header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT json_encode($this->data['hostedConfig'][4]) . ');'; - echo " djc.country = false;\n"; - echo " djc.showLocationInfo = false;\n"; + // echo " djc.country = false;\n"; + // echo " djc.showLocationInfo = false;\n"; if (!$this->data['enableCentralStorage']) { echo " delete djc.disco;\n"; diff --git a/modules/discojuice/www/central.php b/modules/discojuice/www/central.php index 3d8c92927ac221601a7bdb3395465570ed2122e4..6f1a7ead6fd137123deefb72e0e98b77073141af 100644 --- a/modules/discojuice/www/central.php +++ b/modules/discojuice/www/central.php @@ -4,15 +4,9 @@ if (empty($_REQUEST['entityID'])) throw new Exception('Missing parameter [entity if (empty($_REQUEST['return'])) throw new Exception('Missing parameter [return]'); - $djconfig = SimpleSAML_Configuration::getOptionalConfig('discojuice.php'); $config = SimpleSAML_Configuration::getInstance(); - -$feed = new sspmod_discojuice_Feed(); -$metadata = json_decode($feed->read(), TRUE); - - // EntityID $entityid = $_REQUEST['entityID']; @@ -34,7 +28,7 @@ $hostedConfig = array( SimpleSAML_Module::getModuleURL('discojuice/response.html'), // Set of feeds to subscribe to. - $djconfig->getArray('feeds', 'Service'), + $djconfig->getArray('feeds', array('edugain')), $href ); diff --git a/modules/discojuice/www/response.html b/modules/discojuice/www/response.html index 1bb1c002399123ae1cbf173265d7f899ad6eedd2..3067d41be9609fab65a30c05e0afdd1b3431288c 100644 --- a/modules/discojuice/www/response.html +++ b/modules/discojuice/www/response.html @@ -31,18 +31,22 @@ function receive() { if (urlParams.cid) cid = urlParams.cid; var sender = parseURL(document.referrer); + + // Received a specific entity ID from the storage. if (urlParams.entityID) { window.parent.DiscoJuice.Utils.log('ResponseLocation: Response from discovery service [' + sender + ']: ' + urlParams.entityID + ' subID: ' + urlParams.subID); - window.parent.DiscoJuice.Control.discoResponse(sender, urlParams.entityID, urlParams.subID, cid); + // Received a textual error from the storage, to show in the debug log. } else if (urlParams['error']) { window.parent.DiscoJuice.Control.discoResponseError(cid, - "Error from IdP Discovery Service [" + sender + "]: " + urlParams.error); + "Error from IdP Discovery Service [" + sender + "]: " + urlParams.error); + + // Did not receive a response parameter. This probably means that the Disco storage did not have a stored preference + // for the user. Consequently: no error. } else { - console.log('No valid response parameters. cid[' + cid + ']'); + window.parent.DiscoJuice.Utils.log('No valid response parameters. cid[' + cid + ']'); window.parent.DiscoJuice.Control.discoResponseError(cid); - // "ResponseLocation: Response from discovery service [" + sender + "]: No valid response parameters"); } } @@ -51,6 +55,6 @@ function receive() { </head> <body onload="receive();"> -</body> -</html> +</body> +</html> \ No newline at end of file