checkphone
authorrealraum <realraum@realraum.at>
Thu, 17 Jun 2010 18:20:26 +0000 (18:20 +0000)
committerrealraum <realraum@realraum.at>
Thu, 17 Jun 2010 18:20:26 +0000 (18:20 +0000)
checkphone.pl [new file with mode: 0755]

diff --git a/checkphone.pl b/checkphone.pl
new file mode 100755 (executable)
index 0000000..6b3c67b
--- /dev/null
@@ -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);
+}
+