From c3e09438b06443e2b9c5378ff015450be0ad44d4 Mon Sep 17 00:00:00 2001 From: chen Date: Thu, 15 Oct 2020 23:48:54 +0800 Subject: [PATCH 1/5] [debug] [curl] [tester] [new] Added a cURL tester functionality to check the connectivity to the server on the debug template. --- templates/debug.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/templates/debug.php b/templates/debug.php index 44b1efc1f..883ab8be9 100644 --- a/templates/debug.php +++ b/templates/debug.php @@ -100,6 +100,9 @@ + + + @@ -140,6 +143,20 @@ } } }); + + $('#fs_check_connectivity_option').click(async function () { + let response = await fetch('https://api.freemius.com/v1/ping.json'); + + if (!response.ok) { + alert("Error response code: " + response.status); + } else { + // if HTTP-status is 200-299 + // get the response body (the method explained below) + let json = await response.json(); + + alert("Response code:" + response.status + "\nResponse: " + JSON.stringify(json)); + } + }) })(jQuery); Date: Thu, 15 Oct 2020 23:55:04 +0800 Subject: [PATCH 2/5] [debug] [minor] [update] Removed unnecessary comments. --- templates/debug.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/debug.php b/templates/debug.php index 883ab8be9..4fe14b126 100644 --- a/templates/debug.php +++ b/templates/debug.php @@ -150,8 +150,6 @@ if (!response.ok) { alert("Error response code: " + response.status); } else { - // if HTTP-status is 200-299 - // get the response body (the method explained below) let json = await response.json(); alert("Response code:" + response.status + "\nResponse: " + JSON.stringify(json)); From ad1ac88d310d3c91b1ec7e764fe2bfdf614ac83b Mon Sep 17 00:00:00 2001 From: chen Date: Wed, 6 Jan 2021 00:23:13 +0800 Subject: [PATCH 3/5] [debug] [check-connectivity] [curl] Used curl for testing server connectivity on the server side instead of using fetch API. --- includes/class-freemius.php | 22 +++++++++++++++++++++- templates/debug.php | 14 +++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/includes/class-freemius.php b/includes/class-freemius.php index a5b94fc54..d6f65a9b9 100755 --- a/includes/class-freemius.php +++ b/includes/class-freemius.php @@ -3423,7 +3423,7 @@ private static function _load_required_static() { self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) ); - self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) ); + self::add_ajax_action_static( 'check_connectivity', array( 'Freemius', '_check_connectivity' ) ); if ( 0 == did_action( 'plugins_loaded' ) ) { add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 ); @@ -3781,6 +3781,26 @@ static function _debug_page_render() { fs_require_once_template( 'debug.php', $vars ); } + /** + * @author Xiaheng Chen (@xhchen) + */ + static function _check_connectivity() { + $ch = curl_init( 'https://api.freemius.com/v1/ping.json' ); + + curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); + + curl_exec( $ch ); + + $httpcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); + + curl_close( $ch ); + + echo "\nCode: " . $httpcode; + + exit; + } + #endregion #---------------------------------------------------------------------------------- diff --git a/templates/debug.php b/templates/debug.php index 4fe14b126..7d61b8dc6 100644 --- a/templates/debug.php +++ b/templates/debug.php @@ -145,15 +145,11 @@ }); $('#fs_check_connectivity_option').click(async function () { - let response = await fetch('https://api.freemius.com/v1/ping.json'); - - if (!response.ok) { - alert("Error response code: " + response.status); - } else { - let json = await response.json(); - - alert("Response code:" + response.status + "\nResponse: " + JSON.stringify(json)); - } + $.post( ajaxurl, { + action: 'fs_check_connectivity', + }, function ( response ) { + alert("Response: " + response); + }); }) })(jQuery); From b74b38bc55a5ff72b2cce55c6d9df780e10d87c9 Mon Sep 17 00:00:00 2001 From: chen Date: Wed, 6 Jan 2021 00:27:33 +0800 Subject: [PATCH 4/5] [debug] [check-connectivity] [curl] [code-convention] [consistency] Fixed some code convention issues for consistency. --- templates/debug.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/debug.php b/templates/debug.php index 7d61b8dc6..b77dd3f04 100644 --- a/templates/debug.php +++ b/templates/debug.php @@ -144,10 +144,10 @@ } }); - $('#fs_check_connectivity_option').click(async function () { - $.post( ajaxurl, { + $('#fs_check_connectivity_option').click(function () { + $.post(ajaxurl, { action: 'fs_check_connectivity', - }, function ( response ) { + }, function (response) { alert("Response: " + response); }); }) From 074e55a478e7e9a6a1ce5bfcdc979c2667d6361e Mon Sep 17 00:00:00 2001 From: chen Date: Wed, 6 Jan 2021 00:31:48 +0800 Subject: [PATCH 5/5] [debug] [check-connectivity] [curl] [rollback] [minor] --- includes/class-freemius.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/class-freemius.php b/includes/class-freemius.php index d6f65a9b9..cd8c73165 100755 --- a/includes/class-freemius.php +++ b/includes/class-freemius.php @@ -3423,6 +3423,8 @@ private static function _load_required_static() { self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) ); + self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) ); + self::add_ajax_action_static( 'check_connectivity', array( 'Freemius', '_check_connectivity' ) ); if ( 0 == did_action( 'plugins_loaded' ) ) {