HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Installation/Configuration (
-   -   Bulk add DNS Records (

flevoict 25th March 2010 14:23

Bulk add DNS Records
Dear all,

I hope somebody can help.

We have installed a third NS server in an other datacenter. Now I want to add an extra NS record to all my domains in ISP config (about 50 domains).

Does somebody know how to do this in bulk, like add a record with mysql or something like that.

I hope somebody can help me so I don't have to this manually. :mad:


Bas aka Flevoict

till 25th March 2010 22:14

You can do this e.g. with a script that uses the datalogInsert function from the ispconfig mysql library to insert the records in the database.

flevoict 26th March 2010 11:09

Thanks Till for your reply.

Now I have the following issue, I'm not really a database/mysql programmer, more a network engineer who has to manage these things as well.

Is there somebody who can point me in the right direction with the sql script.

Thnx in advance.


SamTzu 26th March 2010 19:48

I just updated our MyDNS sync script.

BorderAmigos 28th May 2010 17:08

What and where is the "ispconfig mysql library"? I will write a script for it if I can find it. :)

till 28th May 2010 17:17

The ISPConfig mysql library is here:


Your php script should look like this (untested, partly pseudo code):




$db = new db;

$tablename = "database_table_name";
$insert_data = "(a,b,c) values ('a','b','c')";
$index_field = "dbtable_index_field_name";

$db->datalogInsert($tablename, $insert_data, $index_field);


The content of the variables has to be changed to match the data and table that you want to modify.

BorderAmigos 28th May 2010 18:50

This is the script I came up with. There are no errors in any logs but it doesn't appear to work as the mail_content_filter table stays empty. Putting it here to see if someone can see what's not working...


// Note:  These includes and their ancestor directories needed 755 permissions

$tablename = "mail_content_filter";  // I emptied this table first using phpMyAdmin
$index_field = "content_filter_id";
$db = new db;

print "Running... ";
$dataFile = fopen("./mail_content_filters.csv", "rb");
while (!feof($dataFile) ) {
        $mailFilters = fgets($dataFile);
        $dVal = explode(',', $mailFilters);
        $insert_data = "content_filter_id,sys_userid,sys_groupid,sys_perm_user,sys_perm_group,sys_perm_other,server_id,type,pattern,data,action,active";
        $insert_data .= " values ";
        $insert_data .= "$dVal[0],$dVal[1],$dVal[2],$dVal[3],$dVal[4],$dVal[5],$dVal[6],$dVal[7],$dVal[8],$dVal[9],$dVal[10],$dVal[11]";
        $db->datalogInsert($tablename, $insert_data, $index_field);
print " Finished!<br>";

mail_content_filters.csv (partial)

1,1,1,riud,riud,,1,body,"/^(Content-Type:.*|\s+)charset\s*=\s*""?(big5|euc-kr|gb2312|koi8|ks_c_5601-1987|Windows-1251)""?/",No foreign character sets please.,REJECT,y
2,1,1,riud,riud,,1,body,"/(filename|name)="".*\..*""$/",No files of type $1 allowed here.,REJECT,y
3,1,1,riud,riud,,1,body,"/(filename|name)=""(music*|dhcp*|Emanuel|kmbfejkm|Na kedWife|Seicho_no_ie|JAMGCJJA|Happy99|Navidad|pret typark|pretty|data|WTC|wtc|README)\.EXE""/",Known virus names,REJECT,y
4,1,1,riud,riud,,1,body,"/(filename|name)=""(doc|body|file)\.scr""/",Known for MyDoom virus names 1,REJECT,y
5,1,1,riud,riud,,1,body,"/(filename|name)=""(document|message|body|text|test) \.pif""/",Known for MyDoom virus names 2,REJECT,y
6,1,1,riud,riud,,1,body,"/(filename|name)=""(document|message|body|text|test) \.zip""/",Known for MyDoom virus names 3,REJECT,y
7,1,1,riud,riud,,1,body,/important information regarding your email address/,Possible W32_Mlmaill@MM,REJECT,y
8,1,1,riud,riud,,1,body,/mailto:.*\@.*\?subject\=(3D)*(remove|removeme|plea sedelete|pleaseremove|deleteme)+/,Lets just say we are removing now.,REJECT,y
9,1,1,riud,riud,,1,body,/.*\@.*\.ru/,No foreign character sets from ru please.,REJECT,y
10,1,1,riud,riud,,1,body,/.*\@.*\.bg/,No foreign character sets from bg please.,REJECT,y
11,1,1,riud,riud,,1,body,/.*\@.*\.it/,No foreign character sets from it please.,REJECT,y
12,1,1,riud,riud,,1,body,/.*\@.*\.au/,No foreign character sets from au please.,REJECT,y

till 28th May 2010 18:56


// Note: These includes and their ancestor directories needed 755 permissions
No, do do this or you open up your system for hackers! Please restore the permissions on your system. The permissions must stay as they are. You have to execute your script as root or ispconfig to be able to include the files.

Regarding your script, you missed a few () and also you missed to quote the content:


$insert_data = "(content_filter_id,sys_userid,sys_groupid,sys_perm_user,sys_perm_group,sys_perm_other,server_id,type,pattern,data,action,active)";
        $insert_data .= " values ";
        $insert_data .= "('$dVal[0]','$dVal[1]','$dVal[2]','$dVal[3]','$dVal[4]','$dVal[5]','$dVal[6]','$dVal[7]','$dVal[8]','$dVal[9]','$dVal[10]','$dVal[11]')";

BorderAmigos 28th May 2010 19:09

The permissions were only temporary.

I had tried both with and without the ().

Now it gives:
Fatal error: Call to a member function quote() on a non-object in /usr/local/ispconfig/interface/lib/classes/ on line 280


OK, got it working but had to modify the ISPConfig 3 code slightly. Not sure if the modification is a work around or a bug fix. Will leave that to others to decide.

in /usr/local/ispconfig/interface/lib/classes/ the $old_rec variable is empty and not being seen as an object. Added the line "$old_rec = $new_rec;" as shown below to define it and now my script works. Comments? Does this break something else?

        public function datalogInsert($tablename, $insert_data, $index_field) {
                global $app;
                $old_rec = array();
                $this->query("INSERT INTO $tablename $insert_data");
                $index_value = $this->insertID();
                $new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
                $old_rec = $new_rec;  // Added.
                $this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
                return $index_value;

Also added a shell script so can be run as root instead of from the web server. When there is confirmation that this doesn't break something else I'll post the full scripts with the entire mail_content_filters.csv attached.

till 28th May 2010 20:49

Yes, the $app object from ispconfig is missing. Changing all accurrences in the diffrec function from:




in the mysql class should fix this.

All times are GMT +2. The time now is 14:57.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.