コード例 #1
0
function session_cache_lookup($key, $refresh_timeout, $refresh_url, $refresh_method, $refresh_arguments)
{
    if (!isset($_SESSION)) {
        //    error_log("Starting Session");
        session_start();
        //    if (isset($_SESSION)) { error_log("SET"); } else { error_log("NOT SET"); }
        //  } else {
        //    error_log("session_cache.lookup: IS SET " . print_r($_SESSION[$key], true));
    }
    $timeout_key = $key . "_TIMEOUT";
    // We need to refresh the cache if:
    // 1- There's no entry in the cache
    // 2- There's no time of last update
    // 3- The time of last update is null
    // 4- The time of last update is longer than $refresh_timeout ago
    $now = time();
    if (!array_key_exists($key, $_SESSION) || !array_key_exists($timeout_key, $_SESSION) || $_SESSION[$timeout_key] == null || $now - $_SESSION[$timeout_key] > $refresh_timeout) {
        $refresh_message['operation'] = $refresh_method;
        if ($refresh_arguments != null) {
            foreach ($refresh_arguments as $arg_key => $arg_val) {
                $refresh_message[$arg_key] = $arg_val;
            }
        }
        $client = XMLRPCClient::get_client($refresh_url);
        $response = $client->{$refresh_method}();
        // ignores args
        $_SESSION[$key] = $response;
        $_SESSION[$timeout_key] = $now;
        //      error_log("Refreshing cache for key $key : message = " . print_r($refresh_message, true) . " " . $key . " " . $_SESSION[$key] . " " . $timeout_key . " " . $_SESSION[$timeout_key] . " " . $now . " " . $refresh_timeout);
    }
    $value = $_SESSION[$key];
    return $value;
}
コード例 #2
0
 /**
  * Do the ping on the cron filter "ping_sites"
  *
  * @param boolean $result The result of the cron job, false if failed
  * @return boolean The result of the cron job, false if failed to get rescheduled
  */
 public static function ping_sites($result)
 {
     $services = Options::get('autopinger__pingservices');
     if (!is_array($services)) {
         EventLog::log('No pings sent - no services configured.');
         return false;
     } else {
         $count = 0;
         foreach ($services as $service) {
             $rpc = new XMLRPCClient($service, 'weblogUpdates');
             $ping = $rpc->ping(Options::get('title'), Site::get_url('habari'));
             $count++;
         }
         EventLog::log("Ping sent via XMLRPC - pinged {$count} sites.", 'info', 'default', null, $result);
         return true;
     }
 }
