From e9192b3d42660a5781101df4357d276318151e8a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:14:41 -0500 Subject: cgi-bin & lib --- lib/cookies.pm | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/cookies.pm (limited to 'lib/cookies.pm') diff --git a/lib/cookies.pm b/lib/cookies.pm new file mode 100644 index 0000000..559e80a --- /dev/null +++ b/lib/cookies.pm @@ -0,0 +1,55 @@ +# &setCookie("fuckface", "j1zzm0p"); + +our $cookie_reset = "Friday, 31-Dec-1999 11:59:59 GMT"; +our $cookie_forever = "Friday, 21-Dec-2069 12:28:49 GMT"; + +# our $cookies = getCookies() if ($ENV{'HTTP_COOKIE'}); +# store cookies in %$cookies + +sub setCookie + { + # end a set-cookie header with the word secure and the cookie will + # only be sent through secure connections + + my ($args) = @_; + my $name = $args->{name} || undef; + my $value = $args->{value} || undef; + my $path = $args->{path} || undef; + my $domain = $args->{domain} || undef; + +# my ($name, $value, $path, $domain) = @_; + my $date; + + if (!$value) + { $date = $cookie_reset; } + elsif (exists($args->{nologout}) && $args->{nologout} == 1) + { $date = $cookie_forever; } + else + { $date = 0; } + + print "Set-Cookie: "; + print $name, "=", $value, "; "; + if ($date) { print "expires=$date; "; } +# print "path=", $path, "; domain=", $domain, "; secure\n"; + print "path=", $path, "; domain=", $domain, "\n"; + } + + +# cookies are seperated by a semicolon and a space, this will split +# them and return a hash of cookies + +sub getCookies + { + my (@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'}); + my %cookies; + + foreach(@rawCookies) + { + my ($key, $val) = split (/=/,$_); + $cookies{$key} = $val; + } + + return \%cookies; + } + +1; -- cgit v1.2.3-70-g09d2