Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranco committed Jun 1, 2018
2 parents 8d84603 + 0a7b9d2 commit 65c7337
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 82 deletions.
2 changes: 1 addition & 1 deletion application/config/application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$app = [ 'name' => 'Bacula-Web', 'version' => '8.0.0-rc3',
$app = [ 'name' => 'Bacula-Web', 'version' => '8.0.0',
'routes' => [ 'home' => 'Dashboard',
'test' => 'Test',
'jobs' => 'Jobs',
Expand Down
14 changes: 6 additions & 8 deletions application/views/templates/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,12 @@
<div class="col-xs-12">
<ol class="breadcrumb">
{php}
$scriptname = explode( "/", $_SERVER['SCRIPT_FILENAME']);
$current = end( $scriptname );

if( $current === 'index.php' ) {
echo '<li class="active"> <i class="fa fa-home fa-fw"></i> Dashboard</li>';
}else{
echo '<li> <a href="index.php" title="{t}Back to Dashboard{/t}"><i class="fa fa-home fa-fw"></i> Dashboard</a> </li>';
}
if( isset($_GET['page'] ) ) {
echo '<li> <a href="index.php" title="' . _("Back to Dashboard") . '"><i class="fa fa-home fa-fw"></i> Dashboard</a> </li>';
echo '<li class="active">' . $this->name . '</li>';
}else {
echo '<li class="active"> <i class="fa fa-home fa-fw"></i> ' . $this->name . '</li>';
}
{/php}
</ol>
</div> <!-- div class="col..." -->
Expand Down
6 changes: 6 additions & 0 deletions application/views/test.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function prepare() {
array( 'check_cmd' => 'php-pdo',
'check_label' => 'PHP - PDO support',
'check_descr' => 'PHP PDO support is required, please compile PHP with this option'),
array( 'check_cmd' => 'php-posix',
'check_label' => 'PHP - Posix support',
'check_descr' => 'PHP Posix support is required, please compile PHP with this option'),
array( 'check_cmd' => 'db-connection',
'check_label' => 'Database connection status (MySQL and postgreSQL only)',
'check_descr' => 'Current status: ' . $catalog->getConnectionStatus() ),
Expand Down Expand Up @@ -100,6 +103,9 @@ public function prepare() {
case 'php-pdo':
$check['check_result'] = $icon_result[class_exists('PDO')];
break;
case 'php-posix':
$check['check_result'] = $icon_result[function_exists('posix_getpwuid')];
break;
case 'smarty-cache':
$check['check_result'] = $icon_result[is_writable(VIEW_CACHE_DIR)];
break;
Expand Down
48 changes: 25 additions & 23 deletions core/app/cerrorhandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,39 @@ public static function displayError($exception)
} // end switch

$output = '';
// Display Exception trace
$output .= self::getFormatedTrace($exception);

// Header
$output .= '<table>';
$output .= "<tr> <th colspan='2'>" . self::$header . "</th> \n </tr> \n";

// Exception details
$output .= "<tr> <td width='200'><b>File</b> </td> <td>" . $exception->getFile() . "</td> \n</tr> \n";
$output .= "<tr> <td><b>Line</b> </td> <td>" . $exception->getLine() . "</td> \n </tr> \n";
$output .= "<tr> <td><b>Exception code</b> </td> <td>" . $exception->getCode() . "</td> \n </tr> \n";
$output .= "<tr> <td><b>Exception message</b> </td> <td>" . $exception->getMessage() . "</td> \n </tr> \n";

$output .= "<tfoot> \n <tr> \n";
$output .= "<td colspan='2'> \n";

// Display PHP exception details
$output .= '<br />';
$output .= '<div class="panel panel-default">';
$output .= '<div class="panel-heading">';
$output .= '<h3 class="panel-title">';
$output .= '<i class="fa fa-exclamation-triangle fa-lg"></i> ';
$output .= self::$header . '</h3> </div>';
$output .= '<div class="panel-body">';
$output .= '<h4>Details</h4>';
$output .= '<p>A problem with the description below happen</p>';
$output .= '<b>Problem: </b>' . $exception->getMessage() . '<br />';
$output .= '<h4>Help</h4>';
$output .= "Have you tried to run the <a href='index.php?page=test'>test page</a> ?<br />";
$output .= "Check the online documentation on <a href='http://www.bacula-web.org' target='_blank'>Bacula-Web project site</a> <br />";
$output .= "Rebort a bug or suggest a new feature in the <a href='http://bugs.bacula-web.org' target='_blank'>Bacula-Web's bugtracking tool</a> <br />";
$output .= "</td> \n";
$output .= " \n</tr> \n </tfoot>";

$output .= "</table>";

$output .= '<h4>Debug</h4>';
$output .= '<b>File: </b>' . $exception->getFile() . '<br />';
$output .= '<b>Line: </b>' . $exception->getLine() . '<br />';
$output .= '<b>Code: </b>' . $exception->getCode() . '<br />';
$output .= '<h5>Exception trace</h5>';
$output .= self::getFormatedTrace($exception);
$output .= '</div> </div>';

// Render Exception page
$output = HtmlHelper::getHtmlHeader() . HtmlHelper::getNavBar() . '<div class="container">' . $output . '</div>' . HtmlHelper::getHtmlFooter();
echo $output;
//die();

} // end function displayError

public static function getFormatedTrace($e)
{
$formated_trace = '<table style="margin: 10px; width: 900px; border: 1px solid #c0c0c0;">';
$formated_trace .= '<tr> <th>Exception trace</th> </tr>';
$formated_trace = '<table class="table">';

foreach ($e->getTrace() as $exception) {
$formated_trace .= '<tr>';
Expand Down
30 changes: 24 additions & 6 deletions core/app/userauth.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@ class UserAuth extends CModel {

public function __construct() {

$this->cdb = new CDB();

$this->appDbBackend = 'application/assets/protected/application.db';
$this->dsn = "sqlite:$this->appDbBackend";

$this->db_link = $this->cdb->connect($this->dsn);
$this->cdb = new CDB();

// Throw an exception if PHP SQLite is not installed
$pdoDrivers = PDO::getAvailableDrivers();

if( ! in_array('sqlite', $pdoDrivers) ) {
throw new Exception('PHP SQLite support not found');
}

// Check protected assets folder permissions$
$webUser = '';
exec('whoami', $webUser);
$webUser = reset($webUser);

$assetsOwner = posix_getpwuid(fileowner('application/assets/protected'));

if($webUser != $assetsOwner['name']) {
throw new Exception('Bad ownership / permissions for protected assets folder (application/assets/protected)');
}

$this->appDbBackend = 'application/assets/protected/application.db';
$this->dsn = "sqlite:$this->appDbBackend";

$this->db_link = $this->cdb->connect($this->dsn);
}

public function checkSchema() {
Expand Down
3 changes: 1 addition & 2 deletions core/app/webapplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ public function run() {
$this->setup();
$this->init();
$this->view->prepare();
$this->view->render();
}catch( Exception $e) {
// Display application error here
CErrorHandler::displayError($e);
// Render the view
}finally {
$this->view->render();
}
}
}
43 changes: 19 additions & 24 deletions core/bweb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,34 @@ class Bweb extends WebApplication

public function init()
{
try {
// Loading configuration file parameters
if (!FileConfig::open(CONFIG_FILE)) {
throw new Exception("The configuration file is missing");
}else {
// Count defined Bacula catalogs
$this->catalog_nb = FileConfig::count_Catalogs();

// Loading configuration file parameters
if (!FileConfig::open(CONFIG_FILE)) {
throw new Exception("The configuration file is missing");
} else {
// Count defined Bacula catalogs
$this->catalog_nb = FileConfig::count_Catalogs();

// Check if datetime_format is defined in configuration
if( FileConfig::get_Value('datetime_format') != NULL) {
$this->datetime_format = FileConfig::get_Value('datetime_format');
$_SESSION['datetime_format'] = $this->datetime_format;
// Check if datetime_format is defined in configuration
if( FileConfig::get_Value('datetime_format') != NULL) {
$this->datetime_format = FileConfig::get_Value('datetime_format');
$_SESSION['datetime_format'] = $this->datetime_format;

// Get first part of datetime_format
$this->datetime_format_short = explode( ' ', $this->datetime_format);
$_SESSION['datetime_format_short'] = $this->datetime_format_short[0];
}else {
// Set default time format
$_SESSION['datetime_format'] = 'Y-m-d H:i:s';
$_SESSION['datetime_format_short'] = 'Y-m-d';
}
// Get first part of datetime_format
$this->datetime_format_short = explode( ' ', $this->datetime_format);
$_SESSION['datetime_format_short'] = $this->datetime_format_short[0];
}else {
// Set default time format
$_SESSION['datetime_format'] = 'Y-m-d H:i:s';
$_SESSION['datetime_format_short'] = 'Y-m-d';
}
} catch (Exception $e) {
CErrorHandler::displayError($e);
}

// Checking template cache permissions
// Checking template cache permissions
if (!is_writable(VIEW_CACHE_DIR)) {
throw new Exception("The template cache folder <b>" . VIEW_CACHE_DIR . "</b> must be writable by Apache user");
}

// Initialize smarty gettext function
// Initialize smarty gettext function
$language = FileConfig::get_Value('language');
if ($language == NULL) {
throw new Exception('<b>Config error:</b> $config[\'language\'] not set correctly, please check configuration file');
Expand Down
20 changes: 8 additions & 12 deletions core/db/cdb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@ public function __construct()

public function connect($dsn, $user = null, $password = null)
{
try {
$this->connection = new PDO($dsn, $user, $password);
$this->connection = new PDO($dsn, $user, $password);

// Set PDO connection options
$this->connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('CDBResult', array($this)));
// Set PDO connection options
$this->connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('CDBResult', array($this)));

// MySQL connection specific parameter
if ($this->getDriverName() == 'mysql') {
$this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
} catch (PDOException $e) {
CErrorHandler::displayError($e);
// MySQL connection specific parameter
if ($this->getDriverName() == 'mysql') {
$this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}

return $this->connection;
Expand Down
1 change: 0 additions & 1 deletion core/utils/datetimeutil.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class DateTimeUtil

public static function checkDate($date) {

//echo "<pre>date: $date</pre>";
$d = DateTime::createFromFormat('Y-m-d H:i:s', $date);

if($d != FALSE) {
Expand Down
103 changes: 103 additions & 0 deletions core/utils/htmlhelper.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright 2010-2018, Davide Franco |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| 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 General Public License for more details. |
+-------------------------------------------------------------------------+
*/

class HtmlHelper
{

/**
* Return html header
* @return string
*/

public static function getHtmlHeader() {

$htmlHeader = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bacula-Web - Application error</title>
<!-- Bootstrap front-end framework -->
<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap-theme.min.css">
<!-- Custom css -->
<link rel="stylesheet" href="application/assets/css/default.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="vendor/components/font-awesome/css/font-awesome.min.css">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>';

return $htmlHeader;
}

/**
* Return Bootstrap navbar
* @return string
*/

public static function getNavBar() {
$navbar = '<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">Bacula-Web</a>
</div> <!-- div class="navbar-header" -->
</div> <!-- div class="collapse navbar-collapse"-->
</div> <!-- div class="container-fluid" -->
</div> <!-- class="navbar" -->
';
return $navbar;
}

/**
* Return html footer
* @return string
*/

public static function getHtmlFooter() {

$htmlFooter = '<!-- JQuery and Bootstrap Javascript -->
<script src="vendor/components/jquery/jquery.min.js"></script>
<script src="vendor/moment/moment/min/moment-with-locales.js"></script>
<script src="vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="vendor/components/bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<script src="vendor/1000hz/bootstrap-validator/dist/validator.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="application/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>';

return $htmlFooter;
}
}

// end class
26 changes: 25 additions & 1 deletion docs/Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
=== Release 8.0.0 (June 1 2018)

Changelog

- General
- Breacrumbs navigation has been fixed
- Application error/exception look and feel have been improved
- PHP Posix support is now required
- Development
- Large amount of code improvement and cleanup
- Documentation
- Add user settings and general settings in features
- Documentation got cleaned up, restructured and updated

Fixed bugs

- 0000234 [bug-php] Directors report page problem if a Bacula catalog is unreachable
- 0000241 [bug-php] Breadcrumbs navigation is broken

Improvement(s)

- 0000161 [enhancement] Improve application errors/warnings exception message
- 0000222 [enhancement] Improve exception handling

=== Release 8.0.0-rc3 (Mar 17 2018)

Changelog
Expand Down Expand Up @@ -40,7 +64,7 @@ Changelog
- Fixed many SQL injection and XSS vulnerabilities (see fixed bugs)

- Development
- Large amount of code improvment and cleanup
- Large amount of code improvement and cleanup
- Upgrade moment/moment to version 2.19.2
- Add Bootstrap validator to Composer's requirements

Expand Down

0 comments on commit 65c7337

Please sign in to comment.