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
        
23
 
24
    //
24
    //
25
    // Valid values for other parameters you can pass to the script.
25
    // Valid values for other parameters you can pass to the script.
26
    // Input parameters will always be limited to one of the values listed here.
26
    // Input parameters will always be limited to one of the values listed here.
27
    // If a parameter is not provided or invalid it will revert to the default,
27
    // If a parameter is not provided or invalid it will revert to the default,
28
    // the first parameter in the list.
28
    // the first parameter in the list.
Line 37... Line 37...
37
    }
37
    }
38
    else
38
    else
39
    {
39
    {
40
	die('can\'t determine script name!');
40
	die('can\'t determine script name!');
41
    }
41
    }
42
    
42
 
43
    $page_list  = array('s','h','d','m');
43
    $page_list  = array('s','h','d','m');
44
    
44
 
45
    $graph_list = array('large','small','none');
45
    $graph_list = array('large','small','none');
46
    
46
 
47
    $page_title['s'] = T('summary');
47
    $page_title['s'] = T('summary');
48
    $page_title['h'] = T('hours');
48
    $page_title['h'] = T('hours');
49
    $page_title['d'] = T('days');
49
    $page_title['d'] = T('days');
50
    $page_title['m'] = T('months');
50
    $page_title['m'] = T('months');
51
    
51
 
52
 
52
 
53
    //
53
    //
54
    // functions
54
    // functions
55
    //
55
    //
56
    function validate_input()
56
    function validate_input()
Line 81... Line 81...
81
        {
81
        {
82
            $graph = $graph_list[0];
82
            $graph = $graph_list[0];
83
        }
83
        }
84
 
84
 
85
	$tp = "./themes/$style";
85
	$tp = "./themes/$style";
86
        if (!is_dir($tp) || !file_exists("$tp/theme.php"))
86
        if (!is_dir($tp) || !file_exists("$tp/theme.php") || !preg_match('/^[a-z0-9-_]+$/i', $style))
87
        {
87
        {
88
	    $style = DEFAULT_COLORSCHEME;
88
	    $style = DEFAULT_COLORSCHEME;
89
        }
89
        }
90
    }
90
    }
91
    
-
 
92
 
91
 
-
 
92
 
93
    function get_vnstat_data()    
93
    function get_vnstat_data($use_label=true)
