Deprecation:
Author: Benoît Sautel ben.popeye@gmail.com / Régis Viarre crowkait@phpboost.com
 /**
  * Fire the webhook notification on the hmbkp_backup_complete
  *
  * @see  Backup::do_action
  * @param  string $action The action received from the backup
  * @return void
  */
 public function action($action, Backup $backup)
 {
     if ('hmbkp_backup_complete' !== $action || !$this->is_service_active()) {
         return;
     }
     $webhook_url = $this->get_url();
     $file = $backup->get_backup_filepath();
     $download = add_query_arg('hmbkp_download', base64_encode($file), HMBKP_ADMIN_URL);
     $domain = parse_url(home_url(), PHP_URL_HOST) . parse_url(home_url(), PHP_URL_PATH);
     // The backup failed, send a message saying as much
     if (!file_exists($file) && ($errors = array_merge($backup->get_errors(), $backup->get_warnings()))) {
         $error_message = '';
         foreach ($errors as $error_set) {
             $error_message .= implode("\n - ", $error_set);
         }
         if ($error_message) {
             $error_message = ' - ' . $error_message;
         }
         $subject = sprintf(__('Backup of %s Failed', 'backupwordpress'), $domain);
         $body = array('type' => 'backup.error', 'site_url' => site_url(), 'backup' => array('id' => 'backup_' . pathinfo($file, PATHINFO_FILENAME), 'start' => '0', 'end' => '0', 'download_url' => '', 'type' => $this->schedule->get_type(), 'status' => array('message' => $subject . ' - ' . $error_message, 'success' => '0')));
     } else {
         $body = array('type' => 'backup.success', 'site_url' => site_url(), 'backup' => array('id' => 'backup_' . $this->schedule->get_id(), 'start' => '0', 'end' => '0', 'download_url' => $download, 'type' => $this->schedule->get_type(), 'status' => array('message' => 'Backup complete', 'success' => '1')));
     }
     $signature = hash_hmac('sha1', serialize($body), $this->get_secret_key());
     $webhook_args = array('headers' => array('X-BWP-Signature' => $signature), 'body' => $body);
     $ret = wp_remote_post($webhook_url, $webhook_args);
     if (is_wp_error($ret)) {
         $backup->warning('Webhook', sprintf(__('Error: %s', 'backupwordpress'), $ret->get_error_message()));
     }
 }
 public function imprimirForm()
 {
     $backups = new Backup();
     $tablas = $backups->dbtablas();
     $text = "<h1>Crear punto de restauracion</h1>\t\t\n\t\t<form id='frmbackups' method='POST'>\n\t\t<div sylte='float:left'>\n\t\t<input type='hidden'  name='opcion' value='crear'/>\n\t\t<p>Puede crear un punto de restauracion, en caso de que necesite devolver el sistema a un estado anterior.</p>\n\t\t<p> \n\t\tEn la opcion 'Restaurar el sistema' aparecerá el último punto de restauracion creado, listo para restaurar\n\t\tel sistema a esa fecha o listo para ser descargado.</p>\n\t\t<table align='center' width='50%'>\t\t\n\t\t\t<tr class='tablaconten'>\n\t\t\t\t<td align='center'>\n\t\t\t\t\t<input type='button' id='crearBackUps' value='Crear'></span>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>\n\t\t<p>La fecha y la hora actual se agregan automaticamente a su punto de restauracion.</p>\n\t\t</div>\n\t\t</form>";
     echo $text;
 }
 function insert(Backup $backup)
 {
     $query = "INSERT INTO `backup`(`backup_name`, `backup_description`) VALUES ('" . $backup->getBackupName() . "','" . $backup->getBackupDescription() . "')";
     $this->con->openConnection();
     $this->con->executeRawQuery($query);
     $this->con->closeConnection();
 }
Beispiel #4
0
	/**
	 * Generates token for backup
	 *
	 * @param \Backup $backup
	 * @return srting token generated based on grouping string
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	private function genToken(\Backup $backup)
	{
		$created = clone $backup->getCreation();
		if(!is_null($this->offset)){
			$created->sub($this->offset);
		}
		return $created->format($this->group);
	}
Beispiel #5
0
 /**
  * Tests Backup::addSync()
  */
 public function testAddSync()
 {
     $backup = new Backup('name', false);
     $sync = new Backup\Sync('dropbox', true);
     $this->assertEquals(0, count($backup->getSyncs()));
     $backup->addSync($sync);
     $this->assertEquals(1, count($backup->getSyncs()));
 }
