From: Emil Williams Date: Wed, 21 May 2025 00:57:48 +0000 (-0600) Subject: -- X-Git-Url: https://git.xolatile.top/?a=commitdiff_plain;h=a9a09294299a234acf477b51b20a9819ab0f0a58;p=emil-3chen.org.git -- --- diff --git a/perl/Triple.pm b/perl/Triple.pm index 26b70a6..267d70a 100644 --- a/perl/Triple.pm +++ b/perl/Triple.pm @@ -11,6 +11,8 @@ use FCGI; use Template; use URI::Escape; +use Syntax::Keyword::Try; + # Internal use Triple::Secrets; use Triple::Init; @@ -72,74 +74,78 @@ sub Triple::main { threads => \@threads, }; - while($request->Accept() >= 0) { - - my $cgi = CGI->new; - - $vars->{"ip"} = $ENV{'REMOTE_ADDR'} || '?'; - $vars->{"uri"} = $ENV{'REQUEST_URI'} // '/'; - my $method = $ENV{'REQUEST_METHOD'} || ''; - my $content_length = $ENV{'CONTENT_LENGTH'} || 0; - my $content_type = $ENV{'CONTENT_TYPE'} || ''; - my $body = ''; - my $status = ''; - my $location = ''; - - if ($method eq 'POST') { - syslog("info", "something like posting has occurred"); - if ($content_length > 0) { - read(STDIN, $body, $content_length); + try { + while($request->Accept() >= 0) { + + my $cgi = CGI->new; + + $vars->{"ip"} = $ENV{'REMOTE_ADDR'} || '?'; + $vars->{"uri"} = $ENV{'REQUEST_URI'} // '/'; + my $method = $ENV{'REQUEST_METHOD'} || ''; + my $content_length = $ENV{'CONTENT_LENGTH'} || 0; + my $content_type = $ENV{'CONTENT_TYPE'} || ''; + my $body = ''; + my $status = ''; + my $location = ''; + + if ($method eq 'POST') { + syslog("info", "something like posting has occurred"); + if ($content_length > 0) { + read(STDIN, $body, $content_length); + } + + open(my $fh, '>', 'post_dump.txt') or die; + # print $fh $body; + # print $fh "\r\n"; + my %post = parse_post($body); + print $fh Dumper %post; + close $fh; + + $status = '302 Found'; + $location = $vars->{"uri"}; } - open(my $fh, '>', 'post_dump.txt') or die; - # print $fh $body; - # print $fh "\r\n"; - my %post = parse_post($body); - print $fh Dumper %post; - close $fh; - - $status = '302 Found'; - $location = $vars->{"uri"}; - } - - my @search = @{$page{$vars->{uri}}}; - if ($search[PAGE_TYPE] == REDIRECT_PAGE) { - # $vars->{uri} = $search[PAGE_TO]; - $status = '301 Moved Permanently'; - $location = $search[PAGE_TO]; - } - - if ($location) { - print $cgi->header( - -Content_Type => 'text/html', - -charset => 'UTF-8', - -status => $status, - -location => $location, - ); - } else { - print $cgi->header( - -Content_Type => 'text/html', - -charset => 'UTF-8', - ); - } + my @search = @{$page{$vars->{uri}}}; + if ($search[PAGE_TYPE] == REDIRECT_PAGE) { + # $vars->{uri} = $search[PAGE_TO]; + $status = '301 Moved Permanently'; + $location = $search[PAGE_TO]; + } - next if $status ne ''; - - my $page = $static{$vars->{uri}}; - if (not $page) { - if (@{$page{$vars->{uri}}}[PAGE_TO]) { - } - my $dynamic = $page{$vars->{uri}}; - if ($dynamic) { - my @set = @{$dynamic}; - $vars->{"title"} = "$set[PAGE_TITLE]"; - $vars->{"description"} = "$set[PAGE_DESCRIPTION]"; - $template->process($set[PAGE_TT], $vars, \$page) or syslog("info", $template->error()); + if ($location) { + print $cgi->header( + -Content_Type => 'text/html', + -charset => 'UTF-8', + -status => $status, + -location => $location, + ); } else { - $page = $static{''}; + print $cgi->header( + -Content_Type => 'text/html', + -charset => 'UTF-8', + ); + } + + next if $status ne ''; + + my $page = $static{$vars->{uri}}; + if (not $page) { + if (@{$page{$vars->{uri}}}[PAGE_TO]) { + } + my $dynamic = $page{$vars->{uri}}; + if ($dynamic) { + my @set = @{$dynamic}; + $vars->{"title"} = "$set[PAGE_TITLE]"; + $vars->{"description"} = "$set[PAGE_DESCRIPTION]"; + $template->process($set[PAGE_TT], $vars, \$page) or syslog("info", $template->error()); + } else { + $page = $static{''}; + } } + print $page; } - print $page; + } catch { + syslog("info", "Crashed"); } }