#!/usr/bin/perl -w use Chipcard::PCSC; open STDIN, '>', '/dev/null'; open STDOUT, '>', '/dev/null'; open STDERR, '>', '/dev/null'; if ($_ = fork) { print "Child process is ", $_, "\n"; exit 0; } setpgrp; my $hcontext = Chipcard::PCSC->new; my %cards = ( '1234567890' => { 'name' => 'Johnny Cuervo', 'card_in' => '/home/cuervo/bin/smartcard-in', 'card_out' => '/home/cuervo/bin/smartcard-out', }, '0987654321' => { 'name' => 'Marie', 'card_in' => 'espeak "Nice try. Get your own laptop."', 'card_out' => 'espeak "Bye now!"', }, ); while (1) { my $hcard = Chipcard::PCSC::Card->new($hcontext, 'SCM SCR 355 00 00', $Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE); if (! defined $hcard) { # # No card present # if ($had_card) { system $cards{$had_card}->{'card_out'}; $had_card = 0; } sleep 1; next; } ($_, $_, $_, $atr) = $hcard->Status; $atr = join '', @$atr; if ((! $had_card) && exists $cards{$atr}) { print "\t", $cards{$atr}->{'name'}, " logged in\n"; system $cards{$atr}->{'card_in'}; $had_card = $atr; } $hcard->Disconnect; sleep 1; }