Beispiel #1
0
 function __construct($url, $feedId, $enableCacheOnly = false)
 {
     $this->cachedir = Config::get('cachedir');
     if (!is_dir($this->cachedir)) {
         throw new Exception('Cache dir not present');
     }
     if (!is_writable($this->cachedir)) {
         throw new Exception('Cache dir not writable');
     }
     $cachefile = $this->cachedir . $feedId;
     // echo 'Cache dir: ' . $cachefile;
     // exit;
     try {
         if (!$enableCacheOnly) {
             DiscoUtils::debug('Downloading metadata from ' . tc_colored($url, 'green') . " and storing cache at " . tc_colored($cachefile, 'green'));
             $data = @file_get_contents($url);
             if ($data === false) {
                 throw new Exception('Error retrieving metadata from ' . $url);
             }
             file_put_contents($cachefile, $data);
         } else {
             DiscoUtils::debug('Looking up cached metadata from ' . tc_colored($cachefile, 'green'));
         }
     } catch (Exception $e) {
         error_log('Error updating metadata from source ' . $feedId . ' : ' . $e->getMessage());
     }
     if (!file_exists($cachefile)) {
         throw new Exception('Not able to continue processing this feed, because cannot read cached file');
     }
     DiscoUtils::debug('Metadata ready, starting to parse XML and validate document');
     $this->list = array();
     $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($cachefile);
     foreach ($entities as $entityId => $entity) {
         $md = $entity->getMetadata1xIdP();
         if ($md !== NULL) {
             $this->list[$entityId] = $md;
         }
         $md = $entity->getMetadata20IdP();
         if ($md !== NULL) {
             $this->list[$entityId] = $md;
         }
         $this->processSPEntity($entity->getMetadata20SP());
     }
     if (count($this->list) === 0) {
         throw new Exception('No entities found at URL ' . $src);
     }
 }
Beispiel #2
0
function phpterm_demo()
{
    echo 'Test basic colors:' . "\n";
    tcechon('Grey color', 'grey');
    tcecho('Red color', 'red');
    echo "\n";
    echo tc_colored('Green color', 'green') . "\n";
    tcechon('Yellow color', 'yellow');
    tcechon('Blue color', 'blue');
    tcechon('Magenta color', 'magenta');
    tcechon('Cyan color', 'cyan');
    tcechon('White color', 'white');
    echo str_repeat('-', 78) . "\n";
    echo 'Test highlights:' . "\n";
    tcechon('On grey color', 'on_grey');
    tcechon('On red color', 'on_red');
    tcechon('On green color', 'on_green');
    tcechon('On yellow color', 'on_yellow');
    tcechon('On blue color', 'on_blue');
    tcechon('On magenta color', 'on_magenta');
    tcechon('On cyan color', 'on_cyan');
    tcechon('On white color', 'grey', 'on_white');
    echo str_repeat('-', 78) . "\n";
    echo 'Test attributes:' . "\n";
    tcechon('Bold grey color', 'grey', 'bold');
    tcechon('Dark red color', 'red', 'dark');
    tcechon('Underline green color', 'green', 'underline');
    tcechon('Blink yellow color', 'yellow', 'blink');
    tcechon('Reversed blue color', 'blue', 'reverse');
    tcechon('Concealed Magenta color', 'magenta', 'concealed');
    tcechon('Bold underline reverse cyan color', 'cyan', 'bold', 'underline', 'reverse');
    tcechon('Dark blink concealed white color', 'white', array('dark', 'blink', 'concealed'));
    echo str_repeat('-', 78) . "\n";
    echo 'Test mixing:' . "\n";
    tcechon('Underline red on grey color', 'red', 'on_grey', 'underline');
    tcechon('Reversed green on red color', 'green', 'on_red', 'reverse');
}
 * background colors and text attributes and their corresponding terminal codes.
 *
 * @return array
 */
