You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

  1. <?php
  2. namespace OrpheusNET\Logchecker\Checks;
  3. use OrpheusNET\Logchecker\Util;
  4. use Symfony\Component\Process\Process;
  5. class Checksum
  6. {
  7. /**
  8. * Will return the checksum status of the given logfile,
  9. * see ChecksumStates.php for the possible values.
  10. */
  11. public static function validate(string $logPath, $EAC)
  12. {
  13. if ($EAC) {
  14. $command = 'eac_logchecker';
  15. $noChecksumResult = 'Log entry has no checksum!';
  16. $invalidResult = 'Log entry was modified, checksum incorrect!';
  17. $goodResult = 'Log entry is fine!';
  18. } else {
  19. $command = 'xld_logchecker';
  20. $noChecksumResult = 'Not a logfile';
  21. $invalidResult = 'Malformed';
  22. $goodResult = 'OK';
  23. }
  24. if (static::logcheckerExists($command)) {
  25. $process = new Process([$command, $logPath]);
  26. $process->run();
  27. $output = $process->getOutput();
  28. if (strpos($output, $goodResult) === false) {
  29. if ($output == null) {
  30. return ChecksumStates::CHECKSUM_MISSING;
  31. } elseif (strpos($output, $noChecksumResult) !== false) {
  32. return ChecksumStates::CHECKSUM_MISSING;
  33. } elseif (strpos($output, $invalidResult) !== false) {
  34. return ChecksumStates::CHECKSUM_INVALID;
  35. }
  36. }
  37. }
  38. return ChecksumStates::CHECKSUM_OK;
  39. }
  40. public static function logcheckerExists($EAC)
  41. {
  42. if ($EAC) {
  43. $command = 'eac_logchecker';
  44. } else {
  45. $command = 'xld_logchecker';
  46. }
  47. return Util::commandExists($command);
  48. }
  49. }