]> bicyclesonthemoon.info Git - yplom/proxy/commitdiff
Fixed access verification.
authorb <b@05ce6ebb-7522-4a6e-a768-0026ae12be9f>
Sat, 14 Nov 2015 22:22:22 +0000 (22:22 +0000)
committerb <b@05ce6ebb-7522-4a6e-a768-0026ae12be9f>
Sat, 14 Nov 2015 22:22:22 +0000 (22:22 +0000)
git-svn-id: svn://botcastle1b/yplom/proxy@8 05ce6ebb-7522-4a6e-a768-0026ae12be9f

access.1.pl
proxy.1.pl

index dbbd195c9f75c5dd0b83baae66154abd4eadc2a8..fee2b6366d63711ea21caa1bf809c78f13ef5736 100644 (file)
@@ -20,27 +20,55 @@ while (<STDIN>) {
        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 {
index e86d433b68aeeee1416038198eaf1691dda2c8df..236cabbbb61edc76537971b6649b0b8e6c80c37f 100755 (executable)
@@ -323,22 +323,48 @@ sub access { #kind of doubles the functionality of access.pl but for http
                        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;
                        }
                }