View ¡m../sdba/././bin/check_for_msgs.pl¡n
sub check_for_msgs { my ($in_file, $fline, $alllines, $logfile); my ($prot, $to, $text, $page, $command); #check for any files at all in integration dir foreach (
){ $in_file = $_; if (!-d $in_file) { print "found outgoing message $in_file, processing....\n"; open (DAT, $in_file); my @raw_data=
; close(DAT); $alllines = ''; #stick everything in a single string, newlines and all foreach $fline (@raw_data){ $alllines .= $fline; } #Get stuff from xml tags #might want to use an xml lib in the future if i ever want to really do this clean #protocol is optional if ($alllines =~ m|
(.+)
|i) { $prot = $1; $prot =~ s|\n||g; } else { $prot = $imnet;} #to is not if ($alllines =~ m|
(.+)
|i) { $to = $1; $to =~ s/(\r|\n)//g; } else { $to = "";} #text is not if ($alllines =~ m|
(.+)
|i) { $text = $1; } else { $text = "";} #page is optional if ($alllines =~ m|
(.+)
|i) { $page = $1; $page =~ s/\r|\n//g; } else { $page = "1";} #command is optional if ($alllines =~ m|
(.+)
|i) { $command = $1; $command =~ s/\r|\n//g; } else { $command = "";} print "Ready to send message:\nprot = $prot\nto = $to\ntext = $text\npage = $page\ncommand = $command\n"; #move file out unlink "$in_file" || die "Why can't I delete $in_file in the integration directory?"; #send off the im if it checks out if ($prot eq $imnet && $to ne "" && $text ne "") { $logfile = "integration/done/".$imnet."integration.log"; open (DAT, ">>$logfile"); print DAT time."\n$alllines\n\n"; close (DAT); open (DAT, ">>logs/$to.log"); print DAT "You: $text\n\n"; close (DAT); if ($page == 2) #remember, only works for MSN { SEND_PAGE ($to, $text); } else { SEND_IM ($to, $text); } } elsif ($command ne "") { #look for commands if ($command eq "DIE") { print "Received DIE command via integration, dying!\n"; die; } else { eval("$command"); if ($@) {print $@."\n";} } } else { print "Couldn't send outgoing message... make sure protocol is right and that
and
are not empty.\n"; } } } #SEND_IM(@_); } 1;