Registrazione Chiamate

Questa è una vecchia versione del documento!


Registrazione Chiamate

Requisiti

Software

  • IndigoPerl
  • Oreka
  • Mysql
  • Tomcat

Moduli Perl

Una volta installato IndigoPerl entrate nella root e aprite il collegamento al “Perl GUI Package Manager” e controllate la presenza dei seguenti moduli:

  • Archive-Tar-1.38
  • Compress-Zlib-2.008
  • DBD-mysql-4.005
  • DBD-mysqlPP-0.04
  • DBI-1.601
  • file-remove-1.40
  • HTML-Parser-1.06
  • IO-Zlib-1.09
  • Net-Mysql-0.09
  • TimeDate-1.16
  • URI-1.35
  • Win32-API-0.47
  • Win32-GUI-1.03
  • libwin32-0.28
  • libwww-perl-5.808
  • modperl-2.0

Se ne manca qualcuno installatelo dal package manager

Configurazione

Oreka

Va bene la configurazione Standard a parte che per il parametro <AudioOutputPath> che deve essere una cartella temporanea e non quella definitiva all'interno della root di Tomcat,i file saranno spostati nella cartella definitiva dallo script perl.

Es. <AudioOutputPath>C:/tmp</AudioOutputPath>

Script per telefoni Cisco

Queste sono le righe da configurare

 ####### Costanti Database 
  
 my $database = "oreka";
 
 my $hostname = "localhost";
  
 my $user = "root";
 
 my $password = "123456";
 
 ###################

Script per pulizia Database/Cartelle

Modificare le seguenti righe:

 #######Costanti File 
 
 #Path di origine dei file, bisogna impostare la stessa cartella impostata in Oreka

 my $origpath = '/Programmi/Apache Software Foundation/Tomcat 5.5/webapps/tmp/';

 #Path di destinazione dei file, deve essere impostata la root di apache
 
 my $destpath = '/Programmi/Apache Software Foundation/Tomcat 5.5/webapps';

 ####### Costanti Database 
 
 my $database = "oreka";

 my $hostname = "10.255.0.19";

 my $user = "root";

 my $password = "123456";
 
 my $tablePS = "recservice";

 my $tableOrekaTape = "rectape";

 my $tableOrekaSeg = "recsegment";

 my $tableDef = "recfromservice";

Sorgente Script Perl

