loadById() public static method

public static loadById ( integer $id ) : DBDNSZone
$id integer
return DBDNSZone
Exemplo n.º 1
0
 public function DNSZoneRecordAdd($ZoneName, $Type, $TTL, $Name, $Value, $Priority = 0, $Weight = 0, $Port = 0)
 {
     $this->restrictAccess(Acl::RESOURCE_DNS_ZONES);
     if (!Scalr::config('scalr.dns.global.enabled')) {
         throw new Exception("DNS functionality is not enabled. Please contact your Scalr administrator.");
     }
     $zoneinfo = $this->DB->GetRow("SELECT id, env_id FROM dns_zones WHERE zone_name=? LIMIT 1", array($ZoneName));
     if (!$zoneinfo || $zoneinfo['env_id'] != $this->Environment->id) {
         throw new Exception(sprintf("Zone '%s' not found in database", $ZoneName));
     }
     if (!in_array($Type, array("A", "MX", "CNAME", "NS", "TXT", "SRV"))) {
         throw new Exception(sprintf("Unknown record type '%s'", $Type));
     }
     $record = array('name' => $Name, 'value' => $Value, 'type' => $Type, 'ttl' => $TTL, 'priority' => $Priority, 'weight' => $Weight, 'port' => $Port);
     $recordsValidation = Scalr_Net_Dns_Zone::validateRecords(array($record));
     if ($recordsValidation === true) {
         $DBDNSZone = DBDNSZone::loadById($zoneinfo['id']);
         $records = $DBDNSZone->getRecords(false);
         array_push($records, $record);
         $DBDNSZone->setRecords($records);
         $DBDNSZone->save(false);
     } else {
         throw new Exception($recordsValidation[0]);
     }
     $response = $this->CreateInitialResponse();
     $response->Result = 1;
     return $response;
 }
Exemplo n.º 2
0
 /**
  * @return array
  * @param integer $farm_id
  */
 public static function loadByFarmId($farm_id)
 {
     $db = \Scalr::getDb();
     $zones = $db->GetAll("SELECT id FROM dns_zones WHERE farm_id=?", array($farm_id));
     $retval = array();
     foreach ($zones as $zone) {
         $retval[] = DBDNSZone::loadById($zone['id']);
     }
     return $retval;
 }
 public function StartThread($zone)
 {
     $DBDNSZone = DBDNSZone::loadById($zone['id']);
     $remoteBind = new Scalr_Net_Dns_Bind_RemoteBind();
     $transport = new Scalr_Net_Dns_Bind_Transports_LocalFs('/usr/sbin/rndc', '/var/named/etc/namedb/client_zones');
     $remoteBind->setTransport($transport);
     switch ($DBDNSZone->status) {
         case DNS_ZONE_STATUS::PENDING_DELETE:
         case DNS_ZONE_STATUS::INACTIVE:
             $remoteBind->removeZoneDbFile($DBDNSZone->zoneName);
             $DBDNSZone->isZoneConfigModified = 1;
             break;
         case DNS_ZONE_STATUS::PENDING_CREATE:
         case DNS_ZONE_STATUS::PENDING_UPDATE:
             $remoteBind->addZoneDbFile($DBDNSZone->zoneName, $DBDNSZone->getContents());
             if ($DBDNSZone->status == DNS_ZONE_STATUS::PENDING_CREATE) {
                 $DBDNSZone->isZoneConfigModified = 1;
             }
             $DBDNSZone->status = DNS_ZONE_STATUS::ACTIVE;
             break;
     }
     $DBDNSZone->save();
 }
Exemplo n.º 4
0
 public function DNSZoneRecordAdd($ZoneName, $Type, $TTL, $Name, $Value, $Priority = 0, $Weight = 0, $Port = 0)
 {
     $zoneinfo = $this->DB->GetRow("SELECT id, env_id FROM dns_zones WHERE zone_name=?", array($ZoneName));
     if (!$zoneinfo || $zoneinfo['env_id'] != $this->Environment->id) {
         throw new Exception(sprintf("Zone '%s' not found in database", $ZoneName));
     }
     if (!in_array($Type, array("A", "MX", "CNAME", "NS", "TXT", "SRV"))) {
         throw new Exception(sprintf("Unknown record type '%s'", $Type));
     }
     $record = array('name' => $Name, 'value' => $Value, 'type' => $Type, 'ttl' => $TTL, 'priority' => $Priority, 'weight' => $Weight, 'port' => $Port);
     $recordsValidation = Scalr_Net_Dns_Zone::validateRecords(array($record));
     if ($recordsValidation === true) {
         $DBDNSZone = DBDNSZone::loadById($zoneinfo['id']);
         $records = $DBDNSZone->getRecords(false);
         array_push($records, $record);
         $DBDNSZone->setRecords($records);
         $DBDNSZone->save(false);
     } else {
         throw new Exception($recordsValidation[0]);
     }
     $response = $this->CreateInitialResponse();
     $response->Result = 1;
     return $response;
 }
Exemplo n.º 5
0
 public function xRemoveZonesAction()
 {
     $this->request->defineParams(array('zones' => array('type' => 'json')));
     foreach ($this->getParam('zones') as $dd) {
         $zone = DBDNSZone::loadById($dd);
         if (!$this->user->getPermissions()->check($zone)) {
             continue;
         }
         $zone->status = DNS_ZONE_STATUS::PENDING_DELETE;
         $zone->save();
     }
     $this->response->success();
 }
Exemplo n.º 6
0
 public function xRemoveZonesAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_DNS_ZONES, Acl::PERM_DNS_ZONES_MANAGE);
     $this->request->defineParams(array('zones' => array('type' => 'json')));
     foreach ($this->getParam('zones') as $dd) {
         $zone = DBDNSZone::loadById($dd);
         if (!$this->user->getPermissions()->check($zone)) {
             continue;
         }
         $zone->status = DNS_ZONE_STATUS::PENDING_DELETE;
         $zone->save();
     }
     $this->response->success('DNS Zone(s) are scheduled to remove');
 }