/** * Checks if an email address is valid * * @since 1.0 * @package facileManager * * @param string $address Email address to validate * @return boolean */ function printfmDNSUsersForm($user_module_perms, $module_name) { global $__FM_CONFIG, $fmdb; if (!array_key_exists($module_name, $__FM_CONFIG)) { /** Include module variables */ @(include dirname(__FILE__) . '/variables.inc.php'); } $available_zones_perms = 0; if (isSerialized($user_module_perms)) { $user_module_perms = unserialize($user_module_perms); } $available_zones_perms = isset($user_module_perms[$module_name]['access_specific_zones']) ? $user_module_perms[$module_name]['access_specific_zones'] : 0; /** Get available zones */ $available_zones[0][] = 'All Zones'; $available_zones[0][] = '0'; basicGetList('fm_' . $__FM_CONFIG[$module_name]['prefix'] . 'domains', 'domain_mapping`,`domain_name', 'domain_', 'AND domain_clone_domain_id=0'); if ($fmdb->num_rows) { $results = $fmdb->last_result; for ($i = 0; $i < $fmdb->num_rows; $i++) { $available_zones[$i + 1][] = !function_exists('displayFriendlyDomainName') ? $results[$i]->domain_name : displayFriendlyDomainName($results[$i]->domain_name); $available_zones[$i + 1][] = $results[$i]->domain_id; } } $zones_list = buildSelect("user_caps[{$module_name}][access_specific_zones]", 1, $available_zones, $available_zones_perms, 5, null, true, null, 'wide_select', __('Select one or more zones')); return sprintf(' <tr class="user_permissions"> <th></th> <td><strong>%s</strong><br />%s</td> </tr> ', __('Limit access to the following zones:'), $zones_list); }
/** * Formats the server key statements * * @since 2.0 * @package fmDNS * * @param integer $view_id The view_id of the zone * @param integer $server_serial_no The server serial number for overrides * @return string */ function getRateLimits($view_id, $server_serial_no) { global $fmdb, $__FM_CONFIG, $fm_dns_acls; /** Check if rrl is supported by server_version */ list($server_version) = explode('-', getNameFromID($server_serial_no, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_version')); if (version_compare($server_version, '9.9.4', '<')) { return "\t//\n\t// BIND 9.9.4 or greater is required for Response Rate Limiting.\n\t//\n\n"; } $ratelimits = $ratelimits_domains = $rate_config_array = null; basicGetList('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', array('domain_id', 'server_serial_no', 'cfg_name'), 'cfg_', 'AND cfg_type="ratelimit" AND view_id=' . $view_id . ' AND server_serial_no="0" AND cfg_status="active"'); if ($fmdb->num_rows) { $rate_result = $fmdb->last_result; $global_rate_count = $fmdb->num_rows; for ($i = 0; $i < $global_rate_count; $i++) { if ($rate_result[$i]->domain_id) { $rate_config_array['domain'][displayFriendlyDomainName(getNameFromID($rate_result[$i]->domain_id, "fm_{$__FM_CONFIG[$_SESSION['module']]['prefix']}domains", 'domain_', 'domain_id', 'domain_name', null, 'active'))][$rate_result[$i]->cfg_name][] = array($rate_result[$i]->cfg_data, $rate_result[$i]->cfg_comment); } else { $rate_config_array[$rate_result[$i]->cfg_name][] = array($rate_result[$i]->cfg_data, $rate_result[$i]->cfg_comment); } } } /** Override with server-specific configs */ basicGetList('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', array('domain_id', 'server_serial_no', 'cfg_name'), 'cfg_', 'AND cfg_type="ratelimit" AND view_id=' . $view_id . ' AND server_serial_no=' . $server_serial_no . ' AND cfg_status="active"'); if ($fmdb->num_rows) { $server_config_result = $fmdb->last_result; $global_config_count = $fmdb->num_rows; for ($i = 0; $i < $global_config_count; $i++) { if ($server_config_result[$i]->domain_id) { $server_config['domain'][displayFriendlyDomainName(getNameFromID($server_config_result[$i]->domain_id, "fm_{$__FM_CONFIG[$_SESSION['module']]['prefix']}domains", 'domain_', 'domain_id', 'domain_name', null, 'active'))][$server_config_result[$i]->cfg_name][] = array($server_config_result[$i]->cfg_data, $server_config_result[$i]->cfg_comment); } else { $server_config[$server_config_result[$i]->cfg_name][] = array($server_config_result[$i]->cfg_data, $server_config_result[$i]->cfg_comment); } } } else { $server_config = array(); } /** Merge arrays */ $rate_config_array = array_merge((array) $rate_config_array, $server_config); foreach ($rate_config_array as $cfg_name => $value_array) { foreach ($value_array as $domain_name => $cfg_data) { if ($cfg_name != 'domain') { list($cfg_info, $cfg_comment) = $cfg_data; $ratelimits .= $this->formatConfigOption($cfg_name, $cfg_info, $cfg_comment); } else { foreach ($cfg_data as $domain_cfg_name => $domain_cfg_data) { $ratelimits_domains .= "\t};\n\trate-limit {\n\t\tdomain {$domain_name};\n"; foreach ($domain_cfg_data as $domain_cfg_data2) { list($cfg_param, $cfg_comment) = $domain_cfg_data2; $ratelimits_domains .= $this->formatConfigOption($domain_cfg_name, $cfg_param, $cfg_comment); } } } } } return $ratelimits || $ratelimits_domains ? "\trate-limit {\n{$ratelimits}{$ratelimits_domains}\t};\n\n" : null; }
/** * Updates the selected option */ function update($post) { global $fmdb, $__FM_CONFIG; /** Validate post */ $post = $this->validatePost($post); if (!is_array($post)) { return $post; } if (isset($post['cfg_id']) && !isset($post['cfg_name'])) { $post['cfg_name'] = getNameFromID($post['cfg_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'cfg_id', 'cfg_name'); } /** Does the record already exist for this account? */ basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', sanitize($post['cfg_name']), 'cfg_', 'cfg_name', "AND cfg_id!={$post['cfg_id']} AND cfg_type='{$post['cfg_type']}' AND server_serial_no='{$post['server_serial_no']}' AND view_id='{$post['view_id']}' AND domain_id='{$post['domain_id']}'"); if ($fmdb->num_rows) { $result = $fmdb->last_result; if ($result[0]->cfg_id != $post['cfg_id']) { $num_same_config = $fmdb->num_rows; $query = "SELECT def_max_parameters FROM fm_{$__FM_CONFIG['fmDNS']['prefix']}functions WHERE def_option='" . sanitize($post['cfg_name']) . "' AND def_option_type='{$post['cfg_type']}'"; $fmdb->get_results($query); if ($num_same_config > $fmdb->last_result[0]->def_max_parameters - 1) { return __('This record already exists.'); } } } $exclude = array('submit', 'action', 'cfg_id'); $sql_edit = null; foreach ($post as $key => $data) { if (!in_array($key, $exclude)) { $clean_data = sanitize($data); if (!strlen($clean_data) && $key != 'cfg_comment') { return false; } if ($key == 'cfg_name' && !isDNSNameAcceptable($clean_data)) { return false; } $sql_edit .= $key . "='" . $clean_data . "',"; } } $sql = rtrim($sql_edit, ','); // Update the config $old_name = getNameFromID($post['cfg_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'cfg_id', 'cfg_name'); $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}config` SET {$sql} WHERE `cfg_id`={$post['cfg_id']} AND `account_id`='{$_SESSION['user']['account_id']}'"; $result = $fmdb->query($query); if (!$fmdb->result) { return __('Could not update the option because a database error occurred.'); } /** Return if there are no changes */ if (!$fmdb->rows_affected) { return true; } $tmp_server_name = $post['server_serial_no'] ? getNameFromID($post['server_serial_no'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_', 'server_serial_no', 'server_name') : 'All Servers'; $tmp_view_name = $post['view_id'] ? getNameFromID($post['view_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'views', 'view_', 'view_id', 'view_name') : 'All Views'; $tmp_domain_name = isset($post['domain_id']) ? "\nZone: " . displayFriendlyDomainName(getNameFromID($post['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name')) : null; include_once ABSPATH . 'fm-modules/fmDNS/classes/class_acls.php'; $cfg_data = strpos($post['cfg_data'], 'acl_') !== false ? $fm_dns_acls->parseACL($post['cfg_data']) : $post['cfg_data']; addLogEntry("Updated option '{$old_name}' to:\nName: {$post['cfg_name']}\nValue: {$cfg_data}\nServer: {$tmp_server_name}\nView: {$tmp_view_name}{$tmp_domain_name}\nComment: {$post['cfg_comment']}"); return true; }
$display_option_type = $view_info[0]->view_name; $display_option_type_sql .= "' AND view_id='{$view_id}"; $name = 'view_id'; $rel = $view_id; /* Configure options for a zone */ } elseif (array_key_exists('domain_id', $_GET)) { $domain_id = isset($_GET['domain_id']) ? sanitize($_GET['domain_id']) : null; if (!$domain_id) { header('Location: ' . $GLOBALS['basename']); } basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $domain_id, 'domain_', 'domain_id'); if (!$fmdb->num_rows) { header('Location: zones.php'); } $domain_info = $fmdb->last_result; $display_option_type = displayFriendlyDomainName($domain_info[0]->domain_name); $display_option_type_sql .= "' AND domain_id='{$domain_id}"; $name = 'domain_id'; $rel = $domain_id; } else { $view_id = $domain_id = $name = $rel = null; $display_option_type_sql .= "' AND view_id='0"; if ($option_type == 'Global') { $display_option_type_sql .= "' AND domain_id='0"; } } if (currentUserCan('manage_servers', $_SESSION['module'])) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'add'; $uri_params = null; foreach ($GLOBALS['URI'] as $param => $val) { if (!in_array($param, array('option_type', 'view_id', 'domain_id', 'server_serial_no'))) {
/** * Process bulk zone reloads * * @since 1.2 * @package facileManager */ function doBulkZoneReload($domain_id) { global $fmdb, $__FM_CONFIG; /** Check serial number */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($domain_id), 'domain_', 'domain_id'); if (!$fmdb->num_rows) { return sprintf(__('%s is not a valid zone ID.'), $domain_id); } $server_details = $fmdb->last_result; extract(get_object_vars($server_details[0]), EXTR_SKIP); $response[] = displayFriendlyDomainName($domain_name); /** Ensure domain is reloadable */ if ($domain_reload != 'yes') { $response[] = ' --> ' . __('Failed: Zone is not available for reload.'); } /** Ensure domain is master */ if (count($response) == 1 && $domain_type != 'master') { $response[] = ' --> ' . __('Failed: Zone is not a master zone.'); } /** Ensure user is allowed to reload zone */ $zone_access_allowed = zoneAccessIsAllowed(array($domain_id), 'reload'); if (count($response) == 1 && !$zone_access_allowed) { $response[] = ' --> ' . __('Failed: You do not have permission to reload this zone.'); } /** Format output */ if (count($response) == 1) { foreach (makePlainText($this->buildZoneConfig($domain_id), true) as $line) { $response[] = ' --> ' . $line; } } $response[] = "\n"; return implode("\n", $response); }
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"; }
} if (!isset($data['record_comment']) || strtolower($data['record_comment']) == 'none') { $data['record_comment'] = null; } /** Remove double quotes */ if (isset($data['record_value'])) { $data['record_value'] = str_replace('"', '', $data['record_value']); } $fm_dns_records->add($domain_id, $record_type, $data); /** Are we auto-creating a PTR record? */ autoCreatePTR($domain_id, $record_type, $data); $record_count++; } } if (isset($import_records)) { $domain_name = displayFriendlyDomainName(getNameFromID($_POST['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name')); addLogEntry(sprintf(dngettext($_SESSION['module'], 'Imported %d record from \'%s\' into %s.', 'Imported %d records from \'%s\' into %s.', $record_count), $record_count, $import_file, $domain_name)); } } if (isset($record_type) && $domain_id && !isset($import_records)) { header('Location: zone-records.php?map=' . $map . '&domain_id=' . $domain_id . '&record_type=' . $record_type); } else { if ($domain_id) { header('Location: zone-records.php?map=' . $map . '&domain_id=' . $domain_id); } else { header('Location: ' . $menu[getParentMenuKey(__('SOA'))][4]); } } function autoCreatePTR($domain_id, $record_type, $data) { if ($record_type == 'A' && isset($data['PTR']) && zoneAccessIsAllowed(array($data['PTR']))) {
/** * Updates the selected record */ function update($domain_id, $id, $record_type, $array, $skipped_record = false) { global $fmdb, $__FM_CONFIG, $fm_dns_zones; $domain_name = displayFriendlyDomainName(getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name')); $record_name = getNameFromID($id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_', 'record_id', 'record_name'); $log_message = "Updated a record ({$record_name}) 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'; $field = $record_type == 'SOA' ? 'soa_id' : 'record_id'; $record_type_sql = $record_type != 'SOA' ? ",record_type='{$record_type}'" : null; $excluded_keys = array('record_skipped', 'PTR'); $null_keys = array('record_key_tag'); $sql_edit = null; foreach ($array as $key => $data) { if (in_array($key, $excluded_keys)) { continue; } if (in_array($key, $null_keys) && empty($data)) { $sql_edit .= $key . '=NULL,'; } else { $sql_edit .= $key . "='" . mysql_real_escape_string(str_replace("\r\n", "\n", $data)) . "',"; } if (!$skipped_record) { $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_edit = rtrim($sql_edit, ','); /** Update the record */ if ($skipped_record) { $table .= '_skipped'; $query = "SELECT * FROM `{$table}` WHERE account_id={$_SESSION['user']['account_id']} AND domain_id={$domain_id} AND record_id={$id}"; $result = $fmdb->query($query); if ($fmdb->num_rows) { $query = "UPDATE `{$table}` SET domain_id={$domain_id}, record_id={$id}, record_status='{$array['record_status']}' WHERE account_id={$_SESSION['user']['account_id']} AND domain_id={$domain_id} AND record_id={$id}"; } else { $query = "INSERT INTO `{$table}` VALUES(NULL, {$_SESSION['user']['account_id']}, {$domain_id}, {$id}, '{$array['record_status']}')"; } $data = $array['record_status'] == 'active' ? 'no' : 'yes'; $log_message .= formatLogKeyData(null, 'Included', $data); } else { $query = "UPDATE `{$table}` SET {$sql_edit} {$record_type_sql} WHERE `{$field}`='{$id}' AND `account_id`='{$_SESSION['user']['account_id']}'"; } $result = $fmdb->query($query); if (!$fmdb->result) { return false; } /** Return if there are no changes */ if (!$fmdb->rows_affected) { return true; } 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); if (reloadAllowed($domain_id) && getSOACount($domain_id) && getNSCount($domain_id)) { $this->updateSOAReload($child_id, 'yes'); } } addLogEntry($log_message); return $result; }
/** * Builds the additional module menu for display * * @since 1.0 * @package facileManager * @subpackage fmDNS */ function buildModuleToolbar() { global $__FM_CONFIG, $fmdb; if (isset($_REQUEST['domain_id'])) { $domain = displayFriendlyDomainName(getNameFromID($_REQUEST['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name')); $domain_menu = '<div id="topheadpart"> <span class="single_line">' . __('Domain') . ': ' . $domain . '</span> </div>'; if ($parent_domain_id = getNameFromID($_GET['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_clone_domain_id')) { basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $parent_domain_id, 'domain_', 'domain_id'); extract(get_object_vars($fmdb->last_result[0])); $domain_name = displayFriendlyDomainName($domain_name); $record_type_uri = array_key_exists('record_type', $_GET) ? '&record_type=' . $_GET['record_type'] : null; $domain_menu .= sprintf('<div id="topheadpart"> <span class="single_line">%s: <a href="zone-records.php?map=%s&domain_id=%s%s" title="%s">%s</a></span> </div>', __('Clone of'), $domain_mapping, $parent_domain_id, $record_type_uri, __('Edit parent zone records'), $domain_name); } if ($parent_domain_id = getNameFromID($_GET['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_template_id')) { basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', $parent_domain_id, 'domain_', 'domain_id'); extract(get_object_vars($fmdb->last_result[0])); $domain_name = displayFriendlyDomainName($domain_name); $record_type_uri = array_key_exists('record_type', $_GET) ? '&record_type=' . $_GET['record_type'] : null; $domain_menu .= sprintf('<div id="topheadpart"> <span class="single_line">%s: <a href="zone-records.php?map=%s&domain_id=%s%s" title="%s">%s</a></span> </div>', __('Based on template'), $domain_mapping, $parent_domain_id, $record_type_uri, __('Edit template zone records'), $domain_name); } } else { $domain_menu = null; } return array($domain_menu, null); }