| 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 {
var $dbs;
var $dbs_name;
+ public $tpl;
public $db_link; // Database link
private $db_dsn; // Data Source Name
// 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) . "<br />";
-
- /*
- $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"];
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 );
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<br />" . $jobs->getMessage() );
+
return $this->human_file_size( $database_size );
} // end function GetDbSize()
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";
$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
break;
} // end switch
- //$this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
$medias = $this->db_link->query( $query );
if( PEAR::isError( $medias ) ) {
}
// Media used bytes in a human format
$media['volbytes'] = $this->human_file_size( $media['volbytes'] );
- //echo "volume " . $media['volumename'] . 'vol bytes' .$media['volbytes'] . '<br />';
} 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);
}
return $volumes;
} // end function GetVolumeList()
+ public function CountJobsbyLevel( $delay = LAST_DAY, $level = 'F' )
+ {
+ $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 = "SELECT COUNT(JobId) as jobs FROM Job ";
+ $query .= "WHERE (EndTime BETWEEN '$start_date' AND '$end_date') AND ";
+ $query .= "Level = '$level' ";
+
+ $result = $this->db_link->query( $query );
+
+ if (PEAR::isError( $result ) ) {
+ die( "Unable to get number of jobs with $level status from catalog <br />" . $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 ";
$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 'terminated_errors':
$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 . '<br />';
+
$jobs = $this->db_link->query( $query );
if (PEAR::isError( $jobs ) ) {
}
}
- 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 <br />" . $result->getMessage() );
}
- return $nbfiles;
+
+ return $totalfiles;
}
public function GetStoredBytes( $delay = LAST_DAY )
$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 );
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 .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' ) AND ";
$query .= "Name = '$jobname'";
- echo 'query ' . $query . '<br />';
-
$result = $this->db_link->query( $query );
if( PEAR::isError( $result ) ) {
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
?>