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_firewall_options.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_firewall_options.php
317 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' ) ) { die( 'Forbidden' ); }
15
16 // Block immediately if user is not allowed :
17 nf_not_allowed( 'block', __LINE__ );
18
19 $nfw_options = nfw_get_option( 'nfw_options' );
20
21 /**
22 * Import, export and backup restoration class.
23 */
24 require_once __DIR__ .'/class-import-export.php';
25
26 ?>
27 <div class="wrap">
28 <h1><img style="vertical-align:top;width:33px;height:33px;" src="<?php echo plugins_url( '/ninjafirewall/images/ninjafirewall_32.png' ) ?>">&nbsp;<?php _e('Firewall Options', 'ninjafirewall') ?></h1>
29 <?php
30
31 // Saved options ?
32 if ( isset( $_POST['nfw_options'] ) ) {
33 if ( empty( $_POST['nfwnonce'] ) || ! wp_verify_nonce( $_POST['nfwnonce'], 'options_save' ) ) {
34 wp_nonce_ays('options_save');
35 }
36 $res = nf_sub_options_save();
37 $nfw_options = nfw_get_option( 'nfw_options' );
38 if ($res) {
39 echo '<div class="error notice is-dismissible"><p>' . $res . '.</p></div>';
40 } else {
41 echo '<div class="updated notice is-dismissible"><p>' . __('Your changes have been saved.', 'ninjafirewall') . '</p></div>';
42 }
43 }
44 nfw_contextual_help();
45 ?>
46
47 <form method="post" name="option_form" enctype="multipart/form-data" onsubmit="return nfwjs_save_options();">
48
49 <?php wp_nonce_field('options_save', 'nfwnonce', 0); ?>
50
51 <table class="form-table nfw-table">
52
53 <?php
54 if ( empty( $nfw_options['enabled'] ) ) {
55 $nfw_options['enabled'] = 0;
56 } else {
57 $nfw_options['enabled'] = 1;
58 }
59 ?>
60 <tr>
61 <th scope="row" class="row-med"><?php _e('Firewall protection', 'ninjafirewall') ?></th>
62 <td>
63 <?php nfw_toggle_switch( 'danger', 'nfw_options[enabled]', __('Enabled', 'ninjafirewall'), __('Disabled', 'ninjafirewall'), 'large', $nfw_options['enabled'] ) ?>
64 </td>
65 </tr>
66
67 <?php
68 if ( empty( $nfw_options['debug'] ) ) {
69 $nfw_options['debug'] = 0;
70 } else {
71 $nfw_options['debug'] = 1;
72 }
73 ?>
74 <tr>
75 <th scope="row" class="row-med"><?php _e('Debugging mode', 'ninjafirewall') ?></th>
76 <td>
77 <?php nfw_toggle_switch( 'warning', 'nfw_options[debug]', __('Yes', 'ninjafirewall'), __('No', 'ninjafirewall'), 'small', $nfw_options['debug'] ) ?>
78 </td>
79 </tr>
80
81 <?php
82 // Get the HTTP error code to return
83 if ( empty( $nfw_options['ret_code'] ) || ! preg_match( '/^(?:4(?:0[0346]|18)|50[03])$/', $nfw_options['ret_code'] ) ) {
84 $nfw_options['ret_code'] = '403';
85 }
86 ?>
87 <tr>
88 <th scope="row" class="row-med"><?php _e('HTTP error code to return', 'ninjafirewall') ?></th>
89 <td>
90 <select name="nfw_options[ret_code]">
91 <option value="400"<?php selected( $nfw_options['ret_code'], 400 ) ?>><?php _e('400 Bad Request', 'ninjafirewall') ?></option>
92 <option value="403"<?php selected( $nfw_options['ret_code'], 403 ) ?>><?php _e('403 Forbidden (default)', 'ninjafirewall') ?></option>
93 <option value="404"<?php selected( $nfw_options['ret_code'], 404 ) ?>><?php _e('404 Not Found', 'ninjafirewall') ?></option>
94 <option value="406"<?php selected( $nfw_options['ret_code'], 406 ) ?>><?php _e('406 Not Acceptable', 'ninjafirewall') ?></option>
95 <option value="418"<?php selected( $nfw_options['ret_code'], 418 ) ?>><?php _e("418 I'm a teapot", 'ninjafirewall') ?></option>
96 <option value="500"<?php selected( $nfw_options['ret_code'], 500 ) ?>><?php _e('500 Internal Server Error', 'ninjafirewall') ?></option>
97 <option value="503"<?php selected( $nfw_options['ret_code'], 503 ) ?>><?php _e('503 Service Unavailable', 'ninjafirewall') ?></option>
98 </select>
99 </td>
100 </tr>
101
102 <?php
103 if ( empty( $nfw_options['anon_ip'] ) ) {
104 $nfw_options['anon_ip'] = 0;
105 } else {
106 $nfw_options['anon_ip'] = 1;
107 }
108 ?>
109 <tr>
110 <th scope="row" class="row-med"><?php _e('IP anonymization', 'ninjafirewall') ?></th>
111 <td>
112 <?php nfw_toggle_switch( 'info', 'nfw_options[anon_ip]', __('Yes', 'ninjafirewall'), __('No', 'ninjafirewall'), 'small', $nfw_options['anon_ip'] ) ?>
113 <p class="description"><?php printf( __('Does not apply to private IP addresses and the <a href="%s">Login Protection</a>.', 'ninjafirewall'), '?page=nfsubloginprot' ) ?></p>
114 </td>
115 </tr>
116
117 <?php
118 if (! empty( $nfw_options['blocked_msg'] ) ) {
119 $msg = base64_decode( $nfw_options['blocked_msg'] );
120 } else {
121 $msg = NFW_DEFAULT_MSG;
122 }
123
124 $logo_uri = rawurlencode( '<img src="' . plugins_url() . '/ninjafirewall/images/ninjafirewall_75.png" width="75" height="75" />' );
125 ?>
126 <tr>
127 <th scope="row" class="row-med"><?php _e('Blocked user message', 'ninjafirewall') ?></th>
128 <td>
129 <textarea id="blocked-msg" name="nfw_options[blocked_msg]" class="large-text code" rows="10" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"><?php echo htmlspecialchars( $msg ) ?></textarea>
130 <p class="description"><?php _e('HTML code, including CSS and JS, is allowed.', 'ninjafirewall') ?></p>
131 <input type="hidden" id="default-msg" value="<?php echo htmlspecialchars( NFW_DEFAULT_MSG ) ?>" />
132 <p><input class="button-secondary" type="button" value="<?php _e('Default message', 'ninjafirewall') ?>" onclick="nfwjs_default_msg();" /></p>
133 </td>
134 </tr>
135 </table>
136
137 <br />
138 <br />
139
140 <h3><?php _e('Firewall configuration', 'ninjafirewall') ?></h3>
141
142 <table class="form-table nfw-table">
143 <tr>
144 <th scope="row" class="row-med"><?php _e('Export configuration', 'ninjafirewall') ?></th>
145 <td>
146 <input class="button-secondary" type="submit" name="ninjafirewall_export" value="<?php _e('Download', 'ninjafirewall') ?>" />
147 <p class="description"><?php _e( 'File Check configuration will not be exported/imported.', 'ninjafirewall') ?></p>
148 </td>
149 </tr>
150 <tr>
151 <th scope="row" class="row-med"><?php _e('Import configuration', 'ninjafirewall') ?></th>
152 <td>
153 <input type="file" name="ninjafirewall_import" />
154 <p class="description"><?php
155 list ( $major_current ) = explode( '.', NFW_ENGINE_VERSION );
156 printf( __( 'Imported configuration must match plugin version %s.', 'ninjafirewall'), (int) $major_current .'.x' );
157 echo '<br />'. __('It will override all your current firewall options and rules.', 'ninjafirewall')
158 ?></p>
159 </td>
160 </tr>
161 <tr>
162 <th scope="row" class="row-med"><?php _e('Configuration backup', 'ninjafirewall') ?></th>
163 <td><?php echo nf_sub_options_confbackup(); ?></td>
164 </tr>
165 </table>
166
167 <br />
168 <br />
169
170 <input class="button-primary" type="submit" name="Save" value="<?php _e('Save Firewall Options', 'ninjafirewall') ?>" />
171 </form>
172 </div>
173
174 <?php
175
176 return;
177
178 // ---------------------------------------------------------------------
179
180 function nf_sub_options_confbackup() {
181
182 $res = '';
183 $dir = NFW_LOG_DIR .'/nfwlog/cache';
184 $files = NinjaFirewall_helpers::nfw_glob( $dir, 'backup_.+?\.php$', true, true );
185
186 if (! empty( $files[0] ) ) {
187 $res .= '<select name="backup_file" onchange="nfwjs_select_backup(this.value)">'.
188 '<option selected value="">'. esc_html__('Available backup files', 'ninjafirewall') .'</option>';
189 foreach( $files as $file ) {
190 if ( preg_match('`/(backup_(\d{10})_.+\.php)$`', $file, $match ) ) {
191
192 $date = ucfirst( date_i18n('F d, Y @ g:i A', $match[2] ) );
193 $size = ' ('. number_format_i18n( filesize( $file ) ) .' '.
194 esc_html__('bytes', 'ninjafirewall') .')';
195 $res .= '<option value="'. esc_attr( $match[1] ) .'" title="'. esc_attr( $file ) .'">'.
196 esc_html( $date . $size ) .'</option>';
197 }
198 }
199 $res .= '</select>';
200 $res .= '<p class="description">'. sprintf(
201 esc_html__("To restore NinjaFirewall's configuration to an earlier date, select it in ".
202 "the list and click '%s'.", 'ninjafirewall'),
203 esc_html__('Save Firewall Options', 'ninjafirewall') ) . '</p>';
204
205 } else {
206 // No backup files yet
207 $res = esc_html__('There are no backup available yet, check back later.', 'ninjafirewall');
208 }
209 return $res;
210
211 }
212
213 // ---------------------------------------------------------------------
214
215 function nf_sub_options_save() {
216
217 /**
218 * Save options.
219 */
220
221 $nfw_options = nfw_get_option('nfw_options');
222
223 /**
224 * Check if we are uploading/importing the configuration.
225 */
226 if (! empty( $_FILES['ninjafirewall_import']['size'] ) ) {
227 if ( empty( $_FILES['ninjafirewall_import']['tmp_name'] ) ||
228 ! is_uploaded_file( $_FILES['ninjafirewall_import']['tmp_name'] ) ) {
229
230 return esc_html__('Invalid configuration upload', 'ninjafirewall');
231 }
232 return NinjaFirewall_ImpExp::import( $_FILES['ninjafirewall_import']['tmp_name'] );
233 }
234 /**
235 * Or restoring the configuration to an earlier date and return.
236 */
237 $backup_file = '';
238 if (! empty( $_POST['backup_file'] ) ) {
239 $backup_file = basename( wp_unslash( $_POST['backup_file'] ) );
240 }
241 if ( $backup_file && preg_match( '/^backup_\d{10}_.+\.php$/', $backup_file ) &&
242 file_exists( NFW_LOG_DIR . "/nfwlog/cache/$backup_file" ) ) {
243
244 return NinjaFirewall_ImpExp::import( NFW_LOG_DIR . "/nfwlog/cache/$backup_file" );
245 }
246
247 if ( empty( $_POST['nfw_options']['enabled']) ) {
248 if (! empty($nfw_options['enabled']) ) {
249 // Alert the admin :
250 NinjaFirewall_ImpExp::email_admin('disabled');
251 }
252 $nfw_options['enabled'] = 0;
253
254 // Disable brute-force protection
255 if ( file_exists( NFW_LOG_DIR . '/nfwlog/cache/bf_conf.php') ) {
256 rename(NFW_LOG_DIR .'/nfwlog/cache/bf_conf.php', NFW_LOG_DIR .'/nfwlog/cache/bf_conf_off.php');
257 }
258
259 } else {
260 $nfw_options['enabled'] = 1;
261
262 // Re-enable brute-force protection
263 if ( file_exists( NFW_LOG_DIR . '/nfwlog/cache/bf_conf_off.php') ) {
264 rename(NFW_LOG_DIR .'/nfwlog/cache/bf_conf_off.php', NFW_LOG_DIR .'/nfwlog/cache/bf_conf.php');
265 }
266 }
267
268 if ( (isset( $_POST['nfw_options']['ret_code'])) &&
269 (preg_match( '/^(?:4(?:0[0346]|18)|50[03])$/', $_POST['nfw_options']['ret_code'])) ) {
270 $nfw_options['ret_code'] = (int)$_POST['nfw_options']['ret_code'];
271 } else {
272 $nfw_options['ret_code'] = '403';
273 }
274
275 if ( isset( $_POST['nfw_options']['anon_ip'] ) ) {
276 $nfw_options['anon_ip'] = 1;
277 } else {
278 $nfw_options['anon_ip'] = 0;
279 }
280
281 if ( empty( $_POST['nfw_options']['blocked_msg']) ) {
282 $nfw_options['blocked_msg'] = base64_encode(NFW_DEFAULT_MSG);
283 } else {
284 $nfw_options['blocked_msg'] = base64_encode(stripslashes($_POST['nfw_options']['blocked_msg']));
285 }
286
287 if ( empty( $_POST['nfw_options']['debug']) ) {
288 $nfw_options['debug'] = 0;
289 } else {
290 if ( empty($nfw_options['debug']) ) {
291 // Alert the admin :
292 NinjaFirewall_ImpExp::email_admin('debugging');
293 }
294 $nfw_options['debug'] = 1;
295 }
296
297 /**
298 * Logo.
299 */
300 $nfw_options['logo'] = plugins_url('images/ninjafirewall_75.png', dirname( __FILE__ ) );
301 $nfw_options['logo'] = preg_replace('/^https?:/', '', $nfw_options['logo'] );
302
303 // Save them :
304 nfw_update_option( 'nfw_options', $nfw_options);
305
306 // Update cronjobs
307 if ( empty( $nfw_options['enabled'] ) ) {
308 nfw_delete_scheduled_tasks();
309 } else {
310 nfw_create_scheduled_tasks();
311 }
312
313 }
314
315 // ---------------------------------------------------------------------
316 // EOF
317