public function runTest()
 {
     $path = $this->getConfigValue('path');
     $operation = array('GetDiskSpace', array('path' => $path));
     $operations = array($operation);
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $results = $commandResult->getOperationResults();
     $operationResult = $results[0];
     if ($operationResult->isSuccessful()) {
         $diskSpace = $operationResult->getValue();
     } else {
         return $this->getFailedOperationResultTestResult($operationResult);
     }
     $minFreeAbsolute = $this->getMinFreeAbsolute($this->getConfigValue('min_free'), $this->getConfigValue('min_free_unit'), $diskSpace);
     $info = '(' . 'free: ' . $this->humanFilesize($diskSpace['free']) . ' ; total: ' . $this->humanFilesize($diskSpace['total']) . ($minFreeAbsolute > 0 ? ' ; expected free: ' . $this->getConfigValue('min_free') . $this->getConfigValue('min_free_unit') : '') . ')';
     if (!empty($minFreeAbsolute)) {
         if ($diskSpace['free'] <= $minFreeAbsolute) {
             $message = 'Not enough free disk space ' . $info;
             return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, $message);
         }
     }
     $message = 'Disk space test successful ' . $info;
     return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, 0, $message);
 }
 /**
  * Notify the service about a test status
  *
  * @param string $event
  * @param tx_caretaker_AbstractNode $node
  * @param tx_caretaker_TestResult $result
  * @param tx_caretaKer_TestResult $lastResult
  */
 public function addNotification($event, $node, $result = NULL, $lastResult = NULL)
 {
     $indent = $this->getCliIndentation($node);
     if (is_a($node, 'tx_caretaker_TestNode')) {
         $infotext = $result->getLocallizedInfotext();
         $msg = $indent . '--+ ' . $node->getTitle() . ' [' . $node->getCaretakerNodeId() . ']';
         $msg .= str_replace(chr(10), chr(10) . $indent . '  | ', chr(10) . $infotext);
         $msg .= chr(10) . $indent . '  +-> ' . $result->getLocallizedStateInfo() . ' (' . $event . ')';
     } else {
         if ($result == NULL) {
             $msg = $indent . '--+ ' . $node->getTitle() . ' [' . $node->getCaretakerNodeId() . ']' . $infotext . ' ' . $event;
         } else {
             $msg = $indent . '  +-> ' . $result->getLocallizedStateInfo() . ' ' . $event . ' [' . $node->getCaretakerNodeId() . ']';
         }
     }
     echo $msg . chr(10);
     flush();
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see caretaker/trunk/services/tx_caretaker_TestServiceBase#runTest()
  */
 function runTest()
 {
     $filename = $this->getTimestampFilename();
     $time = time();
     if (file_put_contents($filename, $time) !== FALSE) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok);
     } else {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, 'Could not touch file ' . $filename);
     }
 }
コード例 #4
0
 function test_TestResult_stores_data()
 {
     $result = new tx_caretaker_TestResult(123, 1, 1.75, 'This is a Message');
     $this->assertEquals($result->getTimestamp(), 123);
     $this->assertEquals($result->getState(), 1);
     $this->assertEquals($result->getStateInfo(), 'WARNING');
     $this->assertEquals($result->getValue(), 1.75);
     $this->assertEquals($result->getMessage()->getText(), 'This is a Message');
 }
コード例 #5
0
 function test_aggregation_of_results()
 {
     $aggregator = new tx_caretaker_AggregatorNode_Stub(0, 'foo', false);
     $instance = new tx_caretaker_InstanceNode(0, 'bar', false);
     $node = new tx_caretaker_TestNode(0, 'baz', $instance, 'tx_caretaker_ping', '');
     $results = array();
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok));
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok));
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create(tx_caretaker_Constants::state_warning));
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error));
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error));
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok));
     $results[] = array('node' => $node, 'result' => tx_caretaker_TestResult::create());
     $aggregated_result = $aggregator->getAggregatedResult($results);
     $this->assertEquals(2, $aggregated_result->getNumERROR(), "wrong error count");
     $this->assertEquals(1, $aggregated_result->getNumWARNING(), "wrong warning count");
     $this->assertEquals(3, $aggregated_result->getNumOK(), "wrong ok count");
     $this->assertEquals(1, $aggregated_result->getNumUNDEFINED(), "wrong undefined count");
     $this->assertEquals(tx_caretaker_Constants::state_error, $aggregated_result->getState(), "wrong result");
 }
