Changeset 416
- Timestamp:
- 05/18/10 18:08:12 (15 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r404 r416 20 20 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); 21 21 22 $VERSION = 2. 0;22 $VERSION = 2.6; 23 23 @ISA = qw(Exporter); 24 24 @EXPORT_OK = qw( … … 52 52 our %bigfree; 53 53 our %IPDBacl; 54 55 our $orgname = 'Example Corp'; 56 our $smtphost = 'smtp.example.com'; 57 our $domain = 'example.com'; 54 58 55 59 # Let's initialize the globals. … … 806 810 ## IPDB::mailNotify() 807 811 # Sends notification mail to recipients regarding an IPDB operation 808 sub mailNotify ($$$) { 809 my ($recip,$subj,$message) = @_; 810 my $mailer = Net::SMTP->new("smtp.example.com", Hello => "ipdb.example.com"); 811 812 $mailer->mail('ipdb@example.com'); 813 $mailer->to($recip); 814 $mailer->data("From: \"IP Database\" <ipdb\@example.com>\n", 812 sub mailNotify { 813 my $dbh = shift; 814 my ($action,$subj,$message) = @_; 815 816 # split action into parts for fiddlement. nb: there are almost certainly better ways to do this. 817 my @actionbits = ($action =~ /^(.)(.)(.)$/); 818 819 # want to notify anyone who has specifically requested notify on *this* type ($action as passed), 820 # on "all static IP types" or "all pool types" (and other last-char-in-type groupings), on eg "all DSL types", 821 # and "all events with this action" 822 my @actionsets = ($action); 823 ##fixme: ick, eww. really gotta find a better way to handle this... 824 push @actionsets, ($actionbits[0].'.'.$actionbits[2], 825 $actionbits[0].$actionbits[1].'.', $actionbits[0].'a') if $action =~ /^.{3}$/; 826 827 my $mailer = Net::SMTP->new($smtphost, Hello => "ipdb.$domain"); 828 829 # get recip list from db 830 my $sth = $dbh->prepare("SELECT reciplist FROM notify WHERE action=?"); 831 832 my @reciplist; 833 foreach (@actionsets) { 834 $sth->execute($action); 835 ##fixme - need to handle db errors 836 my ($recipsub) = $sth->fetchrow_array; 837 next if !$recipsub; 838 foreach (split(/,/, $recipsub)) { 839 push @reciplist, $_ if !grep {/^$_$/} @reciplist; 840 } 841 } 842 843 foreach my $recip (@reciplist) { 844 $mailer->mail("ipdb\@$domain"); 845 $mailer->to($recip); 846 $mailer->data("From: \"IP Database\" <ipdb\@$domain>\n", 815 847 "To: $recip\n", 816 848 "Date: ".strftime("%a, %d %b %Y %H:%M:%S %z",localtime)."\n", 817 849 "Subject: {IPDB} $subj\n", 818 850 "X-Mailer: IPDB Notify v".sprintf("%.1d",$IPDB::VERSION)."\n", 819 "Organization: Example Corp\n",851 "Organization: $orgname\n", 820 852 "\n$message\n"); 853 } 821 854 $mailer->quit; 822 855 } -
trunk/cgi-bin/MyIPDB.pm
r320 r416 19 19 } # end connectDB_My() 20 20 21 # Set some globals declared in IPDB.pm. Most of these only affect mailNotify(). 22 # Note that while you *can* leave these at defaults, it's probably a Really Bad Idea. 23 #$IPDB::orgname = "Bob's Big Bonaza"; 24 #$IPDB::smtphost = '127.0.0.1'; 25 #$IPDB::domain = 'bob.com'; 26 21 27 # Keep Perl from complaining. 22 28 1; -
trunk/cgi-bin/admin.cgi
r415 r416 250 250 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ". 251 251 "'$webvar{alloctype}'"; 252 # Notify tech@example.com 253 mailNotify('tech@example.com',"$disp_alloctypes{$webvar{alloctype}} allocation", 252 mailNotify($ip_dbh, "$disp_alloctypes{$webvar{alloctype}} allocation", 254 253 "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer". 255 254 " $webvar{custid}\n". -
trunk/cgi-bin/ipdb.psql
r409 r416 226 226 node_ip inet 227 227 ); 228 229 -- Email notifications on <action> 230 CREATE TABLE notify ( 231 action varchar(5) NOT NULL PRIMARY KEY, 232 reciplist varchar(500) 233 ); -
trunk/cgi-bin/main.cgi
r415 r416 890 890 qq(&ipdb=1&ip=$msg">Add this IP to RADIUS user table</a></div>) 891 891 : "</div>"); 892 # Notify tech@example.com 893 # mailNotify('tech@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation", 894 # "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n". 895 # "Description: $webvar{desc}\n\nAllocated by: $authuser\n"); 892 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation", 893 "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n". 894 "Description: $webvar{desc}\n\nAllocated by: $authuser\n"); 896 895 } else { 897 896 my $netblock = new NetAddr::IP $webvar{fullcidr}; … … 905 904 qq(">Add this netblock to RADIUS user table</a></div>) 906 905 : "</div>"); 907 # mailNotify('nocmgr@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",908 #"$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".909 #"Description: $webvar{desc}\n\nAllocated by: $authuser\n");906 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation", 907 "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n". 908 "Description: $webvar{desc}\n\nAllocated by: $authuser\n"); 910 909 } 911 910 syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ". … … 1224 1223 # If we get here, the operation succeeded. 1225 1224 syslog "notice", "$authuser updated $webvar{block}"; 1226 #mailNotify('nocmgr@example.com',"SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}", 1227 # "$webvar{block} had SWIP status changed to \"Yes\" by $authuser"); 1225 ##fixme: need to wedge something in to allow "update:field" notifications 1226 ## hmm. how to tell what changed? O_o 1227 mailNotify($ip_dbh, 'ua', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}", 1228 "$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on'; 1228 1229 open (HTML, "../updated.html") 1229 1230 or croak "Could not open updated.html :$!"; … … 1401 1402 syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block}". 1402 1403 " $custid, $city, desc='$description'"; 1403 # Notify tech@ when a block/IP is deallocated 1404 # mailNotify('tech@example.com',"REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}", 1405 # "$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n". 1406 # "CustID: $custid\nCity: $city\nDescription: $description\n"); 1407 # mailNotify('nocmgr@example.com',"REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}", 1408 # "$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n". 1409 # "CustID: $custid\nCity: $city\nDescription: $description\n"); 1404 mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}", 1405 "$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n". 1406 "CustID: $custid\nCity: $city\nDescription: $description\n"); 1410 1407 } else { 1411 1408 if ($webvar{alloctype} =~ /^.i$/) { -
trunk/cgi-bin/newcity.cgi
r415 r416 48 48 if ($sth->err) { 49 49 print "Error adding city to database: ".$sth->errstr; 50 # mailNotify('ipdbadmin@example.com',"IPDB city add failure",51 #"$authuser could not add city '$webvar{city}' to database: ".$sth->errstr);50 mailNotify($dbh, 'f:nci', "IPDB city add failure", 51 "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr); 52 52 syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr; 53 53 } else { -
trunk/cgi-bin/newnode.cgi
r397 r416 45 45 if ($sth->err) { 46 46 print "Error adding node to database: ".$sth->errstr; 47 mailNotify( 'noc@example.com',"IPDB node add failure",47 mailNotify($dbh, 'f:nno', "IPDB node add failure", 48 48 "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr); 49 49 syslog "err", "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr;
Note:
See TracChangeset
for help on using the changeset viewer.