PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/icwp-import-wpf2-processor.php

https://github.com/stackgrinder/wp-simple-firewall
PHP | 147 lines | 81 code | 19 blank | 47 comment | 16 complexity | 2289730a7c38329369aee2260d74ec8b MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (c) 2014 iControlWP <support@icontrolwp.com>
  4. * All rights reserved.
  5. *
  6. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  7. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  8. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  9. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  10. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  11. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  12. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  13. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  15. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. */
  17. require_once( dirname(__FILE__).'/icwp-import-base-processor.php' );
  18. if ( !class_exists('ICWP_ImportWpf2Processor') ):
  19. class ICWP_ImportWpf2Processor extends ICWP_ImportBaseProcessor {
  20. /**
  21. * @var ICWP_OptionsHandler_Wpsf
  22. */
  23. protected $m_oWpsfOptions;
  24. /**
  25. * @var ICWP_OptionsHandler_Firewall
  26. */
  27. protected $m_oFirewallOptions;
  28. public function __construct( $inoPluginOptions, $inoFirewallOptions ) {
  29. $this->m_oWpsfOptions = $inoPluginOptions;
  30. $this->m_oFirewallOptions = $inoFirewallOptions;
  31. $this->m_aOptionsMap = array(
  32. 'WP_firewall_redirect_page' => 'block_response',
  33. 'WP_firewall_email_enable' => 'block_send_email',
  34. /* 'WP_firewall_email_type' => '', unused */
  35. 'WP_firewall_email_address' => 'block_send_email_address',
  36. 'WP_firewall_exclude_directory' => 'block_dir_traversal',
  37. 'WP_firewall_exclude_queries' => 'block_sql_queries',
  38. 'WP_firewall_exclude_terms' => 'block_wordpress_terms',
  39. 'WP_firewall_exclude_spaces' => 'block_field_truncation',
  40. 'WP_firewall_exclude_file' => 'block_exe_file_uploads',
  41. 'WP_firewall_exclude_http' => 'block_leading_schema',
  42. 'WP_firewall_whitelisted_ip' => 'ips_whitelist',
  43. 'WP_firewall_whitelisted_page' => 'page_params_whitelist',
  44. 'WP_firewall_whitelisted_variable' => 'page_params_whitelist',
  45. /* 'WP_firewall_plugin_url' => '', unused */
  46. /* 'WP_firewall_default_whitelisted_page' => '', unused */
  47. /* 'WP_firewall_previous_attack_var' => '', unused */
  48. /* 'WP_firewall_previous_attack_ip' => '', unused */
  49. /* 'WP_firewall_email_limit' => '', unused */
  50. );
  51. }
  52. protected function mapOptionsToTarget() {
  53. $aPluginOptions = array(
  54. 'block_send_email_address'
  55. );
  56. $aFirewallOptions = array(
  57. 'block_response',
  58. 'block_send_email',
  59. 'block_send_email_address',
  60. 'block_dir_traversal',
  61. 'block_sql_queries',
  62. 'block_wordpress_terms',
  63. 'block_field_truncation',
  64. 'block_exe_file_uploads',
  65. 'block_leading_schema',
  66. 'ips_whitelist',
  67. 'page_params_whitelist',
  68. 'page_params_whitelist'
  69. );
  70. //redirect option
  71. if ( $this->m_aSourceValues[ 'WP_firewall_redirect_page' ] == 'homepage' ) {
  72. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_redirect_page'], 'redirect_home' );
  73. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_redirect_page'], 'redirect_home' );
  74. }
  75. else if ( $this->m_aSourceValues[ 'WP_firewall_redirect_page' ] == '404page' ) {
  76. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_redirect_page'], 'redirect_404' );
  77. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_redirect_page'], 'redirect_404' );
  78. }
  79. //Email enable
  80. if ( $this->m_aSourceValues[ 'WP_firewall_email_enable' ] == 'enable' ) {
  81. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_email_enable'], 'Y' );
  82. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_email_enable'], 'Y' );
  83. }
  84. else { // actually the WPF2 doesn't give the option to turn off email(!)
  85. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_email_enable'], 'N' );
  86. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_email_enable'], 'N' );
  87. }
  88. //Email address
  89. $this->m_oWpsfOptions->setOpt( $this->m_aOptionsMap['WP_firewall_email_address'], $this->m_aSourceValues[ 'WP_firewall_email_address' ] );
  90. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_email_address'], $this->m_aSourceValues[ 'WP_firewall_email_address' ] );
  91. //Firewall block options - uses 'allow' to signify the block is in place. :|
  92. $sTargetValue = ( $this->m_aSourceValues[ 'WP_firewall_exclude_directory' ] == 'allow' )? 'Y' : 'N';
  93. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_exclude_directory'], $sTargetValue );
  94. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_exclude_directory'], $sTargetValue );
  95. $sTargetValue = ( $this->m_aSourceValues[ 'WP_firewall_exclude_queries' ] == 'allow' )? 'Y' : 'N';
  96. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_exclude_queries'], $sTargetValue );
  97. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_exclude_queries'], $sTargetValue );
  98. $sTargetValue = ( $this->m_aSourceValues[ 'WP_firewall_exclude_terms' ] == 'allow' )? 'Y' : 'N';
  99. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_exclude_terms'], $sTargetValue );
  100. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_exclude_terms'], $sTargetValue );
  101. $sTargetValue = ( $this->m_aSourceValues[ 'WP_firewall_exclude_spaces' ] == 'allow' )? 'Y' : 'N';
  102. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_exclude_spaces'], $sTargetValue );
  103. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_exclude_spaces'], $sTargetValue );
  104. $sTargetValue = ( $this->m_aSourceValues[ 'WP_firewall_exclude_file' ] == 'allow' )? 'Y' : 'N';
  105. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_exclude_file'], $sTargetValue );
  106. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_exclude_file'], $sTargetValue );
  107. $sTargetValue = ( $this->m_aSourceValues[ 'WP_firewall_exclude_http' ] == 'allow' )? 'Y' : 'N';
  108. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_exclude_http'], $sTargetValue );
  109. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_exclude_http'], $sTargetValue );
  110. // Cookie checking - WPF2 does this by default
  111. // $this->updateTargetOption( 'include_cookie_checks', 'Y' );
  112. $this->m_oFirewallOptions->setOpt( 'include_cookie_checks', 'Y' );
  113. // Whitelisted IPs
  114. $aSourceIps = maybe_unserialize( $this->m_aSourceValues[ 'WP_firewall_whitelisted_ip' ] );
  115. $aNewList = array();
  116. foreach( $aSourceIps as $sIp ) {
  117. $aNewList[ $sIp ] = '';
  118. }
  119. $aTargetIpWhitelist = $this->m_oFirewallOptions->getOpt( $this->m_aOptionsMap['WP_firewall_whitelisted_ip'] );
  120. if ( empty( $aTargetIpWhitelist ) ) {
  121. $aTargetIpWhitelist = array();
  122. }
  123. $this->m_oFirewallOptions->setOpt( $this->m_aOptionsMap['WP_firewall_whitelisted_ip'], ICWP_WPSF_DataProcessor::Add_New_Raw_Ips( $aTargetIpWhitelist, $aNewList ) );
  124. // $this->updateTargetOption( $this->m_aOptionsMap['WP_firewall_whitelisted_ip'], ICWP_WPSF_DataProcessor::Add_New_Raw_Ips( $aTargetIpWhitelist, $aNewList ) );
  125. // Whitelisted Pages and Vars... maybe later :|
  126. }
  127. }
  128. endif;