Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / protocols / ace / HTBP / HTID_Generator.cgi
blob0d57a552d6cdabb4ca95c7bc988bfc5c5ef118e7
1 #!/usr/bin/perl
3 # This is a sample script that may be used to create domain specific
4 # unique ID's rather than using UUID. In a typical scenario, this HTID
5 # generator would reside in the same domain as the target server, so
6 # that it could be used by any clients of the server. While use of UUID
7 # as a unique identifier is perfectly fine, use of a remote generator
8 # gives additional benefits, such as the ability to collect metrics on
9 # identity requestors.
11 print "Content-type:text/html\n\n";
13 $htid = $ENV{'REMOTE_ADDR'};
15 open(IN,"counts.txt") or dienice("Can't open counts.txt for writing: $!");
17 flock(IN,2); # lock the file
18 seek(IN,0,0); # rewind it to the beginning
20 $oldtimestamp = <IN>; # read only the first line.
21 $save_time = $oldtimestamp;
23 close(IN);
26 $timestamp = time;
28 if ($oldtimestamp == $timestamp)
30 open (IN2, "sec_id.txt") or
31 dienice ("Can't open sec_id.txt for writing: $!");
33 flock (IN2, 2);
34 seek (IN2, 0, 0);
36 $secondary_id = <IN2>;
38 # increment the secondary id
39 ++$secondary_id;
42 close (IN2);
44 else {
46 $secondary_id = 0;
49 open(OUT2,">sec_id.txt") or
50 dienice("Can't open outdata.txt for writing: $!");
52 flock(OUT2,2); # lock the file
53 seek(OUT2,0,0); # rewind it to the beginning
55 print OUT2 "$secondary_id";
57 close(OUT2);
60 #save the timestamp for next time
61 $oldtimestamp = $timestamp;
64 open(OUT,">counts.txt") or dienice("Can't open outdata.txt for writing: $!");
66 flock(OUT,2); # lock the file
67 seek(OUT,0,0); # rewind it to the beginning
68 print OUT "$oldtimestamp\n";
69 close(OUT);
72 $result_string = join (".$timestamp", $htid, ".$secondary_id");
74 print <<EndOfHTML;
76 $result_string
78 EndOfHTML