/** * Generates the zone configs (not files) * * @since 1.0 * @package fmDNS */ function buildZoneDefinitions($server_zones_dir, $server_serial_no, $view_id = 0, $view_name = null, $include_hint_zone = false) { global $fmdb, $__FM_CONFIG, $fm_dns_acls, $fm_module_servers; $error = null; include ABSPATH . 'fm-includes/version.php'; /** Get datetime formatting */ $date_format = getOption('date_format', $_SESSION['user']['account_id']); $time_format = getOption('time_format', $_SESSION['user']['account_id']); $files = null; $zones = '// This file was built using ' . $_SESSION['module'] . ' ' . $__FM_CONFIG[$_SESSION['module']]['version'] . ' on ' . date($date_format . ' ' . $time_format . ' e') . "\n\n"; $server_id = getServerID($server_serial_no, $_SESSION['module']); /** Build hint zone (root servers) */ if ($include_hint_zone) { $zones .= 'zone "." {' . "\n"; $zones .= "\ttype hint;\n"; $zones .= "\tfile \"{$server_zones_dir}/hint/named.root\";\n"; $zones .= "};\n"; list($files[$server_zones_dir . '/hint/named.root'], $error) = $this->getHintZone(); } /** Build zones */ $group_sql = null; if ($server_group_ids = $fm_module_servers->getServerGroupIDs($server_id)) { foreach ($server_group_ids as $group_id) { $group_sql .= " OR (`domain_name_servers`='0' OR `domain_name_servers`='g_{$group_id}' OR `domain_name_servers` LIKE 'g_{$group_id};%' OR `domain_name_servers` LIKE '%;g_{$group_id};%' OR `domain_name_servers` LIKE '%;g_{$group_id}')"; } if ($group_sql) { $group_sql = ' OR ' . ltrim($group_sql, ' OR '); } } $view_sql = "AND (`domain_view`<=0 OR `domain_view`={$view_id} OR `domain_view` LIKE '{$view_id};%' OR `domain_view` LIKE '%;{$view_id}' OR `domain_view` LIKE '%;{$view_id};%')"; $query = "SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` WHERE `domain_status`='active' AND `domain_template`='no' AND \n\t\t\t((`domain_name_servers`='0' OR `domain_name_servers`='s_{$server_id}' OR `domain_name_servers` LIKE 's_{$server_id};%' OR `domain_name_servers` LIKE '%;s_{$server_id};%' OR `domain_name_servers` LIKE '%;s_{$server_id}' {$group_sql}))\n\t\t\t {$view_sql} ORDER BY `domain_clone_domain_id`,`domain_name`"; $result = $fmdb->query($query); if ($fmdb->num_rows) { $count = $fmdb->num_rows; $zone_result = $fmdb->last_result; for ($i = 0; $i < $count; $i++) { /** Is this a clone id? */ if ($zone_result[$i]->domain_clone_domain_id) { $zone_result[$i] = $this->mergeZoneDetails($zone_result[$i], 'clone'); } elseif ($zone_result[$i]->domain_template_id) { $zone_result[$i] = $this->mergeZoneDetails($zone_result[$i], 'template'); } if ($zone_result[$i] == false) { continue; } if ($zone_result[$i]->domain_template == 'yes') { $skip = true; foreach (explode(';', $zone_result[$i]->domain_name_servers) as $domain_server_id) { if ($domain_server_id[0] == 's') { if (!$domain_server_id || 's_' . $server_id == $domain_server_id) { $skip = false; } } else { if (!$server_group_ids) { $skip = false; } else { foreach ($server_group_ids as $group_id) { if (!$domain_server_id || 'g_' . $group_id == $domain_server_id) { $skip = false; } } } } } if ($skip) { continue; } } /** Valid SOA and NS records must exist */ if (getSOACount($zone_result[$i]->domain_id) && getNSCount($zone_result[$i]->domain_id) || $zone_result[$i]->domain_type != 'master') { $domain_name_file = $this->getDomainName($zone_result[$i]->domain_mapping, trimFullStop($zone_result[$i]->domain_name)); $domain_name = isset($zone_result[$i]->domain_name_file) ? $this->getDomainName($zone_result[$i]->domain_mapping, trimFullStop($zone_result[$i]->domain_name_file)) : $domain_name_file; list($domain_type, $auto_zone_options) = $this->processServerGroups($zone_result[$i], $server_id); $zones .= 'zone "' . rtrim($domain_name, '.') . "\" {\n"; $zones .= "\ttype {$domain_type};\n"; $file_ext = $zone_result[$i]->domain_mapping == 'forward' ? 'hosts' : 'rev'; /** Are there multiple zones with the same name? */ if (isset($zone_result[$i]->parent_domain_id)) { basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $zone_result[$i]->domain_name, 'domain_', 'domain_name', 'AND domain_id!=' . $zone_result[$i]->parent_domain_id); if ($fmdb->num_rows) { $file_ext = $zone_result[$i]->parent_domain_id . ".{$file_ext}"; } } else { $zone_result[$i]->parent_domain_id = $zone_result[$i]->domain_id; basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $zone_result[$i]->domain_name, 'domain_', 'domain_name', 'AND domain_id!=' . $zone_result[$i]->domain_id); if ($fmdb->num_rows) { $file_ext = $zone_result[$i]->domain_id . ".{$file_ext}"; } } switch ($domain_type) { case 'master': case 'slave': $zones .= "\tfile \"{$server_zones_dir}/{$domain_type}/db." . $domain_name_file . "{$file_ext}\";\n"; $zones .= $this->getZoneOptions(array($zone_result[$i]->domain_id, $zone_result[$i]->parent_domain_id, $zone_result[$i]->domain_template_id), $server_serial_no, $domain_type) . (string) $auto_zone_options; /** Build zone file */ $zone_file_contents = $domain_type == 'master' ? $this->buildZoneFile($zone_result[$i], $server_serial_no) : null; $files[$server_zones_dir . '/' . $domain_type . '/db.' . $domain_name_file . $file_ext] = $zone_file_contents; unset($zone_file_contents); break; case 'stub': $zones .= "\tfile \"{$server_zones_dir}/stub/db." . $domain_name . "{$file_ext}\";\n"; $domain_master_servers = str_replace(';', "\n", rtrim(str_replace(' ', '', getNameFromID($zone_result[$i]->domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='masters'")), ';')); $zones .= "\tmasters { " . trim($fm_dns_acls->parseACL($domain_master_servers), '; ') . "; };\n"; break; case 'forward': $zones .= $this->getZoneOptions($zone_result[$i]->domain_id, $server_serial_no, $domain_type) . (string) $auto_zone_options; } $zones .= "};\n"; /** Add domain_id to built_domain_ids for tracking */ $GLOBALS['built_domain_ids'][] = $zone_result[$i]->domain_id; if (isset($zone_result[$i]->parent_domain_id)) { $GLOBALS['built_domain_ids'][] = $zone_result[$i]->parent_domain_id; } } } if ($view_name) { $files[$server_zones_dir . '/zones.conf.' . $view_name] = $zones; } else { $files[$server_zones_dir . '/zones.conf.all'] = $zones; } } return array($files, $error); }
$supported_record_types = enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_type'); sort($supported_record_types); $supported_record_types[] = 'SOA'; $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>
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> '; } if ($clone_counts_array[1]) { $clone_counts .= ' <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'); } } } }
/** * 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; }