Catch HTTP error codes

pull/439/head
Richard van den Berg 2015-03-19 14:05:10 +01:00
parent 2f58fdec0d
commit 850e4bd19f
2 changed files with 10 additions and 6 deletions

View File

@ -295,7 +295,7 @@ class ServersController extends AppController {
);
$writeableErrors = array(0 => 'OK', 1 => 'Directory doesn\'t exist', 2 => 'Directory is not writeable');
$gpgErrors = array(0 => 'OK', 1 => 'FAIL: settings not set', 2 => 'FAIL: bad GnuPG.*', 3 => 'FAIL: encrypt failed');
$proxyErrors = array(0 => 'OK', 1 => 'Getting URL via proxy failed');
$proxyErrors = array(0 => 'OK', 1 => 'not configured (so not tested)', 2 => 'Getting URL via proxy failed');
$stixErrors = array(0 => 'ERROR', 1 => 'OK');
$results = $this->Server->serverSettingsRead();
@ -407,12 +407,15 @@ class ServersController extends AppController {
$HttpSocket = $syncTool->setupHttpSocket();
$proxyResponse = $HttpSocket->get('http://www.example.com/');
} catch (Exception $e) {
$proxyStatus = 2;
}
if(empty($proxyResponse)) {
if(empty($proxyResponse) || $proxyResponse->code > 399) {
$proxyStatus = 2;
}
} else {
$proxyStatus = 1;
}
}
if ($proxyStatus != 0) $diagnostic_errors++;
if ($proxyStatus > 1) $diagnostic_errors++;
$this->set('gpgStatus', $gpgStatus);
$this->set('proxyStatus', $proxyStatus);
@ -482,8 +485,9 @@ class ServersController extends AppController {
$response = $HttpSocket->get('https://api.github.com/repos/MISP/MISP/tags');
$tags = $response->body;
} catch (Exception $e) {
return false;
}
if (!empty($tags)) {
if ($response->code < 300 && !empty($tags)) {
$json_decoded_tags = json_decode($tags);
// find the latest version tag in the v[major].[minor].[hotfix] format

View File

@ -94,7 +94,7 @@
<?php
$colour = 'green';
$message = $proxyErrors[$proxyStatus];
if ($proxyStatus > 0) {
if ($proxyStatus > 1) {
$colour = 'red';
}
echo 'Proxy settings....<span style="color:' . $colour . ';">' . $message . '</span>';