Subversion Repositories ALCASAR

Rev

Rev 1533 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1533 Rev 1675
1
<?php
1
<?php
2
    //
2
    //
3
    // vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
3
    // vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
4
    //
4
    //
5
    // This program is free software; you can redistribute it and/or modify
5
    // This program is free software; you can redistribute it and/or modify
6
    // it under the terms of the GNU General Public License as published by
6
    // it under the terms of the GNU General Public License as published by
7
    // the Free Software Foundation; either version 2 of the License, or
7
    // the Free Software Foundation; either version 2 of the License, or
8
    // (at your option) any later version.
8
    // (at your option) any later version.
9
    //
9
    //
10
    // This program is distributed in the hope that it will be useful,
10
    // This program is distributed in the hope that it will be useful,
11
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    // GNU General Public License for more details.
13
    // GNU General Public License for more details.
14
    //
14
    //
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';
26
 
26
 
27
    validate_input();
27
    validate_input();
28
 
28
 
29
    require "./themes/$style/theme.php";
29
    require "./themes/$style/theme.php";
30
 
30
 
31
    function allocate_color($im, $colors)
31
    function allocate_color($im, $colors)
32
    {
32
    {
33
	return imagecolorallocatealpha($im, $colors[0], $colors[1], $colors[2], $colors[3]);
33
	return imagecolorallocatealpha($im, $colors[0], $colors[1], $colors[2], $colors[3]);
34
    }
34
    }
35
            
35
 
36
    function init_image()
36
    function init_image()
