Skip to content

Commit

Permalink
Merge pull request #173 from bareos/dev/fbergkemper/master/restore-ve…
Browse files Browse the repository at this point in the history
…rsions

dev/fbergkemper/master/restore versions
  • Loading branch information
Frank Bergkemper committed May 14, 2019
2 parents b7a6914 + 115c86b commit 7fd6b09
Show file tree
Hide file tree
Showing 5 changed files with 788 additions and 47 deletions.
212 changes: 210 additions & 2 deletions webui/module/Restore/src/Restore/Controller/RestoreController.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend * bareos-webui - Bareos Web-Frontend
* *
* @link https://github.com/bareos/bareos-webui for the canonical source repository * @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2017 Bareos GmbH & Co. KG (http://www.bareos.org/) * @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
Expand All @@ -28,6 +28,7 @@
use Zend\Mvc\Controller\AbstractActionController; use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel; use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel; use Zend\View\Model\JsonModel;
use Zend\Json\Json;
use Restore\Model\Restore; use Restore\Model\Restore;
use Restore\Form\RestoreForm; use Restore\Form\RestoreForm;


Expand Down Expand Up @@ -238,7 +239,172 @@ public function indexAction()


} }


/** public function versionsAction()
{
$this->RequestURIPlugin()->setRequestURI();

if (!$this->SessionTimeoutPlugin()->isValid()) {
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

if (!$this->CommandACLPlugin()->validate($_SESSION['bareos']['commands'], $this->required_commands)) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'required_commands' => $this->required_commands,
)
);
}

$this->bsock = $this->getServiceLocator()->get('director');

$this->setRestoreParams();
$errors = null;
$result = null;

if ($this->restore_params['client'] == null) {
try {
$clients = $this->getClientModel()->getClients($this->bsock);
$client = array_pop($clients);
$this->restore_params['client'] = $client['name'];
} catch (Exception $e) {
echo $e->getMessage();
}
}

if ($this->restore_params['type'] == "client" && $this->restore_params['jobid'] == null) {
try {
$latestbackup = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", 1);
if (empty($latestbackup)) {
$this->restore_params['jobid'] = null;
} else {
$this->restore_params['jobid'] = $latestbackup[0]['jobid'];
}
} catch (Exception $e) {
echo $e->getMessage();
}
}

if (isset($this->restore_params['mergejobs']) && $this->restore_params['mergejobs'] == 1) {
$jobids = $this->restore_params['jobid'];
} else {
try {
$jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'], $this->restore_params['mergefilesets']);
$this->restore_params['jobids'] = $jobids;
} catch (Exception $e) {
echo $e->getMessage();
}
}

if ($this->restore_params['type'] == "client") {
try {
$backups = $this->getClientModel()->getClientBackups($this->bsock, $this->restore_params['client'], "any", "desc", null);
} catch (Exception $e) {
echo $e->getMessage();
}
}

try {
//$jobs = $this->getJobModel()->getJobs();
$clients = $this->getClientModel()->getClients($this->bsock);
$filesets = $this->getFilesetModel()->getDotFilesets($this->bsock);
$restorejobs = $this->getJobModel()->getRestoreJobs($this->bsock);
} catch (Exception $e) {
echo $e->getMessage();
}

if (empty($backups)) {
$errors = 'No backups of client <strong>' . $this->restore_params['client'] . '</strong> found.';
}

// Create the form
$form = new RestoreForm(
$this->restore_params,
//$jobs,
$clients,
$filesets,
$restorejobs,
$jobids,
$backups
);

// Set the method attribute for the form
$form->setAttribute('method', 'post');
$form->setAttribute('onsubmit', 'return getFiles()');

$request = $this->getRequest();

if ($request->isPost()) {

$restore = new Restore();
$form->setInputFilter($restore->getInputFilter());
$form->setData($request->getPost());

if ($form->isValid()) {

if ($this->restore_params['type'] == "client") {

$type = $this->restore_params['type'];
$jobid = $form->getInputFilter()->getValue('jobid');
$client = $form->getInputFilter()->getValue('client');
$restoreclient = $form->getInputFilter()->getValue('restoreclient');
$restorejob = $form->getInputFilter()->getValue('restorejob');
$where = $form->getInputFilter()->getValue('where');
$fileid = $form->getInputFilter()->getValue('checked_files');
$dirid = $form->getInputFilter()->getValue('checked_directories');
$jobids = $form->getInputFilter()->getValue('jobids_hidden');
$replace = $form->getInputFilter()->getValue('replace');

try {
$result = $this->getRestoreModel()->restore($this->bsock, $type, $jobid, $client, $restoreclient, $restorejob, $where, $fileid, $dirid, $jobids, $replace);
} catch (Exception $e) {
echo $e->getMessage();
}

}

$this->bsock->disconnect();

return new ViewModel(array(
'restore_params' => $this->restore_params,
'form' => $form,
'result' => $result,
'errors' => $errors,
'checked_files' => '',
'checked_directories' => ''
));

} else {

$this->bsock->disconnect();

return new ViewModel(array(
'restore_params' => $this->restore_params,
'form' => $form,
'result' => $result,
'errors' => $errors
));

}

} else {

$this->bsock->disconnect();

return new ViewModel(array(
'restore_params' => $this->restore_params,
'form' => $form,
'result' => $result,
'errors' => $errors
));

}

}


/**
* Delivers a subtree as Json for JStree * Delivers a subtree as Json for JStree
*/ */
public function filebrowserAction() public function filebrowserAction()
Expand Down Expand Up @@ -521,6 +687,48 @@ private function setRestoreParams()
} }
} }


