#!/usr/bin/perl

######################################################################
### $value =~ s/\+/ /g; kan være farlig på enkelte servere, da den ###
### kan føre til listing av mappeinnhold. Dersom du er usikker,    ###
### bruk denne: $value =~ s/\+//g; , isteden.                      ###
######################################################################
######################################################################
##                HeadPageFoot v1.0 (14.06.02)                      ##
##                HeadPageFoot v1.1 (26.01.04)                      ##
##                  http://www.malmklang.no                         ##
##                 !chmod scriptet til 755!                         ##
######################################################################

$SIG{__DIE__} = \&Error_Msg;

sub Error_Msg {
my $msg = "@_";
print "Handling avbrutt av følgende årsak: $msg\n";
exit;
}

### Variabler og stuff ###
my $header = "header.html";                                           # Sti til header.html
my $idsti = "/home/eyesonde/www/pictures/";                           # Stil til mappe hvor undersidene ligger
my $footer = "footer.html";                                           # Sti til footer.html
my $default = "pictures.html";                                         # Id for hovedsiden (benyttes når scriptet kalles uten "?id=navn")
my $home = "http://www.eyesondesign.net/pictures/eod.cgi";            # Link hjem
my $sendmail = "/usr/sbin/sendmail";                                  # Mailprogam
my $css_path = "/home/eyesonde/www/pictures";                         # PATH. Benyttes i forbindelse med :vis stilark:
my $css_url = "http://www.eyesondesign.net";                          # URL. Benyttes i forbindelse med :vis stilark:

############ Ikke rør:P #############
my $scriptnavn = "HeadPageFoot v1.0";
my $scriptid = "eod.cgi";
#####################################
















### Hovedrutinene ###

&first;
&head;
&suginn;

if ($INPUT{'id'} eq "") {&default;}
if ($INPUT{'id'} eq "$scriptid") {&default;}

else {
&lagside;
}


### Subrutinene ###

sub first {
print "content-type: text/html\n\n";
}

sub head {
open(HEAD, "<$header") || die "Kunne ikke åpne headerfil.\n";
my @headlinjer = <HEAD>;
close (HEAD) || die "Kunne ikke lukke headerfil.\n";
	foreach my $headlinje (@headlinjer) {
	print "$headlinje";
	}
}

sub suginn {
read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
$input = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};
@pairs = split(/&/, $input);
	foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);
	$name =~ s/<([^>]|\n)*>//g;
	$name =~ s/\+/ /g;
	$name =~ s/`//g;
	$name =~ s/\|//g;
	$name =~ s/'//g;
	$name =~ s/<//g;
	$name =~ s/>//g;
	$name =~ s/~//g;
	$name =~ s/\///g;
	#$name =~ tr/+//;

	$value =~ s/\+/ /g;
	$value =~ s/`//g;
	$value =~ s/\|//g;
	$value =~ s/'//g;
	$value =~ s/</&lt;/g;
	$value =~ s/>/&gt;/g;
	$value =~ s/~//g;
#	$value =~ s/\///g;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	#$value =~ s/<([^>]|\n)*>//g;
	#$value =~ tr/+//;
	$INPUT{$name} = $value;
	}
}

&foot;


sub lagside {
### Finn verdien av ident
my $id = "$INPUT{'id'}";
### Bygg sti
my $body = "$idsti$id";
open (BODY, "$body") || die "Kunne ikke åpne htmlfil.\n";
my @body=<BODY><div onClick="this.style.display='none';"><div style="display:block; clear:both; height:1.5em; padding:0.5em;">&nbsp;</div><div style="position:absolute; top:0px; left:0px; display:block; position:fixed; width:100%; padding:0.5em; line-height:1.5em; background-color:#BE0000; color:#FFF; font-family:Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-size:13px; z-index:2147483640; cursor:pointer; " title="click to hide message">Please note, this is a STATIC archive of website www.eyesondesign.net from 07 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.</div></div>;
close (BODY) || die "Kunne ikke lukke htmlfil.\n";
	foreach my $bodyline (@body) {
	print "$bodyline";
	}
}

sub default {
### Finn verdien av ident
$id = "$default";
### Bygg sti
my $body = "$idsti$id";
open (BODY, "$body") || die "Kunne ikke åpne bodyfil.\n";
my @body=<BODY><div onClick="this.style.display='none';"><div style="display:block; clear:both; height:1.5em; padding:0.5em;">&nbsp;</div><div style="position:absolute; top:0px; left:0px; display:block; position:fixed; width:100%; padding:0.5em; line-height:1.5em; background-color:#BE0000; color:#FFF; font-family:Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-size:13px; z-index:2147483640; cursor:pointer; " title="click to hide message">Please note, this is a STATIC archive of website www.eyesondesign.net from 07 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.</div></div>;
close (BODY) || die "Kunne ikke lukke bodyfil.\n";
	foreach my $bodyline (@body) {
	print "$bodyline";
	}

&foot;
exit;
}

sub foot {
open(FOOT, "<$footer") || die "Kunne ikke åpne footerfil.\n";
my @footlinjer = <FOOT>;
close (FOOT) || die "Kunne ikke lukke footerfil.\n";
	foreach my $footlinje (@footlinjer) {
	print "$footlinje";
	}
}

1;