summaryrefslogtreecommitdiff
path: root/perl.cgi
diff options
context:
space:
mode:
authorboredpasta <boredpasta@tutanota.com>2025-01-13 06:39:10 +0200
committerboredpasta <boredpasta@tutanota.com>2025-01-13 06:39:10 +0200
commit44595618b5d162e8bb8362e3891dc694342d1869 (patch)
treea0b08aebb5c6d38b0138c9dd3917d42e03da6c98 /perl.cgi
parent6e6c4aefd07da0aba70d651099a69c928aa7eae7 (diff)
Add project filesHEADmaster
Diffstat (limited to 'perl.cgi')
-rwxr-xr-xperl.cgi70
1 files changed, 70 insertions, 0 deletions
diff --git a/perl.cgi b/perl.cgi
new file mode 100755
index 0000000..d7a1476
--- /dev/null
+++ b/perl.cgi
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use open qw< :encoding(UTF-8) >;
+
+my $BASEDIR = "/htdocs/pastanoggin.com";
+my $base_filename = "$BASEDIR/docs/base";
+my $status_filename = "$BASEDIR/docs/status";
+
+sub print_file {
+ my $filename = shift;
+ my $file = undef;
+ open($file, "<", $filename)
+ or die "$0: can't open $filename for reading: $!";
+ print while (<$file>);
+ die "unexpected error while reading from $filename: $!" if $!
+}
+
+sub print_header {
+ my $code = shift;
+ print <<~END;
+ Status: $code
+ Content-Type: text/html
+
+ END
+}
+
+sub render_page {
+ my ($docname, $doctitle) = @_;
+ my $doc_filename = "$BASEDIR/docs/$docname";
+
+ my $base_file = undef;
+ open($base_file, "<", $base_filename)
+ or die "$0: can't open $base_filename for reading: $!";
+
+ # print header and contents
+ print_header 200;
+ while (<$base_file>) {
+ if (/\[%title%\]/) {
+ print "$doctitle";
+ } elsif (/\[%content%\]/) {
+ print_file $doc_filename;
+ } elsif (/\[%status%\]/) {
+ print_file "$status_filename";
+ } else {
+ print;
+ }
+ }
+ die "unexpected error while reading from $base_filename: $!" if $!
+}
+
+sub render_error {
+ my $errcode = shift;
+ print_header $errcode;
+ print_file "$BASEDIR/docs/${errcode}.html";
+}
+
+my $path = $ENV{'PATH_INFO'} || '/';
+
+if ($path =~ /^\/?$/) {
+ render_page 'root', 'pastanoggin!!';
+} elsif ($path =~ /^\/contact\/?$/) {
+ render_page 'contact', 'hello, is it me you\'re looking for?';
+} elsif ($path =~ /^\/blog\/?$/) {
+ render_page 'blog', 'yapyapyapyap :D';
+} elsif ($path =~ /^\/links\/?$/) {
+ render_page 'links', 'the interwebs';
+} else {
+ render_error '404';
+}