/**
  * @param string $name
  * @return \League\Flysystem\AdapterInterface
  * @throws \RuntimeException
  */
 public static function make($name)
 {
     $connections = Config::get('storage.connections');
     if (!isset($connections[$name])) {
         throw new \RuntimeException(sprintf('The storage connection %d does not exist.', $name));
     }
     $connection = $connections[$name];
     $connection['adapter'] = strtoupper($connection['adapter']);
     switch ($connection['adapter']) {
         case 'LOCAL':
             return new Local($connection['root_path'], $connection['public_url_base']);
         case 'RACKSPACE':
             $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.rackspace');
             $client = new Rackspace($service['api_endpoint'], array('username' => $service['username'], 'tenantName' => $service['tenant_name'], 'apiKey' => $service['api_key']));
             $store = $client->objectStoreService($connection['store'], $connection['region']);
             $container = $store->getContainer($connection['container']);
             return new RackspaceAdapter($container);
         case 'AWS':
             $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.aws');
             $client = S3Client::factory(array('credentials' => array('key' => $service['access_key'], 'secret' => $service['secret_key']), 'region' => $service['region'], 'version' => 'latest'));
             return new AwsS3Adapter($client, $connection['bucket']);
         case 'GCLOUD':
             $service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.google_cloud');
             $credentials = new \Google_Auth_AssertionCredentials($service['service_account'], [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL], file_get_contents($service['key_file']), $service['secret']);
             $config = new \Google_Config();
             $config->setAuthClass(GoogleAuthOAuth2::class);
             $client = new \Google_Client($config);
             $client->setAssertionCredentials($credentials);
             $client->setDeveloperKey($service['developer_key']);
             $service = new \Google_Service_Storage($client);
             return new GoogleStorageAdapter($service, $connection['bucket']);
     }
     throw new \RuntimeException(sprintf('The storage adapter %s is invalid.', $connection['adapter']));
 }
Ejemplo n.º 2
0
 public function getAdapter()
 {
     $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $this->config['username'], 'apiKey' => $this->config['apiKey']));
     $store = $client->objectStoreService(null, $this->config['region']);
     $container = $store->getContainer($this->config['container']);
     return new Adapter($container);
 }
Ejemplo n.º 3
0
 public function get_service($opts, $useservercerts = false, $disablesslverify = null)
 {
     $user = $opts['user'];
     $apikey = $opts['apikey'];
     $authurl = $opts['authurl'];
     $region = !empty($opts['region']) ? $opts['region'] : null;
     require_once UPDRAFTPLUS_DIR . '/vendor/autoload.php';
     global $updraftplus;
     # The new authentication APIs don't match the values we were storing before
     $new_authurl = 'https://lon.auth.api.rackspacecloud.com' == $authurl || 'uk' == $authurl ? Rackspace::UK_IDENTITY_ENDPOINT : Rackspace::US_IDENTITY_ENDPOINT;
     if (null === $disablesslverify) {
         $disablesslverify = UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify');
     }
     if (empty($user) || empty($apikey)) {
         throw new Exception(__('Authorisation failed (check your credentials)', 'updraftplus'));
     }
     $updraftplus->log("Cloud Files authentication URL: " . $new_authurl);
     $client = new Rackspace($new_authurl, array('username' => $user, 'apiKey' => $apikey));
     $this->client = $client;
     if ($disablesslverify) {
         $client->setSslVerification(false);
     } else {
         if ($useservercerts) {
             $client->setConfig(array($client::SSL_CERT_AUTHORITY, 'system'));
         } else {
             $client->setSslVerification(UPDRAFTPLUS_DIR . '/includes/cacert.pem', true, 2);
         }
     }
     return $client->objectStoreService('cloudFiles', $region);
 }
