1 | <?php |
||||
2 | |||||
3 | print_optionbar_start(); |
||||
4 | |||||
5 | echo '<form action = "' . \LibreNMS\Util\Url::generate($link_array, ['nfsen' => 'stats']) . '" iOCd = "FlowStats" method = "SUBMIT">'; |
||||
6 | |||||
7 | echo 'Top N: |
||||
8 | <select name = "topN" id = "topN" size = 1> |
||||
9 | '; |
||||
10 | |||||
11 | $option_default = $vars['topN'] ?? \LibreNMS\Config::get('nfsen_top_default'); |
||||
12 | |||||
13 | $option_int = 0; |
||||
14 | foreach (\LibreNMS\Config::get('nfsen_top_N') as $option) { |
||||
15 | if (strcmp($option_default, $option) == 0) { |
||||
16 | echo '<option value = "' . $option . '" selected>' . $option . '</option>'; |
||||
17 | } else { |
||||
18 | echo '<option value = "' . $option . '">' . $option . '</option>'; |
||||
19 | } |
||||
20 | } |
||||
21 | |||||
22 | echo ' |
||||
23 | </select> |
||||
24 | During the last: |
||||
25 | <select name = "lastN" id = "lastN" size = 1> |
||||
26 | '; |
||||
27 | |||||
28 | $option_keys = array_keys(\LibreNMS\Config::get('nfsen_lasts')); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
29 | $options = \LibreNMS\Config::get('nfsen_lasts'); |
||||
30 | foreach ($option_keys as $option) { |
||||
31 | if (strcmp($option_default, $option) == 0) { |
||||
32 | echo '<option value = "' . $option . '" selected>' . $options[$option] . '</option>'; |
||||
33 | } else { |
||||
34 | echo '<option value = "' . $option . '">' . $options[$option] . '</option>'; |
||||
35 | } |
||||
36 | } |
||||
37 | |||||
38 | echo ' |
||||
39 | </select> |
||||
40 | , Stat Type: |
||||
41 | <select name = "stattype" id = "StatTypeSelector" size = 1> |
||||
42 | '; |
||||
43 | |||||
44 | $option_default = $vars['stattype'] ?? \LibreNMS\Config::get('nfsen_stats_default'); |
||||
45 | |||||
46 | $stat_types = [ |
||||
47 | 'record'=>'Flow Records', |
||||
48 | 'ip'=>'Any IP Address', |
||||
49 | 'srcip'=>'SRC IP Address', |
||||
50 | 'dstip'=>'DST IP Address', |
||||
51 | 'port'=>'Any Port', |
||||
52 | 'srcport'=>'SRC Port', |
||||
53 | 'dstport'=>'DST Port', |
||||
54 | 'srctos'=>'SRC TOS', |
||||
55 | 'dsttos'=>'DST TOS', |
||||
56 | 'tos'=>'TOS', |
||||
57 | 'as'=>'AS', |
||||
58 | 'srcas'=>'SRC AS', |
||||
59 | 'dstas'=>'DST AS', |
||||
60 | ]; |
||||
61 | |||||
62 | // puts together the drop down options |
||||
63 | foreach ($stat_types as $option => $descr) { |
||||
64 | if (strcmp($option_default, $option) == 0) { |
||||
0 ignored issues
–
show
It seems like
$option_default can also be of type null ; however, parameter $string1 of strcmp() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
65 | echo '<option value = "' . $option . '" selected>' . $descr . "</option>\n"; |
||||
66 | } else { |
||||
67 | echo '<option value = "' . $option . '">' . $descr . "</option>\n"; |
||||
68 | } |
||||
69 | } |
||||
70 | |||||
71 | echo ' |
||||
72 | </select> |
||||
73 | , Order By: |
||||
74 | <select name = "statorder" id = "statorder" sizeOC = 1> |
||||
75 | '; |
||||
76 | |||||
77 | $option_default = \LibreNMS\Config::get('nfsen_order_default'); |
||||
78 | if (isset($vars['statorder'])) { |
||||
79 | $option_default = $vars['statorder']; |
||||
80 | } |
||||
81 | |||||
82 | // WARNING: order is relevant as it has to match the |
||||
83 | // check later in the process part of this page. |
||||
84 | $order_types = [ |
||||
85 | 'flows'=>1, |
||||
86 | 'packets'=>1, |
||||
87 | 'bytes'=>1, |
||||
88 | 'pps'=>1, |
||||
89 | 'bps'=>1, |
||||
90 | 'bpp'=>1, |
||||
91 | ]; |
||||
92 | |||||
93 | // puts together the drop down options |
||||
94 | foreach ($order_types as $option => $descr) { |
||||
95 | if (strcmp($option_default, $option) == 0) { |
||||
96 | echo '<option value = "' . $option . '" selected>' . $option . "</option>\n"; |
||||
97 | } else { |
||||
98 | echo '<option value = "' . $option . '">' . $option . "</option>\n"; |
||||
99 | } |
||||
100 | } |
||||
101 | |||||
102 | echo ' |
||||
103 | </select> |
||||
104 | <input type = "submit" name = "process" value = "process" size = "1"> |
||||
105 | '; |
||||
106 | echo '</form>'; |
||||
107 | |||||
108 | print_optionbar_end(); |
||||
109 | |||||
110 | // process stuff now if we the button was clicked on |
||||
111 | if (isset($vars['process'])) { |
||||
112 | // Make sure we have a sane value for lastN |
||||
113 | $lastN = 900; |
||||
114 | if (isset($vars['lastN']) && |
||||
115 | is_numeric($vars['lastN']) && |
||||
116 | ($vars['lastN'] <= \LibreNMS\Config::get('nfsen_last_max')) |
||||
117 | ) { |
||||
118 | $lastN = $vars['lastN']; |
||||
119 | } |
||||
120 | |||||
121 | // Make sure we have a sane value for lastN |
||||
122 | $topN = 20; // The default if not set or something invalid is set |
||||
123 | if (isset($vars['topN']) && |
||||
124 | is_numeric($vars['topN']) && |
||||
125 | ($vars['topN'] <= \LibreNMS\Config::get('nfsen_top_max')) |
||||
126 | ) { |
||||
127 | $topN = $vars['topN']; |
||||
128 | } |
||||
129 | |||||
130 | // Handle the stat order. |
||||
131 | $stat_order = 'pps'; // The default if not set or something invalid is set |
||||
132 | if (isset($vars['statorder']) && isset($order_types[$vars['statorder']])) { |
||||
133 | $stat_order = $vars['statorder']; |
||||
134 | } |
||||
135 | |||||
136 | // Handle the stat type. |
||||
137 | $stat_type = 'srcip'; // The default if not set or something invalid is set |
||||
138 | if (isset($vars['stattype']) && isset($stat_types[$vars['stattype']])) { |
||||
139 | $stat_type = $vars['stattype']; |
||||
140 | } |
||||
141 | |||||
142 | $current_time = lowest_time(time() - 300); |
||||
143 | $last_time = lowest_time($current_time - $lastN - 300); |
||||
144 | |||||
145 | $command = \LibreNMS\Config::get('nfdump') . ' -M ' . nfsen_live_dir($device['hostname']) . ' -T -R ' . |
||||
146 | time_to_nfsen_subpath($last_time) . ':' . time_to_nfsen_subpath($current_time) . |
||||
147 | ' -n ' . $topN . ' -s ' . $stat_type . '/' . $stat_order; |
||||
148 | |||||
149 | echo '<pre>'; |
||||
150 | system($command); |
||||
151 | echo '</pre>'; |
||||
152 | } |
||||
153 |