예제 #1
0
 /**
  * Adds the new record
  */
 function add($domain_id, $record_type, $new_array, $operation = 'insert')
 {
     global $fmdb, $__FM_CONFIG, $fm_dns_zones;
     $domain_name = displayFriendlyDomainName(getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name'));
     $log_message = "Added a record with the following details:\nDomain: {$domain_name}\nType: {$record_type}\n";
     $table = $record_type == 'SOA' ? 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'soa' : 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records';
     /** Check if record already exists */
     if ($record_type != 'SOA') {
         $query = "SELECT * FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}records WHERE domain_id={$domain_id} AND record_name='{$new_array['record_name']}'\n\t\t\t\t\tAND record_value='{$new_array['record_value']}' AND record_type='{$record_type}' AND record_status != 'deleted'";
         $result = $fmdb->get_results($query);
         if ($fmdb->num_rows) {
             return;
         }
     }
     $new_array['account_id'] = $_SESSION['user']['account_id'];
     /** Replacing? */
     if ($operation == 'replace' && $record_type == 'PTR') {
         $query = "UPDATE fm_{$__FM_CONFIG['fmDNS']['prefix']}records SET record_status='deleted' WHERE account_id='{$_SESSION['user']['account_id']}'\n\t\t\t\tAND domain_id={$domain_id} AND record_name='{$new_array['record_name']}' AND record_status!='deleted' LIMIT 1";
         $fmdb->query($query);
     }
     $sql_insert = "INSERT INTO `{$table}`";
     $sql_fields = '(';
     if ($record_type != 'SOA' && $record_type) {
         $sql_fields .= 'domain_id,record_type,';
         $sql_values .= "{$domain_id},'{$record_type}',";
     }
     /** Process default integers */
     if (array_key_exists('record_priority', $new_array) && !is_numeric($new_array['record_priority'])) {
         $new_array['record_priority'] = 0;
     }
     if (array_key_exists('record_weight', $new_array) && !is_numeric($new_array['record_weight'])) {
         $new_array['record_weight'] = 0;
     }
     if (array_key_exists('record_port', $new_array) && !is_numeric($new_array['record_port'])) {
         $new_array['record_port'] = 0;
     }
     if (array_key_exists('record_ttl', $new_array) && !is_numeric($new_array['record_ttl'])) {
         $new_array['record_ttl'] = null;
     }
     foreach ($new_array as $key => $data) {
         if ($key == 'PTR') {
             continue;
         }
         if ($key == 'record_type') {
             continue;
         }
         if ($record_type == 'SOA' && in_array($key, array('record_type', 'record_comment'))) {
             continue;
         }
         $sql_fields .= $key . ',';
         $sql_values .= "'" . mysql_real_escape_string($data) . "',";
         if ($key != 'account_id') {
             $log_message .= $data ? formatLogKeyData('record_', $key, $data) : null;
         }
         if ($key == 'soa_default' && $data == 'yes') {
             $query = "UPDATE `{$table}` SET {$key} = 'no' WHERE `account_id`='{$_SESSION['user']['account_id']}'";
             $result = $fmdb->query($query);
         }
     }
     $sql_fields = rtrim($sql_fields, ',') . ')';
     $sql_values = rtrim($sql_values, ',');
     $query = "{$sql_insert} {$sql_fields} VALUES ({$sql_values})";
     $result = $fmdb->query($query);
     if (!$fmdb->result) {
         return false;
     }
     /** Update domain with SOA ID */
     if ($record_type == 'SOA') {
         $this->assignSOA($fmdb->insert_id, $domain_id);
     }
     if (!$fm_dns_zones) {
         include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_zones.php';
     }
     /** Update the SOA serial number */
     foreach ($fm_dns_zones->getZoneTemplateChildren($domain_id) as $child_id) {
         $domain_id = getParentDomainID($child_id);
         $soa_count = getSOACount($domain_id);
         $ns_count = getNSCount($domain_id);
         if (reloadAllowed($domain_id) && $soa_count && $ns_count) {
             $this->updateSOAReload($child_id, 'yes');
         }
         if (in_array($record_type, array('SOA', 'NS')) && $soa_count && $ns_count) {
             /** Update all associated DNS servers */
             setBuildUpdateConfigFlag(getZoneServers($child_id), 'yes', 'build');
         }
     }
     addLogEntry($log_message);
     return true;
 }
예제 #2
0
 /**
  * Deletes the selected zone and all associated records
  */
 function delete($domain_id)
 {
     global $fmdb, $__FM_CONFIG;
     /** Does the domain_id exist for this account? */
     basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $domain_id, 'domain_', 'domain_id', 'active');
     if ($fmdb->num_rows) {
         $domain_result = $fmdb->last_result[0];
         unset($fmdb->num_rows);
         /** Delete all associated configs */
         basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', $domain_id, 'cfg_', 'domain_id');
         if ($fmdb->num_rows) {
             if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', $domain_id, 'cfg_', 'deleted', 'domain_id') === false) {
                 return __('The associated configs for this zone could not be deleted because a database error occurred.');
             }
             unset($fmdb->num_rows);
         }
         /** Delete all associated records */
         basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', $domain_id, 'record_', 'domain_id');
         if ($fmdb->num_rows) {
             if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', $domain_id, 'record_', 'deleted', 'domain_id') === false) {
                 return __('The associated records for this zone could not be deleted because a database error occurred.');
             }
             unset($fmdb->num_rows);
         }
         basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records_skipped', $domain_id, 'record_', 'domain_id');
         if ($fmdb->num_rows) {
             if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records_skipped', $domain_id, 'record_', 'deleted', 'domain_id') === false) {
                 return __('The associated records for this zone could not be deleted because a database error occurred.');
             }
             unset($fmdb->num_rows);
         }
         /** Delete all associated SOA */
         if (!$domain_result->domain_clone_domain_id && $domain_result->soa_id) {
             basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'soa', $domain_result->soa_id, 'soa_', 'soa_id', "AND soa_template='no'");
             if ($fmdb->num_rows) {
                 if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'soa', $domain_result->soa_id, 'soa_', 'deleted', 'soa_id') === false) {
                     return __('The SOA for this zone could not be deleted because a database error occurred.');
                 }
                 unset($fmdb->num_rows);
             }
         }
         /** Delete associated records from fm_{$__FM_CONFIG['fmDNS']['prefix']}track_builds */
         if (basicDelete('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'track_builds', $domain_id, 'domain_id', false) === false) {
             return sprintf(__('The zone could not be removed from the %s table because a database error occurred.'), 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'track_builds');
         }
         /** Force buildconf for all associated DNS servers */
         setBuildUpdateConfigFlag(getZoneServers($domain_id, array('masters', 'slaves')), 'yes', 'build');
         /** Delete cloned zones */
         basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $domain_id, 'domain_', 'domain_clone_domain_id');
         if ($fmdb->num_rows) {
             unset($fmdb->num_rows);
             /** Delete cloned zone records first */
             basicGetList('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_id', 'domain_', "AND domain_clone_domain_id={$domain_id}");
             if ($fmdb->num_rows) {
                 $clone_domain_result = $fmdb->last_result;
                 $clone_domain_num_rows = $fmdb->num_rows;
                 for ($i = 0; $i < $clone_domain_num_rows; $i++) {
                     if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', $clone_domain_result[$i]->domain_id, 'record_', 'deleted', 'domain_id') === false) {
                         return __('The associated records for the cloned zones could not be deleted because a database error occurred.');
                     }
                 }
                 unset($fmdb->num_rows);
             }
             if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $domain_id, 'domain_', 'deleted', 'domain_clone_domain_id') === false) {
                 return __('The associated clones for this zone could not be deleted because a database error occurred.');
             }
         }
         /** Delete zone */
         $tmp_name = displayFriendlyDomainName(getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name'));
         if (updateStatus('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $domain_id, 'domain_', 'deleted', 'domain_id') === false) {
             return __('This zone could not be deleted because a database error occurred.');
         }
         addLogEntry("Deleted zone '{$tmp_name}' and all associated records.");
         return true;
     }
     return __('This zone does not exist.');
 }
예제 #3
0
 /**
  * Sets SOA serials and reload flags per domain_id
  *
  * @since 2.1
  * @package facileManager
  * @subpackage fmDNS
  *
  * @param id $domain_id domain_id to set
  * @param id $record_type Record type to check
  * @param id $action Add or update
  * @return null
  */
 function processSOAUpdates($domain_id, $record_type, $action)
 {
     global $fm_dns_zones;
     if (!$fm_dns_zones) {
         include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_zones.php';
     }
     foreach ($fm_dns_zones->getZoneTemplateChildren($domain_id) as $child_id) {
         $domain_id = getParentDomainID($child_id);
         $soa_count = getSOACount($domain_id);
         $ns_count = getNSCount($domain_id);
         if (reloadAllowed($domain_id) && $soa_count && $ns_count) {
             $this->updateSOAReload($child_id, 'yes');
         }
         if ($action == 'add') {
             if (in_array($record_type, array('SOA', 'NS')) && $soa_count && $ns_count) {
                 /** Update all associated DNS servers */
                 setBuildUpdateConfigFlag(getZoneServers($child_id), 'yes', 'build');
             }
         }
     }
 }