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.

RecordLog.class.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. class RecordLog {
  3. private $record_prior;
  4. private $record_after;
  5. private $record_changed = false;
  6. public function log_prior($rid) {
  7. $this->record_prior = $this->getRecord($rid);
  8. }
  9. public function log_after($rid) {
  10. $this->record_after = $this->getRecord($rid);
  11. }
  12. private function getRecord($rid) {
  13. return get_record_from_id($rid);
  14. }
  15. public function has_changed(array $record) {
  16. // Arrays are assigned by copy.
  17. // Copy arrays to avoid side effects caused by unset().
  18. $record_copy = $record;
  19. $record_prior_copy = $this->record_prior;
  20. // Don't compare the 'change_date'
  21. unset($record_copy["change_date"]);
  22. unset($record_prior_copy["change_date"]);
  23. // PowerDNS only searches for lowercase records
  24. $record_copy['name'] = strtolower($record_copy['name']);
  25. $record_prior_copy['name'] = strtolower($record_prior_copy['name']);
  26. // Quotes are special for SPF and TXT
  27. $type = $record_prior_copy['type'];
  28. if ($type == "SPF" || $type == "TXT") {
  29. $record_prior_copy['content'] = trim($record_prior_copy['content'], '"');
  30. $record_copy['content'] = trim($record_copy['content'], '"');
  31. }
  32. // Make $record_copy and $record_prior_copy compatible
  33. $record_copy['id'] = $record_copy['rid'];
  34. $record_copy['domain_id'] = $record_copy['zid'];
  35. unset($record_copy['zid']);
  36. unset($record_copy['rid']);
  37. // Do the comparison
  38. $this->record_changed = ($record_copy != $record_prior_copy);
  39. return $this->record_changed;
  40. }
  41. public function write() {
  42. log_info(sprintf('client_ip:%s user:%s operation:edit_record'
  43. . ' old_record_type:%s old_record:%s old_content:%s old_ttl:%s old_priority:%s'
  44. . ' record_type:%s record:%s content:%s ttl:%s priority:%s',
  45. $_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
  46. $this->record_prior['type'], $this->record_prior['name'],
  47. $this->record_prior['content'], $this->record_prior['ttl'], $this->record_prior['prio'],
  48. $this->record_after['type'], $this->record_after['name'],
  49. $this->record_after['content'], $this->record_after['ttl'], $this->record_after['prio']));
  50. }
  51. }