daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env plackup
  2. use strict;
  3. use warnings;
  4.  
  5. use Plack::Builder;
  6. use Plack::App::File;
  7. use Plack::App::WrapCGI;
  8.  
  9. BEGIN {
  10.     chdir "/var/www/blogsum" or die "Unable to chdir: $!";
  11.     require "./startup.pl";
  12. }
  13. use lib '.';
  14.  
  15. my $themes = Plack::App::File->new(  root   => "themes"   )->to_app;
  16. my $index = Plack::App::WrapCGI->new(script => "index.cgi")->to_app;
  17. my $admin = Plack::App::WrapCGI->new(script => "admin.cgi")->to_app;
  18.  
  19. sub rewrite_rule ($$$) {
  20.     my ($env, $match, $action) = @_;
  21.     $action->($env) if $env->{PATH_INFO} =~ s{$match}{};
  22. }
  23.  
  24. sub rewrite { my $app = shift; sub {
  25.     my $env = shift;
  26.  
  27.     rewrite_rule $env, qr{^/rss.xml$}, sub {
  28.         $env->{QUERY_STRING} .= "&rss=1";
  29.     };
  30.     rewrite_rule $env, qr{^/rss2.xml$}, sub {
  31.         $env->{QUERY_STRING} .= "&rss=2";
  32.     };
  33.     rewrite_rule $env, qr{^/Page/([^/]+)/?$}, sub {
  34.         $env->{QUERY_STRING} .= "&page=$1";
  35.     };
  36.     rewrite_rule $env, qr{^/Tags/([^/]+)/?$}, sub {
  37.         $env->{QUERY_STRING} .= "&search=$1";
  38.     };
  39.     rewrite_rule $env, qr{^/([0-9]{4})/([0-9]{2})/([^/]+)$}, sub {
  40.         $env->{QUERY_STRING} .= "view=article&year=$1&month=$2&uri=$3";
  41.     };
  42.     rewrite_rule $env, qr{^/([0-9]{4})/([0-9]{2})/?$}, sub {
  43.         $env->{QUERY_STRING} .= "view=article&year=$1&month=$2";
  44.     };
  45.     rewrite_rule $env, qr{^/([0-9]{4})/?$}, sub {
  46.         $env->{QUERY_STRING} .= "view=article&year=$1";
  47.     };
  48.  
  49.     $env->{PATH_INFO} = '/index.cgi' if $env->{PATH_INFO} eq '/';
  50.     $env->{PATH_INFO} ||= '/index.cgi' ;
  51.  
  52.     return $app->($env);
  53. } }
  54.  
  55. builder {
  56.     enable \&rewrite;
  57.  
  58.     mount "/themes"    => $themes;
  59.     mount "/admin.cgi" => $admin;
  60.     mount "/index.cgi" => $index;
  61. };
RAW Paste Data
Top