Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Issue #12 bconsole call
Browse files Browse the repository at this point in the history
bconsole call now configurable in config/autoload/local.php
  • Loading branch information
fbergkemper committed Aug 5, 2014
1 parent dc21b48 commit 3d8d354
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 114 deletions.
8 changes: 8 additions & 0 deletions config/autoload/local.php.dist
Expand Up @@ -52,5 +52,13 @@ return array(
'password' => '',

),
'bconsole' => array(
// Set full path to bconsole command
'exec_path' => '/usr/sbin/bconsole',
// Use sudo to execute bconsole command: true or false
'sudo' => 'true',
// Set full path to bconsole configuration file
'config_path' => '/etc/bareos/bconsole.conf',
),

);
43 changes: 6 additions & 37 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -4,13 +4,13 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BConsole\BConsoleConnector;

class ClientController extends AbstractActionController
{

protected $clientTable;
protected $jobTable;
protected $bconsoleOutput = array();

public function indexAction()
{
Expand All @@ -30,13 +30,15 @@ public function detailsAction()
}

$result = $this->getClientTable()->getClient($id);
$cmd = "status client=" . $result->name;

$cmd = 'status client="' . $result->name . '"';
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);

return new ViewModel(
array(
'client' => $this->getClientTable()->getClient($id),
'job' => $this->getJobTable()->getLastSuccessfulClientJob($id),
'bconsoleOutput' => $this->getBConsoleOutput($cmd),
'bconsoleOutput' => $bcon->getBConsoleOutput($cmd),
)
);

Expand All @@ -59,39 +61,6 @@ public function getJobTable()
}
return $this->jobTable;
}

public function getBConsoleOutput($cmd)
{

$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "r")
);

$cwd = '/usr/sbin';
$env = array('/usr/sbin');

$process = proc_open('sudo /usr/sbin/bconsole', $descriptorspec, $pipes, $cwd, $env);

if(!is_resource($process))
throw new \Exception("proc_open error");

if(is_resource($process))
{
fwrite($pipes[0], $cmd);
fclose($pipes[0]);
while(!feof($pipes[1])) {
array_push($this->bconsoleOutput, fread($pipes[1],8192));
}
fclose($pipes[1]);
}

$return_value = proc_close($process);

return $this->bconsoleOutput;

}

}

55 changes: 17 additions & 38 deletions module/Director/src/Director/Controller/DirectorController.php
Expand Up @@ -28,83 +28,62 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BConsole\BConsoleConnector;

class DirectorController extends AbstractActionController
{

protected $directorOutput = array();

public function indexAction()
{
$cmd = "status director";
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);
return new ViewModel(array(
'directorOutput' => $this->getBConsoleOutput($cmd),
'directorOutput' => $bcon->getBConsoleOutput($cmd),
));
}

public function messagesAction()
{
$cmd = "messages";
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);
return new ViewModel(array(
'directorOutput' => $this->getBConsoleOutput($cmd),
'directorOutput' => $bcon->getBConsoleOutput($cmd),
));
}

public function scheduleAction()
{
$cmd = "show schedule";
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);
return new ViewModel(array(
'directorOutput' => $this->getBConsoleOutput($cmd),
'directorOutput' => $bcon->getBConsoleOutput($cmd),
));
}

public function schedulerstatusAction()
{
$cmd = "status scheduler";
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);
return new ViewModel(array(
'directorOutput' => $this->getBConsoleOutput($cmd),
'directorOutput' => $bcon->getBConsoleOutput($cmd),
));
}

public function versionAction()
{
$cmd = "version";
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);
return new ViewModel(array(
'directorOutput' => $this->getBConsoleOutput($cmd),
'directorOutput' => $bcon->getBConsoleOutput($cmd),
));
}

public function getBConsoleOutput($cmd)
{

$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "r")
);

$cwd = '/usr/sbin';
$env = array('/usr/sbin');

$process = proc_open('sudo /usr/sbin/bconsole', $descriptorspec, $pipes, $cwd, $env);

if(!is_resource($process))
throw new \Exception("proc_open error");

if(is_resource($process))
{
fwrite($pipes[0], $cmd);
fclose($pipes[0]);
while(!feof($pipes[1])) {
array_push($this->directorOutput, fread($pipes[1],8192));
}
fclose($pipes[1]);
}

$return_value = proc_close($process);

return $this->directorOutput;

}

}

46 changes: 7 additions & 39 deletions module/Fileset/src/Fileset/Controller/FilesetController.php
Expand Up @@ -27,12 +27,12 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Bareos\BConsole\BConsoleConnector;

class FilesetController extends AbstractActionController
{

protected $filesetTable;
protected $bconsoleOutput = array();

public function indexAction()
{
Expand All @@ -46,7 +46,11 @@ public function indexAction()
public function detailsAction()
{
$id = (int) $this->params()->fromRoute('id', 0);

$fset = $this->getFilesetTable()->getFileSet($id);
$cmd = 'show fileset="' . $fset->fileset . '"';
$config = $this->getServiceLocator()->get('Config');
$bcon = new BConsoleConnector($config['bconsole']);

if (!$id) {
return $this->redirect()->toRoute('fileset');
}
Expand All @@ -55,7 +59,7 @@ public function detailsAction()
array(
'fileset' => $this->getFilesetTable()->getFileset($id),
'history' => $this->getFilesetTable()->getFilesetHistory($id),
'configuration' => $this->getFilesetConfig($id),
'configuration' => $bcon->getBConsoleOutput($cmd),
)
);
}
Expand All @@ -69,41 +73,5 @@ public function getFilesetTable()
return $this->filesetTable;
}

public function getFilesetConfig($id)
{

$fset = $this->getFilesetTable()->getFileSet($id);
$cmd = "show fileset=" . $fset->fileset;

$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "r")
);

$cwd = '/usr/sbin';
$env = array('/usr/sbin');

$process = proc_open('sudo /usr/sbin/bconsole', $descriptorspec, $pipes, $cwd, $env);

if(!is_resource($process)) {
throw new \Exception("proc_open error");
}

if(is_resource($process)) {
fwrite($pipes[0], $cmd);
fclose($pipes[0]);
while(!feof($pipes[1])) {
array_push($this->bconsoleOutput, fread($pipes[1], 8192));
}
fclose($pipes[1]);
}

$return_value = proc_close($process);

return $this->bconsoleOutput;

}

}

0 comments on commit 3d8d354

Please sign in to comment.