if ($line =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)( .*)?$/) {
$IP = $1;
$accesspath=ACCESS_PATH.$IP;
- if (open ($accessfile,"<",$accesspath)) {
+ if (! (-e $accesspath)) {
+ print "ERR'n";
+ }
+ elsif (open ($accessfile,"+<",$accesspath)) {
+ unless (flock ($accessfile, 2)) {
+ close ($accessfile);
+ print "ERR\n";
+ next;
+ }
$unlocktime=<$accessfile>;
$lasttime=<$accessfile>;
- close($accessfile);
+
$unlocktime =~ s/[\r\n]//g;
$lasttime =~ s/[\r\n]//g;
- if ((abs($accesstime-$unlocktime)>$timeout_unlock) or (abs($accesstime-$unlocktime)>$timeout_inact)){
- print "ERR too long\n";
+ if ($unlocktime =~ /^([0-9]+)$/) {
+ $unlocktime=int($1);
+ }
+ else {
+ close ($accessfile);
+ print "ERR\n";
+ next;
+ }
+
+ if ($lasttime =~ /^([0-9]+)$/) {
+ $lasttime=int($1);
+ }
+ else {
+ close ($accessfile);
+ print "ERR\n";
+ next;
+ }
+
+ if ((abs($accesstime-$unlocktime)>$timeout_unlock) or (abs($accesstime-$lasttime)>$timeout_inact)){
+ close ($accessfile);
unlink $accesspath;
+ print "ERR\n";
}
else {
- print "OK\n";
- if (open ($accessfile,">",$accesspath)) {
+ if (seek($accessfile, 0, 0)) {
print $accessfile "$unlocktime\n$accesstime\n";
- close ($accessfile);
+ truncate ($accessfile , tell($accessfile));
}
+ close ($accessfile);
+ print "OK\n";
}
}
else {
- print "ERR\n";
+ print "BH\n";
}
}
else {
return 1;
}
$accesspath=ACCESS_PATH.$IP;
- if (open ($accessfile,"<",$accesspath)) {
+ if (! (-e $accesspath)) {
+ return 0;
+ }
+
+ elsif (open ($accessfile,"+<",$accesspath)) {
+ unless (flock ($accessfile, 2)) {
+ close ($accessfile);
+ return 0;
+ }
$unlocktime=<$accessfile>;
$lasttime=<$accessfile>;
- close($accessfile);
+
$unlocktime =~ s/[\r\n]//g;
$lasttime =~ s/[\r\n]//g;
- if ((abs($accesstime-$unlocktime)>$timeout_unlock) or (abs($accesstime-$unlocktime)>$timeout_inact)){
+ if ($unlocktime =~ /^([0-9]+)$/) {
+ $unlocktime=int($1);
+ }
+ else {
+ close ($accessfile);
+ return 0;
+ }
+
+ if ($lasttime =~ /^([0-9]+)$/) {
+ $lasttime=int($1);
+ }
+ else {
+ close ($accessfile);
+ return 0;
+ }
+
+ if ((abs($accesstime-$unlocktime)>$timeout_unlock) or (abs($accesstime-$lasttime)>$timeout_inact)){
+ close ($accessfile);
unlink $accesspath;
return 0;
}
else {
- if (open ($accessfile,">",$accesspath)) {
+ if (seek($accessfile, 0, 0)) {
print $accessfile "$unlocktime\n$accesstime\n";
- close ($accessfile);
+ truncate ($accessfile , tell($accessfile));
}
+ close ($accessfile);
return 1;
}
}