/**
* Get Data Action
*
* @return object
*/
public function getDataAction()
{
$this->RequestURIPlugin()->setRequestURI();

if(!$this->SessionTimeoutPlugin()->isValid()) {
return $this->redirect()->toRoute('auth', array('action' => 'login'), array('query' => array('req' => $this->RequestURIPlugin()->getRequestURI(), 'dird' => $_SESSION['bareos']['director'])));
}

$result = null;

$data = $this->params()->fromQuery('data');
$clientname = $this->params()->fromQuery('clientname');
$pathid = $this->params()->fromQuery('pathid');
$filename = $this->params()->fromQuery('filename');

if($data == "fileversions") {
try {
$this->bsock = $this->getServiceLocator()->get('director');
$result = $this->getRestoreModel()->getFileVersions($this->bsock, $clientname, $pathid, $filename);
$this->bsock->disconnect();
}
catch(Exception $e) {
echo $e->getMessage();
}
}

$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');

if(isset($result)) {
$response->setContent(JSON::encode($result));
}

return $response;

}

/** /**
* Get the restore model * Get the restore model
* @return object * @return object
Expand Down
24 changes: 23 additions & 1 deletion webui/module/Restore/src/Restore/Model/RestoreModel.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend * bareos-webui - Bareos Web-Frontend
* *
* @link https://github.com/bareos/bareos-webui for the canonical source repository * @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2017 Bareos GmbH & Co. KG (http://www.bareos.org/) * @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -153,6 +153,28 @@ public function getFiles(&$bsock=null, $jobid=null, $pathid=null) {
} }
} }


/**
* Get Versions via .bvfs_versions
*
* @param $bsock
* @param $clientname
* @param $pathid
* @param $filename
*
* @return array
*/
public function getFileVersions(&$bsock=null, $clientname=null, $pathid=null, $filename=null) {
if(isset($bsock)) {
$cmd = '.bvfs_versions jobid=0 client='.$clientname.' pathid='.$pathid.' fname='.$filename;
$result = $bsock->send_command($cmd, 2, null);
$versions = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $versions['result']['versions'];
}
else {
throw new \Exception('Missing argument.');
}
}

/** /**
* Get JobIds via .bvfs_get_jodids * Get JobIds via .bvfs_get_jodids
* *
Expand Down
Loading

0 comments on commit 7fd6b09

Please sign in to comment.