Changeset 3409423
- Timestamp:
- 12/03/2025 11:50:32 AM (3 months ago)
- Location:
- patchstack/trunk
- Files:
-
- 13 edited
-
includes/activation.php (modified) (2 diffs)
-
includes/admin/menu.php (modified) (1 diff)
-
includes/admin/options.php (modified) (1 diff)
-
includes/api.php (modified) (1 diff)
-
includes/cron.php (modified) (1 diff)
-
includes/htaccess.php (modified) (1 diff)
-
includes/multisite.php (modified) (2 diffs)
-
includes/rules.php (modified) (2 diffs)
-
includes/views/pages/license.php (modified) (1 diff)
-
includes/views/pages/multisite-activation.php (modified) (1 diff)
-
includes/views/pages/multisite-table.php (modified) (1 diff)
-
patchstack.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
patchstack/trunk/includes/activation.php
r3260796 r3409423 44 44 } 45 45 46 // Only if it's the current plugin. 46 47 if ( $plugin == $this->plugin->basename && ! isset( $_REQUEST['_ajax_nonce'] ) ) { 48 49 // If plugin bulk activate through wp-admin, we ignore the redirect if it's more than 1 plugin. 50 if ( isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) && count( $_POST['checked'] ) > 1 ) { 51 return; 52 } 53 54 // If the plugin is already connected or API activated, no need to redirect again. 55 if ( $this->license_is_active() || $this->is_connected() ) { 56 return; 57 } 47 58 48 59 // Determine if secret token was set, if so, sync with API. … … 231 242 @file_put_contents( trailingslashit( WPMU_PLUGIN_DIR ) . '_patchstack.php', $php ); 232 243 } 233 }234 235 /**236 * Used to activate an individual license on multisite/network.237 *238 * @param object $site239 * @param array $license240 * @return void241 */242 public function activate_multisite_license( $site, $license ) {243 // Build the Patchstack tables on the site.244 $this->migrate( null, $site->id );245 246 // Add the options to given site.247 foreach ( $this->plugin->admin_options->options as $name => $value ) {248 add_blog_option( $site->id, $name, $value['default'] );249 }250 251 // Set the client id and secret key.252 update_blog_option( $site->id, 'patchstack_clientid', $license['id'] );253 $enc = $this->get_secret_key( $license['secret'] );254 update_blog_option( $site->id, 'patchstack_secretkey', $enc['cipher'] );255 update_blog_option( $site->id, 'patchstack_secretkey_nonce', $enc['nonce'] );256 257 $this->plugin->api->blog_id = $site->id;258 259 // Activate the license and update firewall status after activating the plugin.260 $token = $this->plugin->api->get_access_token( $license['id'], $license['secret'], true );261 if ( ! empty( $token ) ) {262 $this->plugin->api->update_firewall_status( [ 'status' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ] );263 $this->plugin->api->update_url( [ 'plugin_url' => get_blog_option( $site->id, 'siteurl' ) ] );264 265 // If we have an access token, tell our API that the firewall is activated266 // and the current URL of the site.267 update_blog_option( $site->id, 'patchstack_license_activated', '1' );268 $this->plugin->api->update_license_status();269 270 // This will trigger the software synchronization action.271 wp_remote_get( get_site_url( $site->id ), [ 'sslverify' => false ] );272 }273 274 // Make sure to switch back to the current blog id.275 $this->plugin->api->blog_id = get_current_blog_id();276 244 } 277 245 -
patchstack/trunk/includes/admin/menu.php
r3114829 r3409423 57 57 add_menu_page( 'Patchstack', 'Patchstack', 'manage_options', 'patchstack-multisite', [ $this->plugin->multisite, 'sites_section_callback' ] ); 58 58 add_submenu_page( 'patchstack-multisite', 'Activate', 'Activate', 'manage_options', 'patchstack-multisite-settings', [ $this, 'render_settings_page' ] ); 59 add_submenu_page( 'patchstack-multisite', 'Sites', 'Sites', 'manage_options', 'patchstack-multisite', [ $this->plugin->multisite, 'sites_section_callback' ] );60 59 } 61 60 -
patchstack/trunk/includes/admin/options.php
r3356031 r3409423 98 98 'patchstack_software_data_hash' => ['default' => '', 'autoload' => 'yes'], 99 99 'patchstack_software_upload_attempted' => ['default' => false, 'autoload' => 'yes'], 100 'patchstack_firewall_htaccess_hash' => ['default' => '', 'autoload' => 'no'],101 100 'patchstack_license_expiry' => ['default' => '', 'autoload' => 'yes'], 102 101 'patchstack_clientid' => ['default' => false, 'autoload' => 'yes'], -
patchstack/trunk/includes/api.php
r3255403 r3409423 345 345 346 346 /** 347 * Get the .htaccess firewall rules.348 *349 * @return array The .htaccess rules.350 */351 public function post_firewall_htaccess_rule() {352 return $this->send_request( '/api/rules/htaccess', 'POST' );353 }354 355 /**356 347 * Send the firewall logs to the API. 357 348 * -
patchstack/trunk/includes/cron.php
r3255403 r3409423 95 95 'patchstack_send_hacker_logs' => 'patchstack_15minute', 96 96 'patchstack_post_firewall_rules' => 'patchstack_daily', 97 'patchstack_post_firewall_htaccess_rules' => 'patchstack_daily',98 97 'patchstack_post_dynamic_firewall_rules' => 'patchstack_hourly', 99 98 'patchstack_send_event_logs' => 'patchstack_15minute', -
patchstack/trunk/includes/htaccess.php
r3260796 r3409423 161 161 } 162 162 163 // Some rule adjustments. 164 $rewrites = [ 165 'RedirectMatch 409 .(htaccess|htpasswd|errordocs|logs)$' => 'RedirectMatch 403 \.(htaccess|htpasswd|errordocs|logs)$', 166 "\n RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]" => '', 167 "\n RewriteCond %{REMOTE_ADDR} !=18.221.197.243" => '', 168 '^wp-includes/[^/]+.php$' => '^wp-includes/.*\.php$', 169 'RewriteRule ^debug*.*log$ index.php?webarx_fpage=502 [L,QSA]' => 'RewriteRule debug\.log$ index.php?webarx_fpage=502 [L,QSA]', 170 '*.*' => '\.' 171 ]; 172 173 foreach ($rewrites as $find => $replace) { 174 $rules = str_replace($find, $replace, $rules); 175 } 176 163 177 return $this->plugin->htaccess->self_check( $rules ); 164 178 } -
patchstack/trunk/includes/multisite.php
r3114829 r3409423 10 10 */ 11 11 class P_Multisite extends P_Core { 12 13 /**14 * Stores any errors.15 *16 * @var string17 */18 public $error = '';19 20 12 /** 21 13 * Add the actions required for the multisite functionality. … … 30 22 } 31 23 32 // When sites are activated.33 if ( isset( $_POST['patchstack_do'], $_POST['PatchstackNonce'], $_POST['sites'] ) && $_POST['patchstack_do'] == 'do_licenses' && wp_verify_nonce( $_POST['PatchstackNonce'], 'patchstack-multisite-activation' ) ) {34 $this->activate_licenses();35 }36 37 24 // When we need to re-run the migration of a specific site. 38 25 if ( isset( $_GET['site'], $_GET['PatchstackNonce'] ) && wp_verify_nonce( $_GET['PatchstackNonce'], 'patchstack-migration' ) ) { 39 26 $this->run_migration(); 40 }41 }42 43 /**44 * When a user selects sites that need to be activated.45 *46 * @return string47 */48 private function activate_licenses() {49 if ( empty( $_POST['sites'] ) ) {50 $this->error = '<span style="color: #ff6262;">Please select at least 1 site to be activated.</span><br /><br />';51 return;52 }53 54 // Determine which sites are already activated and skip those.55 $activate = [];56 $sites = get_sites();57 foreach ( $sites as $site ) {58 if ( in_array( $site->siteurl, $_POST['sites'] ) && get_blog_option( $site->id, 'patchstack_clientid' ) == '' ) {59 array_push( $activate, $site->siteurl );60 }61 }62 63 // Make sure there is a site that can be activated.64 if ( count( $activate ) == 0 ) {65 $this->error = '<span style="color: #ff6262;">None of the selected sites need activation.</span><br /><br />';66 return;67 }68 69 // Add the site to the app and retrieve the license for each site.70 $licenses = $this->plugin->api->get_site_licenses( [ 'sites' => $activate ] );71 72 // Did an error happen during the multisite license activation?73 if ( isset( $licenses['error'] ) ) {74 $this->error = '<span style="color: #ff6262;">' . $licenses['error'] . '</span><br /><br />';75 return;76 }77 78 // Activate licenses on given sites79 $sites = get_sites();80 foreach ( $sites as $site ) {81 if ( isset( $licenses[ $site->siteurl ] ) ) {82 $this->plugin->activation->activate_multisite_license( $site, $licenses[ $site->siteurl ] );83 }84 27 } 85 28 } -
patchstack/trunk/includes/rules.php
r3255403 r3409423 20 20 parent::__construct( $core ); 21 21 add_action( 'patchstack_post_firewall_rules', [ $this, 'post_firewall_rules' ] ); 22 add_action( 'patchstack_post_firewall_htaccess_rules', [ $this, 'post_firewall_htaccess_rules' ] );23 22 add_action( 'patchstack_post_dynamic_firewall_rules', [ $this, 'dynamic_firewall_rules' ] ); 24 23 } … … 49 48 return; 50 49 } 51 }52 53 /**54 * Pull the firewall .htaccess rules from the API.55 * Then apply it to the .htaccess file after we create a backup.56 *57 * @return void58 */59 public function post_firewall_htaccess_rules() {60 if ( $this->get_option( 'patchstack_license_free', 0 ) == 1 ) {61 return;62 }63 64 $results = $this->plugin->api->post_firewall_htaccess_rule();65 $rules = ! isset( $results['rules'] ) || empty( $results ) ? '' : $results['rules'];66 67 // Check if we have to update anything at all.68 $hash = sha1( $rules );69 if ( get_option( 'patchstack_firewall_htaccess_hash', '' ) == $hash || ( get_option( 'patchstack_firewall_htaccess_hash', '' ) == '' && $rules == '' ) ) {70 return;71 }72 73 // We have rules so apply it to the .htaccess file.74 update_option( 'patchstack_firewall_htaccess_hash', $hash );75 50 } 76 51 -
patchstack/trunk/includes/views/pages/license.php
r3255403 r3409423 61 61 62 62 <p class="patchstack-upsell" style="<?php echo $status ? 'display: none;' : ''; ?>"> 63 <a href="https://app.patchstack.com/login " target="_blank"><?php esc_html_e( 'Log in to dashboard', 'patchstack' ); ?></a>63 <a href="https://app.patchstack.com/login?free=1" target="_blank"><?php esc_html_e( 'Log in to dashboard', 'patchstack' ); ?></a> 64 64 </p> 65 65 -
patchstack/trunk/includes/views/pages/multisite-activation.php
r3114829 r3409423 6 6 } 7 7 8 // Determine which sites need activation or not.9 $i = 0;10 $checkbox_list = '';11 $activated = '';12 $sites = get_sites();13 foreach ( $sites as $site ) {14 if ( get_blog_option( $site->id, 'patchstack_clientid' ) == '' ) {15 $checkbox_list .= '<div style="margin-bottom: 10px;"><input type="checkbox" name="sites[]" id="site-' . esc_attr( $site->blog_id ) . '" value="' . esc_url( $site->siteurl ) . '"><label for="site-' . esc_attr( $site->blog_id ) . '">' . esc_url( $site->siteurl ) . '</label></div>';16 $i++;17 } else {18 $activated .= esc_url( $site->siteurl ) . '<br />';19 }20 }21 22 $has_token = !is_null( $this->plugin->api->get_access_token() );23 $main_host = parse_url( get_home_url( get_main_site_id() ) );24 $main_admin_url = get_admin_url( get_main_site_id() ) . '/options-general.php?page=patchstack&tab=license';25 8 ?> 26 9 <div class="patchstack-plan" style="margin-bottom: 64px;"> 27 10 <h2 style="padding: 0;">Multisite Activation</h2> 28 <p><?php echo wp_kses( $this->plugin->multisite->error, $this->allowed_html ); ?>29 <?php30 if ( ! $has_token ) {31 ?>32 You must first manually add your WordPress network's primary site (<?php echo esc_html( $main_host['host'] ); ?>) to Patchstack before you can add the others.<br><br>You can do so by creating an account <a href="https://app.patchstack.com/register" target="_blank">here</a> and then by adding this site <a href="https://app.patchstack.com/sites/overview?add=1" target="_blank">here</a>.<br><br>Once you have obtained the API credentials, the credentials for your site <?php echo esc_html( $main_host['host'] ); ?> can be added <a href="<?php echo esc_url( $main_admin_url ); ?>">here</a>.33 <?php34 } else {35 ?>36 Select the sites on which you would like to activate the Patchstack plugin. These sites must be accessible from the public internet.<br /><br>37 Note that these sites must be added to Patchstack as well, which you can do at <a href="https://app.patchstack.com/sites/overview?add=1" target="_blank">app.patchstack.com</a>. Keep in mind that this might affect your upcoming bill depending on your current subscription plan.<br /><br />38 If you are an AppSumo user or have a limited amount of sites you can add, you must select the proper number of sites that can still be added to your account.<br><br>39 For more information on adding sites on multisite environments, go <a href="https://docs.patchstack.com/patchstack-plugin/installing-patchstack-on-a-multisite" target="_blank">here</a></p>40 11 41 <h2 style="padding: 20px 0 0 0; display: <?php echo $i > 0 ? 'block' : 'none'; ?>;">Not Activated</h2> 42 <form action="" method="POST" style="display: <?php echo $i > 0 ? 'block' : 'none'; ?>;"> 43 <input type="hidden" name="patchstack_do" value="do_licenses"> 44 <input type="hidden" value="<?php echo wp_create_nonce( 'patchstack-multisite-activation' ); ?>" name="PatchstackNonce"> 45 <?php echo wp_kses( $checkbox_list, $this->allowed_html ); ?> 46 <input type="submit" class="button-primary" value="Activate" /> 47 </form> 12 <p><strong>To activate Patchstack on your multisite network, follow these steps:</strong></p> 13 14 <ol style="margin-left: 20px;"> 15 <li><strong>Add all your network sites to Patchstack:</strong><br>Go to <a href="https://app.patchstack.com/sites/overview?add=1" target="_blank">app.patchstack.com</a> and add each of your multisite URLs individually.<br><br></li> 16 <li><strong>Activate API credentials on each site:</strong><br>For each site in your network, visit its individual WordPress admin panel and go to <strong>Settings → Security</strong> to add the API credentials. An overview of sites and its settings page can be found <a href="admin.php?page=patchstack-multisite">here</a>.</li> 17 </ol> 48 18 49 <?php 50 if ( $activated != '' ) { 51 ?> 52 <br /> 53 <h2 style="padding: 0;">Activated</h2> 54 <?php 55 echo wp_kses( $activated, $this->allowed_html ); 56 } 57 } 58 ?> 19 <p> 20 <strong>Note:</strong> All sites in your multisite network must be added to your Patchstack account individually and then activated with API keys on each site. For more information, visit the <a href="https://docs.patchstack.com/patchstack-plugin/installing-patchstack-on-a-multisite" target="_blank">multisite setup documentation</a>. 21 </p> 59 22 </div> -
patchstack/trunk/includes/views/pages/multisite-table.php
r3114829 r3409423 25 25 <form method="GET" style="display: table;"> 26 26 <div class="wrap"> 27 <h2> Available Sites</h2>27 <h2>Patchstack - Available Sites</h2> 28 28 </div> 29 29 <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" /> -
patchstack/trunk/patchstack.php
r3356031 r3409423 5 5 * Author URI: https://patchstack.com/?utm_medium=wp&utm_source=dashboard&utm_campaign=patchstack%20plugin 6 6 * Description: Patchstack identifies security vulnerabilities in WordPress plugins, themes, and core. 7 * Version: 2.3. 37 * Version: 2.3.4 8 8 * Author: Patchstack 9 9 * License: GPLv3 … … 60 60 * @var string 61 61 */ 62 const VERSION = '2.3. 3';62 const VERSION = '2.3.4'; 63 63 64 64 /** -
patchstack/trunk/readme.txt
r3356031 r3409423 5 5 License URI: https://www.gnu.org/licenses/gpl-3.0.html 6 6 Requires at least: 4.4 7 Tested up to: 6. 88 Stable tag: 2.3. 37 Tested up to: 6.9 8 Stable tag: 2.3.4 9 9 Requires PHP: 5.6 10 10 … … 161 161 162 162 = How long does it take to set up Patchstack? = 163 Setup takes just a few minutes. Install the plugin, register at [Patchstack App](https://app.patchstack.com/register ), add your site, and paste the API key into the plugin.163 Setup takes just a few minutes. Install the plugin, register at [Patchstack App](https://app.patchstack.com/register?free=1), add your site, and paste the API key into the plugin. 164 164 See our [Getting Started guide](https://docs.patchstack.com/getting-started/start-using-patchstack/) for help. 165 165
Note: See TracChangeset
for help on using the changeset viewer.