Skip to content
Permalink
Browse files

Merge pull request #454 from bareos/dev/fbergkemper/master/s3431

webui: pre-fill restore location form element according to selected restore job
  • Loading branch information
fbergkemper committed Mar 24, 2020
2 parents 3c41877 + 494608f commit d3ba475cf70ac07a263327ebb434c931dec1b4f3
@@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2020 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
@@ -136,6 +136,7 @@ public function indexAction()
$clients = $this->getClientModel()->getClients($this->bsock);
$filesets = $this->getFilesetModel()->getDotFilesets($this->bsock);
$restorejobs = $this->getJobModel()->getRestoreJobs($this->bsock);
$restorejobresources = $this->getRestoreModel()->getRestoreJobResources($this->bsock, $restorejobs);
}
catch(Exception $e) {
echo $e->getMessage();
@@ -150,7 +151,7 @@ public function indexAction()
$this->restore_params,
$clients,
$filesets,
$restorejobs,
$restorejobresources,
$jobids,
$backups
);
@@ -326,6 +327,7 @@ public function versionsAction()
$clients = $this->getClientModel()->getClients($this->bsock);
$filesets = $this->getFilesetModel()->getDotFilesets($this->bsock);
$restorejobs = $this->getJobModel()->getRestoreJobs($this->bsock);
$restorejobresources = $this->getRestoreModel()->getRestoreJobResources($this->bsock, $restorejobs);
} catch (Exception $e) {
echo $e->getMessage();
}
@@ -339,7 +341,7 @@ public function versionsAction()
$this->restore_params,
$clients,
$filesets,
$restorejobs,
$restorejobresources,
$jobids,
$backups
);
@@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2020 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
@@ -34,19 +34,19 @@ class RestoreForm extends Form
protected $restore_params;
protected $clients;
protected $filesets;
protected $restorejobs;
protected $restorejobresources;
protected $jobids;
protected $backups;

