Changeset 195
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r193 r195 98 98 99 99 # Prepopulate a basic config. Note some of these *will* cause errors if left unset. 100 # note: add appropriate stanzas in loadConfig to parse these 100 101 our %config = ( 101 102 # Database connection info … … 107 108 # Email notice settings 108 109 mailhost => 'smtp.example.com', 109 mailsender => 'dnsdb@example.com', 110 mailnotify => 'dnsdb@example.com', # to 111 mailsender => 'dnsdb@example.com', # from 110 112 mailname => 'DNS Administration', 113 orgname => 'Example Corp', 114 domain => 'example.com', 111 115 112 116 # Template directory … … 116 120 117 121 # Session params 118 timeout => '3600' # 1 hour default 122 timeout => '3600', # 1 hour default 123 124 # Other miscellanea 125 log_failures => 1, # log all evarthing by default 119 126 ); 120 127 … … 150 157 "Error opening site config file $siteconfig"; 151 158 return; 159 } 160 } 161 162 # Munge log_failures. 163 if ($config{log_failures} ne '1' && $config{log_failures} ne '0') { 164 # true/false, on/off, yes/no all valid. 165 if ($config{log_failures} =~ /^(?:true|false|on|off|yes|no)$/) { 166 if ($config{log_failures} =~ /(?:true|on|yes)/) { 167 $config{log_failures} = 1; 168 } else { 169 $config{log_failures} = 0; 170 } 171 } else { 172 $errstr = "Bad log_failures setting $config{log_failures}"; 173 $config{log_failures} = 1; 174 # Bad setting shouldn't be fatal. 175 # return 2; 152 176 } 153 177 } … … 190 214 # Mail settings 191 215 $config{mailhost} = $1 if /^mailhost\s*=\s*([a-z0-9_.-]+)/i; 216 $config{mailnotify} = $1 if /^mailnotify\s*=\s*([a-z0-9_.@-]+)/i; 192 217 $config{mailsender} = $1 if /^mailsender\s*=\s*([a-z0-9_.@-]+)/i; 193 218 $config{mailname} = $1 if /^mailname\s*=\s*([a-z0-9\s_.-]+)/i; 219 $config{orgname} = $1 if /^orgname\s*=\s*([a-z0-9\s_.,'-]+)/i; 220 $config{domain} = $1 if /^domain\s*=\s*([a-z0-9_.-]+)/i; 194 221 # session - note this is fed directly to CGI::Session 195 222 $config{timeout} = $1 if /^[tT][iI][mM][eE][oO][uU][tT]\s*=\s*(\d+[smhdwMy]?)/; 223 # log failed actions 224 $config{log_failures} = $1 if /^log_failures\s*=\s*([a-z01]+)/i; 196 225 } 197 226 close CFG; … … 496 525 ##fixme: need better way(s?) to snag userinfo for log entries. don't want to have 497 526 # to pass around yet *another* constant (already passing $dbh, shouldn't need to) 527 my $fullname; 498 528 if (!$user_id) { 499 $user_id, $fullname) = $dbh->fetchrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".529 ($user_id, $fullname) = $dbh->selectrow_array("SELECT user_id, firstname || ' ' || lastname FROM users". 500 530 " WHERE username=?", undef, ($username)); 501 531 } elsif (!$username) { 502 $username, $fullname) = $dbh->fetchrow_array("SELECT username, firstname || ' ' || lastname FROM users". 532 ($username, $fullname) = $dbh->selectrow_array("SELECT username, firstname || ' ' || lastname FROM users". 533 " WHERE user_id=?", undef, ($user_id)); 534 } else { 535 ($fullname) = $dbh->selectrow_array("SELECT firstname || ' ' || lastname FROM users". 503 536 " WHERE user_id=?", undef, ($user_id)); 504 537 } -
trunk/dns.cgi
r193 r195 350 350 changepage(page => "reclist", id => $msg); 351 351 } else { 352 logaction(0, $session->param("username"), $webvar{group}, "Failed adding domain $webvar{domain} ($msg)"); 352 logaction(0, $session->param("username"), $webvar{group}, "Failed adding domain $webvar{domain} ($msg)") 353 if $config{log_failures}; 353 354 $session->param('add_failed', 1); 354 355 ##fixme: domain a security risk for XSS? … … 383 384 changepage(page => "domlist", resultmsg => "Deleted domain $dom"); 384 385 } else { 385 logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)"); 386 logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)") 387 if $config{log_failures}; 386 388 changepage(page => "domlist", errmsg => "Error deleting domain $dom: $msg"); 387 389 } … … 520 522 if ($webvar{defrec} eq 'y') { 521 523 my $restr = "Added default record '$webvar{name} $typemap{$webvar{type}}"; 522 $restr .= " [distance $dist]" if $typemap{$webvar{type}} eq 'MX'; 523 $restr .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$webvar{type}} eq 'SRV'; 524 $restr .= " [distance $webvar{distance}]" if $typemap{$webvar{type}} eq 'MX'; 525 $restr .= " [priority $webvar{distance}] [weight $webvar{weight}] [port $webvar{port}]" 526 if $typemap{$webvar{type}} eq 'SRV'; 524 527 $restr .= " $webvar{address}', TTL $webvar{ttl}"; 525 528 logaction(0, $session->param("username"), $webvar{parentid}, $restr); 526 529 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr); 527 530 } else { 528 my $restr = "Added record '$webvar{name} $typemap{$webvar{type}}". 529 $restr .= " [distance $dist]" if $typemap{$webvar{type}} eq 'MX'; 530 $restr .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$webvar{type}} eq 'SRV'; 531 my $restr = "Added record '$webvar{name} $typemap{$webvar{type}}"; 532 $restr .= " [distance $webvar{dist}]" if $typemap{$webvar{type}} eq 'MX'; 533 $restr .= " [priority $webvar{dist}] [weight $webvar{weight}] [port $webvar{port}]" 534 if $typemap{$webvar{type}} eq 'SRV'; 531 535 $restr .= " $webvar{address}', TTL $webvar{ttl}"; 532 536 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), $restr); … … 543 547 $page->param(id => $webvar{id}); 544 548 fill_recdata(); # populate the form... er, mostly. 545 if ($webvar{defrec} eq 'y') { 546 logaction(0, $session->param("username"), $webvar{parentid}, 549 if ($config{log_failures}) { 550 if ($webvar{defrec} eq 'y') { 551 logaction(0, $session->param("username"), $webvar{parentid}, 547 552 "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)"); 548 549 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),553 } else { 554 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 550 555 "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)"); 556 } 551 557 } 552 558 } … … 610 616 $page->param(id => $webvar{id}); 611 617 fill_recdata(); 612 if ($webvar{defrec} eq 'y') { 613 logaction(0, $session->param("username"), $webvar{parentid}, 618 if ($config{log_failures}) { 619 if ($webvar{defrec} eq 'y') { 620 logaction(0, $session->param("username"), $webvar{parentid}, 614 621 "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)"); 615 616 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),622 } else { 623 logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), 617 624 "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)"); 625 } 618 626 } 619 627 } … … 669 677 } else { 670 678 ## need to find failure mode 671 if ($webvar{defrec} eq 'y') { 672 logaction(0, $session->param("username"), $rec->{parid}, 679 if ($config{log_failures}) { 680 if ($webvar{defrec} eq 'y') { 681 logaction(0, $session->param("username"), $rec->{parid}, 673 682 "Failed deleting default record '$rec->{host} $typemap{$rec->{type}} $rec->{val}',". 674 683 " TTL $rec->{ttl} ($msg)"); 675 676 logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'),684 } else { 685 logaction($rec->{parid}, $session->param("username"), parentID($rec->{parid}, 'dom', 'group'), 677 686 "Failed deleting record '$rec->{host} $typemap{$rec->{type}} $rec->{val}', TTL $rec->{ttl} ($msg)"); 687 } 678 688 } 679 689 changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, … … 740 750 $page->param(msg => $DBI::errstr); 741 751 fillsoa($webvar{defrec},$webvar{id}); 752 ##fixme: faillog 742 753 } else { 743 754 … … 820 831 } 821 832 } # fallthrough else 822 logaction(0, $session->param("username"), $webvar{pargroup}, "Failed to add group $webvar{newgroup}: $msg"); 833 logaction(0, $session->param("username"), $webvar{pargroup}, "Failed to add group $webvar{newgroup}: $msg") 834 if $config{log_failures}; 823 835 # no point in doing extra work 824 836 fill_permissions($page, \%newperms); … … 864 876 } else { 865 877 # need to find failure mode 866 logaction(0, $session->param("username"), $delparent, "Failed to delete group $deleteme: $msg"); 878 logaction(0, $session->param("username"), $delparent, "Failed to delete group $deleteme: $msg") 879 if $config{log_failures}; 867 880 changepage(page => "grpman", errmsg => "Error deleting group $deleteme: $msg"); 868 881 } … … 913 926 } # fallthrough else 914 927 logaction(0, $session->param("username"), $webvar{gid}, "Failed to update default permissions in group ". 915 groupName($dbh, $webvar{gid}).": $msg"); 928 groupName($dbh, $webvar{gid}).": $msg") 929 if $config{log_failures}; 916 930 # no point in doing extra work 917 931 fill_permissions($page, \%chperms); … … 1002 1016 } else { 1003 1017 logaction($webvar{$_}, $session->param("username"), parentID($webvar{$_}, 'dom', 'group'), 1004 "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg"); 1018 "Failed to move domain ".domainName($dbh, $webvar{$_})." to group $newgname: $msg") 1019 if $config{log_failures}; 1005 1020 } 1006 1021 $row{domerr} = $msg; … … 1059 1074 $row{domok} = ($code eq 'OK'); 1060 1075 } else { 1061 logaction($webvar{$_}, $session->param("username"), $pargroup, "Failed to delete domain $dom: $msg"); 1076 logaction($webvar{$_}, $session->param("username"), $pargroup, "Failed to delete domain $dom: $msg") 1077 if $config{log_failures}; 1062 1078 } 1063 1079 $row{domerr} = $msg; … … 1251 1267 fill_clonemelist(); 1252 1268 logaction(0, $session->param("username"), $curgroup, "Failed to $webvar{action} user ". 1253 "$webvar{uname}: $msg"); 1269 "$webvar{uname}: $msg") 1270 if $config{log_failures}; 1254 1271 } 1255 1272 … … 1330 1347 list_users($curgroup); 1331 1348 logaction(0, $session->param("username"), $curgroup, "Failed to delete user ". 1332 "$webvar{id}/".$userref->{username}.": $msg"); 1349 "$webvar{id}/".$userref->{username}.": $msg") 1350 if $config{log_failures}; 1333 1351 } 1334 1352 } else {
Note:
See TracChangeset
for help on using the changeset viewer.