function _tc_get_options()
{
    $options = array_merge(array_combine(array('grey', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'), range(30, 37)), array_combine(array('on_grey', 'on_red', 'on_green', 'on_yellow', 'on_blue', 'on_magenta', 'on_cyan', 'on_white'), range(40, 47)), array_combine(array('bold', 'dark', '', 'underline', 'blink', '', 'reverse', 'concealed'), range(1, 8)));
    unset($options['']);
    return $options;
}
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
    echo 'Test basic colors:' . "\n";
    tcechon('Grey color', 'grey');
    tcecho('Red color', 'red');
    echo "\n";
    echo tc_colored('Green color', 'green') . "\n";
    tcechon('Yellow color', 'yellow');
    tcechon('Blue color', 'blue');
    tcechon('Magenta color', 'magenta');
    tcechon('Cyan color', 'cyan');
    tcechon('White color', 'white');
    echo str_repeat('-', 78) . "\n";
    echo 'Test highlights:' . "\n";
    tcechon('On grey color', 'on_grey');
    tcechon('On red color', 'on_red');
    tcechon('On green color', 'on_green');
    tcechon('On yellow color', 'on_yellow');
    tcechon('On blue color', 'on_blue');
    tcechon('On magenta color', 'on_magenta');
    tcechon('On cyan color', 'on_cyan');
    tcechon('On white color', 'grey', 'on_white');
Beispiel #4
0
 function save()
 {
     $existing = $this->db->{static::$collection}->findOne($this->getQuery());
     if ($existing !== null) {
         $existingItem = self::fromDB($existing);
         if ($this->equalTo($existingItem)) {
             DiscoUtils::log('No changes ' . tc_colored('SKIP', 'cyan') . ' ');
         } else {
             DiscoUtils::log('Object is modified, storing changes ' . tc_colored('UPDATE', 'red') . ' ');
             $this->update();
         }
     } else {
         DiscoUtils::log('Metadata is completely new ' . tc_colored('INSERT', 'green') . ' ');
         $this->insert();
     }
 }
Beispiel #5
0
 protected function fetchAndStore($id, $src, $meta, $existing = null, $isLocalFile = false)
 {
     // if ($localFile) {
     // 	$cachefile = $this->getCachedLogoLocal($src);
     // 	if ($cachefile === null) return false;
     // } else {
     // $cachefile = $this->getCachedLogo($src);
     // if ($cachefile === null) return false;
     if (empty($src)) {
         return null;
     }
     if ($isLocalFile) {
         $localFile = $src;
     } else {
         // Obtain cache of original file...
         $localFile = $this->getOrigCache($src);
         if ($localFile === null) {
             return null;
         }
         if (empty($localFile)) {
             return null;
         }
     }
     DiscoUtils::debug('Successfully obtained local cache of remote [' . $src . '] file. Local file is stored at ' . $localFile);
     $file = $this->getBaseFile($src);
     DiscoUtils::debug('Preparing a resized file to be cached locally at ' . $file);
     $this->processOrigLocal($localFile, $file);
     $imagedata = file_get_contents($file);
     if ($imagedata === false) {
         return false;
     }
     $etag = sha1($imagedata);
     $data = $meta;
     $data['id'] = $id;
     $data['contentType'] = 'image/png';
     $data['logo'] = new MongoBinData($imagedata);
     $data['etag'] = $etag;
     if (self::isValidEmbedded($src)) {
         $data['src'] = 'embed:sha1:' . sha1($src);
     } else {
         $data['src'] = $src;
     }
     // echo "To Process data";
     // $data['logo'] = sha1($imagedata);
     // print_r($data);
     // exit;
     if ($existing === null) {
         $ok = $this->store->insert($id, $data);
         DiscoUtils::debug('Logo is inserted in database for the first time. ' . tc_colored('INSERT', 'green'));
         return $id;
         //TODO check if saving was ok
     } else {
         if ($existing['etag'] === $etag) {
             DiscoUtils::debug('Generated logo is identical to the existing copy. Will NOT update database. ' . tc_colored('SKIP', 'cyan'));
             return $id;
         } else {
             $ok = $this->store->update($id, $data);
             DiscoUtils::debug('Logo is updated in database, because logo has changed. ' . tc_colored('UPDATE', 'red'));
             return $id;
             //TODO check if saving was ok
         }
     }
     // Will never reach...
     return false;
 }
Beispiel #6
0
 function insertOrUpdateFeed($item)
 {
     $query = array('id' => $item['id']);
     $existing = $this->db->feeds->findOne($query);
     if ($existing !== null) {
         foreach ($item as $k => $v) {
             $existing[$k] = $v;
         }
         $existing['update'] = new MongoDate();
         $this->db->feeds->update($query, $existing);
         DiscoUtils::log('Updating feed config ' . tc_colored('UPDATE', 'red') . ' ' . $item['id']);
     } else {
         $item['created'] = new MongoDate();
         $this->db->feeds->insert($item);
         DiscoUtils::log('Adding new metadata feed ' . tc_colored('INSERT', 'green') . ' ' . $item['id']);
     }
 }