Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Development
Core
Commits
4094935a
Commit
4094935a
authored
Apr 04, 2019
by
agilewarealok
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CIVICRM-1163: Replaced get_headers functions call with Guzzle HTTP request.
parent
46e0ade7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
25 deletions
+74
-25
CRM/Utils/Check/Component.php
CRM/Utils/Check/Component.php
+24
-0
CRM/Utils/Check/Component/Env.php
CRM/Utils/Check/Component/Env.php
+16
-18
CRM/Utils/Check/Component/Security.php
CRM/Utils/Check/Component/Security.php
+5
-7
tests/phpunit/CRM/Utils/Check/Component/EnvTest.php
tests/phpunit/CRM/Utils/Check/Component/EnvTest.php
+29
-0
No files found.
CRM/Utils/Check/Component.php
View file @
4094935a
...
...
@@ -25,6 +25,8 @@
+--------------------------------------------------------------------+
*/
use
GuzzleHttp\Client
;
/**
*
* @package CRM
...
...
@@ -57,4 +59,26 @@ abstract class CRM_Utils_Check_Component {
return
$messages
;
}
/**
* Check if file exists on given URL.
*
* @param $url
* @return bool
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public
function
fileExists
(
$url
,
$timeout
=
0.25
)
{
$fileExists
=
FALSE
;
try
{
$guzzleClient
=
new
GuzzleHttp\Client
();
$guzzleResponse
=
$guzzleClient
->
request
(
'GET'
,
$url
,
array
(
'timeout'
=>
$timeout
,
));
$fileExists
=
(
$guzzleResponse
->
getStatusCode
()
==
200
);
}
catch
(
Exception
$e
)
{
echo
$e
->
getMessage
();
}
return
$fileExists
;
}
}
CRM/Utils/Check/Component/Env.php
View file @
4094935a
...
...
@@ -47,9 +47,9 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
1
=>
$phpVersion
,
2
=>
CRM_Upgrade_Incremental_General
::
RECOMMENDED_PHP_VER
,
)),
ts
(
'PHP Up-to-Date'
),
\
Psr\Log\LogLevel
::
INFO
,
'fa-server'
ts
(
'PHP Up-to-Date'
),
\
Psr\Log\LogLevel
::
INFO
,
'fa-server'
);
}
elseif
(
version_compare
(
$phpVersion
,
CRM_Upgrade_Incremental_General
::
MIN_RECOMMENDED_PHP_VER
)
>=
0
)
{
...
...
@@ -60,9 +60,9 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
1
=>
$phpVersion
,
2
=>
CRM_Upgrade_Incremental_General
::
RECOMMENDED_PHP_VER
,
)),
ts
(
'PHP Out-of-Date'
),
\
Psr\Log\LogLevel
::
NOTICE
,
'fa-server'
ts
(
'PHP Out-of-Date'
),
\
Psr\Log\LogLevel
::
NOTICE
,
'fa-server'
);
}
elseif
(
version_compare
(
$phpVersion
,
CRM_Upgrade_Incremental_General
::
MIN_INSTALL_PHP_VER
)
>=
0
)
{
...
...
@@ -74,9 +74,9 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
2
=>
CRM_Upgrade_Incremental_General
::
MIN_RECOMMENDED_PHP_VER
,
3
=>
CRM_Upgrade_Incremental_General
::
RECOMMENDED_PHP_VER
,
)),
ts
(
'PHP Out-of-Date'
),
\
Psr\Log\LogLevel
::
WARNING
,
'fa-server'
ts
(
'PHP Out-of-Date'
),
\
Psr\Log\LogLevel
::
WARNING
,
'fa-server'
);
}
else
{
...
...
@@ -88,9 +88,9 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
2
=>
CRM_Upgrade_Incremental_General
::
MIN_RECOMMENDED_PHP_VER
,
3
=>
CRM_Upgrade_Incremental_General
::
RECOMMENDED_PHP_VER
,
)),
ts
(
'PHP Out-of-Date'
),
\
Psr\Log\LogLevel
::
ERROR
,
'fa-server'
ts
(
'PHP Out-of-Date'
),
\
Psr\Log\LogLevel
::
ERROR
,
'fa-server'
);
}
...
...
@@ -111,9 +111,9 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
1
=>
'https://civicrm.org/blog/totten/psa-please-verify-php-extension-mysqli'
,
2
=>
'mysqli'
,
)),
ts
(
'Forward Compatibility: Enable "mysqli"'
),
\
Psr\Log\LogLevel
::
WARNING
,
'fa-server'
ts
(
'Forward Compatibility: Enable "mysqli"'
),
\
Psr\Log\LogLevel
::
WARNING
,
'fa-server'
);
}
...
...
@@ -883,9 +883,7 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
// Does arrow.png exist where we expect it?
$arrowUrl
=
CRM_Core_Config
::
singleton
()
->
userFrameworkResourceURL
.
'packages/jquery/css/images/arrow.png'
;
$headers
=
get_headers
(
$arrowUrl
);
$fileExists
=
stripos
(
$headers
[
0
],
"200 OK"
)
?
1
:
0
;
if
(
$fileExists
===
FALSE
)
{
if
(
$this
->
fileExists
(
$arrowUrl
)
===
FALSE
)
{
$messages
[]
=
new
CRM_Utils_Check_Message
(
__FUNCTION__
,
ts
(
'The Resource URL is not set correctly. Please set the <a href="%1">CiviCRM Resource URL</a>.'
,
...
...
CRM/Utils/Check/Component/Security.php
View file @
4094935a
...
...
@@ -86,8 +86,7 @@ class CRM_Utils_Check_Component_Security extends CRM_Utils_Check_Component {
if
(
count
(
$log_path
)
>
1
)
{
$url
[]
=
$log_path
[
1
];
$log_url
=
implode
(
$filePathMarker
,
$url
);
$headers
=
@
get_headers
(
$log_url
);
if
(
stripos
(
$headers
[
0
],
'200'
))
{
if
(
$this
->
fileExists
(
$log_url
))
{
$docs_url
=
$this
->
createDocUrl
(
'checkLogFileIsNotAccessible'
);
$msg
=
'The <a href="%1">CiviCRM debug log</a> should not be downloadable.'
.
'<br />'
.
...
...
@@ -145,9 +144,9 @@ class CRM_Utils_Check_Component_Security extends CRM_Utils_Check_Component {
2
=>
$privateDir
,
3
=>
$heuristicUrl
,
)),
ts
(
'Private Files Readable'
),
\
Psr\Log\LogLevel
::
WARNING
,
'fa-lock'
ts
(
'Private Files Readable'
),
\
Psr\Log\LogLevel
::
WARNING
,
'fa-lock'
);
}
}
...
...
@@ -365,8 +364,7 @@ class CRM_Utils_Check_Component_Security extends CRM_Utils_Check_Component {
return
FALSE
;
}
$headers
=
@
get_headers
(
"
$url
/
$file
"
);
if
(
stripos
(
$headers
[
0
],
'200'
))
{
if
(
$this
->
fileExists
(
"
$url
/
$file
"
))
{
$content
=
@
file_get_contents
(
"
$url
/
$file
"
);
if
(
preg_match
(
'/delete me/'
,
$content
))
{
$result
=
TRUE
;
...
...
tests/phpunit/CRM/Utils/Check/Component/EnvTest.php
0 → 100644
View file @
4094935a
<?php
/**
* Class CRM_Utils_Check_Component_EnvTest
* @package CiviCRM
* @subpackage CRM_Utils_Type
* @group headless
*/
class
CRM_Utils_Check_Component_EnvTest
extends
CiviUnitTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
}
/**
* File check test should fail if reached maximum timeout.
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public
function
testResourceUrlCheck
()
{
$check
=
new
\
CRM_Utils_Check_Component_Env
();
$failRequest
=
$check
->
fileExists
(
'https://civicrm.org'
,
0.001
);
$successRequest
=
$check
->
fileExists
(
'https://civicrm.org'
,
0
);
$this
->
assertEquals
(
FALSE
,
$failRequest
,
'Request should fail for minimum timeout.'
);
$this
->
assertEquals
(
TRUE
,
$successRequest
,
'Request should not fail for infinite timeout.'
);
}
}
totten
@totten
mentioned in issue
#855 (closed)
·
Apr 06, 2019
mentioned in issue
#855 (closed)
mentioned in issue #855
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment