]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bacula-web/index.php
bacula-web: Replaced Get_human_file_size() function by Utils::Get_Human_Size
[bacula/bacula] / gui / bacula-web / index.php
index 78c527309aebfacff064f0ec2c7ed063f0f9c492..b459a08a4c768ebf195b3999b6a2e7001b0eb452 100644 (file)
@@ -1,7 +1,8 @@
-<?
+<?php
 /* 
 +-------------------------------------------------------------------------+
-| Copyright (C) 2004 Juan Luis Francés Jiménez                            |
+| Copyright (C) 2004 Juan Luis Francés Jiménez                                                   |
+| Copyright 2010-2011, Davide Franco                                             |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+ 
 */
-// Last Err: 
-require ("paths.php");
-require($smarty_path."Smarty.class.php");
-include "classes.inc";
+session_start();
+include_once( 'config.inc.php' );
 
-$smarty = new Smarty;                                                                                                                   // Template engine
 $dbSql = new Bweb();
 
-//$smarty->compile_check = true;
-//$smarty->debugging = true;
-$smarty->template_dir = "./templates";
-$smarty->compile_dir = "./templates_c";
-$smarty->config_dir     = "./configs";
-$smarty->config_load("bacula.conf");                                                                                    // Load config file
-$mode = $smarty->get_config_vars("mode");                                                                               // Lite o Extend?
-
-require("lang.php");
-
-
-// generaldata.tpl & last_run_report.tpl (last24bytes)
-$client = $dbSql->link->query("select count(*) from Client")
-        or die ("Error query: 1");
-$totalfiles = $dbSql->link->query("select count(FilenameId) from Filename")
-        or die ("Error query: 2");
-if ( $dbSql->driver == "mysql")
-  $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400")
-        or die ("Error query: 3");
-if ( $dbSql->driver == "pgsql")
-  $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'")
-        or die ("Error query: 3");
-$bytes_stored =& $dbSql->link->getOne("select SUM(VolBytes) from Media")
-        or die ("Error query: 4");
-
-$smarty->assign('database_size', $dbSql->GetDbSize()*1000000);
-$smarty->assign('bytes_stored',$bytes_stored);
-
-$tmp = $client->fetchRow();
-$smarty->assign('clientes_totales',$tmp[0]);
-
-$tmp = $last24bytes->fetchRow();
-if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
-        if ( $dbSql->driver == "mysql" )
-          $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
-        if ( $dbSql->driver == "pgsql")
-          $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800" );
-        $smarty->assign('when',"yesterday");
+// Assign to template catalogs number
+//$dbSql->tpl->assign( "dbs", $dbSql->bwcfg->Count_Catalogs() );
+// Assign dbs
+/*
+if ( count($dbSql->dbs) >1 ) {
+  $smarty->assign("dbs", $dbSql->dbs);
+  $smarty->assign("dbs_now", $_SESSION['DATABASE']);
 }
-$smarty->assign('bytes_totales',$tmp[0]);
-$smarty->assign('total_jobs', $tmp[1]);
-
-$tmp = $totalfiles->fetchRow();
-$smarty->assign('files_totales',$tmp[0]);
-
-$client->free();
-$totalfiles->free();
-$last24bytes->free();
-
-
-// report_select.tpl & last_run_report.tpl
-$res = $dbSql->link->query("select Name from Job group by Name");
-$a_jobs = array();
-while ( $tmp = $res->fetchRow() )
-        array_push($a_jobs, $tmp[0]);
-$smarty->assign('total_name_jobs',$a_jobs);
-$smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
-$res->free();
-
-// volumes.tpl
-$volumes = $dbSql->GetDataVolumes();                                                                                    // Obtain array with info
-$pools = array_keys($volumes);                                                                                                  // Extract Pools
-$smarty->assign('pools',$pools);        
-$smarty->assign('volumes',$volumes);
-
-// last_run_report.tpl
-if ($mode == "Lite" && $_GET['Full_popup'] != "yes") {
-        $tmp = array();
-        if ( $dbSql->driver == "mysql" )
-          $status = $dbSql->link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'" )               
-                or die ("Error: query at row 95");
-        if ( $dbSql->driver == "pgsql" )
-          $status = $dbSql->link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'")
-                or die ( "Error: query at row 98" );
-        $smarty->assign('status', $status->numRows());
-        if ( $status->numRows() ) {
-                while ( $res = $status->fetchRow() )
-                        array_push($tmp, $res);
-                $smarty->assign('errors_array',$tmp);
-        }
-        $status->free();
-        
-        // Total Elapsed Time. Only for single Job.
-        if ( $dbSql->driver == "mysql" )
-          $ret = $dbSql->link->query("select UNIX_TIMESTAMP(EndTime)-UNIX_TIMESTAMP(StartTime) as elapsed from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-84600")
-                or die ("Error at row 110");
-        if ( $dbSql->driver == "pgsql" )
-          $ret = $dbSql->link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
-                or die ("Error at row 113");
-        while ( $res = $ret->fetchRow() ) {
-                if ( $TotalElapsed < 1000000000 )                                                                               // Temporal "workaround" ;) Fix later
-                        $TotalElapsed += $res[0];
-        }
-        if ($TotalElapsed > 86400)                                                                                                      // More than 1 day!
-                $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
-        else
-                $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
-        $smarty->assign('TotalElapsed',$TotalElapsed);
-        $ret->free();
+*/
+// Catalog count
+$catalog_nb = $dbSql->catalog_nb;
+$dbSql->tpl->assign( 'catalog_nb', $catalog_nb );
+
+// Stored files number 
+$totalfiles = $dbSql->GetStoredFiles( ALL );
+$dbSql->tpl->assign('stored_files',$totalfiles);
+  
+// Database size
+$dbSql->tpl->assign('database_size', $dbSql->GetDbSize());
+
+// Overall stored bytes
+$result = $dbSql->GetStoredBytes( ALL );
+$dbSql->tpl->assign('stored_bytes', Utils::Get_Human_Size( $result['stored_bytes'] ) );
+
+// Total stored bytes since last 24 hours
+$result = $dbSql->GetStoredBytes( LAST_DAY );
+$dbSql->tpl->assign('bytes_last', Utils::Get_Human_Size( $result['stored_bytes'] ) );
+
+// Total stored files since last 24 hours
+$files_last = $dbSql->GetStoredFiles( LAST_DAY );
+$dbSql->tpl->assign('files_last', $files_last );
+
+
+// Number of clients
+$nb_clients = $dbSql->Get_Nb_Clients();
+$dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] );
+
+// Backup Job list for report.tpl and last_run_report.tpl
+$dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
+
+// Get volumes list (volumes.tpl)
+$dbSql->tpl->assign('pools', $dbSql->GetVolumeList() );
+
+// Last 24 hours completed jobs number
+$dbSql->tpl->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) );
+
+// Last 24 hours failed jobs number
+$dbSql->tpl->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) );
+
+// Last 24 hours waiting jobs number
+$dbSql->tpl->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) );
+
+// Last 24 hours elapsed time (last_run_report.tpl)
+//$smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
+
+// Last 24 hours Job Levels
+$dbSql->tpl->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') );
+$dbSql->tpl->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') );
+$dbSql->tpl->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') );
+
+// Last 24 hours Job status graph
+$data   = array();  
+$status = array( 'completed', 'terminated_errors', 'failed', 'waiting', 'created', 'running', 'error' );
+
+foreach( $status as $job_status ) {
+       array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
 }
