Plugin Directory

Changeset 3409423


Ignore:
Timestamp:
12/03/2025 11:50:32 AM (3 months ago)
Author:
patchstack
Message:

Changed WordPress version stable tag
Fixed plugin redirect if more than one plugin is being activated
Fixed plugin redirect if the plugin is already connected to the API
Fixed some .htaccess rules
Removed unused cron job
Removed old multisite activation code

Location:
patchstack/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • patchstack/trunk/includes/activation.php

    r3260796 r3409423  
    4444        }
    4545
     46        // Only if it's the current plugin.
    4647        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            }
    4758
    4859            // Determine if secret token was set, if so, sync with API.
     
    231242            @file_put_contents( trailingslashit( WPMU_PLUGIN_DIR ) . '_patchstack.php', $php );
    232243        }
    233     }
    234 
    235     /**
    236      * Used to activate an individual license on multisite/network.
    237      *
    238      * @param object $site
    239      * @param array  $license
    240      * @return void
    241      */
    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 activated
    266             // 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();
    276244    }
    277245
  • patchstack/trunk/includes/admin/menu.php

    r3114829 r3409423  
    5757        add_menu_page( 'Patchstack', 'Patchstack', 'manage_options', 'patchstack-multisite', [ $this->plugin->multisite, 'sites_section_callback' ] );
    5858        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' ] );
    6059    }
    6160
  • patchstack/trunk/includes/admin/options.php

    r3356031 r3409423  
    9898        'patchstack_software_data_hash'                 => ['default' => '', 'autoload' => 'yes'],
    9999        'patchstack_software_upload_attempted'          => ['default' => false, 'autoload' => 'yes'],
    100         'patchstack_firewall_htaccess_hash'             => ['default' => '', 'autoload' => 'no'],
    101100        'patchstack_license_expiry'                     => ['default' => '', 'autoload' => 'yes'],
    102101        'patchstack_clientid'                           => ['default' => false, 'autoload' => 'yes'],
  • patchstack/trunk/includes/api.php

    r3255403 r3409423  
    345345
    346346    /**
    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     /**
    356347     * Send the firewall logs to the API.
    357348     *
  • patchstack/trunk/includes/cron.php

    r3255403 r3409423  
    9595            'patchstack_send_hacker_logs'             => 'patchstack_15minute',
    9696            'patchstack_post_firewall_rules'          => 'patchstack_daily',
    97             'patchstack_post_firewall_htaccess_rules' => 'patchstack_daily',
    9897            'patchstack_post_dynamic_firewall_rules'  => 'patchstack_hourly',
    9998            'patchstack_send_event_logs'              => 'patchstack_15minute',
  • patchstack/trunk/includes/htaccess.php

    r3260796 r3409423  
    161161        }
    162162
     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
    163177        return $this->plugin->htaccess->self_check( $rules );
    164178    }
  • patchstack/trunk/includes/multisite.php

    r3114829 r3409423  
    1010 */
    1111class P_Multisite extends P_Core {
    12 
    13     /**
    14      * Stores any errors.
    15      *
    16      * @var string
    17      */
    18     public $error = '';
    19 
    2012    /**
    2113     * Add the actions required for the multisite functionality.
     
    3022        }
    3123
    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 
    3724        // When we need to re-run the migration of a specific site.
    3825        if ( isset( $_GET['site'], $_GET['PatchstackNonce'] ) && wp_verify_nonce( $_GET['PatchstackNonce'], 'patchstack-migration' ) ) {
    3926            $this->run_migration();
    40         }
    41     }
    42 
    43     /**
    44      * When a user selects sites that need to be activated.
    45      *
    46      * @return string
    47      */
    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 sites
    79         $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             }
    8427        }
    8528    }
  • patchstack/trunk/includes/rules.php

    r3255403 r3409423  
    2020        parent::__construct( $core );
    2121        add_action( 'patchstack_post_firewall_rules', [ $this, 'post_firewall_rules' ] );
    22         add_action( 'patchstack_post_firewall_htaccess_rules', [ $this, 'post_firewall_htaccess_rules' ] );
    2322        add_action( 'patchstack_post_dynamic_firewall_rules', [ $this, 'dynamic_firewall_rules' ] );
    2423    }
     
    4948            return;
    5049        }
    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 void
    58      */
    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 );
    7550    }
    7651
  • patchstack/trunk/includes/views/pages/license.php

    r3255403 r3409423  
    6161
    6262<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>
    6464</p>
    6565
  • patchstack/trunk/includes/views/pages/multisite-activation.php

    r3114829 r3409423  
    66}
    77
    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';
    258?>
    269<div class="patchstack-plan" style="margin-bottom: 64px;">
    2710    <h2 style="padding: 0;">Multisite Activation</h2>
    28     <p><?php echo wp_kses( $this->plugin->multisite->error, $this->allowed_html ); ?>
    29     <?php
    30         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     <?php
    34         } 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>
    4011
    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>
    4818
    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>
    5922</div>
  • patchstack/trunk/includes/views/pages/multisite-table.php

    r3114829 r3409423  
    2525    <form method="GET" style="display: table;">
    2626        <div class="wrap">
    27             <h2>Available Sites</h2>
     27            <h2>Patchstack - Available Sites</h2>
    2828        </div>
    2929        <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
  • patchstack/trunk/patchstack.php

    r3356031 r3409423  
    55 * Author URI: https://patchstack.com/?utm_medium=wp&utm_source=dashboard&utm_campaign=patchstack%20plugin
    66 * Description: Patchstack identifies security vulnerabilities in WordPress plugins, themes, and core.
    7  * Version: 2.3.3
     7 * Version: 2.3.4
    88 * Author: Patchstack
    99 * License: GPLv3
     
    6060         * @var string
    6161         */
    62         const VERSION = '2.3.3';
     62        const VERSION = '2.3.4';
    6363
    6464        /**
  • patchstack/trunk/readme.txt

    r3356031 r3409423  
    55License URI: https://www.gnu.org/licenses/gpl-3.0.html
    66Requires at least: 4.4
    7 Tested up to: 6.8
    8 Stable tag: 2.3.3
     7Tested up to: 6.9
     8Stable tag: 2.3.4
    99Requires PHP: 5.6
    1010
     
    161161
    162162= 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. 
     163Setup 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. 
    164164See our [Getting Started guide](https://docs.patchstack.com/getting-started/start-using-patchstack/) for help.
    165165
Note: See TracChangeset for help on using the changeset viewer.