]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Improved stored bytes graph and modified dashboard design
[bacula/bacula] / gui / bacula-web / index.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004 Juan Luis Francés Jiménez                            |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17 session_start();
18 require ("paths.php");
19 require($smarty_path."Smarty.class.php");
20 include "bweb.inc.php";
21
22 $smarty = new Smarty();     
23 $dbSql = new Bweb();
24
25 require("lang.php");
26
27 $mode = "";                             
28
29 $smarty->compile_check = true;
30 $smarty->debugging = false;
31 $smarty->force_compile = true;
32
33 $smarty->template_dir = "./templates";
34 $smarty->compile_dir = "./templates_c";
35 $smarty->config_dir     = "./configs";
36
37 /*
38 $smarty->config_load("bacula.conf");                                                                                    // Load config file
39 $mode = $smarty->get_config_vars("mode");     
40 */                                                                          // Lite o Extend?
41
42 // Getting mode from config file
43 $mode = $dbSql->get_config_param("mode");
44 if( $mode == false )
45         $mode = "Lite";
46
47 $smarty->assign( "mode", $mode );
48
49 // Determine which template to show
50 $indexreport = $dbSql->get_config_param( "IndexReport" );
51
52 if( $indexreport == 0 ) {
53         $smarty->assign( "last_report", "last_run_report.tpl" );
54 }else {
55         $smarty->assign( "last_report", "report_select.tpl" );
56 }
57
58 // Assign to template catalogs number
59 $smarty->assign( "dbs", $dbSql->Get_Nb_Catalogs() );
60
61 //Assign dbs
62 /*
63 if ( count($dbSql->dbs) >1 ) {
64   $smarty->assign("dbs", $dbSql->dbs);
65   $smarty->assign("dbs_now", $_SESSION['DATABASE']);
66 }
67 */
68
69 // generaldata.tpl & last_run_report.tpl ( Last 24 hours report )
70 $last24bytes = "";
71 $query = "";
72
73 /*$client = $dbSql->db_link->query("select count(*) from Client")
74         or die ("Error query: 1");*/
75   $totalfiles = $dbSql->db_link->query("select count(FilenameId) from Filename") or die ("Error query: 2");
76   
77   if ( PEAR::isError( $totalfiles ) ) {
78           die( "Unable to get Total Files information from catalog" . $totalfiles->getMessage() );
79   }else {
80         $tmp = $totalfiles->fetchRow();
81         $smarty->assign('files_totales',$tmp[0]);
82   }
83   $totalfiles->free();
84   
85   /*
86   switch( $dbSql->driver )
87   {
88         case 'mysql':
89                 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400";
90         break;
91         case 'pgsql':
92                 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'";
93         break;
94         default:
95                 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400";
96         break;
97   }
98   
99   $last24bytes = $dbSql->db_link->query( $query ) or die ("Failed to get Total Job Bytes from catalog");
100         
101   if ( PEAR::isError( $last24bytes ) ) {
102         die( "Unable to get Total Job Bytes from catalog" . $last24bytes->getMessage() );
103   }else {
104         $tmp = $last24bytes->fetchRow();
105         //var_dump( $tmp );
106         // Transfered bytes since last 24 hours
107         $smarty->assign('bytes_totales', $dbSql->human_file_size( $tmp[0] ) );
108
109         $smarty->assign('total_jobs', $tmp[1]);
110
111         $last24bytes->free();           
112   }*/
113                 
114 // Database size
115 $smarty->assign('database_size', $dbSql->GetDbSize());
116
117 // Overall stored bytes
118 $result = $dbSql->GetStoredBytes( ALL );
119 $smarty->assign('stored_bytes', $dbSql->human_file_size($result['stored_bytes']) );
120
121 // Total stored bytes since last 24 hours
122 $result = $dbSql->GetStoredBytes( LAST_DAY );
123 $smarty->assign('bytes_totales', $dbSql->human_file_size($result['stored_bytes']) );
124
125 // Number of clients
126 $nb_clients = $dbSql->Get_Nb_Clients();
127 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
128
129 // Backup Job list for report.tpl and last_run_report.tpl
130 $smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() );
131
132 // Get volumes list (volumes.tpl)
133 $smarty->assign('pools', $dbSql->GetVolumeList() );
134
135 // Last 24 hours completed jobs number (last_run_report.tpl)
136 $completed_jobs = $dbSql->GetLastJobs();
137 $smarty->assign( 'completed_jobs', $completed_jobs['completed_jobs'] );
138
139 // Last 24 hours failed jobs number (last_run_report.tpl)
140 $failed_jobs = $dbSql->GetLastErrorJobs();
141 $smarty->assign( 'failed_jobs', $failed_jobs['failed_jobs'] );
142
143 // Last 24 hours elapsed time (last_run_report.tpl)
144 $smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
145
146 // last_run_report.tpl
147 if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
148 /*
149         // Total Elapsed Time. Only for single Job.
150         if ( $dbSql->driver == "mysql" )
151           $ret = $dbSql->db_link->query("select UNIX_TIMESTAMP(EndTime)-UNIX_TIMESTAMP(StartTime) as elapsed from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-84600")
152                 or die ("Error at row 110");
153         if ( $dbSql->driver == "pgsql" )
154           $ret = $dbSql->db_link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
155                 or die ("Error at row 113");
156         while ( $res = $ret->fetchRow() ) {
157                 if ( $TotalElapsed < 1000000000 )                                                                               // Temporal "workaround" ;) Fix later
158                         $TotalElapsed += $res[0];
159         }
160         if ($TotalElapsed > 86400)                                                                                                      // More than 1 day!
161                 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
162         else
163                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
164         $smarty->assign('TotalElapsed',$TotalElapsed);
165         $ret->free();
166 */              
167                 
168 }
169 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
170 /*
171         $tmp1 = array();
172         if ( $dbSql->driver == "mysql")
173                 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
174                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job 
175                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 
176                                 order by elapsed ";                                                                                                     // Full report array
177         if ( $dbSql->driver == "pgsql")
178                 $query = "select (Job.EndTime - Job.StartTime )
179                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
180                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
181                                 order by elapsed ";
182         $status = $dbSql->db_link->query($query)
183                 or die ("Error: query at row 138");
184         while ( $tmp = $status->fetchRow() ) {
185                 $tdate = explode (":",$tmp[0]);
186                 if ( $tdate[0] > 300000 )                                                                                               // Temporal "workaround" ;) Fix later
187                         $tmp[0] = "00:00:00";
188                 array_push($tmp1,$tmp);
189         }
190         
191         $smarty->assign('clients',$tmp1);
192 */
193 }
194
195 // Last 24 hours Job status graph
196 $data   = array();  
197 $status = array( 'completed', 'completed_errors', 'failed', 'waiting', 'created', 'running', 'error' );
198
199 foreach( $status as $job_status ) {
200         array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
201 }
202
203 $graph = new BGraph( "graph.png" );
204 $graph->SetData( $data, 'pie', 'text-data-single' );
205 //$graph->SetTitle("Overall jobs status");
206 $graph->SetGraphSize( 400, 230 );
207 //$graph->SetColors( array('green', 'yellow','red','blue','white','green','red') );
208
209 $graph->Render();
210 $smarty->assign('graph_jobs', $graph->Get_Image_file() );
211 unset($graph);
212
213 // Pool and volumes graph
214 $data = array();
215 $graph = new BGraph( "graph1.png" );
216
217 $pools = $dbSql->Get_Pools_List();
218
219 foreach( $pools as $pool ) {
220         array_push( $data, $dbSql->GetPoolsStatistics( $pool ) );
221 }
222
223 $graph->SetData( $data, 'pie', 'text-data-single' );
224 $graph->SetGraphSize( 400, 230 );
225
226 $graph->Render();
227 $smarty->assign('graph_pools', $graph->Get_Image_file() );
228
229 // Last 7 days stored Bytes graph
230 $data  = array();
231 $graph = new BGraph( "graph2.png" );
232 $days  = array();
233
234 // Get the last 7 days interval (start and end)
235 for( $c = 6 ; $c >= 0 ; $c-- ) {
236         $today = ( mktime() - ($c * 86400) );
237         array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
238 }
239
240 $days_stored_bytes = array();
241
242 foreach( $days as $day ) {
243   array_push( $days_stored_bytes, $dbSql->GetStoredBytesByInterval( $day['start'], $day['end'] ) );
244 }
245
246 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
247 $graph->SetGraphSize( 400, 230 );
248
249 $graph->Render();
250 $smarty->assign('graph_stored_bytes', $graph->Get_Image_file() );
251
252 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
253         $smarty->display('full_popup.tpl');
254 else
255         $smarty->display('index.tpl');
256 ?>