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