-else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
-        $tmp1 = array();
-        if ( $dbSql->driver == "mysql")
-                $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
-                                as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job 
-                                LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 
-                                order by elapsed ";                                                                                                     // Full report array
-        if ( $dbSql->driver == "pgsql")
-                $query = "select Job.EndTime - Job.StartTime )
-                                as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
-                                LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
-                                order by elapsed ";
-        $status = $dbSql->link->query($query)
-                or die ("Error: query at row 138");
-        while ( $tmp = $status->fetchRow() ) {
-                $tdate = explode (":",$tmp[0]);
-                if ( $tdate[0] > 300000 )                                                                                               // Temporal "workaround" ;) Fix later
-                        $tmp[0] = "00:00:00";
-                array_push($tmp1,$tmp);
-        }
-        
-        $smarty->assign('clients',$tmp1);
-}  
-
-
-if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
-        $smarty->display('full_popup.tpl');
-else
-        $smarty->display('index.tpl');
+
+$graph = new BGraph( "graph.png" );
+$graph->SetData( $data, 'pie', 'text-data-single' );
+$graph->SetGraphSize( 400, 230 );
+
+$graph->Render();
+$dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() );
+unset($graph);
+
+// Pool and volumes graph
+$data = array();
+$graph = new BGraph( "graph1.png" );
+
+$pools = $dbSql->Get_Pools_List();
+
+foreach( $pools as $pool ) {
+       array_push( $data, $dbSql->CountVolumesByPool( $pool ) );
+}
+
+$graph->SetData( $data, 'pie', 'text-data-single' );
+$graph->SetGraphSize( 400, 230 );
+
+$graph->Render();
+$dbSql->tpl->assign('graph_pools', $graph->Get_Image_file() );
+
+// Last 7 days stored Bytes graph
+$data  = array();
+$graph = new BGraph( "graph2.png" );
+$days  = array();
+
+// Get the last 7 days interval (start and end)
+for( $c = 6 ; $c >= 0 ; $c-- ) {
+       $today = ( mktime() - ($c * LAST_DAY) );
+       array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
+}
+
+$days_stored_bytes = array();
+
+foreach( $days as $day ) {
+  array_push( $days_stored_bytes, $dbSql->GetStoredBytesByInterval( $day['start'], $day['end'] ) );
+}
+
+$graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
+$graph->SetGraphSize( 400, 230 );
+
+$graph->Render();
+$dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );
+
+// Last 15 used volumes
+$vol_list = array();
+
+$query  = "SELECT DISTINCT Media.Volumename, Media.Lastwritten, Media.VolStatus, Job.JobId FROM Job ";
+$query .= "LEFT JOIN JobMedia ON Job.JobId = JobMedia.JobId ";
+$query .= "LEFT JOIN Media ON JobMedia.MediaId = Media.MediaId ";
+$query .= "ORDER BY Job.JobId DESC ";
+$query .= "LIMIT 10 ";
+
+$result = $dbSql->db_link->query( $query );
+
+if ( PEAR::isError( $result ) )
+       die( "Unable to get last used volumes from catalog \n " . $result->getMessage() );
+else {
+       while ( $vol = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) 
+               array_push( $vol_list, $vol );
+}
+$dbSql->tpl->assign( 'volume_list', $vol_list );       
+
+//if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
+//        $smarty->display('full_popup.tpl');
+//else
+
+// Render template
+$dbSql->tpl->display('index.tpl');
 ?>