94
    {
94
    {
95
        global $iface, $vnstat_bin, $data_dir;
95
        global $iface, $vnstat_bin, $data_dir;
96
        global $hour,$day,$month,$top,$summary;
96
        global $hour,$day,$month,$top,$summary;
97
 
97
 
98
        if (!isset($vnstat_bin) || $vnstat_bin == '')
98
        if (!isset($vnstat_bin) || $vnstat_bin == '')
99
        {
99
        {
100
	    if (file_exists("$data_dir/vnstat_dump_$iface"))
100
	    if (file_exists("$data_dir/vnstat_dump_$iface"))
101
	    {
101
	    {
102
        	$vnstat_data = file("$data_dir/vnstat_dump_$iface");
102
        	$vnstat_data = file("$data_dir/vnstat_dump_$iface");
103
	    }	    
103
	    }
104
	    else
104
	    else
105
	    {
105
	    {
106
		$vnstat_data = array();
106
		$vnstat_data = array();
107
	    }
107
	    }
108
        }
108
        }
Line 121... Line 121...
121
        $day = array();
121
        $day = array();
122
        $hour = array();
122
        $hour = array();
123
        $month = array();
123
        $month = array();
124
        $top = array();
124
        $top = array();
125
 
125
 
-
 
126
        if (strpos($vnstat_data[0], 'Error') !== false) {
-
 
127
          return;
-
 
128
        }
-
 
129
 
126
        //
130
        //
127
        // extract data
131
        // extract data
128
        //
132
        //
129
        foreach($vnstat_data as $line) 
133
        foreach($vnstat_data as $line)
130
        {
134
        {
131
            $d = explode(';', trim($line));
135
            $d = explode(';', trim($line));
132
            if ($d[0] == 'd')
136
            if ($d[0] == 'd')
133
            {
137
            {
134
                $day[$d[1]]['time']  = $d[2];
138
                $day[$d[1]]['time']  = $d[2];
135
                $day[$d[1]]['rx']    = $d[3] * 1024 + $d[5];
139
                $day[$d[1]]['rx']    = $d[3] * 1024 + $d[5];
136
                $day[$d[1]]['tx']    = $d[4] * 1024 + $d[6];
140
                $day[$d[1]]['tx']    = $d[4] * 1024 + $d[6];
137
                $day[$d[1]]['act']   = $d[7];
141
                $day[$d[1]]['act']   = $d[7];
138
                if ($d[2] != 0)
142
                if ($d[2] != 0 && $use_label)
139
                {
143
                {
140
                    $day[$d[1]]['label'] = strftime(T('datefmt_days'),$d[2]);
144
                    $day[$d[1]]['label'] = strftime(T('datefmt_days'),$d[2]);
141
                    $day[$d[1]]['img_label'] = strftime(T('datefmt_days_img'), $d[2]);
145
                    $day[$d[1]]['img_label'] = strftime(T('datefmt_days_img'), $d[2]);
142
                }
146
                }
143
                else
147
                elseif($use_label)
144
                {
148
                {
145
                    $day[$d[1]]['label'] = '';
149
                    $day[$d[1]]['label'] = '';
146
                    $day[$d[1]]['img_label'] = '';          
150
                    $day[$d[1]]['img_label'] = '';
147
                }           
151
                }
148
            }
152
            }
149
            else if ($d[0] == 'm')
153
            else if ($d[0] == 'm')
150
            {
154
            {
151
                $month[$d[1]]['time'] = $d[2];
155
                $month[$d[1]]['time'] = $d[2];
152
                $month[$d[1]]['rx']   = $d[3] * 1024 + $d[5];
156
                $month[$d[1]]['rx']   = $d[3] * 1024 + $d[5];
153
                $month[$d[1]]['tx']   = $d[4] * 1024 + $d[6];
157
                $month[$d[1]]['tx']   = $d[4] * 1024 + $d[6];
154
                $month[$d[1]]['act']  = $d[7];
158
                $month[$d[1]]['act']  = $d[7];
155
                if ($d[2] != 0)
159
                if ($d[2] != 0 && $use_label)
156
                {
160
                {
157
                    $month[$d[1]]['label'] = strftime(T('datefmt_months'), $d[2]);
161
                    $month[$d[1]]['label'] = strftime(T('datefmt_months'), $d[2]);
158
                    $month[$d[1]]['img_label'] = strftime(T('datefmt_months_img'), $d[2]);
162
                    $month[$d[1]]['img_label'] = strftime(T('datefmt_months_img'), $d[2]);
159
                }
163
                }
160
                else
164
                else if ($use_label)
161
                {
165
                {
162
                    $month[$d[1]]['label'] = '';
166
                    $month[$d[1]]['label'] = '';
163
                    $month[$d[1]]['img_label'] = '';            
167
                    $month[$d[1]]['img_label'] = '';
164
                }
168
                }
165
            }
169
            }
166
            else if ($d[0] == 'h')
170
            else if ($d[0] == 'h')
167
            {
171
            {
168
                $hour[$d[1]]['time'] = $d[2];
172
                $hour[$d[1]]['time'] = $d[2];
169
                $hour[$d[1]]['rx']   = $d[3];
173
                $hour[$d[1]]['rx']   = $d[3];
170
                $hour[$d[1]]['tx']   = $d[4];
174
                $hour[$d[1]]['tx']   = $d[4];
171
                $hour[$d[1]]['act']  = 1;
175
                $hour[$d[1]]['act']  = 1;
172
                if ($d[2] != 0)
176
                if ($d[2] != 0 && $use_label)
173
                {
177
                {
174
                    $st = $d[2] - ($d[2] % 3600);
178
                    $st = $d[2] - ($d[2] % 3600);
175
                    $et = $st + 3600;
179
                    $et = $st + 3600;
176
                    $hour[$d[1]]['label'] = strftime(T('datefmt_hours'), $st).' - '.strftime(T('datefmt_hours'), $et);
180
                    $hour[$d[1]]['label'] = strftime(T('datefmt_hours'), $st).' - '.strftime(T('datefmt_hours'), $et);
177
                    $hour[$d[1]]['img_label'] = strftime(T('datefmt_hours_img'), $d[2]);
181
                    $hour[$d[1]]['img_label'] = strftime(T('datefmt_hours_img'), $d[2]);
178
                }
182
                }
179
                else
183
                else if ($use_label)
180
                {
184
                {
181
                    $hour[$d[1]]['label'] = '';
185
                    $hour[$d[1]]['label'] = '';
182
                    $hour[$d[1]]['img_label'] = '';
186
                    $hour[$d[1]]['img_label'] = '';
183
                }
187
                }
184
            }
188
            }
185
            else if ($d[0] == 't')
189
            else if ($d[0] == 't')
186
            {   
190
            {
187
                $top[$d[1]]['time'] = $d[2];
191
                $top[$d[1]]['time'] = $d[2];
188
                $top[$d[1]]['rx']   = $d[3] * 1024 + $d[5];
192
                $top[$d[1]]['rx']   = $d[3] * 1024 + $d[5];
189
                $top[$d[1]]['tx']   = $d[4] * 1024 + $d[6];
193
                $top[$d[1]]['tx']   = $d[4] * 1024 + $d[6];
190
                $top[$d[1]]['act']  = $d[7];
194
                $top[$d[1]]['act']  = $d[7];
-
 
195
                if($use_label)
-
 
196
                {
191
                $top[$d[1]]['label'] = strftime(T('datefmt_top'), $d[2]);
197
                    $top[$d[1]]['label'] = strftime(T('datefmt_top'), $d[2]);
192
                $top[$d[1]]['img_label'] = '';
198
                    $top[$d[1]]['img_label'] = '';
-
 
199
                }
193
            }
200
            }
194
            else
201
            else
195
            {
202
            {
196
                $summary[$d[0]] = isset($d[1]) ? $d[1] : '';
203
                $summary[$d[0]] = isset($d[1]) ? $d[1] : '';
197
            }
204
            }
198
        }
205
        }
199
        if (count($day) == 0)
-
 
200
            $day[0] = 'nodata';
-
 
201
        rsort($day);
-
 
202
 
206
 
203
        if (count($month) == 0)
207
        rsort($day);
204
            $month[0] = 'nodata';
-
 
205
        rsort($month);
208
        rsort($month);
206
 
-
 
207
        if (count($hour) == 0)
-
 
208
            $hour[0] = 'nodata';
-
 
209
        rsort($hour);
209
        rsort($hour);
210
    }
210
    }
211
?>
211
?>