#!/usr/bin/perl use CGI; $debug = 0; $report = 0; $basedir = "/home/clients/mediaink"; $show_dir = "cafe/work"; $wmd = "/$show_dir"; $amd = "$basedir/$show_dir"; $ifile = "$basedir/maillist"; $Keyword = "MIWorkV"; $cafe = "/cafe/"; $MainArea = '/cafe/work/index3.cgi'; $query = new CGI; $home = "homequery.html"; $type = $query->param("type"); $key = $query->param("$Keyword"); $debug = 1 if $type eq "debug"; $viz = $query->param("viz"); $script = $ENV{'SCRIPT_NAME'}; $timeout = 4460; $viz = 'new' unless $viz; # cookie, this contains the URL of the page, this is the thing that Netscape # supports. # #($name,$cookie) = split(/=/,$ENV{'HTTP_COOKIE'}); $cookies = $ENV{'HTTP_COOKIE'}; #$cookie =~ s/([^URL]*)URL=([^;]*);.*/$2/; #$cookies =~ /URL=([^;]*)/; #$cookies = $1; while ($cookies =~ s/^([^;]*);//) { $r .= $1; GrabCookies ($1); } if ($cookies =~ /^([^=]*=.*)/) { GrabCookies ($1); } $key = $cookie{"$Keyword"} if $cookie{"$Keyword"}; #$email = $cookie{"Email"} if $cookie{"$Keyword"}; #$eml = $query->param("$Keyword"); $emaip = $query->param("Email"); $renew = $query->param("renew"); $declined = $query->param("decline"); $emaic = $cookie{'Email'}; foreach $k (keys %cookie) { $emaic = $cookie{$k} if $k =~ /email/i; } $email = $emaic; $email = $emaip if $emaip; sub GrabCookies { my ($i) = @_; $i =~ /^([^=]+)=(.*)$/; $cookie{$1} = $2; } $host = $ENV{'HTTP_HOST'}; $now = time(); $cexp = $now+$timeout; ($exp = gmtime($cexp)) =~ s/ /, /; if ($key) { $c1 = "$Keyword=$key;expires=$exp"; $viz = $key; } else { $c1 = "$Keyword=$cexp;expires=$exp"; $viz = "$cexp"; } #print $query->header(-cookie=>[$c1,$c2], # -location=>'media2/index2.cgi'); if ($email && $email ne 'none') { $c1 = "Email=$email;expires=$exp"; } else { $email = 'none'; $c1 = "Email=$email;expires=$exp"; } # Mail list dbmopen (%mlist, "$ifile", 0666); $mlist{$email} = $now unless $mlist{$email}; $mlist{$email} = $now if $renew; $mlist{"$email-lastvisit"} = localtime(); $mlist{"$email-fstvisit"} = localtime() unless $mlist{"$email-fstvisit"}; $mlist{"$email-totalvisit"}++; # If request has the sub directory, It will Forward to that # else this wil forward to main area. # # $viz is the session tag time, check for expiration. # $gotop = $query->param('media'); $gotoc = $cookie{'media'}; foreach $k (keys %cookie) { $gotoc = $cookie{"$k"} if $k =~ /media/; } $location = $gotop || $gotoc; $goto = "$wmd/$location" unless $goto; $here = $ENV{'REQUEST_URI'}; unless ($location) { ($location = $here) =~ s%^$wmd\/(.*)$%$1%; $location =~ s/\?.+$//; if ($location !~ /\/$/) { $location =~ s%\/[^\/]+$%/%; } } $l1 = "media=$location;expires=$exp"; $expired = $mlist{"$email"} + $timeout; if ($declined) { print $query->header(-location=>"$cafe"); } elsif ($email eq 'none') { # Session is NOT started $mlist{$email} = $now; print $query->header(-cookie=>[$c1,$l1]); if ($debug) { print start_html('Hello'); print "

NEW Session
Catched \$email is $email

"; $z = $expired - $now; print "

  • $z

    "; print qq(

    Email:
    ); } $j = &passthru('home.html','login.html'); print "$j"; } elsif ($expired > $now) { # Session is NOT expired if ($here !~ m%$goto%) { print $query->header(-cookie=>[$c1,$l1]); # print $query->header(-cookie=>[$c1,$l1], # -location=>"$goto"); if ($debug) { print start_html('Hello'); print "

    Session in progress and forwarded to $goto
    Catched $mlist{$email} + $timeout is $expired Greater than $now

    "; $z = $expired - $now; print "

  • $z

    "; } $j = &passthru; print "$j"; } else { # print $query->header(-cookie=>[$c1,$l1], # -location=>"$wmd/index3.cgi"); print $query->header(-cookie=>[$c1,$l1]); if ($debug) { print start_html('You are here'); print "

    Session in progress and you are here
    Catched $mlist{$email} + $timeout is $expired Greater than $now

    "; $z = $expired - $now; print "

  • $z

    "; print "
    pass thru
    "; } $j = &passthru; print "$j"; } } else { #here session expires $mlist{$email} = $now; print $query->header(-cookie=>$c1); if ($debug) { print start_html('Debug Screen'); print "

    Expired session
    Catched $mlist{$email} + $timeout is $expired LESS than $now

    "; print "This is default

    "; $z = $expired - $now; print "

  • $z

    "; print qq(

    Email:
    ); } $j = &passthru('home.html','login.html'); print "$j"; } ## delete me later OR NOT if ($report) { print "

    Report

    \n"; print "
    $r
    "; } elsif ($debug) { print "Local time is $now

    "; print '


    '; print "

    Request Line

    "; @z = $query->param; foreach $i (@z) { $j = $query->param("$i"); print "$i - $j
    "; } print '
    '; print "

    Cookies

    "; foreach $k (keys %cookie) { print "$k = $cookie{$k}
    "; } print '
    '; print "

    Environment

    "; foreach $k ( keys %ENV) { print "\$ENV\{$k\} = $ENV{$k}
    "; } print '
    '; print "

    Raw Deal Jose

    $r"; print qq(

    • \$goto = $goto
    • \$email = $email
    • cookie = $cookie{$media}
    • $emaip = \$query->param("Email");
    • $emaic = \$cookie{"Email"};
    • $gotop = \$query->param("media");
    • $gotoc = \$cookie{"media"};

      ); } sub start_html { my ($i, $o) = @_; $o = qq( $i ); } sub passthro { $xjfdu = "

      khjjdhfehfuehfeuhfeuhfuehf

      "; } sub passthru { my ($uri, $alt, $o) = @_; $r .= "open ". `pwd` . " home.html"; if (open (I, "./home.html")) { while () { if (/\<\!--\#include\s+file=(\S+)/) { $o .= "

      INCLUDE START

      " if $debug; if ($alt) { if (-e "$alt") { $o .= &included("$alt"); } else { $o .= &included("../$alt"); } } else { $o .= &included("$1"); } $o .= "

      INCLUDE END

      " if $debug; } else { $o .= "$_"; } } } else { $o = 'Check back later'; } $o; } sub included { my ($file, $d, $o) = @_; $d = `pwd`; $file =~ s/\"//g; $o .= "

      File is $d/$file

      " if $debug; if (open (C, "./$file")) { while () { s/MYID/Email=$email/g; $o .= "$_"; } close (C); } $o; }