$parent_domain_ids = getZoneParentID($domain_id);
$zone_access_allowed = zoneAccessIsAllowed($parent_domain_ids);
if (!in_array($record_type, $supported_record_types)) {
    $record_type = $default_record_type;
}
$avail_types = buildRecordTypes($record_type, $parent_domain_ids, $map, $supported_record_types, $search_query);
$response = $form_data = $action = null;
if (reloadZone($domain_id)) {
    if (reloadAllowed($domain_id) && currentUserCan('reload_zones', $_SESSION['module']) && $zone_access_allowed) {
        $response = '** You need to <a href="" class="zone_reload" id="' . $domain_id . '">reload</a> this zone **';
    }
}
if (!getNSCount($domain_id)) {
    $response = sprintf('** %s **', __('One more more NS records still needs to be created for this zone'));
}
if (!getSOACount($domain_id)) {
    $response = sprintf('** %s **', __('The SOA record still needs to be created for this zone'));
}
$body = '<div id="body_container" class="fm-noscroll">' . "\n";
if (!empty($response)) {
    $body .= '<div id="response"><p>' . $response . '</p></div>';
}
$body .= sprintf('<h2>%s</h2>
	<div id="pagination_container" class="submenus record-types">
	<div>
	<div class="stretch"></div>
	%s
	</div>
</div>', __('Records'), $avail_types);
if (currentUserCan('manage_records', $_SESSION['module']) && $zone_access_allowed) {
    $form = '<form method="POST" action="zone-records-validate.php">
    /**
     * Imports records from a zone file and presents a confirmation
     */
    function zoneImportWizard()
    {
        global $__FM_CONFIG, $fm_name;
        if (!currentUserCan('manage_records', $_SESSION['module'])) {
            return $this->unAuth('zone');
        }
        if (!zoneAccessIsAllowed(array($_POST['domain_id']))) {
            return $this->unAuth('zone');
        }
        $raw_contents = file_get_contents($_FILES['import-file']['tmp_name']);
        /** Strip commented lines */
        $clean_contents = preg_replace('/^;.*\\n?/m', '', $raw_contents);
        /** Strip blank lines */
        $clean_contents = preg_replace('/^\\n?/m', '', $clean_contents);
        /** Strip $GENERATE lines */
        $clean_contents = preg_replace('/^\\$GENERATE.*\\n?/m', '', $clean_contents, -1, $generate_count);
        /** Strip $ORIGIN lines */
        $clean_contents = preg_replace('/^\\$ORIGIN.*\\n?/m', '', $clean_contents, -1, $origin_count);
        /** Handle unsupported message */
        if ($generate_count || $origin_count) {
            $unsupported[] = sprintf('<h4>%s:</h4>', __('Unsupported Entries'));
            $unsupported[] = '<p class="soa_import">' . sprintf(__('%s currently does not support importing $GENERATE and $ORIGIN entries which were found in your zone file.'), $fm_name) . '</p>';
            $unsupported = implode("\n", $unsupported);
        } else {
            $unsupported = null;
        }
        $domain_name = getNameFromID($_POST['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name');
        $domain_map = getNameFromID($_POST['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_mapping');
        $count = 1;
        /** Detect SOA */
        if (!getSOACount($_POST['domain_id']) && strpos($clean_contents, ' SOA ') !== false && (in_array('SOA', $__FM_CONFIG['records']['require_zone_rights']) && currentUserCan('manage_zones', $_SESSION['module']))) {
            $raw_soa = preg_replace("/SOA(.+?)\\)/esim", "str_replace(PHP_EOL, ' ', '\\1')", $clean_contents);
            preg_match("/SOA(.+?)\\)/esim", $clean_contents, $raw_soa);
            preg_match("/TTL(.+?)\$/esim", $clean_contents, $raw_ttl);
            if (is_array($raw_ttl)) {
                $soa_array['soa_ttl'] = trim(preg_replace('/;(.+?)+/', '', $raw_ttl[1]));
            }
            if (is_array($raw_soa)) {
                $raw_soa = preg_replace('/;(.+?)+/', '', $raw_soa[1]);
                $soa = str_replace(array("\n", "\t", '(', ')', '  '), ' ', preg_replace('/\\s\\s+/', ' ', $raw_soa));
                $soa = str_replace(' ', '|', trim($soa));
                $soa_fields = explode('|', str_replace('||', '|', $soa));
                list($soa_array['soa_master_server'], $soa_array['soa_email_address'], $tmp_serial, $soa_array['soa_refresh'], $soa_array['soa_retry'], $soa_array['soa_expire'], $tmp_neg_cache) = $soa_fields;
                if (strpos($soa_array['soa_master_server'], $domain_name) !== false) {
                    $soa_array['soa_master_server'] = str_replace('.' . trimFullStop($domain_name) . '.', '', $soa_array['soa_master_server']);
                    $soa_array['soa_email_address'] = str_replace('.' . trimFullStop($domain_name) . '.', '', $soa_array['soa_email_address']);
                    $soa_array['soa_append'] = 'yes';
                } else {
                    $soa_array['soa_append'] = 'no';
                }
            }
            $soa_row = '<h4>SOA:</h4><p class="soa_import">' . trimFullStop($domain_name) . '. IN SOA ' . $soa_array['soa_master_server'];
            if ($soa_array['soa_append'] == 'yes') {
                $soa_row .= '.' . trimFullStop($domain_name) . '.';
            }
            $soa_row .= ' ' . $soa_array['soa_email_address'];
            if ($soa_array['soa_append'] == 'yes') {
                $soa_row .= '.' . trimFullStop($domain_name) . '.';
            }
            $soa_row .= ' ( &lt;autogen_serial&gt; ' . $soa_array['soa_refresh'] . ' ' . $soa_array['soa_retry'] . ' ' . $soa_array['soa_expire'] . ' ' . $soa_array['soa_ttl'] . ' )';
            $soa_row = <<<HTML
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_master_server]" value="{$soa_array['soa_master_server']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_email_address]" value="{$soa_array['soa_email_address']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_refresh]" value="{$soa_array['soa_refresh']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_retry]" value="{$soa_array['soa_retry']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_expire]" value="{$soa_array['soa_expire']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_ttl]" value="{$soa_array['soa_ttl']}" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][record_type]" value="SOA" />
\t\t\t\t\t\t<input type="hidden" name="create[{$count}][soa_append]" value="{$soa_array['soa_append']}" />
\t\t\t\t\t\t{$soa_row}
\t\t\t\t\t\t<span><label><input type="checkbox" name="create[{$count}][record_skip]" />Skip Import</label></span>
\t\t\t\t\t\t</p>
\t\t\t\t\t\t
\t\t\t\t\t\t<h4>Records:</h4>

HTML;
            $count++;
        } else {
            $soa_row = null;
        }
        $clean_contents = str_replace('.' . trimFullStop($domain_name) . '.', '', $clean_contents);
        $clean_contents = str_replace(trimFullStop($domain_name) . '.', '', $clean_contents);
        $available_record_types = array_filter(enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_type'), 'removeRestrictedRR');
        sort($available_record_types);
        /** Loop through the lines */
        $lines = explode(PHP_EOL, $clean_contents);
        $failed = 0;
        $rows = null;
        $valid_hashes = array(';', '//', '#');
        foreach ($lines as $line) {
            $null_keys = array('record_ttl', 'record_priority', 'record_weight', 'record_port');
            foreach ($null_keys as $key) {
                $array[$key] = null;
            }
            if (!strlen(trim($line))) {
                continue;
            }
            foreach ($valid_hashes as $tmp_hash) {
                if (strpos($line, $tmp_hash)) {
                    $hash = $tmp_hash;
                    break;
                } else {
                    $hash = null;
                }
            }
            if ($hash == '//') {
                $hash = '\\/\\/';
            }
            /** Break up the line for comments */
            if ($hash) {
                $comment_parts = preg_split("/{$hash}+/", $line);
                $array['record_comment'] = trim($comment_parts[1]) ? trim($comment_parts[1]) : 'none';
            } else {
                $comment_parts[0] = $line;
                $array['record_comment'] = 'none';
            }
            /** Break up the line for parts */
            $parts = preg_split('/\\s+/', trim($comment_parts[0]));
            if ($domain_map == 'forward') {
                if (in_array('MX', $parts)) {
                    switch (array_search('MX', $parts)) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_priority'], $array['record_value']) = $parts;
                    }
                } elseif (in_array('SRV', $parts)) {
                    switch (array_search('SRV', $parts)) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_priority'], $array['record_weight'], $array['record_port'], $array['record_value']) = $parts;
                    }
                } elseif (in_array('TXT', $parts)) {
                    $key = array_search('TXT', $parts);
                    $txt_record = null;
                    for ($i = $key + 1; $i < count($parts); $i++) {
                        $txt_record .= $parts[$i] . ' ';
                    }
                    $parts[$key + 1] = rtrim($txt_record);
                    switch ($key) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                    }
                    $array['record_value'] = str_replace('"', '', $array['record_value']);
                } elseif (in_array('A', $parts) || in_array('CNAME', $parts) || in_array('AAAA', $parts)) {
                    if (in_array('AAAA', $parts)) {
                        $key = array_search('AAAA', $parts);
                    } else {
                        $key = in_array('A', $parts) ? array_search('A', $parts) : array_search('CNAME', $parts);
                    }
                    switch ($key) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if (is_numeric($parts[0])) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                    }
                }
            } else {
                if (in_array('PTR', $parts)) {
                    switch (array_search('PTR', $parts)) {
                        case 3:
                            list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            break;
                        case 2:
                            if ($parts[0] > 255) {
                                $array['record_name'] = isset($current_name) ? $current_name : '@';
                                list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            } else {
                                list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                            }
                            break;
                        case 1:
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                    }
                }
            }
            if (in_array('NS', $parts) && in_array('NS', $__FM_CONFIG['records']['require_zone_rights']) && currentUserCan('manage_zones', $_SESSION['module'])) {
                switch (array_search('NS', $parts)) {
                    case 3:
                        list($array['record_name'], $array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                        break;
                    case 2:
                        if (is_numeric($parts[0])) {
                            $array['record_name'] = isset($current_name) ? $current_name : '@';
                            list($array['record_ttl'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                        } else {
                            list($array['record_name'], $array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                        }
                        break;
                    case 1:
                        $array['record_name'] = isset($current_name) ? $current_name : '@';
                        list($array['record_class'], $array['record_type'], $array['record_value']) = $parts;
                }
            }
            if (empty($array['record_name']) && !empty($array['record_comment'])) {
                continue;
            }
            $array['record_append'] = substr($array['record_value'], -1) == '.' ? 'no' : 'yes';
            /** Set current_name to check for blanks on next run */
            $current_name = $array['record_name'];
            /** Automatically skip duplicates */
            $checked = $this->checkDuplicates($array, $_POST['domain_id']);
            $rows .= <<<ROW
\t\t\t\t\t<tr class="import_swap">
\t\t\t\t\t\t<td><span id="name{$count}" onclick="exchange(this);">{$array['record_name']}</span><input onblur="exchange(this);" type="text" id="name{$count}b" name="create[{$count}][record_name]" value="{$array['record_name']}" /></td>
\t\t\t\t\t\t<td><span id="ttl{$count}" onclick="exchange(this);">{$array['record_ttl']}</span><input onblur="exchange(this);" type="number" id="ttl{$count}b" name="create[{$count}][record_ttl]" value="{$array['record_ttl']}" /></td>
\t\t\t\t\t\t<td><input type="hidden" name="create[{$count}][record_class]" value="{$array['record_class']}" />{$array['record_class']}</td>
\t\t\t\t\t\t<td><input type="hidden" name="create[{$count}][record_type]" value="{$array['record_type']}" />{$array['record_type']}</td>
\t\t\t\t\t\t<td><span id="priority{$count}" onclick="exchange(this);">{$array['record_priority']}</span><input onblur="exchange(this);" type="number" id="priority{$count}b" name="create[{$count}][record_priority]" value="{$array['record_priority']}" /></td>
\t\t\t\t\t\t<td><span id="value{$count}" onclick="exchange(this);">{$array['record_value']}</span><input onblur="exchange(this);" type="text" id="value{$count}b" name="create[{$count}][record_value]" value="{$array['record_value']}" /></td>
\t\t\t\t\t\t<td><span id="weight{$count}" onclick="exchange(this);">{$array['record_weight']}</span><input onblur="exchange(this);" type="number" id="weight{$count}b" name="create[{$count}][record_weight]" value="{$array['record_weight']}" /></td>
\t\t\t\t\t\t<td><span id="port{$count}" onclick="exchange(this);">{$array['record_port']}</span><input onblur="exchange(this);" type="number" id="port{$count}b" name="create[{$count}][record_port]" value="{$array['record_port']}" /></td>
\t\t\t\t\t\t<td><span id="comment{$count}" onclick="exchange(this);">{$array['record_comment']}</span><input onblur="exchange(this);" type="text" id="comment{$count}b" name="create[{$count}][record_comment]" value="{$array['record_comment']}" /></td>
\t\t\t\t\t\t<td style="text-align: center;" nowrap><input type="hidden" name="create[{$count}][record_append]" value="{$array['record_append']}" />{$array['record_append']}</td>
\t\t\t\t\t\t<td style="text-align: center;"><label><input type="checkbox" name="create[{$count}][record_skip]" {$checked} />Skip Import</label></td>
\t\t\t\t\t</tr>

ROW;
            $count++;
        }
        $table_info = array('class' => 'display_results', 'id' => 'table_edits', 'name' => 'views');
        $title_array = array(__('Record'), __('TTL'), __('Class'), __('Type'), __('Priority'), __('Value'), __('Weight'), __('Port'), __('Comment'));
        $title_array[] = array('title' => __('Append Domain'), 'style' => 'text-align: center;', 'nowrap' => null);
        $title_array[] = array('title' => __('Actions'), 'class' => 'header-actions');
        $table_header = displayTableHeader($table_info, $title_array);
        $popup_header = buildPopup('header', __('Import Verification'));
        $popup_footer = buildPopup('footer', __('Import'), array('import' => 'submit', 'cancel_button' => 'cancel'));
        $body = <<<BODY
\t\t<form method="post" action="zone-records-write.php">
\t\t{$popup_header}
\t\t\t<p>Domain: {$domain_name}</p>
\t\t\t<input type="hidden" name="domain_id" value="{$_POST['domain_id']}">
\t\t\t<input type="hidden" name="map" value="{$domain_map}">
\t\t\t<input type="hidden" name="import_records" value="true">
\t\t\t<input type="hidden" name="import_file" value="{$_FILES['import-file']['name']}">
\t\t\t{$unsupported}
\t\t\t{$soa_row}
\t\t\t{$table_header}
\t\t\t\t{$rows}
\t\t\t\t</tbody>
\t\t\t</table>
\t\t\t<br />
\t\t{$popup_footer}
\t\t</form>
BODY;
        return $body;
    }
 /**
  * Figures out what files to update on the DNS server
  *
  * @since 1.0
  * @package fmDNS
  */
 function buildCronConfigs($post_data)
 {
     global $fmdb, $__FM_CONFIG;
     $server_serial_no = sanitize($post_data['SERIALNO']);
     extract($post_data);
     basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', $server_serial_no, 'server_', 'server_serial_no');
     if ($fmdb->num_rows) {
         $result = $fmdb->last_result;
         $data = $result[0];
         extract(get_object_vars($data), EXTR_SKIP);
         /** check if this server is configured for cron updates */
         if ($server_update_method != 'cron') {
             $error = "This server is not configured to receive updates via cron.\n";
             if ($compress) {
                 echo gzcompress(serialize($error));
             } else {
                 echo serialize($error);
             }
             return;
         }
         /** check if there are updates */
         if ($server_update_config == 'no') {
             $error = "No updates found.\n";
             if ($compress) {
                 echo gzcompress(serialize($error));
             } else {
                 echo serialize($error);
             }
             return;
         }
         /** purge configs first? */
         $data->purge_config_files = getOption('purge_config_files', getAccountID($post_data['AUTHKEY']), 'fmDNS');
         /** process zone reloads if present */
         $track_reloads = $this->getReloadRequests($server_serial_no);
         if ($track_reloads && $server_update_config == 'yes') {
             /** process zone config build */
             for ($i = 0; $i < count($track_reloads); $i++) {
                 $query = "SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` WHERE `domain_status`='active' AND (`domain_id`=" . $track_reloads[$i]->domain_id . " OR `domain_clone_domain_id`=" . $track_reloads[$i]->domain_id . ") ORDER BY `domain_clone_domain_id`,`domain_name`";
                 $result = $fmdb->query($query);
                 if ($fmdb->num_rows) {
                     $zone_result = $fmdb->last_result[0];
                     /** Is this a clone id? */
                     if ($zone_result->domain_clone_domain_id) {
                         $zone_result = $this->mergeZoneDetails($zone_result, 'clone');
                     } elseif ($zone_result->domain_template_id) {
                         $zone_result = $this->mergeZoneDetails($zone_result, 'template');
                     }
                     if (getSOACount($zone_result->domain_id)) {
                         $domain_name = $this->getDomainName($zone_result->domain_mapping, trimFullStop($zone_result->domain_name));
                         $file_ext = $zone_result->domain_mapping == 'forward' ? 'hosts' : 'rev';
                         /** Are there multiple zones with the same name? */
                         if (isset($zone_result->parent_domain_id)) {
                             basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $zone_result->domain_name, 'domain_', 'domain_name', 'AND domain_id!=' . $zone_result->parent_domain_id);
                             if ($fmdb->num_rows) {
                                 $file_ext = $zone_result->parent_domain_id . ".{$file_ext}";
                             }
                         } else {
                             $zone_result->parent_domain_id = $zone_result->domain_id;
                             basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $zone_result->domain_name, 'domain_', 'domain_name', 'AND domain_id!=' . $zone_result->domain_id);
                             if ($fmdb->num_rows) {
                                 $file_ext = $zone_result->domain_id . ".{$file_ext}";
                             }
                         }
                         //							basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $zone_result->domain_name, 'domain_', 'domain_name', 'AND domain_clone_domain_id=0 AND domain_id!=' . $zone_result->domain_id);
                         //							if ($fmdb->num_rows) $file_ext = $zone_result->domain_id . ".$file_ext";
                         /** Build zone file */
                         $data->files[$server_zones_dir . '/' . $zone_result->domain_type . '/db.' . $domain_name . $file_ext] = $this->buildZoneFile($zone_result);
                         /** Track reloads */
                         $data->reload_domain_ids[] = isset($zone_result->parent_domain_id) ? $zone_result->parent_domain_id : $zone_result->domain_id;
                     }
                 }
             }
             if (is_array($data->files)) {
                 return get_object_vars($data);
             }
         } else {
             /** process server config build */
             list($config, $message) = $this->buildServerConfig($post_data);
             $config['server_build_all'] = true;
             $config['purge_config_files'] = $data->purge_config_files;
             return $config;
         }
     }
     /** Bad DNS server */
     $error = "DNS server is not found.\n";
     if ($compress) {
         echo gzcompress(serialize($error));
     } else {
         echo serialize($error);
     }
 }
    function displayRow($row, $map, $reload_allowed)
    {
        global $fmdb, $__FM_CONFIG;
        if (!currentUserCan(array('access_specific_zones', 'view_all'), $_SESSION['module'], array(0, $row->domain_id))) {
            return;
        }
        $zone_access_allowed = zoneAccessIsAllowed(array($row->domain_id));
        if ($row->domain_status == 'disabled') {
            $classes[] = 'disabled';
        }
        $response = $add_new = null;
        $checkbox = currentUserCan('reload_zones', $_SESSION['module']) ? '<td></td>' : null;
        $soa_count = getSOACount($row->domain_id);
        $ns_count = getNSCount($row->domain_id);
        $reload_allowed = reloadAllowed($row->domain_id);
        if (!$soa_count && $row->domain_type == 'master') {
            $response = __('The SOA record still needs to be created for this zone');
            $classes[] = 'attention';
        }
        if (!$ns_count && $row->domain_type == 'master' && !$response) {
            $response = __('One more more NS records still needs to be created for this zone');
            $classes[] = 'attention';
        }
        if ($row->domain_type == 'master' && currentUserCan('manage_zones', $_SESSION['module'])) {
            global $map;
            $add_new = displayAddNew($map, $row->domain_id, __('Clone this zone'), 'fa-plus-square-o');
        }
        $clones = $this->cloneDomainsList($row->domain_id);
        $clone_names = $clone_types = $clone_views = $clone_counts = null;
        foreach ($clones as $clone_id => $clone_array) {
            $clone_names .= '<p class="clone' . $clone_id . '"><a href="' . $clone_array['clone_link'] . '" title="' . __('Edit zone records') . '">' . $clone_array['clone_name'] . '</a>' . $clone_array['clone_edit'] . $clone_array['clone_delete'] . "</p>\n";
            $clone_types .= '<p class="clone' . $clone_id . '">' . __('clone') . '</p>' . "\n";
            $clone_views .= '<p class="clone' . $clone_id . '">' . $this->IDs2Name($clone_array['clone_views'], 'view') . "</p>\n";
            $clone_counts_array = explode('|', $clone_array['clone_count']);
            $clone_counts .= '<p class="clone' . $clone_id . '" title="' . __('Differences from parent zone') . '">';
            if ($clone_counts_array[0]) {
                $clone_counts .= '<span class="record-additions">' . $clone_counts_array[0] . '</span>&nbsp;';
            }
            if ($clone_counts_array[1]) {
                $clone_counts .= '&nbsp;<span class="record-subtractions">' . $clone_counts_array[1] . '</span> ';
            }
            if (!array_sum($clone_counts_array)) {
                $clone_counts .= '-';
            }
            $clone_counts .= "</p>\n";
        }
        if ($clone_names) {
            $classes[] = 'clones';
        }
        if ($soa_count && $row->domain_reload == 'yes' && $reload_allowed) {
            if (currentUserCan('reload_zones', $_SESSION['module']) && $zone_access_allowed) {
                $reload_zone = '<form name="reload" id="' . $row->domain_id . '" method="post" action="' . $GLOBALS['basename'] . '?map=' . $map . '"><input type="hidden" name="action" value="reload" /><input type="hidden" name="domain_id" id="domain_id" value="' . $row->domain_id . '" />' . $__FM_CONFIG['icons']['reload'] . '</form>';
                $checkbox = '<td><input type="checkbox" name="domain_list[]" value="' . $row->domain_id . '" /></td>';
            } else {
                $reload_zone = __('Reload Available') . '<br />';
            }
        } else {
            $reload_zone = null;
        }
        if ($reload_zone) {
            $classes[] = 'build';
        }
        /*
        		$edit_status = <<<FORM
        <form method="post" action="{$GLOBALS['basename']}?map={$map}">
        	<input type="hidden" name="action" value="download" />
        	<input type="hidden" name="domain_id" value="{$row->domain_id}" />
        	{$__FM_CONFIG['icons']['export']}
        	</form>
        FORM;
        */
        $edit_status = null;
        if (!$soa_count && $row->domain_type == 'master' && currentUserCan('manage_zones', $_SESSION['module'])) {
            $type = 'SOA';
        } elseif (!$ns_count && $row->domain_type == 'master' && currentUserCan('manage_zones', $_SESSION['module'])) {
            $type = 'NS';
        } else {
            $type = $row->domain_mapping == 'forward' ? 'A' : 'PTR';
        }
        if ($soa_count && $ns_count && $row->domain_type == 'master') {
            $edit_status = '<a href="preview.php" onclick="javascript:void window.open(\'preview.php?server_serial_no=-1&config=zone&domain_id=' . $row->domain_id . '\',\'1356124444538\',\'width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1,left=0,top=0\');return false;">' . $__FM_CONFIG['icons']['preview'] . '</a>';
        }
        if (currentUserCan('manage_zones', $_SESSION['module']) && $zone_access_allowed) {
            $edit_status .= '<a class="edit_form_link" name="' . $map . '" href="#">' . $__FM_CONFIG['icons']['edit'] . '</a>';
            $edit_status .= '<a class="delete" href="#">' . $__FM_CONFIG['icons']['delete'] . '</a>' . "\n";
        }
        $domain_name = displayFriendlyDomainName($row->domain_name);
        $edit_name = $row->domain_type == 'master' ? "<a href=\"zone-records.php?map={$map}&domain_id={$row->domain_id}&record_type={$type}\" title=\"" . __('Edit zone records') . "\">{$domain_name}</a>" : $domain_name;
        $domain_view = $this->IDs2Name($row->domain_view, 'view');
        $class = 'class="' . implode(' ', $classes) . '"';
        $record_count = null;
        if ($row->domain_type == 'master') {
            $query = "SELECT COUNT(*) record_count FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}records WHERE account_id={$_SESSION['user']['account_id']} AND domain_id={$row->domain_id} AND record_status!='deleted'";
            $fmdb->query($query);
            $record_count = $fmdb->last_result[0]->record_count;
        }
        $template_icon = ($domain_template_id = getNameFromID($row->domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_template_id')) ? sprintf('<i class="template-icon fa fa-picture-o" title="%s"></i>', sprintf(__('Based on %s'), getNameFromID($domain_template_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name'))) : null;
        echo <<<HTML
\t\t<tr title="{$response}" id="{$row->domain_id}" {$class}>
\t\t\t{$checkbox}
\t\t\t<td>{$row->domain_id}</td>
\t\t\t<td><b>{$edit_name}</b> {$template_icon} {$add_new} {$clone_names}</td>
\t\t\t<td>{$row->domain_type}
\t\t\t\t{$clone_types}</td>
\t\t\t<td>{$domain_view}
\t\t\t\t{$clone_views}</td>
\t\t\t<td align="center">{$record_count}
\t\t\t\t{$clone_counts}</td>
\t\t\t<td id="edit_delete_img">
\t\t\t\t{$reload_zone}
\t\t\t\t{$edit_status}
\t\t\t</td>
\t\t</tr>

HTML;
    }
    function displayRow($row, $prefix)
    {
        global $__FM_CONFIG, $fmdb, $fm_dns_zones;
        if (currentUserCan('manage_zones', $_SESSION['module'])) {
            $edit_status = '<td id="edit_delete_img">';
            $edit_status .= '<a class="edit_form_link" href="#">' . $__FM_CONFIG['icons']['edit'] . '</a>';
            $show_delete = true;
            /** Cannot delete templates in use */
            if ($prefix == 'soa') {
                basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $row->soa_id, 'domain_', 'soa_id');
            }
            if ($prefix == 'domain') {
                basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $row->domain_id, 'domain_', 'domain_template_id');
            }
            if ($fmdb->num_rows) {
                $show_delete = false;
            }
            $edit_status .= $show_delete ? '<a href="#" class="delete">' . $__FM_CONFIG['icons']['delete'] . '</a>' : null;
            $edit_status .= '</td>';
        } else {
            $edit_status = null;
        }
        $field_name = $prefix . '_name';
        if ($prefix == 'domain') {
            if (!getSOACount($row->domain_id) && $row->domain_type == 'master' && currentUserCan('manage_zones', $_SESSION['module'])) {
                $type = 'SOA';
            } elseif (!getNSCount($row->domain_id) && $row->domain_type == 'master' && currentUserCan('manage_zones', $_SESSION['module'])) {
                $type = 'NS';
            } else {
                $type = $row->domain_mapping == 'forward' ? 'A' : 'PTR';
            }
            $edit_name = $row->domain_type == 'master' ? "<a href=\"zone-records.php?map={$row->domain_mapping}&domain_id={$row->domain_id}&record_type={$type}\" title=\"" . __('Edit zone records') . '">' . displayFriendlyDomainName($row->{$field_name}) . "</a>" : displayFriendlyDomainName($row->{$field_name});
        } else {
            $edit_name = $row->{$field_name};
        }
        $field_name = $prefix . '_default';
        $star = $row->{$field_name} == 'yes' ? str_replace(__('Super Admin'), __('Default Template'), $__FM_CONFIG['icons']['star']) : null;
        $field_id = $prefix . '_id';
        echo <<<HTML
