]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
789675db32f2c199329ae8cf4db7d9a8b2adbca9
[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 // Last Err: 
18 session_start();
19 require ("paths.php");
20 require($smarty_path."Smarty.class.php");
21 include "classes.inc";
22
23 $smarty = new Smarty;                                                                                                                   // Template engine
24 $dbSql = new Bweb();
25
26 $smarty->compile_check = true;
27 $smarty->debugging = false;
28 $smarty->force_compile = true;
29
30 $smarty->template_dir = "./templates";
31 $smarty->compile_dir = "./templates_c";
32 $smarty->config_dir     = "./configs";
33 $smarty->config_load("bacula.conf");                                                                                    // Load config file
34 $mode = $smarty->get_config_vars("mode");                                                                               // Lite o Extend?
35
36 require("lang.php");
37
38 //Assign dbs
39 if ( count($dbSql->dbs) >1 ) {
40   $smarty->assign("dbs", $dbSql->dbs);
41   $smarty->assign("dbs_now", $_SESSION['DATABASE']);
42 }
43
44 // generaldata.tpl & last_run_report.tpl (last24bytes)
45 $client = $dbSql->link->query("select count(*) from Client")
46         or die ("Error query: 1");
47 $totalfiles = $dbSql->link->query("select count(FilenameId) from Filename")
48         or die ("Error query: 2");
49 if ( $dbSql->driver == "mysql")
50   $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400")
51         or die ("Error query: 3");
52 if ( $dbSql->driver == "pgsql")
53   $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'")
54         or die ("Error query: 3");
55 $bytes_stored =& $dbSql->link->getOne("select SUM(VolBytes) from Media")
56         or die ("Error query: 4");
57
58 // Database size
59 $smarty->assign('database_size', $dbSql->GetDbSize());
60
61 // Total bytes stored
62 $smarty->assign('bytes_stored', $dbSql->human_file_size($bytes_stored) );
63
64 // Number of clients
65 $tmp = $client->fetchRow();
66 $smarty->assign('clientes_totales',$tmp[0]);
67
68 $tmp = $last24bytes->fetchRow();
69 /*if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
70         if ( $dbSql->driver == "mysql" )
71           $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
72         if ( $dbSql->driver == "pgsql")
73           $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800 * interval '1 second'" )
74             or die ("Error query: 4.1");
75         $smarty->assign('when',"yesterday");
76         $tmp = $last24bytes->fetchRow();        
77 }*/
78
79 // Transfered bytes since last 24 hours
80 $smarty->assign('bytes_totales', $dbSql->human_file_size( $tmp[0] ) );
81
82 $smarty->assign('total_jobs', $tmp[1]);
83
84 $tmp = $totalfiles->fetchRow();
85 $smarty->assign('files_totales',$tmp[0]);
86
87 $client->free();
88 $totalfiles->free();
89 $last24bytes->free();
90
91 // report_select.tpl & last_run_report.tpl
92 $res = $dbSql->link->query("select Name from Job group by Name");
93 $a_jobs = array();
94 while ( $tmp = $res->fetchRow() )
95         array_push($a_jobs, $tmp[0]);
96 $smarty->assign('total_name_jobs',$a_jobs);
97 $smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
98 $res->free();
99
100 // Get volumes list (volumes.tpl)
101 $smarty->assign('pools',$dbSql->GetVolumeList() );
102
103 // last_run_report.tpl
104 if ($mode == "Lite" && $_GET['Full_popup'] != "yes") {
105         $tmp = array();
106         if ( $dbSql->driver == "mysql" )
107           $status = $dbSql->link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'" )               
108                 or die ("Error: query at row 95");
109         if ( $dbSql->driver == "pgsql" )
110           $status = $dbSql->link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'")
111                 or die ( "Error: query at row 98" );
112         $smarty->assign('status', $status->numRows());
113         if ( $status->numRows() ) {
114                 while ( $res = $status->fetchRow() )
115                         array_push($tmp, $res);
116                 $smarty->assign('errors_array',$tmp);
117         }
118         $status->free();
119         
120         // Total Elapsed Time. Only for single Job.
121         if ( $dbSql->driver == "mysql" )
122           $ret = $dbSql->link->query("select UNIX_TIMESTAMP(EndTime)-UNIX_TIMESTAMP(StartTime) as elapsed from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-84600")
123                 or die ("Error at row 110");
124         if ( $dbSql->driver == "pgsql" )
125           $ret = $dbSql->link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
126                 or die ("Error at row 113");
127         while ( $res = $ret->fetchRow() ) {
128                 if ( $TotalElapsed < 1000000000 )                                                                               // Temporal "workaround" ;) Fix later
129                         $TotalElapsed += $res[0];
130         }
131         if ($TotalElapsed > 86400)                                                                                                      // More than 1 day!
132                 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
133         else
134                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
135         $smarty->assign('TotalElapsed',$TotalElapsed);
136         $ret->free();
137 }
138 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
139         $tmp1 = array();
140         if ( $dbSql->driver == "mysql")
141                 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
142                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job 
143                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 
144                                 order by elapsed ";                                                                                                     // Full report array
145         if ( $dbSql->driver == "pgsql")
146                 $query = "select (Job.EndTime - Job.StartTime )
147                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
148                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
149                                 order by elapsed ";
150         $status = $dbSql->link->query($query)
151                 or die ("Error: query at row 138");
152         while ( $tmp = $status->fetchRow() ) {
153                 $tdate = explode (":",$tmp[0]);
154                 if ( $tdate[0] > 300000 )                                                                                               // Temporal "workaround" ;) Fix later
155                         $tmp[0] = "00:00:00";
156                 array_push($tmp1,$tmp);
157         }
158         
159         $smarty->assign('clients',$tmp1);
160 }  
161
162
163 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
164         $smarty->display('full_popup.tpl');
165 else
166         $smarty->display('index.tpl');
167 ?>