コード例 #3
0
ファイル: cs_client.php プロジェクト: ahelsing/geni-portal
function get_permissions($cs_url, $signer, $principal)
{
    global $permission_cache;
    if (array_key_exists($principal, $permission_cache)) {
        //    error_log("CACHE HIT get_permissions : " . $principal);
        return $permission_cache[$principal];
    }
    $client = XMLRPCClient::get_client($cs_url, $signer);
    $result = $client->get_permissions($principal, $client->creds(), $client->options());
    //  error_log("RESULT = " . print_r($result, true));
    $pm = compute_permission_manager($result);
    $permission_cache[$principal] = $pm;
    return $pm;
}
コード例 #4
0
ファイル: pingback.plugin.php プロジェクト: rynodivino/system
	/**
	 * Send a single Pingback
	 * @param string $source_uri The URI source of the ping (here)
	 * @param string $target_uri The URI destination of the ping (there, the site linked to in the content)
	 * @param Post $post The post	object that is initiating the ping, used to track the pings that were sent
	 * @todo If receive error code of already pinged, add to the successful.
	 */
	public function send_pingback( $source_uri, $target_uri, $post = NULL )
	{
		// RemoteRequest makes it easier to retrieve the headers.
		try {
			$rr = new RemoteRequest( $target_uri );
			$rr->execute();
			if ( ! $rr->executed() ) {
				return false;
			}
		}
		catch ( Exception $e ) {
			// log the pingback error
			EventLog::log( _t( 'Unable to retrieve target, can\'t detect pingback endpoint. (Source: %1$s | Target: %2$s)', array( $source_uri, $target_uri ) ), 'err', 'Pingback' );
			return false;
		}

		$headers = $rr->get_response_headers();
		$body = $rr->get_response_body();

		// Find a Pingback endpoint.
		if ( isset( $headers['X-Pingback'] ) ) {
			$pingback_endpoint = $headers['X-Pingback'];
		}
		elseif ( preg_match( '/<link rel="pingback" href="([^"]+)" ?\/?'.'>/is', $body, $matches ) ) {
			$pingback_endpoint = $matches[1];
		}
		else {
			// No Pingback endpoint found.
			return false;
		}

		try {
			$response = XMLRPCClient::open( $pingback_endpoint )->pingback->ping( $source_uri, $target_uri );
		}
		catch ( Exception $e ) {
			EventLog::log( _t( 'Invalid Pingback endpoint - %1$s (Source: %2$s | Target: %3$s)', array( $pingback_endpoint, $source_uri, $target_uri ) ), 'err', 'Pingback' );
			return false;
		}

		if ( isset( $response->faultString ) ) {
			EventLog::log( _t( 'Pingback error: %1$s - %2$s (Source: %3$s | Target: %4$s)', array( $response->faultCode, $response->faultString, $source_uri, $target_uri ) ), 'err', 'Pingback' );
			return false;
		}
		else {
			// The pingback has been registered and is stored as a successful pingback.
			if ( is_object( $post ) ) {
				if ( isset( $post->info->pingbacks_successful ) ) {
					$pingbacks_successful = $post->info->pingbacks_successful;
					$pingbacks_successful[]= $target_uri;
					$post->info->pingbacks_successful = $pingbacks_successful;
				}
				else {
					$post->info->pingbacks_successful = array( $target_uri );
				}
				$post->info->commit();
			}
			return true;
		}
	}
コード例 #5
0
ファイル: rq_client.php プロジェクト: ahelsing/geni-portal
function get_request_by_id($url, $signer, $request_id, $context_type)
{
    $client = XMLRPCClient::get_client($url, $signer);
    return $client->get_request_by_id($request_id, $context_type, $client->creds(), $client->options());
}
コード例 #6
0
ファイル: pingback.plugin.php プロジェクト: anupom/my-blog
 /**
  * Send a single Pingback
  * @param string $source_uri The URI source of the ping (here)
  * @param string $target_uri The URI destination of the ping (there, the site linked to in the content)
  * @param Post $post The post	object that is initiating the ping, used to track the pings that were sent
  * @todo If receive error code of already pinged, add to the successful.
  */
 public function send_pingback($source_uri, $target_uri, $post = NULL)
 {
     // RemoteRequest makes it easier to retrieve the headers.
     $rr = new RemoteRequest($target_uri);
     $rr->execute();
     if (!$rr->executed()) {
         return false;
     }
     $headers = $rr->get_response_headers();
     $body = $rr->get_response_body();
     // Find a Pingback endpoint.
     if (preg_match('/^X-Pingback: (\\S*)/im', $headers, $matches)) {
         $pingback_endpoint = $matches[1];
     } elseif (preg_match('/<link rel="pingback" href="([^"]+)" ?\\/?' . '>/is', $body, $matches)) {
         $pingback_endpoint = $matches[1];
     } else {
         // No Pingback endpoint found.
         return false;
     }
     try {
         $response = XMLRPCClient::open($pingback_endpoint)->pingback->ping($source_uri, $target_uri);
     } catch (Exception $e) {
         EventLog::log('Invalid Pingback endpoint - ' . $pingback_endpoint . '  (Source: ' . $source_uri . ' | Target: ' . $target_uri . ')', 'info', 'Pingback');
         return false;
     }
     if (isset($response->faultString)) {
         EventLog::log($response->faultCode . ' - ' . $response->faultString . ' (Source: ' . $source_uri . ' | Target: ' . $target_uri . ')', 'info', 'Pingback');
         return false;
     } else {
         // The pingback has been registered and is stored as a successful pingback.
         if (is_object($post)) {
             if (isset($post->info->pingbacks_successful)) {
                 $pingbacks_successful = $post->info->pingbacks_successful;
                 $pingbacks_successful[] = $target_uri;
                 $post->info->pingbacks_successful = $pingbacks_successful;
             } else {
                 $post->info->pingbacks_successful = array($target_uri);
             }
             $post->info->commit();
         }
         return true;
     }
 }
