[code=php]<?php
require '../../library/imscp-lib.php';
$cfg = iMSCP_Registry::get('config');
$db = iMSCP_Registry::get('db');
echo "//CONFIGURATION FOR MAIN DOMAIN\n";
echo "zone \"$cfg->BASE_SERVER_VHOST\"{\n";
echo "\ttype slave;\n";
echo "\tfile \"/var/cache/bind/$cfg->BASE_SERVER_VHOST.db\";\n";
echo "\tmasters { $cfg->BASE_SERVER_IP; };\n";
echo "\tallow-notify { $cfg->BASE_SERVER_IP; };\n";
echo "};\n";
echo "//END CONFIGURATION FOR MAIN DOMAIN\n\n";
$query = "SELECT `domain_id`,`domain_name` FROM `domain`";
$rs = exec_query($query);
if ($rs->rowCount() == 0) {
echo "//NO DOMAINS LISTED";
} else {
$records_count = $rs->rowCount();
echo "//$records_count HOSTED DOMAINS LISTED ON $cfg->SERVER_HOSTNAME [$cfg->BASE_SERVER_IP]\n";
while (!$rs->EOF){
echo "zone \"".$rs->fields['domain_name']."\"{\n";
echo "\ttype slave;\n";
echo "\tfile \"/var/cache/bind/".$rs->fields['domain_name'].".db\";\n";
echo "\tmasters { $cfg->BASE_SERVER_IP; };\n";
echo "\tallow-notify { $cfg->BASE_SERVER_IP; };\n";
echo "};\n";
$rs->moveNext();
}
}
echo "//END DOMAINS LIST\n\n";
$query = "SELECT `alias_id`,`alias_name` FROM `domain_aliasses`";
$rs = exec_query($query);
if ($rs->rowCount() == 0) {
echo "//NO ALIASSES LISTED";
} else {
$records_count = $rs->rowCount();
echo "//$records_count HOSTED ALIASSES LISTED ON $cfg->SERVER_HOSTNAME [$cfg->BASE_SERVER_IP]\n";
while (!$rs->EOF){
echo "zone \"".$rs->fields['alias_name']."\"{\n";
echo "\ttype slave;\n";
echo "\tfile \"/var/cache/bind/".$rs->fields['alias_name'].".db\";\n";
echo "\tmasters { $cfg->BASE_SERVER_IP; };\n";
echo "\tallow-notify { $cfg->BASE_SERVER_IP; };\n";
echo "};\n";
$rs->moveNext();
}
}
echo "//END ALIASSES LIST\n";
?>[/php]
put it into /var/www/imscp/gui/public/domain/index.php on your primary dns / imscp server
create a .htaccess that allows only your secondary dns ip to call the script.
on your secondary:
create a cronjob
*/30 * * * * /usr/bin/wget http://IP-OF-PRIMARY-DNS/domain/ -O /etc/bind/named.hostname.conf && /etc/init.d/bind9 reload && /usr/bin/logger "i-MSCP: DNS zones updated from hostname\!"
then in /etc/bind/named.conf add the line
include "/etc/bind/named.hostname.conf";
replace hostname with the hostname or something that identify your primary server
not the best solution, but works. ofc here ist the bind configuration missing, if you want i can write a full howto. because you need to configure your primary and secondary for zone transfer, rndc keys and such