Subversion Repositories ALCASAR

Rev

Rev 1533 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1533 Rev 1675
Line 15... Line 15...
15
    // You should have received a copy of the GNU General Public License
15
    // You should have received a copy of the GNU General Public License
16
    // along with this program; if not, write to the Free Software
16
    // along with this program; if not, write to the Free Software
17
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
    //
18
    //
19
    //
19
    //
20
    // see file COPYING or at http://www.gnu.org/licenses/gpl.html 
20
    // see file COPYING or at http://www.gnu.org/licenses/gpl.html
21
    // for more information.
21
    // for more information.
22
    //
22
    //
23
    require 'config.php';
23
    require 'config.php';
24
    require 'localize.php';
24
    require 'localize.php';
25
    require 'vnstat.php';
25
    require 'vnstat.php';
Line 29... Line 29...
29
    require "./themes/$style/theme.php";
29
    require "./themes/$style/theme.php";
30
 
30
 
31
    function write_side_bar()
31
    function write_side_bar()
32
    {
32
    {
33
        global $iface, $page, $graph, $script, $style;
33
        global $iface, $page, $graph, $script, $style;
34
        global $iface_list, $iface_title;   
34
        global $iface_list, $iface_title;
35
        global $page_list, $page_title;
35
        global $page_list, $page_title;
36
        
36
 
37
        $p = "&graph=$graph&style=$style";
37
        $p = "&graph=$graph&style=$style";
38
 
38
 
39
        print "<ul class=\"iface\">\n";
39
        print "<ul class=\"iface\">\n";
40
        foreach ($iface_list as $if)
40
        foreach ($iface_list as $if)
41
        {
41
        {
-
 
42
            if ($iface == $if) {
-
 
43
                print "<li class=\"iface active\">";
-
 
44
            } else {
42
            print "<li class=\"iface\">";
45
                print "<li class=\"iface\">";
-
 
46
            }
-
 
47
            print "<a href=\"$script?if=$if$p\">";
43
            if (isset($iface_title[$if]))
48
            if (isset($iface_title[$if]))
44
            {
49
            {
45
                print $iface_title[$if];
50
                print $iface_title[$if];
46
            }
51
            }
47
            else
52
            else
48
            {
53
            {
49
                print $if;
54
                print $if;
50
            }
55
            }
-
 
56
            print "</a>";
51
            print "<ul class=\"page\">\n";
57
            print "<ul class=\"page\">\n";
52
            foreach ($page_list as $pg)
58
            foreach ($page_list as $pg)
53
            {
59
            {
54
                print "<li class=\"page\"><a href=\"$script?if=$if$p&amp;page=$pg\">".$page_title[$pg]."</a></li>\n";
60
                print "<li class=\"page\"><a href=\"$script?if=$if$p&amp;page=$pg\">".$page_title[$pg]."</a></li>\n";
55
            }
61
            }
56
            print "</ul></li>\n";
62
            print "</ul></li>\n";
57
	    
-
 
58
        }
63
        }
59
        print "</ul>\n"; 
64
        print "</ul>\n";
60
    }
65
    }
61
    
66
 
62
 
67
 
63
    function kbytes_to_string($kb)
68
    function kbytes_to_string($kb)
64
    {
69
    {
-
 
70
 
-
 
71
        global $byte_notation;
-
 
72
 
65
        $units = array('TB','GB','MB','KB');
73
        $units = array('TB','GB','MB','KB');
66
        $scale = 1024*1024*1024;
74
        $scale = 1024*1024*1024;
67
        $ui = 0;
75
        $ui = 0;
68
 
76
 
-
 
77
        $custom_size = isset($byte_notation) && in_array($byte_notation, $units);
-
 
78
 
69
        while (($kb < $scale) && ($scale > 1))
79
        while ((($kb < $scale) && ($scale > 1)) || $custom_size)
70
        {
80
        {
71
            $ui++;
81
            $ui++;
72
            $scale = $scale / 1024;
82
            $scale = $scale / 1024;
-
 
83
 
-
 
84
            if ($custom_size && $units[$ui] == $byte_notation) {
-
 
85
                break;
73
        }   
86
            }
-
 
87
        }
-
 
88
 
74
        return sprintf("%0.2f %s", ($kb/$scale),$units[$ui]);
89
        return sprintf("%0.2f %s", ($kb/$scale),$units[$ui]);
75
    }
90
    }
