PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/bulletproof-security/includes/functions.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 690 lines | 568 code | 63 blank | 59 comment | 167 complexity | 224fae8cd157cc0d0649c03ec4965fdc MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. // Direct calls to this file are Forbidden when core files are not present
  3. if (!function_exists ('add_action')) {
  4. header('Status: 403 Forbidden');
  5. header('HTTP/1.1 403 Forbidden');
  6. exit();
  7. }
  8. // Get BPS Version - Just for display purposes
  9. function bpsWhatVersion() {
  10. echo " ~ .46.6";
  11. }
  12. // BPS Master htaccess File Editing - file checks and get contents for editor
  13. function get_secure_htaccess() {
  14. $secure_htaccess_file = ABSPATH .'wp-content/plugins/bulletproof-security/admin/htaccess/secure.htaccess';
  15. if (file_exists($secure_htaccess_file)) {
  16. $bpsString = file_get_contents($secure_htaccess_file);
  17. echo $bpsString;
  18. } else {
  19. _e('The secure.htaccess file either does not exist or is not named correctly. Check the /wp-content/plugins/bulletproof-security/admin/htaccess/ folder to make sure the secure.htaccess file exists and is named secure.htaccess.');
  20. }
  21. }
  22. function get_default_htaccess() {
  23. $default_htaccess_file = ABSPATH .'wp-content/plugins/bulletproof-security/admin/htaccess/default.htaccess';
  24. if (file_exists($default_htaccess_file)) {
  25. $bpsString = file_get_contents($default_htaccess_file);
  26. echo $bpsString;
  27. } else {
  28. _e('The default.htaccess file either does not exist or is not named correctly. Check the /wp-content/plugins/bulletproof-security/admin/htaccess/ folder to make sure the default.htaccess file exists and is named default.htaccess.');
  29. }
  30. }
  31. function get_maintenance_htaccess() {
  32. $maintenance_htaccess_file = ABSPATH . 'wp-content/plugins/bulletproof-security/admin/htaccess/maintenance.htaccess';
  33. if (file_exists($maintenance_htaccess_file)) {
  34. $bpsString = file_get_contents($maintenance_htaccess_file);
  35. echo $bpsString;
  36. } else {
  37. _e('The maintenance.htaccess file either does not exist or is not named correctly. Check the /wp-content/plugins/bulletproof-security/admin/htaccess/ folder to make sure the maintenance.htaccess file exists and is named maintenance.htaccess.');
  38. }
  39. }
  40. function get_wpadmin_htaccess() {
  41. $wpadmin_htaccess_file = ABSPATH . 'wp-content/plugins/bulletproof-security/admin/htaccess/wpadmin-secure.htaccess';
  42. if (file_exists($wpadmin_htaccess_file)) {
  43. $bpsString = file_get_contents($wpadmin_htaccess_file);
  44. echo $bpsString;
  45. } else {
  46. _e('The wpadmin-secure.htaccess file either does not exist or is not named correctly. Check the /wp-content/plugins/bulletproof-security/admin/htaccess/ folder to make sure the wpadmin-secure.htaccess file exists and is named wpadmin-secure.htaccess.');
  47. }
  48. }
  49. // The current active root htaccess file - file check
  50. function get_root_htaccess() {
  51. $root_htaccess_file = ABSPATH . '.htaccess';
  52. if (file_exists($root_htaccess_file)) {
  53. $bpsString = file_get_contents($root_htaccess_file);
  54. echo $bpsString;
  55. } else {
  56. _e('An .htaccess file was not found in your website root folder.');
  57. }
  58. }
  59. // The current active wp-admin htaccess file - file check
  60. function get_current_wpadmin_htaccess_file() {
  61. $current_wpadmin_htaccess_file = ABSPATH . 'wp-admin/.htaccess';
  62. if (file_exists($current_wpadmin_htaccess_file)) {
  63. $bpsString = file_get_contents($current_wpadmin_htaccess_file);
  64. echo $bpsString;
  65. } else {
  66. _e('An .htaccess file was not found in your wp-admin folder.');
  67. }
  68. }
  69. // File write checks for editor
  70. function secure_htaccess_file_check() {
  71. $secure_htaccess_file = ABSPATH . '/wp-content/plugins/bulletproof-security/admin/htaccess/secure.htaccess';
  72. if (!is_writable($secure_htaccess_file)) {
  73. _e('<font color="red"><strong>Cannot write to the secure.htaccess file. Minimum file permission required is 600.</strong></font><br>');
  74. } else {
  75. _e('');
  76. }
  77. }
  78. // File write checks for editor
  79. function default_htaccess_file_check() {
  80. $default_htaccess_file = ABSPATH . '/wp-content/plugins/bulletproof-security/admin/htaccess/default.htaccess';
  81. if (!is_writable($default_htaccess_file)) {
  82. _e('<font color="red"><strong>Cannot write to the default.htaccess file. Minimum file permission required is 600.</strong></font><br>');
  83. } else {
  84. _e('');
  85. }
  86. }
  87. // File write checks for editor
  88. function maintenance_htaccess_file_check() {
  89. $maintenance_htaccess_file = ABSPATH . '/wp-content/plugins/bulletproof-security/admin/htaccess/maintenance.htaccess';
  90. if (!is_writable($maintenance_htaccess_file)) {
  91. _e('<font color="red"><strong>Cannot write to the maintenance.htaccess file. Minimum file permission required is 600.</strong></font><br>');
  92. } else {
  93. _e('');
  94. }
  95. }
  96. // File write checks for editor
  97. function wpadmin_htaccess_file_check() {
  98. $wpadmin_htaccess_file = ABSPATH . '/wp-content/plugins/bulletproof-security/admin/htaccess/wpadmin-secure.htaccess';
  99. if (!is_writable($wpadmin_htaccess_file)) {
  100. _e('<font color="red"><strong>Cannot write to the wpadmin-secure.htaccess file. Minimum file permission required is 600.</strong></font><br>');
  101. } else {
  102. _e('');
  103. }
  104. }
  105. // File write checks for editor
  106. function root_htaccess_file_check() {
  107. $root_htaccess_file = ABSPATH . '/.htaccess';
  108. if (!is_writable($root_htaccess_file)) {
  109. _e('<font color="red"><strong>Cannot write to the root .htaccess file. Minimum file permission required is 600.</strong></font><br>');
  110. } else {
  111. _e('');
  112. }
  113. }
  114. // File write checks for editor
  115. function current_wpadmin_htaccess_file_check() {
  116. $current_wpadmin_htaccess_file = ABSPATH . '/wp-admin/.htaccess';
  117. if (!is_writable($current_wpadmin_htaccess_file)) {
  118. _e('<font color="red"><strong>Cannot write to the wp-admin .htaccess file. Minimum file permission required is 600.</strong></font><br>');
  119. } else {
  120. _e('');
  121. }
  122. }
  123. // Get contents of Root .htaccess file from 3-45 - if "6" found in string position 17 - offset 16 - good - else bad
  124. // Check for string BPSQSE
  125. function root_htaccess_status() {
  126. $filename = ABSPATH . '.htaccess';
  127. $section = @file_get_contents($filename, NULL, NULL, 3, 45);
  128. $check_stringBPSQSE = @file_get_contents($filename);
  129. $check_string = @strpos($section, "6", 16);
  130. if ( !file_exists($filename)) {
  131. _e('<font color="red">An .htaccess file was NOT found in your root folder</font><br><br>');
  132. _e('<font color="red">wp-config.php is NOT .htaccess protected by BPS</font><br><br>');
  133. } else {
  134. if (file_exists($filename)) {
  135. _e('<font color="green"><strong>The .htaccess file that is activated in your root folder is:</strong></font><br>');
  136. print($section);
  137. if ($check_string == "17" && strpos($check_stringBPSQSE, "BPSQSE")) {
  138. _e('<font color="green"><strong><br><br>&radic; wp-config.php is .htaccess protected by BPS<br>&radic; php.ini and php5.ini are .htaccess protected by BPS</strong></font><br><br>');
  139. } else {
  140. _e('<font color="red"><br><br><strong>Either a BPS .htaccess file was NOT found in your root folder or you have not activated BulletProof Mode for your Root folder yet, Default Mode is activated, Maintenance Mode is activated or the version of the BPS Pro htaccess file that you are using is not .46.6 or the BPS QUERY STRING EXPLOITS code does not exist in your root .htaccess file. Please read the Read Me hover Tooltip above.</strong></font><br><br>');
  141. _e('<font color="red"><strong>wp-config.php is NOT .htaccess protected by BPS</strong></font><br><br>');
  142. }}}}
  143. // Get contents of wp-admin .htaccess file from 3-45 - if "6" found in string position 17 - offset 16 - good - else bad
  144. function wpadmin_htaccess_status() {
  145. $filename = ABSPATH . 'wp-admin/.htaccess';
  146. $section = @file_get_contents($filename, NULL, NULL, 3, 45);
  147. $check_stringBPSQSE = @file_get_contents($filename);
  148. $check_string = @strpos($section, "6", 16);
  149. if ( !file_exists($filename)) {
  150. _e('<font color="red"><strong>An .htaccess file was NOT found in your wp-admin folder.<br>BulletProof Mode for the wp-admin folder MUST also be activated when you have BulletProof Mode activated for the Root folder.</strong></font><br>');
  151. } else {
  152. if ($check_string == "17" && strpos($check_stringBPSQSE, "BPSQSE")) {
  153. _e('<font color="green"><strong>The .htaccess file that is activated in your wp-admin folder is:</strong></font><br>');
  154. print($section);
  155. } else {
  156. _e('<font color="red"><strong><br><br>A valid BPS .htaccess file was NOT found in your wp-admin folder. Either you have not activated BulletProof Mode for your wp-admin folder yet or the version of the wp-admin htaccess file that you are using is not .46.6. BulletProof Mode for the wp-admin folder MUST also be activated when you have BulletProof Mode activated for the Root folder. Please read the Read Me hover Tooltip above.</strong></font><br>');
  157. }
  158. }
  159. }
  160. // Check if BPS Deny ALL htaccess file is activated for the BPS Master htaccess folder
  161. function denyall_htaccess_status_master() {
  162. $filename = ABSPATH . '/wp-content/plugins/bulletproof-security/admin/htaccess/.htaccess';
  163. if (file_exists($filename)) {
  164. _e('<font color="green"><strong>&radic; Deny All protection activated for BPS Master /htaccess folder</strong></font><br>');
  165. } else {
  166. _e('<font color="red"><strong>Deny All protection NOT activated for BPS Master /htaccess folder</strong></font><br>');
  167. }
  168. }
  169. // Check if BPS Deny ALL htaccess file is activated for the /wp-content/bps-backup folder
  170. function denyall_htaccess_status_backup() {
  171. $filename = ABSPATH . '/wp-content/bps-backup/.htaccess';
  172. if (file_exists($filename)) {
  173. _e('<font color="green"><strong>&radic; Deny All protection activated for /wp-content/bps-backup folder</strong></font><br><br>');
  174. } else {
  175. _e('<font color="red"><strong>Deny All protection NOT activated for /wp-content/bps-backup folder</strong></font><br><br>');
  176. }
  177. }
  178. // File and Folder Permission Checking - substr error is suppressed @ else fileperms error if file does not exist
  179. function bps_check_perms($name,$path,$perm) {
  180. clearstatcache();
  181. $current_perms = @substr(sprintf(".%o.", fileperms($path)), -4);
  182. echo '<table style="width:100%;background-color:#fff;">';
  183. echo '<tr>';
  184. echo '<td style="background-color:#fff;padding:2px;width:150px;">' . $name . '</td>';
  185. echo '<td style="background-color:#fff;padding:2px;width:170px;">' . $path . '</td>';
  186. echo '<td style="background-color:#fff;padding:2px;width:85px;">' . $perm . '</td>';
  187. echo '<td style="background-color:#fff;padding:2px;">' . $current_perms . '</td>';
  188. echo '</tr>';
  189. echo '</table>';
  190. }
  191. // General BulletProof Security File Status Checking
  192. function general_bps_file_checks() {
  193. $dir='../';
  194. $filename = '.htaccess';
  195. if (file_exists($dir.$filename)) {
  196. _e('<font color="green">&radic; An .htaccess file was found in your root folder</font><br>');
  197. } else {
  198. _e('<font color="red">NO .htaccess file was found in your root folder</font><br>');
  199. }
  200. $filename = '.htaccess';
  201. if (file_exists($filename)) {
  202. _e('<font color="green">&radic; An .htaccess file was found in your /wp-admin folder</font><br>');
  203. } else {
  204. _e('<font color="red">NO .htaccess file was found in your /wp-admin folder</font><br>');
  205. }
  206. $filename = '/wp-content/plugins/bulletproof-security/admin/htaccess/default.htaccess';
  207. if (file_exists(ABSPATH . $filename)) {
  208. _e('<font color="green">&radic; A default.htaccess file was found in the /htaccess folder</font><br>');
  209. } else {
  210. _e('<font color="red">NO default.htaccess file found in the /htaccess folder</font><br>');
  211. }
  212. $filename = '/wp-content/plugins/bulletproof-security/admin/htaccess/secure.htaccess';
  213. if (file_exists(ABSPATH . $filename)) {
  214. _e('<font color="green">&radic; A secure.htaccess file was found in the /htaccess folder</font><br>');
  215. } else {
  216. _e('<font color="red">NO secure.htaccess file found in the /htaccess folder</font><br>');
  217. }
  218. $filename = '/wp-content/plugins/bulletproof-security/admin/htaccess/maintenance.htaccess';
  219. if (file_exists(ABSPATH . $filename)) {
  220. _e('<font color="green">&radic; A maintenance.htaccess file was found in the /htaccess folder</font><br>');
  221. } else {
  222. _e('<font color="red">NO maintenance.htaccess file found in the /htaccess folder</font><br>');
  223. }
  224. $filename = '/wp-content/plugins/bulletproof-security/admin/htaccess/bp-maintenance.php';
  225. if (file_exists(ABSPATH . $filename)) {
  226. _e('<font color="green">&radic; A bp-maintenance.php file was found in the /htaccess folder</font><br>');
  227. } else {
  228. _e('<font color="red">NO bp-maintenance.php file found in the /htaccess folder</font><br>');
  229. }
  230. $filename = '/wp-content/plugins/bulletproof-security/admin/htaccess/bps-maintenance-values.php';
  231. if (file_exists(ABSPATH . $filename)) {
  232. _e('<font color="green">&radic; A bps-maintenance-values.php file was found in the /htaccess folder</font><br>');
  233. } else {
  234. _e('<font color="red">NO bps-maintenance-values.php file found in the /htaccess folder</font><br>');
  235. }
  236. $filename = '/wp-content/plugins/bulletproof-security/admin/htaccess/wpadmin-secure.htaccess';
  237. if (file_exists(ABSPATH . $filename)) {
  238. _e('<font color="green">&radic; A wpadmin-secure.htaccess file was found in the /htaccess folder</font><br>');
  239. } else {
  240. _e('<font color="red">NO wpadmin-secure.htaccess file found in the /htaccess folder</font><br>');
  241. }
  242. $filename = '/wp-content/bps-backup/root.htaccess';
  243. if (file_exists(ABSPATH . $filename)) {
  244. _e('<font color="green">&radic; Your Current Root .htaccess File is backed up</font><br>');
  245. } else {
  246. _e('<font color="red">Your Current Root .htaccess file is NOT backed up yet</font><br>');
  247. }
  248. $filename = '/wp-content/bps-backup/wpadmin.htaccess';
  249. if (file_exists(ABSPATH . $filename)) {
  250. _e('<font color="green">&radic; Your Current wp-admin .htaccess File is backed up</font><br>');
  251. } else {
  252. _e('<font color="red">Your Current wp-admin .htaccess File is NOT backed up yet</font><br>');
  253. }
  254. $filename = '/wp-content/bps-backup/master-backups/backup_default.htaccess';
  255. if (file_exists(ABSPATH . $filename)) {
  256. _e('<font color="green">&radic; Your BPS Master default.htaccess file is backed up</font><br>');
  257. } else {
  258. _e('<font color="red">Your BPS Master default.htaccess file is NOT backed up yet</font><br>');
  259. }
  260. $filename = '/wp-content/bps-backup/master-backups/backup_secure.htaccess';
  261. if (file_exists(ABSPATH . $filename)) {
  262. _e('<font color="green">&radic; Your BPS Master secure.htaccess file is backed up</font><br>');
  263. } else {
  264. _e('<font color="red">Your BPS Master secure.htaccess file is NOT backed up yet</font><br>');
  265. }
  266. $filename = '/wp-content/bps-backup/master-backups/backup_wpadmin-secure.htaccess';
  267. if (file_exists(ABSPATH . $filename)) {
  268. _e('<font color="green">&radic; Your BPS Master wpadmin-secure.htaccess file is backed up</font><br>');
  269. } else {
  270. _e('<font color="red">Your BPS Master wpadmin-secure.htaccess file is NOT backed up yet</font><br>');
  271. }
  272. $filename = '/wp-content/bps-backup/master-backups/backup_maintenance.htaccess';
  273. if (file_exists(ABSPATH . $filename)) {
  274. _e('<font color="green">&radic; Your BPS Master maintenance.htaccess file is backed up</font><br>');
  275. } else {
  276. _e('<font color="red">Your BPS Master maintenance.htaccess file is NOT backed up yet</font><br>');
  277. }
  278. $filename = '/wp-content/bps-backup/master-backups/backup_bp-maintenance.php';
  279. if (file_exists(ABSPATH . $filename)) {
  280. _e('<font color="green">&radic; Your BPS Master bp-maintenance.php file is backed up</font><br>');
  281. } else {
  282. _e('<font color="red">Your BPS Master bp-maintenance.php file is NOT backed up yet</font><br>');
  283. }
  284. $filename = '/wp-content/bps-backup/master-backups/backup_bps-maintenance-values.php';
  285. if (file_exists(ABSPATH . $filename)) {
  286. _e('<font color="green">&radic; Your BPS Master bps-maintenance-values.php file is backed up</font><br>');
  287. } else {
  288. _e('<font color="red">Your BPS Master bps-maintenance-values.php file is NOT backed up yet</font><br>');
  289. }
  290. }
  291. // Backup and Restore page - Backed up Root and wp-admin .htaccess file checks
  292. function backup_restore_checks() {
  293. $bp_root_back = ABSPATH . '/wp-content/bps-backup/root.htaccess';
  294. if (file_exists($bp_root_back)) {
  295. _e('<font color="green"><strong>&radic; Your Root .htaccess file is backed up.</strong></font><br>');
  296. } else {
  297. _e('<font color="red"><strong>Your Root .htaccess file is NOT backed up either because you have not done a Backup yet, an .htaccess file did NOT already exist in your root folder or because of a file copy error. Read the "Current Backed Up .htaccess Files Status Read Me" hover ToolTip for more specific information.</strong></font><br><br>');
  298. }
  299. $bp_wpadmin_back = ABSPATH . '/wp-content/bps-backup/wpadmin.htaccess';
  300. if (file_exists($bp_wpadmin_back)) {
  301. _e('<font color="green"><strong>&radic; Your wp-admin .htaccess file is backed up.</strong></font><br>');
  302. } else {
  303. _e('<font color="red"><strong>Your wp-admin .htaccess file is NOT backed up either because you have not done a Backup yet, an .htaccess file did NOT already exist in your /wp-admin folder or because of a file copy error. Read the "Current Backed Up .htaccess Files Status Read Me" hover ToolTip for more specific information.</strong></font><br>');
  304. }
  305. }
  306. // Backup and Restore page - General check if existing .htaccess files already exist
  307. function general_bps_file_checks_backup_restore() {
  308. $dir='../';
  309. $filename = '.htaccess';
  310. if (file_exists($dir.$filename)) {
  311. _e('<font color="green">&radic; An .htaccess file was found in your root folder</font><br>');
  312. } else {
  313. _e('<font color="red">NO .htaccess file was found in your root folder</font><br>');
  314. }
  315. $filename = '.htaccess';
  316. if (file_exists($filename)) {
  317. _e('<font color="green">&radic; An .htaccess file was found in your /wp-admin folder</font><br>');
  318. } else {
  319. _e('<font color="red">NO .htaccess file was found in your /wp-admin folder</font><br>');
  320. }
  321. }
  322. // Backup and Restore page - BPS Master .htaccess backup file checks
  323. function bps_master_file_backups() {
  324. $bps_default_master = ABSPATH . '/wp-content/bps-backup/master-backups/backup_default.htaccess';
  325. if (file_exists($bps_default_master)) {
  326. _e('<font color="green"><strong>&radic; The default.htaccess Master file is backed up.</strong></font><br>');
  327. } else {
  328. _e('<font color="red"><strong>Your default.htaccess Master file has NOT been backed up yet!</strong></font><br>');
  329. }
  330. $bps_secure_master = ABSPATH . '/wp-content/bps-backup/master-backups/backup_secure.htaccess';
  331. if (file_exists($bps_secure_master)) {
  332. _e('<font color="green"><strong>&radic; The secure.htaccess Master file is backed up.</strong></font><br>');
  333. } else {
  334. _e('<font color="red"><strong>Your secure.htaccess Master file has NOT been backed up yet!</strong></font><br>');
  335. }
  336. $bps_wpadmin_master = ABSPATH . '/wp-content/bps-backup/master-backups/backup_wpadmin-secure.htaccess';
  337. if (file_exists($bps_wpadmin_master)) {
  338. _e('<font color="green"><strong>&radic; The wpadmin-secure.htaccess Master file is backed up.</strong></font><br>');
  339. } else {
  340. _e('<font color="red"><strong>Your wpadmin-secure.htaccess Master file has NOT been backed up yet!</strong></font><br>');
  341. }
  342. $bps_maintenance_master = ABSPATH . '/wp-content/bps-backup/master-backups/backup_maintenance.htaccess';
  343. if (file_exists($bps_maintenance_master)) {
  344. _e('<font color="green"><strong>&radic; The maintenance.htaccess Master file is backed up.<strong</font><br>');
  345. } else {
  346. _e('<font color="red"><strong>Your maintenance.htaccess Master file has NOT been backed up yet!</strong></font><br>');
  347. }
  348. $bps_bp_maintenance_master = ABSPATH . '/wp-content/bps-backup/master-backups/backup_bp-maintenance.php';
  349. if (file_exists($bps_bp_maintenance_master)) {
  350. _e('<font color="green"><strong>&radic; The bp-maintenance.php Master file is backed up.</strong></font><br>');
  351. } else {
  352. _e('<font color="red"><strong>Your bp-maintenance.php Master file has NOT been backed up yet!</strong></font><br>');
  353. }
  354. $bps_bp_maintenance_values = ABSPATH . '/wp-content/bps-backup/master-backups/backup_bps-maintenance-values.php';
  355. if (file_exists($bps_bp_maintenance_values)) {
  356. _e('<font color="green"><strong>&radic; The bps-maintenance-values.php Master file is backed up.</strong></font><br>');
  357. } else {
  358. _e('<font color="red"><strong>Your bps-maintenance-values.php Master file has NOT been backed up yet!</strong></font><br>');
  359. }
  360. }
  361. // Check if Permalinks are enabled
  362. $permalink_structure = get_option('permalink_structure');
  363. function bps_check_permalinks() {
  364. if ( get_option('permalink_structure') != '' ) {
  365. _e('Permalinks Enabled: <font color="green"><strong>&radic; Permalinks are Enabled</strong></font>');
  366. } else {
  367. _e('Permalinks Enabled: <font color="red"><strong>WARNING! Permalinks are NOT Enabled<br>Permalinks MUST be enabled for BPS to function correctly</strong></font>');
  368. }
  369. }
  370. // Check PHP version
  371. function bps_check_php_version() {
  372. if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
  373. _e('PHP Version Check: <font color="green"><strong>&radic; Running PHP5</strong></font><br>');
  374. }
  375. if (version_compare(PHP_VERSION, '5.0.0', '<')) {
  376. _e('<font color="red"><strong>WARNING! BPS requires PHP5 to function correctly. Your PHP version is: ' . PHP_VERSION . '</strong></font><br>');
  377. }
  378. }
  379. // Heads Up Display - Check PHP version - top error message new activations / installations
  380. function bps_check_php_version_error() {
  381. if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
  382. _e('');
  383. }
  384. if (version_compare(PHP_VERSION, '5.0.0', '<')) {
  385. _e('<font color="red"><strong>WARNING! BPS requires at least PHP5 to function correctly. Your PHP version is: ' . PHP_VERSION . '</font></strong><br><strong><a href="http://www.ait-pro.com/aitpro-blog/1166/bulletproof-security-plugin-support/bulletproof-security-plugin-guide-bps-version-45/#bulletproof-security-issues-problems" target="_blank">BPS Guide - PHP5 Solution</a></strong><br><strong>The BPS Guide will open in a new browser window. You will not be directed away from your WordPress Dashboard.</strong><br>');
  386. }
  387. }
  388. // Heads Up Display - Check if Permalinks are enabled - top error message new activations / installations
  389. $permalink_structure = get_option('permalink_structure');
  390. function bps_check_permalinks_error() {
  391. if ( get_option('permalink_structure') != '' ) {
  392. _e('');
  393. } else {
  394. _e('<br><font color="red"><strong>WARNING! Permalinks are NOT Enabled. Permalinks MUST be enabled for BPS to function correctly</strong></font><br><strong><a href="http://www.ait-pro.com/aitpro-blog/2304/wordpress-tips-tricks-fixes/permalinks-wordpress-custom-permalinks-wordpress-best-wordpress-permalinks-structure/" target="_blank">BPS Guide - Enabling Permalinks</a></strong><br><strong>The BPS Guide will open in a new browser window. You will not be directed away from your WordPress Dashboard.</strong><br>');
  395. }
  396. }
  397. // Heads Up Display - Check if this is a Windows IIS server and if IIS7 supports permalink rewriting
  398. function bps_check_iis_supports_permalinks() {
  399. global $wp_rewrite, $is_IIS, $is_iis7;
  400. if ( $is_IIS && !iis7_supports_permalinks() ) {
  401. _e('<br><font color="red"><strong>WARNING! BPS has detected that your Server is a Windows IIS Server that does not support .htaccess rewriting. Do NOT activate BulletProof Security Modes unless you are absolutely sure you know what you are doing. Your Server Type is: ' . $_SERVER['SERVER_SOFTWARE'] . '</strong></font><br><strong><a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">WordPress Codex - Using Permalinks - see IIS section</a></strong><br><strong>This link will open in a new browser window. You will not be directed away from your WordPress Dashboard.</strong><br>To remove this message permanently click <strong><a href="http://www.ait-pro.com/aitpro-blog/2566/bulletproof-security-plugin-support/bulletproof-security-error-messages" target="_blank">here.</a></strong><br>');
  402. } else {
  403. _e('');
  404. }
  405. }
  406. // Heads Up Display - mkdir and chmod errors are suppressed on activation - check if /bps-backup folder exists
  407. function bps_hud_check_bpsbackup() {
  408. if( !is_dir (WP_CONTENT_DIR . '/bps-backup')) {
  409. _e('<br><font color="red"><strong>WARNING! BPS was unable to automatically create the /wp-content/bps-backup folder.</strong></font><br><strong>You will need to create the /wp-content/bps-backup folder manually via FTP. The folder permissions for the bps-backup folder need to be set to 755 in order to successfully perform permanent online backups.</strong><br>To remove this message permanently click <strong><a href="http://www.ait-pro.com/aitpro-blog/2566/bulletproof-security-plugin-support/bulletproof-security-error-messages" target="_blank">here.</a></strong><br>');
  410. } else {
  411. _e('');
  412. }
  413. if( !is_dir (WP_CONTENT_DIR . '/bps-backup/master-backups')) {
  414. _e('<br><font color="red"><strong>WARNING! BPS was unable to automatically create the /wp-content/bps-backup/master-backups folder.</strong></font><br><strong>You will need to create the /wp-content/bps-backup/master-backups folder manually via FTP. The folder permissions for the master-backups folder need to be set to 755 in order to successfully perform permanent online backups.</strong><br>To remove this message permanently click <strong><a href="http://www.ait-pro.com/aitpro-blog/2566/bulletproof-security-plugin-support/bulletproof-security-error-messages" target="_blank">here.</a></strong><br>');
  415. } else {
  416. _e('');
  417. }
  418. }
  419. // Heads Up Display - Check if PHP Safe Mode is On - 1 is On - 0 is Off
  420. function bps_check_safemode() {
  421. if (ini_get('safe_mode') == '1') {
  422. _e('<br><font color="red"><strong>WARNING! BPS has detected that Safe Mode is set to On in your php.ini file.</strong></font><br><strong>If you see errors that BPS was unable to automatically create the backup folders this is probably the reason why.</strong><br>To remove this message permanently click <strong><a href="http://www.ait-pro.com/aitpro-blog/2566/bulletproof-security-plugin-support/bulletproof-security-error-messages" target="_blank">here.</a></strong><br>');
  423. } else {
  424. _e('');
  425. }
  426. }
  427. // Heads Up Display - Check if W3TC is active or not and check root htaccess file for W3TC htaccess code
  428. function bps_w3tc_htaccess_check($plugin_var) {
  429. $filename = ABSPATH . '.htaccess';
  430. $string = file_get_contents($filename);
  431. $plugin_var = 'w3-total-cache';
  432. $return_var = in_array( $plugin_var. '/' .$plugin_var. '.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
  433. if ($return_var == 1) { // return $return_var; ---- 1 equals active
  434. if (!strpos($string, "W3TC")) {
  435. _e('<font color="red"><strong>W3 Total Cache is activated, but W3TC .htaccess code was NOT found in your root .htaccess file.</strong></font><br><strong>W3TC needs to be redeployed by clicking either the auto-install or deploy buttons. Click to <a href="admin.php?page=w3tc_general" >Redeploy W3TC.</a></strong><br><br>');
  436. }
  437. }
  438. elseif ($return_var != 1) {
  439. if (strpos($string, "W3TC")) {
  440. _e('<font color="red"><strong>W3 Total Cache is deactivated and W3TC .htaccess code was found in your root .htaccess file.</strong></font><br><strong>If this is just temporary then this warning message will go away when you reactivate W3TC. If you are planning on uninstalling W3TC the W3TC .htaccess code will be automatically removed from your root .htaccess file when you uninstall W3TC. If you manually edit your root htaccess file then refresh your browser to perform a new HUD htaccess file check.</strong><br><br>');
  441. }
  442. }
  443. }
  444. // Heads Up Display - Check if WPSC is active or not and check root htaccess file for WPSC htaccess code
  445. function bps_wpsc_htaccess_check($plugin_var) {
  446. $filename = ABSPATH . '.htaccess';
  447. $string = file_get_contents($filename);
  448. $plugin_var = 'wp-super-cache';
  449. $return_var = in_array( $plugin_var. '/' .'wp-cache.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
  450. if ($return_var == 1) { // return $return_var; ---- 1 equals active
  451. if (!strpos($string, "WPSuperCache")) {
  452. _e('<font color="red"><strong>WP Super Cache is activated, but either you are not using WPSC mod_rewrite to serve cache files or the WPSC .htaccess code was NOT found in your root .htaccess file.</strong></font><br><strong>If you are not using WPSC mod_rewrite then just add this commented out line of code in anywhere in your root htaccess file - # WPSuperCache. If you are using WPSC mod_rewrite and the WPSC htaccess code is not in your root htaccess file then click this <a href="options-general.php?page=wpsupercache&tab=settings" >Update WPSC link</a> to go to the WPSC Settings page and click the Update Mod_Rewrite Rules button. It appears that the BPS filters are working correctly with the WPSC htaccess code being written to the bottom of the root htaccess file, but I recommend that you manually cut and paste the WPSC htaccess code and the section of Wordpress htaccess code that starts with # BEGIN WordPress and ends with # END WordPress to the top area of your root htaccess file right after Options -Indexes in your root htaccess file. Refresh your browser to perform a new HUD htaccess file check.</strong><br><br>');
  453. }
  454. }
  455. elseif ($return_var != 1) {
  456. if (strpos($string, "WPSuperCache") ) {
  457. _e('<font color="red"><strong>WP Super Cache is deactivated and WPSC .htaccess code - # BEGIN WPSuperCache # END WPSuperCache - was found in your root .htaccess file.</strong></font><br><strong>If this is just temporary then this warning message will go away when you reactivate WPSC. You will need to set up and reconfigure WPSC again when you reactivate WPSC. If you are planning on uninstalling WPSC the WPSC .htaccess code will be automatically removed from your root .htaccess file when you uninstall WPSC. If you added commented out line of code in anywhere in your root htaccess file - # WPSuperCache - then delete it and refresh your browser. It appears that the BPS filters are working correctly with the WPSC htaccess code being written to the bottom of the root htaccess file, but I recommend that you manually cut and paste the WPSC htaccess code and the section of Wordpress htaccess code that starts with # BEGIN WordPress and ends with # END WordPress to the top area of your root htaccess file right after Options -Indexes in your root htaccess file.</strong><br><br>');
  458. }
  459. }
  460. }
  461. // Get WordPress Root Installation Folder - Borrowed from WP Core
  462. function bps_wp_get_root_folder() {
  463. $site_root = parse_url(get_option('siteurl'));
  464. if ( isset( $site_root['path'] ) )
  465. $site_root = trailingslashit($site_root['path']);
  466. else
  467. $site_root = '/';
  468. return $site_root;
  469. }
  470. // Display Root or Subfolder Installation Type
  471. function bps_wp_get_root_folder_display_type() {
  472. $site_root = parse_url(get_option('siteurl'));
  473. if ( isset( $site_root['path'] ) )
  474. $site_root = trailingslashit($site_root['path']);
  475. else
  476. $site_root = '/';
  477. if (preg_match('/[a-zA-Z0-9]/', $site_root)) {
  478. echo "Subfolder Installation";
  479. } else {
  480. echo "Root Folder Installation";
  481. }
  482. }
  483. // Check for Multisite
  484. function bps_multsite_check() {
  485. if ( is_multisite() ) {
  486. _e('Multisite: <strong>Multisite is enabled</strong><br>');
  487. } else {
  488. _e('Multisite: <strong>Multisite is not enabled</strong><br>');
  489. }
  490. }
  491. // Security Modes Page - AutoMagic Single site message
  492. function bps_multsite_check_smode_single() {
  493. global $wpdb;
  494. if ( !is_multisite() ) {
  495. _e('<font color="green"><strong>Use These AutoMagic Buttons For Your Website<br>For Standard WP Installations</strong></font>');
  496. } else {
  497. _e('<strong>Do Not Use These AutoMagic Buttons</strong><br>For Standard WP Single Sites Only');
  498. }
  499. }
  500. // Security Modes Page - AutoMagic Multisite sub-directory message
  501. function bps_multsite_check_smode_MUSDir() {
  502. global $wpdb;
  503. if ( is_multisite() && !is_subdomain_install() ) {
  504. _e('<font color="green"><strong>Use These AutoMagic Buttons For Your Website<br>For WP Network / MU sub-directory Installations</strong></font>');
  505. } else {
  506. _e('<strong>Do Not Use These AutoMagic Buttons</strong><br>For Network / MU Sub-directory Webites Only');
  507. }
  508. }
  509. // Security Modes Page - AutoMagic Multisite sub-domain message
  510. function bps_multsite_check_smode_MUSDom() {
  511. global $wpdb;
  512. if ( is_multisite() && is_subdomain_install() ) {
  513. //if ( is_subdomain_install() ) {
  514. _e('<font color="green"><strong>Use These AutoMagic Buttons For Your Website<br>For WP Network / MU sub-domain Installations</strong></font>');
  515. } else {
  516. _e('<strong>Do Not Use These AutoMagic Buttons</strong><br>For Network / MU Sub-domain Websites Only');
  517. }
  518. }
  519. /*
  520. // Security Modes Page - htaccess warning for Multisite
  521. function bps_multsite_check_smode() {
  522. if ( is_multisite() ) {
  523. _e('<strong>WordPress Network (Multisite) Installation Detected</strong><br>Please read the Read Me help hover tooltip for an additional step required to set up WordPress Network sites.<br>');
  524. } else {
  525. _e('');
  526. }
  527. }
  528. */
  529. // Check if username Admin exists
  530. function check_admin_username() {
  531. global $wpdb;
  532. $name = $wpdb->get_var("SELECT user_login FROM $wpdb->users WHERE user_login='admin'");
  533. if ($name=="admin"){
  534. _e('<font color="red"><strong>Recommended Security Changes: Username "admin" is being used. It is recommended that you change the default administrator username "admin" to a new unique username.</strong></font><br><br>');
  535. } else {
  536. _e('<font color="green"><strong>&radic; The Administrator username "admin" is not being used</strong></font><br>');
  537. }
  538. }
  539. // Check for WP readme.html file and if valid BPS .htaccess file is activated
  540. // Get contents of Root .htaccess file from 3-45 - if "6" found in string position 17 - offset 16 - good - else bad
  541. // Check for WP readme.html file and if valid BPS .htaccess file is activated
  542. function bps_filesmatch_check_readmehtml() {
  543. $htaccess_filename = ABSPATH . '.htaccess';
  544. $filename = ABSPATH . 'readme.html';
  545. $section = @file_get_contents($htaccess_filename, NULL, NULL, 3, 45);
  546. $check_string = @strpos($section, "6", 16);
  547. $check_stringBPSQSE = file_get_contents($htaccess_filename);
  548. if (file_exists($htaccess_filename)) {
  549. if ($check_string == "17") {
  550. _e('');
  551. }
  552. if ( !file_exists($filename)) {
  553. _e('<font color="green"><strong>&radic; The WP readme.html file does not exist</strong></font><br>');
  554. } else {
  555. if ($check_string == "17" && strpos($check_stringBPSQSE, "BPSQSE")) {
  556. _e('<font color="green"><strong>&radic; The WP readme.html file is .htaccess protected</strong></font><br>');
  557. } else {
  558. _e('<font color="red"><strong>The WP readme.html file is not .htaccess protected</strong></font><br>');
  559. }
  560. }}}
  561. // Check for WP /wp-admin/install.php file and if valid BPS .htaccess file is activated
  562. // Get contents of Root .htaccess file from 3-45 - if "6" found in string position 17 - offset 16 - good - else bad
  563. function bps_filesmatch_check_installphp() {
  564. $htaccess_filename = ABSPATH . 'wp-admin/.htaccess';
  565. $filename = ABSPATH . 'wp-admin/install.php';
  566. $check_stringBPSQSE = file_get_contents($htaccess_filename);
  567. $section = @file_get_contents($htaccess_filename, NULL, NULL, 3, 45);
  568. $check_string = @strpos($section, "6", 16);
  569. if (file_exists($htaccess_filename)) {
  570. if ($check_string == "17") {
  571. _e('');
  572. }
  573. if ( !file_exists($filename)) {
  574. _e('<font color="green"><strong>&radic; The WP /wp-admin/install.php file does not exist</strong></font><br>');
  575. } else {
  576. if ($check_string == "17" && strpos($check_stringBPSQSE, "BPSQSE")) {
  577. _e('<font color="green"><strong>&radic; The WP /wp-admin/install.php file is .htaccess protected</strong></font><br>');
  578. } else {
  579. _e('<font color="red"><strong>The WP /wp-admin/install.php file is not .htaccess protected</strong></font><br>');
  580. }
  581. }}}
  582. // Check BPS Pro Modules Status
  583. function check_bps_pro_mod () {
  584. global $bulletproof_security;
  585. $filename_pro = 'wp-content/plugins/bulletproof-security/admin/options-bps-pro-modules.php';
  586. if (file_exists(ABSPATH . $filename_pro)) {
  587. $section_pro = file_get_contents(ABSPATH . $filename, NULL, NULL, 5, 10);
  588. _e('<font color="green"><strong>&radic; BulletProof Security Pro Modules are installed and activated.</strong></font><br>');
  589. var_dump($section_pro);
  590. } else {
  591. _e('<font color="black"><br>*BPS Pro Modules are not installed</font><br>');
  592. }
  593. }
  594. // Get SQL Mode from WPDB
  595. function bps_get_sql_mode() {
  596. global $wpdb;
  597. $mysqlinfo = $wpdb->get_results("SHOW VARIABLES LIKE 'sql_mode'");
  598. if (is_array($mysqlinfo)) $sql_mode = $mysqlinfo[0]->Value;
  599. if (empty($sql_mode)) $sql_mode = __('Not Set');
  600. else $sql_mode = __('Off');
  601. }
  602. // Show DB errors should already be set to false in /includes/wp-db.php
  603. // Extra function insurance show_errors = false
  604. function bps_wpdb_errors_off() {
  605. global $wpdb;
  606. $wpdb->show_errors = false;
  607. if ($wpdb->show_errors != false) {
  608. _e('<font color="red"><strong>WARNING! WordPress DB Show Errors Is Set To: true! DB errors will be displayed</strong></font><br>');
  609. } else {
  610. _e('<font color="green"><strong>&radic; WordPress DB Show Errors Function Is Set To: </strong></font>');
  611. _e('<font color="black"><strong>false</strong></font><br>');
  612. _e('<font color="green"><strong>&radic; WordPress Database Errors Are Turned Off</strong></font><br>');
  613. }
  614. }
  615. // Hide / Remove WordPress Version Meta Generator Tag - echo only for remove_action('wp_head', 'wp_generator');
  616. function bps_wp_remove_version() {
  617. global $wp_version;
  618. _e('<font color="green"><strong>&radic; WordPress Meta Generator Tag Removed<br>&radic; WordPress Version Is Not Displayed / Not Shown</strong></font><br>');
  619. }
  620. // Return Nothing For WP Version Callback
  621. function bps_wp_generator_meta_removed() {
  622. if ( !is_admin()) {
  623. global $wp_version;
  624. $wp_version = '';
  625. }
  626. }
  627. ?>