Ejemplo n.º 4
0
 public function __construct(callable $conf)
 {
     $client = new Rackspace($conf('FS_RACK_ENDPOINT'), ['username' => $conf('FS_RACK_USERNAME'), 'apiKey' => $conf('FS_RACK_API_KEY')]);
     $store = $client->objectStoreService('cloudFiles', $conf('FS_RACK_REGION'), $conf('FS_RACK_URL_TYPE'));
     $container = $store->getContainer($conf('FS_RACK_CONTAINER'));
     $adapter = new RackspaceAdapter($container);
     $this->constructFileSystem($adapter);
 }
 /**
  * @return \OpenCloud\ObjectStore\Resource\Container
  */
 protected function getContainer()
 {
     if (!isset($this->container)) {
         $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $this->config[self::USERNAME], 'apiKey' => $this->config[self::API_KEY]));
         $service = $client->objectStoreService('cloudFiles', $this->config[self::REGION], empty($this->config[self::SERVICE_NET]) ? 'publicURL' : 'internalURL');
         $this->container = $service->getContainer($this->containerName);
     }
     return $this->container;
 }
 private function get_container_connection()
 {
     if (!$this->container) {
         $client = new Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, array('username' => env('RACKSPACE_USERNAME'), 'apiKey' => env('RACKSPACE_KEY')));
         $region = env('RACKSPACE_REGION');
         $objectStoreService = $client->objectStoreService(null, $region);
         $this->container = $objectStoreService->getContainer(env('RACKSPACE_CONTAINER'));
     }
     return $this->container;
 }
Ejemplo n.º 7
0
Archivo: Rcf.php Proyecto: hhgr/hhgolf
 /**
  * Returns the remote transport client
  * @param array $params
  * @param string $include_container
  * @return \OpenCloud\ObjectStore\Resource\Container|\OpenCloud\ObjectStore\Service
  */
 public static function getRemoteClient(array $params, $include_container = true)
 {
     $url = isset($params['rcf_location']) && strtolower($params['rcf_location']) == 'uk' ? Rackspace::UK_IDENTITY_ENDPOINT : Rackspace::US_IDENTITY_ENDPOINT;
     $client = new Rackspace($url, ['username' => $params['rcf_username'], 'apiKey' => $params['rcf_api']]);
     $client->authenticate();
     $store = $client->objectStoreService('cloudFiles');
     if ($include_container) {
         return $store->getContainer($params['rcf_container']);
     }
     return $store;
 }
Ejemplo n.º 8
0
 /**
  * Get the Rackspace Cloud Files container.
  *
  * @param  \OpenCloud\Rackspace  $client
  * @param  array  $config
  * @return \OpenCloud\ObjectStore\Resource\Container
  */
 protected function getRackspaceContainer(Rackspace $client, array $config)
 {
     $urlType = Arr::get($config, 'url_type');
     $store = $client->objectStoreService('cloudFiles', $config['region'], $urlType);
     return $store->getContainer($config['container']);
 }
Ejemplo n.º 9
0
<?php

/**
 * Copyright 2012-2014 Rackspace US, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require dirname(__DIR__) . '/../vendor/autoload.php';
use OpenCloud\Rackspace;
// 1. Instantiate a Rackspace client. You can replace {authUrl} with
// Rackspace::US_IDENTITY_ENDPOINT or similar
$client = new Rackspace('{authUrl}', array('username' => '{username}', 'apiKey' => '{apiKey}'));
// 2. Obtain an Object Store service object from the client.
$objectStoreService = $client->objectStoreService(null, '{region}');
// Get all containers
$containers = $objectStoreService->listContainers();
// Delete them
foreach ($containers as $container) {
    $container->delete(true);
}
Ejemplo n.º 10
0
 /**
  * @param mixed[] $config
  * @return AdapterInterface
  */
 protected function onCreate($config = [])
 {
     $client = new Rackspace($this->param($config, 'identityEndpoint'), $this->params($config));
     $store = $client->objectStoreService($this->param($config, 'serviceName'), $this->param($config, 'serviceRegion'), $this->param($config, 'serviceUrlType'));
     return new RackspaceAdapter($store->getContainer('flysystem'));
 }
