{"id":28,"date":"2008-09-22T12:30:46","date_gmt":"2008-09-22T17:30:46","guid":{"rendered":"http:\/\/xux.in\/blog\/?p=28"},"modified":"2021-06-19T19:47:38","modified_gmt":"2021-06-20T01:47:38","slug":"addremove-multiple-dns-zones-for-ensim-4x","status":"publish","type":"post","link":"http:\/\/xux.in\/blog\/post\/addremove-multiple-dns-zones-for-ensim-4x\/","title":{"rendered":"Add\/Remove multiple DNS zones for Ensim 4.x"},"content":{"rendered":"<p>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&#8217;ll come back to thank me \ud83d\ude1b<\/p>\n<p>Basicly, the script asks you for 2 options:<\/p>\n<pre lang=\"cmd\">What do you want to do?\n[1] Add zone(s)\n[2] Delete zone(s)<\/pre>\n<p>Then, you&#8217;ll need to write the domain(s) separated by spaces and also the IP address and that&#8217;s all. By default it uses Ensim&#8217;s DNS zone template but you can change it to whatever you want.<\/p>\n<p>File: mdns.php<\/p>\n<pre lang=\"php\">#!\/usr\/bin\/php -q\n&lt;?\n\/\/ This settings should be OK!\n\/\/ Add more if you need ;)\ndefine('DEBUG',true); \/\/ make it 'false' if you want to see it work\ndefine('DPATH','\/usr\/lib\/opcenter\/bind\/');\ndefine('ADD',DPATH.'add_zone');\ndefine('REM',DPATH.'remove_zone');\ndefine('AA',DPATH.'add_a');\ndefine('AMX',DPATH.'add_mx');\n\nmain_menu();\n\nfunction main_menu() {\n?--&gt;\nWhat do you want to do?\n[1] Add zone(s)\n[2] Delete zone(s)\nOption: <!--?\n\t$option = get_line();\n\tswitch ($option) {\n\t\tcase \"1\":\n\t\t\t$__domains = option_domains();\n\t\t\t$__ip = option_ip();\n\t\t\toption_confirm();\n\t\t\tadd_domains($__domains,$__ip);\n\t\tbreak;\n\t\tcase \"2\":\n\t\t\t$__domains = option_domains();\n\t\t\toption_confirm();\n\t\t\trem_domains($__domains);\n\t\tbreak;\n\t\tdefault:\n\t\t\tmain_menu();\n\t}\n}\n\nfunction add_domains($domains=array(),$ip=\"\") {\n\tif (!$domains[0] || !$ip) {\n\t\tprint_out(\"\\nThere are no domain(s) or ip, please start again <ENTER-->\\n\");\n\t\tget_line();\n\t\tmain_menu();\n\t\treturn;\n\t}\n\tforeach ($domains as $k =&gt; $v) {\n\t\tprint_out(\"\\nAdding Zone $v ...\\n\");\n\t\tecmd(ADD.\" -f \".$v);\n\t\tprint_out(\"\\nAdding A (www,ftp,mail) and MX records ...\\n\");\n\t\tecmd(AA.\" -u $v $ip\");\n\t\tecmd(AA.\" -z $v www $ip\");\n\t\tecmd(AA.\" -z $v ftp $ip\");\n\t\tecmd(AA.\" -z $v mail $ip\");\n\t\tecmd(AMX.\" $v mail.\".$v.\" 10\");\n\t}\n}\n\nfunction rem_domains($domains=array()) {\n\tif (!$domains[0]) {\n\t\tprint_out(\"\\nThere are no domain(s), please start again <enter>\\n\");\n\t\tget_line();\n\t\tmain_menu();\n\t\treturn;\n\t}\n\tforeach ($domains as $k =&gt; $v) {\n\t\tprint_out(\"\\nRemoving Zone $v ...\\n\");\n\t\tecmd(REM.\" \".$v);\n\t}\n}\n\nfunction ecmd($cmd=\"\") {\n\tif (!$cmd) {\n\t\techo \"Nothing to execute!\\n\";\n\t\treturn;\n\t}\n\t$cmd = escapeshellcmd($cmd);\n\tprint_out(\"\\t$cmd\\n\");\n\tif (!DEBUG) {\n\t\t$out = `$cmd 2&gt;&amp;1`;\n\t}\n}\n\nfunction option_domains() {\n\tprint_out(\"\\nEnter domain or domains separated by spaces or comas:\\n\");\n\t$line = get_line();\n\t$domains = preg_split('\/\\s+|,\/',$line,-1,PREG_SPLIT_NO_EMPTY);\n\tif (!$domains[0]) {\n\t\tprint_out(\"\\nYou need to enter at least one domain name, press any key to continue...\");\n\t\tget_line();\n\t\tmain_menu();\n\t}\n\tprint_out(\"\\nCheck your information submitted: \");\n\t$i = 1;\n\tforeach ($domains as $k =&gt; $v) {\n\t\techo \"($i)$v \";\n\t\t$i++;\n\t}\n\tprint_out(\"\\n\");\n\treturn $domains;\n}\n\nfunction option_ip() {\n\tprint_out(\"\\nEnter the IP: \");\n\t$line = get_line();\n\tif (!$line) {\n\t\tprint_out(\"\\nYou need to enter an IP, press any key to continue...\");\n\t\tget_line();\n\t\tmain_menu();\n\t}\n\tprint_out(\"\\nCheck your information submitted: $line\\n\");\n\treturn $line;\n}\n\nfunction option_confirm($info=\"\") {\n\tprint_out(\"\\nIs this information correct?\\n$info\\n\");\n\tprint_out(\"Type 'return' to start over again, 'exit' to quit this application or any other key to continue...\");\n\t$line = get_line();\n\tif (preg_match('\/return\/i',$line)) main_menu();\n\telseif (preg_match('\/exit|quit|bye\/i',$line)) exit;\n\telse return;\n}\n\nfunction print_out($line=\"\") {\n\tif (!$line) return;\n\techo \"$line\";\n}\n\nfunction get_line() {\n\t$fh = fopen(\"php:\/\/stdin\",\"r\");\n\t$stdin = trim(fgets($fh));\n\tfclose($fh);\n\treturn $stdin;\n}\n?&gt;<\/enter><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;ll come back to thank me \ud83d\ude1b Basicly, the script asks you for 2 options: What do you want to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,10,8],"tags":[13,32,33,15,20,16],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-code","category-ensim","category-linux","tag-centos","tag-ensim","tag-linux","tag-php","tag-rhel","tag-snippet"],"_links":{"self":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":4,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":153,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/153"}],"wp:attachment":[{"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xux.in\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}