PluginProbe
Patchstack – WordPress & Plugins Security / 2.3.0
Patchstack – WordPress & Plugins Security v2.3.0
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
patchstack / includes / admin / general.php

general.php in Patchstack – WordPress & Plugins Security 2.3.0, at includes/admin/general.php

120 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Do not allow the file to be called directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * This class is used for any general admin functionality.
10 * For example to display general errors on all pages or event listeners.
11 */
12 class P_Admin_General extends P_Core {
13
14 /**
15 * Add any general actions for the backend.
16 *
17 * @param Patchstack $core
18 * @return void
19 */
20 public function __construct( $core ) {
21 parent::__construct( $core );
22
23 // Add admin and network notices.
24 add_action( 'admin_notices', [ $this, 'file_error_notice' ] );
25 add_action( 'network_admin_notices', [ $this, 'file_error_notice' ] );
26 add_action( 'update_option_siteurl', [ $this, 'update_option_url' ], 10, 2 );
27 add_action( 'update_option', [ $this, 'update_option_ap' ], 10, 3 );
28
29 // If the firewall or whitelist rules do not exist, attempt to pull fresh.
30 $token = get_option( 'patchstack_api_token', false );
31 if ( ! empty( $token ) && ( get_option( 'patchstack_firewall_rules', '' ) == '' || get_option( 'patchstack_whitelist_keys_rules' ) == '' ) && get_option( 'patchstack_license_free', 0 ) != 1 ) {
32 do_action( 'patchstack_post_dynamic_firewall_rules' );
33 }
34 }
35
36 /**
37 * Display error message if file/folder permissions are not set properly.
38 *
39 * @return void
40 */
41 public function file_error_notice() {
42 // No need to display this error if the .htaccess functionality has been disabled.
43 if ( get_site_option( 'patchstack_disable_htaccess', 0 ) || ( defined( 'PS_DISABLE_HTACCESS' ) && PS_DISABLE_HTACCESS ) ) {
44 return;
45 }
46
47 // No need to display if a free user without protection.
48 if ( get_option( 'patchstack_license_free', 0 ) == 1 ) {
49 return;
50 }
51
52 // No need to display on nginx.
53 if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && stripos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ) {
54 return;
55 }
56
57 // Check root .htaccess file and data folder writability.
58 $files = [];
59 if ( file_exists( ABSPATH . '.htaccess' ) && ! wp_is_writable( ABSPATH . '.htaccess' ) ) {
60 array_push( $files, ABSPATH . '.htaccess' );
61 }
62
63 // Are there any errors to display?
64 if ( count( $files ) > 0 ) {
65 ?>
66 <div class="error notice">
67 <h2>Patchstack File Permission Error</h2>
68 <p><?php esc_html_e( 'The following file/folder could not be written to:<br />' . implode( '<br />', $files ), 'patchstack' ); ?></p>
69 <?php
70 foreach ( $files as $file ) {
71 echo wp_kses( '<p><b>Debug info: </b>' . $file . ' chmod permissions: <b>' . substr( decoct( fileperms( $file ) ), -3 ) . '</b>, owned by <b>' . posix_getpwuid( fileowner( $file ) )['name'] . '</b></p>', $this->allowed_html );
72 }
73 ?>
74 <p><?php esc_html_e( '<strong>How to fix?</strong><br />CHMOD the file/folder to <strong>755</strong> through a <a href="http://www.dummies.com/web-design-development/wordpress/navigation-customization/how-to-change-file-permissions-using-filezilla-on-your-ftp-site/" target="_blank">FTP client</a>, <a href="http://support.hostgator.com/articles/cpanel/how-to-change-permissions-chmod-of-a-file" target="_blank">CPanel</a>, <a href="https://www.inmotionhosting.com/support/website/managing-files/change-file-permissions" target="_blank">WHM</a> or ask your hosting provider. Make sure file or folder ownership is set to <b>' . posix_getpwuid( fileowner( ABSPATH . 'index.php' ) )['name'] . '</b> user .', 'patchstack_file_error_notice' ); ?></p>
75 <p><?php esc_html_e( '<strong>CHMOD properly set but still not working?</strong><br />Make sure the group/owner (chown) settings of the /wp-content/plugins/patchstack/ folder is properly setup, you may have to ask your host to fix this.', 'patchstack_file_error_notice' ); ?></p>
76 </div>
77 <?php
78 }
79 }
80
81 /**
82 * When the user updates the site URL, update it on the API side as well.
83 * This needs to be done so we can communicate with the site properly.
84 *
85 * @param mixed $old_value
86 * @param mixed $new_value
87 * @return void
88 */
89 public function update_option_url( $old_value, $new_value ) {
90 if ( $old_value != $new_value ) {
91 $this->plugin->api->update_url( [ 'plugin_url' => $new_value ] );
92 }
93 }
94
95 /**
96 * When the firewall auto prepend option value is changed, ensure that we prepare the environment or remove it from the environment.
97 *
98 * @param mixed $option_name
99 * @param mixed $old_value
100 * @param mixed $new_value
101 * @return void
102 */
103 public function update_option_ap( $option_name, $old_value, $new_value ) {
104 if ( $option_name != 'patchstack_firewall_ap_enabled' ) {
105 return;
106 }
107
108 // No need to perform if user is on free plan.
109 if ( get_option( 'patchstack_license_activated', 0 ) != 1 ) {
110 return;
111 }
112
113 if ( $new_value && get_option( 'patchstack_license_free', 0 ) == 0 ) {
114 $this->plugin->activation->auto_prepend_injection();
115 } else {
116 $this->plugin->activation->auto_prepend_removal();
117 }
118 }
119 }
120