コード例 #6
0
 function test_comparisonOfTestResults()
 {
     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined);
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined);
     $this->assertTrue($result->equals($compareResult), 'two empty undefined results should be equal');
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok);
     $this->assertTrue($result->isDifferent($compareResult), 'result with other state is not equal');
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0);
     $this->assertTrue($result->equals($compareResult), 'default is undefined state and value 0');
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 1);
     $this->assertTrue($result->isDifferent($compareResult), 'value 1 is different from 0');
     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok);
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok);
     $this->assertTrue($result->equals($compareResult), 'two empty OK results should be equal');
     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_warning);
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_warning);
     $this->assertTrue($result->equals($compareResult), 'two empty WARNING results should be equal');
     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error);
     $compareResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error);
     $this->assertTrue($result->equals($compareResult), 'two empty ERROR results should be equal');
 }
 public function runTest()
 {
     $minVersion = $this->checkForLatestVersion($this->getConfigValue('min_version'));
     $maxVersion = $this->checkForLatestVersion($this->getConfigValue('max_version'));
     if (!$minVersion && !$maxVersion) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0, 'Cannot execute TYPO3 version test without min and max version');
     }
     if ($maxVersion === FALSE) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0, 'No TYPO3 version information available. Please add "TYPO3 Versionnumbers Update" to your scheduler queue.');
     }
     $operation = array('GetTYPO3Version');
     $operations = array($operation);
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $results = $commandResult->getOperationResults();
     $operationResult = $results[0];
     if ($operationResult->isSuccessful()) {
         $version = $operationResult->getValue();
     } else {
         return $this->getFailedOperationResultTestResult($operationResult);
     }
     $checkResult = $this->checkVersionRange($version, $minVersion, $maxVersion);
     if ($checkResult) {
         $message = 'TYPO3 version ' . $version . ' is installed';
         $testResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, 0, $message);
     } else {
         $message = 'TYPO3 version ' . $version . ' is installed, but';
         if ($minVersion) {
             $message .= ' >= ' . $minVersion;
         }
         if ($maxVersion) {
             $message .= ' <= ' . $maxVersion;
         }
         $message .= ' expected.';
         $testResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, $message);
     }
     return $testResult;
 }
 /**
  * Execute the find insecure extension test
  * @return tx_caretaker_TestResult
  */
 public function runTest()
 {
     $location_list = $this->getLocationList();
     $operation = array('GetExtensionList', array('locations' => $location_list));
     $operations = array($operation);
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $results = $commandResult->getOperationResults();
     $operationResult = $results[0];
     if (!$operationResult->isSuccessful()) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, 'Remote operation failed: ' . $operationResult->getValue());
     }
     $extensionList = $operationResult->getValue();
     $errors = array();
     $warnings = array();
     $oks = array();
     foreach ($extensionList as $extension) {
         $this->checkExtension($extension, $errors, $warnings, $oks);
     }
     // Return error if insecure extensions are installed
     $num_errors = count($errors);
     $num_warnings = count($warnings);
     $num_oks = count($oks);
     $submessages = array();
     $values = array('num_errors' => $num_errors, 'num_warnings' => $num_warnings);
     // add error submessages
     if ($num_errors > 0) {
         $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker_instance/locallang.xml:find_extension_updates_test_detail_error');
         foreach ($errors as $error) {
             $submessages[] = new tx_caretaker_ResultMessage($error['message'], $error['values']);
         }
     }
     // add warning submessages
     if ($num_warnings > 0) {
         $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker_instance/locallang.xml:find_extension_updates_test_detail_warning');
         foreach ($warnings as $warning) {
             $submessages[] = new tx_caretaker_ResultMessage($warning['message'], $warning['values']);
         }
     }
     // add ok submessages
     if ($num_oks > 0) {
         $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker_instance/locallang.xml:find_extension_updates_test_detail_ok');
         foreach ($oks as $ok) {
             $submessages[] = new tx_caretaker_ResultMessage($ok['message'], $ok['values']);
         }
     }
     // return error
     if ($num_errors > 0) {
         $value = count($errors) + count($warnings);
         $message = new tx_caretaker_ResultMessage('LLL:EXT:caretaker_instance/locallang.xml:insecure_extension_test_problems', $values);
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, $value, $message, $submessages);
     }
     // return warning
     if ($num_warnings > 0) {
         $value = count($warnings);
         $message = new tx_caretaker_ResultMessage('LLL:EXT:caretaker_instance/locallang.xml:insecure_extension_test_problems', $values);
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_warning, $value, $message, $submessages);
     }
     // return ok
     $value = 0;
     $message = new tx_caretaker_ResultMessage('LLL:EXT:caretaker_instance/locallang.xml:insecure_extension_test_ok', $values);
     return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, $value, $message, $submessages);
 }
