#!/usr/bin/perl use strict; use IO::Socket; use POSIX; use warnings; use MIME::Lite; use Config::Simple; use Win32(); sub logMonitor{ # Reading configuration parameters from the config.ini file my $cfg = new Config::Simple(); $cfg->read('config.ini'); my $HOST = $cfg->param("pbx"); my $COMPANY = $cfg->param("company"); my $COMMUNITY = $cfg->param("community"); my $PORT = $cfg->param("port"); for(;; ){ my $sock = new IO::Socket::INET(PeerAddr => $HOST, PeerPort => $PORT,Proto => "tcp",) or die "Cannot connect to PBX at address: $HOST port: $PORT: $!"; while (<$sock>) { s/^\0+//; # Remove leading null characters print $_; chomp ($_); if ($_ =~m"Emergency Call From Extension") { filePrint(); } } } } #End of monitor subroutine sub filePrint{ #write data to file with date and time stamp my $data = $_; print $data; my $file = strftime '%Y-%m-%d_%H-%M-%S.txt', localtime; if (-f $file){ open (my $fh,'>>', $file); print $fh "$_"; close $file; } else { open (my $fh,'>', $file); print $fh "$_"; close $file; } }# End of filePrint routine sub keepAlive{ while () { sleep 20; print " It's alive!!!"; } } #print disclaimer and wait for "y" to continue or exit my $disclaimer = "disclaimer.txt"; open(my $fh, '<:encoding(UTF-8)', $disclaimer) or die "Could not open file '$disclaimer' $!"; while (my $row = <$fh>) { chomp $row; Win32::MsgBox($row); } print "\nDo you accept this disclaimer and continue at your own risk?(Y/N)?"; # first question yes/no my $input = ; chomp $input; if ($input =~ m/^[Y]$/i){ # Start of processing logMonitor(); #Open the log monitoring subroutine keepAlive(); #start the alive email message }