Servizio per telefoni Cisco

 #!/usr/bin/perl
 
 ###################################################################################
 
 # Created by: Marco Longo, marchrist85@gmail.com
 
 # Created by: Ergon2000, www.ergon2000.it
 
 # Date: 03/02/2009
 
 ##############################
 
 #Questo script riceve una richiesta http da un telefono cisco, ne legge l'ip e si connette alla pagina xml StreamingStatisticsX generata dal telefon
 
 #da essa ricava l'indirizzo e la porta del sorgente della conversazione e l'indirizzo e la porta del destinatario, questi dati vengono registrati su
 
 #un database mysql con il relativo timestamp 
 
 ####################################################################################
 
 
 
 
 
 use Cisco::IPPhone; 
 
 use XML::Simple;
 
 use LWP::Simple;
 
 use Data::Dumper;
 
 # use strict;
 
 use DBI;
 
 $|++;
 
 use CGI;
 
 
 
 ####### Costanti Database 
 
 my $database = "oreka";
 
 my $hostname = "localhost";
 
 my $user = "root";
 
 my $password = "123456";
 
 ###################
 
 
 
 ###Carico pagina web e prendo indirizzo ip client
 
 
 
 my $cgi = CGI->new;
 
 map { "$_\t$ENV{$_}\n" } keys %ENV ;
 
 my $remoteip = $ENV{'REMOTE_ADDR'};
 
 
 
 ###############################
 
 # my $count = 0;
 
 my $response;
 
 
 
 ####Recupero dati conversazione######
 
 my $url = "http://$remoteip/StreamingStatisticsX";   #da modificare 
 
 my $response = get($url);
 
 $response =~ s///;    #Sostituisco
 
 # while ($response = get($url) or $count == 10){
 
             # $response = get($url);
 
             # $count = $count + 1;
 
 # }
 
 my $xs = XML::Simple->new(ForceArray => 1, KeepRoot => 1, KeyAttr=>[]);
 
 my $tmp = eval { $xs->XMLin($response)};
 
 # if ($@) {
 
   # while ($@){
 
 			 # my $tmp = eval { $xs->XMLin($response)};
 
        # }
 
 # }
 
 my $localip = @{$tmp -> {StreamingStatistics}}[0]->{LocalAddr}[0];
 
 my $remoteip = @{$tmp -> {StreamingStatistics}}[0]->{RemoteAddr}[0];
 
 my $message = "registrazione In Corso";
 
 #################################
 
 
 
 ##############
 
 
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
 
 my $timestamp = ($year+1900) ."-". ($month+1) ."-". $mday ." ". $hour .":". $min .":". $sec; 
 
 
 
 # print ($tmp);
 
 # print Dumper($tmp);
 
 
 
 ##### Inserisco dati nel DB ######
 
 $localip =~ s/\//,/;    #Sostituisco / con ,
 
 $remoteip =~ s/\//,/;
 
 
 
 my $dbh = DBI->connect("DBI:mysql:dbname=$database;host=$hostname",$user,$password,{'RaiseError' => 1});
 
 $dbh->do("INSERT INTO recservice (timestamp, recport, remoteport)VALUES (\"$timestamp\",\"$localip\",\"$remoteip\")") or $message ="Registrazione fallita, riprovare" ;
 
 $dbh ->disconnect();
 
 
 
 
 #my $sth = $dbh->prepare("INSERT INTO recservice VALUES ($timestamp,$localip)") or die(mysql_error());
 
 #$sth ->execute();
 
 
 
 my $mytext = new Cisco::IPPhone;
 
 $mytext->Text({ Title => "Registrazione", Prompt => $remoteip, Text => "Registrazione in corso" });
 
 $mytext->AddSoftKeyItem( { Name => "Exit", URL => "SoftKey:Exit", Position => "2" });
 
 print $mytext->Content;

