/home/altere25/infinet.finance/wp-content/plugins/ninjafirewall/lib/firewall_options.php (17262B)
' . $res . '.
' . __('Your changes have been saved.', 'ninjafirewall') . '
'. sprintf( __( "To restore NinjaFirewall's configuration to an earlier date, select it in the list and click '%s'.", 'ninjafirewall'), __('Save Firewall Options', 'ninjafirewall') ) . '
'; } else { // No backup files yet: $res = __('There are no backup available yet, check back later.', 'ninjafirewall'); } return $res; } // --------------------------------------------------------------------- function nf_sub_options_save() { // Save options : // Check if we are uploading/importing the configuration... : if (! empty($_FILES['nf_imp']['size']) ) { return nf_sub_options_import( $_FILES['nf_imp']['tmp_name'] ); } // ...or restoring the configuration to an earlier date and return: if (! empty( $_POST['backup_file'] ) && file_exists( NFW_LOG_DIR ."/nfwlog/cache/{$_POST['backup_file']}" ) ) { return nf_sub_options_import( NFW_LOG_DIR ."/nfwlog/cache/{$_POST['backup_file']}" ); } $nfw_options = nfw_get_option( 'nfw_options' ); if ( empty( $_POST['nfw_options']['enabled']) ) { if (! empty($nfw_options['enabled']) ) { // Alert the admin : nf_sub_options_alert(1); } $nfw_options['enabled'] = 0; // Disable brute-force protection if ( file_exists( NFW_LOG_DIR . '/nfwlog/cache/bf_conf.php' ) ) { rename(NFW_LOG_DIR . '/nfwlog/cache/bf_conf.php', NFW_LOG_DIR . '/nfwlog/cache/bf_conf_off.php'); } } else { $nfw_options['enabled'] = 1; // Re-enable brute-force protection if ( file_exists( NFW_LOG_DIR . '/nfwlog/cache/bf_conf_off.php' ) ) { rename(NFW_LOG_DIR . '/nfwlog/cache/bf_conf_off.php', NFW_LOG_DIR . '/nfwlog/cache/bf_conf.php'); } } if ( (isset( $_POST['nfw_options']['ret_code'])) && (preg_match( '/^(?:4(?:0[0346]|18)|50[03])$/', $_POST['nfw_options']['ret_code'])) ) { $nfw_options['ret_code'] = (int)$_POST['nfw_options']['ret_code']; } else { $nfw_options['ret_code'] = '403'; } if ( isset( $_POST['nfw_options']['anon_ip'] ) ) { $nfw_options['anon_ip'] = 1; } else { $nfw_options['anon_ip'] = 0; } if ( empty( $_POST['nfw_options']['blocked_msg']) ) { $nfw_options['blocked_msg'] = base64_encode(NFW_DEFAULT_MSG); } else { $nfw_options['blocked_msg'] = base64_encode(stripslashes($_POST['nfw_options']['blocked_msg'])); } if ( empty( $_POST['nfw_options']['debug']) ) { $nfw_options['debug'] = 0; } else { if ( empty($nfw_options['debug']) ) { // Alert the admin : nf_sub_options_alert(2); } $nfw_options['debug'] = 1; } // Logo $nfw_options['logo'] = plugins_url() . '/ninjafirewall/images/ninjafirewall_75.png'; $nfw_options['logo'] = preg_replace( '/^https?:/', '', $nfw_options['logo'] ); // Save them : nfw_update_option( 'nfw_options', $nfw_options); // Update cronjobs if ( empty( $nfw_options['enabled'] ) ) { nfw_delete_scheduled_tasks(); } else { nfw_create_scheduled_tasks(); } } // --------------------------------------------------------------------- function nf_sub_options_import( $file ) { // Import NF configuration from file : $data = file_get_contents( $file ); $err_msg = __('Uploaded file is either corrupted or its format is not supported (#%s)', 'ninjafirewall'); if (! $data) { return sprintf($err_msg, 1); } $data = str_replace( '', '', $data ); // Is it base64-encoded (since 4.3.5)? if ( $data[0] == 'B' ) { // Decode it $data = ltrim( $data, 'B' ); $data = base64_decode( $data ); } @list ($nfw_options, $rules, $bf) = @explode("\n:-:\n", $data . "\n:-:\n"); // Detect and remove potential Unicode BOM: if ( preg_match( '/^\xef\xbb\xbf/', $nfw_options ) ) { $nfw_options = preg_replace( '/^\xef\xbb\xbf/', '', $nfw_options ); } if (! $nfw_options || ! $rules) { return sprintf($err_msg, 2); } $nfw_options = @json_decode( $nfw_options, true ); $nfw_rules = @json_decode( $rules, true ); if (! empty( $bf ) ) { $bf_conf = json_decode( $bf, true ); } if ( empty($nfw_options['engine_version']) ) { return sprintf($err_msg, 3); } // Make sure the major version numbers match (3.x, 4.x etc): list ( $major_current ) = explode( '.', NFW_ENGINE_VERSION ); list ( $major_import ) = explode( '.', $nfw_options['engine_version'] ); if ( $major_current != $major_import ) { return esc_html__('The imported file is not compatible with that version of NinjaFirewall', 'ninjafirewall'); } if ( $major_import < '4' ) { if ( empty( $nfw_options['allow_local_ip'] ) ) { $nfw_options['allow_local_ip'] = 1; } else { $nfw_options['allow_local_ip'] = 0; } } // We cannot import WP+ config : if ( isset($nfw_options['shmop']) ) { return sprintf($err_msg, 4); } if ( empty($nfw_rules[1]) ) { return sprintf($err_msg, 5); } // Dropins code: if ( isset( $nfw_rules['dropins'] ) ) { if ( $nfw_rules['dropins'] == 'delete' ) { if ( file_exists( NFW_LOG_DIR .'/nfwlog/dropins.php' ) ) { @unlink( NFW_LOG_DIR .'/nfwlog/dropins.php' ); } } else { $dropins = base64_decode( $nfw_rules['dropins'], true ); if ( $dropins !== false ) { @file_put_contents( NFW_LOG_DIR .'/nfwlog/dropins.php', $dropins, LOCK_EX ); } } unset( $nfw_rules['dropins'] ); } // Fix paths and directories: $nfw_options['logo'] = plugins_url() . '/ninjafirewall/images/ninjafirewall_75.png'; $nfw_options['logo'] = preg_replace( '/^https?:/', '', $nfw_options['logo'] ); // We must preserve the previous option, but we still need to adjust // the paths because WP_CONTENT_DIR can be user-defined and thus different (e.g., server migration): if ( isset( $nfw_options['wp_dir'] ) ) { $nfw_options['wp_dir'] = preg_replace( '`(^|\|)/([^/]+)(/\(\?:uploads\|blogs\\\.dir\)/)`', "$1/" .basename(WP_CONTENT_DIR). "$3", $nfw_options['wp_dir'] ); } if (! empty( $_FILES['nf_imp']['tmp_name'] ) && $file == $_FILES['nf_imp']['tmp_name'] ) { // We don't import the File Check 'snapshot directory' path // (applies to imported configuration, not to restoration of configuration backup): $nfw_options['snapdir'] = ''; $nfw_options['sched_scan'] = ''; } // Check compatibility before importing HSTS headers configration // or unset the option : if (! function_exists('header_register_callback') || ! function_exists('headers_list') || ! function_exists('header_remove') ) { if ( isset($nfw_options['response_headers']) ) { unset($nfw_options['response_headers']); } } // If brute force protection is enabled, we need to create a new config file : $nfwbfd_log = NFW_LOG_DIR . '/nfwlog/cache/bf_conf.php'; if (! empty($bf_conf) ) { $fh = fopen($nfwbfd_log, 'w'); fwrite($fh, $bf_conf); fclose($fh); } else { // ...or delete the current one, if any : if ( file_exists($nfwbfd_log) ) { unlink($nfwbfd_log); } } // Save options : nfw_update_option( 'nfw_options', $nfw_options); // Add the correct DOCUMENT_ROOT : if ( strlen( $_SERVER['DOCUMENT_ROOT'] ) > 5 ) { $nfw_rules[NFW_DOC_ROOT]['cha'][1]['wha'] = str_replace( '/', '/[./]*', $_SERVER['DOCUMENT_ROOT'] ); } elseif ( strlen( getenv( 'DOCUMENT_ROOT' ) ) > 5 ) { $nfw_rules[NFW_DOC_ROOT]['cha'][1]['wha'] = str_replace( '/', '/[./]*', getenv( 'DOCUMENT_ROOT' ) ); } else { $nfw_rules[NFW_DOC_ROOT]['ena'] = 0; } // Save rules : nfw_update_option( 'nfw_rules', $nfw_rules); // Recreate cronjobs if needed nfw_create_scheduled_tasks(); // Alert the admin : nf_sub_options_alert(3); return; } // --------------------------------------------------------------------- function nf_sub_options_alert( $what ) { $nfw_options = nfw_get_option( 'nfw_options' ); global $current_user; $current_user = wp_get_current_user(); $subject = __('[NinjaFirewall] Alert: Firewall is disabled', 'ninjafirewall'); if ( is_multisite() ) { $url = __('-Blog :', 'ninjafirewall') .' '. network_home_url('/') . "\n\n"; } else { $url = __('-Blog :', 'ninjafirewall') .' '. home_url('/') . "\n\n"; } // Disabled ? if ($what == 1) { $message = __('Someone disabled NinjaFirewall from your WordPress admin dashboard:', 'ninjafirewall') . "\n\n"; // Debugging mode : } elseif ($what == 2) { $message = __('NinjaFirewall is disabled because someone enabled debugging mode from your WordPress admin dashboard:', 'ninjafirewall') . "\n\n"; // Imported configuration ? } elseif ($what == 3) { $subject = __('[NinjaFirewall] Alert: Firewall override settings', 'ninjafirewall'); $message = __('Someone imported a new configuration which overrode the firewall settings:', 'ninjafirewall') . "\n\n"; } else { // Should never reach this line! return; } $message .= __('-User :', 'ninjafirewall') .' '. $current_user->user_login . ' (' . $current_user->roles[0] . ")\n" . __('-IP :', 'ninjafirewall') .' '. NFW_REMOTE_ADDR . "\n" . __('-Date :', 'ninjafirewall') .' '. ucfirst( date_i18n('F j, Y @ H:i:s O') ) ."\n" . $url . NF_PG_SIGNATURE ."\n\n". NF_PG_MORESEC; nfw_mail( $subject, $message, 'unsubscribe' ); } // --------------------------------------------------------------------- // EOF