Beispiel #6
0
 private function _create_backup($files, $description)
 {
     $file = $this->_backup_store->new_backup_file();
     $bkp = new Backup($file);
     $this->_chdir_to_epesi();
     $success = $bkp->create($files, $description, $this->_backup_dir);
     $this->_chdir_back();
     return $success ? $bkp : false;
 }
 /**
  * Deletes a range of backup files
  *
  * @return boolean True on success
  */
 public function deleteSelection($list)
 {
     foreach ($list as $file) {
         $backup = new Backup($file);
         if (!$backup->delete()) {
             $this->error = $backup->error;
             return false;
         }
     }
     return true;
 }
Beispiel #8
0
	/**
	 *  Clones backup by recursive copying directory
	 *
	 * @param \Backup $toClone
	 * @param $destDir
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	public function cloneBackup( \Backup $toClone,  $destDir)
	{
		//TODO Implement in native
		exec("cp -r ".escapeshellarg($toClone->getPath())." ".
			escapeshellarg($destDir), $output, $ret);
		if($ret){
			throw new \RuntimeException(
				"Copying failed with return status [".$ret."] and output :\n".
				implode($output)
			);
		}
	}
	/**
	 * Runs transformation commnad on backup
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Transform\n";
		$fileInfo= new \SplFileInfo($this->path);
		$backup = \Backup::create($fileInfo);
		return $backup->transform();
	}
Beispiel #10
0
 public static function getInstance()
 {
     if (!self::$instance instanceof Backup) {
         self::$instance = new Backup();
     }
     return self::$instance;
 }
 public function current()
 {
     $count = Host::where("id", "!=", 0)->get()->count();
     $backups = Backup::where(DB::raw('YEAR(created_at)'), '=', "2013")->where(DB::raw('MONTH(created_at)'), '=', "01")->where(DB::raw('DAY(created_at)'), '=', "21")->where('type', '=', 'cron')->get(array('id', 'host_id', 'hostname', 'status', 'files_original_size', 'db_original_size', 'total_size'));
     $report = "";
     foreach ($backups as $backup) {
         $backup["files_original_size"] = $this->ghs($backup["files_original_size"]);
         $backup["db_original_size"] = $this->ghs($backup["db_original_size"]);
         $backup["total_size"] = $this->ghs($backup["total_size"]);
         if ($backup["status"] == "ok") {
             $row = '<tr class="success">';
         }
         if ($backup["status"] == "broken") {
             $row = '<tr class="danger">';
         }
         if ($backup["status"] == "removed") {
             $row = '<tr class="warning">';
         }
         $row .= "<td>" . $backup["id"] . "</td>";
         $row .= "<td>" . $backup["host_id"] . "</td>";
         $row .= "<td>" . $backup["hostname"] . "</td>";
         $row .= "<td>" . $backup["files_original_size"] . "</td>";
         $row .= "<td>" . $backup["db_original_size"] . "</td>";
         $row .= "<td>" . $backup["total_size"] . "</td>";
         $row .= "</tr>";
         $report .= $row;
     }
     return View::make('reports.daily')->with('report', $report)->with('hosts_count', $count)->with('email', Auth::user()->email);
 }
Beispiel #12
0
 static function sharedInstance()
 {
     if (is_null(self::$sharedInstance)) {
         self::$sharedInstance = new self();
     }
     return self::$sharedInstance;
 }
Beispiel #13
0
 public static function set_current_backup_dir($new_backup_dir)
 {
     if ($new_backup_dir instanceof File) {
         self::$current_backup_dir = $new_backup_dir->getPath();
     } else {
         self::$current_backup_dir = $new_backup_dir;
     }
 }
Beispiel #14
0
 function testBackupDir()
 {
     $resulting_path = Backup::backup_dir("/" . FRAMEWORK_CORE_PATH . "tests/io/advances_dir_list/");
     $f = new File($resulting_path);
     $this->assertTrue($f->exists(), "Il file di backup non e' stato creato!!");
     $this->assertTrue($f->getSize() > 0, "Il file ha dimensione nulla!!");
     $f->delete();
 }
 /**
  * 还原
  */
 public function recovery()
 {
     if (!IS_GET) {
         $this->error("页面不存在!");
     }
     $dir = Q("get.dir");
     Backup::recovery(array('dir' => ROOT_PATH . 'Backup/Databases/' . $dir, "url" => U("Admin/Databases/index")));
 }
 /**
  * Perform a Backup.
  *
  * ## OPTIONS
  *
  * [--files_only]
  * : Backup files only, default to off
  *
  * [--database_only]
  * : Backup database only, defaults to off
  *
  * [--destination]
  * : dir that the backup should be save in, defaults to your existing backups directory
  *
  * [--root]
  * : dir that should be backed up, defaults to site root.
  *
  * [--zip_command_path]
  * : path to your zip binary, standard locations are automatically used
  *
  * [--mysqldump_command_path]
  * : path to your mysqldump binary, standard locations are automatically used
  *
  * [--archive_filename]
  * : filename for the resulting zip file
  *
  * [--excludes]
  * : list of paths you'd like to exclude
  *
  * ## Usage
  *
  *     wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
  *
  * @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated.
  */
 public function backup($args, $assoc_args)
 {
     add_action('hmbkp_mysqldump_started', function () {
         WP_CLI::line(__('Backup: Dumping database...', 'backupwordpress'));
     });
     add_action('hmbkp_archive_started', function () {
         WP_CLI::line(__('Backup: Zipping everything up...', 'backupwordpress'));
     });
     $hm_backup = new Backup();
     if (!empty($assoc_args['destination'])) {
         Path::get_instance()->set_path($assoc_args['destination']);
     }
     Path::get_instance()->cleanup();
     if (!empty($assoc_args['root'])) {
         $hm_backup->set_root($assoc_args['root']);
     }
     if (!is_dir(hmbkp_path())) {
         WP_CLI::error(__('Invalid backup path', 'backupwordpress'));
         return false;
     }
     if (!is_dir($hm_backup->get_root()) || !is_readable($hm_backup->get_root())) {
         WP_CLI::error(__('Invalid root path', 'backupwordpress'));
         return false;
     }
     if (isset($assoc_args['archive_filename'])) {
         $hm_backup->set_archive_filename($assoc_args['archive_filename']);
     }
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->set_type('file');
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->set_type('database');
     }
     if (isset($assoc_args['mysqldump_command_path'])) {
         $hm_backup->set_mysqldump_command_path($assoc_args['mysqldump_command_path']);
     }
     if (isset($assoc_args['zip_command_path'])) {
         $hm_backup->set_zip_command_path($assoc_args['zip_command_path']);
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->set_excludes($assoc_args['excludes']);
     }
     $hm_backup->backup();
     if (file_exists($hm_backup->get_archive_filepath())) {
         WP_CLI::success(__('Backup Complete: ', 'backupwordpress') . $hm_backup->get_archive_filepath());
     } else {
         WP_CLI::error(__('Backup Failed', 'backupwordpress'));
     }
 }
 public function recovery()
 {
     $dir = APP_PATH . "Backup/" . Q("dir");
     $result = Backup::recovery(array('dir' => $dir));
     if ($result['status'] == 'success') {
         $this->success($result['message'], U('index'));
     } else {
         $this->success($result['message'], $result['url'], 0.2);
     }
 }