76
    
91
 
77
    function write_summary()
92
    function write_summary()
78
    {
93
    {
79
        global $summary,$top,$day,$hour,$month;
94
        global $summary,$top,$day,$hour,$month;
80
 
95
 
81
        $trx = $summary['totalrx']*1024+$summary['totalrxk'];
96
        $trx = $summary['totalrx']*1024+$summary['totalrxk'];
82
        $ttx = $summary['totaltx']*1024+$summary['totaltxk'];
97
        $ttx = $summary['totaltx']*1024+$summary['totaltxk'];
83
 
98
 
84
        //
99
        //
85
        // build array for write_data_table
100
        // build array for write_data_table
86
        //
101
        //
-
 
102
 
-
 
103
        $sum = array();
-
 
104
 
-
 
105
        if (count($day) > 0 && count($hour) > 0 && count($month) > 0) {
87
        $sum[0]['act'] = 1;
106
            $sum[0]['act'] = 1;
88
        $sum[0]['label'] = T('This hour');
107
            $sum[0]['label'] = T('This hour');
89
        $sum[0]['rx'] = $hour[0]['rx'];
108
            $sum[0]['rx'] = $hour[0]['rx'];
90
        $sum[0]['tx'] = $hour[0]['tx'];
109
            $sum[0]['tx'] = $hour[0]['tx'];
91
 
110
 
92
        $sum[1]['act'] = 1;
111
            $sum[1]['act'] = 1;
93
        $sum[1]['label'] = T('This day');
112
            $sum[1]['label'] = T('This day');
94
        $sum[1]['rx'] = $day[0]['rx'];
113
            $sum[1]['rx'] = $day[0]['rx'];
95
        $sum[1]['tx'] = $day[0]['tx'];
114
            $sum[1]['tx'] = $day[0]['tx'];
96
 
115
 
97
        $sum[2]['act'] = 1;
116
            $sum[2]['act'] = 1;
98
        $sum[2]['label'] = T('This month');
117
            $sum[2]['label'] = T('This month');
99
        $sum[2]['rx'] = $month[0]['rx'];
118
            $sum[2]['rx'] = $month[0]['rx'];
100
        $sum[2]['tx'] = $month[0]['tx'];
119
            $sum[2]['tx'] = $month[0]['tx'];
101
 
120
 
102
        $sum[3]['act'] = 1;
121
            $sum[3]['act'] = 1;
103
        $sum[3]['label'] = T('All time');
122
            $sum[3]['label'] = T('All time');
104
        $sum[3]['rx'] = $trx;
123
            $sum[3]['rx'] = $trx;
105
        $sum[3]['tx'] = $ttx;
124
            $sum[3]['tx'] = $ttx;
-
 
125
        }
106
 
126
 
107
        write_data_table(T('Summary'), $sum);
127
        write_data_table(T('Summary'), $sum);
108
        print "<br/>\n";
128
        print "<br/>\n";
109
        write_data_table(T('Top 10 days'), $top);
129
        write_data_table(T('Top 10 days'), $top);
110
    }
130
    }
111
    
131
 
112
    
132
 
113
    function write_data_table($caption, $tab)
133
    function write_data_table($caption, $tab)
