PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / trunk
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall vtrunk
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_events.php
ninjafirewall / lib Last commit date
share 8 years ago .htaccess 11 years ago anti_malware.php 4 years ago class-coupon.php 6 months ago class-email-sodium.php 3 weeks ago class-firewall-log.php 1 week ago class-helpers.php 7 months ago class-import-export.php 3 months ago class-ip.php 4 months ago class-nfw-database.php 6 months ago class-nfw-session.php 1 week ago class-php-session.php 1 year ago class-plugin-upgrade.php 1 week ago class_mail.php 3 weeks ago event_updates.php 9 months ago firewall.php 4 months ago fw_centlog.php 1 week ago fw_fileguard.php 4 months ago fw_livelog.php 1 year ago help.php 3 weeks ago helpers.php 1 week ago i18n-extra.php 3 weeks ago i18n.php 1 year ago index.html 13 years ago init_update.php 1 year ago install.php 1 year ago install_default.php 6 months ago loader.php 6 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 1 month ago scheduled_tasks.php 3 years ago settings_dashboard.php 1 month ago settings_dashboard_about.php 3 weeks ago settings_dashboard_statistics.php 1 month ago settings_event_notifications.php 1 month ago settings_events.php 1 month ago settings_firewall_options.php 1 month ago settings_firewall_policies.php 1 week ago settings_login_protection.php 1 month ago settings_logs.php 1 month ago settings_logs_firewall_log.php 3 weeks ago settings_logs_live_log.php 1 month ago settings_monitoring.php 3 weeks ago settings_monitoring_file_check.php 1 month ago settings_monitoring_file_guard.php 1 month ago settings_network.php 1 month ago settings_security_rules.php 1 month ago settings_security_rules_editor.php 1 month ago settings_security_rules_update.php 1 week ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 3 months ago
settings_events.php
283 lines
1 <?php
2 /*
3 +=====================================================================+
4 | _ _ _ _ _____ _ _ _ |
5 | | \ | (_)_ __ (_) __ _| ___(_)_ __ _____ ____ _| | | |
6 | | \| | | '_ \ | |/ _` | |_ | | '__/ _ \ \ /\ / / _` | | | |
7 | | |\ | | | | || | (_| | _| | | | | __/\ V V / (_| | | | |
8 | |_| \_|_|_| |_|/ |\__,_|_| |_|_| \___| \_/\_/ \__,_|_|_| |
9 | |__/ |
10 | (c) NinTechNet Limited ~ https://nintechnet.com/ |
11 +=====================================================================+
12 */
13
14 if (! defined('NFW_ENGINE_VERSION') ) {
15 die('Forbidden');
16 }
17
18 function nfw_sys_events() {
19
20 $nfw_options = nfw_get_option( 'nfw_options' );
21
22 $script = $_SERVER['SCRIPT_NAME'];
23 $label_name = __('Name:', 'ninjafirewall');
24 $label_plugin = __('Plugin', 'ninjafirewall');
25 $label_theme = __('Theme', 'ninjafirewall');
26 $label_version = __('Version:', 'ninjafirewall');
27 $alert_action = 0;
28
29 /**
30 * themes.php.
31 */
32 if ( strpos( $script, '/themes.php') !== FALSE ) {
33
34 if ( current_user_can('switch_themes') && isset( $_GET['action'] ) ) {
35
36 if ( $_GET['action'] == 'activate' && ! empty( $nfw_options['a_23'] ) ) {
37 $theme = wp_get_theme( $_GET['stylesheet'] );
38 $alert_action = sprintf( '%s %s', $label_theme, __('activated', 'ninjafirewall') );
39 $alert_item = sprintf( '%s %s', $label_name, $theme );
40
41 } elseif ( $_GET['action'] == 'delete' && current_user_can( 'delete_themes' ) &&
42 ! empty( $nfw_options['a_24'] ) ) {
43
44 $theme = wp_get_theme( $_GET['stylesheet'] );
45 $alert_action = sprintf( '%s %s', $label_theme, __('deleted', 'ninjafirewall') );
46 $alert_item = sprintf( '%s %s', $label_name, $theme );
47 }
48 }
49
50 /**
51 * plugins.php
52 */
53 } elseif ( current_user_can('activate_plugins') &&
54 strpos( $script, '/plugins.php') !== FALSE ) {
55
56 if ( isset( $_REQUEST['action2'] ) ) {
57 if (! isset( $_REQUEST['action'] ) || $_REQUEST['action'] == '-1' ) {
58 $_REQUEST['action'] = $_REQUEST['action2'];
59 }
60 $_REQUEST['action2'] = '-1';
61 }
62 if (! isset( $_REQUEST['action'] ) ) { return; }
63
64 if ( isset( $_REQUEST['plugin'] ) ) {
65 $plugin = $_REQUEST['plugin'];
66 } else {
67 $plugin = '';
68 }
69 if ( isset( $_POST['checked'] ) ) {
70 $plugin_list = nfw_implode( ", ", $_POST['checked'] );
71 } else {
72 $plugin_list = '';
73 }
74
75 if ( $_REQUEST['action'] == 'activate' && ! empty( $nfw_options['a_13'] ) ) {
76 $alert_action = sprintf( '%s %s', $label_plugin, __('activated', 'ninjafirewall') );
77 $alert_item = sprintf( '%s %s', $label_name, $plugin );
78
79 } elseif ( $_REQUEST['action'] == 'activate-selected' && ! empty( $nfw_options['a_13'] ) ) {
80 $alert_action = sprintf( '%s %s', $label_plugin, __('activated', 'ninjafirewall') );
81 $alert_item = sprintf( '%s %s', $label_name, $plugin_list );
82
83 } elseif ( $_REQUEST['action'] == 'update-selected' && ! empty( $nfw_options['a_14'] ) ) {
84 $alert_action = sprintf( '%s %s', $label_plugin, __('updated', 'ninjafirewall') );
85 $alert_item = sprintf( '%s %s', $label_name, $plugin_list );
86
87 } elseif ( $_REQUEST['action'] == 'deactivate' && current_user_can( 'deactivate_plugin' ) &&
88 ! empty( $nfw_options['a_15'] ) ) {
89
90 $alert_action = sprintf( '%s %s', $label_plugin, __('deactivated', 'ninjafirewall') );
91 $alert_item = sprintf( '%s %s', $label_name, $plugin );
92
93 } elseif ( $_REQUEST['action'] == 'deactivate-selected' &&
94 current_user_can( 'deactivate_plugin' ) && ! empty( $nfw_options['a_15'] ) ) {
95
96 $alert_action = sprintf( '%s %s', $label_plugin, __('deactivated', 'ninjafirewall') );
97 $alert_item = sprintf( '%s %s', $label_name, $plugin_list );
98
99 } elseif ( $_REQUEST['action'] == 'delete-selected' &&
100 current_user_can( 'delete_plugins' ) && ! empty( $nfw_options['a_16'] ) ) {
101
102 $alert_action = sprintf( '%s %s', $label_plugin, __('deleted', 'ninjafirewall') );
103 $alert_item = sprintf( '%s %s', $label_name, $plugin_list );
104 }
105
106 // update-core.php (only used for WP updates)
107 } elseif ( strpos($_SERVER['SCRIPT_NAME'], '/update-core.php' ) !== FALSE ) {
108
109 if (! isset( $_GET['action'] ) || empty( $_POST['upgrade'] ) ) { return; }
110
111 if ( $_GET['action'] == 'do-core-upgrade' && current_user_can( 'update_core' ) &&
112 ! empty( $nfw_options['a_31'] ) ) {
113
114 $alert_action = sprintf( '%s %s', 'WordPress', __('updated', 'ninjafirewall') );
115 $alert_item = sprintf( '%s %s', $label_version, @$_POST['version'] );
116 }
117
118 // update.php
119 } elseif ( strpos($_SERVER['SCRIPT_NAME'], '/update.php' ) !== FALSE ) {
120
121 if (! isset( $_GET['action'] ) ) { return; }
122
123 if ( $_GET['action'] == 'update-selected' && current_user_can( 'update_plugins' ) &&
124 ! empty( $nfw_options['a_14'] ) ) {
125
126 if ( isset( $_GET['plugins'] ) ) {
127 $plugin = $_GET['plugins'];
128 } elseif ( isset( $_POST['checked'] ) ) {
129 $plugin = nfw_implode( ", ", $_POST['checked'] );
130 }
131 $alert_action = sprintf( '%s %s', $label_plugin, __('updated', 'ninjafirewall') );
132 $alert_item = sprintf( '%s %s', $label_name, $plugin );
133
134 } elseif ( $_GET['action'] == 'upgrade-plugin' && current_user_can( 'update_plugins' ) &&
135 ! empty( $nfw_options['a_14'] ) ) {
136
137 $alert_action = sprintf( '%s %s', $label_plugin, __('updated', 'ninjafirewall') );
138 $alert_item = sprintf( '%s %s', $label_name, @$_REQUEST['plugin'] );
139
140 } elseif ( $_GET['action'] == 'activate-plugin' && current_user_can( 'update_plugins' ) &&
141 ! empty( $nfw_options['a_13'] ) ) {
142
143 $alert_action = sprintf( '%s %s', $label_plugin, __('activated', 'ninjafirewall') );
144 $alert_item = sprintf( '%s %s', $label_name, @$_REQUEST['plugin'] );
145
146 } elseif ( $_GET['action'] == 'install-plugin' && current_user_can( 'install_plugins' ) &&
147 ! empty( $nfw_options['a_12'] ) ) {
148
149 $alert_action = sprintf( '%s %s', $label_plugin, __('installed', 'ninjafirewall') );
150 $alert_item = sprintf( '%s %s', $label_name, @$_REQUEST['plugin'] );
151
152 } elseif ( $_GET['action'] == 'upload-plugin' && current_user_can( 'upload_plugins' ) &&
153 ! empty( $nfw_options['a_11'] ) ) {
154
155 if ( isset( $_FILES['pluginzip']['name'] ) ) {
156 $alert_action = sprintf( '%s %s', $label_plugin, __('uploaded', 'ninjafirewall') );
157 $alert_item = sprintf( '%s %s', $label_name, $_FILES['pluginzip']['name'] );
158 }
159
160 } elseif ( $_GET['action'] == 'upgrade-theme' && current_user_can( 'update_themes' ) &&
161 ! empty( $nfw_options['a_25'] ) ) {
162
163 $alert_action = sprintf( '%s %s', $label_theme, __('updated', 'ninjafirewall') );
164 $alert_item = sprintf( '%s %s', $label_name, @$_REQUEST['theme'] );
165
166 } elseif ( $_GET['action'] == 'update-selected-themes' &&
167 current_user_can( 'update_themes' ) && ! empty( $nfw_options['a_25'] ) ) {
168
169 if ( isset( $_GET['themes'] ) ) {
170 $theme = nfw_implode( ", ", $_GET['themes'] );
171 } elseif ( isset( $_POST['checked'] ) ) {
172 $theme = nfw_implode( ", ", $_POST['checked'] );
173 }
174 $alert_action = sprintf( '%s %s', $label_theme, __('updated', 'ninjafirewall') );
175 $alert_item = sprintf( '%s %s', $label_name, $theme );
176
177 } elseif ( $_GET['action'] == 'install-theme' && current_user_can( 'install_themes' ) &&
178 ! empty( $nfw_options['a_22'] ) ) {
179
180 $alert_action = sprintf( '%s %s', $label_theme, __('installed', 'ninjafirewall') );
181 $alert_item = sprintf( '%s %s', $label_name, @$_REQUEST['theme'] );
182
183 } elseif ( $_GET['action'] == 'upload-theme' && current_user_can( 'upload_themes' ) &&
184 ! empty( $nfw_options['a_21'] ) ) {
185
186 $alert_action = sprintf( '%s %s', $label_theme, __('uploaded', 'ninjafirewall') );
187 $alert_item = sprintf( '%s %s', $label_name, @$_FILES['themezip']['name'] );
188 }
189
190 // AJAX actions
191 } elseif ( strpos($_SERVER['SCRIPT_NAME'], '/admin-ajax.php' ) !== FALSE ) {
192
193 if (! isset( $_REQUEST['action'] ) ) { return; }
194
195 if ( $_REQUEST['action'] == 'install-theme' && current_user_can( 'install_themes' ) &&
196 ! empty( $nfw_options['a_22'] ) ) {
197
198 $alert_action = sprintf( '%s %s', $label_theme, __('installed', 'ninjafirewall') );
199 $alert_item = sprintf( '%s %s', $label_name, @$_POST['slug'] );
200
201 } elseif ( $_REQUEST['action'] == 'update-theme' && current_user_can( 'update_themes' ) &&
202 ! empty( $nfw_options['a_25'] ) ) {
203
204 $alert_action = sprintf( '%s %s', $label_theme, __('updated', 'ninjafirewall') );
205 $alert_item = sprintf( '%s %s', $label_name, @$_POST['slug'] );
206
207 } elseif ( $_REQUEST['action'] == 'delete-theme' && current_user_can( 'delete_themes' ) &&
208 ! empty( $nfw_options['a_24'] ) ) {
209
210 $alert_action = sprintf( '%s %s', $label_theme, __('deleted', 'ninjafirewall') );
211 $alert_item = sprintf( '%s %s', $label_name, @$_POST['slug'] );
212
213 } elseif ( $_REQUEST['action'] == 'install-plugin' && current_user_can( 'install_plugins' ) &&
214 ! empty( $nfw_options['a_12'] ) ) {
215
216 $alert_action = sprintf( '%s %s', $label_plugin, __('installed', 'ninjafirewall') );
217 $alert_item = sprintf( '%s %s', $label_name, @$_POST['slug'] );
218
219 } elseif ( $_REQUEST['action'] == 'update-plugin' && current_user_can( 'update_plugins' ) &&
220 ! empty( $nfw_options['a_14'] ) ) {
221
222 $alert_action = sprintf( '%s %s', $label_plugin, __('updated', 'ninjafirewall') );
223 $alert_item = sprintf( '%s %s', $label_name, @$_POST['plugin'] );
224
225 } elseif ( $_REQUEST['action'] == 'delete-plugin' && current_user_can( 'delete_plugins' ) &&
226 ! empty( $nfw_options['a_16'] ) ) {
227
228 $alert_action = sprintf( '%s %s', $label_plugin, __('deleted', 'ninjafirewall') );
229 $alert_item = sprintf( '%s %s', $label_name, @$_POST['plugin'] );
230 }
231 }
232
233 if (! empty( $alert_action ) ) {
234
235 global $current_user;
236 $current_user = wp_get_current_user();
237
238 if ( is_multisite() ) {
239 $url = network_home_url('/');
240 } else {
241 $url = home_url('/');
242 }
243
244 /**
245 * Email notification.
246 */
247 $subject = [ $alert_action ];
248 $content = [ $alert_action, $alert_item,
249 $current_user->user_login .' ('. $current_user->roles[0] .")",
250 NFW_REMOTE_ADDR, ucfirst( date_i18n('F j, Y @ H:i:s O') ), $url ];
251
252 NinjaFirewall_mail::send('events', $subject, $content, '', [], 1 );
253
254 /**
255 * Write to the log.
256 */
257 if (! empty($nfw_options['a_41']) ) {
258 NinjaFirewall_log::write(
259 "$alert_action by {$current_user->user_login}",
260 $alert_item,
261 NFWLOG_INFO, 0, $nfw_options, NFW_LOG_DIR .'/nfwlog'
262 );
263 }
264 }
265 }
266
267 add_action('admin_init', 'nfw_sys_events', 999999);
268
269 /* ------------------------------------------------------------------ */
270 // Make sure we have an array to prevent E_ERROR.
271
272 function nfw_implode( $separator, $input ) {
273
274 if ( is_array( $input ) ) {
275 return implode( ', ', $input );
276 } else {
277 return $input;
278 }
279
280 }
281 /* ------------------------------------------------------------------ */
282 // EOF
283