/** * Init connection object * * @param string $error * @return boolean */ function _init(&$error) { if (empty($this->_config['user'])) { $error = 'Empty username.'; return false; } if (empty($this->_config['key'])) { $error = 'Empty API key.'; return false; } if (empty($this->_config['location'])) { $error = 'Empty API key.'; return false; } switch ($this->_config['location']) { default: case 'us': $host = US_AUTHURL; break; case 'uk': $host = UK_AUTHURL; break; } try { $this->_auth = new CF_Authentication($this->_config['user'], $this->_config['key'], null, $host); $this->_auth->ssl_use_cabundle(); $this->_auth->authenticate(); $this->_connection = new CF_Connection($this->_auth); $this->_connection->ssl_use_cabundle(); } catch (Exception $exception) { $error = $exception->getMessage(); return false; } return true; }
/** * Get a connection to the Swift proxy * * @return CF_Connection|false * @throws InvalidResponseException */ protected function getConnection() { if ($this->conn === false) { throw new InvalidResponseException(); // failed last attempt } // Session keys expire after a while, so we renew them periodically if ($this->conn && time() - $this->connStarted > $this->authTTL) { $this->conn->close(); // close active cURL connections $this->conn = null; } // Authenticate with proxy and get a session key... if ($this->conn === null) { $this->connContainers = array(); try { $this->auth->authenticate(); $this->conn = new CF_Connection($this->auth); $this->connStarted = time(); } catch (AuthenticationException $e) { $this->conn = false; // don't keep re-trying } catch (InvalidResponseException $e) { $this->conn = false; // don't keep re-trying } } if (!$this->conn) { throw new InvalidResponseException(); // auth/connection problem } return $this->conn; }
function doRackspaceUploadNewDeleteOld($RS_USERNAME, $RS_KEY) { //get the most recent grouping of files. $arrRecentFiles = getMostRecentFiles(); sort($arrRecentFiles); if (count($arrRecentFiles > 0)) { //============================================ get our rackspace auth, connection, and container set up ===================================== //Create the authentication instance $auth = new CF_Authentication($RS_USERNAME, $RS_KEY); //Perform authentication request $auth->authenticate(); //Create a connection to the storage/cdn system(s) and pass in the validated CF_Authentication instance. $conn = new CF_Connection($auth); //get the "salesforce_backups" container $cont = $conn->get_container('salesforce_backups'); //============================================ end get our rackspace auth, connection, and container set up ===================================== //get the date prefix off of the most recent grouping of local files $recentFileDate = getDatePrefix($arrRecentFiles[0]); //get the listing of files from rackspace cloud files $arrRackspaceFiles = $cont->list_objects(); sort($arrRackspaceFiles); //get a distinct listing off all the rackspace prefixes (Dates) $arrRackspaceDistinctPrefixes = filterDistinctPrefixes($arrRackspaceFiles); //see if the most recent local date is in rackspace or not if (!in_array($recentFileDate, $arrRackspaceDistinctPrefixes)) { //we haven't uploaded our most recent local files yet to rackspace. Let's do it. uploadToRackspace($cont, $arrRecentFiles); } //refresh our container and objects so we are sure the newly included files are in them $cont = $conn->get_container('salesforce_backups'); //if we have more than 4 distinct date range prefixes (more than 4 weekly backups), delete the older ones so we are just left with the 4 most recent. deleteOlderBackups($conn, $cont); } }
/** * Get the Swift thumbnail container for this wiki. * * @param $site string * @param $lang string * @param $relPath string Path relative to container * @return CF_Container|null */ function wmfGetSwiftThumbContainer($site, $lang, $relPath) { global $wmfSwiftConfig; // from PrivateSettings.php $auth = new CF_Authentication($wmfSwiftConfig['user'], $wmfSwiftConfig['key'], NULL, $wmfSwiftConfig['authUrl']); try { $auth->authenticate(); } catch (Exception $e) { wfDebugLog('swiftThumb', "Could not establish a connection to Swift."); return null; } $conn = new CF_Connection($auth); $wikiId = "{$site}-{$lang}"; // Get the full swift container name, including any shard suffix $name = "{$wikiId}-local-thumb"; if (in_array($wikiId, array('wikipedia-commons', 'wikipedia-en'))) { // Code stolen from FileBackend::getContainerShard() if (preg_match("!^(?:[^/]{2,}/)*[0-9a-f]/(?P<shard>[0-9a-f]{2})(?:/|\$)!", $relPath, $m)) { $name .= '.' . $m['shard']; } else { throw new MWException("Can't determine shard of path '{$relPath}' for '{$wikiId}'."); } } try { $container = $conn->get_container($name); } catch (NoSuchContainerException $e) { // container not created yet $container = null; wfDebugLog('swiftThumb', "Could not access `{$name}`; container does not exist."); } return $container; }
public function connect() { App::import('Vendor', 'rackspace-php-cloudfiles-5b45176/cloudfiles'); $auth = new CF_Authentication(Configure::read('Cloudfiles.username'), Configure::read('Cloudfiles.apikey')); $auth->authenticate(); $conn = new CF_Connection($auth); return $conn; }
protected function initContainer() { if (!$this->containerInitiated) { $auth = new \CF_Authentication($this->username, $this->apiKey); $auth->authenticate(); $conn = new \CF_Connection($auth, $this->serviceNet); $container = $conn->get_container($this->name); parent::__construct($container->cfs_auth, $container->cfs_http, $container->name, $container->object_count, $container->bytes_used); } $this->containerInitiated = true; }
public function authconn($use_servicenet) { $auth = new CF_Authentication($this->authname, $this->authkey); try { $auth->authenticate(); } catch (AuthenticationException $e) { //for some reason this returns two error msgs. one is echo'd even without the below echo echo $e->getMessage(); return false; } $this->conn = new CF_Connection($auth, $servicenet = $use_servicenet); }
public function __construct($config) { $return = parent::__construct($config); require_once 'cloudfiles.php'; $auth = new CF_Authentication($this->config['rsc-username'], $this->config['rsc-apikey']); $auth->authenticate(); $this->conn = new CF_Connection($auth); if ($this->config['rsc-ssl_use_cabundle']) { $this->conn->ssl_use_cabundle(); } return $return; }
function getConnection() { require_once 'modulos/cdn/clases/cloudfiles.php'; $username = "******"; $api_key = "a4958be56757129de44332626cb0594b"; $auth = new CF_Authentication($username, $api_key); $auth->authenticate(); //Creamos una conexión //Si esta en el servidor con true //$conn = new CF_Connection($auth, TRUE); $conn = new CF_Connection($auth); return $conn; }
/** * Get an authenticated connection handle to the Swift proxy * * @throws CloudFilesException * @throws CloudFilesException|Exception * @return CF_Connection|bool False on failure */ protected function getConnection() { if ($this->connException instanceof CloudFilesException) { if (time() - $this->connErrorTime < 60) { throw $this->connException; // failed last attempt; don't bother } else { // actually retry this time $this->connException = null; $this->connErrorTime = 0; } } // Session keys expire after a while, so we renew them periodically $reAuth = time() - $this->sessionStarted > $this->authTTL; // Authenticate with proxy and get a session key... if (!$this->conn || $reAuth) { $this->sessionStarted = 0; $this->connContainerCache->clear(); $cacheKey = $this->getCredsCacheKey($this->auth->username); $creds = $this->srvCache->get($cacheKey); // credentials if (is_array($creds)) { // cache hit $this->auth->load_cached_credentials($creds['auth_token'], $creds['storage_url'], $creds['cdnm_url']); $this->sessionStarted = time() - ceil($this->authTTL / 2); // skew for worst case } else { // cache miss try { $this->auth->authenticate(); $creds = $this->auth->export_credentials(); $this->srvCache->add($cacheKey, $creds, ceil($this->authTTL / 2)); // cache $this->sessionStarted = time(); } catch (CloudFilesException $e) { $this->connException = $e; // don't keep re-trying $this->connErrorTime = time(); throw $e; // throw it back } } if ($this->conn) { // re-authorizing? $this->conn->close(); // close active cURL handles in CF_Http object } $this->conn = new CF_Connection($this->auth); } return $this->conn; }
public function createSynchronizer() { $username = sfConfig::get('app_rackspace_username'); $key = sfConfig::get('app_rackspace_key'); $containerName = sfConfig::get('app_rackspace_container'); $webDir = sfConfig::get('sf_web_dir'); $ttl = sfConfig::get('app_rackspace_ttl'); $mimeTypeResolver = $this->get('mime_type_resolver'); $dispatcher = $this->get('dispatcher'); $this->logSection("rackspace", "Connecting '{$username}' to '{$containerName}'"); $auth = new CF_Authentication($username, $key); $auth->authenticate(); $conn = new CF_Connection($auth); $container = $conn->create_container($containerName); $synchronizer = new knpDmRackspaceSynchronizer($container, $webDir, $ttl, $mimeTypeResolver, $dispatcher); return $synchronizer; }
private static function getAuth() { global $wgMemc; $cacheKey = wfMemcKey('rscloudauth'); $auth = new CF_Authentication(WH_RSCLOUD_USERNAME, WH_RSCLOUD_API_KEY); $creds = $wgMemc->get($cacheKey); if (!$creds) { # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle $auth->authenticate(); // makes a call to a remote web server $creds = $auth->export_credentials(); $wgMemc->set($cacheKey, $creds); } else { $auth->load_cached_credentials($creds['auth_token'], $creds['storage_url'], $creds['cdnm_url']); } return $auth; }
/** * Get a connection to the Swift proxy * * @return CF_Connection|false * @throws InvalidResponseException */ protected function getConnection() { if ($this->conn === false) { throw new InvalidResponseException(); // failed last attempt } // Session keys expire after a while, so we renew them periodically if ($this->conn && time() - $this->connStarted > $this->authTTL) { $this->closeConnection(); } // Authenticate with proxy and get a session key... if ($this->conn === null) { $cacheKey = $this->getCredsCacheKey($this->auth->username); $creds = $this->srvCache->get($cacheKey); // credentials if (is_array($creds)) { // cache hit $this->auth->load_cached_credentials($creds['auth_token'], $creds['storage_url'], $creds['cdnm_url']); $this->connStarted = time() - ceil($this->authTTL / 2); // skew for worst case } else { // cache miss try { $this->auth->authenticate(); $creds = $this->auth->export_credentials(); $this->srvCache->set($cacheKey, $creds, ceil($this->authTTL / 2)); // cache $this->connStarted = time(); } catch (AuthenticationException $e) { $this->conn = false; // don't keep re-trying $this->logException($e, __METHOD__, $creds); } catch (InvalidResponseException $e) { $this->conn = false; // don't keep re-trying $this->logException($e, __METHOD__, $creds); } } $this->conn = new CF_Connection($this->auth); } if (!$this->conn) { throw new InvalidResponseException(); // auth/connection problem } return $this->conn; }
protected function createSynchronizer() { require_once dirname(__FILE__) . '/../vendor/rackspace/cloudfiles.php'; $username = sfConfig::get('app_rackspace_username'); $key = sfConfig::get('app_rackspace_key'); $containerName = sfConfig::get('app_rackspace_container'); $webDir = sfConfig::get('sf_web_dir'); $ttl = sfConfig::get('app_rackspace_ttl'); $mimeTypeResolver = $this->container->getService('mime_type_resolver'); $dispatcher = $this->container->getService('dispatcher'); $auth = new CF_Authentication($username, $key); $auth->authenticate(); $conn = new CF_Connection($auth); $container = $conn->create_container($containerName); $synchronizer = new knpDmRackspaceSynchronizer($container, $webDir, $ttl, $mimeTypeResolver, $dispatcher); return $synchronizer; }
public function connect() { static $bConnected = false; if ($bConnected === true) { return; } require_once PHPFOX_DIR_LIB . 'rackspace/cloudfiles.php'; $oAuth = new CF_Authentication(Phpfox::getParam('core.rackspace_username'), Phpfox::getParam('core.rackspace_key')); try { $oAuth->authenticate(); } catch (Exception $e) { Phpfox_Error::trigger('Rackspace error: ' . $e->getMessage(), E_USER_ERROR); } $this->_oObject = new CF_Connection($oAuth); $this->_sBucket = Phpfox::getParam('core.rackspace_container'); $this->_oContainer = $this->_oObject->get_container($this->_sBucket); $bConnected = true; }
function process_rackspace_copy($rs_backup, $rs_username, $rs_api_key, $rs_container, $rs_server) { pb_backupbuddy::set_greedy_script_limits(); require_once pb_backupbuddy::plugin_path() . '/lib/rackspace/cloudfiles.php'; $auth = new CF_Authentication($rs_username, $rs_api_key, NULL, $rs_server); $auth->authenticate(); $conn = new CF_Connection($auth); // Set container $container = $conn->get_container($rs_container); // Get file from Rackspace $rsfile = $container->get_object($rs_backup); $destination_file = ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . $rs_backup; if (file_exists($destination_file)) { $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file); } $fso = fopen(ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . $rs_backup, 'w'); $rsfile->stream($fso); fclose($fso); }
/** * Creates a singleton connection handle * * @return CF_Connection */ private function auth() { if (is_null($this->conn)) { $username = Mage::getStoreConfig('imagecdn/rackspace/username'); $api_key = Mage::getStoreConfig('imagecdn/rackspace/api_key'); $auth = new CF_Authentication($username, $api_key); $auth->ssl_use_cabundle(); $auth->authenticate(); if ($auth->authenticated()) { $this->conn = new CF_Connection($auth); $this->conn->ssl_use_cabundle(); return $this->conn; } else { return false; } } else { return $this->conn; } }
/** * Connect to the CloudFiles Service * @return boolean success * @throws CloudFilesException * @throws AuthenticationException * @throws InvalidResponseException */ protected static function connect() { if ($server = self::$server_to_auth_map[self::getConfig('server')]) { self::$Authentication = new CF_Authentication(self::getConfig('username'), self::getConfig('api_key'), null, $server); self::$Authentication->ssl_use_cabundle(); self::$Authentication->authenticate(); $hostname = gethostname(); // Check to see if this is a rackspace node if (stripos($hostname, 'rackspace') === FALSE) { $serviceNet = FALSE; } else { $serviceNet = TRUE; } self::$Connection = new CF_Connection(self::$Authentication, $serviceNet); } $retval = !!self::$Connection; if (!$retval) { self::error("Unable to connect to rackspace, check your settings."); } return $retval; }
public static function connect($settings = array()) { require_once dirname(__FILE__) . '/lib/rackspace/cloudfiles.php'; $auth = new CF_Authentication($settings['username'], $settings['api_key'], NULL, $settings['server']); try { $auth->authenticate(); } catch (Exception $e) { global $pb_backupbuddy_destination_errors; $message = 'Error #238338: Unable to authenticate to Rackspace Cloud Files. Details: `' . $e->getMessage() . '`.'; pb_backupbuddy::status('error', $message); $pb_backupbuddy_destination_errors[] = $message; return false; } //error_log( print_r( $auth, true ) ); if (isset($settings['service_net']) && '1' == $settings['service_net']) { $sn_url = 'https://snet-' . substr($auth->storage_url, strlen('https://')); $auth->storage_url = $sn_url; } $conn = new CF_Connection($auth); return $conn; }
/** * Set up Rackspace cloud files - used by rackspace:initialise task as well as constructor * * @see rackspaceInitialiseTask::execute() * @var array $options Passed through from __construct * @return CF_Container */ public static function setup($options) { $required_fields = array('container', 'api_key', 'username'); $adapter_options = $options['options']; foreach ($required_fields as $f) { if (!array_key_exists($f, $adapter_options)) { throw new InvalidArgumentException(sprintf("Missing option '%s' is required", $f)); } } $adapter_options = array_merge(self::$adapter_options, $adapter_options); $auth = new CF_Authentication($adapter_options['username'], $adapter_options['api_key'], null, 'UK' == $adapter_options['auth_host'] ? UK_AUTHURL : US_AUTHURL); $auth->authenticate(); $conn = new CF_Connection($auth); try { $container = $conn->get_container($adapter_options['container']); } catch (NoSuchContainerException $e) { // Container doesn't already exist so create it $container = $conn->create_container($adapter_options['container']); $container->make_public(); } return $container; }
/** * Get the Swift thumbnail container for this wiki. * * @param $site string * @param $lang string * @return CF_Container|null */ function wmfGetSwiftThumbContainer( $site, $lang ) { global $wmfSwiftConfig; // PrivateSettings.php $auth = new CF_Authentication( $wmfSwiftConfig['user'], $wmfSwiftConfig['key'], NULL, $wmfSwiftConfig['authUrl'] ); $auth->authenticate(); $conn = new CF_Connection( $auth ); $name = "{$site}-{$lang}-media-thumb"; // swift container name try { $container = $conn->get_container( $name ); } catch ( NoSuchContainerException $e ) { // container not created yet $container = null; wfDebugLog( 'swiftThumb', "Could not access `{$name}`; container does not exist." ); } return $container; }
public function authenticate() { /** @var Host $host */ foreach ($this->hosts as $host) { $config = $host->getAuthConfig(); $auth = new \CF_Authentication($config['swiftUser'], $config['swiftKey'], null, $config['swiftAuthUrl']); $auth->authenticate(); $credentials = $auth->export_credentials(); $host->setCredentials($credentials['auth_token'], $credentials['storage_url']); } }
function test_rackspace($rs_username, $rs_api_key, $rs_container, $rs_server) { if (empty($rs_username) || empty($rs_api_key) || empty($rs_container)) { return __('Missing one or more required fields.', 'it-l10n-backupbuddy'); } require_once pb_backupbuddy::plugin_path() . '/lib/rackspace/cloudfiles.php'; $auth = new CF_Authentication($rs_username, $rs_api_key, NULL, $rs_server); if (!$auth->authenticate()) { return __('Unable to authenticate. Verify your username/api key.', 'it-l10n-backupbuddy'); } $conn = new CF_Connection($auth); // Set container $container = @$conn->get_container($rs_container); // returns object on success, string error message on failure. if (!is_object($container)) { return __('There was a problem selecting the container:', 'it-l10n-backupbuddy') . ' ' . $container; } // Create test file $testbackup = @$container->create_object('backupbuddytest.txt'); if (!$testbackup->load_from_filename(pb_backupbuddy::plugin_path() . '/readme.txt')) { return __('BackupBuddy was not able to write the test file.', 'it-l10n-backupbuddy'); } // Delete test file from Rackspace if (!$container->delete_object('backupbuddytest.txt')) { return __('Unable to delete file from container.', 'it-l10n-backupbuddy'); } return true; // Success }
public function authenticate() { if ($this->conn) { return; } // Include CF libraries require_once Kohana::find_file('libraries/cloudfiles', 'CF_Authentication'); require_once Kohana::find_file('libraries/cloudfiles', 'CF_Connection'); require_once Kohana::find_file('libraries/cloudfiles', 'CF_Container'); require_once Kohana::find_file('libraries/cloudfiles', 'CF_Http'); require_once Kohana::find_file('libraries/cloudfiles', 'CF_Object'); $auth = new CF_Authentication($this->username, $this->api_key); $auth->authenticate(); $this->conn = new CF_Connection($auth); }
public function testBadAuthentication() { $this->setExpectedException('AuthenticationException'); $auth = new CF_Authentication('e046e8db7d813050b14ce335f2511e83', 'bleurrhrhahra'); $auth->authenticate(); }
private function authenticate() { $auth = new \CF_Authentication($this->username, $this->apiKey); $auth->authenticate(); return new \CF_Connection($auth); }
// Rackspace information $rs_username = $destination['username']; $rs_api_key = $destination['api_key']; $rs_container = $destination['container']; $rs_server = $destination['server']; /* if ( isset( $destination['server'] ) ) { $rs_server = $destination['server']; } else { $rs_server = 'https://auth.api.rackspacecloud.com'; } $rs_path = ''; //$destination['path']; */ require_once pb_backupbuddy::plugin_path() . '/destinations/rackspace/lib/rackspace/cloudfiles.php'; $auth = new CF_Authentication($rs_username, $rs_api_key, NULL, $rs_server); $auth->authenticate(); try { $conn = new CF_Connection($auth); } catch (Exception $e) { echo 'Error #847834: Exception caught accessing Rackspace. If this persists try deleting (by selecting the configure destination button) & re-creating this destination. Details: `' . $e->getMessage() . '`.'; die; } // Set container $container = @$conn->get_container($rs_container); // Delete Rackspace backups if (!empty($_POST['delete_file'])) { pb_backupbuddy::verify_nonce(); $delete_count = 0; if (!empty($_POST['files']) && is_array($_POST['files'])) { // loop through and delete Rackspace files foreach ($_POST['files'] as $rsfile) {
function afterDelete(&$model) { if ($this->_fileToRemove) { $conf = Configure::read('Trois.media'); switch ($conf['fileEngine']) { case 'local': $file = new File(WWW_ROOT . $this->_fileToRemove); return $file->delete(); break; case 'cloudFiles': App::import('Vendor', 'Trois.Cloudfiles', array('file' => 'php-cloudfiles' . DS . 'cloudfiles.php')); $auth = new CF_Authentication($conf['user'], $conf['secret']); $auth->authenticate(); $conn = new CF_Connection($auth); $container = $conn->get_container($conf['base']); return $container->delete_object($this->_fileToRemove); break; } } return true; }
try { $storageClient = new Microsoft_WindowsAzure_Storage_Blob($_POST['msazureHost'], $_POST['msazureAccName'], $_POST['msazureKey']); $result = $storageClient->createContainer($_POST['newmsazureContainer']); $jobvalues['msazureContainer'] = $result->Name; } catch (Exception $e) { $backwpup_message .= __($e->getMessage(), 'backwpup') . '<br />'; } } if (!empty($_POST['rscUsername']) and !empty($_POST['rscAPIKey']) and !empty($_POST['newrscContainer'])) { //create new Rackspase Container if needed if (!class_exists('CF_Authentication')) { require_once dirname(__FILE__) . '/../libs/rackspace/cloudfiles.php'; } try { $auth = new CF_Authentication($_POST['rscUsername'], $_POST['rscAPIKey']); if ($auth->authenticate()) { $conn = new CF_Connection($auth); $public_container = $conn->create_container($_POST['newrscContainer']); $public_container->make_private(); } } catch (Exception $e) { $backwpup_message .= __($e->getMessage(), 'backwpup') . '<br />'; } } if (isset($_POST['dropboxauthdel']) and !empty($_POST['dropboxauthdel'])) { $jobvalues['dropetoken'] = ''; $jobvalues['dropesecret'] = ''; $backwpup_message .= __('Dropbox authentication deleted!', 'backwpup') . '<br />'; } if (!empty($_POST['sugaremail']) && !empty($_POST['sugarpass']) && $_POST['authbutton'] == __('Sugarsync authenticate!', 'backwpup')) { if (!class_exists('SugarSync')) {
function test_rackspace($rs_username, $rs_api_key, $rs_container) { if (empty($rs_username) || empty($rs_api_key) || empty($rs_container)) { return 'Missing one or more required fields.'; } require_once $this->_pluginPath . '/lib/rackspace/cloudfiles.php'; $auth = new CF_Authentication($rs_username, $rs_api_key); if (!$auth->authenticate()) { return 'Unable to authenticate. Verify your username/api key.'; } $conn = new CF_Connection($auth); // Set container if (false === ($container = @$conn->get_container($rs_container))) { return 'Invalid container. You must create it first.'; } // Create test file $testbackup = @$container->create_object('backupbuddytest.txt'); if (!$testbackup->load_from_filename($this->_pluginPath . '/readme.txt')) { return 'BackupBuddy was not able to write the test file.'; } // Delete test file from Rackspace if (!$container->delete_object('backupbuddytest.txt')) { return 'Unable to delete file from container.'; } return true; // Success }