can79
Posts: 4
Joined: Apr 2010
Reputation: 0
RE: Custom DNS server
I have a solution for custom NS records. (based on ispCP 1.05)
I think dev team can improve.
NOTE.
After you customize for each domain you have to create A records and NS records
So there is no longer automatically ns records created.
advantage is that you can yourself edit ns records for each domain.
This will only a tip for dev team.
I do not support on pm. and you are responsible for errors.
before you start. make backup
it works as follows;
Change /etc/ispcp/bind/parts/db_e.tpl and /etc/ispcp/bind/parts/db_master_e.tpl as follows
Code:
$TTL 12H
$ORIGIN {DMN_NAME}.
@ IN SOA ns1.{DMN_NAME}. postmaster.{DMN_NAME}. (
; dmn [{DMN_NAME}] timestamp entry BEGIN.
{TIMESTAMP} ; Serial
; dmn [{DMN_NAME}] timestamp entry END.
8H ; Refresh
30M ; Retry
4W ; Expire
3H ; Minimum TTL
)
{DMN_NAME}. IN A {DMN_IP}
localhost IN A 127.0.0.1
; CNAME for VHCS compatibility
ns IN CNAME ns1
; CNAME for mail transfer
; CNAME for web transfer
; sub [{SUB_NAME}] entry BEGIN.
; sub [{SUB_NAME}] entry END.
; dns [{MANUAL_DNS_ID}] entry BEGIN.
; dns [{MANUAL_DNS_ID}] entry END.
Change in /var/www/ispcp/gui/client/dns_edit.php following lines.
next line
Code:
$DNS_allowed_types = array('A','AAAA','SRV','CNAME','MX');
to
Code:
$DNS_allowed_types = array('A','NS','AAAA','SRV','CNAME','MX');
next
Code:
function decode_zone_data($data) {
$address = $addressv6 = $srv_name = $srv_proto = $cname = $txt = $name = '';
$srv_TTL = $srv_prio = $srv_weight = $srv_host = $srv_port = '';
if (is_array($data)) {
$name = $data['domain_dns'];
switch ($data['domain_type']) {
case 'A':
$address = $data['domain_text'];
break;
case 'AAAA':
$addressv6 = $data['domain_text'];
break;
case 'CNAME':
$cname = $data['domain_text'];
break;
case 'SRV':
$name = '';
if (preg_match('~_([^\.]+)\._([^\s]+)[\s]+([\d]+)~', $data['domain_dns'], $srv)) {
$srv_name = $srv[1];
$srv_proto = $srv[2];
$srv_TTL = $srv[3];
}
if (preg_match('~([\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([^\s]+)+~', $data['domain_text'], $srv)) {
$srv_prio = $srv[1];
$srv_weight = $srv[2];
$srv_port = $srv[3];
$srv_host = $srv[4];
}
break;
case 'MX':
$name = '';
if (preg_match('~([\d]+)[\s]+([^\s]+)+~', $data['domain_text'], $srv)) {
$srv_prio = $srv[1];
$srv_host = $srv[2];
}
break;
default:
$txt = $data['domain_text'];
}
}
return array(
$name, $addressns, $addressv6, $srv_name, $srv_proto, $srv_TTL, $srv_prio,
$srv_weight, $srv_host, $srv_port, $cname, $txt
);
to
Code:
function decode_zone_data($data) {
$address = $addressns = $addressv6 = $srv_name = $srv_proto = $cname = $txt = $name = '';
$srv_TTL = $srv_prio = $srv_weight = $srv_host = $srv_port = '';
if (is_array($data)) {
$name = $data['domain_dns'];
switch ($data['domain_type']) {
case 'A':
$address = $data['domain_text'];
break;
case 'NS':
// $cname = $data['domain_text'];
$addressns = $data['domain_text'];
break;
case 'AAAA':
$addressv6 = $data['domain_text'];
break;
case 'CNAME':
$cname = $data['domain_text'];
break;
case 'SRV':
$name = '';
if (preg_match('~_([^\.]+)\._([^\s]+)[\s]+([\d]+)~', $data['domain_dns'], $srv)) {
$srv_name = $srv[1];
$srv_proto = $srv[2];
$srv_TTL = $srv[3];
}
if (preg_match('~([\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([^\s]+)+~', $data['domain_text'], $srv)) {
$srv_prio = $srv[1];
$srv_weight = $srv[2];
$srv_port = $srv[3];
$srv_host = $srv[4];
}
break;
case 'MX':
$name = '';
if (preg_match('~([\d]+)[\s]+([^\s]+)+~', $data['domain_text'], $srv)) {
$srv_prio = $srv[1];
$srv_host = $srv[2];
}
break;
default:
$txt = $data['domain_text'];
}
}
return array(
$name, $address, $addressns, $addressv6, $srv_name, $srv_proto, $srv_TTL, $srv_prio,
$srv_weight, $srv_host, $srv_port, $cname, $txt
);
next
Code:
switch ($_POST['type']) {
case 'CNAME':
if (!validate_CNAME($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_cname'];
$_dns = $_POST['dns_name'];
break;
case 'A':
if (!validate_A($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
if (!check_CNAME_conflict($_POST['dns_name'].'.'.$record_domain, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_A_address'];
$_dns = $_POST['dns_name'];
break;
case 'AAAA':
if (!validate_AAAA($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
if (!check_CNAME_conflict($_POST['dns_name'].'.'.$record_domain, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_AAAA_address'];
$_dns = $_POST['dns_name'];
break;
to
Code:
switch ($_POST['type']) {
case 'CNAME':
if (!validate_CNAME($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_cname'];
$_dns = $_POST['dns_name'];
break;
case 'A':
if (!validate_A($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_A_address'];
$_dns = $_POST['dns_name'];
break;
case 'NS':
if (!validate_NS($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_NS_addressns'];
$_dns = $_POST['dns_name'];
break;
case 'AAAA':
if (!validate_AAAA($_POST, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
if (!check_CNAME_conflict($_POST['dns_name'].'.'.$record_domain, $err))
$ed_error = sprintf(tr('Cannot validate %s record. Reason \'%s\'.'), $_POST['type'], $err);
$_text = $_POST['dns_AAAA_address'];
$_dns = $_POST['dns_name'];
break;
next
Code:
list(
$name,
$address,
$addressv6,
$srv_name,
$srv_proto,
$srv_ttl,
$srv_prio,
$srv_weight,
$srv_host,
$srv_port,
$cname,
$plain
) = decode_zone_data($data);
to
Code:
list(
$name,
$address,
$addressns,
$addressv6,
$srv_name,
$srv_proto,
$srv_ttl,
$srv_prio,
$srv_weight,
$srv_host,
$srv_port,
$cname,
$plain
) = decode_zone_data($data);
next
Code:
$tpl->assign(
array(
'SELECT_DNS_TYPE' => $dns_type,
'SELECT_DNS_CLASS' => $dns_class,
'DNS_NAME' => $name,
'DNS_ADDRESS' => tryPost('dns_A_address', $address),
'DNS_ADDRESS_V6' => tryPost('dns_AAAA_address', $addressv6),
'SELECT_DNS_SRV_PROTOCOL' => create_options(array('tcp','udp'), tryPost('srv_proto', $srv_proto)),
'DNS_SRV_NAME' => tryPost('dns_srv_name', $srv_name),
'DNS_SRV_TTL' => tryPost('dns_srv_ttl', $srv_ttl),
'DNS_SRV_PRIO' => tryPost('dns_srv_prio', $srv_prio),
'DNS_SRV_WEIGHT' => tryPost('dns_srv_weight', $srv_weight),
'DNS_SRV_HOST' => tryPost('dns_srv_host', $srv_host),
'DNS_SRV_PORT' => tryPost('dns_srv_port', $srv_port),
'DNS_CNAME' => tryPost('dns_cname', $cname),
'DNS_PLAIN' => tryPost('dns_plain_data', $plain),
'ID' => $edit_id
)
);
to
Code:
$tpl->assign(
array(
'SELECT_DNS_TYPE' => $dns_type,
'SELECT_DNS_CLASS' => $dns_class,
'DNS_NAME' => $name,
'DNS_ADDRESS' => tryPost('dns_A_address', $address),
'DNS_NS' => tryPost('dns_NS_address', $addressns),
'DNS_ADDRESS_V6' => tryPost('dns_AAAA_address', $addressv6),
'SELECT_DNS_SRV_PROTOCOL' => create_options(array('tcp','udp'), tryPost('srv_proto', $srv_proto)),
'DNS_SRV_NAME' => tryPost('dns_srv_name', $srv_name),
'DNS_SRV_TTL' => tryPost('dns_srv_ttl', $srv_ttl),
'DNS_SRV_PRIO' => tryPost('dns_srv_prio', $srv_prio),
'DNS_SRV_WEIGHT' => tryPost('dns_srv_weight', $srv_weight),
'DNS_SRV_HOST' => tryPost('dns_srv_host', $srv_host),
'DNS_SRV_PORT' => tryPost('dns_srv_port', $srv_port),
'DNS_CNAME' => tryPost('dns_cname', $cname),
'DNS_PLAIN' => tryPost('dns_plain_data', $plain),
'ID' => $edit_id
)
);
next
Code:
$tpl->assign(
array(
'TR_MODIFY' => tr('Modify'),
'TR_CANCEL' => tr('Cancel'),
'TR_ADD' => tr('Add'),
'TR_DOMAIN' => tr('Domain'),
'TR_EDIT_DNS' => ($add_mode) ? tr("Add DNS zone's record (EXPERIMENTAL)") : tr("Edit DNS zone's record (EXPERIMENTAL)"),
'TR_DNS' => tr("DNS zone's records"),
'TR_DNS_NAME' => tr('Name'),
'TR_DNS_CLASS' => tr('Class'),
'TR_DNS_TYPE' => tr('Type'),
'TR_DNS_SRV_NAME' => tr('Service name'),
'TR_DNS_IP_ADDRESS' => tr('IP address'),
'TR_DNS_IP_ADDRESS_V6' => tr('IPv6 address'),
'TR_DNS_SRV_PROTOCOL' => tr('Service protocol'),
'TR_DNS_SRV_TTL' => tr('TTL'),
'TR_DNS_SRV_PRIO' => tr('Priority'),
'TR_DNS_SRV_WEIGHT' => tr('Relative weight for records with the same priority'),
'TR_DNS_SRV_HOST' => tr('Target host'),
'TR_DNS_SRV_PORT' => tr('Target port'),
'TR_DNS_CNAME' => tr('Canonical name'),
'TR_DNS_PLAIN' => tr('Plain record data'),
'TR_MANAGE_DOMAIN_DNS' => tr("DNS zone's records (EXPERIMENTAL)")
)
);
to
Code:
$tpl->assign(
array(
'TR_MODIFY' => tr('Modify'),
'TR_CANCEL' => tr('Cancel'),
'TR_ADD' => tr('Add'),
'TR_DOMAIN' => tr('Domain'),
'TR_EDIT_DNS' => ($add_mode) ? tr("Add DNS zone's record (EXPERIMENTAL)") : tr("Edit DNS zone's record (EXPERIMENTAL)"),
'TR_DNS' => tr("DNS zone's records"),
'TR_DNS_NAME' => tr('Name'),
'TR_DNS_CLASS' => tr('Class'),
'TR_DNS_TYPE' => tr('Type'),
'TR_DNS_SRV_NAME' => tr('Service name'),
'TR_DNS_IP_ADDRESS' => tr('IP address (Absolute names must end with a .)'),
'TR_DNS_NS' => tr('NS address (Absolute names must end with a .)'),
'TR_DNS_IP_ADDRESS_V6' => tr('IPv6 address'),
'TR_DNS_SRV_PROTOCOL' => tr('Service protocol'),
'TR_DNS_SRV_TTL' => tr('TTL'),
'TR_DNS_SRV_PRIO' => tr('Priority'),
'TR_DNS_SRV_WEIGHT' => tr('Relative weight for records with the same priority'),
'TR_DNS_SRV_HOST' => tr('Target host'),
'TR_DNS_SRV_PORT' => tr('Target port'),
'TR_DNS_CNAME' => tr('Canonical name'),
'TR_DNS_PLAIN' => tr('Plain record data'),
'TR_MANAGE_DOMAIN_DNS' => tr("DNS zone's records (EXPERIMENTAL)")
)
);
Change in /var/www/ispcp/gui/themes/omega_original/client/dns_edit.tpl following lines.
next
Code:
function dns_show_rows(arr_show) {
var arr_possible = new Array('name', 'ip_address', 'ip_address_v6',
to
Code:
function dns_show_rows(arr_show) {
var arr_possible = new Array('name', 'ip_address', 'addressns', 'ip_address_v6',
next
Code:
function dns_type_changed(value) {
if (value == 'A') {
dns_show_rows(new Array('name', 'ip_address'));
} else if (value == 'NS') {
dns_show_rows(new Array('name', 'addressns'));
} else if (value == 'AAAA') {
dns_show_rows(new Array('name', 'ip_address_v6'));
} else if (value == 'SRV') {
dns_show_rows(new Array('srv_name', 'srv_protocol', 'srv_ttl',
'srv_prio', 'srv_weight', 'srv_host', 'srv_port'));
} else if (value == 'CNAME') {
dns_show_rows(new Array('name', 'cname'));
} else if (value == 'MX') {
dns_show_rows(new Array('srv_prio', 'srv_host'));
}
}
to
Code:
function dns_type_changed(value) {
if (value == 'A') {
dns_show_rows(new Array('name', 'ip_address'));
} else if (value == 'NS') {
dns_show_rows(new Array('name', 'addressns'));
} else if (value == 'AAAA') {
dns_show_rows(new Array('name', 'ip_address_v6'));
} else if (value == 'SRV') {
dns_show_rows(new Array('srv_name', 'srv_protocol', 'srv_ttl',
'srv_prio', 'srv_weight', 'srv_host', 'srv_port'));
} else if (value == 'CNAME') {
dns_show_rows(new Array('name', 'cname'));
} else if (value == 'MX') {
dns_show_rows(new Array('srv_prio', 'srv_host'));
}
}
next
Code:
<tr id="tr_dns_ip_address">
<td width="25"> </td>
<td width="200" class="content2">{TR_DNS_IP_ADDRESS}</td>
<td class="content"><input type="text" onkeypress="return filterChars(event, IPADDRESS);" name="dns_A_address" value="{DNS_ADDRESS}" /></td>
</tr>
<tr id="tr_dns_ip_address_v6">
<td width="25"> </td>
<td width="200" class="content2">{TR_DNS_IP_ADDRESS_V6}</td>
<td class="content"><input type="text" onkeypress="return filterChars(event, IPv6ADDRESS);" name="dns_AAAA_address" value="{DNS_ADDRESS_V6}" /></td>
to
Code:
<tr id="tr_dns_ip_address">
<td width="25"> </td>
<td width="200" class="content2">{TR_DNS_IP_ADDRESS}</td>
<td class="content"><input type="text" name="dns_A_address" value="{DNS_ADDRESS}" /></td>
</tr>
<tr id="tr_dns_addressns">
<td width="25"> </td>
<td width="200" class="content2">{TR_DNS_NS}</td>
<td class="content"><input type="text" name="dns_NS_addressns" value="{DNS_ADDRESS}" /></td>
</tr>
yup I can now manage manual ns records
see my edited files
Attached File(s)
custom_ns_record.zip (Size: 8.75 KB / Downloads: 12)