]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Changed variable name for backup job list
[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 // Stored files number 
74 $totalfiles = $dbSql->GetStoredFiles( ALL );
75 $smarty->assign('stored_files',$totalfiles);
76   
77 // Database size
78 $smarty->assign('database_size', $dbSql->GetDbSize());
79
80 // Overall stored bytes
81 $result = $dbSql->GetStoredBytes( ALL );
82 $smarty->assign('stored_bytes', $dbSql->human_file_size($result['stored_bytes']) );
83
84 // Total stored bytes since last 24 hours
85 $result = $dbSql->GetStoredBytes( LAST_DAY );
86 $smarty->assign('bytes_last', $dbSql->human_file_size($result['stored_bytes']) );
87
88 // Total stored files since last 24 hours
89 $files_last = $dbSql->GetStoredFiles( LAST_DAY );
90 $smarty->assign('files_last', $files_last );
91
92
93 // Number of clients
94 $nb_clients = $dbSql->Get_Nb_Clients();
95 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
96
97 // Backup Job list for report.tpl and last_run_report.tpl
98 $smarty->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
99
100 // Get volumes list (volumes.tpl)
101 $smarty->assign('pools', $dbSql->GetVolumeList() );
102
103 // Last 24 hours completed jobs number
104 $smarty->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) );
105
106 // Last 24 hours failed jobs number
107 $smarty->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) );
108
109 // Last 24 hours waiting jobs number
110 $smarty->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) );
111
112 // Last 24 hours elapsed time (last_run_report.tpl)
113 //$smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
114
115 // Last 24 hours Job Levels
116 $smarty->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') );
117 $smarty->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') );
118 $smarty->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') );
119
120 // Last 24 hours Job status graph
121 $data   = array();  
122 $status = array( 'completed', 'terminated_errors', 'failed', 'waiting', 'created', 'running', 'error' );
123
124 foreach( $status as $job_status ) {
125         array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
126 }
127
128 $graph = new BGraph( "graph.png" );
129 $graph->SetData( $data, 'pie', 'text-data-single' );
130 $graph->SetGraphSize( 400, 230 );
131
132 $graph->Render();
133 $smarty->assign('graph_jobs', $graph->Get_Image_file() );
134 unset($graph);
135
136 // Pool and volumes graph
137 $data = array();
138 $graph = new BGraph( "graph1.png" );
139
140 $pools = $dbSql->Get_Pools_List();
141
142 foreach( $pools as $pool ) {
143         array_push( $data, $dbSql->GetPoolsStatistics( $pool ) );
144 }
145
146 $graph->SetData( $data, 'pie', 'text-data-single' );
147 $graph->SetGraphSize( 400, 230 );
148
149 $graph->Render();
150 $smarty->assign('graph_pools', $graph->Get_Image_file() );
151
152 // Last 7 days stored Bytes graph
153 $data  = array();
154 $graph = new BGraph( "graph2.png" );
155 $days  = array();
156
157 // Get the last 7 days interval (start and end)
158 for( $c = 6 ; $c >= 0 ; $c-- ) {
159         $today = ( mktime() - ($c * LAST_DAY) );
160         array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
161 }
162
163 $days_stored_bytes = array();
164
165 foreach( $days as $day ) {
166   array_push( $days_stored_bytes, $dbSql->GetStoredBytesByInterval( $day['start'], $day['end'] ) );
167 }
168
169 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
170 $graph->SetGraphSize( 400, 230 );
171
172 $graph->Render();
173 $smarty->assign('graph_stored_bytes', $graph->Get_Image_file() );
174
175 // Last 15 used volumes
176 $vol_list = array();
177
178 $query  = "SELECT DISTINCT Media.Volumename, Media.Lastwritten, Media.VolStatus, Job.JobId FROM Job ";
179 $query .= "LEFT JOIN JobMedia ON Job.JobId = JobMedia.JobId ";
180 $query .= "LEFT JOIN Media ON JobMedia.MediaId = Media.MediaId ";
181 $query .= "ORDER BY Job.JobId DESC ";
182 $query .= "LIMIT 10 ";
183
184 $result = $dbSql->db_link->query( $query );
185
186 if ( PEAR::isError( $result ) )
187         die( "Unable to get last used volumes from catalog \n " . $result->getMessage() );
188 else {
189         while ( $vol = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) 
190                 array_push( $vol_list, $vol );
191 }
192 $smarty->assign( 'volume_list', $vol_list );    
193
194 //if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
195 //        $smarty->display('full_popup.tpl');
196 //else
197
198 // Render template
199 $smarty->display('index.tpl');
200 ?>