Ejemplo n.º 11
0
// Pre-requisites:
// * Prior to running this script, you must setup the following environment variables:
//   * RAX_USERNAME: Your Rackspace Cloud Account Username, and
//   * RAX_API_KEY:  Your Rackspace Cloud Account API Key
// * There exists a container named 'logos' in your Object Store. Run
//   create-container.php if you need to create one first.
// * The 'logos' container contains an object named 'php-elephant.jpg'. Run
//   upload-object.php if you need to create it first.
//
require __DIR__ . '/../../vendor/autoload.php';
use OpenCloud\Rackspace;
// 1. Instantiate a Rackspace client.
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => getenv('RAX_USERNAME'), 'apiKey' => getenv('RAX_API_KEY')));
// 2. Obtain an Object Store service object from the client.
$region = 'DFW';
$objectStoreService = $client->objectStoreService(null, $region);
// 3. Get container.
$container = $objectStoreService->getContainer('logos');
// 4. Get object.
$objectName = 'php-elephant.jpg';
$object = $container->getObject($objectName);
/** @var $object OpenCloud\ObjectStore\Resource\DataObject **/
printf("Object name: %s\n", $object->getName());
$objectContent = $object->getContent();
/** @var $objectContent Guzzle\Http\EntityBody **/
// 5. Write object content to file on local filesystem.
$objectContent->rewind();
$stream = $objectContent->getStream();
$localFilename = tempnam("/tmp", 'php-opencloud-');
file_put_contents($localFilename, $stream);
printf("Your object has been written to %s\n", $localFilename);
Ejemplo n.º 12
0
    // RESIZE AND PRESERVE TRANSPARENCY ON EYES
    $temp_image = imagecreatetruecolor($eye_image_width, $eye_image_height);
    imagealphablending($temp_image, false);
    imagesavealpha($temp_image, true);
    $transparent = imagecolorallocatealpha($temp_image, 255, 255, 255, 127);
    imagefilledrectangle($temp_image, 0, 0, $eye_image_width, $eye_image_height, $transparent);
    imagecopyresampled($temp_image, $eye_image, 0, 0, 0, 0, $eye_image_width, $eye_image_height, imagesx($eye_image), imagesy($eye_image));
    // get width and height of resized eye
    $sx = imagesx($temp_image) - $eye_image_width / 2;
    $sy = imagesy($temp_image) - $eye_image_width / 2;
    imagecopy($profile_image, $temp_image, $left_eye_marge_right - $sx, $left_eye_marge_bottom - $sy, 0, 0, imagesx($temp_image), imagesy($temp_image));
    imagecopy($profile_image, $temp_image, $right_eye_marge_right - $sx, $right_eye_marge_bottom - $sy, 0, 0, imagesx($temp_image), imagesy($temp_image));
}
imagepng($profile_image, __DIR__ . rand(0, 10000) . 'png');
imagedestroy($profile_image);
$objectStoreService = $client->objectStoreService(null, 'ORD');
//$container = $objectStoreService->createContainer('eyes');
$container = $objectStoreService->getContainer('tomato');
//print_r($container);
$new_image_name = rand(0, 10000) . 'png';
imagepng($profile_image, __DIR__ . '/' . $new_image_name);
$localFileName = __DIR__ . '/' . $new_image_name;
$remoteFileName = $new_image_name;
$handle = fopen($localFileName, 'r');
$container->uploadObject($remoteFileName, $handle);
//fclose($handle);
//print_r($container);
header('Content-type: text/plain');
echo 'http://9ac6f2b05dad964c4500-289fb48c1e3607de5437a0c9e6e868be.r38.cf2.rackcdn.com/' . $remoteFileName;
/*
// Output and free memory
 /**
  * Get the rackspace client.
  *
  * @param string[] $auth
  *
  * @return \OpenCloud\ObjectStore\Resource\Container
  */
 protected function getClient(array $auth)
 {
     $client = new OpenStackRackspace($auth['endpoint'], ['username' => $auth['username'], 'apiKey' => $auth['apiKey']]);
     $urlType = array_get($auth, 'internal', false) ? 'internalURL' : 'publicURL';
     return $client->objectStoreService('cloudFiles', $auth['region'], $urlType)->getContainer($auth['container']);
 }
Ejemplo n.º 14
0
 /**
  * @param array $config
  * @return Flysystem
  */
 public function get(array $config)
 {
     $client = new Rackspace($config['endpoint'], ['username' => $config['username'], 'apiKey' => $config['key']]);
     $container = $client->objectStoreService('cloudFiles', $config['zone'])->getContainer($config['container']);
     return new Flysystem(new RackspaceAdapter($container, $config['root']));
 }
Ejemplo n.º 15
0
<?php

/**
 * Backup MySQL to Rackspace Cloud Files
 *
 * @author     Chris Mears <*****@*****.**>
 */