コード例 #7
0
function get_attributes_for_log_entry($log_url, $signer, $event_id)
{
    $client = XMLRPCClient::get_client($log_url, $signer);
    $attribs = $client->get_attributes_for_log_entry($event_id, $client->creds(), $client->options());
    return $attribs;
}
コード例 #8
0
ファイル: sr_client.php プロジェクト: ahelsing/geni-portal
function get_trust_roots()
{
    $client = XMLRPCClient::get_client(get_sr_url());
    $certs = $client->_get_trust_roots();
    // _ prefix means raw return value
    return $certs;
}
コード例 #9
0
ファイル: sa_client.php プロジェクト: ahelsing/geni-portal
function lookup_sliver_info_by_slice($sa_url, $signer, $slice_urn)
{
    $client = XMLRPCClient::get_client($sa_url, $signer);
    $options = array('match' => array('SLIVER_INFO_SLICE_URN' => $slice_urn));
    $options = array_merge($options, $client->options());
    $result = $client->lookup_sliver_info($client->creds(), $options);
    // results are structs by sliver_urn
    //         - SLIVER_INFO_URN
    //         - SLIVER_INFO_SLICE_URN
    //         - SLIVER_INFO_AGGREGATE_URN
    //         - SLIVER_INFO_CREATOR_URN
    //         - SLIVER_INFO_EXPIRATION
    //         - SLIVER_INFO_CREATION
    return $result;
}
コード例 #10
0
ファイル: pa_client.php プロジェクト: ahelsing/geni-portal
function remove_project_attribute($sa_url, $signer, $project_id, $name)
{
    $client = XMLRPCClient::get_client($sa_url, $signer);
    $project_urn = get_project_urn($sa_url, $signer, $project_id);
    $options = array('attr_name' => $name);
    //  error_log("RPA.options = " . print_r($options, true));
    $options = array_merge($options, $client->options());
    $result = $client->remove_project_attribute($project_urn, $client->creds(), $options);
    //  error_log("RPA.result = " . print_r($result, true));
    return $result;
    //  global $user;
    //  $remove_project_attribute_message['operation'] = 'remove_project_attribute';
    //  $remove_project_attribute_message[PA_ARGUMENT::PROJECT_ID] = $project_id;
    //  $remove_project_attribute_message[PA_ATTRIBUTE::NAME] = $name;
    //  $results = put_message($sa_url, $remove_project_attribute_message,
    //			 $signer->certificate(), $signer->privateKey());
    //  return $results;
}
コード例 #11
0
ファイル: ma_client.php プロジェクト: ahelsing/geni-portal
function get_member_urn($ma_url, $signer, $id)
{
    $cache = get_session_cached('member_urn');
    if (array_key_exists($id, $cache)) {
        return $cache[$id];
    } else {
        if (!isset($id) || is_null($id) || count($id) == 0 || count($id) == 1 && (!isset($id[0]) || is_null($id[0]) || $id[0] == '')) {
            error_log("Cannot get_member_urn for empty id: " . print_r($id, true));
            return null;
        }
        $client = XMLRPCClient::get_client($ma_url, $signer);
        $options = array('match' => array('MEMBER_UID' => $id), 'filter' => array('MEMBER_URN'));
        $options = array_merge($options, $client->options());
        $r = $client->lookup_public_member_info($client->creds(), $options);
        if (sizeof($r) > 0) {
            $urns = array_keys($r);
            $urn = $urns[0];
        } else {
            $urn = null;
            // cache failures
        }
        $cache[$id] = $urn;
        set_session_cached('member_urn', $cache);
        return $urn;
    }
}