Changeset 16
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r15 r16 24 24 @EXPORT_OK = qw( 25 25 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine 26 &getDomRecs &addRec & delRec &domStatus26 &getDomRecs &addRec &updateRec &delRec &domStatus 27 27 %typemap %reverse_typemap 28 28 ); … … 31 31 %EXPORT_TAGS = ( ALL => [qw( 32 32 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &grpName &getSOA &getRecLine 33 &getDomRecs &addRec & delRec &domStatus33 &getDomRecs &addRec &updateRec &delRec &domStatus 34 34 %typemap %reverse_typemap 35 35 )] … … 453 453 454 454 455 ## DNSDB::updateRec() 456 # Update a record 457 sub updateRec { 458 $errstr = ''; 459 my $dbh = shift; 460 my $defrec = shift; 461 my $id = shift; 462 463 # all records have these 464 my $host = shift; 465 my $type = shift; 466 my $val = shift; 467 my $ttl = shift; 468 469 return('FAIL',"Missing standard argument(s)") if !defined($ttl); 470 471 # only MX and SRV will use these 472 my $dist = 0; 473 my $weight = 0; 474 my $port = 0; 475 476 if ($type == $reverse_typemap{MX} || $type == $reverse_typemap{SRV}) { 477 $dist = shift 478 or return ('FAIL',"MX or SRV requires distance"); 479 if ($type == $reverse_typemap{SRV}) { 480 my $weight = shift 481 or return ('FAIL',"SRV requires weight"); 482 my $port = shift 483 or return ('FAIL',"SRV requires port"); 484 } 485 } 486 487 my $sth = $dbh->prepare("UPDATE ".($defrec eq 'y' ? 'default_' : '')."records ". 488 "SET host=?,type=?,val=?,ttl=?,distance=?,weight=?,port=? ". 489 "WHERE record_id=?"); 490 $sth->execute($host,$type,$val,$ttl,$dist,$weight,$port,$id); 491 492 return ('FAIL',$sth->errstr) if $sth->err; 493 494 return ('OK','OK'); 495 } # end updateRec() 496 497 455 498 ## DNSDB::delRec() 456 499 # Delete a record. -
trunk/dns.cgi
r15 r16 177 177 178 178 } elsif ($webvar{page} eq 'record') { 179 179 180 if ($webvar{recact} eq 'new') { 181 180 182 $page->param(todo => "Add record to"); 181 183 $page->param(recact => "add"); 182 stdrecs(); 184 fill_rectypes(); 185 183 186 } elsif ($webvar{recact} eq 'add') { 184 187 … … 191 194 } 192 195 } 193 # wtf?194 # push @recargs,195 196 my ($code,$msg) = addRec(@recargs); 196 197 197 198 if ($code eq 'OK') { 198 199 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}); 199 # showdomain($webvar{defrec},$webvar{parentid});200 # NB: should **really** redirect here, in case of reload. >_< eyowch.201 200 } else { 202 $page->param( add_failed => 1);201 $page->param(failed => 1); 203 202 $page->param(errmsg => $msg); 204 stdrecs($webvar{type}); # populate the form... er, mostly. 205 $page->param(name => $webvar{name}); 206 $page->param(address => $webvar{address}); 207 $page->param(distance => $webvar{distance}) 208 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}); 209 $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV}; 210 $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV}; 211 } 212 213 $page->param(defrec => $webvar{defrec}); 203 fill_recdata(); # populate the form... er, mostly. 204 } 214 205 215 206 } elsif ($webvar{recact} eq 'edit') { 216 207 217 $page->param(todo => "Edit record in"); 208 $page->param(todo => "Update record"); 209 $page->param(recact => "update"); 210 $page->param(parentid => $webvar{parentid}); 211 $page->param(defrec => $webvar{defrec}); 218 212 my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ". 219 213 ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?"); … … 226 220 $page->param(port => $port); 227 221 $page->param(ttl => $ttl); 228 stdrecs($type); 229 } 222 fill_rectypes($type); 223 224 } elsif ($webvar{recact} eq 'update') { 225 226 my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id}, 227 $webvar{name},$webvar{type},$webvar{address},$webvar{ttl}, 228 $webvar{distance},$webvar{weight},$webvar{port}); 229 230 if ($code eq 'OK') { 231 $page->param(failed => 1); 232 $page->param(errmsg => "testing"); 233 $page->param(wastrying => "updating"); 234 $page->param(todo => "Update record"); 235 $page->param(recact => "update"); 236 $page->param(parentid => $webvar{parentid}); 237 $page->param(defrec => $webvar{defrec}); 238 fill_recdata(); 239 # changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}); 240 } else { 241 $page->param(failed => 1); 242 $page->param(errmsg => $msg); 243 $page->param(wastrying => "updating"); 244 $page->param(todo => "Update record"); 245 $page->param(recact => "update"); 246 $page->param(parentid => $webvar{parentid}); 247 $page->param(defrec => $webvar{defrec}); 248 fill_recdata(); 249 } 250 } 251 230 252 if ($webvar{defrec} eq 'y') { 231 $page->param(do main=> "group ".grpName($dbh,$webvar{parentid}));232 } else { 233 $page->param(do main=> domainName($dbh,$webvar{parentid}));253 $page->param(dohere => "group ".grpName($dbh,$webvar{parentid})); 254 } else { 255 $page->param(dohere => domainName($dbh,$webvar{parentid})); 234 256 } 235 257 … … 464 486 } 465 487 466 sub stdrecs { 488 # fill in record type list on add/update/edit record template 489 sub fill_rectypes { 467 490 my $type = shift || $reverse_typemap{A}; 468 491 469 492 my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder"); 470 493 $sth->execute; 471 472 push @debugbits, "DEBUG: type $type\n"; 494 push @debugbits, "type $type"; 473 495 my @typelist; 474 496 while (my ($rval,$rname) = $sth->fetchrow_array()) { … … 478 500 } 479 501 $page->param(typelist => \@typelist); 480 $page->param(domain => domainName($dbh,$webvar{domainid})); 481 $page->param(defrec => $webvar{defrec}); 502 } 503 504 sub fill_recdata { 505 fill_rectypes($webvar{type}); 506 507 $page->param(name => $webvar{name}); 508 $page->param(address => $webvar{address}); 509 $page->param(distance => $webvar{distance}) 510 if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}); 511 $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV}; 512 $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV}; 482 513 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl})); 483 if ($webvar{defrec} eq 'y') {484 ##fixme - should be groupid485 $page->param(parentid => 1);486 } else {487 print "DEBUG: foobar: parentid $webvar{parentid}<br>\n";488 $page->param(parentid => $webvar{parentid});489 }490 514 } 491 515 -
trunk/templates/record.tmpl
r15 r16 5 5 <td align="center"> 6 6 7 <TMPL_IF edit_failed><span class="errmsg">Error <TMPL VAR NAME=recact> record: <TMPL_VARNAME=errmsg></span></TMPL_IF>7 <TMPL_IF failed><div class="errmsg">Error <TMPL_VAR NAME=wastrying> record: <TMPL_VARNAME=errmsg></div></TMPL_IF> 8 8 <form action="dns.cgi" method="POST"> 9 9 <input type="hidden" name="page" value="record"> … … 17 17 18 18 <table border=0 width="100%"> 19 <tr class="tableheader"><td align="center" colspan=2><TMPL_VAR NAME=todo> <TMPL_VAR NAME=domain></td></tr>19 <tr class="tableheader"><td align="center" colspan=2><TMPL_VAR NAME=todo>: <TMPL_VAR NAME=dohere></td></tr> 20 20 <tr class="datalinelight"> 21 21 <td>Hostname</td> … … 51 51 </tr> 52 52 <tr class="datalinelight"> 53 <td colspan=2 align=center><input type="submit" value=" Add record"></td>53 <td colspan=2 align=center><input type="submit" value=" <TMPL_VAR NAME=todo> "></td> 54 54 </tr> 55 55 </table>
Note:
See TracChangeset
for help on using the changeset viewer.