\t\t<tr id="{$row->{$field_id}}">
\t\t\t<td>{$star}</td>
\t\t\t<td>{$edit_name}</td>
HTML;
        $row = get_object_vars($row);
        $excluded_fields = array($prefix . '_id', 'account_id', $prefix . '_template', $prefix . '_default', $prefix . '_name', $prefix . '_status', $prefix . '_template_id');
        if ($prefix == 'soa') {
            $excluded_fields = array_merge($excluded_fields, array($prefix . '_append'));
        }
        if ($prefix == 'domain') {
            $excluded_fields = array_merge($excluded_fields, array('soa_serial_no', 'soa_id', $prefix . '_clone_domain_id', $prefix . '_reload', $prefix . '_clone_dname'));
        }
        foreach ($row as $key => $val) {
            if (in_array($key, $excluded_fields)) {
                continue;
            }
            if ($prefix == 'domain') {
                /** Friendly servers and view names */
                if (in_array($key, array($prefix . '_view', $prefix . '_name_servers'))) {
                    if (!isset($fm_dns_zones)) {
                        include_once ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_zones.php';
                    }
                    if ($key == $prefix . '_view') {
                        $val = $fm_dns_zones->IDs2Name($val, 'view');
                    } elseif ($key == $prefix . '_name_servers') {
                        $val = $fm_dns_zones->IDs2Name($val, 'server');
                    }
                }
            }
            echo '<td>' . $val;
            if ($prefix == 'soa') {
                if (in_array($key, array('soa_master_server', 'soa_email_address')) && $row['soa_append'] == 'yes') {
                    echo '<span class="grey">.mydomain.tld</span>';
                }
            }
            echo '</td>';
        }
        echo $edit_status . "</tr>\n";
    }
 /**
  * Assigns SOA to domain_id
  *
  * @since 1.3
  * @package facileManager
  * @subpackage fmDNS
  *
  * @param id $soa_id SOA ID to assign
  * @param id $domain_id Domain ID to assign to
  * @return boolean
  */
 function assignSOA($soa_id, $domain_id)
 {
     global $__FM_CONFIG, $fm_dns_zones;
     $old_soa_id = getNameFromID($domain_id, "fm_{$__FM_CONFIG['fmDNS']['prefix']}domains", 'domain_', 'domain_id', 'soa_id');
     if (basicUpdate("fm_{$__FM_CONFIG['fmDNS']['prefix']}domains", $domain_id, 'soa_id', $soa_id, 'domain_id')) {
         /** Delete old custom SOA */
         if (getNameFromID($old_soa_id, "fm_{$__FM_CONFIG['fmDNS']['prefix']}soa", 'soa_', 'soa_id', 'soa_template') == 'no') {
             updateStatus("fm_{$__FM_CONFIG['fmDNS']['prefix']}soa", $old_soa_id, 'soa_', 'deleted', 'soa_id');
         }
         if (!isset($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);
             if (reloadAllowed($domain_id) && getSOACount($domain_id) && getNSCount($domain_id)) {
                 $this->updateSOAReload($child_id, 'yes');
             }
         }
     }
 }
 /**
  * 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');
             }
         }
     }
 }
Exemple #8
0
/**
 * Gets the menu badge counts
 *
 * @since 1.1
 * @package facileManager
 * @subpackage fmDNS
 *
 * @return integer
 */
