[Update 21. Februar 2010: Nun mit Namensauflösung]
Linux: Ubuntu 9.10
Benötigte Pakete: isdnlog
Einstellungen:
/etc/isdn/callerid.conf (einfach erstellen, wenn nicht vorhanden, wird automatisch eingebunden)
[MSN]
NUMBER = (Your MSN without prefix)
ALIAS = (An Alias Name for your MSN)
SI = 1
ZONE = 1
START = {
[FLAG]
FLAGS = I|R
PROGRAM = /usr/bin/perl /scripts/isdn-notifier.pl jabber (your jabber address) \$1 \$2 \$3
[FLAG]
FLAGS = I|H
PROGRAM = /usr/bin/perl /scripts/isdn-notifier.pl mail (your email address) \$1 \$2 \$3 \$5
}
Variables: \$1 = Flags (f.e. IR, IH); \$2 = number of caller, \$3 = called number (your MSN), \$5 = duration of call
The flag “R” means Ringing and “H” means Hangup → In this example there will be a jabber notification on incoming calls and a mail notification on missed calls (hangup with 0 seconds duration).
/scripts/isdn-notifier.pl
#!/usr/bin/perl
use strict;
use Net::Jabber qw(Client);
use Net::Jabber qw(Message);
use Net::Jabber qw(Protocol);
use Net::Jabber qw(Presence);
my $len = scalar @ARGV;
my @field=split(/,/,$ARGV[1]);
use constant ISDNTYPE => $ARGV[2];
my $body = "";
my $subject = "";
use constant MAXWAIT => 2;
my $name1 = `grep $ARGV[3] /scripts/contacts.utf8.csv | cut -d ',' -f 1,3 -s --output-delimiter ' '`;
my $name2 = `grep $ARGV[4] /scripts/contacts.utf8.csv | cut -d ',' -f 1,3 -s --output-delimiter ' '`;
if (ISDNTYPE eq "IR") {
$body = "Anruf!\n\nVon:\t$ARGV[3]\n\t$name1\nAn:\t$ARGV[4]\n\t$name2";
$subject = "Incoming call from $ARGV[3]";
}
if (ISDNTYPE eq "IH") {
if ($ARGV[5] eq 0) {
$body = "Verpasster Anruf!\n\nVon:\t$ARGV[3]\n\t$name1\nAn:\t$ARGV[4]\n\t$name2";
$subject = "Verpasster Anruf von $ARGV[3]";
}
}
if ($body ne "") {
if ($ARGV[0] eq "jabber") {
# Constants you have to customize:
use constant SERVER => '###';
use constant PORT => 5222;
use constant USER => '###';
use constant PASSWORD => '###';
use constant RESOURCE => 'isdnlog';
# Create the connection
my $connection = Net::Jabber::Client->new();
$connection->Connect("hostname" => SERVER, "port" => PORT, "tls" => 1, "log" => 1,) or die "Cannot connect ($!)\n";
# Authenticate
### Use only one of the following lines: ###
my @result = $connection->AuthSend("username" => USER,"password" => PASSWORD,"resource" => RESOURCE);
#my @result = $connection->AuthIQAuth("username" => USER,"password" => PASSWORD,"resource" => RESOURCE);
if ($result[0] ne "ok") {
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
# Send the message
foreach (@field) {
my $message = Net::Jabber::Message->new();
$message->SetMessage("to" => $_,
"subject" => $subject,
"type" => "headline",
"body" => $body);
$connection->Send($message);
sleep(MAXWAIT);
}
# Disconnect and exit
$connection->Disconnect();
}
if ($ARGV[0] eq "mail") {
# Simple Email Function
# ($to, $from, $subject, $message)
sub sendEmail
{
my ($to, $from, $subject, $message) = @_;
my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
close(MAIL);
}
foreach (@field) {
sendEmail($_, 'ISDN Notifier <#### your email ####>', $subject, $body );
}
} # if ($ARGV[0] eq "mail")
}
exit;
/scripts/contacts.utf8.csv
Die Datei hat bei mir folgenden Aufbau:
Vorname,,Nachname,,,,,,,,+49176xxxxx,+49711xxxx,,,,
Die Datei ist entstanden aus einem Export aus Google Mail (Contacts → Export → Outlook CSV), danach mit einem iconv -f iso-8859-1 -t utf-8 contacts.csv > contacts.utf8.csv nach UTF-8 umgewandelt, dann die erste Zeile mit sed -i '1d' contacts.utf8.csv, dann mit perl -p -e 's/[^,]\r\n/ /g' contacts.utf8.csv > contacts.final.csv Leerzeichen aus Adressfeldern entfernt und auf den Server verschoben.
Für das richtige Nummernformat (keine Leerzeichen, Klammern, …) muss man selber von Hand sorgen.

0 Responses to “Getting Jabber/Mail Notifications on incoming ISDN calls”