#!/usr/bin/perl
use ExtUtils::testlib;
use Chipcard::PCSC;
use Chipcard::PCSC::Card;
use Data::Dumper;
use warnings;
use strict;
my @mycard = [
59,
105,
0,
0,
36,
148,
1,
2,
1,
0,
1,
1,
169
];
sub compare_arrays {
my ($first, $second) = @_;
no warnings; # silence spurious -w undef complaints
return 0 unless @$first == @$second;
for (my $i = 0; $i < @$first; $i++) {
return 0 if $first->[$i] ne $second->[$i];
}
return 1;
}
sub checkCard(){
#-------------------------------------------------------------------------------
my $hContext = new Chipcard::PCSC();
return 1 unless (defined $hContext);
#-------------------------------------------------------------------------------
my @ReadersList = $hContext->ListReaders ();
return 1 unless (defined($ReadersList[0]));
#-------------------------------------------------------------------------------
my $hCard = new Chipcard::PCSC::Card ($hContext, $ReadersList[0]);
return 1 unless (defined($hCard));
#-------------------------------------------------------------------------------
my @StatusResult = $hCard->Status ();
return 1 unless (defined ($StatusResult[0]));
if (not compare_arrays(\@mycard ,\@{$StatusResult[3]})) {
return 0;
}
#-------------------------------------------------------------------------------
$hCard->Disconnect($Chipcard::PCSC::SCARD_LEAVE_CARD);
undef $hCard;
#-------------------------------------------------------------------------------
$hContext = undef;
}
my $forked =0;
daemonize();
while (1) {
# Device was found and command should be executed
if (checkCard()==0 && $forked == 1) {
system("/bin/sh -c \"killall xscreensaver\"");
system("/bin/sh -c \"xscreensaver -no-splash &\"");
$forked =0;
}
# Device is gone and command should be executed
elsif ( (checkCard()==1) && ($forked != 1) ) {
my $pid =fork();
if ($pid == 0) {
system("/bin/sh -c \"xscreensaver-command -activate\"");
exit(0);
}else{
$forked = 1;
}
}
sleep ( 2 );
}
# Become a daemon
sub daemonize
{
chdir("/");
close(STDIN);
close(STDOUT);
}
Lock my screen with a smartcard
I bought a new Keyboard. A "Dell Smart Card Reader Keyboard" as the Name says it has a smartcard reader integrated in it. Now I wanted that if I pull the smartcard my screen locks and if I push it back in it unlocks. Here is the demon code to do so :
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment