I wrote this small script a few years ago (2005). This script allows you to add/delete 1 or more DNS zones and trust me, when you need to add 300 domains to your Ensim box you’ll come back to thank me 😛
Basicly, the script asks you for 2 options:
What do you want to do?
[1] Add zone(s)
[2] Delete zone(s)
Then, you’ll need to write the domain(s) separated by spaces and also the IP address and that’s all. By default it uses Ensim’s DNS zone template but you can change it to whatever you want.
File: mdns.php
#!/usr/bin/php -q
<?
// This settings should be OK!
// Add more if you need ;)
define('DEBUG',true); // make it 'false' if you want to see it work
define('DPATH','/usr/lib/opcenter/bind/');
define('ADD',DPATH.'add_zone');
define('REM',DPATH.'remove_zone');
define('AA',DPATH.'add_a');
define('AMX',DPATH.'add_mx');
main_menu();
function main_menu() {
?-->
What do you want to do?
[1] Add zone(s)
[2] Delete zone(s)
Option: \n");
get_line();
main_menu();
return;
}
foreach ($domains as $k => $v) {
print_out("\nAdding Zone $v ...\n");
ecmd(ADD." -f ".$v);
print_out("\nAdding A (www,ftp,mail) and MX records ...\n");
ecmd(AA." -u $v $ip");
ecmd(AA." -z $v www $ip");
ecmd(AA." -z $v ftp $ip");
ecmd(AA." -z $v mail $ip");
ecmd(AMX." $v mail.".$v." 10");
}
}
function rem_domains($domains=array()) {
if (!$domains[0]) {
print_out("\nThere are no domain(s), please start again \n");
get_line();
main_menu();
return;
}
foreach ($domains as $k => $v) {
print_out("\nRemoving Zone $v ...\n");
ecmd(REM." ".$v);
}
}
function ecmd($cmd="") {
if (!$cmd) {
echo "Nothing to execute!\n";
return;
}
$cmd = escapeshellcmd($cmd);
print_out("\t$cmd\n");
if (!DEBUG) {
$out = `$cmd 2>&1`;
}
}
function option_domains() {
print_out("\nEnter domain or domains separated by spaces or comas:\n");
$line = get_line();
$domains = preg_split('/\s+|,/',$line,-1,PREG_SPLIT_NO_EMPTY);
if (!$domains[0]) {
print_out("\nYou need to enter at least one domain name, press any key to continue...");
get_line();
main_menu();
}
print_out("\nCheck your information submitted: ");
$i = 1;
foreach ($domains as $k => $v) {
echo "($i)$v ";
$i++;
}
print_out("\n");
return $domains;
}
function option_ip() {
print_out("\nEnter the IP: ");
$line = get_line();
if (!$line) {
print_out("\nYou need to enter an IP, press any key to continue...");
get_line();
main_menu();
}
print_out("\nCheck your information submitted: $line\n");
return $line;
}
function option_confirm($info="") {
print_out("\nIs this information correct?\n$info\n");
print_out("Type 'return' to start over again, 'exit' to quit this application or any other key to continue...");
$line = get_line();
if (preg_match('/return/i',$line)) main_menu();
elseif (preg_match('/exit|quit|bye/i',$line)) exit;
else return;
}
function print_out($line="") {
if (!$line) return;
echo "$line";
}
function get_line() {
$fh = fopen("php://stdin","r");
$stdin = trim(fgets($fh));
fclose($fh);
return $stdin;
}
?>
Good work, at least it still works on 4.x series, thanks!