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.

DnsRecordsBusiness.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Business;
  3. use Carbon\Carbon;
  4. use Luticate\Utils\LuBusiness;
  5. use App\Http\DataAccess\DnsRecordsDataAccess;
  6. use App\Http\DBO\DnsRecordsDbo;
  7. class DnsRecordsBusiness extends LuBusiness {
  8. const RECORD_TYPES = array("A", "AAAA", "CNAME", "HINFO", "MX", "NAPTR", "NS", "PTR",
  9. "SOA", "SPF", "SRV", "SSHFP", "TXT", "RP");
  10. protected static function getDataAccess()
  11. {
  12. return new DnsRecordsDataAccess();
  13. }
  14. public static function checkRecord(DnsRecordsDbo $record)
  15. {
  16. DnsDomainsBusiness::getById($record->getDomainId());
  17. if (is_null($record->getName()) || !is_string($record->getName())) {
  18. self::badInput("Name must be an string");
  19. }
  20. if (is_null($record->getContent()) || !is_string($record->getContent())) {
  21. self::badInput("Content must be an string");
  22. }
  23. if (!in_array($record->getType(), self::RECORD_TYPES)) {
  24. self::badInput("Type be must be one of " . join(",", self::RECORD_TYPES));
  25. }
  26. if (!is_bool($record->getDisabled())) {
  27. self::badInput("Disabled must be a boolean");
  28. }
  29. if (!is_bool($record->getAuth())) {
  30. self::badInput("Auth must be a boolean");
  31. }
  32. if (!is_null($record->getOrdername()) && !is_string($record->getOrdername())) {
  33. self::badInput("Ordername must be an string or null");
  34. }
  35. if (!is_int($record->getPrio())) {
  36. self::badInput("Prio must be an int");
  37. }
  38. if (!is_int($record->getTtl())) {
  39. self::badInput("Ttl must be a int");
  40. }
  41. $record->setChangeDate(Carbon::now()->timestamp);
  42. }
  43. public static function getAll($domain_id, $page = 0, $perPage = PHP_INT_MAX, $query = "")
  44. {
  45. return DnsRecordsDataAccess::getAll($domain_id, $query, $page, $perPage);
  46. }
  47. public static function add(DnsRecordsDbo $record)
  48. {
  49. self::checkRecord($record);
  50. return DnsRecordsDataAccess::addId($record);
  51. }
  52. }