function InitializeStorage() { if (USE_DEV_EMULATOR) { //Connect to the Storage Emulator $tableClient = new Microsoft_WindowsAzure_Storage_Table(); $blobClient = new Microsoft_WindowsAzure_Storage_Blob(); $queueClient = new Microsoft_WindowsAzure_Storage_Queue(); } else { //Connect to Azure storage $tableClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_TABLES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); $blobClient = new Microsoft_WindowsAzure_Storage_Blob(AZURE_BLOBS_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); $queueClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_QUEUES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); } //Create a table to store GuestBook Entries if it doesn't exist if (!$tableClient->tableExists(GB_TABLE_NAME)) { $result = $tableClient->createTable(GB_TABLE_NAME); } //Validate the blob container name if ($blobClient->isValidContainerName(GB_BLOB_CONTAINER)) { if (!$blobClient->containerExists(GB_BLOB_CONTAINER)) { //create it if it doesn't exist $result = $blobClient->createContainer(GB_BLOB_CONTAINER); //Make it public $blobClient->setContainerAcl(GB_BLOB_CONTAINER, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC); } } //Create a queue to send thumbnail jobs to a worker process if it doesn't exist $queue = $queueClient->createQueueIfNotExists(GB_QUEUE_NAME); return array($tableClient, $blobClient, $queueClient); }
function dest_msazure() { global $WORKING, $STATIC; $WORKING['STEPTODO'] = 2 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']); trigger_error(sprintf(__('%d. try sending backup to a Microsoft Azure (Blob)...', 'backwpup'), $WORKING['DEST_MSAZURE']['STEP_TRY']), E_USER_NOTICE); require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php'; need_free_memory(4194304 * 1.5); try { $storageClient = new Microsoft_WindowsAzure_Storage_Blob($STATIC['JOB']['msazureHost'], $STATIC['JOB']['msazureAccName'], $STATIC['JOB']['msazureKey']); if (!$storageClient->containerExists($STATIC['JOB']['msazureContainer'])) { trigger_error(sprintf(__('Microsoft Azure container "%s" not exists!', 'backwpup'), $STATIC['JOB']['msazureContainer']), E_USER_ERROR); return; } else { trigger_error(sprintf(__('Connected to Microsoft Azure container "%s"', 'backwpup'), $STATIC['JOB']['msazureContainer']), E_USER_NOTICE); } trigger_error(__('Upload to MS Azure now started... ', 'backwpup'), E_USER_NOTICE); $result = $storageClient->putBlob($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir'] . $STATIC['backupfile'], $STATIC['JOB']['backupdir'] . $STATIC['backupfile']); if ($result->Name == $STATIC['JOB']['msazuredir'] . $STATIC['backupfile']) { $WORKING['STEPTODO'] = 1 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']); trigger_error(sprintf(__('Backup transferred to %s', 'backwpup'), 'https://' . $STATIC['JOB']['msazureAccName'] . '.' . $STATIC['JOB']['msazureHost'] . '/' . $STATIC['JOB']['msazuredir'] . $STATIC['backupfile']), E_USER_NOTICE); $STATIC['JOB']['lastbackupdownloadurl'] = $STATIC['WP']['ADMINURL'] . '?page=backwpupbackups&action=downloadmsazure&file=' . $STATIC['JOB']['msazuredir'] . $STATIC['backupfile'] . '&jobid=' . $STATIC['JOB']['jobid']; $WORKING['STEPSDONE'][] = 'DEST_MSAZURE'; //set done } else { trigger_error(__('Can not transfer backup to Microsoft Azure!', 'backwpup'), E_USER_ERROR); } if ($STATIC['JOB']['msazuremaxbackups'] > 0) { //Delete old backups $backupfilelist = array(); $blobs = $storageClient->listBlobs($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir']); if (is_array($blobs)) { foreach ($blobs as $blob) { $file = basename($blob->Name); 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']['msazuremaxbackups']; $i < sizeof($backupfilelist); $i++) { $storageClient->deleteBlob($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir'] . $backupfilelist[$i]); //delte files on Cloud $numdeltefiles++; } if ($numdeltefiles > 0) { trigger_error(sprintf(_n('One file deleted on Microsoft Azure container', '%d files deleted on Microsoft Azure container', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE); } } } } catch (Exception $e) { trigger_error(sprintf(__('Microsoft Azure API: %s', 'backwpup'), $e->getMessage()), E_USER_ERROR); } $WORKING['STEPDONE']++; }
protected function createStorageInstance() { $storageClient = null; if (TESTS_SESSIONHANDLER_RUNONPROD) { $storageClient = new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_PROD, TESTS_STORAGE_ACCOUNT_PROD, TESTS_STORAGE_KEY_PROD, false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); } else { $storageClient = new Microsoft_WindowsAzure_Storage_Blob(TESTS_BLOB_HOST_DEV, TESTS_STORAGE_ACCOUNT_DEV, TESTS_STORAGE_KEY_DEV, true, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); } if (TESTS_STORAGE_USEPROXY) { $storageClient->setProxy(TESTS_STORAGE_USEPROXY, TESTS_STORAGE_PROXY, TESTS_STORAGE_PROXY_PORT, TESTS_STORAGE_PROXY_CREDENTIALS); } return $storageClient; }
/** * Garbage collector * * @param int $lifeTime Session maximal lifetime * @see session.gc_divisor 100 * @see session.gc_maxlifetime 1440 * @see session.gc_probability 1 * @usage Execution rate 1/100 (session.gc_probability/session.gc_divisor) * @return boolean */ public function gc($lifeTime) { if ($this->_storageType == self::STORAGE_TYPE_TABLE) { // In table storage try { $result = $this->_storage->retrieveEntities($this->_sessionContainer, 'PartitionKey eq \'' . $this->_sessionContainerPartition . '\' and sessionExpires lt ' . (time() - $lifeTime)); foreach ($result as $sessionRecord) { $this->_storage->deleteEntity($this->_sessionContainer, $sessionRecord); } return true; } catch (Microsoft_WindowsAzure_exception $ex) { return false; } } else { if ($this->_storageType == self::STORAGE_TYPE_BLOB) { // In blob storage try { $result = $this->_storage->listBlobs($this->_sessionContainer, $this->_sessionContainerPartition, '', null, null, 'metadata'); foreach ($result as $sessionRecord) { if ($sessionRecord->Metadata['sessionexpires'] < time() - $lifeTime) { $this->_storage->deleteBlob($this->_sessionContainer, $sessionRecord->Name); } } return true; } catch (Microsoft_WindowsAzure_exception $ex) { return false; } } } }
/** * Set configuration for a specific role instance * * @param string $roleInstance Role instance name, can be found in $_SERVER['RdRoleId'] when hosted on Windows Azure. * @param Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration Configuration to apply * @throws Microsoft_WindowsAzure_Diagnostics_Exception */ public function setConfigurationForRoleInstance($roleInstance = null, Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration) { if (is_null($roleInstance)) { throw new Microsoft_WindowsAzure_Diagnostics_Exception('Role instance should be specified. Try reading $_SERVER[\'RdRoleId\'] for this information if the application is hosted on Windows Azure Fabric or Development Fabric.'); } $this->_blobStorageClient->putBlobData($this->_controlContainer, $roleInstance, $configuration->toXml(), array(), null, array('Content-Type' => 'text/xml')); }
/** * Check if a file can be created at a given storage path. * FS backends should check if the parent directory exists and the file is writable. * Backends using key/value stores should check if the container exists. * * @param $storagePath string * @return bool */ public function isPathUsableInternal($storagePath) { list($c, $dir) = $this->resolveStoragePath($storagePath); if ($dir === null) { return false; } if (!$this->storageClient->containerExists($c)) { return false; } return true; }
/** * @see FileBackend::doFileExists() */ protected function doGetFileStat( array $params ) { // TODO: Refactor list( $srcCont, $srcRel ) = $this->resolveStoragePathReal( $params['src'] ); if ( $srcRel === null ) { return false; // invalid storage path } $timestamp= false; $size = false; // TODO: need additional checks?? try { // TODO: Maybe use getBlobData()? $blob = $this->storageClient->getBlobInstance( $srcCont, $srcRel ); $timestamp = wfTimestamp( TS_MW, $blob->LastModified ); //TODO: Timezone? $size = $blob->Size; return array( 'mtime' => $timestamp, 'size' => $size ); } catch ( Exception $e ) { // TODO: Log it? What about different types of exceptions? } return false; }
/** * Creates bucket * * @param string $container_id * @param string $error * @return boolean */ function create_container(&$container_id, &$error) { if (!$this->_init($error)) { return false; } try { $containers = $this->_client->listContainers(); } 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 { $this->_client->createContainer($this->_config['container']); $this->_client->setContainerAcl($this->_config['container'], Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_BLOB); } catch (Exception $exception) { $error = sprintf('Unable to create container: %s (%s)', $this->_config['container'], $exception->getMessage()); return false; } return true; }
<?php require_once 'Microsoft/WindowsAzure/Storage/Blob.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Blob(); // download del file picture.jpg in to /path/to/picture.jpg $storageClient->getBlob('testcontainer', 'picture.jpg', '/path/to/picture.jpg');
function backwpup_get_msazure_container($args = '') { if (is_array($args)) { extract($args); $ajax = false; } else { check_ajax_referer('backwpupeditjob_ajax_nonce'); if (!current_user_can(BACKWPUP_USER_CAPABILITY)) { die('-1'); } $msazureHost = $_POST['msazureHost']; $msazureAccName = $_POST['msazureAccName']; $msazureKey = $_POST['msazureKey']; $msazureselected = $_POST['msazureselected']; $ajax = true; } if (!class_exists('Microsoft_WindowsAzure_Storage_Blob')) { require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php'; } if (empty($msazureHost)) { echo '<span id="msazureContainer" style="color:red;">' . __('Missing Hostname!', 'backwpup') . '</span>'; if ($ajax) { die; } else { return; } } if (empty($msazureAccName)) { echo '<span id="msazureContainer" style="color:red;">' . __('Missing Account Name!', 'backwpup') . '</span>'; if ($ajax) { die; } else { return; } } if (empty($msazureKey)) { echo '<span id="msazureContainer" style="color:red;">' . __('Missing Access Key!', 'backwpup') . '</span>'; if ($ajax) { die; } else { return; } } try { $storageClient = new Microsoft_WindowsAzure_Storage_Blob($msazureHost, $msazureAccName, $msazureKey); $Containers = $storageClient->listContainers(); } catch (Exception $e) { echo '<span id="msazureContainer" style="color:red;">' . $e->getMessage() . '</span>'; if ($ajax) { die; } else { return; } } if (empty($Containers)) { echo '<span id="msazureContainer" style="color:red;">' . __('No Container found!', 'backwpup') . '</span>'; if ($ajax) { die; } else { return; } } echo '<select name="msazureContainer" id="msazureContainer">'; foreach ($Containers as $Container) { echo "<option " . selected(strtolower($msazureselected), strtolower($Container->Name), false) . ">" . $Container->Name . "</option>"; } echo '</select>'; if ($ajax) { die; } else { return; } }
<?php require_once 'Microsoft/WindowsAzure/Storage/Blob.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Blob(); // rende il container pubblicamente accessibile $storageClient->setContainerAcl('testcontainer', Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);
* DEV to false and set your account and keys appropriately */ define('DEV', true); define('STORAGE_ACCOUNT', '<endpoint of your storage account>'); define('STORAGE_KEY', '<storage account key>'); define('TABLE_GUESTBOOK', 'guestbook'); define('BLOB_GUESTBOOK', 'guestbook'); // Setup the connection if (DEV) { // Connect to local development storage $table = new Microsoft_WindowsAzure_Storage_Table(); $blob = new Microsoft_WindowsAzure_Storage_Blob(); } else { // Connect to Windows Azure Storage in the cloud $table = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY); $blob = new Microsoft_WindowsAzure_Storage_Blob('blob.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY); } // Ensure the table exists $table->createTableIfNotExists(TABLE_GUESTBOOK); // Ensure the blob container exists $blob->createcontainerIfNotExists(BLOB_GUESTBOOK); // Set ACL $blob->setContainerAcl(BLOB_GUESTBOOK, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER); // If the user submitted something put it into the table storage // NOTE: Inputs are not cleaned for example purposes if (isset($_POST['NameTextBox']) && isset($_POST['MessageTextBox'])) { $g = new GuestBookEntry(); $image = $blob->putBlob(BLOB_GUESTBOOK, $_FILES['Image']['name'], $_FILES['Image']['tmp_name']); $g->GuestName = $_POST['NameTextBox']; $g->Message = $_POST['MessageTextBox']; $g->ImageUrl = $image->Url;
function backwpup_get_backup_files($jobid, $dest) { global $backwpup_message; if (empty($jobid) or !in_array(strtoupper($dest), explode(',', strtoupper(BACKWPUP_DESTS))) and $dest != 'FOLDER') { return false; } $jobs = get_option('backwpup_jobs'); //Load jobs $jobvalue = $jobs[$jobid]; $filecounter = 0; $files = array(); //Get files/filinfo in backup folder if ($dest == 'FOLDER' and !empty($jobvalue['backupdir']) and is_dir($jobvalue['backupdir'])) { if ($dir = opendir($jobvalue['backupdir'])) { while (($file = readdir($dir)) !== false) { if (substr($file, 0, 1) == '.') { continue; } if (is_file($jobvalue['backupdir'] . $file)) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = $jobvalue['backupdir']; $files[$filecounter]['file'] = $jobvalue['backupdir'] . $file; $files[$filecounter]['filename'] = $file; $files[$filecounter]['downloadurl'] = backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=download&file=' . $jobvalue['backupdir'] . $file; $files[$filecounter]['filesize'] = filesize($jobvalue['backupdir'] . $file); $files[$filecounter]['time'] = filemtime($jobvalue['backupdir'] . $file); $filecounter++; } } closedir($dir); } } //Get files/filinfo from Dropbox if ($dest == 'DROPBOX' and !empty($jobvalue['dropetoken']) and !empty($jobvalue['dropesecret'])) { require_once realpath(dirname(__FILE__) . '/../libs/dropbox.php'); try { $dropbox = new backwpup_Dropbox('dropbox'); $dropbox->setOAuthTokens($jobvalue['dropetoken'], $jobvalue['dropesecret']); $contents = $dropbox->metadata($jobvalue['dropedir']); if (is_array($contents)) { foreach ($contents['contents'] as $object) { if ($object['is_dir'] != true) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = "https://api-content.dropbox.com/1/files/" . $jobvalue['droperoot'] . "/" . dirname($object['path']) . "/"; $files[$filecounter]['file'] = $object['path']; $files[$filecounter]['filename'] = basename($object['path']); $files[$filecounter]['downloadurl'] = backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=downloaddropbox&file=' . $object['path'] . '&jobid=' . $jobid; $files[$filecounter]['filesize'] = $object['bytes']; $files[$filecounter]['time'] = strtotime($object['modified']); $filecounter++; } } } } catch (Exception $e) { $backwpup_message .= 'DROPBOX: ' . $e->getMessage() . '<br />'; } } //Get files/filinfo from Sugarsync if ($dest == 'SUGARSYNC' and !empty($jobvalue['sugarrefreshtoken'])) { if (!class_exists('SugarSync')) { require_once dirname(__FILE__) . '/../libs/sugarsync.php'; } if (class_exists('SugarSync')) { try { $sugarsync = new SugarSync($jobvalue['sugarrefreshtoken']); $dirid = $sugarsync->chdir($jobvalue['sugardir'], $jobvalue['sugarroot']); $user = $sugarsync->user(); $dir = $sugarsync->showdir($dirid); $getfiles = $sugarsync->getcontents('file'); if (is_object($getfiles)) { foreach ($getfiles->file as $getfile) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = 'https://' . $user->nickname . '.sugarsync.com/' . $dir; $files[$filecounter]['file'] = (string) $getfile->ref; $files[$filecounter]['filename'] = utf8_decode((string) $getfile->displayName); $files[$filecounter]['downloadurl'] = backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=downloadsugarsync&file=' . (string) $getfile->ref . '&jobid=' . $jobid; $files[$filecounter]['filesize'] = (int) $getfile->size; $files[$filecounter]['time'] = strtotime((string) $getfile->lastModified); $filecounter++; } } } catch (Exception $e) { $backwpup_message .= 'SUGARSYNC: ' . $e->getMessage() . '<br />'; } } } //Get files/filinfo from S3 if ($dest == 'S3' and !empty($jobvalue['awsAccessKey']) and !empty($jobvalue['awsSecretKey']) and !empty($jobvalue['awsBucket'])) { if (!class_exists('AmazonS3')) { require_once dirname(__FILE__) . '/../libs/aws/sdk.class.php'; } if (class_exists('AmazonS3')) { try { $s3 = new AmazonS3(array('key' => $jobvalue['awsAccessKey'], 'secret' => $jobvalue['awsSecretKey'], 'certificate_authority' => true)); if (($contents = $s3->list_objects($jobvalue['awsBucket'], array('prefix' => $jobvalue['awsdir']))) !== false) { foreach ($contents->body->Contents as $object) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = "https://" . $jobvalue['awsBucket'] . ".s3.amazonaws.com/" . dirname((string) $object->Key) . '/'; $files[$filecounter]['file'] = (string) $object->Key; $files[$filecounter]['filename'] = basename($object->Key); $files[$filecounter]['downloadurl'] = backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=downloads3&file=' . $object->Key . '&jobid=' . $jobid; $files[$filecounter]['filesize'] = (string) $object->Size; $files[$filecounter]['time'] = strtotime($object->LastModified); $filecounter++; } } } catch (Exception $e) { $backwpup_message .= 'Amazon S3: ' . $e->getMessage() . '<br />'; } } } //Get files/filinfo from Google Storage if ($dest == 'GSTORAGE' and !empty($jobvalue['GStorageAccessKey']) and !empty($jobvalue['GStorageSecret']) and !empty($jobvalue['GStorageBucket'])) { if (!class_exists('AmazonS3')) { require_once dirname(__FILE__) . '/../libs/aws/sdk.class.php'; } if (class_exists('AmazonS3')) { try { $gstorage = new AmazonS3(array('key' => $jobvalue['GStorageAccessKey'], 'secret' => $jobvalue['GStorageSecret'], 'certificate_authority' => true)); $gstorage->set_hostname('storage.googleapis.com'); $gstorage->allow_hostname_override(false); if (($contents = $gstorage->list_objects($jobvalue['GStorageBucket'], array('prefix' => $jobvalue['GStoragedir']))) !== false) { foreach ($contents->body->Contents as $object) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = "https://storage.cloud.google.com/" . $jobvalue['GStorageBucket'] . "/" . dirname((string) $object->Key) . '/'; $files[$filecounter]['file'] = (string) $object->Key; $files[$filecounter]['filename'] = basename($object->Key); $files[$filecounter]['downloadurl'] = "https://storage.cloud.google.com/" . $jobvalue['GStorageBucket'] . "/" . (string) $object->Key; $files[$filecounter]['filesize'] = (string) $object->Size; $files[$filecounter]['time'] = strtotime($object->LastModified); $filecounter++; } } } catch (Exception $e) { $backwpup_message .= sprintf(__('GStorage API: %s', 'backwpup'), $e->getMessage()) . '<br />'; } } } //Get files/filinfo from Microsoft Azure if ($dest == 'MSAZURE' and !empty($jobvalue['msazureHost']) and !empty($jobvalue['msazureAccName']) and !empty($jobvalue['msazureKey']) and !empty($jobvalue['msazureContainer'])) { if (!class_exists('Microsoft_WindowsAzure_Storage_Blob')) { require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php'; } if (class_exists('Microsoft_WindowsAzure_Storage_Blob')) { try { $storageClient = new Microsoft_WindowsAzure_Storage_Blob($jobvalue['msazureHost'], $jobvalue['msazureAccName'], $jobvalue['msazureKey']); $blobs = $storageClient->listBlobs($jobvalue['msazureContainer'], $jobvalue['msazuredir']); if (is_array($blobs)) { foreach ($blobs as $blob) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = "https://" . $jobvalue['msazureAccName'] . '.' . $jobvalue['msazureHost'] . "/" . $jobvalue['msazureContainer'] . "/" . dirname($blob->Name) . "/"; $files[$filecounter]['file'] = $blob->Name; $files[$filecounter]['filename'] = basename($blob->Name); $files[$filecounter]['downloadurl'] = backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=downloadmsazure&file=' . $blob->Name . '&jobid=' . $jobid; $files[$filecounter]['filesize'] = $blob->size; $files[$filecounter]['time'] = strtotime($blob->lastmodified); $filecounter++; } } } catch (Exception $e) { $backwpup_message .= 'MSAZURE: ' . $e->getMessage() . '<br />'; } } } //Get files/filinfo from RSC if ($dest == 'RSC' and !empty($jobvalue['rscUsername']) and !empty($jobvalue['rscAPIKey']) and !empty($jobvalue['rscContainer'])) { if (!class_exists('CF_Authentication')) { require_once dirname(__FILE__) . '/../libs/rackspace/cloudfiles.php'; } if (class_exists('CF_Authentication')) { try { $auth = new CF_Authentication($jobvalue['rscUsername'], $jobvalue['rscAPIKey']); $auth->ssl_use_cabundle(); if ($auth->authenticate()) { $conn = new CF_Connection($auth); $conn->ssl_use_cabundle(); $backwpupcontainer = $conn->get_container($jobvalue['rscContainer']); $contents = $backwpupcontainer->get_objects(0, NULL, NULL, $jobvalue['rscdir']); foreach ($contents as $object) { $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = "RSC://" . $jobvalue['rscContainer'] . "/" . dirname($object->name) . "/"; $files[$filecounter]['file'] = $object->name; $files[$filecounter]['filename'] = basename($object->name); $files[$filecounter]['downloadurl'] = backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=downloadrsc&file=' . $object->name . '&jobid=' . $jobid; $files[$filecounter]['filesize'] = $object->content_length; $files[$filecounter]['time'] = strtotime($object->last_modified); $filecounter++; } } } catch (Exception $e) { $backwpup_message .= 'RSC: ' . $e->getMessage() . '<br />'; } } } //Get files/filinfo from FTP if ($dest == 'FTP' and !empty($jobvalue['ftphost']) and function_exists('ftp_connect') and !empty($jobvalue['ftpuser']) and !empty($jobvalue['ftppass'])) { if (function_exists('ftp_ssl_connect') and $jobvalue['ftpssl']) { //make SSL FTP connection $ftp_conn_id = ftp_ssl_connect($jobvalue['ftphost'], $jobvalue['ftphostport'], 10); } elseif (!$jobvalue['ftpssl']) { //make normal FTP conection if SSL not work $ftp_conn_id = ftp_connect($jobvalue['ftphost'], $jobvalue['ftphostport'], 10); } $loginok = false; if ($ftp_conn_id) { //FTP Login if (@ftp_login($ftp_conn_id, $jobvalue['ftpuser'], backwpup_base64($jobvalue['ftppass']))) { $loginok = true; } else { //if PHP ftp login don't work use raw login ftp_raw($ftp_conn_id, 'USER ' . $jobvalue['ftpuser']); $return = ftp_raw($ftp_conn_id, 'PASS ' . backwpup_base64($jobvalue['ftppass'])); if (substr(trim($return[0]), 0, 3) <= 400) { $loginok = true; } } } if ($loginok) { ftp_chdir($ftp_conn_id, $jobvalue['ftpdir']); $currentftpdir = rtrim(ftp_pwd($ftp_conn_id), '/') . '/'; ftp_pasv($ftp_conn_id, $jobvalue['ftppasv']); if ($ftpfilelist = ftp_nlist($ftp_conn_id, $currentftpdir)) { foreach ($ftpfilelist as $ftpfiles) { if (substr(basename($ftpfiles), 0, 1) == '.') { continue; } $files[$filecounter]['JOBID'] = $jobid; $files[$filecounter]['DEST'] = $dest; $files[$filecounter]['folder'] = "ftp://" . $jobvalue['ftphost'] . ':' . $jobvalue['ftphostport'] . dirname($ftpfiles) . "/"; $files[$filecounter]['file'] = $ftpfiles; $files[$filecounter]['filename'] = basename($ftpfiles); $files[$filecounter]['downloadurl'] = "ftp://" . rawurlencode($jobvalue['ftpuser']) . ":" . rawurlencode(backwpup_base64($jobvalue['ftppass'])) . "@" . $jobvalue['ftphost'] . ':' . $jobvalue['ftphostport'] . $ftpfiles; $files[$filecounter]['filesize'] = ftp_size($ftp_conn_id, $ftpfiles); $files[$filecounter]['time'] = ftp_mdtm($ftp_conn_id, $ftpfiles); $filecounter++; } } } else { $backwpup_message .= 'FTP: ' . __('Login failure!', 'backwpup') . '<br />'; } $donefolders[] = $jobvalue['ftphost'] . '|' . $jobvalue['ftpuser'] . '|' . $jobvalue['ftpdir']; } return $files; }
<?php require_once 'Microsoft/WindowsAzure/Storage/Blob.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Blob(); $result = $storageClient->createContainer('testcontainer'); echo 'Il nome del container creato è : ' . $result->Name;
/** * Retrieve storage client for this stream type * * @param string $path * @return Microsoft_WindowsAzure_Storage_Blob */ protected function getStorageClient($path = '') { if (is_null($this->_storageClient)) { $url = explode(':', $path); if (!$url) { throw new Microsoft_WindowsAzure_Exception('Could not parse path "' . $path . '".'); } $this->_storageClient = Microsoft_WindowsAzure_Storage_Blob::getWrapperClient($url[0]); if (!$this->_storageClient) { throw new Microsoft_WindowsAzure_Exception('No storage client registered for stream type "' . $url[0] . '://".'); } } return $this->_storageClient; }
$gstorage->allow_hostname_override(false); $gstorage->create_bucket($_POST['newGStorageBucket'], ''); $jobvalues['GStorageBucket'] = $_POST['newGStorageBucket']; sleep(1); //creation take a moment } catch (Exception $e) { $backwpup_message .= __($e->getMessage(), 'backwpup') . '<br />'; } } if (!empty($_POST['newmsazureContainer']) and !empty($_POST['msazureHost']) and !empty($_POST['msazureAccName']) and !empty($_POST['msazureKey'])) { //create new s3 bucket if needed if (!class_exists('Microsoft_WindowsAzure_Storage_Blob')) { require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php'; } 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);
<?php require_once 'Microsoft/WindowsAzure/Storage/Blob.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Blob(); // upload del file picture.jpg in Windows Azure $result = $storageClient->putBlob('testcontainer', 'picture.jpg', '/path/to/picture.jpg'); echo 'File inserito: ' . $result->Name;
echo $sugarsync->download(urldecode($_GET['file'])); die; } catch (Exception $e) { die($e->getMessage()); } break; case 'downloadmsazure': //Download Microsoft Azure Backup check_admin_referer('download-backup'); if (!class_exists('Microsoft_WindowsAzure_Storage_Blob')) { require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php'; } $jobs = get_option('backwpup_jobs'); $jobid = $_GET['jobid']; try { $storageClient = new Microsoft_WindowsAzure_Storage_Blob($jobs[$jobid]['msazureHost'], $jobs[$jobid]['msazureAccName'], $jobs[$jobid]['msazureKey']); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Content-Type: ".$s3file->header->_info->content_type); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=" . basename($_GET['file']) . ";"); header("Content-Transfer-Encoding: binary"); //header("Content-Length: ".$s3file->header->_info->size_download); echo $storageClient->getBlobData($jobs[$jobid]['msazureContainer'], $_GET['file']); die; } catch (Exception $e) { die($e->getMessage()); }