date_default_timezone_set('America/Chicago');
require 'vendor/autoload.php';
require 'settings.php';
use OpenCloud\Rackspace;
echo date('[r] ') . "INFO: Backup initiated.\n";
echo date('[r] ') . "INFO: Backing up {$db} on {$dbserver}...\n";
exec("mysqldump --opt --user={$user} --password={$password} --host={$dbserver} {$db} > {$file}");
// Create gzip and force overwrite
echo date('[r] ') . "INFO: {$file} created. Compressing...\n";
exec("gzip -f {$file}");
echo date('[r] ') . "INFO: {$file}.gz created. Sending to Rackspace Cloud Files {$rackspaceContainer} container...\n";
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $rackspaceUser, 'apiKey' => $rackspaceApiKey));
$service = $client->objectStoreService(null, $rackspaceRegion, $rackspaceUrlType);
try {
    $container = $service->getContainer($rackspaceContainer);
    $container->uploadObject("{$file}.gz", fopen("{$file}.gz", 'r+'));
} catch (Exception $e) {
    echo date('[r] ') . "ERROR: {$file}.gz upload failed.\n";
    echo date('[r] ') . "ERROR: " . $e->getMessage() . "\n";
    echo date('[r] ') . "ERROR: Backup failed.\n";
    exit;
}
echo date('[r] ') . "INFO: {$file}.gz uploaded.\n";
echo date('[r] ') . "SUCCESS: Backup complete.\n";
Ejemplo n.º 16
0
 /**
  * Get the rackspace client.
  *
  * @param string[] $auth
  *
  * @return \OpenCloud\ObjectStore\Resource\Container
  */
 protected function getClient(array $auth)
 {
     $client = new OpenStackRackspace($auth['endpoint'], ['username' => $auth['username'], 'apiKey' => $auth['apiKey']]);
     return $client->objectStoreService('cloudFiles', $auth['region'])->getContainer($auth['container']);
 }
Ejemplo n.º 17
0
 /**
  * Get the Rackspace Cloud Files container.
  *
  * @param  Rackspace  $client
  * @param  array  $config
  * @return \OpenCloud\ObjectStore\Resource\Container
  */
 protected function getRackspaceContainer(Rackspace $client, array $config)
 {
     $store = $client->objectStoreService('cloudFiles', $config['region']);
     return $store->getContainer($config['container']);
 }
Ejemplo n.º 18
0
function upload_data($authuserid)
{
    $username = "******";
    // username
    $key = "0d5739ba0696428f885890282d3ba150";
    // api key
    //Rackspace client
    $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $username, 'apiKey' => $key));
    //Authenticate client
    $client->authenticate();
    $service = $client->objectStoreService('cloudFiles');
    $container = $service->getContainer('userimages');
    //Figure out the user first name and last name based on the $name variable
    //We must have got some dimensions to crop the images, lets get that set
    $profile_image_crop_x = $_POST['x'];
    $profile_image_crop_y = $_POST['y'];
    $profile_image_crop_w = $_POST['w'];
    $profile_image_crop_h = $_POST['h'];
    if ($_FILES['profile_image']['tmp_name'] != "") {
        $imageProcessor = new ImageManipulator($_FILES['profile_image']['tmp_name']);
        if ($profile_image_crop_w > 1 && $profile_image_crop_h > 1) {
            $croppedImage = $imageProcessor . crop($profile_image_crop_x, $profile_image_crop_y, $profile_image_crop_x + $profile_image_crop_w, $profile_image_crop_y + $profile_image_crop_h);
        }
        $imageProcessor->save($basePath . $target_profile_pic_name);
        //Read back the file so that we can now upload it to Rackspace CDN.
        //Common Meta
        $meta = array('Author' => $name, 'Origin' => 'FINAO Web');
        $metaHeaders = DataObject::stockHeaders($meta);
        $data = fopen($basePath . $target_profile_pic_name, 'r+');
        $container->uploadObject($target_profile_pic_name, $data, $metaHeaders);
        $targ_w = 150;
        $targ_h = 150;
        $jpeg_quality = 90;
        $profile_thumb_image = $imageProcessor->resample($targ_w, $targ_h);
        $imageProcessor->save($basePath . $target_profile_pic_thumb);
        $data = fopen($basePath . $target_profile_pic_thumb, 'r+');
        $container->uploadObject($target_profile_pic_thumb, $data, $metaHeaders);
    }
    if ($_FILES['profile_bg_image']['tmp_name'] != "") {
        @move_uploaded_file($_FILES['profile_bg_image']['tmp_name'], 'images/uploads/profileimages/' . $target_banner_pic_name);
        //Common Meta
        $meta = array('Author' => $name, 'Origin' => 'FINAO Web');
        $metaHeaders = DataObject::stockHeaders($meta);
        $data = fopen($basePath . $target_banner_pic_name, 'r+');
        $container->uploadObject($target_banner_pic_name, $data, $metaHeaders);
    }
}