Beispiel #18
0
 /**
  * Get the path to the directory where backups will be stored
  */
 public function get_path()
 {
     // Calculate the path if needed
     if (empty($this->path) || !wp_is_writable($this->path)) {
         $this->calculate_path();
     }
     // Ensure the backup directory is protected
     $this->protect_path();
     return Backup::conform_dir($this->path);
 }
 public function getViewDate($id, $year, $month)
 {
     // if ((Session::token() != Input::get('_token')) && !(Request::ajax()))
     //    {
     //        App::abort(401, 'You are not authorized or using wrong request type or csrf token not provided.');
     //    }
     $count = Host::where("id", "!=", 0)->get()->count();
     //ignoring service host
     $backups = Backup::select('id', 'created_at', 'status', 'file', 'username', 'total_size', 'type')->where('host_id', '=', $id)->where(DB::raw('YEAR(created_at)'), '=', $year)->where(DB::raw('MONTH(created_at)'), '=', $month)->orderBy('created_at', 'desc')->get();
     return View::make('backups.show')->with('backups', $backups)->with('backups', $backups)->with('hosts_count', $count)->with('email', Auth::user()->email);
 }
Beispiel #20
0
 /**
  * standard constructor
  * @access public
  **/
 public function __construct($entity, $entity_id)
 {
     if (!isset(Backup::$auth)) {
         try {
             Backup::$auth = new SatelliteAuth('obmsatelliterequest');
         } catch (Exception $e) {
             throw new Exception($GLOBALS['l_err_obm_satellite_usersystem']);
         }
     }
     $detailsFunc = $entity . 'Details';
     $this->{$detailsFunc}($entity_id);
 }