function getModuleBadgeCounts($type)
{
    global $fmdb, $__FM_CONFIG;
    $badge_counts = null;
    if ($type == 'zones') {
        $badge_counts = array('forward' => 0, 'reverse' => 0);
        /** Zones */
        basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', 'domain_id', 'domain_');
        $domain_count = $fmdb->num_rows;
        if ($domain_count) {
            $domain_results = $fmdb->last_result;
        }
        for ($i = 0; $i < $domain_count; $i++) {
            if ($domain_results[$i]->domain_template == 'no') {
                if (!getSOACount($domain_results[$i]->domain_id) && !$domain_results[$i]->domain_clone_domain_id && $domain_results[$i]->domain_type == 'master') {
                    if (currentUserCan(array('access_specific_zones'), $_SESSION['module'], array(0, $domain_results[$i]->domain_id))) {
                        $badge_counts[$domain_results[$i]->domain_mapping]++;
                    }
                } elseif (!getNSCount($domain_results[$i]->domain_id) && !$domain_results[$i]->domain_clone_domain_id && $domain_results[$i]->domain_type == 'master') {
                    if (currentUserCan(array('access_specific_zones'), $_SESSION['module'], array(0, $domain_results[$i]->domain_id))) {
                        $badge_counts[$domain_results[$i]->domain_mapping]++;
                    }
                } elseif ($domain_results[$i]->domain_reload != 'no' && !$domain_results[$i]->domain_clone_domain_id && $domain_results[$i]->domain_type == 'master') {
                    if (currentUserCan(array('access_specific_zones'), $_SESSION['module'], array(0, $domain_results[$i]->domain_id))) {
                        $badge_counts[$domain_results[$i]->domain_mapping]++;
                    }
                }
            }
        }
        unset($domain_results, $domain_count);
    } elseif ($type == 'servers' && currentUserCan('manage_servers', $_SESSION['module'])) {
        $server_builds = array();
        /** Servers */
        basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_id', 'server_', "AND `server_installed`!='yes' OR (`server_status`='active' AND `server_build_config`='yes')");
        $server_count = $fmdb->num_rows;
        if ($server_count) {
            $server_results = $fmdb->last_result;
        }
        for ($i = 0; $i < $server_count; $i++) {
            $server_builds[] = $server_results[$i]->server_name;
        }
        if (version_compare(getOption('version', 0, $_SESSION['module']), '1.1', '>=')) {
            basicGetList('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_id', 'server_', "AND `server_client_version`!='" . getOption('client_version', 0, $_SESSION['module']) . "'");
            $server_count = $fmdb->num_rows;
            if ($server_count) {
                $server_results = $fmdb->last_result;
            }
            for ($i = 0; $i < $server_count; $i++) {
                $server_builds[] = $server_results[$i]->server_name;
            }
        }
        $servers = array_unique($server_builds);
        $badge_counts = count($servers);
        unset($server_builds, $servers, $server_count, $server_results);
    }
    return $badge_counts;
}