public function __construct($restore_params=null, $clients=null, $filesets=null, $restorejobs=null, $jobids=null, $backups=null)
public function __construct($restore_params=null, $clients=null, $filesets=null, $restorejobresources=null, $jobids=null, $backups=null)
{

parent::__construct('restore');

$this->restore_params = $restore_params;
$this->clients = $clients;
$this->filesets = $filesets;
$this->restorejobs = $restorejobs;
$this->restorejobresources = $restorejobresources;
$this->jobids = $jobids;
$this->backups = $backups;

@@ -88,40 +88,21 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,

// Client
if(isset($restore_params['client'])) {
if($restore_params['type'] == "client") {
$this->add(array(
'name' => 'client',
'type' => 'select',
'options' => array(
'label' => _('Client'),
'empty_option' => _('Please choose a client'),
'value_options' => $this->getClientList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'client',
'value' => $restore_params['client']
)
));
}
else {
$this->add(array(
'name' => 'client',
'type' => 'select',
'options' => array(
'label' => _('Client'),
'empty_option' => _('Please choose a client'),
'value_options' => $this->getClientList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'client',
'value' => $restore_params['client']
)
));
}
$this->add(array(
'name' => 'client',
'type' => 'select',
'options' => array(
'label' => _('Client'),
'empty_option' => _('Please choose a client'),
'value_options' => $this->getClientList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'client',
'value' => $restore_params['client']
)
));
}
else {
$this->add(array(
@@ -142,7 +123,7 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
}

// Restore client
if(isset($restore_params['restoreclient'])) {
if(isset($this->restore_params['restoreclient'])) {
$this->add(array(
'name' => 'restoreclient',
'type' => 'select',
@@ -155,11 +136,11 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'restoreclient',
'value' => $restore_params['restoreclient']
'value' => $this->restore_params['restoreclient']
)
));
}
elseif(!isset($restore_params['restoreclient']) && isset($restore_params['client']) ) {
elseif(!isset($this->restore_params['restoreclient']) && isset($this->restore_params['client']) ) {
$this->add(array(
'name' => 'restoreclient',
'type' => 'select',
@@ -172,7 +153,7 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'restoreclient',
'value' => $restore_params['client']
'value' => $this->restore_params['client']
)
));
}
@@ -408,7 +389,7 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
}

// Where
if(isset($this->restore_params['client'])) {
if(isset($this->restore_params['restorejob'])) {
$this->add(array(
'name' => 'where',
'type' => 'text',
@@ -417,31 +398,51 @@ public function __construct($restore_params=null, $clients=null, $filesets=null,
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'value' => '/tmp/bareos-restores/',
'value' => $this->determineWhereDirective($this->restore_params['restorejob']),
'id' => 'where',
'size' => '30',
'placeholder' => _('e.g. / or /tmp/bareos-restores/')
'placeholder' => _('e.g. / or /tmp/bareos-restores/'),
'required' => 'required'
)
)
);
}
else {
$this->add(array(
'name' => 'where',
'type' => 'text',
'options' => array(
'label' => _('Restore location on client')
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'value' => '/tmp/bareos-restores/',
'id' => 'where',
'size' => '30',
'placeholder' => _('e.g. / or /tmp/bareos-restores/'),
'disabled' => true
)
)
);
if(!empty($this->restore_params['client']) && count($this->getRestoreJobList()) > 0) {
$this->add(array(
'name' => 'where',
'type' => 'text',
'options' => array(
'label' => _('Restore location on client')
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'value' => @array_pop($this->getRestoreJobWhereDirectives()),
'id' => 'where',
'size' => '30',
'placeholder' => _('e.g. / or /tmp/bareos-restores/'),
'required' => 'required'
)
)
);
} else {
$this->add(array(
'name' => 'where',
'type' => 'text',
'options' => array(
'label' => _('Restore location on client')
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'id' => 'where',
'size' => '30',
'placeholder' => _('e.g. / or /tmp/bareos-restores/'),
'required' => 'required',
'disabled' => true
)
)
);
}
}

// JobIds hidden
@@ -608,12 +609,42 @@ private function getFilesetList()
private function getRestoreJobList()
{
$selectData = array();
if(!empty($this->restorejobs)) {
foreach($this->restorejobs as $restorejob) {
$selectData[$restorejob['name']] = $restorejob['name'];
if(!empty($this->restorejobresources)) {
foreach($this->restorejobresources as $restorejob) {
$selectData[$restorejob['job']] = $restorejob['job'];
}
}
return $selectData;
}

/**
*
*/
private function getRestoreJobWhereDirectives()
{
$selectData = array();
if(!empty($this->restorejobresources)) {
foreach($this->restorejobresources as $restorejob) {
$selectData[$restorejob['where']] = $restorejob['where'];
}
}
return $selectData;
}

/**
*
*/
private function determineWhereDirective($restorejob=null)
{
$where = null;
if(isset($restorejob)) {
foreach($this->restorejobresources as $restorejobresource) {
if($restorejobresource['job'] == $restorejob) {
$where = $restorejobresource['where'];
}
}
}
return $where;
}

}
@@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2020 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
@@ -165,6 +165,30 @@ public function getFileVersions(&$bsock=null, $clientname=null, $pathid=null, $f
}
}

/**
* Get all configured restore job resources
*
* @param $bsock
* @param $restorejobs
*
* @return array
*/
public function getRestoreJobResources(&$bsock=null, $restorejobs=null)
{
if(isset($bsock) && isset($restorejobs)) {
$restorejobresources = array();
foreach($restorejobs as $restorejob) {
$cmd = '.defaults job="'.$restorejob['name'].'"';
$result = $bsock->send_command($cmd, 2);
$defaults = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
array_push($restorejobresources, $defaults['result']['defaults']);
}
return $restorejobresources;
} else {
throw new \Exception('Missing argument.');
}
}

/**
* Get JobIds via .bvfs_get_jodids
*
@@ -143,8 +143,8 @@ $this->headTitle($title);
echo '<p>'.$this->formRow($form->get('backups')).'</p>';
echo '<p>'.$this->formRow($form->get('mergefilesets')).'</p>';
echo '<p>'.$this->formRow($form->get('mergejobs')).'</p>';
echo '<p>'.$this->formRow($form->get('restoreclient')).'</p>';
echo '<p>'.$this->formRow($form->get('restorejob')).'</p>';
echo '<p>'.$this->formRow($form->get('restoreclient')).'</p>';
echo '<p>'.$this->formRow($form->get('replace')).'</p>';
echo '<p>'.$this->formRow($form->get('where')).'</p>';

@@ -433,6 +433,10 @@ $this->headTitle($title);
window.location.href = window.location.pathname + '?' + updateRestoreParams('client', this.value);
});

$('#restorejob').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('restorejob', this.value);
});

$('#mergefilesets').change(function(event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('mergefilesets', this.value);
});
@@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2020 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
@@ -141,8 +141,8 @@ $this->headTitle($title);
echo '<p>' . $this->formRow($form->get('backups')) . '</p>';
echo '<p>' . $this->formRow($form->get('mergefilesets')) . '</p>';
echo '<p>' . $this->formRow($form->get('mergejobs')) . '</p>';
echo '<p>' . $this->formRow($form->get('restoreclient')) . '</p>';
echo '<p>' . $this->formRow($form->get('restorejob')) . '</p>';
echo '<p>' . $this->formRow($form->get('restoreclient')) . '</p>';
echo '<p>' . $this->formRow($form->get('replace')) . '</p>';
echo '<p>' . $this->formRow($form->get('where')) . '</p>';

@@ -557,6 +557,10 @@ $('#client').change(function (event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('client', this.value);
});

$('#restorejob').change(function (event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('restorejob', this.value);
});

$('#mergefilesets').change(function (event) {
window.location.href = window.location.pathname + '?' + updateRestoreParams('mergefilesets', this.value);
});

0 comments on commit d3ba475

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