-
Notifications
You must be signed in to change notification settings - Fork 25
/
mactrack_vendormacs.php
268 lines (225 loc) · 7.95 KB
/
mactrack_vendormacs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
include('./include/auth.php');
include_once('./plugins/mactrack/lib/mactrack_functions.php');
set_default_action();
if (isset_request_var('export')) {
mactrack_vmacs_export();
} else {
top_header();
mactrack_vmacs();
bottom_footer();
}
function mactrack_vmacs_validate_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'vendor_mac',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_mt_vmacs');
/* ================= input validation ================= */
}
function mactrack_vmacs_export() {
global $site_actions, $config;
mactrack_vmacs_validate_request_vars();
$sql_where = '';
$vmacs = mactrack_vmacs_get_vmac_records($sql_where, 0, false);
$xport_array = array();
array_push($xport_array, '"vendor_mac","vendor_name","vendor_address"');
if (cacti_sizeof($vmacs)) {
foreach($vmacs as $vmac) {
array_push($xport_array,'"' . $vmac['vendor_mac'] . '","' .
$vmac['vendor_name'] . '","' .
$vmac['vendor_address'] . '"');
}
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=cacti_site_xport.csv');
foreach($xport_array as $xport_line) {
print $xport_line . "\n";
}
}
function mactrack_vmacs_get_vmac_records(&$sql_where, $rows, $apply_limits = true) {
$sql_where = '';
/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = "WHERE (mac_track_oui_database.vendor_name LIKE '%" . get_request_var('filter') . "%' OR " .
"mac_track_oui_database.vendor_mac LIKE '%" . get_request_var('filter') . "%' OR " .
"mac_track_oui_database.vendor_address LIKE '%" . get_request_var('filter') . "%')";
}
$sql_order = get_order_string();
if ($apply_limits) {
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ', ' . $rows;
} else {
$sql_limit = '';
}
$query_string = "SELECT *
FROM mac_track_oui_database
$sql_where
$sql_order
$sql_limit";
return db_fetch_assoc($query_string);
}
function mactrack_vmacs() {
global $site_actions, $config, $item_rows;
mactrack_vmacs_validate_request_vars();
if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} elseif (get_request_var('rows') == -2) {
$rows = 999999;
} else {
$rows = get_request_var('rows');
}
html_start_box(__('Mactrack Vendor Mac Filter', 'mactrack'), '100%', '', '3', 'center', '');
mactrack_vmac_filter();
html_end_box();
$sql_where = '';
$vmacs = mactrack_vmacs_get_vmac_records($sql_where, $rows);
$total_rows = db_fetch_cell("SELECT
COUNT(*)
FROM mac_track_oui_database
$sql_where");
$display_text = array(
'vendor_mac' => array(__('Vendor MAC', 'mactrack'), 'ASC'),
'vendor_name' => array(__('Corporation', 'mactrack'), 'ASC'),
'vendor_address' => array(__('Address', 'mactrack'), 'ASC')
);
$columns = cacti_sizeof($display_text);
$nav = html_nav_bar('mactrack_vendormacs.php', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, $columns, __('Vendor Macs', 'mactrack'), 'page', 'main');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
if (cacti_sizeof($vmacs)) {
foreach ($vmacs as $vmac) {
form_alternate_row();
?>
<td class='linkEditMain'><?php print $vmac['vendor_mac'];?></td>
<td><?php print filter_value($vmac['vendor_name'], get_request_var('filter'));?></td>
<td><?php print filter_value($vmac['vendor_address'], get_request_var('filter'));?></td>
</tr>
<?php
}
} else {
print '<tr><td colspen="' . $columns . '"><em>' . __('No Mactrack Vendor MACS Found', 'mactrack') . '</em></td></tr>';
}
html_end_box(false);
if (cacti_sizeof($vmacs)) {
print $nav;
}
}
function mactrack_vmac_filter() {
global $item_rows;
?>
<tr class='even'>
<td>
<form id='mactrack'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search', 'mactrack');?>
</td>
<td>
<input type='text' id='filter' size='25' value='<?php print get_request_var('filter');?>'>
</td>
<td>
<?php print __('MAC\'s', 'mactrack');?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack');?></option>
<?php
if (cacti_sizeof($item_rows) > 0) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . $value . '</option>';
}
}
?>
</select>
</td>
<td>
<span class='nowrap'>
<input type='submit' id='go' value='<?php print __esc('Go', 'mactrack');?>'>
<input type='button' id='clear' value='<?php print __esc('Clear', 'mactrack');?>'>
<input type='button' id='export' value='<?php print __esc('Export', 'mactrack');?>'>
</span>
</td>
</tr>
</table>
</form>
<script type='text/javascript'>
function applyFilter() {
strURL = urlPath+'plugins/mactrack/mactrack_vendormacs.php?header=false';
strURL += '&filter=' + $('#filter').val();
strURL += '&rows=' + $('#rows').val();
loadPageNoHeader(strURL);
}
function clearFilter() {
strURL = urlPath+'plugins/mactrack/mactrack_vendormacs.php?header=false&clear=true';
loadPageNoHeader(strURL);
}
function exportRows() {
strURL = urlPath+'plugins/mactrack/mactrack_vendormacs.php?export=true';
document.location = strURL;
}
$(function() {
$('#mactrack').submit(function(event) {
event.preventDefault();
applyFilter();
});
$('#clear').click(function() {
clearFilter();
});
$('#export').click(function() {
exportRows();
});
});
</script>
</td>
</tr>
<?php
}