Subversion Repositories ALCASAR

Rev

Rev 3091 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3091 Rev 3106
Line 76... Line 76...
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)) {
Line 111... Line 121...
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++;
Line 131... Line 169...
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++;
Line 144... Line 181...
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
				}
Line 160... Line 198...
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
				}
Line 186... Line 226...
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
}