114
    {
134
    {
115
        print "<table width=\"100%\" cellspacing=\"0\">\n";
135
        print "<table width=\"100%\" cellspacing=\"0\">\n";
116
        print "<caption>$caption</caption>\n";
136
        print "<caption>$caption</caption>\n";
117
        print "<tr>";
137
        print "<tr>";
118
        print "<th class=\"label\" style=\"width:120px;\">&nbsp;</th>";
138
        print "<th class=\"label\" style=\"width:120px;\">&nbsp;</th>";
119
        print "<th class=\"label\">".T('In')."</th>";
139
        print "<th class=\"label\">".T('In')."</th>";
120
        print "<th class=\"label\">".T('Out')."</th>";
140
        print "<th class=\"label\">".T('Out')."</th>";
121
        print "<th class=\"label\">".T('Total')."</th>";  
141
        print "<th class=\"label\">".T('Total')."</th>";
122
        print "</tr>\n";
142
        print "</tr>\n";
123
 
143
 
124
        for ($i=0; $i<count($tab); $i++)
144
        for ($i=0; $i<count($tab); $i++)
125
        {
145
        {
126
            if ($tab[$i]['act'] == 1)
146
            if ($tab[$i]['act'] == 1)
Line 146... Line 166...
146
    //
166
    //
147
    // html start
167
    // html start
148
    //
168
    //
149
    header('Content-type: text/html; charset=utf-8');
169
    header('Content-type: text/html; charset=utf-8');
150
    print '<?xml version="1.0"?>';
170
    print '<?xml version="1.0"?>';
151
?>        
171
?>
152
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
172
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
153
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
173
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
154
<head>
174
<head>
155
  <title>vnStat - PHP frontend</title>
175
  <title>vnStat - PHP frontend</title>
156
  <link rel="stylesheet" type="text/css" href="themes/<?php echo $style ?>/style.css"/>
176
  <link rel="stylesheet" type="text/css" href="themes/<?php echo $style ?>/style.css"/>
Line 158... Line 178...
158
<body>
178
<body>
159
 
179
 
160
<div id="wrap">
180
<div id="wrap">
161
  <div id="sidebar"><?php write_side_bar(); ?></div>
181
  <div id="sidebar"><?php write_side_bar(); ?></div>
162
   <div id="content">
182
   <div id="content">
163
    <div id="header"><?php print T('Traffic data for')." $iface_title[$iface] ($iface)";?></div>
183
    <div id="header"><?php print T('Traffic data for').(isset($iface_title[$iface]) ? $iface_title[$iface] : '')." ($iface)";?></div>
164
    <div id="main">
184
    <div id="main">
165
    <?php
185
    <?php
166
    $graph_params = "if=$iface&amp;page=$page&amp;style=$style";
186
    $graph_params = "if=$iface&amp;page=$page&amp;style=$style";
167
    if ($page != 's')
187
    if ($page != 's')
168
        if ($graph_format == 'svg') {
188
        if ($graph_format == 'svg') {
169
	     print "<object type=\"image/svg+xml\" width=\"692\" height=\"297\" data=\"graph_svg.php?$graph_params\"></object>\n";
189
	     print "<object type=\"image/svg+xml\" width=\"692\" height=\"297\" data=\"graph_svg.php?$graph_params\"></object>\n";
170
        } else {
190
        } else {
171
	     print "<img src=\"graph.php?$graph_params\" alt=\"graph\"/>\n";	
191
	     print "<img src=\"graph.php?$graph_params\" alt=\"graph\"/>\n";
172
        }
192
        }
173
 
193
 
174
    if ($page == 's')
194
    if ($page == 's')
175
    {
195
    {
176
        write_summary();
196
        write_summary();
177
    }
197
    }
178
    else if ($page == 'h')
198
    else if ($page == 'h')
179
    {   
199
    {
180
        write_data_table(T('Last 24 hours'), $hour); 
200
        write_data_table(T('Last 24 hours'), $hour);
181
    }
201
    }
182
    else if ($page == 'd')
202
    else if ($page == 'd')
183
    {
203
    {
184
        write_data_table(T('Last 30 days'), $day);	
204
        write_data_table(T('Last 30 days'), $day);
185
    }
205
    }
186
    else if ($page == 'm')
206
    else if ($page == 'm')
187
    {
207
    {
188
        write_data_table(T('Last 12 months'), $month);   
208
        write_data_table(T('Last 12 months'), $month);
189
    }
209
    }
190
    ?>
210
    ?>
191
    </div>
211
    </div>
192
    <div id="footer"><a href="http://www.sqweek.com/">vnStat PHP frontend</a> 1.5.1 - &copy;2006-2010 Bjorge Dijkstra (bjd _at_ jooz.net)</div>
212
    <div id="footer"><a href="http://www.sqweek.com/">vnStat PHP frontend</a> 1.5.2 - &copy;2006-2011 Bjorge Dijkstra (bjd _at_ jooz.net)</div>
193
  </div>
213
  </div>
194
</div>
214
</div>
195
 
215
 
196
</body></html>
216
</body></html>