PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.8.8
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.8.8
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 / fw_livelog.php
ninjafirewall / lib Last commit date
share 9 years ago .htaccess 11 years ago anti_malware.php 5 years ago class-coupon.php 7 months ago class-email-sodium.php 1 month ago class-firewall-log.php 1 month 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-nfw-session.php 1 month ago class-php-session.php 1 year ago class-plugin-upgrade.php 1 month ago class_mail.php 1 month ago event_updates.php 11 months ago firewall.php 5 months ago fw_centlog.php 1 month ago fw_fileguard.php 5 months ago fw_livelog.php 1 year ago help.php 1 month ago helpers.php 1 month ago i18n-extra.php 1 month 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 7 months ago loader.php 7 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 2 months ago scheduled_tasks.php 3 years ago settings_dashboard.php 2 months ago settings_dashboard_about.php 1 month ago settings_dashboard_statistics.php 2 months ago settings_event_notifications.php 2 months ago settings_events.php 2 months ago settings_firewall_options.php 2 months ago settings_firewall_policies.php 1 month ago settings_login_protection.php 2 months ago settings_logs.php 2 months ago settings_logs_firewall_log.php 1 month ago settings_logs_live_log.php 2 months ago settings_monitoring.php 1 month 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 2 months ago settings_security_rules_update.php 1 month ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 5 months ago
fw_livelog.php
145 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
18 */
19
20 if (! isset( $nfw_['nfw_options']['enabled']) ) {
21 header('HTTP/1.1 404 Not Found');
22 header('Status: 404 Not Found');
23 exit;
24 }
25
26 /* ------------------------------------------------------------------ */
27
28 function fw_livelog_show() {
29
30 global $nfw_;
31
32 $nfw_['livelog'] = $nfw_['log_dir'] . '/cache/livelog.php';
33 if ( is_file( $nfw_['livelog'] ) ) {
34 // Check if we need to flush it :
35 if ($_POST['livecls'] > 0) {
36 @file_put_contents( $nfw_['livelog'], '<?php exit; ?>', LOCK_EX);
37 }
38 $count = 0;
39 $buffer = '';
40 if ( $fh = fopen($nfw_['livelog'], 'r' ) ) {
41 while (! feof($fh) ) {
42 if ( $count >= $_POST['lines'] ) {
43 $buffer .= fgets($fh);
44 } else {
45 fgets($fh);
46 }
47 ++$count;
48 }
49 fclose($fh);
50 }
51
52 // Return the log content :
53 header('HTTP/1.0 200 OK');
54 if ( $buffer ) {
55 echo '^'.$buffer;
56 } else {
57 echo '*';
58 }
59 touch($nfw_['log_dir'] .'/cache/livelogrun.php');
60 } else {
61 // Something went wrong :
62 header('HTTP/1.0 503 Service Unavailable');
63 }
64 exit;
65 }
66
67 /* ------------------------------------------------------------------ */
68 function fw_livelog_record() {
69
70 global $nfw_;
71
72 $nfw_['mtime'] = filemtime($nfw_['log_dir'] .'/cache/livelogrun.php');
73 $now = time();
74
75 // If the file was not accessed for more than 100s, we assume
76 // the admin has stopped using live log from WordPress
77 // dashboard (max refresh rate is 45s) :
78 if ( $now - $nfw_['mtime'] > 100 ) {
79 unlink($nfw_['log_dir'] .'/cache/livelogrun.php');
80 // If the log was not modified for the past 10mn, we delete it as well :
81 $nfw_['livelog'] = $nfw_['log_dir'] . '/cache/livelog.php';
82 if ( is_file( $nfw_['livelog'] ) ) {
83 $nfw_['mtime'] = filemtime($nfw_['livelog']);
84 if ( $now - $nfw_['mtime'] > 600 ) {
85 unlink( $nfw_['livelog'] );
86 }
87 }
88 } else {
89
90 // Check if we are supposed to log the request (http/https) :
91 if ( empty($nfw_['nfw_options']['liveport']) ||
92 ($nfw_['nfw_options']['liveport'] == 1 && NFW_IS_HTTPS == false) ||
93 ($nfw_['nfw_options']['liveport'] == 2 && NFW_IS_HTTPS == true) ) {
94
95 // Inclusion and exclusion rules:
96 if (! empty( $nfw_['nfw_options']['liverules'] ) && ! empty( $nfw_['nfw_options']['liverulespath'] ) ) {
97 $liverulespath = preg_quote( $nfw_['nfw_options']['liverulespath'], '/' );
98 $liverulespath = str_replace(',', '|', $liverulespath);
99
100 // Must include:
101 if ( $nfw_['nfw_options']['liverules'] == 1 ) {
102 if (! preg_match("/$liverulespath/", $_SERVER['REQUEST_URI']) ) { return; }
103 // Must not include:
104 } else {
105 if ( preg_match("/$liverulespath/", $_SERVER['REQUEST_URI']) ) { return; }
106 }
107 }
108
109 if ( empty($_SERVER['PHP_AUTH_USER']) ) { $PHP_AUTH_USER = '-'; }
110 else { $PHP_AUTH_USER = $_SERVER['PHP_AUTH_USER']; }
111 if ( empty($_SERVER['HTTP_REFERER']) ) { $HTTP_REFERER = '-'; }
112 else { $HTTP_REFERER = $_SERVER['HTTP_REFERER']; }
113 if ( empty($_SERVER['HTTP_USER_AGENT']) ) { $HTTP_USER_AGENT = '-'; }
114 else { $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; }
115 if ( empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { $HTTP_X_FORWARDED_FOR = '-'; }
116 else { $HTTP_X_FORWARDED_FOR = $_SERVER['HTTP_X_FORWARDED_FOR']; }
117 if ( empty($_SERVER['HTTP_HOST']) ) { $HTTP_HOST = '-'; }
118 else { $HTTP_HOST = $_SERVER['HTTP_HOST']; }
119
120 // Set the user-defined timezone
121 if (! empty($nfw_['nfw_options']['livetz']) ) {
122 @date_default_timezone_set($nfw_['nfw_options']['livetz']);
123 }
124
125 // Log the request :
126 if (! empty($nfw_['nfw_options']['liveformat']) ) {
127 // User-defined format :
128 $nfw_['tmp'] = str_replace(
129 array( '%time', '%name', '%client', '%method', '%uri', '%referrer', '%ua', '%forward', '%host' ),
130 array( date('d/M/y:H:i:s O', time()), $PHP_AUTH_USER, $_SERVER["REMOTE_ADDR"], $_SERVER["REQUEST_METHOD"], $_SERVER["REQUEST_URI"], $HTTP_REFERER, $HTTP_USER_AGENT, $HTTP_X_FORWARDED_FOR, $HTTP_HOST ), $nfw_['nfw_options']['liveformat'] );
131 @file_put_contents( $nfw_['log_dir'] . '/cache/livelog.php', htmlentities($nfw_['tmp'], ENT_NOQUOTES) ."\n", FILE_APPEND | LOCK_EX);
132 } else {
133 // Default format :
134 @file_put_contents( $nfw_['log_dir'] . '/cache/livelog.php',
135 '['. @date('d/M/y:H:i:s O', time()) .'] '. htmlentities(
136 $PHP_AUTH_USER .' '. $_SERVER['REMOTE_ADDR'] .' "'. $_SERVER['REQUEST_METHOD'] .' '.
137 $_SERVER['REQUEST_URI'] .'" "'. $HTTP_REFERER .'" "'. $HTTP_USER_AGENT .'" "'.
138 $HTTP_X_FORWARDED_FOR .'" "'. $HTTP_HOST, ENT_NOQUOTES) ."\"\n", FILE_APPEND | LOCK_EX);
139 }
140 }
141 }
142 }
143 /* ------------------------------------------------------------------ */
144 // EOF
145