PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.9
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.9
4.9 4.8.8 4.8.7 4.8.6 trunk 4.5 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6 4.6.1 4.7 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5
ninjafirewall / lib / settings_dashboard_statistics.php
ninjafirewall / lib Last commit date
share 9 years ago .htaccess 11 years ago anti_malware.php 5 years ago class-api.php 4 weeks ago class-centralised-logging.php 4 weeks ago class-coupon.php 7 months ago class-email-sodium.php 4 weeks ago class-firewall-log.php 4 weeks ago class-helpers.php 9 months ago class-import-export.php 5 months ago class-ip.php 5 months ago class-nfw-database.php 7 months ago class-plugin-upgrade.php 4 weeks ago class-security-updates.php 4 weeks ago class-session.php 4 weeks ago class_mail.php 4 weeks ago firewall.php 4 weeks ago fw_fileguard.php 5 months ago fw_livelog.php 1 year ago help.php 4 weeks ago helpers.php 4 weeks ago i18n-extra.php 4 weeks ago i18n.php 1 year ago index.html 13 years ago init_update.php 2 years ago install.php 1 year ago install_default.php 4 weeks ago loader.php 7 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 4 weeks ago scheduled_tasks.php 3 years ago settings_dashboard.php 4 weeks ago settings_dashboard_about.php 4 weeks ago settings_dashboard_statistics.php 2 months ago settings_event_notifications.php 4 weeks ago settings_events.php 2 months ago settings_firewall_options.php 2 months ago settings_firewall_policies.php 4 weeks ago settings_login_protection.php 2 months ago settings_logs.php 4 weeks ago settings_logs_firewall_log.php 4 weeks ago settings_logs_live_log.php 2 months ago settings_monitoring.php 4 weeks ago settings_monitoring_file_check.php 2 months ago settings_monitoring_file_guard.php 2 months ago settings_network.php 2 months ago settings_security_rules.php 2 months ago settings_security_rules_editor.php 4 weeks ago settings_security_rules_update.php 4 weeks ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 5 months ago
settings_dashboard_statistics.php
211 lines
1 <?php
2 /*
3 +---------------------------------------------------------------------+
4 | NinjaFirewall (WP Edition) |
5 | |
6 | (c) NinTechNet - https://nintechnet.com/ |
7 +---------------------------------------------------------------------+
8 | This program is free software: you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License as |
10 | published by the Free Software Foundation, either version 3 of |
11 | the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 +---------------------------------------------------------------------+ i18n++ / sa / 2
18 */
19
20 if (! defined( 'NFW_ENGINE_VERSION' ) ) { die( 'Forbidden' ); }
21
22 // Display a one-time notice after two weeks of use:
23 $nfw_options = nfw_get_option( 'nfw_options' );
24 nfw_rate_notice( $nfw_options );
25
26 $slow = 0; $tot_bench = 0; $speed = 0; $fast = 1000;
27
28 // Which monthly log should we read ?
29 if ( empty( $_GET['statx'] ) || ! preg_match('/^\d{4}-\d{2}$/D', $_GET['statx'] ) ) {
30 $statx = date('Y-m');
31 } else {
32 $statx = $_GET['statx'];
33 }
34 // Make sure the stat file exists:
35 $stat_file = NFW_LOG_DIR . "/nfwlog/stats_{$statx}.php";
36 // Parse it:
37 if ( file_exists( $stat_file ) ) {
38 $nfw_stat = file_get_contents( $stat_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
39 $nfw_stat = str_replace( '<?php exit; ?>', '', $nfw_stat );
40 } else {
41 $nfw_stat = '0:0:0:0:0:0:0:0:0:0';
42 goto NO_STATS;
43 }
44 // Look for the corresponding firewall log:
45 $log_file = NFW_LOG_DIR . "/nfwlog/firewall_{$statx}.php";
46 if ( file_exists( $log_file ) ) {
47 $fh = @fopen( $log_file, 'r', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
48 // Fetch processing times to output benchmarks:
49 while (! feof( $fh ) ) {
50 $line = fgets( $fh );
51 if ( preg_match( '/^\[.+?\]\s+\[(.+?)\]/', $line, $match ) ) {
52 if ( $match[1] == 0 ) { continue; }
53 if ( $match[1] > $slow ) {
54 $slow = $match[1];
55 }
56 if ( $match[1] < $fast ) {
57 $fast = $match[1];
58 }
59 $speed += $match[1];
60 ++$tot_bench;
61 }
62 }
63 fclose( $fh );
64 }
65
66 NO_STATS:
67 list( $tmp, $medium, $high, $critical ) = explode( ':', $nfw_stat );
68 $medium = (int) $medium;
69 $high = (int) $high;
70 $critical = (int) $critical;
71 $total = $critical + $high + $medium;
72 $c = $critical; $h = $high; $m = $medium;
73 if ( $total == 1 ) { $fast = $slow; }
74
75 if (! $total ) {
76 echo '<div class="nfw-notice nfw-notice-orange"><p>' . esc_html__('You do not have any stats for the selected month yet.', 'ninjafirewall') . '</p></div>';
77 $fast = 0;
78 } else {
79 $coef = 100 / $total;
80 $critical = round( $critical * $coef, 2 );
81 $high = round( $high * $coef, 2 );
82 $medium = round( $medium * $coef, 2 );
83 // Avoid divide error :
84 if ($tot_bench) {
85 $speed = round( $speed / $tot_bench, 4 );
86 } else {
87 $fast = 0;
88 }
89 }
90
91 ?><h3><?php esc_html_e('Monthly Statistics', 'ninjafirewall') ?></h3>
92 <table class="form-table nfw-table">
93 <tr>
94 <th scope="row" class="row-med"><?php esc_html_e('Select a month', 'ninjafirewall') ?></th>
95 <td style="vertical-align: middle;"><?php echo summary_stats_combo( $statx ) ?></td>
96 </tr>
97 <tr>
98 <th scope="row" class="row-med"><?php esc_html_e('Blocked threats', 'ninjafirewall') ?></th>
99 <td><?php echo $total ?></td>
100 </tr>
101 <tr>
102 <th scope="row" class="row-med"><?php esc_html_e('Threats level', 'ninjafirewall') ?></th>
103 <td><canvas id="nfw_stats"></canvas></td>
104 </tr>
105 <tr>
106 <th scope="row" class="row-med"><h3><?php esc_html_e('Benchmarks', 'ninjafirewall') ?> <span class="ninjafirewall-tip" data-tip="<?php esc_attr_e('In the Premium version of NinjaFirewall and on compatible servers, you can use Unix shared memory to speed up the processing of each HTTP request by the firewall.', 'ninjafirewall' ) ?>"></span></h3></th>
107 <td>&nbsp;</td><td>&nbsp;</td>
108 </tr>
109 <tr>
110 <th scope="row" class="row-med"><?php esc_html_e('Average time per request', 'ninjafirewall') ?></th>
111 <td><?php echo $speed ?> <?php esc_html_e('seconds', 'ninjafirewall') ?></td>
112 </tr>
113 <tr>
114 <th scope="row" class="row-med"><?php esc_html_e('Fastest request', 'ninjafirewall') ?></th>
115 <td><?php echo round( $fast, 4) ?> <?php esc_html_e('seconds', 'ninjafirewall') ?></td>
116 </tr>
117 <tr>
118 <th scope="row" class="row-med"><?php esc_html_e('Slowest request', 'ninjafirewall') ?></th>
119 <td><?php echo round( $slow, 4) ?> <?php esc_html_e('seconds', 'ninjafirewall') ?></td>
120 </tr>
121 </table>
122
123 <script type="text/javascript">
124 window.onload = function() {
125 var ctx = document.getElementById('nfw_stats').getContext('2d');
126 var myChart = new Chart(ctx, {
127 type: 'bar',
128 data: {
129 labels: [
130 "<?php echo esc_attr__('Critical', 'ninjafirewall') .': '. $critical ?>%",
131 "<?php echo esc_attr__('High', 'ninjafirewall') .': '. $high ?>%",
132 "<?php echo esc_attr__('Medium', 'ninjafirewall') .': '. $medium ?>%"
133 ],
134 datasets: [{
135 label: '<?php esc_attr_e('Blocked threats', 'ninjafirewall') ?>',
136 data: [<?php echo "{$c}, {$h}, {$m}" ?>],
137 backgroundColor: ['rgba(201, 48, 44, .8)', 'rgba(236, 151, 31, .8)', 'rgba(236, 232, 31, .8)'],
138 hoverBackgroundColor: ['rgba(201, 48, 44, 1)', 'rgba(236, 151, 31, 1)', 'rgba(236, 232, 31, 1)'],
139 borderColor: ['#8C2C2A', '#c9302c', '#ec971f'],
140 borderWidth: 1
141 }]
142 },
143 options: {
144 indexAxis: 'y',
145 scales: {
146 y: {
147 beginAtZero: true
148 }
149 },
150 responsive: true,
151 plugins: {
152 legend: {
153 display: false
154 },
155 tooltip: {
156 borderWidth: 1,
157 borderColor: '#666',
158 displayColors: false,
159 backgroundColor: '#F5F5B5',
160 titleColor:'#666',
161 padding: 8,
162 footerColor: '#666',
163 callbacks: {
164 labelTextColor: function(context) {
165 return '#543453';
166 }
167 }
168 }
169 }
170 }
171 });
172 }
173 </script>
174 <?php
175
176 // ---------------------------------------------------------------------
177 function summary_stats_combo( $statx ) {
178
179 // Find all stat files:
180 $avail_logs = array();
181 if ( is_dir( NFW_LOG_DIR . '/nfwlog/' ) ) {
182 if ( $dh = opendir( NFW_LOG_DIR . '/nfwlog/' ) ) {
183 while ( ( $file = readdir( $dh ) ) !== false ) {
184 if (preg_match( '/^stats_(\d{4})-(\d\d)\.php$/', $file, $match ) ) {
185 $month = ucfirst( date_i18n('F', mktime(0, 0, 0, $match[2], 1, 2000) ) );
186 $avail_logs["{$match[1]}-{$match[2]}" ] = "{$month} {$match[1]}";
187 }
188 }
189 closedir( $dh );
190 }
191 }
192 krsort( $avail_logs );
193
194 $ret = '<form>
195 <select class="input" name="statx" onChange="return nfwjs_stat_redir(this.value);">
196 <option value="">' . esc_html__('Select monthly stats to view...', 'ninjafirewall') . '</option>';
197 foreach ( $avail_logs as $file => $text ) {
198 $ret .= '<option value="'. $file .'"';
199 if ($file === $statx ) {
200 $ret .= ' selected';
201 }
202 $ret .= ">{$text}</option>";
203 }
204 $ret .= '</select>
205 </form>';
206 return $ret;
207 }
208
209 // ---------------------------------------------------------------------
210 // EOF
211