コード例 #9
0
 /**
  * (non-PHPdoc)
  * @see caretaker/trunk/services/tx_caretaker_TestServiceBase#runTest()
  */
 function runTest()
 {
     $timeWarning = $this->getTimeWarning();
     $timeError = $this->getTimeError();
     // request
     $requestQuery = $this->getRequestQuery();
     $requestMethod = $this->getRequestMethod();
     $requestData = $this->getRequestData();
     $requestUsername = $this->getRequestUsername();
     $requestPassword = $this->getRequestPassword();
     $requestPort = $this->getRequestPort();
     $requestProxy = $this->getRequestProxy();
     $requestProxyport = $this->getRequestProxyport();
     // response
     $expectedStatus = $this->getExpectedReturnCode();
     $expectedHeaders = $this->getExpectedHeaders();
     $expectedRegex = $this->getExpectedRegex();
     $expectedDateAge = $this->getExpectedDateAge();
     $expectedModifiedAge = $this->getExpectedModifiedAge();
     if (preg_match('/^https?:\\/\\/.*/', $requestQuery)) {
         $parsed_url = parse_url($requestQuery);
         $requestQuery = '?' . $parsed_url['query'];
     } else {
         $url = $this->getInstanceUrl();
         $parsed_url = parse_url($url);
     }
     if ($parsed_url['path'] == '') {
         $parsed_url['path'] = '/';
     }
     if ($parsed_url['port'] && !$requestPort) {
         $requestPort = $parsed_url['port'];
     }
     if ($parsed_url['user'] && !$requestUsername) {
         $requestUsername = $parsed_url['user'];
     }
     if ($parsed_url['pass'] && !$requestPassword) {
         $requestPassword = $parsed_url['pass'];
     }
     $request_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path'] . $requestQuery;
     // no query
     if (!($expectedStatus && $request_url)) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0, 'LLL:EXT:caretaker/locallang_fe.xml:http_no_query');
     }
     // execute query
     list($time, $content, $info, $headers) = $this->executeCurlRequest($request_url, $timeError * 3, $requestPort, $requestMethod, $requestUsername, $requestPassword, $requestData, $requestProxy, $requestProxyport);
     $submessages = array();
     // time-ERROR
     $resultState = tx_caretaker_Constants::state_ok;
     if ($timeError && $time > $timeError) {
         $resultState = tx_caretaker_Constants::state_error;
         $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_time_error', array('time' => $time));
     } else {
         if ($timeWarning && $time > $timeWarning) {
             if ($resultState < tx_caretaker_Constants::state_warning) {
                 $resultState = tx_caretaker_Constants::state_warning;
             }
             $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_time_warning', array('time' => $time));
         }
     }
     // http-status check
     if (!in_array($info['http_code'], $expectedStatus)) {
         $resultState = $this->getErrorTypeOnFailure();
         $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_state_error', array('state_returned' => $info['http_code'], 'state_expected' => implode(',', $expectedStatus)));
     }
     // http-header check
     if (count($expectedHeaders) > 0) {
         $headerSuccess = TRUE;
         foreach ($expectedHeaders as $headerName => $expectedValue) {
             $returnedValue = $headers[$headerName];
             if (!$returnedValue) {
                 $resultState = tx_caretaker_Constants::state_error;
                 $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_header_missing', array('name' => $headerName));
             } else {
                 $partialSuccess = $this->checkSingleHeader($returnedValue, $expectedValue);
                 if ($partialSuccess == FALSE) {
                     $headerSuccess = FALSE;
                     $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_header_error', array('name' => $headerName, 'expected' => $expectedValue, 'returned' => $returnedValue));
                 } else {
                     $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_header_ok', array('name' => $headerName, 'expected' => $expectedValue, 'returned' => $returnedValue));
                 }
             }
         }
         if (!$headerSuccess) {
             $resultState = tx_caretaker_Constants::state_error;
         }
     }
     // regex  check
     if (count($expectedRegex) > 0) {
         $regexSuccess = TRUE;
         foreach ($expectedRegex as $regex) {
             if (preg_match($regex, $content)) {
                 $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_regex_ok', array('regex' => htmlspecialchars($regex)));
             } else {
                 $regexSuccess = FALSE;
                 $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_regex_error', array('regex' => htmlspecialchars($regex)));
             }
         }
         if (!$regexSuccess) {
             $resultState = tx_caretaker_Constants::state_error;
         }
     }
     // date header check
     if ($expectedDateAge) {
         $expectedDate = 'Age:<' . $expectedDateAge;
         $returnedDate = $headers['Date'];
         if (!$returnedDate) {
             $resultState = tx_caretaker_Constants::state_error;
             $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_header_missing', array('name' => 'Date'));
         } else {
             $partialSuccess = $this->checkSingleHeader($returnedDate, $expectedDate);
             if (!$partialSuccess) {
                 $resultState = tx_caretaker_Constants::state_error;
                 $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_date_error', array('plain' => $returnedDate, 'parsed' => strftime('%X %x', $this->parseHeaderDate($returnedDate)), 'max_age' => $expectedDateAge));
             }
         }
     }
     // modified header check
     if ($expectedModifiedAge) {
         $expectedDate = 'Age:<' . $expectedModifiedAge;
         $returnedDate = $headers['Last-Modified'];
         if (!$returnedDate) {
             $resultState = tx_caretaker_Constants::state_error;
             $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_header_missing', array('name' => 'Last-Modified'));
         } else {
             $partialSuccess = $this->checkSingleHeader($returnedDate, $expectedDate);
             if (!$partialSuccess) {
                 $resultState = tx_caretaker_Constants::state_error;
                 $submessages[] = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:http_modified_error', array('plain' => $returnedDate, 'parsed' => strftime('%X %x', $this->parseHeaderDate($returnedDate)), 'max_age' => $expectedModifiedAge));
             }
         }
     }
     $message = '';
     $values = array('url' => $request_url, 'time' => $time, 'state' => $info['http_code']);
     switch ($resultState) {
         case tx_caretaker_Constants::state_error:
             $message = 'LLL:EXT:caretaker/locallang_fe.xml:http_error';
             break;
         case tx_caretaker_Constants::state_warning:
             $message = 'LLL:EXT:caretaker/locallang_fe.xml:http_warning';
             break;
         case tx_caretaker_Constants::state_ok:
             $message = 'LLL:EXT:caretaker/locallang_fe.xml:http_ok';
             break;
     }
     // Return
     return tx_caretaker_TestResult::create($resultState, $time, new tx_caretaker_ResultMessage($message, $values), $submessages);
 }
 public function runTest()
 {
     $blacklistedUsernames = explode(chr(10), $this->getConfigValue('blacklist'));
     $operations = array();
     foreach ($blacklistedUsernames as $username) {
         $username = trim($username);
         if (strlen($username)) {
             $operations[] = array('GetRecord', array('table' => 'be_users', 'field' => 'username', 'value' => $username, 'checkEnableFields' => TRUE));
         }
     }
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $usernames = array();
     $results = $commandResult->getOperationResults();
     foreach ($results as $operationResult) {
         if ($operationResult->isSuccessful()) {
             $user = $operationResult->getValue();
             if ($user !== FALSE) {
                 $usernames[] = $user['username'];
             }
         } else {
             return $this->getFailedOperationResultTestResult($operationResult);
         }
     }
     $blacklistedUsernamesFound = array();
     foreach ($blacklistedUsernames as $username) {
         if (in_array($username, $usernames)) {
             $blacklistedUsernamesFound[] = $username;
         }
     }
     if (count($blacklistedUsernamesFound) > 0) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, 'Users [' . implode(',', $blacklistedUsernamesFound) . '] are blacklisted and should not be active.');
     }
     return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, 0, '');
 }
 /**
  * Get the test result for a failed operation result
  * @param $operationResult
  * @return tx_caretaker_TestResult
  */
 protected function getFailedOperationResultTestResult($operationResult)
 {
     return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, 'Operation execution failed: ' . $operationResult->getValue());
 }
