From: realraum Date: Thu, 17 Jun 2010 18:20:26 +0000 (+0000) Subject: checkphone X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=caa173d63dc52abefe31b034c20bdf787377ade9;p=svn42.git checkphone --- diff --git a/checkphone.pl b/checkphone.pl new file mode 100755 index 0000000..6b3c67b --- /dev/null +++ b/checkphone.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl -w + +use Socket; +use strict; +my $fh; + +my $socketfile = $ARGV[0] || "/var/run/tuer/door_cmd.socket"; +sleep(1) while (! -S $socketfile); +my $socketaddr = sockaddr_un($socketfile); + +my $keys; +my %good; + +open $keys,'/flash/phone'; +while (<$keys>) +{ + chomp; + if ($_ =~ /^(\S+)\s+(.+)$/) + { + $good{$1}=$2; + } +} +my $id = $ARGV[2]; +my $action = $ARGV[1]; +if ($good{$id}) +{ + if ($action == 1591) + { + send_to_fifo("close Phone ".$good{$id}); + } elsif ($action == 1590) { + send_to_fifo("open Phone ".$good{$id}); + } else { + send_to_fifo("log invalid action $action, but valid Phone $id"); + } +} else { + send_to_fifo("log invalid Phone $id"); +} +exit 0; + +sub send_to_fifo +{ + socket(my $conn, PF_UNIX, SOCK_STREAM,0) || die "socket: $!"; + connect($conn, $socketaddr) || die "socket connect: $!"; + print $conn shift(@_)."\n"; + close($conn); +} +