Skip to content

Commit

Permalink
fmDNS - #65 - Added support to modify cloned zones
Browse files Browse the repository at this point in the history
  • Loading branch information
WillyXJ authored and WillyXJ committed Apr 18, 2014
1 parent 4e2f864 commit 60c611f
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
1 change: 1 addition & 0 deletions server/fm-modules/fmDNS/change.log
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Server - [bug] Removed non-master zones from the 'clone of' list.
* Server - [feature] Disabled records now have the proper css class assigned.
* Server - Updated help file text.
* Server - [feature] Added support to modify cloned zones. (Issue #65)

1.1.1 (2014-03-24)
==================
Expand Down
10 changes: 8 additions & 2 deletions server/fm-modules/fmDNS/classes/class_records.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function getHeader($type) {
return $title_array;
}

function getInputForm($type, $new, $domain_id, $results = null, $start = 1) {
function getInputForm($type, $new, $parent_domain_id, $results = null, $start = 1) {
global $allowed_to_manage_records, $allowed_to_manage_zones, $__FM_CONFIG, $zone_access_allowed;

$form = $record_status = $record_class = $record_name = $record_ttl = null;
Expand Down Expand Up @@ -266,7 +266,7 @@ function getInputForm($type, $new, $domain_id, $results = null, $start = 1) {

$class = buildSelect($action . '[_NUM_][record_class]', '_NUM_', enumMYSQLSelect('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_class'), $record_class);

if (($allowed_to_manage_records || $allowed_to_manage_zones) && $zone_access_allowed) {
if (($allowed_to_manage_records || $allowed_to_manage_zones) && $zone_access_allowed && ($new || $domain_id == $parent_domain_id)) {
if ($type == 'PTR') {
$domain_map = getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_mapping');
$input_box = '<input ';
Expand Down Expand Up @@ -358,6 +358,12 @@ function getInputForm($type, $new, $domain_id, $results = null, $start = 1) {
if (in_array($type, $append)) $field_values['data']['Append Domain'] = ' style="text-align: center;">' . $record_append;

$field_values['data']['Status'] = '>' . $record_status;

if (($allowed_to_manage_records || $allowed_to_manage_zones) && $zone_access_allowed && $domain_id != $parent_domain_id) {
$field_values['data']['Actions'] = ' align="center"><label><input style="height: 10px;" type="checkbox" name="' . $action . '[_NUM_][Skip]" ';
$field_values['data']['Actions'] .= in_array($parent_domain_id, explode(';', $record_skipped_by_domain_id)) ? ' checked' : null;
$field_values['data']['Actions'] .= '/>Skip Import</label>';
}
}

for ($i=$start; $i<=$end; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion server/fm-modules/fmDNS/classes/class_zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ function cloneDomainsList($domain_id) {
if ($fmdb->num_rows) {
$clone_results = $fmdb->last_result;
for ($i=0; $i<$fmdb->num_rows; $i++) {
$return .= '<p>' . $clone_results[$i]->domain_name;
$return .= '<p><a href="zone-records.php?map=' . $clone_results[$i]->domain_mapping . '&domain_id=' . $clone_results[$i]->domain_id . '" title="Edit zone records">' . $clone_results[$i]->domain_name . '</a>';
if ($allowed_to_manage_zones) $return .= ' ' . str_replace('__ID__', $clone_results[$i]->domain_id, $__FM_CONFIG['module']['icons']['sub_delete']);
$return .= "</p>\n";
}
Expand Down
22 changes: 19 additions & 3 deletions server/fm-modules/fmDNS/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function buildModuleDashboard() {
* @subpackage fmDNS
*/
function buildModuleToolbar() {
global $__FM_CONFIG;
global $__FM_CONFIG, $fmdb;

if (isset($_GET['domain_id'])) {
$domain = getNameFromID($_GET['domain_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name');
Expand All @@ -143,6 +143,16 @@ function buildModuleToolbar() {
<span class="single_line">Domain:&nbsp;&nbsp; $domain</span>
</div>
HTML;
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]));
$record_type_uri = array_key_exists('record_type', $_GET) ? '&record_type=' . $_GET['record_type'] : null;
$domain_menu .= <<<HTML
<div id="topheadpart">
<span class="single_line">Clone of:&nbsp;&nbsp; <a href="zone-records.php?map=$domain_mapping&domain_id=$parent_domain_id$record_type_uri" title="Edit parent zone records">$domain_name</a></span>
</div>
HTML;
}
} else $domain_menu = null;

return $domain_menu;
Expand Down Expand Up @@ -351,15 +361,21 @@ function reloadZone($domain_id) {
function getSOACount($domain_id) {
global $fmdb, $__FM_CONFIG;

$query = "SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}soa` WHERE `domain_id`='$domain_id' AND `soa_status`!='deleted'";
$query = "SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}soa` WHERE (`domain_id`='$domain_id' OR
`domain_id` = (SELECT `domain_clone_domain_id` FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` WHERE
`domain_id`='$domain_id')
) AND `soa_status`!='deleted'";
$fmdb->get_results($query);
return $fmdb->num_rows;
}

function getNSCount($domain_id) {
global $fmdb, $__FM_CONFIG;

$query = "SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` WHERE `domain_id`='$domain_id' AND `record_type`='NS' AND `record_status`='active'";
$query = "SELECT * FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` WHERE (`domain_id`='$domain_id' OR
`domain_id` = (SELECT `domain_clone_domain_id` FROM `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` WHERE
`domain_id`='$domain_id')
) AND `record_type`='NS' AND `record_status`='active'";
$fmdb->get_results($query);
return $fmdb->num_rows;
}
Expand Down
19 changes: 13 additions & 6 deletions server/fm-modules/fmDNS/pages/zone-records-validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ function buildReturnUpdate($domain_id, $record_type, $value) {

if (isset($data['Delete'])) {
$action = 'Delete';
$HTMLOut.= buildInputReturn('update', $record_type, $i ,'record_status', 'deleted');
$HTMLOut.= buildInputReturn('update', $i ,'record_status', 'deleted');
} elseif (isset($data['Skip'])) {
$action = 'Skip Import';
$HTMLOut.= buildInputReturn('update', $i ,'record_status', 'deleted');
$value[$i] = $changes[$i];
} else {
$y = 0;
$action = null;
Expand Down Expand Up @@ -255,7 +259,7 @@ function buildReturnUpdate($domain_id, $record_type, $value) {

if (!isset($input_return_error[$i]) || !$input_return_error[$i]) {
if ($key == 'soa_serial_no' && !$val) continue;
$input_return[$i][$y]= buildInputReturn('update', $record_type, $i, $key, $val);
$input_return[$i][$y]= buildInputReturn('update', $i, $key, $val);
$action = 'Update';
} else {
$action = 'None';
Expand Down Expand Up @@ -504,7 +508,7 @@ function buildReturnCreate($domain_id, $record_type, $value) {
}

if (!isset($input_return_error[$i]) || !$input_return_error[$i]) {
$input_return[$i][$y] = buildInputReturn('create', $record_type, $i, $key, $val);
$input_return[$i][$y] = buildInputReturn('create', $i, $key, $val);
$action = 'Create';
} else {
$action = 'None';
Expand Down Expand Up @@ -540,7 +544,7 @@ function buildReturnCreate($domain_id, $record_type, $value) {
return $HTMLOut;
}

function buildInputReturn($action, $record_type, $i, $key, $val) {
function buildInputReturn($action, $i, $key, $val) {

return "<input type='hidden' name='{$action}[$i][$key]' value='$val'>\n";
}
Expand Down Expand Up @@ -643,10 +647,13 @@ function buildSQLRecords($record_type, $domain_id) {
array_shift($sql_results[$result[0]->soa_id]);
return $sql_results;
} else {
$parent_domain_id = getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_clone_domain_id');
$valid_domain_ids = ($parent_domain_id) ? "IN ('$domain_id', '$parent_domain_id')" : "='$domain_id'";

if (in_array($record_type, array('A', 'AAAA'))) {
$record_sql = "AND domain_id='$domain_id' AND record_type IN ('A', 'AAAA')";
$record_sql = "AND domain_id $valid_domain_ids AND record_type IN ('A', 'AAAA')";
} else {
$record_sql = "AND domain_id='$domain_id' AND record_type='$record_type'";
$record_sql = "AND domain_id $valid_domain_ids AND record_type='$record_type'";
}
$result = basicGetList('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', 'record_name', 'record_', $record_sql);
if ($result) {
Expand Down
14 changes: 10 additions & 4 deletions server/fm-modules/fmDNS/pages/zone-records.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
$page_name = 'Zones';
$page_name_sub = ($map == 'forward') ? 'Forward' : 'Reverse';

$default_record_type = $map == 'forward' ? 'A' : 'PTR';
if (isset($_GET['record_type'])) {
$record_type = strtoupper($_GET['record_type']);
} else {
$record_type = $map == 'forward' ? 'A' : 'PTR';
$record_type = $default_record_type;
}

$domain_id = (isset($_GET['domain_id'])) ? $_GET['domain_id'] : header('Location: ' . $__FM_CONFIG['menu']['Zones']['URL']);
if (!isValidDomain($domain_id)) header('Location: ' . $__FM_CONFIG['menu']['Zones']['URL']);

if (in_array($record_type, $__FM_CONFIG['records']['require_zone_rights']) && !$allowed_to_manage_zones) header('Location: ' . $GLOBALS['RELPATH']);
if (in_array($record_type, $__FM_CONFIG['records']['require_zone_rights']) && !$allowed_to_manage_zones) $record_type = $default_record_type;
if (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_clone_domain_id') && $record_type == 'SOA') $record_type = $default_record_type;

printHeader('Records' . ' &lsaquo; ' . $_SESSION['module']);
@printMenu($page_name, $page_name_sub);
Expand All @@ -62,7 +64,7 @@

$response = $form_data = $action = null;
if (reloadZone($domain_id)) {
if (reloadAllowed($domain_id)) $response = '** You need to <a href="" class="zone_reload" id="' . $domain_id . '">reload</a> this zone **';
if (reloadAllowed($domain_id) && $allowed_to_reload_zones && $zone_access_allowed) $response = '** You need to <a href="" class="zone_reload" id="' . $domain_id . '">reload</a> this zone **';
}
if (!getNSCount($domain_id)) {
$response = '** One more more NS records still needs to be created for this zone **';
Expand Down Expand Up @@ -113,7 +115,9 @@
$ip_sort = false;
break;
}
$record_sql = "AND domain_id='$domain_id' AND record_type='$record_type'";
$parent_domain_id = getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_clone_domain_id');
$valid_domain_ids = ($parent_domain_id) ? "IN ('$domain_id', '$parent_domain_id')" : "='$domain_id'";
$record_sql = "AND domain_id $valid_domain_ids AND record_type='$record_type'";
$sort_direction = null;

if (isset($_SESSION[$_SESSION['module']][$GLOBALS['path_parts']['filename']])) {
Expand Down Expand Up @@ -151,6 +155,8 @@ function buildRecordTypes($record_type = null, $domain_id = null, $map = 'forwar
if (isset($record_type) && $domain_id != null) {
foreach ($__FM_CONFIG['records']['common_types'] as $type) {
if (in_array($type, $__FM_CONFIG['records']['require_zone_rights']) && !$allowed_to_manage_zones) continue;
if (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_clone_domain_id') && $type == 'SOA') continue;

$select = ($record_type == $type) ? ' class="selected"' : '';
$menu_selects .= "<span$select><a$select href=\"zone-records.php?map={$map}&domain_id={$domain_id}&record_type=$type\">$type</a></span>\n";
}
Expand Down
3 changes: 2 additions & 1 deletion server/fm-modules/fmDNS/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ function upgradefmDNS_120($__FM_CONFIG, $running_version) {
ADD `record_key_tag` INT NULL AFTER `record_cert_type` ,
ADD `record_algorithm` TINYINT NULL AFTER `record_key_tag`,
ADD `record_flags` ENUM( '0', '256', '257' ) NULL AFTER `record_algorithm`,
ADD `record_text` VARCHAR( 255 ) NULL AFTER `record_flags` ;";
ADD `record_text` VARCHAR( 255 ) NULL AFTER `record_flags`,
ADD `record_skipped_by_domain_id` TEXT NULL AFTER `record_comment` ;";
$table[] = "ALTER TABLE `fm_{$__FM_CONFIG['fmDNS']['prefix']}records` CHANGE `record_value` `record_value` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ;";

$inserts = $updates = null;
Expand Down

0 comments on commit 60c611f

Please sign in to comment.