コード例 #12
0
 /**
  * Get the current Test Result from Cache
  *
  * @see caretaker/trunk/classes/nodes/tx_caretaker_AbstractNode#getTestResult()
  * @return tx_caretaker_TestResult
  */
 public function getTestResult()
 {
     if ($this->getHidden()) {
         $result = tx_caretaker_TestResult::undefined('Node is disabled');
         return $result;
     }
     $test_result_repository = tx_caretaker_TestResultRepository::getInstance();
     $result = $test_result_repository->getLatestByNode($this);
     return $result;
 }
 public function runTest()
 {
     $extensionKey = $this->getConfigValue('extension_key');
     $requirementMode = $this->getConfigValue('requirement_mode');
     $minVersion = $this->getConfigValue('min_version');
     $maxVersion = $this->getConfigValue('max_version');
     if (!$extensionKey) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0, 'Cannot execute extension test without extension key');
     }
     $operation = array('GetExtensionVersion', array('extensionKey' => $extensionKey));
     $operations = array($operation);
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $results = $commandResult->getOperationResults();
     $operationResult = $results[0];
     if ($operationResult->isSuccessful()) {
         $extensionVersion = $operationResult->getValue();
     } else {
         $extensionVersion = FALSE;
     }
     $checkResult = $this->checkVersionForRequirementAndVersionRange($extensionVersion, $requirementMode, $minVersion, $maxVersion);
     if ($checkResult) {
         $message = 'Extension "' . $extensionKey . '" version ' . $extensionVersion . ' is ' . ($extensionVersion === false ? 'not ' : '') . 'installed';
         $testResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, 0, $message);
     } else {
         $message = 'Extension "' . $extensionKey . '" version ' . $extensionVersion . ' is ' . ($extensionVersion === false ? 'not ' : '') . 'installed, but ';
         if ($minVersion) {
             $message .= ' >= ' . $minVersion;
         }
         if ($maxVersion) {
             $message .= ' <= ' . $maxVersion;
         }
         $message .= ' expected';
         $testResult = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, $message);
     }
     return $testResult;
 }
 public function runTest()
 {
     $checkConfVars = explode(chr(10), $this->getConfigValue('checkConfVars'));
     $operations = array();
     foreach ($checkConfVars as $checkConfVar) {
         $checkConfVar = trim($checkConfVar);
         // ignore empty and comment lines
         if ($checkConfVar == '' || strpos($checkConfVar, '#') === 0 || strpos($checkConfVar, '//') === 0) {
             continue;
         }
         // detect comparison Opertor by regex
         $matches = array();
         preg_match('/([a-zA-Z0-9\\|_]+)[\\s]*([\\=\\!\\<\\>]{1,2})[\\s]*(.*)/', $checkConfVar, $matches);
         if ($matches[1] && $matches[2] && isset($matches[3])) {
             $path = trim($matches[1]);
             $operator = trim($matches[2]);
             $value = trim($matches[3]);
             // numeric comparison
             if (is_numeric($value) && intval($value) == $value) {
                 $value = intval($value);
             }
             if ($path && $operator) {
                 $operations[] = array('MatchPredefinedVariable', array('key' => 'GLOBALS|TYPO3_CONF_VARS|' . $path, 'usingRegexp' => false, 'match' => $value, 'comparisonOperator' => $operator));
             }
         } else {
             if (strpos($checkConfVar, ':regex:') > 0) {
                 list($path, $value) = explode(':regex:', $checkConfVar);
                 $path = trim($path);
                 $value = trim($value);
                 $regex = false;
                 if ($path && $value) {
                     $operations[] = array('MatchPredefinedVariable', array('key' => 'GLOBALS|TYPO3_CONF_VARS|' . $path, 'usingRegexp' => true, 'match' => $value, 'comparisonOperator' => false));
                 }
             }
         }
     }
     if (count($operations) == 0) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_warning, 0, 'No conditions found');
     }
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $results = $commandResult->getOperationResults();
     $sucess = array();
     $failures = array();
     foreach ($results as $key => $operationResult) {
         if ($operationResult->isSuccessful()) {
             if ($operations[$key][1]['usingRegexp'] == true) {
                 $sucess[] = 'Variable-Path ' . $operations[$key][1]['key'] . ' matched the regular expression ' . $operations[$key][1]['match'];
             } else {
                 $sucess[] = 'Variable-Path ' . $operations[$key][1]['key'] . ' matched the expectation ' . $operations[$key][1]['comparisonOperator'] . ' "' . $operations[$key][1]['match'] . '"';
             }
         } else {
             if ($operations[$key][1]['usingRegexp'] == true) {
                 $failures[] = 'Variable-Path ' . $operations[$key][1]['key'] . ' did not match the regular expression ' . $operations[$key][1]['match'];
             } else {
                 $failures[] = 'Variable-Path ' . $operations[$key][1]['key'] . ' did not match the expectation ' . $operations[$key][1]['comparisonOperator'] . ' "' . $operations[$key][1]['match'] . '"';
             }
         }
     }
     $msg_failures = '';
     $msg_success = '';
     if (count($sucess)) {
         $msg_success .= chr(10) . 'Matched Conditions: ' . chr(10) . implode(chr(10), $sucess);
     }
     $resultMatch = $this->getConfigValue('resultMatch');
     $resultNoMatch = $this->getConfigValue('resultNoMatch');
     if ($resultMatch == NULL) {
         $resultMatch = tx_caretaker_Constants::state_error;
     }
     if ($resultNoMatch == NULL) {
         $resultNoMatch = tx_caretaker_Constants::state_ok;
     }
     if (count($failures)) {
         $msg_failures .= chr(10) . 'Not Matched Conditions: ' . chr(10) . implode(chr(10), $failures);
         return tx_caretaker_TestResult::create(intval($resultNoMatch), 0, $msg_failures . chr(10) . $msg_success);
     } else {
         return tx_caretaker_TestResult::create(intval($resultMatch), 0, $msg_success);
     }
 }
 public function runTest()
 {
     $blacklistedPasswords = explode(chr(10), $this->getConfigValue('blacklist'));
     $checkForDuplicatePasswords = $this->getConfigValue('check_duplicate_passwords');
     $operations = array();
     $operations[] = array('GetExtensionVersion', array('extensionKey' => 'saltedpasswords'));
     $commandResult = $this->executeRemoteOperations($operations);
     $results = $commandResult->getOperationResults();
     $operationResult = $results[0];
     if ($operationResult->isSuccessful()) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0, 'FindBlacklistedBePassword is not supported if EXT:saltedpasswords is installed on instance.');
     }
     $operations = array();
     foreach ($blacklistedPasswords as $password) {
         $password = trim($password);
         if (strlen($password)) {
             $operations[] = array('GetRecords', array('table' => 'be_users', 'field' => 'password', 'value' => md5($password), 'checkEnableFields' => TRUE));
         }
     }
     $commandResult = $this->executeRemoteOperations($operations);
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     $careless_users = array();
     $results = $commandResult->getOperationResults();
     foreach ($results as $operationResult) {
         if ($operationResult->isSuccessful()) {
             $users = $operationResult->getValue();
             if ($users !== FALSE) {
                 foreach ($users as $user) {
                     $careless_users[] = $user;
                 }
             }
         } else {
             return $this->getFailedOperationResultTestResult($operationResult);
         }
     }
     if ($checkForDuplicatePasswords) {
         // clean the preceding operations
         unset($operations);
         $operations = array();
         // Will check whether "password" is IN (subselect or comma separated list)
         $sql_fields = array('password' => array('SELECT password FROM be_users WHERE disable = 0 AND deleted = 0 GROUP BY password HAVING COUNT(*) > 1'));
         $operations[] = array('GetRecords', array('table' => 'be_users', 'field' => array_keys($sql_fields), 'value' => $sql_fields, 'checkEnableFields' => TRUE));
         $commandResult = $this->executeRemoteOperations($operations);
         if (!$this->isCommandResultSuccessful($commandResult)) {
             return $this->getFailedCommandResultTestResult($commandResult);
         }
         $results = $commandResult->getOperationResults();
         foreach ($results as $operationResult) {
             if ($operationResult->isSuccessful()) {
                 $users = $operationResult->getValue();
                 if ($users !== FALSE) {
                     foreach ($users as $user) {
                         $careless_users[] = $user;
                     }
                 }
             } else {
                 return $this->getFailedOperationResultTestResult($operationResult);
             }
         }
     }
     // Check if multiple users have the same password, if so then add them to $careless_users array.
     if (count($careless_users) > 0) {
         $submessages = array();
         foreach ($careless_users as $user) {
             $submessages[] = new tx_caretaker_ResultMessage($user['username']);
         }
         //			// Remove dublets
         $submessages = array_unique($submessages, SORT_REGULAR);
         asort($submessages);
         if ($checkForDuplicatePasswords) {
             $text_reply = 'The following accounts have blacklisted or duplicate passwords: ';
         } else {
             $text_reply = 'The following accounts have blacklisted passwords: ';
         }
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, $text_reply, $submessages);
     }
     return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, 0, '');
 }
