예제 #1
0
 /**
  * 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;
 }
예제 #2
0
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;
    }
}