Changeset 18 for trunk/DNSDB.pm
- Timestamp:
- 10/08/09 17:29:50 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r17 r18 23 23 @ISA = qw(Exporter); 24 24 @EXPORT_OK = qw( 25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName & grpName &getSOA &getRecLine26 &get DomRecs &addRec &updateRec &delRec &domStatus25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA 26 &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 27 27 %typemap %reverse_typemap 28 28 ); … … 30 30 @EXPORT = (); # Export nothing by default. 31 31 %EXPORT_TAGS = ( ALL => [qw( 32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName & grpName &getSOA &getRecLine33 &get DomRecs &addRec &updateRec &delRec &domStatus32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA 33 &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus 34 34 %typemap %reverse_typemap 35 35 )] … … 256 256 257 257 258 ## DNSDB::addGroup() 259 # Add a group 260 # Takes a database handle, group name, parent group, and template-vs-cloneme flag 261 # Returns a status code and message 262 sub addGroup { 263 $errstr = ''; 264 my $dbh = shift; 265 my $grpname = shift; 266 my $pargrp = shift; 267 268 # 0 indicates "template", hardcoded. 269 # Any other value clones that group's default records, if it exists. 270 my $torc = shift || 0; 271 272 # Allow transactions, and raise an exception on errors so we can catch it later. 273 # Use local to make sure these get "reset" properly on exiting this block 274 local $dbh->{AutoCommit} = 0; 275 local $dbh->{RaiseError} = 1; 276 277 # Wrap all the SQL in a transaction 278 eval { 279 my $sth = $dbh->prepare("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)"); 280 $sth->execute($pargrp,$grpname); 281 282 $sth = $dbh->prepare("SELECT group_id FROM groups WHERE group_name=?"); 283 $sth->execute($grpname); 284 my ($grpid) = $sth->fetchrow_array(); 285 286 $sth = $dbh->prepare("INSERT INTO default_records (group_id,host,type,val,distance,weight,port,ttl) ". 287 "VALUES ($grpid,?,?,?,?,?,?,?)"); 288 if ($torc) { 289 my $sth2 = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?"); 290 while (my @clonedata = $sth2->fetchrow_array) { 291 $sth->execute(@clonedata); 292 } 293 } else { 294 # reasonable basic defaults for SOA, MX, NS, and minimal hosting 295 # could load from a config file, but somewhere along the line we need hardcoded bits. 296 $sth->execute('ns1.example.com:hostmaster.example.com', 6, '10800:3600:604800:10800', 0, 0, 0, 86400); 297 $sth->execute('DOMAIN', 1, '192.168.4.2', 0, 0, 0, 7200); 298 $sth->execute('DOMAIN', 15, 'mx.example.com', 10, 0, 0, 7200); 299 $sth->execute('DOMAIN', 2, 'ns1.example.com', 0, 0, 0, 7200); 300 $sth->execute('DOMAIN', 2, 'ns2.example.com', 0, 0, 0, 7200); 301 $sth->execute('www.DOMAIN', 5, 'DOMAIN', 0, 0, 0, 7200); 302 } 303 304 die "epic FAIL.. hahahah, just testing!\n"; 305 # once we get here, we should have suceeded. 306 $dbh->commit; 307 }; # end eval 308 309 if ($@) { 310 my $msg = $@; 311 eval { $dbh->rollback; }; 312 return ('FAIL',$msg); 313 } else { 314 return ('OK','OK'); 315 } 316 317 } # end addGroup() 318 319 258 320 ## DNSDB::grpName() 259 321 # Return the group name based on a group ID
Note:
See TracChangeset
for help on using the changeset viewer.