/public/wp-content/plugins/better-wp-security/core/content/perms.php

https://gitlab.com/kath.de/cibedo_cibedo.de · PHP · 260 lines · 161 code · 92 blank · 7 comment · 46 complexity · de8a65411ec2c4c93a7a0db6b810b59b MD5 · raw file

  1. <?php
  2. /**
  3. * WordPress Permissions check code from Serverbuddy by PluginBuddy written by Dustin Bolton of iThemes
  4. */
  5. global $itsec_globals;
  6. $tests = array();
  7. //BEGIN FOLDERS
  8. $this_test = array(
  9. 'title' => '/',
  10. 'suggestion' => '= 755',
  11. 'value' => substr( sprintf( '%o', fileperms( ABSPATH . '/' ) ), - 4 ),
  12. );
  13. if ( ! fileperms( ABSPATH . '/' ) || 755 != substr( sprintf( '%o', fileperms( ABSPATH . '/' ) ), - 4 ) ) {
  14. $this_test['status'] = 'WARNING';
  15. } else {
  16. $this_test['status'] = 'OK';
  17. }
  18. array_push( $tests, $this_test );
  19. $this_test = array(
  20. 'title' => '/wp-includes/',
  21. 'suggestion' => '= 755',
  22. 'value' => substr( sprintf( '%o', fileperms( ABSPATH . '/wp-includes/' ) ), - 4 ),
  23. );
  24. if ( ! fileperms( ABSPATH . '/wp-includes/' ) || 755 != substr( sprintf( '%o', fileperms( ABSPATH . '/wp-includes/' ) ), - 4 ) ) {
  25. $this_test['status'] = 'WARNING';
  26. } else {
  27. $this_test['status'] = 'OK';
  28. }
  29. array_push( $tests, $this_test );
  30. $this_test = array(
  31. 'title' => '/wp-admin/',
  32. 'suggestion' => '= 755',
  33. 'value' => substr( sprintf( '%o', fileperms( ABSPATH . '/wp-admin/' ) ), - 4 ),
  34. );
  35. if ( ! fileperms( ABSPATH . '/wp-admin/' ) || 755 != substr( sprintf( '%o', fileperms( ABSPATH . '/wp-admin/' ) ), - 4 ) ) {
  36. $this_test['status'] = 'WARNING';
  37. } else {
  38. $this_test['status'] = 'OK';
  39. }
  40. array_push( $tests, $this_test );
  41. $this_test = array(
  42. 'title' => '/wp-admin/js/',
  43. 'suggestion' => '= 755',
  44. 'value' => substr( sprintf( '%o', fileperms( ABSPATH . '/wp-admin/js/' ) ), - 4 ),
  45. );
  46. if ( ! fileperms( ABSPATH . '/wp-admin/js/' ) || 755 != substr( sprintf( '%o', fileperms( ABSPATH . '/wp-admin/js/' ) ), - 4 ) ) {
  47. $this_test['status'] = 'WARNING';
  48. } else {
  49. $this_test['status'] = 'OK';
  50. }
  51. array_push( $tests, $this_test );
  52. $this_test = array(
  53. 'title' => get_theme_root(),
  54. 'suggestion' => '= 755',
  55. 'value' => substr( sprintf( '%o', fileperms( get_theme_root() ) ), - 4 ),
  56. );
  57. if ( ! fileperms( get_theme_root() ) || 755 != substr( sprintf( '%o', fileperms( get_theme_root() ) ), - 4 ) ) {
  58. $this_test['status'] = 'WARNING';
  59. } else {
  60. $this_test['status'] = 'OK';
  61. }
  62. array_push( $tests, $this_test );
  63. $this_test = array(
  64. 'title' => str_replace( ABSPATH, '', dirname( plugin_dir_path( $itsec_globals['plugin_file'] ) ) ),
  65. 'suggestion' => '= 755',
  66. 'value' => substr( sprintf( '%o', fileperms( dirname( plugin_dir_path( $itsec_globals['plugin_file'] ) ) ) ), - 4 ),
  67. );
  68. if ( ! dirname( plugin_dir_path( $itsec_globals['plugin_file'] ) ) || 755 != substr( sprintf( '%o', fileperms( dirname( plugin_dir_path( $itsec_globals['plugin_file'] ) ) ) ), - 4 ) ) {
  69. $this_test['status'] = 'WARNING';
  70. } else {
  71. $this_test['status'] = 'OK';
  72. }
  73. array_push( $tests, $this_test );
  74. if ( defined( 'WP_CONTENT_DIR' ) ) {
  75. $wp_content_dir = WP_CONTENT_DIR;
  76. } else {
  77. $wp_content_dir = ABSPATH . '/wp-content/';
  78. }
  79. $this_test = array(
  80. 'title' => str_replace( ABSPATH, '', $wp_content_dir ),
  81. 'suggestion' => '= 755',
  82. 'value' => substr( sprintf( '%o', fileperms( $wp_content_dir ) ), - 4 ),
  83. );
  84. if ( ! fileperms( $wp_content_dir ) || 755 != substr( sprintf( '%o', fileperms( $wp_content_dir ) ), - 4 ) ) {
  85. $this_test['status'] = 'WARNING';
  86. } else {
  87. $this_test['status'] = 'OK';
  88. }
  89. array_push( $tests, $this_test );
  90. $wp_upload_dir = wp_upload_dir();
  91. $this_test = array(
  92. 'title' => str_replace( ABSPATH, '', $wp_upload_dir['basedir'] ),
  93. 'suggestion' => '= 755',
  94. 'value' => substr( sprintf( '%o', fileperms( $wp_upload_dir['basedir'] ) ), - 4 ),
  95. );
  96. if ( ! fileperms( $wp_upload_dir['basedir'] ) || 755 != substr( sprintf( '%o', fileperms( $wp_upload_dir['basedir'] ) ), - 4 ) ) {
  97. $this_test['status'] = 'WARNING';
  98. } else {
  99. $this_test['status'] = 'OK';
  100. }
  101. array_push( $tests, $this_test );
  102. //END FOLDERS
  103. //BEGIN FILES
  104. $this_test = array(
  105. 'title' => 'wp-config.php',
  106. 'suggestion' => '= 444',
  107. 'value' => substr( sprintf( '%o', fileperms( ITSEC_Lib::get_config() ) ), - 4 ),
  108. );
  109. if ( ! fileperms( ITSEC_Lib::get_config() ) || 444 != substr( sprintf( '%o', fileperms( ITSEC_Lib::get_config() ) ), - 4 ) ) {
  110. $this_test['status'] = 'WARNING';
  111. } else {
  112. $this_test['status'] = 'OK';
  113. }
  114. array_push( $tests, $this_test );
  115. $this_test = array(
  116. 'title' => '.htaccess',
  117. 'suggestion' => '= 444',
  118. 'value' => substr( sprintf( '%o', fileperms( ITSEC_Lib::get_htaccess() ) ), - 4 ),
  119. );
  120. if ( ! fileperms( ITSEC_Lib::get_htaccess() ) || 444 != substr( sprintf( '%o', fileperms( ITSEC_Lib::get_htaccess() ) ), - 4 ) ) {
  121. $this_test['status'] = 'WARNING';
  122. } else {
  123. $this_test['status'] = 'OK';
  124. }
  125. array_push( $tests, $this_test );
  126. //END FILES
  127. ?>
  128. <table class="widefat">
  129. <thead>
  130. <tr class="thead">
  131. <th><?php _e('Relative Path', 'better-wp-security' ); ?></th>
  132. <th><?php _e('Suggestion', 'better-wp-security' ); ?></th>
  133. <th<?php _e('>Value', 'better-wp-security' ); ?></th>
  134. <th><?php _e('Result', 'better-wp-security' ); ?></th>
  135. <th style="width: 60px;"><?php _e('Status', 'better-wp-security' ); ?></th>
  136. </tr>
  137. </thead>
  138. <tfoot>
  139. <tr class="thead">
  140. <th><?php _e('Relative Path', 'better-wp-security' ); ?></th>
  141. <th><?php _e('Suggestion', 'better-wp-security' ); ?></th>
  142. <th><?php _e('Value', 'better-wp-security' ); ?></th>
  143. <th><?php _e('Result', 'better-wp-security' ); ?></th>
  144. <th style="width: 60px;"><?php _e('Status', 'better-wp-security' ); ?></th>
  145. </tr>
  146. </tfoot>
  147. <tbody>
  148. <?php
  149. foreach ( $tests as $this_test ) {
  150. echo '<tr class="entry-row alternate">';
  151. echo ' <td>' . $this_test['title'] . '</td>';
  152. echo ' <td>' . $this_test['suggestion'] . '</td>';
  153. echo ' <td>' . $this_test['value'] . '</td>';
  154. echo ' <td>' . $this_test['status'] . '</td>';
  155. echo ' <td>';
  156. if ( 'OK' == $this_test['status'] ) {
  157. echo '<div style="background-color: #22EE5B; border: 1px solid #E2E2E2;">&nbsp;&nbsp;&nbsp;</div>';
  158. } elseif ( 'FAIL' == $this_test['status'] ) {
  159. echo '<div style="background-color: #CF3333; border: 1px solid #E2E2E2;">&nbsp;&nbsp;&nbsp;</div>';
  160. } elseif ( 'WARNING' == $this_test['status'] ) {
  161. echo '<div style="background-color: #FEFF7F; border: 1px solid #E2E2E2;">&nbsp;&nbsp;&nbsp;</div>';
  162. }
  163. echo ' </td>';
  164. echo '</tr>';
  165. }
  166. ?>
  167. </tbody>
  168. </table>