Skip to content
Permalink
Browse files

Merge pull request #173 from bareos/dev/fbergkemper/master/restore-ve…

…rsions

dev/fbergkemper/master/restore versions
  • Loading branch information...
fbergkemper committed May 14, 2019
2 parents b7a6914 + 115c86b commit 7fd6b09a4e63aee0683a03646fc6ca0ec486d0da
@@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @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/)
*
* This program is free software: you can redistribute it and/or modify
@@ -28,6 +28,7 @@
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Zend\Json\Json;
use Restore\Model\Restore;
use Restore\Form\RestoreForm;
@@ -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
*/
public function filebrowserAction()
@@ -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
* @return object
@@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @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/)
*
* This program is free software: you can redistribute it and/or modify
@@ -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
*

0 comments on commit 7fd6b09

Please sign in to comment.
You can’t perform that action at this time.