Changeset 416 for trunk/cgi-bin/IPDB.pm
- Timestamp:
- 05/18/10 18:08:12 (14 years ago)
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.