X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=gui%2Fbacula-web%2Fbweb.inc.php;h=d57090bedbe6fea1c0f5e2461c143127b4c2bb47;hb=42dd3beecf66880bb879affbcefe369ba108b89c;hp=3b5fc635c57629c55367b9499d01c97a2f59dbfd;hpb=3b7d8e1fc0c80fe995d089bb801e56a0d1ec87e9;p=bacula%2Fbacula
diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php
index 3b5fc635c5..d57090bedb 100644
--- a/gui/bacula-web/bweb.inc.php
+++ b/gui/bacula-web/bweb.inc.php
@@ -14,15 +14,7 @@
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
*/
-require_once "paths.php";
-require_once "DB.php"; // Pear DB
require_once "config.inc.php";
-require_once "bgraph.inc.php";
-require_once($smarty_path."Config_File.class.php");
-
-if (!function_exists('array_fill')) { // For PHP < 4.2.0 users
- require_once('array_fill.func.php');
-}
class Bweb extends DB {
@@ -32,6 +24,7 @@ class Bweb extends DB {
var $dbs;
var $dbs_name;
+ public $tpl;
public $db_link; // Database link
private $db_dsn; // Data Source Name
@@ -45,50 +38,10 @@ class Bweb extends DB {
// Loading configuration
$this->config_file = getcwd() . '/configs/bacula.conf';
+
if( !$this->load_config() )
die( "Unable to load configuration");
- //echo "Number of catalog defined " . count($this->catalogs) . "
";
-
- /*
- $conf = new Config_File (CONFIG_DIR);
- $this->dbs = array();
-
- $i = 2;
- $sections = $conf->get(CONFIG_FILE,"DATABASE","host");
- array_push($this->dbs, "DATABASE");
-
- while ( !empty($sections) ) {
- $sections = $conf->get(CONFIG_FILE,"DATABASE".$i,"host");
- if ( !empty($sections) )
- array_push($this->dbs,"DATABASE".$i);
- $i++;
- }
-
- if ( $i < 4)
- $sec = "DATABASE";
- else {
- if ( !empty($_POST['sel_database']) ) {
- $_SESSION['DATABASE'] = $_POST['sel_database'];
- $sec = $_POST['sel_database'];
- } else {
- if (isset($_SESSION['DATABASE']) )
- $sec = $_SESSION['DATABASE'];
- else
- $sec = "DATABASE";
- }
- }
-
- $this->dsn['hostspec'] = $conf->get(CONFIG_FILE,$sec,"host");
- $this->dsn['username'] = $conf->get(CONFIG_FILE,$sec,"login");
- $this->dsn['password'] = $conf->get(CONFIG_FILE,$sec,"pass");
- $this->dsn['database'] = $conf->get(CONFIG_FILE,$sec,"db_name");
- $this->dsn['phptype'] = $conf->get(CONFIG_FILE,$sec,"db_type"); // mysql, pgsql
-
- if ( $conf->get(CONFIG_FILE,$sec,"db_port") )
- $this->dsn[port] = $conf->get(CONFIG_FILE,$sec,"db_port");
- */
-
// Construct a valid dsn
$this->db_dsn['hostspec'] = $this->catalogs[0]["host"];
$this->db_dsn['username'] = $this->catalogs[0]["login"];
@@ -106,9 +59,51 @@ class Bweb extends DB {
register_shutdown_function(array(&$this,'close'));
$this->dbs_name = $this->db_dsn['database'];
}
+
+ // Initialize smarty template classe
+ $this->init_tpl();
+ // Initialize smarty gettext function
+ $this->init_gettext();
}
- function load_config()
+ // Initialize Smarty template classe
+ function init_tpl()
+ {
+ $this->tpl = new Smarty();
+
+ $this->tpl->compile_check = true;
+ $this->tpl->debugging = false;
+ $this->tpl->force_compile = true;
+
+ $this->tpl->template_dir = "./templates";
+ $this->tpl->compile_dir = "./templates_c";
+ $this->tpl->config_dir = "./configs";
+ }
+
+ function init_gettext()
+ {
+ global $smarty_gettext_path;
+
+ if ( function_exists("gettext") ) {
+ require_once( BW_SMARTY_GETTEXT . "smarty_gettext.php" );
+ $this->tpl->register_block('t','smarty_translate');
+
+ $language = $this->get_config_param("lang");
+ $domain = "messages";
+ putenv("LANG=$language");
+ setlocale(LC_ALL, $language);
+ bindtextdomain($domain,"./locale");
+ textdomain($domain);
+ }
+ else {
+ function smarty_translate($params, $text, &$smarty) {
+ return $text;
+ }
+ $smarty->register_block('t','smarty_translate');
+ }
+ }
+
+ function load_config()
{
$this->config = parse_ini_file( $this->config_file, true );
@@ -211,33 +206,35 @@ class Bweb extends DB {
function GetDbSize()
{
- $database_size = 0;
- if ( $this->driver == "mysql") {
- $dbsize = $this->db_link->query("show table status") or die ("classes.inc: Error query: 3");
-
- if ( $dbsize->numRows() ) {
- while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
- $database_size += $res["Data_length"];
- } else {
- return 0;
- } // end if else
- } // end if
- else if ( $this->driver == "pgsql") {
- $dbsize = $this->db_link->query("select pg_database_size('$this->dbs_name')") or die ("classes.inc: Error query: 4");
-
- if (PEAR::isError($dbsize))
- die($dbsize->getMessage());
-
- if ( $dbsize->numRows() ) {
- while ( $res = $dbsize->fetchRow() )
- $database_size += $res[0];
- } else {
- return 0;
- }
- } // end if
-
- $dbsize->free();
-
+ $database_size = 0;
+ $query = "";
+
+ switch( $this->driver )
+ {
+ case 'mysql':
+ $query = "SELECT table_schema AS 'database', sum( data_length + index_length) AS 'dbsize' ";
+ $query .= "FROM information_schema.TABLES ";
+ $query .= "WHERE table_schema = 'bacula' ";
+ $query .= "GROUP BY table_schema";
+ break;
+ case 'pgsql':
+ $query = "SELECT pg_database_size('bacula') AS dbsize";
+ break;
+ case 'sqlite':
+ // Not yet implemented
+ return "0 MB";
+ break;
+ }
+
+ $result = $this->db_link->query( $query );
+
+ if(! PEAR::isError( $result ) )
+ {
+ $db = $result->fetchRow( DB_FETCHMODE_ASSOC );
+ $database_size =+ $db['dbsize'];
+ }else
+ die( "Unable to get database size
" . $jobs->getMessage() );
+
return $this->human_file_size( $database_size );
} // end function GetDbSize()
@@ -270,11 +267,6 @@ class Bweb extends DB {
switch( $this->driver )
{
case 'mysql':
-/*
- $query = "SELECT Media.VolumeName, Media.VolBytes, Media.VolStatus, Pool.Name, Media.MediaType,Media.LastWritten, FROM_UNIXTIME(UNIX_TIMESTAMP(Media.LastWritten)+Media.VolRetention ) AS expire
- FROM Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId WHERE poolid='$pool[0]'
- ORDER BY Media.VolumeName";
-*/
$query = "SELECT Media.volumename, Media.volbytes, Media.volstatus, Media.mediatype, Media.lastwritten, Media.volretention
FROM Media LEFT JOIN Pool ON Media.poolid = Pool.poolid
WHERE Media.poolid = '". $pool['poolid'] . "' ORDER BY Media.volumename";
@@ -283,11 +275,6 @@ class Bweb extends DB {
$query = "SELECT media.volumename, media.volbytes, media.volstatus, media.mediatype, media.lastwritten, media.volretention
FROM media LEFT JOIN pool ON media.poolid = pool.poolid
WHERE media.poolid = '". $pool['poolid'] . "' ORDER BY media.volumename";
- /*
- $query = "SELECT Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten, Media.LastWritten + Media.VolRetention * interval '1 second' AS expire
- FROM Pool LEFT JOIN Media ON media.poolid=pool.poolid WHERE poolid='$pool[0]'
- ORDER BY Media.VolumeName";
- */
break;
case 'sqlite':
$query = ""; // not yet implemented
@@ -296,7 +283,6 @@ class Bweb extends DB {
break;
} // end switch
- //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
$medias = $this->db_link->query( $query );
if( PEAR::isError( $medias ) ) {
@@ -327,12 +313,16 @@ class Bweb extends DB {
}
// Media used bytes in a human format
$media['volbytes'] = $this->human_file_size( $media['volbytes'] );
- //echo "volume " . $media['volumename'] . 'vol bytes' .$media['volbytes'] . '
';
} else {
$media['lastwritten'] = "N/A";
$media['expire'] = "N/A";
$media['volbytes'] = "0 KB";
}
+
+ // Odd or even row
+ if( count( $volumes[ $pool['name'] ] ) % 2)
+ $media['class'] = 'odd';
+
// Add the media in pool array
array_push( $volumes[ $pool['name']], $media);
}
@@ -342,36 +332,78 @@ class Bweb extends DB {
return $volumes;
} // end function GetVolumeList()
- public function CountJobs( $delay = LAST_DAY, $status )
+ public function CountJobsbyLevel( $delay = LAST_DAY, $level = 'F' )
{
- $query = "SELECT COUNT(JobId) AS job_nb FROM Job ";
-
- // Interval condition for SQL query
$end_date = mktime();
$start_date = $end_date - $delay;
$start_date = date( "Y-m-d H:i:s", $start_date );
$end_date = date( "Y-m-d H:i:s", $end_date );
- $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+ $query = "SELECT COUNT(JobId) as jobs FROM Job ";
+ $query .= "WHERE (EndTime BETWEEN '$start_date' AND '$end_date') AND ";
+ $query .= "Level = '$level' ";
- // Job Status for SQL query
- switch( $status )
- {
- case 'completed':
- $query .= "AND JobStatus = 'T' ";
- break;
- case 'failed':
- $query .= "AND JobStatus = 'f' ";
- break;
- } // end switch
+ $result = $this->db_link->query( $query );
+
+ if (PEAR::isError( $result ) ) {
+ die( "Unable to get number of jobs with $level status from catalog
" . $result->getMessage() );
+ }else {
+ $jobs = $result->fetchRow( DB_FETCHMODE_ASSOC );
+ return $jobs['jobs'];
+ }
+
+ }
+
+ public function CountJobs( $delay = LAST_DAY, $status = 'any' )
+ {
+ $query = "SELECT COUNT(JobId) AS job_nb FROM Job ";
+ $where_delay = "";
+ $where_status = "";
+ // Interval condition for SQL query
+ if( $delay != ALL ) {
+ $end_date = mktime();
+ $start_date = $end_date - $delay;
+
+ $start_date = date( "Y-m-d H:i:s", $start_date );
+ $end_date = date( "Y-m-d H:i:s", $end_date );
+
+ $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+ }
+
+ if( $status != 'any' ) {
+ switch( $status )
+ {
+ case 'completed':
+ $where_status = "JobStatus = 'T' ";
+ break;
+ case 'failed':
+ $where_status = "JobStatus IN ('f','E') ";
+ break;
+ case 'canceled':
+ $where_status = "JobStatus = 'A' ";
+ break;
+ case 'waiting':
+ $where_status = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
+ break;
+ } // end switch
+ }
+
+ if( !empty($where_delay) )
+ $query = $query . $where_delay . 'AND ' . $where_status;
+ else {
+ if( !empty($where_status) )
+ $query = $query . 'WHERE ' . $where_status;
+ }
+
$jobs = $this->db_link->query( $query );
if (PEAR::isError( $jobs ) ) {
- die( "Unable to get last $status jobs number from catalog
" . $status->getMessage() );
+ die( "Unable to get last $status jobs number from catalog
" . $jobs->getMessage() );
}else {
- return $jobs->fetchRow( DB_FETCHMODE_ASSOC );
+ $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC );
+ return $jobs['job_nb'];
}
}
@@ -412,6 +444,27 @@ class Bweb extends DB {
}
}
+ // Return elasped time string for a job
+ function Get_ElapsedTime( $start_time, $end_time )
+ {
+ $diff = $end_time - $start_time;
+
+ $daysDiff = sprintf("%02d", floor($diff/60/60/24) );
+ $diff -= $daysDiff*60*60*24;
+
+ $hrsDiff = sprintf("%02d", floor($diff/60/60) );
+ $diff -= $hrsDiff*60*60;
+
+ $minsDiff = sprintf("%02d", floor($diff/60) );
+ $diff -= $minsDiff*60;
+ $secsDiff = sprintf("%02d", $diff );
+
+ if( $daysDiff > 0 )
+ return $daysDiff . 'day(s) ' . $hrsDiff.':' . $minsDiff . ':' . $secsDiff;
+ else
+ return $hrsDiff . ':' . $minsDiff . ':' . $secsDiff;
+ }
+
public function Get_ElapsedTime_Job( $delay = LAST_DAY )
{
$query = "";
@@ -441,7 +494,7 @@ class Bweb extends DB {
$total_elapsed += $time['elapsed'];
}
// Verify if elapsed time is more than 1 day
- if ( $total_elapsed > 86400 ) {
+ if ( $total_elapsed > LAST_DAY ) {
return date("%d days H:i:s", $total_elapsed );
}else {
return date("H:i:s", $total_elapsed );
@@ -469,44 +522,47 @@ class Bweb extends DB {
$start_date = date( "Y-m-d H:i:s", $start_date );
$end_date = date( "Y-m-d H:i:s", $end_date );
+ $interval_where = "(EndTime BETWEEN '$start_date' AND '$end_date') AND ";
+
// Job status
switch( $type )
{
case 'completed':
- $where = "AND JobStatus = 'T' ";
+ $where = $interval_where . "JobStatus = 'T' ";
$label = "Completed";
break;
- case 'completed_errors':
- $where = "AND JobStatus = 'E' ";
- $label = "Completed with errors";
+ case 'terminated_errors':
+ $where = $interval_where . "JobStatus = 'E' ";
+ $label = "Terminated with errors";
break;
case 'failed':
- $where = "AND JobStatus = 'f' ";
+ $where = $interval_where . "JobStatus = 'f' ";
$label = "Failed";
break;
case 'waiting':
- $where = "AND JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
+ $where = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
$label = "Waiting";
break;
case 'created':
- $where = "AND JobStatus = 'C' ";
+ $where = "JobStatus = 'C' ";
$label = "Created but not running";
break;
case 'running':
- $where = "AND JobStatus = 'R' ";
+ $where = "JobStatus = 'R' ";
$label = "Running";
break;
case 'error':
- $where = "AND JobStatus IN ('e','f') ";
+ $where = $interval_where . "JobStatus IN ('e','f') ";
$label = "Errors";
break;
}
$query = 'SELECT COUNT(JobId) AS ' . $type . ' ';
$query .= 'FROM Job ';
- $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
- $query .= $where;
+ $query .= "WHERE $where ";
+ //echo 'query = ' . $query . '
';
+
$jobs = $this->db_link->query( $query );
if (PEAR::isError( $jobs ) ) {
@@ -535,19 +591,32 @@ class Bweb extends DB {
}
}
- public function GetStoredFiles()
+ public function GetStoredFiles( $delay = LAST_DAY )
{
- $nbfiles = 0;
- $query = "SELECT COUNT(FilenameId) AS nbfiles FROM Filename";
+ $totalfiles = 0;
+
+ $query = "SELECT SUM(JobFiles) AS stored_files FROM Job ";
+
+ // Interval calculation
+ $end_date = mktime();
+ $start_date = $end_date - $delay;
+
+ $start_date = date( "Y-m-d H:i:s", $start_date );
+ $end_date = date( "Y-m-d H:i:s", $end_date );
+
+ if( $delay != ALL )
+ $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
+
$result = $this->db_link->query( $query );
if( !PEAR::isError($result) ) {
- $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
- $nbfiles = $nbfiles['nbfiles'];
+ $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
+ $totalfiles = $totalfiles + $nbfiles['stored_files'];
}else{
- die("Unable to get protected files from catalog");
+ die("Unable to get protected files from catalog
" . $result->getMessage() );
}
- return $nbfiles;
+
+ return $totalfiles;
}
public function GetStoredBytes( $delay = LAST_DAY )
@@ -561,9 +630,8 @@ class Bweb extends DB {
$start_date = date( "Y-m-d H:i:s", $start_date );
$end_date = date( "Y-m-d H:i:s", $end_date );
- if( $delay != ALL ) {
+ if( $delay != ALL )
$query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
- }
$result = $this->db_link->query( $query );
@@ -597,5 +665,52 @@ class Bweb extends DB {
return array( $day, $stored_bytes );
}
}
+
+ public function GetStoredBytesByJob( $jobname, $start_date, $end_date )
+ {
+ $query = "SELECT SUM(JobBytes) as stored_bytes, EndTime FROM Job ";
+ $query .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' ) AND ";
+ $query .= "Name = '$jobname'";
+
+ $result = $this->db_link->query( $query );
+
+ if( PEAR::isError( $result ) ) {
+ die( "Unable to get Job Bytes from catalog" );
+ }else{
+ $stored_bytes = 0;
+ $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
+
+ $day = date( "D d", strtotime($end_date) );
+
+ if( isset( $tmp['stored_bytes'] ) ) {
+ $hbytes = $this->human_file_size( $tmp['stored_bytes'], 3, 'GB');
+ $hbytes = explode( " ", $hbytes );
+ $stored_bytes = $hbytes[0];
+ }
+
+ return array( $day, $stored_bytes );
+ }
+ }
+
+ public function GetStoredFilesByJob( $jobname, $start_date, $end_date )
+ {
+ $query = "SELECT SUM(JobFiles) as stored_files, EndTime FROM Job ";
+ $query .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' ) AND ";
+ $query .= "Name = '$jobname'";
+
+ $result = $this->db_link->query( $query );
+
+ if( PEAR::isError( $result ) ) {
+ die( "Unable to get Job Files from catalog" );
+ }else{
+ $stored_bytes = 0;
+ $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
+
+ $day = date( "D d", strtotime($end_date) );
+ $stored_files = $tmp['stored_files'];
+
+ return array( $day, $stored_files );
+ }
+ }
} // end class Bweb
?>