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