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