37
    {
37
    {
38
        global $im, $xlm, $xrm, $ytm, $ybm, $iw, $ih,$graph, $cl, $iface, $colorscheme, $style;
38
        global $im, $xlm, $xrm, $ytm, $ybm, $iw, $ih,$graph, $cl, $iface, $colorscheme, $style;
39
 
39
 
40
        if ($graph == 'none')
40
        if ($graph == 'none')
41
            return;
41
            return;
42
 
42
 
43
        //
43
        //
44
        // image object
44
        // image object
45
        //    
45
        //
46
        $xlm = 70;
46
        $xlm = 70;
47
        $xrm = 20;
47
        $xrm = 20;
48
        $ytm = 35;
48
        $ytm = 35;
49
        $ybm = 60;
49
        $ybm = 60;
50
        if ($graph == 'small')
50
        if ($graph == 'small')
51
        {
51
        {
52
            $iw = 300 + $xrm + $xlm;
52
            $iw = 300 + $xrm + $xlm;
53
            $ih = 100 + $ytm + $ybm;    
53
            $ih = 100 + $ytm + $ybm;
54
        }
54
        }
55
        else
55
        else
56
        {
56
        {
57
            $iw = 600 + $xrm + $xlm;
57
            $iw = 600 + $xrm + $xlm;
58
            $ih = 200 + $ytm + $ybm;
58
            $ih = 200 + $ytm + $ybm;
59
        }
59
        }
60
 
60
 
61
        $im = imagecreatetruecolor($iw,$ih);
61
        $im = imagecreatetruecolor($iw,$ih);
62
 
62
 
63
        //
63
        //
64
        // colors
64
        // colors
65
        //
65
        //
66
	$cs = $colorscheme;
66
	$cs = $colorscheme;
67
	$cl['image_background'] = allocate_color($im, $cs['image_background']);
67
	$cl['image_background'] = allocate_color($im, $cs['image_background']);
68
	$cl['background'] = allocate_color($im, $cs['graph_background']);
68
	$cl['background'] = allocate_color($im, $cs['graph_background']);
69
	$cl['background_2'] = allocate_color($im, $cs['graph_background_2']);
69
	$cl['background_2'] = allocate_color($im, $cs['graph_background_2']);
70
        $cl['grid_stipple_1'] = allocate_color($im, $cs['grid_stipple_1']);
70
        $cl['grid_stipple_1'] = allocate_color($im, $cs['grid_stipple_1']);
71
        $cl['grid_stipple_2'] = allocate_color($im, $cs['grid_stipple_2']);
71
        $cl['grid_stipple_2'] = allocate_color($im, $cs['grid_stipple_2']);
72
        $cl['text'] = allocate_color($im, $cs['text']);
72
        $cl['text'] = allocate_color($im, $cs['text']);
73
        $cl['border'] = allocate_color($im, $cs['border']);
73
        $cl['border'] = allocate_color($im, $cs['border']);
74
        $cl['rx'] = allocate_color($im, $cs['rx']);
74
        $cl['rx'] = allocate_color($im, $cs['rx']);
75
        $cl['rx_border'] = allocate_color($im, $cs['rx_border']);
75
        $cl['rx_border'] = allocate_color($im, $cs['rx_border']);
76
        $cl['tx'] = allocate_color($im, $cs['tx']);
76
        $cl['tx'] = allocate_color($im, $cs['tx']);
77
        $cl['tx_border'] = allocate_color($im, $cs['tx_border']);
77
        $cl['tx_border'] = allocate_color($im, $cs['tx_border']);
78
	
78
 
79
        imagefilledrectangle($im,0,0,$iw,$ih,$cl['image_background']);
79
        imagefilledrectangle($im,0,0,$iw,$ih,$cl['image_background']);
80
	imagefilledrectangle($im,$xlm,$ytm,$iw-$xrm,$ih-$ybm, $cl['background']);
80
	imagefilledrectangle($im,$xlm,$ytm,$iw-$xrm,$ih-$ybm, $cl['background']);
81
	
81
 
82
	$x_step = ($iw - $xlm - $xrm) / 12;
82
	$x_step = ($iw - $xlm - $xrm) / 12;
83
	$depth = ($x_step / 8) + 4;
83
	$depth = ($x_step / 8) + 4;
84
	imagefilledpolygon($im, array($xlm, $ytm, $xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $xlm - $depth, $ytm + $depth), 4, $cl['background_2']);
84
	imagefilledpolygon($im, array($xlm, $ytm, $xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $xlm - $depth, $ytm + $depth), 4, $cl['background_2']);
85
	imagefilledpolygon($im, array($xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $iw - $xrm - $depth, $ih - $ybm  + $depth, $iw - $xrm, $ih - $ybm), 4, $cl['background_2']);
85
	imagefilledpolygon($im, array($xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $iw - $xrm - $depth, $ih - $ybm  + $depth, $iw - $xrm, $ih - $ybm), 4, $cl['background_2']);
86
 
86
 
87
	// draw title
87
	// draw title
88
	$text = T('Traffic data for')." $iface";
88
	$text = T('Traffic data for')." $iface";
89
 	$bbox = imagettfbbox(10, 0, GRAPH_FONT, $text);
89
 	$bbox = imagettfbbox(10, 0, GRAPH_FONT, $text);
90
	$textwidth = $bbox[2] - $bbox[0];
90
	$textwidth = $bbox[2] - $bbox[0];
91
	imagettftext($im, 10, 0, ($iw-$textwidth)/2, ($ytm/2), $cl['text'], GRAPH_FONT, $text);
91
	imagettftext($im, 10, 0, ($iw-$textwidth)/2, ($ytm/2), $cl['text'], GRAPH_FONT, $text);
92
		
92
 
93
    }
93
    }
94
 
94
 
95
    function draw_border()
95
    function draw_border()
96
    {
96
    {
97
        global $im,$cl,$iw,$ih;
97
        global $im,$cl,$iw,$ih;
98
 
98
 
99
        imageline($im,     0,    0,$iw-1,    0, $cl['border']);
99
        imageline($im,     0,    0,$iw-1,    0, $cl['border']);
100
        imageline($im,     0,$ih-1,$iw-1,$ih-1, $cl['border']);
100
        imageline($im,     0,$ih-1,$iw-1,$ih-1, $cl['border']);
101
        imageline($im,     0,    0,    0,$ih-1, $cl['border']);  
101
        imageline($im,     0,    0,    0,$ih-1, $cl['border']);
102
        imageline($im, $iw-1,    0,$iw-1,$ih-1, $cl['border']);
102
        imageline($im, $iw-1,    0,$iw-1,$ih-1, $cl['border']);
103
    }
103
    }
104
    
104
 
105
    function draw_grid($x_ticks, $y_ticks)
105
    function draw_grid($x_ticks, $y_ticks)
