Ejemplo n.º 1
0
 /**
  * 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;
             }
         }
     }
 }
	/**
	 * @see FileBackend::doDeleteInternal()
	 */
	function doDeleteInternal( array $params ) {
		$status = Status::newGood();

		list( $srcCont, $srcRel ) = $this->resolveStoragePath( $params['src'] );
		if ( $srcRel === null ) {
			$status->fatal( 'backend-fail-invalidpath', $params['src'] );
			return $status;
		}

		// (a) Check the source container
		try { //TODO: Unnecessary --> remove (or better, check in resolveStoragePath?)
			$container = $this->storageClient->getContainer( $srcCont );
		}
		catch ( Exception $e ) {
			$status->fatal( 'backend-fail-delete', $srcRel );
			return $status;
		}

		// (b) Actually delete the object
		try {
			$this->storageClient->deleteBlob( $srcCont, $srcRel );
		}
		catch ( Exception $e ) {
			$status->fatal( 'backend-fail-internal' );
		}

		return $status;
	}
Ejemplo n.º 3
0
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']++;
}
Ejemplo n.º 4
0
 /**
  * Tests S3
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $string = 'test_azure_' . md5(time());
     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;
     }
     $container = null;
     foreach ((array) $containers as $_container) {
         if ($_container->Name == $this->_config['container']) {
             $container = $_container;
             break;
         }
     }
     if (!$container) {
         $error = sprintf('Container doesn\'t exist: %s.', $this->_config['container']);
         return false;
     }
     try {
         $this->_client->putBlobData($this->_config['container'], $string, $string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to put blob data (%s).', $exception->getMessage());
         return false;
     }
     try {
         $data = $this->_client->getBlobData($this->_config['container'], $string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to get blob data (%s).', $exception->getMessage());
         return false;
     }
     if ($data != $string) {
         try {
             $this->_client->deleteBlob($this->_config['container'], $string);
         } catch (Exception $exception) {
         }
         $error = 'Blob datas are not equal.';
         return false;
     }
     try {
         $this->_client->deleteBlob($this->_config['container'], $string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to delete blob (%s).', $exception->getMessage());
         return false;
     }
     return true;
 }
Ejemplo n.º 5
0
                 $gstorage->delete_object($jobvalue['GStorageBucket'], $backupfile);
                 unset($gstorage);
             } catch (Exception $e) {
                 $backwpup_message .= sprintf(__('GStorage API: %s', 'backwpup'), $e->getMessage()) . '<br />';
             }
         }
     }
 } elseif ($dest == 'MSAZURE') {
     if (!class_exists('Microsoft_WindowsAzure_Storage_Blob')) {
         require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php';
     }
     if (class_exists('Microsoft_WindowsAzure_Storage_Blob')) {
         if (!empty($jobvalue['msazureHost']) and !empty($jobvalue['msazureAccName']) and !empty($jobvalue['msazureKey']) and !empty($jobvalue['msazureContainer'])) {
             try {
                 $storageClient = new Microsoft_WindowsAzure_Storage_Blob($jobvalue['msazureHost'], $jobvalue['msazureAccName'], $jobvalue['msazureKey']);
                 $storageClient->deleteBlob($jobvalue['msazureContainer'], $backupfile);
                 unset($storageClient);
             } catch (Exception $e) {
                 $backwpup_message .= 'MS AZURE: ' . $e->getMessage() . '<br />';
             }
         }
     }
 } elseif ($dest == 'DROPBOX') {
     if (!class_exists('Dropbox_API')) {
         require_once realpath(dirname(__FILE__) . '/../libs/dropbox.php');
     }
     if (!empty($jobvalue['dropetoken']) and !empty($jobvalue['dropesecret'])) {
         try {
             $dropbox = new backwpup_Dropbox('dropbox');
             $dropbox->setOAuthTokens($jobvalue['dropetoken'], $jobvalue['dropesecret']);
             $dropbox->fileopsDelete($backupfile);
// If the user submitted something put it into the blob storage
// NOTE: Inputs are not cleaned for example purposes
if (isset($_POST['submit'])) {
    $image = $blob->putBlob(BLOB_GUESTBOOK, $_FILES['Image']['name'], $_FILES['Image']['tmp_name']);
    $table = new Microsoft_WindowsAzure_Storage_Table();
    $writer = new Microsoft_WindowsAzure_Log_Writer_WindowsAzure($table, 'logThis');
    $logger = new Microsoft_Log($writer);
    //$logger->addWriter($writer);
    $logger->log($_FILES['Image']['name'] . " added", 1);
}
if (isset($_POST['Update'])) {
    echo "<b>UPDATE NOT YET IMPLEMENTED</b>";
}
// User wishes to delete something
if (isset($_GET['Delete'])) {
    $blob->deleteBlob(BLOB_GUESTBOOK, $_GET['Delete']);
}
// Get all the guest book entries for display
$entries = $blob->listBlobs(BLOB_GUESTBOOK);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Windows Azure Guestbook</title>
    <link href="main.css" rel="stylesheet" type="text/css" />
   
</head>
<body>
     <div class="general">
        <div class="title">