Subversion Repositories ALCASAR

Rev

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

Rev 3091 Rev 3106
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * Copyright (C) 2019 Alexander Marston (alexander.marston@gmail.com)
4
 * Copyright (C) 2019 Alexander Marston (alexander.marston@gmail.com)
5
 *
5
 *
6
 * This program is free software: you can redistribute it and/or modify
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
9
 * (at your option) any later version.
10
 *
10
 *
11
 * This program is distributed in the hope that it will be useful,
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
14
 * GNU General Public License for more details.
15
 *
15
 *
16
 * You should have received a copy of the GNU General Public License
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
18
 */
19
 
19
 
20
class vnStat {
20
class vnStat {
21
	protected $executablePath;
21
	protected $executablePath;
22
	protected $vnstatVersion;
22
	protected $vnstatVersion;
23
	protected $vnstatJsonVersion;
23
	protected $vnstatJsonVersion;
24
	protected $vnstatData;
24
	protected $vnstatData;
25
 
25
 
26
	public function __construct ($executablePath) {
26
	public function __construct ($executablePath) {
27
		if (isset($executablePath)) {
27
		if (isset($executablePath)) {
28
			$this->executablePath = $executablePath;
28
			$this->executablePath = $executablePath;
29
 
29
 
30
			// Execute a command to output a json dump of the vnstat data
30
			// Execute a command to output a json dump of the vnstat data
31
			$vnstatStream = popen("$this->executablePath --json", 'r');
31
			$vnstatStream = popen("$this->executablePath --json", 'r');
32
 
32
 
33
			// Is the stream valid?
33
			// Is the stream valid?
34
			if (is_resource($vnstatStream)) {
34
			if (is_resource($vnstatStream)) {
35
				$streamBuffer = '';
35
				$streamBuffer = '';
36
 
36
 
37
				while (!feof($vnstatStream)) {
37
				while (!feof($vnstatStream)) {
38
					$streamBuffer .= fgets($vnstatStream);
38
					$streamBuffer .= fgets($vnstatStream);
39
				}
39
				}
40
 
40
 
41
				// Close the handle
41
				// Close the handle
42
				pclose($vnstatStream);
42
				pclose($vnstatStream);
43
 
43
 
44
				$this->processVnstatData($streamBuffer);
44
				$this->processVnstatData($streamBuffer);
45
			} else {
45
			} else {
46
 
46
 
47
			}
47
			}
48
 
48
 
49
 
49
 
50
		} else {
50
		} else {
51
			die();
51
			die();
52
		}
52
		}
53
	}
53
	}
54
 
54
 
55
	private function processVnstatData($vnstatJson) {
55
	private function processVnstatData($vnstatJson) {
56
		$decodedJson = json_decode($vnstatJson, true);
56
		$decodedJson = json_decode($vnstatJson, true);
57
 
57
 
58
		// Check the JSON is valid
58
		// Check the JSON is valid
59
		if (json_last_error() != JSON_ERROR_NONE) {
59
		if (json_last_error() != JSON_ERROR_NONE) {
60
			throw new Exception('JSON is invalid');
60
			throw new Exception('JSON is invalid');
61
		}
61
		}
62
 
62
 
63
		$this->vnstatData = $decodedJson;
63
		$this->vnstatData = $decodedJson;
64
		$this->vnstatVersion = $decodedJson['vnstatversion'];
64
		$this->vnstatVersion = $decodedJson['vnstatversion'];
65
		$this->vnstatJsonVersion = $decodedJson['jsonversion'];
65
		$this->vnstatJsonVersion = $decodedJson['jsonversion'];
66
	}
66
	}
67
 
67
 
68
	public function getVnstatVersion() {
68
	public function getVnstatVersion() {
69
		return $this->vnstatVersion;
69
		return $this->vnstatVersion;
70
	}
70
	}
71
 
71
 
72
	public function getVnstatJsonVersion() {
72
	public function getVnstatJsonVersion() {
73
		return $this->vnstatJsonVersion;
73
		return $this->vnstatJsonVersion;
74
	}
74
	}
75
 
75
 
76
	public function getInterfaces() {
76
	public function getInterfaces() {
77
		// Create a placeholder array
77
		// Create a placeholder array
78
		$vnstatInterfaces = [];
78
		$vnstatInterfaces = [];
79
 
79
 
80
		foreach($this->vnstatData['interfaces'] as $interface) {
80
		foreach($this->vnstatData['interfaces'] as $interface) {
-
 
81
		    if ($this->vnstatJsonVersion == 1) {
81
			array_push($vnstatInterfaces, $interface['id']);
82
			array_push($vnstatInterfaces, $interface['id']);
-
 
83
		    } else {
-
 
84
			array_push($vnstatInterfaces, $interface['name']);
-
 
85
		    }
82
		}
86
		}
83
 
87
 
84
		return $vnstatInterfaces;
88
		return $vnstatInterfaces;
85
	}
89
	}
86
 
90
 
87
	public function getInterfaceData($timeperiod, $type, $interface) {
91
	public function getInterfaceData($timeperiod, $type, $interface) {
88
		// If json version equals 1, add an 's' onto the end of each type.
92
		// If json version equals 1, add an 's' onto the end of each type.
89
		// e.g. 'top' becomes 'tops'
93
		// e.g. 'top' becomes 'tops'
-
 
94
		$typeAppend = '';
90
		if ($this->vnstatJsonVersion == 1) {
95
		if ($this->vnstatJsonVersion == 1) {
91
			$typeAppend = 's';
96
			$typeAppend = 's';
92
		}
97
		}
93
 
98
 
94
		// Blank placeholder
99
		// Blank placeholder
95
		$trafficData = [];
100
		$trafficData = [];
-
 
101
		$i = -1;
96
 
102
 
97
		// Get the array index for the chosen interface
103
		// Get the array index for the chosen interface
-
 
104
		if ($this->vnstatJsonVersion == 1) {
98
		$arrayIndex = array_search($interface, array_column($this->vnstatData['interfaces'], 'id'));
105
		    $arrayIndex = array_search($interface, array_column($this->vnstatData['interfaces'], 'id'));
-
 
106
                } else {
-
 
107
		    $arrayIndex = array_search($interface, array_column($this->vnstatData['interfaces'], 'name'));
-
 
108
                }
99
 
109
 
100
		if ($timeperiod == 'top10') {
110
		if ($timeperiod == 'top10') {
101
			if ($type == 'table') {
111
			if ($type == 'table') {
102
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['top'.$typeAppend] as $traffic) {
112
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['top'.$typeAppend] as $traffic) {
103
					if (is_array($traffic)) {
113
					if (is_array($traffic)) {
104
						$i++;
114
						$i++;
105
 
115
 
106
						$trafficData[$i]['label'] = date('d/m/Y', strtotime($traffic['date']['month'] . "/" . $traffic['date']['day'] . "/" . $traffic['date']['year']));;
116
						$trafficData[$i]['label'] = date('d/m/Y', strtotime($traffic['date']['month'] . "/" . $traffic['date']['day'] . "/" . $traffic['date']['year']));;
107
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
117
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
108
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
118
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
109
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
119
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
110
                                                $trafficData[$i]['totalraw'] = ($traffic['rx'] + $traffic['tx']);
120
                                                $trafficData[$i]['totalraw'] = ($traffic['rx'] + $traffic['tx']);
111
					}
121
					}
112
				}
122
				}
113
			}
123
			}
114
		}
124
		}
115
 
125
 
-
 
126
		if (($this->vnstatJsonVersion > 1) && ($timeperiod == 'five')) {
-
 
127
			if ($type == 'table') {
-
 
128
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['fiveminute'] as $traffic) {
-
 
129
					if (is_array($traffic)) {
-
 
130
						$i++;
-
 
131
 
-
 
132
						$trafficData[$i]['label'] = date("d/m/Y H:i", mktime($traffic['time']['hour'], $traffic['time']['minute'], 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']));
-
 
133
                                                $trafficData[$i]['time'] =  mktime($traffic['time']['hour'], $traffic['time']['minute'], 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
-
 
134
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
-
 
135
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
-
 
136
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
-
 
137
					}
-
 
138
				}
-
 
139
			} else if ($type == 'graph') {
-
 
140
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['fiveminute'] as $traffic) {
-
 
141
					if (is_array($traffic)) {
-
 
142
						$i++;
-
 
143
 
-
 
144
						$trafficData[$i]['label'] = sprintf("Date(%d, %d, %d, %d, %d)", $traffic['date']['year'], $traffic['date']['month']-1, $traffic['date']['day'], $traffic['time']['hour'], $traffic['time']['minute']);
-
 
145
                                                $trafficData[$i]['time'] =  mktime($traffic['time']['hour'], $traffic['time']['minute'], 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
-
 
146
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
-
 
147
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
-
 
148
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
-
 
149
					}
-
 
150
				}
-
 
151
			}
-
 
152
		}
-
 
153
 
116
		if ($timeperiod == 'hourly') {
154
		if ($timeperiod == 'hourly') {
117
			if ($type == 'table') {
155
			if ($type == 'table') {
118
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['hour'.$typeAppend] as $traffic) {
156
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['hour'.$typeAppend] as $traffic) {
119
					if (is_array($traffic)) {
157
					if (is_array($traffic)) {
120
						$i++;
158
						$i++;
121
 
159
 
122
                                                if ($this->vnstatJsonVersion == 1) {
160
                                                if ($this->vnstatJsonVersion == 1) {
123
                                                    $hour = $traffic['id'];
161
                                                    $hour = $traffic['id'];
124
                                                } else {
162
                                                } else {
125
                                                    $hour = $traffic['time']['hour'];
163
                                                    $hour = $traffic['time']['hour'];
126
                                                }
164
                                                }
127
 
165
 
128
						$trafficData[$i]['label'] = date("d/m/Y H:i", mktime($hour, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']));
166
						$trafficData[$i]['label'] = date("d/m/Y H:i", mktime($hour, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']));
129
                                                $trafficData[$i]['time'] =  mktime($hour, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
167
                                                $trafficData[$i]['time'] =  mktime($hour, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
130
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
168
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
131
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
169
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
132
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
170
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
133
					}
171
					}
134
				}
172
				}
135
 
173
 
136
                               // usort($trafficData, sortingFunction);
-
 
137
 
174
 
138
			} else if ($type == 'graph') {
175
			} else if ($type == 'graph') {
139
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['hour'.$typeAppend] as $traffic) {
176
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['hour'.$typeAppend] as $traffic) {
140
					if (is_array($traffic)) {
177
					if (is_array($traffic)) {
141
						$i++;
178
						$i++;
142
 
179
 
143
                                                if ($this->vnstatJsonVersion == 1) {
180
                                                if ($this->vnstatJsonVersion == 1) {
144
                                                    $hour = $traffic['id'];
181
                                                    $hour = $traffic['id'];
145
                                                } else {
182
                                                } else {
146
                                                    $hour = $traffic['time']['hour'];
183
                                                    $hour = $traffic['time']['hour'];
147
                                                }
184
                                                }
148
 
185
 
149
						$trafficData[$i]['label'] = sprintf("Date(%d, %d, %d, %d, %d, %d)", $traffic['date']['year'], $traffic['date']['month']-1, $traffic['date']['day'], $hour, 0, 0);
186
						$trafficData[$i]['label'] = sprintf("Date(%d, %d, %d, %d)", $traffic['date']['year'], $traffic['date']['month']-1, $traffic['date']['day'], $hour);
-
 
187
                                                $trafficData[$i]['time'] =  mktime($hour, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
150
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
188
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
151
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
189
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
152
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
190
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
153
					}
191
					}
154
				}
192
				}
155
			}
193
			}
156
		}
194
		}
157
 
195
 
158
		if ($timeperiod == 'daily') {
196
		if ($timeperiod == 'daily') {
159
			if ($type == 'table') {
197
			if ($type == 'table') {
160
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['day'.$typeAppend] as $traffic) {
198
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['day'.$typeAppend] as $traffic) {
161
					if (is_array($traffic)) {
199
					if (is_array($traffic)) {
162
						$i++;
200
						$i++;
163
 
201
 
164
						$trafficData[$i]['label'] = date('d/m/Y', mktime(0, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']));
202
						$trafficData[$i]['label'] = date('d/m/Y', mktime(0, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']));
-
 
203
                                                $trafficData[$i]['time'] =  mktime(0, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
165
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
204
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
166
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
205
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
167
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
206
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
168
					}
207
					}
169
				}
208
				}
170
			} else if ($type == 'graph') {
209
			} else if ($type == 'graph') {
171
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['day'.$typeAppend] as $traffic) {
210
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['day'.$typeAppend] as $traffic) {
172
					if (is_array($traffic)) {
211
					if (is_array($traffic)) {
173
						$i++;
212
						$i++;
174
 
213
 
175
						$trafficData[$i]['label'] = sprintf("Date(%d, %d, %d, %d, %d, %d)", $traffic['date']['year'], $traffic['date']['month']-1, $traffic['date']['day'], 0, 0, 0);
214
						$trafficData[$i]['label'] = sprintf("Date(%d, %d, %d)", $traffic['date']['year'], $traffic['date']['month']-1, $traffic['date']['day']);
-
 
215
                                                $trafficData[$i]['time'] =  mktime(0, 0, 0, $traffic['date']['month'], $traffic['date']['day'], $traffic['date']['year']);
176
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
216
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
177
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
217
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
178
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
218
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
179
					}
219
					}
180
				}
220
				}
181
			}
221
			}
182
		}
222
		}
183
 
223
 
184
		if ($timeperiod == 'monthly') {
224
		if ($timeperiod == 'monthly') {
185
			if ($type == 'table') {
225
			if ($type == 'table') {
186
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['month'.$typeAppend] as $traffic) {
226
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['month'.$typeAppend] as $traffic) {
187
					if (is_array($traffic)) {
227
					if (is_array($traffic)) {
188
						$i++;
228
						$i++;
189
 
229
 
190
						$trafficData[$i]['label'] = date('F Y', mktime(0, 0, 0, $traffic['date']['month'], 10, $traffic['date']['year']));
230
						$trafficData[$i]['label'] = date('F Y', mktime(0, 0, 0, $traffic['date']['month'], 10, $traffic['date']['year']));
-
 
231
                                                $trafficData[$i]['time'] =  mktime(0, 0, 0, $traffic['date']['month'], 10, $traffic['date']['year']);
191
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
232
						$trafficData[$i]['rx'] = formatSize($traffic['rx'], $this->vnstatJsonVersion);
192
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
233
						$trafficData[$i]['tx'] = formatSize($traffic['tx'], $this->vnstatJsonVersion);
193
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
234
						$trafficData[$i]['total'] = formatSize(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
194
					}
235
					}
195
				}
236
				}
196
			} else if ($type == 'graph') {
237
			} else if ($type == 'graph') {
197
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['month'.$typeAppend] as $traffic) {
238
				foreach ($this->vnstatData['interfaces'][$arrayIndex]['traffic']['month'.$typeAppend] as $traffic) {
198
					if (is_array($traffic)) {
239
					if (is_array($traffic)) {
199
						$i++;
240
						$i++;
200
 
241
 
201
                                                $trafficData[$i]['label'] = sprintf("Date(%d, %d, %d, %d, %d, %d)", $traffic['date']['year'], $traffic['date']['month'] - 1, 10, 0, 0, 0);
242
                                                $trafficData[$i]['label'] = sprintf("Date(%d, %d, %d)", $traffic['date']['year'], $traffic['date']['month'] - 1, 10);
-
 
243
                                                $trafficData[$i]['time'] =  mktime(0, 0, 0, $traffic['date']['month'], 10, $traffic['date']['year']);
202
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
244
						$trafficData[$i]['rx'] = kibibytesToBytes($traffic['rx'], $this->vnstatJsonVersion);
203
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
245
						$trafficData[$i]['tx'] = kibibytesToBytes($traffic['tx'], $this->vnstatJsonVersion);
204
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
246
						$trafficData[$i]['total'] = kibibytesToBytes(($traffic['rx'] + $traffic['tx']), $this->vnstatJsonVersion);
205
					}
247
					}
206
				}
248
				}
207
			}
249
			}
208
		}
250
		}
209
 
251
 
-
 
252
		if ($timeperiod != 'top10') {
-
 
253
                    usort($trafficData, 'sortingFunction');
-
 
254
                }
-
 
255
 
210
                if ($type == 'graph') {
256
                if ($type == 'graph') {
211
                    // Get the largest value and then prefix (B, KB, MB, GB, etc)
257
                    // Get the largest value and then prefix (B, KB, MB, GB, etc)
212
                    $trafficLargestValue = getLargestValue($trafficData);
258
                    $trafficLargestValue = getLargestValue($trafficData);
-
 
259
                    $trafficScale = getScale($trafficLargestValue);
213
                    $trafficLargestPrefix = getLargestPrefix($trafficLargestValue);
260
                    $trafficLargestPrefix = getLargestPrefix($trafficScale);
-
 
261
                    $trafficBase = getBaseValue($trafficData, $trafficScale);
-
 
262
                    if (($trafficBase < .0099) && ($trafficScale >= 1))
-
 
263
                    {
-
 
264
                        $trafficScale = $trafficScale - 1;
-
 
265
                        $trafficLargestPrefix = getLargestPrefix($trafficScale);
-
 
266
                        $trafficBase = getBaseValue($trafficData, $trafficScale);
-
 
267
                    }
214
 
268
 
215
                    foreach($trafficData as $key => $value) {
269
                    foreach($trafficData as &$value) {
216
                        $trafficData[$key]['rx'] = formatBytesTo($value['rx'], $trafficLargestPrefix);
270
                        $value['rx'] = formatBytesTo($value['rx'], $trafficScale);
217
                        $trafficData[$key]['tx'] = formatBytesTo($value['tx'], $trafficLargestPrefix);
271
                        $value['tx'] = formatBytesTo($value['tx'], $trafficScale);
218
                        $trafficData[$key]['total'] = formatBytesTo($value['total'], $trafficLargestPrefix);
272
                        $value['total'] = formatBytesTo($value['total'], $trafficScale);
219
                        $trafficData[$key]['delimiter'] = $trafficLargestPrefix;
-
 
220
                    }
273
                    }
-
 
274
 
-
 
275
                    unset($value);
-
 
276
                    $trafficData[0]['delimiter'] = $trafficLargestPrefix;
-
 
277
                    $trafficData[0]['base'] = $trafficBase;
221
                }
278
                }
222
 
279
 
223
		return $trafficData;
280
		return $trafficData;
224
	}
281
	}
225
}
282
}
226
 
283
 
227
?>
284
?>
228
 
285