Plugin Directory

Changeset 2378681


Ignore:
Timestamp:
09/10/2020 12:15:35 PM (6 years ago)
Author:
akshatc
Message:

Disabling deactivate for botprotection accounts/Disconnect functionality through wpcli

Location:
malcare-security/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • malcare-security/trunk/account.php

    r2297475 r2378681  
    8585        }
    8686
     87        public static function accountsByType($settings, $account_type) {
     88            $accounts = self::allAccounts($settings);
     89            $accounts_by_type = array();
     90            foreach ($accounts as $pubkey => $value) {
     91                if (array_key_exists('account_type', $value) && $value['account_type'] === $account_type) {
     92                    $accounts_by_type[$pubkey] = $value;
     93                }
     94            }
     95            return $accounts_by_type;
     96        }
     97
     98        public static function accountsByGid($settings, $account_gid) {
     99            $accounts = self::allAccounts($settings);
     100            $accounts_by_gid = array();
     101            foreach ($accounts as $pubkey => $value) {
     102                if (array_key_exists('account_gid', $value) && $value['account_gid'] === $account_gid) {
     103                    $accounts_by_gid[$pubkey] = $value;
     104                }
     105            }
     106            return $accounts_by_gid;
     107        }
     108
     109        public static function accountsByPattern($settings, $search_key, $search_pattern) {
     110            $accounts = self::allAccounts($settings);
     111            $accounts_by_pattern = array();
     112            foreach ($accounts as $pubkey => $value) {
     113                if (array_key_exists($search_key, $value) && preg_match($search_pattern, $value[$search_key]) == 1) {
     114                    $accounts_by_pattern[$pubkey] = $value;
     115                }
     116            }
     117            return $accounts_by_pattern;
     118        }
     119
    87120        public static function isConfigured($settings) {
    88121            $accounts = self::accountsByPlugname($settings);
     
    156189            return 1;
    157190        }
    158    
     191
    159192        public function updateInfo($info) {
    160193            $accounts = self::allAccounts($this->settings);
    161             $plugname = self::getPlugName($this->settings);
     194            $plugname = $info["plugname"];
     195            $account_type = $info["account_type"];
    162196            $pubkey = $info['pubkey'];
    163197            if (!array_key_exists($pubkey, $accounts)) {
    164198                $accounts[$pubkey] = array();
    165199            }
     200            if (array_key_exists('secret', $info)) {
     201                $accounts[$pubkey]['secret'] = $info['secret'];
     202            }
     203            $accounts[$pubkey]['account_gid'] = $info['account_gid'];
    166204            $accounts[$pubkey]['lastbackuptime'] = time();
    167205            $accounts[$pubkey][$plugname] = true;
     206            $accounts[$pubkey]['account_type'] = $account_type;
    168207            $accounts[$pubkey]['url'] = $info['url'];
    169208            $accounts[$pubkey]['email'] = $info['email'];
     
    181220        }
    182221
     222        public static function removeByAccountType($settings, $account_type) {
     223            $accounts = MCAccount::accountsByType($settings, $account_type);
     224            if (sizeof($accounts) >= 1) {
     225                foreach ($accounts as $pubkey => $value) {
     226                    MCAccount::remove($settings, $pubkey);
     227                }
     228                return true;
     229            }
     230            return false;
     231        }
     232
     233        public static function removeByAccountGid($settings, $account_gid) {
     234            $accounts = MCAccount::accountsByGid($settings, $account_gid);
     235            if (sizeof($accounts) >= 1) {
     236                foreach ($accounts as $pubkey => $value) {
     237                    MCAccount::remove($settings, $pubkey);
     238                }
     239                return true;
     240            }
     241            return false;
     242        }
     243
    183244        public static function exists($settings, $pubkey) {
    184245            $accounts = self::allAccounts($settings);
  • malcare-security/trunk/callback/wings/account.php

    r2207998 r2378681  
    2525            break;
    2626        case "updt":
    27             $info = array();
    28             $info['email'] = $params['email'];
    29             $info['url'] = $params['url'];
    30             $info['pubkey'] = $params['pubkey'];
    31             $account->updateInfo($info);
     27            $account->updateInfo($params);
    3228            $resp = array("status" => MCAccount::exists($this->settings, $params['pubkey']));
    3329            break;
     
    3632            $resp = array("status" => $this->settings->getOption(MCAccount::$api_public_key));
    3733            break;
    38         case "rmdefsec":
    39             $resp = array("status" => $settings->deleteOption('bvDefaultSecret'));
     34        case "rmbvscrt":
     35            $resp = array("status" => $settings->deleteOption('bvSecretKey'));
    4036            break;
    4137        case "rmbvkeys":
  • malcare-security/trunk/callback/wings/db.php

    r2323804 r2378681  
    7070        $stream_init_info = BVStream::startStream($this->account, $request);
    7171
    72         if(MCWPSiteInfo::isCWServer() && !$this->bvinfo->isManualSignup()) {
     72        if($this->bvinfo->canSetCWBranding()) {
    7373            $bv_table = $params['table'];
    7474            if (!empty($bv_table)) {
  • malcare-security/trunk/callback/wings/fs.php

    r2350813 r2378681  
    1313    public function __construct($callback_handler) {
    1414        $this->account = $callback_handler->account;
     15        $this->bvinfo = $callback_handler->bvinfo;
    1516    }
    1617
     
    2728                $fdata["link"] = @readlink($absfile);
    2829            }
    29             if ($md5 === true) {
     30            if ($md5 === true && !is_dir($absfile)) {
    3031                $fdata["md5"] = $this->calculateMd5($absfile, array(), 0, 0, 0);
    3132            }
     
    197198                continue;
    198199            }
    199             if ($md5 === true) {
     200            if ($md5 === true && !is_dir($absfile)) {
    200201                $fdata["md5"] = $this->calculateMd5($absfile, $fdata, $offset, $limit, $bsize);
    201202            }
     
    246247        $params = $request->params;
    247248        $stream_init_info = BVStream::startStream($this->account, $request);
    248        
    249        
     249
     250        if($this->bvinfo->canSetCWBranding()) {
     251            if(array_key_exists('initdir', $params)) {
     252                return $stream_init_info;
     253            }
     254
     255            if (array_key_exists('files', $params)) {
     256                $files = $params['files'];
     257
     258                foreach($files as $file) {
     259                    if (!in_array($file, BVFSCallback::$cwAllowedFiles)) {
     260                        return $stream_init_info;
     261                    }
     262                }
     263            }
     264        }
     265
    250266
    251267        if (array_key_exists('stream', $stream_init_info)) {
  • malcare-security/trunk/callback/wings/misc.php

    r2323804 r2378681  
    9595            $resp = array("dlttrsnt" => $settings->deleteTransient($params['key']));
    9696            break;
    97         case "setmanulsignup":
    98             $resp = array("setmanulsignup" => $settings->updateOption("bvmanualsignup", true));
     97        case "setbvss":
     98            $resp = array("status" => $settings->updateOption('bv_site_settings', $params['bv_site_settings']));
    9999            break;
    100100        default:
  • malcare-security/trunk/info.php

    r2350813 r2378681  
    1010        public $ip_header_option = 'mcipheader';
    1111        public $brand_option = 'mcbrand';
    12         public $version = '4.35';
     12        public $version = '4.4';
    1313        public $webpage = 'https://www.malcare.com';
    1414        public $appurl = 'https://app.malcare.com';
     
    2222        }
    2323
    24         public function isManualSignup() {
    25             $scanOption = $this->settings->getOption('bvmanualsignup');
    26             return (isset($scanOption) && $scanOption == 1);
     24        public function canSetCWBranding() {
     25            if (MCWPSiteInfo::isCWServer()) {
     26
     27                $bot_protect_accounts = MCAccount::accountsByType($this->settings, 'botprotect');
     28                if (sizeof($bot_protect_accounts) >= 1)
     29                    return true;
     30
     31                $bot_protect_accounts = MCAccount::accountsByPattern($this->settings, 'email', '/@cw_user\.com$/');
     32                if (sizeof($bot_protect_accounts) >= 1)
     33                    return true;
     34            }
     35
     36            return false;
    2737        }
    2838
     
    3747            }
    3848          $bvinfo = new MCInfo($this->settings);
    39 if (MCWPSiteInfo::isCWServer() && !$bvinfo->isManualSignup()) {
     49if ($bvinfo->canSetCWBranding()) {
    4050                return "Cloudways";
    4151            }
  • malcare-security/trunk/malcare.php

    r2350813 r2378681  
    66Author: MalCare Security
    77Author URI: https://www.malcare.com
    8 Version: 4.35
     8Version: 4.4
    99Network: True
    1010 */
     
    7575    add_action('admin_notices', array($wpadmin, 'activateWarning'));
    7676    add_action('admin_enqueue_scripts', array($wpadmin, 'mcsecAdminMenu'));
     77    add_action('plugin_action_links', array($wpadmin, 'disableDeactivation'), 10, 2);
    7778}
    7879
     
    143144
    144145    ##DYNSYNCMODULE##
     146    ##WPAUTOUPDATEBLOCKMODULE##
    145147}
  • malcare-security/trunk/readme.txt

    r2350813 r2378681  
    77Tested up to: 5.5
    88Requires PHP: 5.4.0
    9 Stable tag: 4.35
     9Stable tag: 4.4
    1010License: GPLv2 or later
    1111License URI: [http://www.gnu.org/licenses/gpl-2.0.html](http://www.gnu.org/licenses/gpl-2.0.html)
     
    391391
    392392== CHANGELOG ==
    393 = 4.35 =
    394 * Improved scanfiles and filelist api
     393= 4.4 =
     394* Disabling deactivate for botprotection accounts
     395* Disconnect functionality through wpcli with params account_gid and account_type
     396* Removed manual signup logic
    395397
    396398= 4.33 =
  • malcare-security/trunk/wp_admin.php

    r2336505 r2378681  
    3030            remove_all_actions('all_admin_notices');
    3131        }
     32    }
     33
     34    public function disableDeactivation($actions, $plugin_file) {
     35        if ($this->bvinfo->canSetCWBranding()) {
     36            if ( $this->bvinfo->slug === $plugin_file ) {
     37                unset( $actions['deactivate'] );
     38            }
     39        }
     40        return $actions;
    3241    }
    3342
     
    6877        if ($this->bvinfo->isActivateRedirectSet()) {
    6978            $this->settings->updateOption($this->bvinfo->plug_redirect, 'no');
    70             $this->settings->updateOption('bvmanualsignup', true);
    7179            wp_redirect($this->mainUrl());
    7280        }
     
    106114            array($this, 'showAccountDetailsPage'));
    107115
    108         if (!MCWPSiteInfo::isCWServer() || $this->bvinfo->isManualSignup()) {
     116        if (!$this->bvinfo->canSetCWBranding()) {
    109117            $bname = $this->bvinfo->getBrandName();
    110118            $icon = $this->bvinfo->getBrandIcon();
     
    138146        #XNOTE: Fix this
    139147        if ( $file == plugin_basename( dirname(__FILE__).'/malcare.php' ) ) {
    140             if (!MCWPSiteInfo::isCWServer() || $this->bvinfo->isManualSignup()) {
     148            if (!$this->bvinfo->canSetCWBranding()) {
    141149                $settings_link = '<a href="'.$this->mainUrl().'">'.__( 'Settings' ).'</a>';
    142150                array_unshift($links, $settings_link);
     
    189197
    190198    public function showAddAccountPage() {
    191         $this->settings->updateOption('bvmanualsignup', true);
    192199        $this->enqueueBootstrapCSS();
    193200        require_once dirname( __FILE__ ) . "/admin/registration.php";
     
    228235        }
    229236
    230         if (MCWPSiteInfo::isCWServer() && !$this->bvinfo->isManualSignup()) {
     237        if ($this->bvinfo->canSetCWBranding()) {
    231238            $brand = $this->cwBrandInfo();
    232239            if (array_key_exists('name', $brand)) {
  • malcare-security/trunk/wp_cli.php

    r2336505 r2378681  
    3030            'Authorization' => "BVAPI-HMAC {$params['account_public']}:{$params['sig']}:{$params['timestamp']}"
    3131        );
    32         $this->request($url, $request_params, $headers);
     32
     33        $resp = $this->request($url, $request_params, $headers);
     34
     35        $this->updateAccountInfo($resp);
     36
     37        $this->handle_response($resp);
    3338    }
    3439
     
    5661            WP_CLI::error('Account not found');
    5762        }
    58         $this->request($account->authenticatedUrl('/bvapi/disable_fw'));
     63        $resp = $this->request($account->authenticatedUrl('/bvapi/disable_fw'));
     64        $this->handle_response($resp);
    5965    }
    6066
     
    6470            WP_CLI::error('Account not found.');
    6571        }
    66         $this->request($account->authenticatedUrl('/bvapi/enable_fw'));
     72        $resp = $this->request($account->authenticatedUrl('/bvapi/enable_fw'));
     73        $this->handle_response($resp);
    6774    }
    6875
    6976    public function disconnect($args, $params) {
     77        $status = false;
    7078        if (isset($params['public_key'])) {
    71             if (strlen($params['public_key']) >= 32) {
    72                 $status = MCAccount::remove($this->settings, $params['public_key']);
    73                 if ($status) {
    74                     WP_CLI::success('Account Keys removed successfully.');
    75                 } else {
    76                     WP_CLI::error('No Account with provided public key exists.');
    77                 }
    78             } else {
    79                 WP_CLI::error('Invalid Public Key.');
    80             }
     79            $status = MCAccount::remove($this->settings, $params['public_key']);
     80        } else if(isset($params['account_type'])) {
     81            $status = MCAccount::removeByAccountType($this->settings, $params['account_type']);
     82        } else if(isset($params['account_gid'])) {
     83            $status = MCAccount::removeByAccountGid($this->settings, $params['account_gid']);
    8184        } else {
    82             WP_CLI::error('Please Provide Public Key.');
     85            WP_CLI::error('Input Params are incorrect. Please validate the params.');
     86        }
     87
     88        if ($status) {
     89            WP_CLI::success('Account removed successfully.');
     90        } else {
     91            WP_CLI::error('No Account exists.');
    8392        }
    8493    }
     
    8695    private function request($url, $request_params = array(), $headers = array()) {
    8796        $resp = $this->bvapi->http_request($url, $request_params, $headers);
    88         $this->handle_response($resp);
     97        return $resp;
     98    }
     99
     100    private function updateAccountInfo($resp) {
     101        if(isset($resp["response"]) && isset($resp["response"]["code"]) && ($resp["response"]["code"] == 200)) {
     102            if (isset($resp["body"])) {
     103                $body = json_decode($resp["body"], true);
     104                if (isset($body["account_info"])) {
     105                    $info = $body["account_info"];
     106                    MCAccount::addAccount($this->settings, $info['pubkey'], $info['secret']);
     107                    $account = MCAccount::find($this->settings, $info['pubkey']);
     108                    $account->updateInfo($info);
     109                }
     110            }
     111        }
    89112    }
    90113
Note: See TracChangeset for help on using the changeset viewer.