PluginProbe ʕ •ᴥ•ʔ
Aruba HiSpeed Cache / 3.0.15
Aruba HiSpeed Cache v3.0.15
3.0.15 3.0.14 3.0.13 1.2.4 1.2.5 1.2.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.19 2.0.20 2.0.21 2.0.22 2.0.23 2.0.24 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3
aruba-hispeed-cache / src / AHSC_Check.php
aruba-hispeed-cache / src Last commit date
APC 3 days ago Events 3 days ago Purger 3 days ago assets 3 days ago AHSC_Apc.php 3 days ago AHSC_Check.php 3 days ago AHSC_Config.php 3 days ago AHSC_Dboptimization.php 3 days ago AHSC_Functions.php 3 days ago AHSC_HtmlOptimizer.php 5 months ago AHSC_Lazyload.php 3 days ago AHSC_Preconnect.php 5 months ago AHSC_Static.php 4 months ago AHSC_Version.php 5 months ago AHSC_Warmer.php 3 days ago AHSC_XmlRPC.php 5 months ago index.php 5 months ago
AHSC_Check.php
353 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 const ACTIVE = 'active';
6 const AVAILABLE = 'available';
7 const UNAVAILABLE = 'unavailable';
8 const NOARUBASERVER = 'no-aruba-server';
9
10 //$ahsc_target=AHSC_CONSTANT['HOME_URL'];
11 //var_dump(AHSC_CONSTANT);
12 $ahsc_check_error=false;
13 $ahsc_check_status_code=false;
14 $ahsc_check_parameters=array(
15 'is_aruba_server'=>"",
16 'service_is_active'=>"",
17 'service_is_activabile'=>"",
18 'service_status'=>"",
19 'esit'=>""
20 );
21
22 /**
23 * Set_parameters_to_check Set the parameters to perform the service check.
24 *
25 * @param boolean $is_aruba_server Set to true if the site is on aruba server.
26 * @param boolean $service_is_active Set to true if the service is active.
27 * @param boolean $service_is_activabile Set to true if the service is activabile.
28 * @param string $service_status The value of x-aruba-cache header def is ''.
29 * @return void
30 */
31 function AHSC_set_parameters_to_check(
32 $is_aruba_server,
33 $service_is_active,
34 $service_is_activabile,
35 $service_status = '',
36 $cdn_status=''
37 ) {
38 global $ahsc_check_parameters;
39 $ahsc_check_parameters['is_aruba_server'] = $is_aruba_server;
40 $ahsc_check_parameters['service_is_active' ] = $service_is_active;
41 $ahsc_check_parameters['service_is_activabile'] = $service_is_activabile;
42 $ahsc_check_parameters['service_status'] = $service_status;
43 $ahsc_check_parameters['cdn_status'] = $cdn_status;
44 }
45
46 /**
47 * Headers_analizer - Analyze the request headers and value the variables.
48 *
49 * @since 1.0.1
50 * @return void
51 */
52 function AHSC_headers_analizer() {
53 $headers=AHSC_get_headers();
54 $is_active = false;
55 $is_activabile = false;
56 $_status = '';
57 /**
58 * If the request headers are empty or the request
59 * produced a wp_error then I set everything to true.
60 */
61 if ( empty( $headers ) ) {
62 AHSC_set_parameters_to_check( false, false, false );
63 }
64
65 /**
66 * If the headers contain 'x-aruba-cache' we are on an aruba server.
67 * If it has value NA we are on servers without cache.
68 */
69 if ( is_array($headers) && array_key_exists( 'x-aruba-cache', $headers ) ) {
70 $is_active = true;
71 $is_activabile = true;
72 if ( 'NA' === $headers['x-aruba-cache'] ) {
73 $is_activabile = false;
74 $is_active = false;
75 }
76 AHSC_set_parameters_to_check( true, $is_active, $is_activabile, $headers['x-aruba-cache'] );
77
78 }else{
79 AHSC_set_parameters_to_check( false, false, false );
80
81 }
82
83 if ( is_array($headers) && array_key_exists( 'x-aruba-cdn', $headers ) ) {
84 AHSC_set_parameters_to_check( true, $is_active, $is_activabile, $headers['x-aruba-cache'],$headers['x-aruba-cdn'] );
85 }else{
86 AHSC_set_parameters_to_check( false, false, false, false,false );
87 }
88
89 /**
90 * If the headers do not contain 'x-aruba-cache'
91 * we are not on the aruba server.
92 *
93 * If the 'server' header contains 'aruba-proxy'
94 * the service can be activated.
95 *
96 * If it is different from 'aruba-proxy' we are
97 * not on aruba server or behind cdn.
98 */
99 if ( is_array($headers) && array_key_exists( 'server', $headers ) ) {
100 switch ( $headers['server'] ) {
101 case 'aruba-proxy':
102 if ( is_array($headers) && array_key_exists( 'x-aruba-cache', $headers ) ){
103 if( 'NA' !== $headers['x-aruba-cache'] ){
104 $_status=$headers['x-aruba-cache'];
105 }else{
106 $_status=UNAVAILABLE;
107 }
108 AHSC_set_parameters_to_check( true, true, true , $_status,false);
109 }
110 AHSC_set_parameters_to_check( true, true, true , $_status);
111 if ( is_array($headers) && array_key_exists( 'x-aruba-cdn', $headers ) ){
112 if( 'NA' !== $headers['x-aruba-cdn'] ){
113 $cdn_status=$headers['x-aruba-cdn'];
114 }else{
115 $cdn_status=UNAVAILABLE;
116 }
117
118 AHSC_set_parameters_to_check( true, true, true , $_status,$cdn_status);
119 }
120 break;
121 default:
122 AHSC_set_parameters_to_check( false, false, false );
123
124 if ( array_key_exists( 'x-servername', $headers ) && false !== strpos( $headers['x-servername'], 'aruba.it' ) ) {
125 AHSC_set_parameters_to_check( true, false, true );
126 }
127 break;
128 }
129 }
130 }
131
132 /**
133 * Check - Check the populated variables and issue a control message.
134 *
135 * @since 1.0.1
136 * @return array
137 */
138 function AHSC_check() {
139 global $ahsc_check_parameters;
140
141 // Bypass in locale / dev
142 // if ( $_SERVER['HTTP_HOST'] === 'cconsole-test-20230620.eu:8081' ) {
143 // AHSC_set_parameters_to_check(true, true, true, ACTIVE);
144 // $ahsc_check_parameters['esit'] = ACTIVE;
145 // return $ahsc_check_parameters;
146 // }
147
148 AHSC_get_headers();
149 AHSC_headers_analizer();
150
151 $ahsc_check_parameters['esit'] = ACTIVE;
152
153 if ( $ahsc_check_parameters['is_aruba_server'] && ! $ahsc_check_parameters['service_is_active'] ) {
154 $ahsc_check_parameters['esit'] = ( $ahsc_check_parameters['service_is_activabile'] ) ? ACTIVE : UNAVAILABLE;
155
156 }else{
157 $ahsc_check_parameters['esit'] = ( $ahsc_check_parameters['service_is_activabile'] ) ? ACTIVE : NOARUBASERVER;
158 }
159
160 //var_dump($check_parameters);
161
162 return $ahsc_check_parameters;
163 }
164
165 /**
166 * Debugger - It exposes some elements of the control to
167 * try to resolve any errors. To activate it, just go to the
168 * dominio.tld/wp-admin/options-general.php?page=aruba-hispeed-cache&debug=1
169 *
170 * @return string
171 */
172 function ahsc_debugger() {
173 global $ahsc_check_error,$ahsc_check_status_code;
174
175 $headers=AHSC_get_headers();
176
177 $ahsc_check_parameters=AHSC_check();
178
179 $data = array(
180 'date' => \wp_date( 'D, d M Y H:i:s', time() ),
181 'target' => AHSC_CONSTANT['HOME_URL'],
182 'headers' => $headers,
183 'status_code' => $ahsc_check_status_code,
184 'check_params' => $ahsc_check_parameters,
185 );
186
187 if ( $ahsc_check_error ) {
188 $data['error'] = 'Sorry but the call was answered with an error. please try again later';
189 unset( $data['headers'] );
190 unset( $data['status_code'] );
191 unset( $data['check_params'] );
192 }
193
194 // Was var_export(). This is plain diagnostic output for the ?debug=1 view, so JSON
195 // serves the same purpose without reaching for a debug helper.
196 return (string) \wp_json_encode( $data, JSON_PRETTY_PRINT );
197 }
198
199 /**
200 * Get_headers - Getter of the headers for the request to perform the check.
201 *
202 * @since 1.0.1
203 * @return bool
204 */
205 function AHSC_get_headers() {
206
207 global $ahsc_check_status_code,$ahsc_check_error;
208
209
210 $response = \wp_remote_get(
211 AHSC_CONSTANT['HOME_URL'],
212 array(
213 'sslverify' => false,
214 'user-agent' => 'aruba-ua',
215 'httpversion' => '1.1',
216 'timeout' =>AHSC_CHECKER['request_timeout'],
217 )
218 );
219
220
221 if ( \is_array( $response ) && ! \is_wp_error( $response ) ) {
222 $headers = $response['headers']->getAll();
223 //var_dump($headers);
224 $ahsc_check_status_code = $response['response']['code'];
225
226 return $headers;
227 }
228
229 if ( \is_wp_error( $response ) ) {
230 $ahsc_check_error = true;
231 }
232
233 return false;
234 }
235
236 /**
237 * Check_hispeed_cache_services - check if aruba hispeed cache service is activable or is a aruba server.
238 *
239 * @param string $plugin The plugin fine relative path.
240 * @return void
241 *
242 * @SuppressWarnings(PHPMD.StaticAccess)
243 */
244 function ahsc_check_hispeed_cache_services( $plugin ) {
245 if ( 'aruba-hispeed-cache/aruba-hispeed-cache.php' === $plugin ) {
246 $check = AHSC_check();
247
248 if ( \is_multisite() ) {
249 \set_site_transient(
250 AHSC_CHECKER['transient_name'],
251 $check,
252 AHSC_CHECKER['transient_life_time']
253 );
254 }else{
255 \set_transient(
256 AHSC_CHECKER['transient_name'],
257 $check,
258 AHSC_CHECKER['transient_life_time']
259 );
260 }
261 }
262 }
263
264 if ( ! \function_exists( 'ahsc_get_check_notice' ) ) {
265
266 /**
267 * Return null or the admin notice to render.
268 *
269 * @param array $notice_type The option key to get.
270 * @return null|string
271 *
272 * @SuppressWarnings(PHPMD.StaticAccess)
273 */
274 function ahsc_get_check_notice( $notice_type ) {
275 $localize_link = AHSC_LOCALIZE_LINK;
276 $notice = null;
277 $lng=strtolower(substr( get_bloginfo ( 'language' ), 0, 2 ));
278
279 if($notice_type){
280 $notice_type=(array) $notice_type;
281 switch ( $notice_type['esit'] ) {
282 case AVAILABLE:
283 $notice['handle'] = 'ahsc-service-warning';
284 $notice['type'] = 'warning';
285 $notice['message'] = \sprintf(
286 \wp_kses(
287 // translators: %1$s: the pca url.
288 // translators: %2$s: the guide url.
289 __( '<strong>The HiSpeed Cache service is not enabled.</strong> To activate it, go to your domain <a href="%1$s" rel="nofollow" target="_blank">control panel</a> (verifying the status may take up to 15 minutes). For further details <a href="%2$s" rel="nofollow" target="_blank">see our guide</a>.', 'aruba-hispeed-cache' ),
290 array(
291 'strong' => array(),
292 'a' => array(
293 'href' => array(),
294 'target' => array(),
295 'rel' => array(),
296 ),
297 )
298 ),
299 esc_html( $localize_link['link_aruba_pca'][$lng] ),
300 esc_html( $localize_link['link_guide'][$lng] )
301 );
302 break;
303 case UNAVAILABLE:
304 $notice['handle'] = 'ahsc-service-error';
305 $notice['type'] = 'error';
306 $notice['message'] = \sprintf(
307 \wp_kses(
308 // translators: %s: the assistance url.
309 __( '<strong>The HiSpeed Cache service with which the plugin interfaces is not available on the server that hosts your website.</strong> To use HiSpeed Cache and the plugin, please contact <a href="%s" rel="nofollow" target="_blank">support</a>.', 'aruba-hispeed-cache' ),
310 array(
311 'strong' => array(),
312 'a' => array(
313 'href' => array(),
314 'target' => array(),
315 'rel' => array(),
316 ),
317 )
318 ),
319 esc_html( $localize_link['link_assistance'][$lng] )
320 );
321 break;
322 case NOARUBASERVER:
323 $notice['handle'] = 'ahsc-service-error';
324 $notice['type'] = 'error';
325 $notice['message'] = \sprintf(
326 \wp_kses(
327 // translators: %s: the hosting truck url.
328 __( '<strong>The Aruba HiSpeed Cache plugin cannot be used because your WordPress website is not hosted on an Aruba hosting platform.</strong> Buy an <a href="%s" rel="nofollow" target="_blank">Aruba Hosting service</a> and migrate your website to use the plugin.', 'aruba-hispeed-cache' ),
329 array(
330 'strong' => array(),
331 'a' => array(
332 'href' => array(),
333 'target' => array(),
334 'rel' => array(),
335 ),
336 )
337 ),
338 esc_html( $localize_link[ 'link_hosting_truck' ][$lng] )
339 );
340 break;
341 }
342
343 if ( ACTIVE !== $notice_type['esit'] ) {
344 $notice = AHSC_Notice_Render( $notice['handle'], $notice['type'],$notice['message'], false );
345 }
346
347 }else{
348 $notice=null;
349 }
350
351 return $notice;
352 }
353 }