Beispiel #21
0
	public function run_backup() {
	  $encrypt = $this->post('useEncryption');
	  $tp = new TaskPermission();
  	  if ($tp->canBackup()) {		
          $encrypt = (bool) $encrypt;
          try {
	          $backup = Backup::execute($encrypt);   
 			} catch(Exception $e) {
 				$this->set('error', $e);
 			}
 			$this->view();
		}
	}
Beispiel #22
0
	/**
	 * Verify backup using sumfile
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Verify\n";
		if(is_string($this->backup)){
			$fileinfo = new \SplFileInfo($this->backup);
			$backup=\Backup::create($fileinfo);
			$backups=array($backup);
		}else{
			$pickup = $store->getPickup();
			$backups=$pickup->getBackups();
		}
		return $this->runVerify($backups,$store);
	}
 public function showPage($selected = '')
 {
     if (!FUTURI_Session::isUserAdmin()) {
         $this->load->view("nopermission_admin");
     }
     $this->load->view("admin_header", array('selected' => $selected));
     switch ($selected) {
         case "usuarios":
             include "application/controllers/User.php";
             define_constants();
             $userController = new User();
             $userController->showListPage('', 10, false);
             break;
         case "estatisticas":
             break;
         case "backups":
             include "application/controllers/Backup.php";
             define_constants();
             $backupController = new Backup();
             $backupController->showListPage('', 10, false);
             break;
         case "configs":
             $this->load->view("admin_configs", array("object_handler" => $this));
             break;
         case "relatorios":
             include "application/controllers/Report.php";
             define_constants();
             $reportController = new Report();
             $reportController->showListPage('', 10, false);
             break;
         case "graficos":
             include "application/controllers/Chart.php";
             define_constants();
             $chartController = new Chart();
             $chartController->showListPage('', 10, false);
             break;
     }
 }
 public function recovery()
 {
     $dir = "Backup/" . Q("dir");
     $result = Backup::recovery(array('dir' => $dir));
     if ($result === false) {
         //还原发生错误
         $this->error(Backup::$error, addon_url('index'));
     } else {
         if ($result['status'] == 'success') {
             //还原完毕
             $this->success($result['message'], addon_url('index'));
         } else {
             //备份运行中...
             $this->success($result['message'], $result['url'], 0.2);
         }
     }
 }
Beispiel #25
0
 public static function backup($filename, $channelId, $removeAfterBackup = false)
 {
     $serv = StorageServer::getFreestServer();
     $relativepath = "uploads/{$channelId}/{$filename}";
     if ($serv !== false) {
         $hash = hash_hmac('sha256', $serv->address, $serv->private_key);
         $err = file_get_contents($serv->address . 'mkdir.php?cid=' . $channelId . '&hash=' . $hash);
         $filepath = ROOT . $relativepath;
         $addr = preg_replace("#^https?://([a-zA-Z0-9.-]+)(/.*)?\$#", "\$1", $serv->address);
         shell_exec("scp {$filepath} " . $serv->user . "@{$addr}:" . $serv->path . $relativepath . "");
         if ($removeAfterBackup) {
             unlink($filepath);
         }
         if (class_exists('Backup')) {
             Backup::create(array('channel_id' => $channelId, 'filepath' => $filepath, 'server' => $serv->address));
         }
     }
     return $serv->address . $relativepath;
 }
Beispiel #26
0
function curlBackup($params)
{
    $id = (int) $params['id'];
    $backup = Backup::sharedInstance();
    $modelJob = ModelJob::sharedInstance();
    ini_set("max_execution_time", 0);
    $jobConf = ModelJobConf::sharedInstance()->findById($id)[0];
    $db = ModelDb::sharedInstance()->findById((int) $jobConf->dbId)[0];
    $path = ModelPath::sharedInstance()->findById((int) $jobConf->pathId)[0];
    if (!is_null($jobConf)) {
        $job = new EntityJob();
        $job->jobConfId = $jobConf->id;
        $job->jobConfName = $jobConf->name;
        $job->starttime = time();
        $job->status = "file";
        $job->uploaded = 0;
        $job->deleted = 0;
        $modelJob->save($job);
        // update job status to "file" and save()
        $filename = $backup->backupFiles($path->path, $path->ignored);
        $job->filename = $filename;
        // update job status to "db" and save()
        $job->status = "db";
        $modelJob->save($job);
        $dbfilename = $backup->backupDatabase($db->host, $db->username, $db->pass, $db->dbname);
        $job->dbfilename = $dbfilename;
        // update job status to "cleanup" and save()
        $job->status = "files";
        $modelJob->save($job);
        //$backup->deleteBackups(); //TODO: implement a counter int he config and delete old backups when necessary
        $job->status = "done";
        $job->endtime = time();
        $modelJob->save($job);
        echo "<br/>All done\n";
        //update job status to "complete" or "error" and save()
    }
    exit;
}
	/**
	 *  Clones backup by recursive copying directory
	 *
	 * @param \Backup $toClone
	 * @param string $destDir Destination directory
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	public function cloneBackup( \Backup $toClone,  $destDir)
	{
		mkdir($destDir);
		// Crypt files
		foreach($toClone as $item){
			$newName=
				$destDir.
				DIRECTORY_SEPARATOR.
				$item->getName().
				$this->extension;
			$this->cryptFile($item->getPath(), $newName);
		}
		// Crypt old sumfile
			$newName=
				$destDir.
				DIRECTORY_SEPARATOR.
				\Backup::SUMFILE.
				$this->extension;
		$this->cryptFile($toClone->getSumfilePath(),$newName);

		$newBackup=\Backup::create(new \SplFileInfo($destDir));
		$newBackup->fill();
	}
Beispiel #28
0
 public function runRecovery()
 {
     Backup::recovery();
 }
Beispiel #29
0
    $member = Member::findOrFail($mem_id);
    $loanaccount = Loanaccount::findOrFail(Input::get('loanaccount_id'));
    $guarantor = new Loanguarantor();
    $guarantor->member()->associate($member);
    $guarantor->loanaccount()->associate($loanaccount);
    $guarantor->amount = Input::get('amount');
    $guarantor->save();
    return Redirect::to('memloans/' . $loanaccount->id);
});
Route::get('backups', function () {
    //$backups = Backup::getRestorationFiles('../app/storage/backup/');
    return View::make('backup');
});
Route::get('backups/create', function () {
    echo '<pre>';
    $instance = Backup::getBackupEngineInstance();
    print_r($instance);
    //Backup::setPath(public_path().'/backups/');
    //Backup::export();
    //$backups = Backup::getRestorationFiles('../app/storage/backup/');
    //return View::make('backup');
});
Route::get('memtransactions/{id}', 'MembersController@savingtransactions');
/*
* This route is for testing how license conversion works. its purely for testing purposes
*/
Route::get('convert', function () {
    // get the name of the organization from the database
    //$org_id = Confide::user()->organization_id;
    $organization = Organization::findorfail(1);
    $string = $organization->name;
Beispiel #30
0
 */
namespace OCA_Updater;

\OCP\JSON::checkAdminUser();
// Url to download package e.g. http://download.owncloud.org/releases/owncloud-4.0.5.tar.bz2
$packageUrl = 'http://owncloud.org/releases/owncloud-latest.zip';
//Package version e.g. 4.0.4
$packageVersion = '';
$updateData = \OC_Updater::check();
if (isset($updateData['version'])) {
    $packageVersion = $updateData['version'];
}
if (isset($updateData['url']) && extension_loaded('bz2')) {
    $packageUrl = $updateData['url'];
}
if (!$packageVersion) {
    \OCP\JSON::error(array('msg' => 'Version not found'));
    exit;
}
$sourcePath = Downloader::getPackage($packageUrl, $packageVersion);
if (!$sourcePath) {
    \OCP\JSON::error(array('msg' => 'Unable to fetch package'));
    exit;
}
$backupPath = Backup::createBackup();
if ($backupPath) {
    Updater::update($sourcePath, $backupPath);
    \OCP\JSON::success(array());
} else {
    \OCP\JSON::error(array('msg' => 'Failed to create backup'));
}