]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Changed filename for classes.inc to classes.inc.php
[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 "classes.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   switch( $dbSql->driver )
86   {
87         case 'mysql':
88                 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400";
89         break;
90         case 'pgsql':
91                 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'";
92         break;
93         default:
94                 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400";
95         break;
96   }
97   
98   $last24bytes = $dbSql->db_link->query( $query ) or die ("Failed to get Total Job Bytes from catalog");
99         
100   if ( PEAR::isError( $last24bytes ) ) {
101         die( "Unable to get Total Job Bytes from catalog" . $last24bytes->getMessage() );
102   }else {
103         $tmp = $last24bytes->fetchRow();
104         var_dump( $tmp );
105         // Transfered bytes since last 24 hours
106         $smarty->assign('bytes_totales', $dbSql->human_file_size( $tmp[0] ) );
107
108         $smarty->assign('total_jobs', $tmp[1]);
109
110         $last24bytes->free();           
111   }
112                 
113 // Database size
114 $smarty->assign('database_size', $dbSql->GetDbSize());
115
116 // Total bytes stored
117 $bytes_stored = $dbSql->db_link->getOne("select SUM(VolBytes) from Media") or die ("Failed to get Total stored Bytes from catalog");
118 $smarty->assign('bytes_stored', $dbSql->human_file_size($bytes_stored) );
119
120 // Number of clients
121 $nb_clients = $dbSql->Get_Nb_Clients();
122 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
123
124 /*if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
125         if ( $dbSql->driver == "mysql" )
126           $last24bytes = $dbSql->db_link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
127         if ( $dbSql->driver == "pgsql")
128           $last24bytes = $dbSql->db_link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800 * interval '1 second'" )
129             or die ("Error query: 4.1");
130         $smarty->assign('when',"yesterday");
131         $tmp = $last24bytes->fetchRow();        
132 }*/
133
134 // report_select.tpl & last_run_report.tpl
135 $res = $dbSql->db_link->query("select Name from Job group by Name");
136
137 $a_jobs = array();
138 while ( $tmp = $res->fetchRow() )
139         array_push($a_jobs, $tmp[0]);
140 $smarty->assign('total_name_jobs',$a_jobs);
141 $smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
142 $res->free();
143
144 // Get volumes list (volumes.tpl)
145 $smarty->assign('pools',$dbSql->GetVolumeList() );
146
147 // last_run_report.tpl
148 if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
149         $tmp = array();
150         switch( $dbSql->driver )
151                 {
152                         case 'mysql':
153                                 $query  = "SELECT JobId, Name, EndTime, JobStatus";
154                                 $query .= "FROM Job ";
155                                 $query .= "WHERE EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'";
156                         break;
157                         case 'pgsql':
158                                 $query  = "SELECT JobId, Name, EndTime, JobStatus ";
159                                 $query .= "FROM Job ";
160                                 $query .= "WHERE EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'";
161                         break;
162                 }
163                 
164                 $status = $dbSql->db_link->query( $query );
165                 
166                 if (PEAR::isError( $status ) )
167                         die( "Unable to get last job status from catalog<br />" . $status->getMessage() );
168                 
169                 /*
170                 if ( $dbSql->driver == "mysql" )
171           $status = $dbSql->db_link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'" )               
172                 or die ("Error: query at row 95");
173         if ( $dbSql->driver == "pgsql" )
174           $status = $dbSql->db_link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'")
175                 or die ( "Error: query at row 98" );
176         */
177                 $smarty->assign('status', $status->numRows() );
178         if ( $status->numRows() ) {
179                 while ( $res = $status->fetchRow() )
180                         array_push($tmp, $res);
181                 $smarty->assign('errors_array',$tmp);
182         }
183         $status->free();
184         
185         // Total Elapsed Time. Only for single Job.
186         if ( $dbSql->driver == "mysql" )
187           $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")
188                 or die ("Error at row 110");
189         if ( $dbSql->driver == "pgsql" )
190           $ret = $dbSql->db_link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
191                 or die ("Error at row 113");
192         while ( $res = $ret->fetchRow() ) {
193                 if ( $TotalElapsed < 1000000000 )                                                                               // Temporal "workaround" ;) Fix later
194                         $TotalElapsed += $res[0];
195         }
196         if ($TotalElapsed > 86400)                                                                                                      // More than 1 day!
197                 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
198         else
199                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
200         $smarty->assign('TotalElapsed',$TotalElapsed);
201         $ret->free();
202 }
203 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
204         $tmp1 = array();
205         if ( $dbSql->driver == "mysql")
206                 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
207                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job 
208                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 
209                                 order by elapsed ";                                                                                                     // Full report array
210         if ( $dbSql->driver == "pgsql")
211                 $query = "select (Job.EndTime - Job.StartTime )
212                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
213                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
214                                 order by elapsed ";
215         $status = $dbSql->db_link->query($query)
216                 or die ("Error: query at row 138");
217         while ( $tmp = $status->fetchRow() ) {
218                 $tdate = explode (":",$tmp[0]);
219                 if ( $tdate[0] > 300000 )                                                                                               // Temporal "workaround" ;) Fix later
220                         $tmp[0] = "00:00:00";
221                 array_push($tmp1,$tmp);
222         }
223         
224         $smarty->assign('clients',$tmp1);
225 }  
226
227
228 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
229         $smarty->display('full_popup.tpl');
230 else
231         $smarty->display('index.tpl');
232 ?>