private function init_connection() { // Verify authentication information try { $this->auth = new CF_Authentication($this->username, $this->api_key); $this->auth->authenticate(); } catch (Exception $e) { throw new moodle_exception('repo_auth_fail', 'repository_rackspace_cf'); } // Initialize the connection $conn = new CF_Connection($this->auth); // Get a list of all the available containers $containers = $conn->list_containers(); // See if the container already exists $container_exists = in_array($this->container_name, $containers); if ($container_exists) { // Save a connection to the container $this->container = $conn->get_container($this->container_name); } else { // The container specified does not exists so create it. $this->container = $conn->create_container($this->container_name); } if ($this->cdn_enable) { // Enable CDN for the container $this->container->make_public(); } else { // Disable CDN for the container $this->container->make_private(); } }
/** * Creates container * * @param string $container_id * @param string $error * @return boolean */ function create_container(&$container_id, &$error) { if (!$this->_init($error)) { return false; } try { $containers = $this->_connection->list_containers(); } catch (Exception $exception) { $error = sprintf('Unable to list containers (%s).', $exception->getMessage()); return false; } if (in_array($this->_config['container'], (array) $containers)) { $error = sprintf('Container already exists: %s.', $this->_config['container']); return false; } try { $container = $this->_connection->create_container($this->_config['container']); $container->make_public(); } catch (Exception $exception) { $error = sprintf('Unable to create container: %s (%s).', $this->_config['container'], $exception->getMessage()); return false; } $matches = null; if (preg_match('~^https?://(.+)$~', $container->cdn_uri, $matches)) { $container_id = $matches[1]; } return true; }
private static function getBucket($bucketName) { $auth = self::getAuth(); $conn = new CF_Connection($auth); try { $images = $conn->get_container($bucketName); } catch (NoSuchContainerException $e) { $images = $conn->create_container($bucketName); $uri = $images->make_public(); } return $images; }
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 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; }
/** * 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; }
public static function test($settings, $files = array()) { $rs_username = $settings['username']; $rs_api_key = $settings['api_key']; $rs_container = $settings['container']; $rs_server = $settings['server']; if (empty($rs_username) || empty($rs_api_key) || empty($rs_container)) { return __('Missing one or more required fields.', 'it-l10n-backupbuddy'); } require_once dirname(__FILE__) . '/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 @$conn->create_container($rs_container); // Create container if it does not exist. $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 }
$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')) { include_once realpath(dirname(__FILE__) . '/../libs/sugarsync.php'); }
echo "Listing buckets from your Amazon S3\n"; $awsBucketList = $objS3->listBuckets(); echo str_replace('Array', 'Amazon S3 Buckets', print_r($awsBucketList, true)) . "\n"; foreach ($awsBucketList as $awsBucketName) { if (in_array($awsBucketName, $awsExcludeBuckets)) { echo "---> Bucket {$awsBucketName} will be excluded\n"; continue; } $mossoContainerName = $prefixToAddToContainers . $awsBucketName; // TODO: check if Bucket is CDN enabled // Get objects echo "Listing objects in Bucket {$awsBucketName} \n"; $awsObjectList = $objS3->getBucket($awsBucketName); // Create this bucket as a Container on MOSSO echo "Creating Container {$mossoContainerName} in Cloud Files\n"; $objMossoContainer = $objMosso->create_container($mossoContainerName); echo "Processing objects in Bucket {$awsBucketName} \n"; foreach ($awsObjectList as $awsObjectInfo) { // Check if Object is in ignore list if (in_array($awsObjectInfo["name"], $awsExcludeObjects[$awsBucketName])) { echo "---> Object {$awsObjectInfo["name"]} will be excluded\n"; continue; } //$awsObjectInfo = $objS3->getObjectInfo($awsBucketName, $awsObjectName); echo str_replace('Array', $awsObjectInfo["name"], print_r($awsObjectInfo, true)); // TODO: Get Metadata and convert them to Mosso // Check if it's a folder if (strstr($awsObjectInfo["name"], '_$folder$')) { // No need to download anything, just create a folder entry $awsObjectInfo["name"] = substr($awsObjectInfo["name"], 0, -strlen('_$folder$')); echo 'Creating Marker for Folder ' . $awsObjectInfo["name"] . " on CloudFiles\n";
/** * Uploads the final videos (flv, iso) to the Rackspace CDN */ private function uploadToCDN() { require_once '_common/includes/rackspace_cloud_php/cloudfiles.php'; require_once '_common/config/rackspace_cloud.php'; // vars $container_name = $this->tributeId; $root_path = "/home/www/sites/worldwidememorials.net/htdocs/"; $final_video_path = $root_path . $this->tributePath . "video/" . $this->randomCode . $this->videoFilename . '.' . $this->outputFormat; $final_iso_path = $root_path . $this->imagesPath . $this->randomCode . $this->videoFilename . '.iso'; $object_name = md5(time() . $this->tributeId); // authentication process $cf_auth = new CF_Authentication($cloud_settings['production']['username'], $cloud_settings['production']['api_key']); $cf_auth->authenticate(); // creates the connection $cf_conn = new CF_Connection($cf_auth); // creates the container $cf_container = $cf_conn->create_container($container_name); // deletes the previous files $cf_container_objects = $cf_container->list_objects(); foreach ($cf_container_objects as $object) { $cf_container->delete_object($object); } // creates and upload the flv video¡ $cf_flv = $cf_container->create_object($object_name . '.flv'); $cf_flv->content_type = "video/x-flv"; $cf_flv->load_from_filename($final_video_path); // creates and upload the iso file $cf_iso = $cf_container->create_object($object_name . '.iso'); $cf_iso->content_type = "application/x-iso-image"; $cf_iso->load_from_filename($final_iso_path); // makes the container public $public_container = $cf_container->make_public(); $this->vars['filename'] = $public_container . '/' . $object_name . '.' . $this->outputFormat; $this->nextStep(false); }
<?php // Inclusione della libreria php-cloudfiles require 'php-cloudfiles/cloudfiles.php'; // Rackspace key $user = "******"; $key = "chiave segreta API"; // Autenticazione con il servizio API di Rackspace $auth = new CF_Authentication($user, $key); try { $auth->authenticate(); } catch (Exception $e) { die('Errore: ' . $e->getMessage()); } $conn = new CF_Connection($auth); // Creazione di un container di prova $container = $conn->create_container('test'); // Nome del file da memorizzare $filename = 'picture.jpg'; // Invio del file a Rackspace $object = $container->create_object($filename); $object->load_from_filename($filename);
if (empty($container_name)) { $log->LogError('Container name MUST be set.'); die('Container name MUST be set.'); } $log->LogInfo('Received ' . $_FILES['filename']['name']); include 'php-cloudfiles/cloudfiles.php'; // Extract user and api key from the http auth $username = $_SERVER['PHP_AUTH_USER']; $api_key = $_SERVER['PHP_AUTH_PW']; // If there's a ?name= query variable, use that as the file name $filename = empty($_GET['name']) ? $_FILES['filename']['name'] : $_GET['name']; // Authenticate with CloudFiles and create our file and container objects $auth = new CF_Authentication($username, $api_key); $auth->authenticate(); $conn = new CF_Connection($auth); $container = $conn->create_container($container_name); $file = $container->create_object($filename); // Set the content-type if (class_exists('finfo')) { // Use the PECL finfo to determine mime type $finfo = new finfo(FILEINFO_MIME); // Rename the file so we get the right extension move_uploaded_file($_FILES['filename']['tmp_name'], "/tmp/{$filename}"); $file->content_type = $finfo->file("/tmp/{$filename}"); } else { // PECL extension not installed, so try and guess $file->content_type = guessmime($filename); } $size = (double) sprintf("%u", filesize($_FILES['filename']['tmp_name'])); $fp = fopen($_FILES['filename']['tmp_name'], "r"); $file->write($fp, $size);
function dest_rsc() { global $WORKING, $STATIC; trigger_error($WORKING['DEST_RSC']['STEP_TRY'] . '. ' . __('Try to sending backup file to Rackspace Cloud...', 'backwpup'), E_USER_NOTICE); $WORKING['STEPTODO'] = 2 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']); $WORKING['STEPDONE'] = 0; require_once dirname(__FILE__) . '/../libs/rackspace/cloudfiles.php'; $auth = new CF_Authentication($STATIC['JOB']['rscUsername'], $STATIC['JOB']['rscAPIKey']); $auth->ssl_use_cabundle(); try { if ($auth->authenticate()) { trigger_error(__('Connected to Rackspase ...', 'backwpup'), E_USER_NOTICE); } $conn = new CF_Connection($auth); $conn->ssl_use_cabundle(); $is_container = false; $containers = $conn->get_containers(); foreach ($containers as $container) { if ($container->name == $STATIC['JOB']['rscContainer']) { $is_container = true; } } if (!$is_container) { $public_container = $conn->create_container($STATIC['JOB']['rscContainer']); $public_container->make_private(); if (empty($public_container)) { $is_container = false; } } } catch (Exception $e) { trigger_error(__('Rackspase Cloud API:', 'backwpup') . ' ' . $e->getMessage(), E_USER_ERROR); return; } if (!$is_container) { trigger_error(__('Rackspase Cloud Container not exists:', 'backwpup') . ' ' . $STATIC['JOB']['rscContainer'], E_USER_ERROR); return; } try { //Transfer Backup to Rackspace Cloud $backwpupcontainer = $conn->get_container($STATIC['JOB']['rscContainer']); //if (!empty($STATIC['JOB']['rscdir'])) //make the foldder // $backwpupcontainer->create_paths($STATIC['JOB']['rscdir']); $backwpupbackup = $backwpupcontainer->create_object($STATIC['JOB']['rscdir'] . $STATIC['backupfile']); //set content Type if ($STATIC['JOB']['fileformart'] == '.zip') { $backwpupbackup->content_type = 'application/zip'; } if ($STATIC['JOB']['fileformart'] == '.tar') { $backwpupbackup->content_type = 'application/x-ustar'; } if ($STATIC['JOB']['fileformart'] == '.tar.gz') { $backwpupbackup->content_type = 'application/x-compressed'; } if ($STATIC['JOB']['fileformart'] == '.tar.bz2') { $backwpupbackup->content_type = 'application/x-compressed'; } trigger_error(__('Upload to RSC now started ... ', 'backwpup'), E_USER_NOTICE); if ($backwpupbackup->load_from_filename($STATIC['JOB']['backupdir'] . $STATIC['backupfile'])) { $WORKING['STEPTODO'] = 1 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']); trigger_error(__('Backup File transferred to RSC://', 'backwpup') . $STATIC['JOB']['rscContainer'] . '/' . $STATIC['JOB']['rscdir'] . $STATIC['backupfile'], E_USER_NOTICE); $STATIC['JOB']['lastbackupdownloadurl'] = $STATIC['WP']['ADMINURL'] . '?page=backwpupbackups&action=downloadrsc&file=' . $STATIC['JOB']['rscdir'] . $STATIC['backupfile'] . '&jobid=' . $STATIC['JOB']['jobid']; $WORKING['STEPSDONE'][] = 'DEST_RSC'; //set done } else { trigger_error(__('Can not transfer backup to RSC.', 'backwpup'), E_USER_ERROR); } } catch (Exception $e) { trigger_error(__('Rackspase Cloud API:', 'backwpup') . ' ' . $e->getMessage(), E_USER_ERROR); } try { if ($STATIC['JOB']['rscmaxbackups'] > 0) { //Delete old backups $backupfilelist = array(); $contents = $backwpupcontainer->list_objects(0, NULL, NULL, $STATIC['JOB']['rscdir']); if (is_array($contents)) { foreach ($contents as $object) { $file = basename($object); if ($STATIC['JOB']['rscdir'] . $file == $object) { //only in the folder and not in complete bucket if ($STATIC['JOB']['fileprefix'] == substr($file, 0, strlen($STATIC['JOB']['fileprefix'])) and $STATIC['JOB']['fileformart'] == substr($file, -strlen($STATIC['JOB']['fileformart']))) { $backupfilelist[] = $file; } } } } if (sizeof($backupfilelist) > 0) { rsort($backupfilelist); $numdeltefiles = 0; for ($i = $STATIC['JOB']['rscmaxbackups']; $i < sizeof($backupfilelist); $i++) { if ($backwpupcontainer->delete_object($STATIC['JOB']['rscdir'] . $backupfilelist[$i])) { //delte files on Cloud $numdeltefiles++; } else { trigger_error(__('Can not delete file on RSC://', 'backwpup') . $STATIC['JOB']['rscContainer'] . $STATIC['JOB']['rscdir'] . $backupfilelist[$i], E_USER_ERROR); } } if ($numdeltefiles > 0) { trigger_error(sprintf(_n('One file deleted on RSC container', '%d files deleted on RSC container', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE); } } } } catch (Exception $e) { trigger_error(__('Rackspase Cloud API:', 'backwpup') . ' ' . $e->getMessage(), E_USER_ERROR); } $WORKING['STEPDONE']++; }