Servizio temporizzato per pulire database e cartella

 #!/usr/bin/perl
 
 ###################################################################################
 
 # Created by: Marco Longo, marchrist85@gmail.com
 
 # Created by: Ergon2000, www.ergon2000.it
 
 # Date: 03/02/2009
 
 ##############################
 
    
 use DBI;
 
 use strict;
 
 use File::Copy;
 
 use File::Path;
 
 use File::Remove 'remove';
 
 
 
 #######Costanti File 
 
 my $origpath = '/Programmi/Apache Software Foundation/Tomcat 5.5/webapps/';
 
 my $destpath = '/Programmi/Apache Software Foundation/Tomcat 5.5/webapps/tmp/';
 
 #$origpath =~ s/ /\\ /g;
 
 #$destpath =~ s/ /\\ /g;
 
 
 ####### Costanti Database 
 
 my $database = "oreka";
 
 my $hostname = "10.255.0.19";
 
 my $user = "root";
 
 my $password = "123456";
 
 my $tablePS = "recservice";
 
 my $tableOrekaTape = "rectape";
 
 my $tableOrekaSeg = "recsegment";
 
 my $tableDef = "recfromservice";
 
 ###################
 
 
 my @row;
 
 my @rowdbrec;
 
 
 
 ######################################## Lavoro sul DB ######
 
 my $dbh = DBI->connect("DBI:mysql:dbname=oreka;host=$hostname",$user,$password,{'RaiseError' => 1}) or die "Can't connect to database: $DBI::errstr!";
 
 my $sth = $dbh->prepare("SELECT * FROM $tablePS") or die "Can't prepare SQL statement: $DBI::errstr\n";
 
 $sth -> execute() or die "Can't execute SQL statement: $DBI::errstr\n";
 
 
 #$query_handle->bind_columns(undef, \$id, \$timestamp, \$recport);
 
 
 while(@row = $sth->fetchrow_array()) {
 
my $dbrec = $dbh->prepare("SELECT * FROM $tableOrekaTape WHERE (recPortName = \"@row[2]\" OR recPortName = \"@row[3]\") AND timestamp <= \"$row[1]\" AND expirYTimeStamp >= \"$row[1]\" ");
 
#    my $dbrec = $dbh->prepare("SELECT * FROM $tableOrekaTape WHERE recPortName = \"10.255.0.19,24588\" AND timestamp <= \"2009-01-09 15:52:15\" AND expirYTimeStamp >= \"2009-01-09 15:52:15\" ");
 
 	$dbrec -> execute();
 
 	@rowdbrec = $dbrec ->fetchrow_array;
 
 	$dbh->do("INSERT INTO $tableDef (id, timestamp, direction, duration, localEntryPoint, localParty, remoteParty, filename, recPortName, expiryTimestamp, service_id, recPort_id)VALUES (\"@rowdbrec[0]\",\"@rowdbrec[1]\",\"@rowdbrec[2]\",\"@rowdbrec[3]\",\"@rowdbrec[4]\",\"@rowdbrec[5]\",\"@rowdbrec[6]\",\"@rowdbrec[7]\",\"@rowdbrec[8]\",\"@rowdbrec[9]\",\"@rowdbrec[10]\",\"0\")");
 
 
 ###############Lavoro su i file
 	my $del = rindex(@rowdbrec[7],'/');
 	my $destdir = substr(@rowdbrec[7],0,($del)); 
 	my $dir = $destpath .$destdir;
	if (-d $dir) {
 		#directory esiste
 	}
 	else
 	{
 		#directory non esiste
 		mkpath($dir, {verbose => 1}) or die "impossibile creare directory"; 
 	}
 	if (move($origpath.@rowdbrec[7],$destpath.@rowdbrec[7]))
	{
	
 		#se il file esiste e viene spostato
 		
 		$dbh->do("DELETE FROM $tablePS WHERE ID = \"$row[0]\"") or die "impossibile eseguire query: $DBI::errstr!";
 		print (@rowdbrec[0]);
 		#$dbh->do("DELETE FROM $tableOrekaTape WHERE id = \"$@rowdbrec[0]\"") or die "impossibile eseguire query: $DBI::errstr!";
 		
 	}
 	else
 	{
 		#se il file non esiste
 		print ("file inesistente");
 	}
 
 #################Fine lavoro sui file
 		
 
 } #fine ciclo while
 
 warn "Data fetching terminated early by error: $DBI::errstr\n"
    if $DBI::err;
 	  
 
 my $sec; my $min;my $hour;my $mday;my $month; my $year; my $wday;my $yday; my$isdst;
 
 ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst)=localtime(time);
 
 my $timestamp = ($year+1900) ."-". ($month+1) ."-". $mday ." ". $hour .":". ($min -5).":". $sec; 
 
 
 ########################Cancellazione File inutili
 
 $sth = $dbh->prepare("SELECT filename FROM $tableOrekaTape WHERE id NOT IN (SELECT id FROM $tableDef) AND timestamp < \"$timestamp\"") or die "Can't prepare SQL statement: $DBI::errstr\n";
 
 $sth -> execute() or die "Can't execute SQL statement: $DBI::errstr\n";
 
 while(@row = $sth->fetchrow_array()) {
 
 remove($origpath.@row[0] );
 } 
 
 ################################
 
 
 #####################Pulisco Database
 
 $dbh->do("DELETE FROM $tableOrekaTape WHERE id NOT IN (SELECT id FROM $tableDef) AND timestamp < \"$timestamp\"") or die "impossibile eseguire query: $DBI::errstr!";
 
 $dbh->do("DELETE FROM $tableOrekaSeg WHERE rectape_id NOT IN (SELECT id FROM $tableOrekaTape) AND timestamp < \"$timestamp\"") or die "impossibile eseguire query: $DBI::errstr!";
 
 ################################
 
 
 $dbh ->disconnect or warn "Error disconnecting: $DBI::errstr\n";
 
 ######################################## Fine Lavoro sul DB ######
 
 
 exit;