Plugin Directory

Changeset 3145261


Ignore:
Timestamp:
09/02/2024 10:40:06 AM (18 months ago)
Author:
wtsec
Message:

2.4.32

  • Fixed the issue of our API address being blocked by adding a site mirror
Location:
wt-security
Files:
451 added
4 edited

Legend:

Unmodified
Added
Removed
  • wt-security/trunk/lib/API.php

    r3121600 r3145261  
    2929     *   Returns auth status
    3030     */
    31     public static function auth($api_key)
     31    public static function auth($api_key, $repeat = false)
    3232    {
    3333        $domain = WEBTOTEM_SITE_DOMAIN;
     
    3636            $prefix = substr($api_key, 0, 1);
    3737            if ($api_url = self::getApiUrl($prefix)) {
    38                 WebTotemOption::setOptions(['api_url' => $api_url]);
     38                WebTotemOption::setOptions(['api_url' => $api_url, 'api_environment' => $prefix]);
    3939            } else {
    4040                WebTotemOption::setNotification('error', __('Invalid API key', 'wtotem'));
     
    4747            return FALSE;
    4848        }
     49
    4950        $payload = '{"query":"mutation{ guest{ apiKeys{ auth(apiKey:\"' . $api_key . '\", source:\"' . $domain . '\"),{ token{ value, refreshToken, expiresIn } } } } }"}';
    5051        $result = self::sendRequest($payload, FALSE, TRUE);
     52
     53        WebTotem::log('$result: ' . json_encode($result));
    5154
    5255        if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
     
    6467        }
    6568
     69        if($repeat == false){
     70            self::checkEndpoint();
     71            return self::auth($api_key, true);
     72        }
     73
    6674        return FALSE;
    6775    }
     
    7886    {
    7987        $urls = [
    80             'P' => '.wtotem.com',
    81             'C' => '.webtotem.kz',
     88            'P' => 'wtotem.com',
     89            'C' => 'webtotem.kz',
     90            'M' => 'wtotem.net',
    8291        ];
    8392
    8493        if (array_key_exists($prefix, $urls)) {
    85             return 'https://api' . $urls[$prefix] . '/graphql';
     94            return 'https://api.' . $urls[$prefix] . '/graphql';
    8695        }
    8796        return false;
     97    }
     98
     99    /**
     100     * Method to check endpoint.
     101     */
     102    public static function checkEndpoint() {
     103        global $wp_filesystem;
     104
     105        if ( empty( $wp_filesystem ) ) {
     106            require_once( ABSPATH . 'wp-admin/includes/file.php' );
     107            WP_Filesystem();
     108        }
     109
     110        $api_params['api_url'] = WebTotemOption::getOption('api_url');
     111        $api_params['api_environment'] = WebTotemOption::getOption('api_environment');
     112
     113        switch ($api_params['api_environment'] ?? $api_params['api_url'] ){
     114            case 'P' :
     115            case 'https://api.wtotem.com/graphql':
     116                $path = 'https://api.wtotem.com/isv20/health-check';
     117                $new_api_params = ['api_environment' => 'M', 'api_url' => 'https://api.wtotem.net/graphql' ];
     118                break;
     119
     120            case "M":
     121            case "https://api.wtotem.net/graphql":
     122                $path = 'https://api.wtotem.net/isv20/health-check';
     123                $new_api_params = ['api_environment' => 'P', 'api_url' => 'https://api.wtotem.com/graphql' ];
     124                break;
     125
     126            default:
     127                $path = 'https://api.wtotem.com/isv20/health-check';
     128                $new_api_params = ['api_environment' => 'M', 'api_url' => 'https://api.wtotem.net/graphql' ];
     129        }
     130
     131
     132        if(!empty($wp_filesystem)){
     133            $response = $wp_filesystem->get_contents($path);
     134        } else {
     135            $response = file_get_contents($path);
     136        }
     137
     138        if($response){
     139            $response_json = json_decode($response, true);
     140
     141            if(is_array($response_json)){
     142                if($response_json['status'] === "OK"){
     143                   return true;
     144                }
     145            }
     146        }
     147
     148        WebTotemOption::setOptions($new_api_params);
     149        return false;
     150
    88151    }
    89152
  • wt-security/trunk/lib/Helper.php

    r3121600 r3145261  
    1212 */
    1313class WebTotem {
    14 
     14 
    1515    /**
    1616     * Returns an URL from the admin dashboard.
     
    16851685        }
    16861686        $list = implode(', ', $list ?? []);
    1687         $cve_list = WebTotem::arrayMapIndex(WebTotemAPI::getCVE($list), 'technology');
     1687
     1688        $response = WebTotemAPI::getCVE($list);
     1689        $cve_list = $response ? WebTotem::arrayMapIndex($response, 'technology') : [];
    16881690
    16891691        $update_plugins = get_site_transient( 'update_plugins' );
     
    16951697            if(array_key_exists($plugin['TextDomain'], $cve_list)){
    16961698                $new_version = $update_plugins[$key]['new_version'] ?? 0;
    1697                 foreach ($cve_list[$plugin['TextDomain']]['cves'] as $cve){
    1698                     $cve['published'] = self::dateFormatter($cve['published'], 'Y-m-d');
    1699                     $values .= sprintf("('%s','%s','%s','%s','%s','%s'),",
    1700                         $cve['cve_id'],
    1701                         $plugin['Name'],
    1702                         $plugin['TextDomain'],
    1703                         $plugin['Version'],
    1704                         $new_version,
    1705                         json_encode($cve)
    1706                     );
     1699                $cves = $cve_list[$plugin['TextDomain']]['cves'];
     1700                if ($cves){
     1701                    foreach ($cves as $cve){
     1702                        $cve['published'] = self::dateFormatter($cve['published'], 'Y-m-d');
     1703                        $cve['summary'] = str_replace("'", "", $cve['summary']);
     1704                        $values .= sprintf("('%s','%s','%s','%s','%s','%s'),",
     1705                            $cve['cve_id'],
     1706                            $plugin['Name'],
     1707                            $plugin['TextDomain'],
     1708                            $plugin['Version'],
     1709                            $new_version,
     1710                            json_encode($cve)
     1711                        );
     1712                    }
    17071713                }
    1708 
    17091714            }
    17101715        }
  • wt-security/trunk/readme.txt

    r3125416 r3145261  
    22Contributors: wtsec
    33Donate Link: https://wtotem.com/
    4 Tags: security, firewall, monitoring, antivirus, wtotem
     4Tags: security, firewall, monitoring, antivirus, protection
    55Requires at least: 5.0
    66License: GPLv3
    7 Tested up to: 6.5
     7Tested up to: 6.6
    88Requires PHP: 7.1
    99Requires at least: 6.0
    10 Stable tag: 2.4.31
     10Stable tag: 2.4.32
    1111
    1212WebTotem is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way.
     
    8787
    8888== Changelog ==
     89= 2.4.32 =
     90* Fixed the issue of our API address being blocked by adding a site mirror
     91
    8992= 2.4.31 =
    9093* Internal improvements
  • wt-security/trunk/wt-security.php

    r3125416 r3145261  
    77 * Text Domain: wtotem
    88 * Domain Path: /lang
    9  * Version: 2.4.31
     9 * Version: 2.4.32
    1010 * License: GPL v2 or later
    1111 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     
    5555 * Current version of the plugin's code.
    5656 */
    57 define('WEBTOTEM_VERSION', '2.4.31');
     57define('WEBTOTEM_VERSION', '2.4.32');
    5858
    5959/**
Note: See TracChangeset for help on using the changeset viewer.