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

Commit

Permalink
Run jobs
Browse files Browse the repository at this point in the history
Displays current defined jobs of type backup from config and
allows to run them via one click action.
  • Loading branch information
fbergkemper committed Aug 21, 2015
1 parent cefcce4 commit c997134
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 1 deletion.
55 changes: 54 additions & 1 deletion module/Job/src/Job/Controller/JobController.php
Expand Up @@ -215,8 +215,61 @@ public function cancelAction()
}
}

public function runAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {
return new ViewModel(
array(
'jobs' => $this->getJobs()
)
);
}
else {
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}
}

public function queueAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {
if($this->params()->fromQuery('job')) {
$jobname = $this->params()->fromQuery('job');
}
else {
$jobname = null;
}

return new ViewModel(
array(
'result' => $this->queueJob($jobname)
)
);
}
else {
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}
}

private function getJobs()
{
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command(".jobs type=B", 2, null);
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $jobs['result']['jobs'];
}

private function queueJob($jobname=null)
{
$result = "";
if($jobname != null) {
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command('run job="'.$jobname.'" yes');
}
return $result;
}

public function getJobTable()
{
{
if(!$this->jobTable)
{
$sm = $this->getServiceLocator();
Expand Down
1 change: 1 addition & 0 deletions module/Job/view/job/job/index.phtml
Expand Up @@ -59,6 +59,7 @@ elseif($order_by == 'duration') {
<li><a href="<?php echo $this->url('job', array('action'=>'unsuccessful')); ?>"><?php echo $this->translate('Unsuccessful (past 24 hours)'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'successful')); ?>"><?php echo $this->translate('Successful (past 24 hours)'); ?></a></li>
<!-- <li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li> -->
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
</ul>

<br />
Expand Down
15 changes: 15 additions & 0 deletions module/Job/view/job/job/queue.phtml
@@ -0,0 +1,15 @@
<?php

$title = 'Job';
$this->headTitle($title);

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<pre style="font-size: 8pt;">
<code>
<?php echo $this->result; ?>
</code>
</pre>
69 changes: 69 additions & 0 deletions module/Job/view/job/job/run.phtml
@@ -0,0 +1,69 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

$title = 'Jobs';
$this->headTitle($title);

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<ul class="nav nav-tabs">
<li><a href="<?php echo $this->url('job', array('action'=>'index')); ?>"><?php echo $this->translate('History'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'running')); ?>"><?php echo $this->translate('Running'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'waiting')); ?>"><?php echo $this->translate('Waiting'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'unsuccessful')); ?>"><?php echo $this->translate('Unsuccessful (past 24 hours)'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'successful')); ?>"><?php echo $this->translate('Successful (past 24 hours)'); ?></a></li>
<!-- <li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li> -->
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
</ul>

<br />

<div class="row">
<div class="col-md-8">

<table class="table table-bordered table-condensed">

<tr>
<th class="bg-primary"><?php echo $this->translate("Name"); ?></th>
<th class="bg-primary"></th>
</tr>

<?php foreach ($this->jobs as $job) : ?>
<tr>
<td><?php echo $this->escapeHtml($job['name']); ?></td>
<td class="text-center">
<a href="<?php echo $this->url('job',array('action'=>'queue'),array('query' => array('job' => $job['name']))); ?>" class="btn btn-default btn-sm" role="button"><?php echo $this->translate('Run now'); ?></a></td>
</tr>
<?php endforeach; ?>

</table>


</div>
</div>
1 change: 1 addition & 0 deletions module/Job/view/job/job/running.phtml
Expand Up @@ -73,6 +73,7 @@ $flash->setMessageOpenFormat('
<li><a href="<?php echo $this->url('job', array('action'=>'unsuccessful')); ?>"><?php echo $this->translate('Unsuccessful (past 24 hours)'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'successful')); ?>"><?php echo $this->translate('Successful (past 24 hours)'); ?></a></li>
<!-- <li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li> -->
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
</ul>

<br />
Expand Down
1 change: 1 addition & 0 deletions module/Job/view/job/job/successful.phtml
Expand Up @@ -77,6 +77,7 @@ $flash->setMessageOpenFormat('
<li><a href="<?php echo $this->url('job', array('action'=>'unsuccessful')); ?>"><?php echo $this->translate('Unsuccessful (past 24 hours)'); ?></a></li>
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'successful')); ?>"><?php echo $this->translate('Successful (past 24 hours)'); ?></a></li>
<!-- <li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li> -->
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
</ul>

<br />
Expand Down
1 change: 1 addition & 0 deletions module/Job/view/job/job/unsuccessful.phtml
Expand Up @@ -74,6 +74,7 @@ $flash->setMessageOpenFormat('
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'unsuccessful')); ?>"><?php echo $this->translate('Unsuccessful (past 24 hours)'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'successful')); ?>"><?php echo $this->translate('Successful (past 24 hours)'); ?></a></li>
<!-- <li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li> -->
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
</ul>

<br />
Expand Down
1 change: 1 addition & 0 deletions module/Job/view/job/job/waiting.phtml
Expand Up @@ -69,6 +69,7 @@ $flash->setMessageOpenFormat('
<li><a href="<?php echo $this->url('job', array('action'=>'unsuccessful')); ?>"><?php echo $this->translate('Unsuccessful (past 24 hours)'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'successful')); ?>"><?php echo $this->translate('Successful (past 24 hours)'); ?></a></li>
<!-- <li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li> -->
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
</ul>

<br />
Expand Down

0 comments on commit c997134

Please sign in to comment.