106
    {
106
    {
107
        global $im, $cl, $iw, $ih, $xlm, $xrm, $ytm, $ybm;
107
        global $im, $cl, $iw, $ih, $xlm, $xrm, $ytm, $ybm;
108
        $x_step = ($iw - $xlm - $xrm) / $x_ticks;
108
        $x_step = ($iw - $xlm - $xrm) / ($x_ticks ?: 1);
109
        $y_step = ($ih - $ytm - $ybm) / $y_ticks;
109
        $y_step = ($ih - $ytm - $ybm) / $y_ticks;
110
	
110
 
111
	$depth = 10;//($x_step / 8) + 4;
111
	$depth = 10;//($x_step / 8) + 4;
112
 
112
 
113
        $ls = array($cl['grid_stipple_1'],$cl['grid_stipple_2']);
113
        $ls = array($cl['grid_stipple_1'],$cl['grid_stipple_2']);
114
        imagesetstyle($im, $ls);
114
        imagesetstyle($im, $ls);
115
        for ($i=$xlm;$i<=($iw-$xrm); $i += $x_step)
115
        for ($i=$xlm;$i<=($iw-$xrm); $i += $x_step)
116
        {
116
        {
117
            imageline($im, $i, $ytm, $i, $ih - $ybm, IMG_COLOR_STYLED);
117
            imageline($im, $i, $ytm, $i, $ih - $ybm, IMG_COLOR_STYLED);
118
	    imageline($im, $i, $ih - $ybm, $i - $depth, $ih - $ybm + $depth, IMG_COLOR_STYLED);
118
	    imageline($im, $i, $ih - $ybm, $i - $depth, $ih - $ybm + $depth, IMG_COLOR_STYLED);
119
        }
119
        }
120
        for ($i=$ytm;$i<=($ih-$ybm); $i += $y_step)
120
        for ($i=$ytm;$i<=($ih-$ybm); $i += $y_step)
121
        {
121
        {
122
            imageline($im, $xlm, $i, $iw - $xrm, $i, IMG_COLOR_STYLED); 
122
            imageline($im, $xlm, $i, $iw - $xrm, $i, IMG_COLOR_STYLED);
123
	    imageline($im, $xlm, $i, $xlm - $depth, $i + $depth, IMG_COLOR_STYLED);
123
	    imageline($im, $xlm, $i, $xlm - $depth, $i + $depth, IMG_COLOR_STYLED);
124
        }
124
        }
125
        imageline($im, $xlm, $ytm, $xlm, $ih - $ybm, $cl['border']);
125
        imageline($im, $xlm, $ytm, $xlm, $ih - $ybm, $cl['border']);
126
        imageline($im, $xlm, $ih - $ybm, $iw - $xrm, $ih - $ybm, $cl['border']);
126
        imageline($im, $xlm, $ih - $ybm, $iw - $xrm, $ih - $ybm, $cl['border']);
127
    }
127
    }
128
    
-
 
129
    
128
 
130
    function draw_data($data)
129
    function draw_data($data)
