PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/adatux_/uakami
PHP | 164 lines | 111 code | 29 blank | 24 comment | 10 complexity | 187c566033768ea558a2f449a10fb367 MD5 | raw file
  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. function bulletproof_security_admin_init() {
  9. // whitelist BPS DB options
  10. register_setting('bulletproof_security_options', 'bulletproof_security_options', 'bulletproof_security_options_validate');
  11. register_setting('bulletproof_security_options_autolock', 'bulletproof_security_options_autolock', 'bulletproof_security_options_validate_autolock');
  12. register_setting('bulletproof_security_options_customcode', 'bulletproof_security_options_customcode', 'bulletproof_security_options_validate_customcode');
  13. register_setting('bulletproof_security_options_customcode_WPA', 'bulletproof_security_options_customcode_WPA', 'bulletproof_security_options_validate_customcode_WPA');
  14. register_setting('bulletproof_security_options_mynotes', 'bulletproof_security_options_mynotes', 'bulletproof_security_options_validate_mynotes');
  15. register_setting('bulletproof_security_options_maint', 'bulletproof_security_options_maint', 'bulletproof_security_options_validate_maint');
  16. // Register BPS js
  17. wp_register_script( 'bps-js', plugins_url('/bulletproof-security/admin/js/bulletproof-security-admin.js'));
  18. // Register BPS stylesheet
  19. wp_register_style('bps-css', plugins_url('/bulletproof-security/admin/css/bulletproof-security-admin-blue.css'));
  20. // Create BPS Backup Folder structure - suppressing errors on activation - errors displayed in HUD
  21. if( !is_dir (WP_CONTENT_DIR . '/bps-backup')) {
  22. @mkdir (WP_CONTENT_DIR . '/bps-backup/master-backups', 0755, true);
  23. @chmod (WP_CONTENT_DIR . '/bps-backup/', 0755);
  24. @chmod (WP_CONTENT_DIR . '/bps-backup/master-backups/', 0755);
  25. }
  26. // Create the BPS Backup folder Deny all .htaccess file - recursive will protect all /bps-backup subfolders
  27. $bps_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/deny-all.htaccess';
  28. $bps_ARHtaccess = WP_CONTENT_DIR . '/bps-backup/.htaccess';
  29. if (!file_exists($bps_ARHtaccess)) {
  30. @copy($bps_denyall_htaccess, $bps_ARHtaccess);
  31. }
  32. // Create logs folder
  33. if( !is_dir (WP_CONTENT_DIR . '/bps-backup/logs')) {
  34. @mkdir (WP_CONTENT_DIR . '/bps-backup/logs', 0755, true);
  35. @chmod (WP_CONTENT_DIR . '/bps-backup/logs/', 0755);
  36. }
  37. // Create the Security / HTTP error log in /logs
  38. $bpsProLog = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/http_error_log.txt';
  39. $bpsProLogARQ = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
  40. if (!file_exists($bpsProLogARQ)) {
  41. @copy($bpsProLog, $bpsProLogARQ);
  42. }
  43. // Load scripts and styles only on BPS specified pages
  44. add_action('load-bulletproof-security/admin/options.php', 'bulletproof_security_load_settings_page');
  45. }
  46. // BPS Menu
  47. function bulletproof_security_admin_menu() {
  48. if (is_multisite() && !is_super_admin()) {
  49. $bpsSuperAdminsError = 'Only Super Admins can access BPS';
  50. return $bpsSuperAdminsError;
  51. } else {
  52. //if (function_exists('add_menu_page')){
  53. add_menu_page(__('BulletProof Security ~ htaccess Core', 'bulletproof-security'), __('BPS Security', 'bulletproof-security'), 'manage_options', 'bulletproof-security/admin/options.php', '', plugins_url('bulletproof-security/admin/images/bps-icon-small.png'));
  54. add_submenu_page('bulletproof-security/admin/options.php', __('BulletProof Security ~ htaccess Core', 'bulletproof-security'), __('BPS Settings', 'bulletproof-security'), 'manage_options', 'bulletproof-security/admin/options.php' );
  55. }}
  56. // Loads Settings for H-Core and P-Security
  57. // Enqueue BPS scripts and styles
  58. function bulletproof_security_load_settings_page() {
  59. global $bulletproof_security;
  60. wp_enqueue_script('jquery');
  61. wp_enqueue_script('jquery-ui-tabs');
  62. wp_enqueue_script('jquery-ui-dialog');
  63. wp_enqueue_script('jquery-form');
  64. //wp_enqueue_script('swfobject');
  65. wp_enqueue_script('bps-js');
  66. // Engueue BPS stylesheet
  67. wp_enqueue_style('bps-css', plugins_url('/bulletproof-security/admin/css/bulletproof-security-admin-blue.css'));
  68. }
  69. function bulletproof_security_install() {
  70. global $bulletproof_security;
  71. $previous_install = get_option('bulletproof_security_options');
  72. if ( $previous_install ) {
  73. if ( version_compare($previous_install['version'], '.48', '<') )
  74. remove_role('denied');
  75. }
  76. }
  77. // Deactivation - remove/delete nothing at this point
  78. function bulletproof_security_deactivation() {
  79. // nothing needs to removed on deactivation for now
  80. }
  81. // Uninstall - do not unlink .htaccess files on uninstall to prevent catastrophic user errors
  82. function bulletproof_security_uninstall() {
  83. require_once( ABSPATH . 'wp-admin/includes/plugin.php');
  84. $options = get_option('bulletproof_security_options');
  85. delete_option('bulletproof_security_options');
  86. delete_option('bulletproof_security_options_customcode');
  87. delete_option('bulletproof_security_options_customcode_WPA');
  88. delete_option('bulletproof_security_options_maint');
  89. delete_option('bulletproof_security_options_mynotes');
  90. delete_option('bulletproof_security_options_autolock');
  91. }
  92. // Validate BPS options
  93. function bulletproof_security_options_validate($input) {
  94. $options = get_option('bulletproof_security_options');
  95. $options['bps_blank'] = wp_filter_nohtml_kses($input['bps_blank']);
  96. return $options;
  97. }
  98. // Validate BPS options - Maintenance Mode Form
  99. function bulletproof_security_options_validate_maint($input) {
  100. $options = get_option('bulletproof_security_options_maint');
  101. $options['bps-site-title'] = wp_filter_nohtml_kses($input['bps-site-title']);
  102. $options['bps-message-1'] = wp_filter_nohtml_kses($input['bps-message-1']);
  103. $options['bps-message-2'] = wp_filter_nohtml_kses($input['bps-message-2']);
  104. $options['bps-retry-after'] = wp_filter_nohtml_kses($input['bps-retry-after']);
  105. $options['bps-background-image'] = wp_filter_nohtml_kses($input['bps-background-image']);
  106. return $options;
  107. }
  108. // Validate BPS options - Options.php - Edit/Uploads/Downloads page - Root .htaccess file AutoLock
  109. function bulletproof_security_options_validate_autolock($input) {
  110. $options = get_option('bulletproof_security_options_autolock');
  111. $options['bps_root_htaccess_autolock'] = wp_filter_nohtml_kses($input['bps_root_htaccess_autolock']);
  112. return $options;
  113. }
  114. // Validate BPS options - BPS Custom Code - Root .htaccess
  115. function bulletproof_security_options_validate_customcode($input) {
  116. $options = get_option('bulletproof_security_options_customcode');
  117. $options['bps_customcode_one'] = esc_html($input['bps_customcode_one']);
  118. $options['bps_customcode_two'] = esc_html($input['bps_customcode_two']);
  119. $options['bps_customcode_three'] = esc_html($input['bps_customcode_three']);
  120. return $options;
  121. }
  122. // Validate BPS options - BPS Custom Code - WP-admin .htaccess
  123. function bulletproof_security_options_validate_customcode_WPA($input) {
  124. $options = get_option('bulletproof_security_options_customcode_WPA');
  125. $options['bps_customcode_one_wpa'] = esc_html($input['bps_customcode_one_wpa']);
  126. $options['bps_customcode_two_wpa'] = esc_html($input['bps_customcode_two_wpa']);
  127. return $options;
  128. }
  129. // Validate BPS options - BPS "My Notes" settings
  130. function bulletproof_security_options_validate_mynotes($input) {
  131. $options = get_option('bulletproof_security_options_mynotes');
  132. $options['bps_my_notes'] = esc_html($input['bps_my_notes']);
  133. return $options;
  134. }
  135. ?>