コード例 #16
0
 /**
  *
  * @param tx_caretaker_TestServiceInterface $testService
  * @param tx_caretaker_TestNode $node
  * @param tx_caretaker_NodeResult $latestTestResult
  * @param array $options
  * @return tx_caretaker_NodeResult
  */
 protected function executeTestServiceRun($testService, $node, $latestTestResult, $options)
 {
     // check wether the test can be executed
     if ($testService && $testService->isExecutable()) {
         try {
             $result = $testService->runTest();
         } catch (Exception $e) {
             $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, '{LLL:EXT:caretaker/locallang_fe.xml:service_exception}' . $e->getMessage);
         }
         // retry if not ok and retrying is enabled
         if ($result->getState() != 0 && $node->getTestRetry() > 0) {
             $round = 0;
             while ($round < $node->getTestRetry() && $result->getState() != 0) {
                 // TODO make sleep time between retry configurable
                 sleep(1);
                 try {
                     $result = $testService->runTest();
                 } catch (Exception $e) {
                     $result = tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, '{LLL:EXT:caretaker/locallang_fe.xml:service_exception}' . $e->getMessage);
                 }
                 $round++;
             }
             $result->addSubMessage(new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:retry_info', array('number' => $round)));
         }
         // save to repository after reading the previous result
         $resultRepository = tx_caretaker_TestResultRepository::getInstance();
         $resultRepository->saveTestResultForNode($node, $result);
         // trigger notification
         $node->notify('updatedTestResult', $result, $latestTestResult);
         return $result;
     } else {
         $result = tx_caretaker_TestResult::undefined();
         $result->addSubMessage(new tx_caretaker_ResultMessage('test service was not executable this time so the cached result is used'));
         $node->notify('cachedTestResult', $result, $latestTestResult);
         return $latestTestResult;
     }
 }
 /**
  * @return tx_caretaker_TestResult
  */
 public function runTest()
 {
     // fetch config values
     $paths = $this->getConfigValue('cppaths');
     $inverse = $this->getConfigValue('cpinverse');
     $type = $this->getConfigValue('cptype');
     $time = intval($this->getConfigValue('cptime'));
     $fileAgeShouldBe = $this->getConfigValue('cptimeflag');
     // catch required fields
     if (!$paths) {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_undefined, 0, 'Cannot test without path.');
     }
     // prepare tests
     $paths = explode(chr(10), $paths);
     foreach ($paths as $path) {
         $operations[] = array('CheckPathExists', $path);
     }
     // run
     $commandResult = $this->executeRemoteOperations($operations);
     // catch errors
     if (!$this->isCommandResultSuccessful($commandResult)) {
         return $this->getFailedCommandResultTestResult($commandResult);
     }
     // process resultset
     $resultset = $commandResult->getOperationResults();
     foreach ($resultset as $result) {
         $resValue = $result->getValue();
         if (!$result->isSuccessful() && !$inverse) {
             $msg[] = $resValue['path'] . ' does not exist';
             $resultState = tx_caretaker_Constants::state_error;
         } else {
             if ($result->isSuccessful() && $inverse) {
                 $msg[] = $resValue['path'] . ' does exist';
                 $resultState = tx_caretaker_Constants::state_error;
             } else {
                 if ($result->isSuccessful() && $type && $type != $resValue['type']) {
                     $msg[] = $resValue['path'] . ' exists, but is a ' . $resValue['type'];
                     $resultState = tx_caretaker_Constants::state_error;
                 }
             }
         }
         if ($fileAgeShouldBe != '' && $time != 0 && $result->isSuccessful()) {
             if ($resValue['time'] == 0) {
                 $msg[] = 'Seems like the caretaker_instance can\'t report the file modification time.';
                 $resultState = max($resultState, tx_caretaker_Constants::state_warning);
             } else {
                 $fileIsYounger = time() - $resValue['time'] < $time;
                 if ($fileAgeShouldBe == 'younger' && $fileIsYounger || $fileAgeShouldBe == 'older' && !$fileIsYounger) {
                     $resultState = tx_caretaker_Constants::state_error;
                     $msg[] = $resValue['path'] . ' is ' . ($fileIsYounger ? 'younger' : 'older') . ' than ' . $time . ' seconds';
                 } else {
                     if ($inverse) {
                         // if we do time checks, the file exists, but it should not ($inverse), it's only a warning
                         $resultState = tx_caretaker_Constants::state_warning;
                     }
                 }
             }
         }
     }
     if (is_array($msg)) {
         return tx_caretaker_TestResult::create($resultState, 0, implode(chr(10), $msg));
     } else {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, 1);
     }
 }