131
    {
130
    {
132
        global $im,$cl,$iw,$ih,$xlm,$xrm,$ytm,$ybm;
131
        global $im,$cl,$iw,$ih,$xlm,$xrm,$ytm,$ybm;
133
 
132
 
134
        sort($data);
133
        sort($data);
135
 
134
 
136
        $x_ticks = count($data);
135
        $x_ticks = count($data);
137
        $y_ticks = 10;
136
        $y_ticks = 10;
138
        $y_scale = 1;
137
        $y_scale = 1;
139
        $prescale = 1;
138
        $prescale = 1;
140
        $unit = 'K';
139
        $unit = 'K';
141
        $offset = 0;
140
        $offset = 0;
142
        $gr_h = $ih - $ytm - $ybm;
141
        $gr_h = $ih - $ytm - $ybm;
143
        $x_step = ($iw - $xlm - $xrm) / $x_ticks;
142
        $x_step = ($iw - $xlm - $xrm) / ($x_ticks ?: 1);
144
        $y_step = ($ih - $ytm - $ybm) / $y_ticks;
143
        $y_step = ($ih - $ytm - $ybm) / $y_ticks;
145
        $bar_w = ($x_step / 2) ;
144
        $bar_w = ($x_step / 2) ;
146
 
145
 
147
        //
146
        //
148
        // determine scale
147
        // determine scale
149
        //
148
        //
150
        $low = 99999999999;
149
        $low = 99999999999;
151
        $high = 0;
150
        $high = 0;
152
        for ($i=0; $i<$x_ticks; $i++)
151
        for ($i=0; $i<$x_ticks; $i++)
153
        {
152
        {
154
            if ($data[$i]['rx'] < $low)
153
            if ($data[$i]['rx'] < $low)
155
            $low = $data[$i]['rx'];
154
            $low = $data[$i]['rx'];
156
            if ($data[$i]['tx'] < $low)
155
            if ($data[$i]['tx'] < $low)
157
            $low = $data[$i]['tx'];
156
            $low = $data[$i]['tx'];
158
            if ($data[$i]['rx'] > $high)
157
            if ($data[$i]['rx'] > $high)
159
            $high = $data[$i]['rx'];
158
            $high = $data[$i]['rx'];
160
            if ($data[$i]['tx'] > $high)
159
            if ($data[$i]['tx'] > $high)
161
            $high = $data[$i]['tx'];
160
            $high = $data[$i]['tx'];
162
        }
161
        }
163
 
162
 
164
        while ($high > ($prescale * $y_scale * $y_ticks))
163
        while ($high > ($prescale * $y_scale * $y_ticks))
165
        {
164
        {
166
            $y_scale = $y_scale * 2;
165
            $y_scale = $y_scale * 2;
167
            if ($y_scale >= 1024)
166
            if ($y_scale >= 1024)
168
            {
167
            {
169
            $prescale = $prescale * 1024;
168
            $prescale = $prescale * 1024;
170
            $y_scale = $y_scale / 1024;
169
            $y_scale = $y_scale / 1024;
171
            if ($unit == 'K') 
170
            if ($unit == 'K')
172
                $unit = 'M';
171
                $unit = 'M';
173
            else if ($unit == 'M')
172
            else if ($unit == 'M')
174
                $unit = 'G';
173
                $unit = 'G';
175
            else if ($unit == 'G')
174
            else if ($unit == 'G')
176
                $unit = 'T';
175
                $unit = 'T';
177
            }
176
            }
178
        }
177
        }
179
 
178
 
180
        draw_grid($x_ticks, $y_ticks);
179
        draw_grid($x_ticks, $y_ticks);
181
	
180
 
182
        //
181
        //
183
        // graph scale factor (per pixel)
182
        // graph scale factor (per pixel)
184
        //
183
        //
185
	imagesetthickness($im, 1);
184
	imagesetthickness($im, 1);
186
        $sf = ($prescale * $y_scale * $y_ticks) / $gr_h;
185
        $sf = ($prescale * $y_scale * $y_ticks) / $gr_h;
187
 
186
 
188
        if ($data[0] == 'nodata')
187
        if (count($data) == 0)
189
        {
188
        {
190
            $text = 'no data available';
189
            $text = T('no data available');
191
	    $bbox = imagettfbbox(10, 0, GRAPH_FONT, $text);
190
	    $bbox = imagettfbbox(10, 0, GRAPH_FONT, $text);
192
	    $textwidth = $bbox[2] - $bbox[0];
191
	    $textwidth = $bbox[2] - $bbox[0];
193
	    imagettftext($im, 10, 0, ($iw-$textwidth)/2, $ytm + 80, $cl['text'], GRAPH_FONT, $text);
192
	    imagettftext($im, 10, 0, ($iw-$textwidth)/2, $ytm + 80, $cl['text'], GRAPH_FONT, $text);
194
        }
193
        }
195
        else
194
        else
196
        {
195
        {
197
            //
196
            //
198
            // draw bars
197
            // draw bars
199
            //      
198
            //
200
            for ($i=0; $i<$x_ticks; $i++)
199
            for ($i=0; $i<$x_ticks; $i++)
201
            {
200
            {
202
        	$x = $xlm + ($i * $x_step);
201
        	$x = $xlm + ($i * $x_step);
203
        	$y = $ytm + ($ih - $ytm - $ybm) - (($data[$i]['rx'] - $offset) / $sf);
202
        	$y = $ytm + ($ih - $ytm - $ybm) - (($data[$i]['rx'] - $offset) / $sf);
204
		
203
 
205
		$depth = $x_step / 8;
204
		$depth = $x_step / 8;
206
		$space = 0;
205
		$space = 0;
207
		
206
 
208
		$x1 = $x;
207
		$x1 = $x;
209
		$y1 = $y;
208
		$y1 = $y;
210
		$x2 = $x + $bar_w - $space;
209
		$x2 = $x + $bar_w - $space;
211
		$y2 = $ih - $ybm;
210
		$y2 = $ih - $ybm;
212
		
211
 
213
        	imagefilledrectangle($im, $x1, $y1, $x2, $y2, $cl['rx']);
212
        	imagefilledrectangle($im, $x1, $y1, $x2, $y2, $cl['rx']);
214
		imagerectangle($im, $x1, $y1, $x2, $y2, $cl['rx_border']);
213
		imagerectangle($im, $x1, $y1, $x2, $y2, $cl['rx_border']);
215
		
214
 
216
		imagefilledrectangle($im, $x1 - $depth, $y1 + $depth, $x2 -$depth, $y2 + $depth, $cl['rx']);
215
		imagefilledrectangle($im, $x1 - $depth, $y1 + $depth, $x2 -$depth, $y2 + $depth, $cl['rx']);
217
		imagerectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['rx_border']);
216
		imagerectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['rx_border']);
218
		
217
 
219
		imagefilledpolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['rx']);
218
		imagefilledpolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['rx']);
220
		imagepolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['rx_border']);
219
		imagepolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['rx_border']);
