]> git.xolatile.top Git - emil-3chen.org.git/commitdiff
--
authorEmil Williams <emilemilemil@cock.li>
Wed, 21 May 2025 00:57:48 +0000 (18:57 -0600)
committerEmil Williams <emilemilemil@cock.li>
Wed, 21 May 2025 00:57:48 +0000 (18:57 -0600)
perl/Triple.pm

index 26b70a6d68d19544ce50feeb6fb29d5e695f9277..267d70ab51072e7de2d607568f89d647ba3d39f7 100644 (file)
@@ -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");
     }
 }