コード例 #18
0
 /**
  * @return tx_caretaker_TestResult
  */
 public function runTest()
 {
     $time_warning = $this->getTimeWarning();
     $time_error = $this->getTimeError();
     $command = $this->buildPingCommand();
     if ($command) {
         list($returnCode, $message, $time) = $this->executeSystemCommand($command);
         if ($returnCode === 0) {
             if ($time_error && $time > $time_error) {
                 return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, $time, 'LLL:EXT:caretaker/locallang_fe.xml:ping_info');
             }
             if ($time_warning && $time > $time_warning) {
                 return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_warning, $time, 'LLL:EXT:caretaker/locallang_fe.xml:ping_info');
             }
             return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_ok, $time, 'LLL:EXT:caretaker/locallang_fe.xml:ping_info');
         } else {
             $message = new tx_caretaker_ResultMessage('LLL:EXT:caretaker/locallang_fe.xml:ping_error', array('command' => $command, 'message' => $message));
             return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, $time, $message);
         }
     } else {
         return tx_caretaker_TestResult::create(tx_caretaker_Constants::state_error, 0, 'LLL:EXT:caretaker/locallang_fe.xml:ping_no_command_template');
     }
 }
 /**
  * Notify the service about a test status
  *
  * @param string $event Event Identifier
  * @param tx_caretaker_AbstractNode $node
  * @param tx_caretaker_TestResult $result
  * @param tx_caretaker_TestResult $lastResult
  */
 public function addNotification($event, $node, $result = NULL, $lastResult = NULL)
 {
     // stop if event is not updatedTestResult of a TestNode
     if ($event != 'updatedTestResult' || is_a($node, 'tx_caretaker_TestNode') == false) {
         return;
     }
     // Check that the result is not equal to the previous one
     if ($lastResult && $result->getState() == $lastResult->getState()) {
         return;
     }
     // collect the recipients from the node rootline
     $recipientIds = array();
     if (count($this->mail_roles) > 0) {
         $contacts = array();
         foreach ($this->mail_roles as $role) {
             $contacts = array_merge($contacts, $node->getContacts($role));
         }
     } else {
         $contacts = $node->getContacts();
     }
     foreach ($contacts as $contact) {
         $address = $contact->getAddress();
         if (!$this->recipients_addresses[$address['uid']]) {
             $this->recipients_addresses[$address['uid']] = $address;
         }
         $recipientIds[] = $address['uid'];
     }
     $recipientIds = array_unique($recipientIds);
     // store the notifications for the recipients
     foreach ($recipientIds as $recipientId) {
         if (!isset($this->recipients_messages[$recipientId])) {
             $this->recipients_messages[$recipientId] = array('messages' => array(), 'num_undefined' => 0, 'num_ok' => 0, 'num_warning' => 0, 'num_error' => 0, 'num_ack' => 0, 'num_due' => 0);
         }
         switch ($result->getState()) {
             case tx_caretaker_Constants::state_undefined:
                 $this->recipients_messages[$recipientId]['num_undefined']++;
                 break;
             case tx_caretaker_Constants::state_ok:
                 $this->recipients_messages[$recipientId]['num_ok']++;
                 break;
             case tx_caretaker_Constants::state_warning:
                 $this->recipients_messages[$recipientId]['num_warning']++;
                 break;
             case tx_caretaker_Constants::state_error:
                 $this->recipients_messages[$recipientId]['num_error']++;
                 break;
             case tx_caretaker_Constants::state_ack:
                 $this->recipients_messages[$recipientId]['num_ack']++;
                 break;
             case tx_caretaker_Constants::state_due:
                 $this->recipients_messages[$recipientId]['num_due']++;
                 break;
         }
         array_unshift($this->recipients_messages[$recipientId]['messages'], '*' . ($lastResult ? $lastResult->getLocallizedStateInfo() . '->' : '') . $result->getLocallizedStateInfo() . ' ' . $node->getInstance()->getTitle() . ':' . $node->getTitle() . '* ' . $node->getCaretakerNodeId() . chr(10) . chr(10) . $result->getLocallizedInfotext() . chr(10) . str_replace('###', $node->getCaretakerNodeId(), $this->mail_link) . chr(10));
     }
 }
コード例 #20
0
 /**
  * Save the Testresult for the given TestNode
  * @param tx_caretaker_TestNode $test
  * @param tx_caretaker_TestResult $testResult
  */
 function saveTestResultForNode(tx_caretaker_TestNode $test, $testResult)
 {
     $values = array('test_uid' => $test->getUid(), 'instance_uid' => $test->getInstance()->getUid(), 'tstamp' => $testResult->getTimestamp(), 'result_status' => $testResult->getState(), 'result_value' => $testResult->getValue(), 'result_msg' => $testResult->getMessage()->getText(), 'result_values' => serialize($testResult->getMessage()->getValues()), 'result_submessages' => serialize($testResult->getSubMessages()));
     // store log of results
     $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_caretaker_testresult', $values);
     // store last results for fast access
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tx_caretaker_lasttestresult', 'test_uid = ' . $test->getUid() . ' AND instance_uid = ' . $test->getInstance()->getUid(), '', '', 1);
     if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_caretaker_lasttestresult', 'uid = ' . $row['uid'], $values);
     } else {
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_caretaker_lasttestresult', $values);
     }
 }