221
		imagefilledpolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['rx']);
220
		imagefilledpolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['rx']);
222
		imagepolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['rx_border']);
221
		imagepolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['rx_border']);
223
 
222
 
224
        	$y1 = $ytm + ($ih - $ytm - $ybm) - (($data[$i]['tx'] - $offset) / $sf);
223
        	$y1 = $ytm + ($ih - $ytm - $ybm) - (($data[$i]['tx'] - $offset) / $sf);
225
		$x1 = $x1 + $bar_w;
224
		$x1 = $x1 + $bar_w;
226
		$x2 = $x2 + $bar_w;
225
		$x2 = $x2 + $bar_w;
227
 
226
 
228
        	imagefilledrectangle($im, $x1, $y1, $x2, $y2, $cl['tx']);
227
        	imagefilledrectangle($im, $x1, $y1, $x2, $y2, $cl['tx']);
229
		imagerectangle($im, $x1, $y1, $x2, $y2, $cl['tx_border']);
228
		imagerectangle($im, $x1, $y1, $x2, $y2, $cl['tx_border']);
230
		
229
 
231
        	imagefilledrectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['tx']);
230
        	imagefilledrectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['tx']);
232
		imagerectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['tx_border']);		
231
		imagerectangle($im, $x1 - $depth, $y1 + $depth, $x2 - $depth, $y2 + $depth, $cl['tx_border']);
233
		
232
 
234
		imagefilledpolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['tx']);
233
		imagefilledpolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['tx']);
235
		imagepolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['tx_border']);
234
		imagepolygon($im, array($x1, $y1, $x2, $y1, $x2 - $depth, $y1 + $depth, $x1 - $depth, $y1 + $depth), 4, $cl['tx_border']);
236
		imagefilledpolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['tx']);
235
		imagefilledpolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['tx']);
237
		imagepolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['tx_border']);
236
		imagepolygon($im, array($x2, $y1, $x2, $y2, $x2 - $depth, $y2 + $depth, $x2 - $depth, $y1 + $depth), 4, $cl['tx_border']);
238
            }
237
            }
239
    
238
 
240
            //
239
            //
241
            // axis labels
240
            // axis labels
242
            //
241
            //
243
            for ($i=0; $i<=$y_ticks; $i++)
242
            for ($i=0; $i<=$y_ticks; $i++)
244
            {
243
            {
245
                $label = ($i * $y_scale).$unit;
244
                $label = ($i * $y_scale).$unit;
246
		$bbox = imagettfbbox(8, 0, GRAPH_FONT, $label);
245
		$bbox = imagettfbbox(8, 0, GRAPH_FONT, $label);
247
		$textwidth = $bbox[2] - $bbox[0];
246
		$textwidth = $bbox[2] - $bbox[0];
248
		imagettftext($im, 8, 0, $xlm - $textwidth - 16, ($ih - $ybm) - ($i * $y_step) + 8 + $depth, $cl['text'], GRAPH_FONT, $label);
247
		imagettftext($im, 8, 0, $xlm - $textwidth - 16, ($ih - $ybm) - ($i * $y_step) + 8 + $depth, $cl['text'], GRAPH_FONT, $label);
249
            }
248
            }
250
 
249
 
251
            for ($i=0; $i<$x_ticks; $i++)
