use Template;
use URI::Escape;
+use Syntax::Keyword::Try;
+
# Internal
use Triple::Secrets;
use Triple::Init;
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");
}
}