PageRenderTime 72ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/src/icwp-optionshandler-lockdown.php

https://github.com/stackgrinder/wp-simple-firewall
PHP | 170 lines | 132 code | 20 blank | 18 comment | 12 complexity | 7de7459da48a835765d4ecdcb878f594 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-optionshandler-base.php' );
  18. if ( !class_exists('ICWP_OptionsHandler_Lockdown') ):
  19. class ICWP_OptionsHandler_Lockdown extends ICWP_OptionsHandler_Base_Wpsf {
  20. const StoreName = 'lockdown_options';
  21. public function __construct( $oPluginVo ) {
  22. parent::__construct( $oPluginVo, self::StoreName );
  23. $this->sFeatureName = _wpsf__('Lockdown');
  24. $this->sFeatureSlug = 'lockdown';
  25. }
  26. public function doPrePluginOptionsSave() {
  27. if ( $this->getOpt( 'action_reset_auth_salts' ) == 'Y' ) {
  28. $this->setOpt( 'action_reset_auth_salts', 'P' );
  29. }
  30. else if ( $this->getOpt( 'action_reset_auth_salts' ) == 'P' ) {
  31. $this->setOpt( 'action_reset_auth_salts', 'N' );
  32. }
  33. $sCurrent = $this->getOpt( 'mask_wordpress_version' );
  34. if ( !empty( $sCurrent ) ) {
  35. $this->setOpt( 'mask_wordpress_version', preg_replace( '/[^a-z0-9_.-]/i', '', $sCurrent ) );
  36. }
  37. }
  38. /**
  39. * @return bool|void
  40. */
  41. public function defineOptions() {
  42. $aBase = array(
  43. 'section_title' => sprintf( _wpsf__( 'Enable Plugin Feature: %s' ), _wpsf__('WordPress Lockdown') ),
  44. 'section_options' => array(
  45. array(
  46. 'enable_lockdown',
  47. '',
  48. 'N',
  49. 'checkbox',
  50. _wpsf__( 'Enable Lockdown' ),
  51. _wpsf__( 'Enable (or Disable) The Lockdown Feature' ),
  52. sprintf( _wpsf__( 'Checking/Un-Checking this option will completely turn on/off the whole %s feature.' ), _wpsf__('WordPress Lockdown') ),
  53. '<a href="http://icwp.io/4r" target="_blank">'._wpsf__( 'more info' ).'</a>'
  54. )
  55. )
  56. );
  57. $aAccess = array(
  58. 'section_title' => _wpsf__( 'Access Options' ),
  59. 'section_options' => array(
  60. array(
  61. 'disable_file_editing',
  62. '',
  63. 'N',
  64. 'checkbox',
  65. _wpsf__( 'Disable File Editing' ),
  66. _wpsf__( 'Disable Ability To Edit Files' ),
  67. _wpsf__( 'Removes the option to directly edit any files from within the WordPress admin area.' )
  68. .'<br />'._wpsf__( 'Equivalent to setting DISALLOW_FILE_EDIT to TRUE.' ),
  69. '<a href="http://icwp.io/4q" target="_blank">'._wpsf__( 'more info' ).'</a>'
  70. ),
  71. array(
  72. 'force_ssl_login',
  73. '',
  74. 'N',
  75. 'checkbox',
  76. _wpsf__( 'Force SSL Login' ),
  77. _wpsf__( 'Forces Login Form To Be Submitted Over SSL' ),
  78. _wpsf__( 'Please only enable this option if you have a valid SSL certificate installed.' )
  79. .'<br />'._wpsf__( 'Equivalent to setting FORCE_SSL_LOGIN to TRUE.' ),
  80. '<a href="http://icwp.io/4s" target="_blank">'._wpsf__( 'more info' ).'</a>'
  81. ),
  82. array(
  83. 'force_ssl_admin',
  84. '',
  85. 'N',
  86. 'checkbox',
  87. _wpsf__( 'Force SSL Admin' ),
  88. _wpsf__( 'Forces WordPress Admin Dashboard To Be Delivered Over SSL' ),
  89. _wpsf__( 'Please only enable this option if you have a valid SSL certificate installed.' )
  90. .'<br />'._wpsf__( 'Equivalent to setting FORCE_SSL_ADMIN to TRUE.' ),
  91. '<a href="http://icwp.io/4t" target="_blank">'._wpsf__( 'more info' ).'</a>'
  92. )
  93. )
  94. );
  95. $aObscurity = array(
  96. 'section_title' => _wpsf__( 'WordPress Obscurity Options' ),
  97. 'section_options' => array(
  98. array(
  99. 'mask_wordpress_version',
  100. '',
  101. '',
  102. 'text',
  103. _wpsf__( 'Mask WordPress Version' ),
  104. _wpsf__( 'Prevents Public Display Of Your WordPress Version' ),
  105. _wpsf__( 'Enter how you would like your WordPress version displayed publicly. Leave blank to disable this feature.' )
  106. .'<br />'._wpsf__( 'Warning: This may interfere with WordPress plugins that rely on the $wp_version variable.' ),
  107. '<a href="http://icwp.io/43" target="_blank">'._wpsf__( 'more info' ).'</a>'
  108. )
  109. )
  110. );
  111. $this->m_aOptions = array(
  112. $aBase,
  113. $aAccess,
  114. $aObscurity
  115. );
  116. if ( false && $this->getCanDoAuthSalts() ) {
  117. $this->m_aOptions[] = array(
  118. 'section_title' => _wpsf__( 'Security Actions' ),
  119. 'section_options' => array(
  120. array(
  121. 'action_reset_auth_salts',
  122. '',
  123. 'N',
  124. 'checkbox',
  125. _wpsf__( 'Reset Auth Keys/Salts' ),
  126. _wpsf__( 'Reset WordPress Authentication Keys and Salts' ),
  127. _wpsf__( 'Selecting this will reset the WordPress Authentication Keys and Salts in your wp-config.php file.' )
  128. .'<br /><strong>'._wpsf__( 'Note: This will log you and all other users out of their current session.' ).'</strong>'
  129. )
  130. )
  131. );
  132. }
  133. }
  134. protected function getCanDoAuthSalts() {
  135. $oWpFs = $this->loadFileSystemProcessor();
  136. if ( !$oWpFs->getCanWpRemoteGet() ) {
  137. return false;
  138. }
  139. if ( !$oWpFs->getCanDiskWrite() ) {
  140. return false;
  141. }
  142. $sWpConfigPath = $oWpFs->exists( ABSPATH.'wp-config.php' )? ABSPATH.'wp-config.php' : ABSPATH.'..'.ICWP_DS.'wp-config.php';
  143. if ( !$oWpFs->exists( $sWpConfigPath ) ) {
  144. return false;
  145. }
  146. $mResult = $oWpFs->getCanReadWriteFile( $sWpConfigPath );
  147. return !empty( $mResult );
  148. }
  149. }
  150. endif;