my $cookie = shift; # e.g. RCG01lastactivity=1119168277; domain=.homegunsmith.com; path=/;
expires=Mon, 19-Jun-2006 08:04:37 GMT
# Note: should *not* have the Set-Cookie: prefix
if (not $cookie) {
return; # We can't properly figure out the cookie without all these things
}
my @nvpair = split(/;/,$cookie); # Split up the name/value pairs. The first pair must be the
cookie name and value
my %cookie = ();
my ($name, $value, $i, $lcname);
# ($name, $value) = split(/=/,$nvpair[0]);
($name, $value) = $nvpair[0] =~ m/^([^=]*)=(.*)$/; # Unlike the previous "split", this
handles if there are equal signs ('=') embedded in the string
$name =~ s/\s//g; # remove any whitespace from the name
$lcname = lc($name); # we are going to use the lowercase name of the cookie for storage purposes
$cookie{'name'} = $name; # Later specs specify the cookie name is to be case insensitive, so
when replacing old with new, we'll be case insensitive, but we'll store the case "as sent" so we
can return it "as sent" in case the application cares.
$cookie{'value'} = $value;
for ($i=1; $i <=$#nvpair; $i++) {
# my($name,$value) = split(/=/,$nvpair[$i]);
my($name, $value) = $nvpair[$i] =~ m/^([^=]*)=(.*)$/; # Unlike the previous "split", this
handles if there are equal signs ('=') embedded in the string
$name =~ s/\s//g; # remove any whitespace from the name
$name = lc($name); # All of these parameters should have their names in lower case
if (($name eq 'domain') or ($name eq 'path') or ($name eq 'expires') or ($name eq 'secure')) {
# Only want the parameters we understand
if ($name eq 'secure') { # The 'secure' nv pair isn't really a pair, only the name will
appear, so we force a 1
$value = 1;
}
$cookie{$name} = $value;
}
}
if ($cookie{'expires'}) {
$cookie{'expiresEpoch'} = str2time($cookie{'expires'});
}
return %cookie;
}
sub sortableDate {
# Used to return time as GMT. Now just returning as local time without a time zone indicator
# my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time);
# return sprintf("%04d-%02d-%02d %02d:%02d:%02d GMT",$year+1900,$mon+1,$mday,$hour,$min,$sec);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time);
return sprintf("%04d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec);
}
sub logevent {
my $user = shift;
my $ip = shift;
my $message = shift;
print OUT sortableDate() . "\t$user\t$ip\t$message\n";
autoflush OUT;
}
sub periodCount { # How many periods ('.') in a string?
my $string = shift;
$string =~ s/[^.]//g;
return length($string);
}
sub loadConfig {
my $configFile = shift;
my $filehandle;
if (not open ($filehandle,"$path/$configFile")) {
die "Cannot open config file $configFile.\nError: $!\nEnding.\n";
}
while (<$filehandle>) {
chomp $_;
if ($_ =~ m/^#/) { # if the line starts with a # character
# do nothing, this is a comment line
} elsif ($_) {
my ($name,$value) = $_ =~ m/^([^=]*) = (.*)$/; # e.g. DefaultHomePage = http://wap.google.com
if ($name =~ s/^-//) {
$hiddenConfig{$name} = 1; # elements with names that start with a minus sign will have the
minus sign stripped, but will be hidden from the console display - great for things that never
change and nobody cares about
}
if ($name =~ m/s$/) { # If the element name ends in 's' force it to be a "multi" (e.g.
TrustedDomains or ValidLocalHosts) - done so if a multi has only one value, it is still created as
a multi
my @values = split(/;/,$value); # Note: don't put spaces around your ; delimiters in a value
list or they'll end up in the values
foreach my $i (@values) {
$HoTTProxyConfig{$name}{$i} = 1; # Just make them true so they exist and can easily be tested
for
}
} else {
$HoTTProxyConfig{$name} = $value;
}
}
=10= |