]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Fixed php bugs in Bweb class
[bacula/bacula] / gui / bacula-web / index.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004 Juan Luis Francés Jiménez                                                    |
5 | Copyright 2010-2011, Davide Franco                                              |
6 |                                                                         |
7 | This program is free software; you can redistribute it and/or           |
8 | modify it under the terms of the GNU General Public License             |
9 | as published by the Free Software Foundation; either version 2          |
10 | of the License, or (at your option) any later version.                  |
11 |                                                                         |
12 | This program is distributed in the hope that it will be useful,         |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
15 | GNU General Public License for more details.                            |
16 +-------------------------------------------------------------------------+ 
17 */
18 session_start();
19 include_once( 'config.inc.php' );
20
21 $dbSql = new Bweb();
22
23 // How many catalog configured
24 $dbSql->tpl->assign( 'catalog_nb', $dbSql->catalog_nb );
25
26 // Stored files number 
27 $dbSql->tpl->assign('stored_files', $dbSql->GetStoredFiles( ALL ) );
28   
29 // Database size
30 $dbSql->tpl->assign('database_size', $dbSql->GetDbSize());
31
32 // Overall stored bytes
33 $result = $dbSql->GetStoredBytes( ALL );
34 $dbSql->tpl->assign('stored_bytes', CUtils::Get_Human_Size( $result['stored_bytes'] ) );
35
36 // Total stored bytes since last 24 hours
37 $result = $dbSql->GetStoredBytes( LAST_DAY );
38 $dbSql->tpl->assign('bytes_last', CUtils::Get_Human_Size( $result['stored_bytes'] ) );
39
40 // Total stored files since last 24 hours
41 $files_last = $dbSql->GetStoredFiles( LAST_DAY );
42 $dbSql->tpl->assign('files_last', $files_last );
43
44
45 // Number of clients
46 $nb_clients = $dbSql->Get_Nb_Clients();
47 $dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] );
48
49 // Backup Job list for report.tpl and last_run_report.tpl
50 $dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
51
52 // Get volumes list (volumes.tpl)
53 $dbSql->tpl->assign('pools', $dbSql->GetVolumeList() );
54
55 // Last 24 hours completed jobs number
56 $dbSql->tpl->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) );
57
58 // Last 24 hours failed jobs number
59 $dbSql->tpl->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) );
60
61 // Last 24 hours waiting jobs number
62 $dbSql->tpl->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) );
63
64 // Last 24 hours Job Levels
65 $dbSql->tpl->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') );
66 $dbSql->tpl->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') );
67 $dbSql->tpl->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') );
68
69 // Last 24 hours Job status graph
70 $data   = array();  
71 $status = array( 'completed', 'terminated_errors', 'failed', 'waiting', 'created', 'running', 'error' );
72
73 foreach( $status as $job_status ) {
74         array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
75 }
76
77 $graph = new BGraph( "graph.png" );
78 $graph->SetData( $data, 'pie', 'text-data-single' );
79 $graph->SetGraphSize( 400, 230 );
80
81 $graph->Render();
82 $dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() );
83 unset($graph);
84
85 // Pool and volumes graph
86 $data = array();
87 $graph = new BGraph( "graph1.png" );
88
89 $pools = $dbSql->Get_Pools_List();
90
91 foreach( $pools as $pool ) {
92         array_push( $data, $dbSql->CountVolumesByPool( $pool ) );
93 }
94
95 $graph->SetData( $data, 'pie', 'text-data-single' );
96 $graph->SetGraphSize( 400, 230 );
97
98 $graph->Render();
99 $dbSql->tpl->assign('graph_pools', $graph->Get_Image_file() );
100
101 // Last 7 days stored Bytes graph
102 $data  = array();
103 $graph = new BGraph( "graph2.png" );
104 $days  = array();
105
106 // Get the last 7 days interval (start and end)
107 for( $c = 6 ; $c >= 0 ; $c-- ) {
108         $today = ( mktime() - ($c * LAST_DAY) );
109         array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
110 }
111
112 $days_stored_bytes = array();
113
114 foreach( $days as $day ) {
115   array_push( $days_stored_bytes, $dbSql->GetStoredBytesByInterval( $day['start'], $day['end'] ) );
116 }
117
118 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
119 $graph->SetGraphSize( 400, 230 );
120 $graph->SetYTitle( "GB" );
121
122 $graph->Render();
123 $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );
124
125 // Last 15 used volumes
126 $vol_list = array();
127
128 $query  = "SELECT DISTINCT Media.Volumename, Media.Lastwritten, Media.VolStatus, Job.JobId FROM Job ";
129 $query .= "LEFT JOIN JobMedia ON Job.JobId = JobMedia.JobId ";
130 $query .= "LEFT JOIN Media ON JobMedia.MediaId = Media.MediaId ";
131 $query .= "ORDER BY Job.JobId DESC ";
132 $query .= "LIMIT 10 ";
133
134 $result = $dbSql->db_link->query( $query );
135
136 if ( PEAR::isError( $result ) )
137         die( "Unable to get last used volumes from catalog \n " . $result->getMessage() );
138 else {
139         while ( $vol = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) 
140                 array_push( $vol_list, $vol );
141 }
142 $dbSql->tpl->assign( 'volume_list', $vol_list );        
143
144 // Render template
145 $dbSql->tpl->display('index.tpl');
146 ?>