#!/usr/sbin/perl require '/usr/people/jevbratt/web/cookielib/cookie.lib'; #get file to link to and which link to edit $input=$ENV{'QUERY_STRING'}; ($link_nr,$pageurl)= split(/=/,$input); #redirect print "Location: $pageurl\n\n"; #if the right cookie is there if (&GetCookies('domaineType')) { print "Location: http://cadre.sjsu.edu\n\n"; #get file to edit (must be in same directory as cgi) +link $ref_html=$ENV{'HTTP_REFERER'}; @path=split(/(\/)/,$ref_html); $change_html=@path[@path-1]; if($change_html eq "/"){ $change_html="index.html"; } # Begin the editing of the file open (FILE,"$change_html") || die "Can't Open $change_html: $!\n"; @LINES=; close(FILE); $SIZE=@LINES; # Open Link File to Output open (GUEST,">$change_html") || die "Can't Open $change_html: $!\n"; for ($i=0;$i<=$SIZE;$i++) { $_=$LINES[$i]; if (//) { $COLORLINE=$_; @colorline=split(/#/,$COLORLINE); $COLORintR=hex(substr(@colorline[1],0,2)); $COLORintG=hex(substr(@colorline[1],2,2)); $COLORintB=hex(substr(@colorline[1],4,2)); #16777215 amout of colors (ffffff) #15658734 (eeeeee) $COLORintRc=(substr($Cookies{'domaineType'},0,1)); $COLORintGc=(substr($Cookies{'domaineType'},1,1)); $COLORintBc=(substr($Cookies{'domaineType'},2,1)); if ($COLORintRc==1){ $COLORintR=$COLORintR+8; $COLORintG=$COLORintG-4; $COLORintB=$COLORintB-4; } if ($COLORintGc==1){ $COLORintR=$COLORintR-4; $COLORintG=$COLORintG+8; $COLORintB=$COLORintB-4; } if ($COLORintBc==1){ $COLORintR=$COLORintR-4; $COLORintG=$COLORintG-4; $COLORintB=$COLORintB+8; } if($COLORintR < 0){ $COLORintR=0; } if($COLORintG < 0){ $COLORintG=0; } if($COLORintB < 0){ $COLORintB=0; } if($COLORintR > 255){ $COLORintR=255; } if($COLORintG > 255){ $COLORintG=255; } if($COLORintB > 255){ $COLORintB=255; } $COLORr = sprintf ("%lx", $COLORintR); $COLORg = sprintf ("%lx", $COLORintG); $COLORb = sprintf ("%lx", $COLORintB); if($COLORintR < 16){ $COLORr= join ('',"0",$COLORr); } if($COLORintG < 16){ $COLORg= join ('',"0",$COLORg); } if($COLORintB < 16){ $COLORb= join ('',"0",$COLORb); } substr(@colorline[1],0,2)=$COLORr; substr(@colorline[1],2,2)=$COLORg; substr(@colorline[1],4,2)=$COLORb; #$COLORLINE= join ('#',@colorline[0],@colorline[1]); print GUEST "@colorline[0]"; print GUEST "#"; print GUEST "@colorline[1]"; # print GUEST "$COLORLINE"; } else { print GUEST $_; } } close (GUEST); } #what happens if user has no cookie else{ $remote_address = $ENV{'REMOTE_ADDR'}; @subnet_numbers = split (/\./, $remote_address); $packed_address = pack ("C4",@subnet_numbers ); ($hosttype)= gethostbyaddr($packed_address,2); #$hosttype="asd.asdad.se.mil"; #@domainSections=split(/\./,$hosttype); #$sectionamount=@domainSections; #$toplevel=@domainSections[$sectionamount-1]; #get file to edit (must be in same directory as cgi) $ref_html=$ENV{'HTTP_REFERER'}; @path=split(/(\/)/,$ref_html); $change_html=@path[@path-1]; if($change_html eq "/"){ $change_html="index.html"; } # Begin the editing of the file open (FILE,"$change_html") || die "Can't Open $change_html: $!\n"; @LINES=; close(FILE); $SIZE=@LINES; # Open Link File to Output open (GUEST,">$change_html") || die "Can't Open $change_html: $!\n"; for ($i=0;$i<=$SIZE;$i++) { $_=$LINES[$i]; if (//) { $COLORLINE=$_; @colorline=split(/#/,$COLORLINE); $COLORintR=hex(substr(@colorline[1],0,2)); $COLORintG=hex(substr(@colorline[1],2,2)); $COLORintB=hex(substr(@colorline[1],4,2)); if ($hosttype =~ /\.edu\b|\.net\b|\.org\b|\.edu\.|\.net\.|\.org\./i){ $COLORintR=$COLORintR+8; $COLORintG=$COLORintG-4; $COLORintB=$COLORintB-4; } if ($hosttype =~ /\.mil\b|\.gov\b|\.mil\.|\.gov\./i){ $COLORintR=$COLORintR-4; $COLORintG=$COLORintG+8; $COLORintB=$COLORintB-4; } if ($hosttype =~ /\.com\b|\.com\./i){ $COLORintR=$COLORintR-4; $COLORintG=$COLORintG-4; $COLORintB=$COLORintB+8; } if($COLORintR < 0){ $COLORintR=0; } if($COLORintG < 0){ $COLORintG=0; } if($COLORintB < 0){ $COLORintB=0; } if($COLORintR > 255){ $COLORintR=255; } if($COLORintG > 255){ $COLORintG=255; } if($COLORintB > 255){ $COLORintB=255; } $COLORr = sprintf ("%lx", $COLORintR); $COLORg = sprintf ("%lx", $COLORintG); $COLORb = sprintf ("%lx", $COLORintB); if($COLORintR < 16){ $COLORr= join ('',"0",$COLORr); } if($COLORintG < 16){ $COLORg= join ('',"0",$COLORg); } if($COLORintB < 16){ $COLORb= join ('',"0",$COLORb); } substr(@colorline[1],0,2)=$COLORr; substr(@colorline[1],2,2)=$COLORg; substr(@colorline[1],4,2)=$COLORb; ########################################## print GUEST "@colorline[0]"; print GUEST "#"; print GUEST "@colorline[1]"; ########################################## } else { print GUEST $_; } } close (GUEST); ########################################## # print "Content-type: text/html\n\n"; # print "ENV\n"; # print "\n"; # print "hosttype = $hosttype
\n"; # print "change_html= $change_html
\n"; # print "colorline[0]= @colorline[0]
\n"; # print "link_nr= $link_nr
\n"; # print "\n"; ########################################## }