250
            for ($i=0; $i<$x_ticks; $i++)
252
            {
251
            {
253
                $label = $data[$i]['img_label'];
252
                $label = $data[$i]['img_label'];
254
		$bbox = imagettfbbox(9, 0, GRAPH_FONT, $label);
253
		$bbox = imagettfbbox(9, 0, GRAPH_FONT, $label);
255
		$textwidth = $bbox[2] - $bbox[0];
254
		$textwidth = $bbox[2] - $bbox[0];
256
		imagettftext($im, 9, 0, $xlm + ($i * $x_step) + ($x_step / 2) - ($textwidth / 2) - $depth - 4, $ih - $ybm + 20 + $depth, $cl['text'], GRAPH_FONT, $label);
255
		imagettftext($im, 9, 0, $xlm + ($i * $x_step) + ($x_step / 2) - ($textwidth / 2) - $depth - 4, $ih - $ybm + 20 + $depth, $cl['text'], GRAPH_FONT, $label);
257
            }
256
            }
258
        }
257
        }
259
 
258
 
260
        draw_border();
259
        draw_border();
261
 
260
 
262
 
261
 
263
        //
262
        //
264
        // legend
263
        // legend
265
        //
264
        //
266
        imagefilledrectangle($im, $xlm, $ih-$ybm+39, $xlm+8,$ih-$ybm+47,$cl['rx']);
265
        imagefilledrectangle($im, $xlm, $ih-$ybm+39, $xlm+8,$ih-$ybm+47,$cl['rx']);
267
        imagerectangle($im, $xlm, $ih-$ybm+39, $xlm+8,$ih-$ybm+47,$cl['text']);
266
        imagerectangle($im, $xlm, $ih-$ybm+39, $xlm+8,$ih-$ybm+47,$cl['text']);
268
	imagettftext($im, 8,0, $xlm+14, $ih-$ybm+48,$cl['text'], GRAPH_FONT,'bytes in');
267
	imagettftext($im, 8,0, $xlm+14, $ih-$ybm+48,$cl['text'], GRAPH_FONT,T('bytes in'));
269
 
268
 
270
        imagefilledrectangle($im, $xlm+120 , $ih-$ybm+39, $xlm+128,$ih-$ybm+47,$cl['tx']);
269
        imagefilledrectangle($im, $xlm+120 , $ih-$ybm+39, $xlm+128,$ih-$ybm+47,$cl['tx']);
271
        imagerectangle($im, $xlm+120, $ih-$ybm+39, $xlm+128,$ih-$ybm+47,$cl['text']);
270
        imagerectangle($im, $xlm+120, $ih-$ybm+39, $xlm+128,$ih-$ybm+47,$cl['text']);
272
	imagettftext($im, 8,0, $xlm+134, $ih-$ybm+48,$cl['text'], GRAPH_FONT,'bytes out'); 
271
	imagettftext($im, 8,0, $xlm+134, $ih-$ybm+48,$cl['text'], GRAPH_FONT,T('bytes out'));
273
    }
272
    }
274
 
273
 
275
    function output_image()
274
    function output_image()
276
    {
275
    {
277
        global $page,$hour,$day,$month,$im,$iface;
276
        global $page,$hour,$day,$month,$im,$iface;
278
 
277
 
279
        if ($page == 'summary')
278
        if ($page == 'summary')
280
            return;
279
            return;
281
 
280
 
282
        init_image();
281
        init_image();
283
 
282
 
284
        if ($page == 'h')
283
        if ($page == 'h')
285
        {
284
        {
286
            draw_data($hour);
285
            draw_data($hour);
287
        }
286
        }
288
        else if ($page == 'd')
287
        else if ($page == 'd')
289
        {
288
        {
290
            draw_data($day);
289
            draw_data($day);
291
        }
290
        }
292
        else if ($page == 'm')
291
        else if ($page == 'm')
293
        {
292
        {
294
            draw_data($month);
293
            draw_data($month);
295
        }
294
        }
296
	
295
 
297
        header('Content-type: image/png');	
296
        header('Content-type: image/png');
298
        imagepng($im);
297
        imagepng($im);
299
    }
298
    }
300
 
299
 
301
    get_vnstat_data();
300
    get_vnstat_data();
302
    output_image();
301
    output_image();
303
?>        
302
?>
304
 
303