Skip to content

Commit

Permalink
Merge branch 'hotfix-alt-ports'
Browse files Browse the repository at this point in the history
  • Loading branch information
gav- committed Mar 21, 2016
2 parents 5896f73 + e7dd274 commit b72e584
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.htaccess
web.config
code
Build
FileMaker
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 4.0.1 (Released 2016-03-22) ###
- Handle alternate http/https ports and/or port-forwarding scenarios
in report page.

### 4.0.0 (Released 2016-03-11) ###
- Handle searching on repetitions where submitted search field contains an
index.
Expand Down
175 changes: 51 additions & 124 deletions lib/RESTfm/Diagnostics.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ class Diagnostics {
'hostServerVersion',
'hostSystemDate',
'documentRoot',
//'licence',
'baseURI',
'webserverRedirect',
'filemakerAPI',
'filemakerConnect',
'sslEnforced',
'sslServer',
'sslWebserverRedirect',
'xslExtension',
);

Expand Down Expand Up @@ -264,11 +261,13 @@ public function test_baseURI($reportItem) {
public function test_webserverRedirect($reportItem) {
$reportItem->name = 'Web server redirect to RESTfm.php';

$URL = $this->_calculatedRESTfmURL() . '/?RFMversion';
if (RESTfmConfig::getVar('settings', 'SSLOnly') && ! $this->_isHTTPS()) {
$URL = preg_replace('/^http:/', 'https:', $URL);
if ($this->_isSSLOnlyAndNotHTTPS()) {
$reportItem->status = ReportItem::WARN;
$reportItem->details .= 'Unable to test, SSLOnly is TRUE. Try visiting this page with https instead.' . "\n";
return;
}

$URL = $this->_calculatedRESTfmURL() . '/?RFMversion';
$reportItem->details .= '<a href="'. $URL . '">' . $URL . '</a>' . "\n";

$ch = curl_init($URL);
Expand Down Expand Up @@ -299,8 +298,14 @@ public function test_webserverRedirect($reportItem) {
$reportItem->details .= htmlspecialchars($this->_darwinAllowOverrideInstructions());
} else {
$reportItem->details .= 'Check the Apache httpd configuration has \'AllowOverride All\' for the RESTfm directory.' . "\n";
if ($this->_isHTTPS()) {
$reportItem->details .= 'May also be needed in the VirtualHost section for SSL port (443).' . "\n";
}
}
}
} elseif ($this->_isHTTPS() && curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404 && $this->_isDarwinFileMaker13()) {
$reportItem->status = ReportItem::ERROR;
$reportItem->details .= htmlspecialchars($this->_darwinFMS13InstallerInstructions());
} elseif ( $result != Version::getVersion() ) {
$reportItem->status = ReportItem::ERROR;
$reportItem->details .= 'RESTfm failed to respond correctly: ' . $result . "\n";
Expand All @@ -314,11 +319,13 @@ public function test_webserverRedirect($reportItem) {
public function test_filemakerAPI($reportItem) {
$reportItem->name = 'FileMaker PHP API';

$URL = $this->_calculatedRESTfmURL() . '/RESTfm.php?RFMcheckFMAPI';
if (RESTfmConfig::getVar('settings', 'SSLOnly') && ! $this->_isHTTPS()) {
$URL = preg_replace('/^http:/', 'https:', $URL);
if ($this->_isSSLOnlyAndNotHTTPS()) {
$reportItem->status = ReportItem::WARN;
$reportItem->details .= 'Unable to test, SSLOnly is TRUE. Try visiting this page with https instead.' . "\n";
return;
}

$URL = $this->_calculatedRESTfmURL() . '/RESTfm.php?RFMcheckFMAPI';
$reportItem->details .= '<a href="'. $URL . '">' . $URL . '</a>' . "\n";

$ch = curl_init($URL);
Expand Down Expand Up @@ -350,6 +357,12 @@ public function test_filemakerAPI($reportItem) {
public function test_filemakerConnect($reportItem) {
$reportItem->name = 'FileMaker Server connection test';

if ($this->_isSSLOnlyAndNotHTTPS()) {
$reportItem->status = ReportItem::WARN;
$reportItem->details .= 'Unable to test, SSLOnly is TRUE. Try visiting this page with https instead.' . "\n";
return;
}

if ($this->_report->filemakerAPI->status != ReportItem::OK) {
$reportItem->status = ReportItem::ERROR;
$reportItem->details = 'Cannot test, FileMaker PHP API not found.' . "\n";
Expand Down Expand Up @@ -441,120 +454,13 @@ public function test_filemakerConnect($reportItem) {
public function test_sslEnforced($reportItem) {
$reportItem->name = 'SSL enforced (' . RESTfmConfig::CONFIG_INI . ')';

if (RESTfmConfig::getVar('settings', 'SSLOnly') != TRUE) {
$reportItem->status = ReportItem::WARN;
$reportItem->details .= "SSLOnly not TRUE in " . RESTfmConfig::CONFIG_INI . ' configuration file.' . "\n";
$reportItem->details .= 'SSL is highly recommended to protect data, usernames and passwords from eavesdropping.' . "\n";
if (RESTfmConfig::getVar('settings', 'SSLOnly') === TRUE) {
$reportItem->details .= 'SSLOnly is TRUE in ' . RESTfmConfig::CONFIG_INI . "\n";
} else {
$reportItem->details .= 'OK' . "\n";
}
}

public function test_sslServer($reportItem) {
$reportItem->name = 'SSL enabled on web server';

// Increase error level if user has enforced SSL in config.
$SSLfailureCode = ReportItem::WARN;
if ($this->_report->sslEnforced->status == ReportItem::OK) {
$SSLfailureCode = ReportItem::ERROR;
}

if ($this->_isHTTPS() && $this->_report->webserverRedirect->status == ReportItem::OK) {
// Already working.
$reportItem->details = "OK";
$reportItem->status = ReportItem::NA;
return;
}

$URL = 'https://' . $_SERVER['SERVER_NAME'];
$reportItem->details .= '<a href="'. $URL . '">' . $URL . '</a>' . "\n";

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if (RESTfmConfig::getVar('settings', 'strictSSLCertsReport') === FALSE) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
}
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'RESTfm Diagnostics');
$result = curl_exec($ch);

if (curl_errno($ch)) {
$reportItem->status = $SSLfailureCode;
$reportItem->details .= 'cURL failed with error: ' . curl_errno($ch) . ': ' . curl_error($ch) . "\n";
if (curl_errno($ch) == 60) { // SSL certificate problem: self signed certificate
$reportItem->details .= 'On development (not production) systems it is possible to disable this check' ."\n";
$reportItem->details .= 'by setting "strictSSLCertsReport" to FALSE in ' . RESTfmConfig::CONFIG_INI ."\n";
}
} else {
$reportItem->details .= "OK" . "\n";
}
curl_close($ch);
}

public function test_sslWebserverRedirect($reportItem) {
$reportItem->name = 'SSL redirect to RESTfm';

// Increase error level if user has enforced SSL in config.
$SSLfailureCode = ReportItem::WARN;
if ($this->_report->sslEnforced->status == ReportItem::OK) {
$SSLfailureCode = ReportItem::ERROR;
}

if ($this->_isHTTPS() && $this->_report->webserverRedirect->status == ReportItem::OK) {
// Already working.
$reportItem->details = "OK";
$reportItem->status = ReportItem::NA;
return;
} elseif ($this->_report->sslServer->status != ReportItem::OK) {
// No chance.
$reportItem->details = "Not tested, SSL not enabled on web server.";
$reportItem->status = $SSLfailureCode;
return;
}

$URL = $this->_calculatedRESTfmURL() . '/?RFMversion';
$URL = preg_replace('/^http:/', 'https:', $URL);

$reportItem->details .= '<a href="'. $URL . '">' . $URL . '</a>' . "\n";

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if (RESTfmConfig::getVar('settings', 'strictSSLCertsReport') === FALSE) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
}
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'RESTfm Diagnostics');
$result = curl_exec($ch);

if (curl_errno($ch)) {
$reportItem->status = ReportItem::WARN;
$reportItem->details .= 'cURL failed with error: ' . curl_errno($ch) . ': ' . curl_error($ch) . "\n";
} elseif ( strpos($result, 'RESTfm is not configured') ) {
$reportItem->status = $SSLfailureCode;
$reportItem->details .= 'Redirection not working, index.html was returned instead.' . "\n";
if ($this->_isApache()) {
$reportItem->details .= 'Check the Apache httpd configuration has \'AllowOverride All\' for the RESTfm Directory,' . "\n";
$reportItem->details .= 'may also be needed in the VirtualHost section for port 443.' . "\n";
}
} elseif (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404 && $this->_isDarwinFileMaker13()) {
$reportItem->status = $SSLfailureCode;
$reportItem->details .= htmlspecialchars($this->_darwinFMS13SSLAllowOverrideInstructions());
} elseif ( $result != Version::getVersion() ) {
$reportItem->status = $SSLfailureCode;
$reportItem->details .= 'RESTfm failed to respond correctly: ' . $result . "\n";
} else {
$reportItem->details .= 'OK';
$reportItem->details .= "SSLOnly not TRUE in " . RESTfmConfig::CONFIG_INI . "\n";
$reportItem->details .= 'SSL is highly recommended to protect data, usernames and passwords from eavesdropping.' . "\n";
}

curl_close($ch);
}

public function test_xslExtension ($reportItem) {
Expand Down Expand Up @@ -631,7 +537,7 @@ private function _isIIS() {
}

/**
* Returns TRUE if https was used to connect.
* Returns TRUE if HTTPS was used to connect.
*/
private function _isHTTPS() {
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ||
Expand All @@ -641,6 +547,17 @@ private function _isHTTPS() {
return FALSE;
}

/**
* Returns TRUE if SSLOnly is set in config AND HTTPS was NOT used to
* connect. (Some diagnostic tests would fail in this case.)
*/
private function _isSSLOnlyAndNotHTTPS() {
if (RESTfmConfig::getVar('settings', 'SSLOnly') && ! $this->_isHTTPS()) {
return TRUE;
}
return FALSE;
}

/**
* Returns Release string if Darwin is the Operating System. Returns False
* otherwise.
Expand Down Expand Up @@ -698,11 +615,21 @@ private function _isDarwinFileMaker13() {
* Returns the proper RESTfm URL as determined by the calculated base URI.
*/
private function _calculatedRESTfmURL() {
$URL = 'http://';
$scheme = '';
$port = '';

if ($this->_isHTTPS()) {
$URL = 'https://';
$scheme = 'https';
if ($_SERVER['SERVER_PORT'] !== '443') {
$port = ':' . $_SERVER['SERVER_PORT'];
}
} else {
$scheme = 'http';
if ($_SERVER['SERVER_PORT'] !== '80') {
$port = ':' . $_SERVER['SERVER_PORT'];
}
}
$URL .= $_SERVER['SERVER_NAME'] . $this->_calculatedBaseURI();
$URL = $scheme . '://' . $_SERVER['SERVER_NAME'] . $port . $this->_calculatedBaseURI();
return($URL);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/RESTfm/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Version static class to hold release version.
*/
class Version {
private static $_release = '4.0.0';
private static $_release = '4.0.1';
private static $_revision = '%%REVISION%%';
private static $_protocol = '5'; // Bump this when REST API changes.

Expand Down

0 comments on commit b72e584

Please sign in to comment.