about summary refs log tree commit homepage
path: root/public-inbox-cgi
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2014-04-05 06:53:19 +0000
committerEric Wong <normalperson@yhbt.net>2014-04-05 06:55:35 +0000
commite97da7bb0d230fd624e7f21464c6355a4fdad119 (patch)
tree37becb267c83ee384adb9884c3891f9bc430523b /public-inbox-cgi
parente6c85810fc1536676fb72b4bf050aca72f0e9b10 (diff)
downloadpublic-inbox-e97da7bb0d230fd624e7f21464c6355a4fdad119.tar.gz
We should be able to wire up the rest, soon.
Diffstat (limited to 'public-inbox-cgi')
-rwxr-xr-xpublic-inbox-cgi92
1 files changed, 92 insertions, 0 deletions
diff --git a/public-inbox-cgi b/public-inbox-cgi
new file mode 100755
index 00000000..cfcf3feb
--- /dev/null
+++ b/public-inbox-cgi
@@ -0,0 +1,92 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+#
+# We focus on the lowest common denominators here:
+# - targeted at text-only console browsers (lynx, w3m, etc..)
+# - Only basic HTML, CSS only for line-wrapping <pre> text content for GUIs
+# - No JavaScript, graphics or icons allowed.
+# - Must not rely on static content
+# - UTF-8 is only for user-content, 7-bit US-ASCII for us
+
+use 5.008;
+use strict;
+use warnings;
+use CGI qw(:cgi :escapeHTML -nosticky); # PSGI/FastCGI/mod_perl compat
+use CGI::Util qw(unescape);
+use Encode;
+use PublicInbox::Config;
+our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
+our $pi_config;
+BEGIN {
+        $pi_config = PublicInbox::Config->new;
+        # TODO: detect and reload config as needed
+        if ($ENV{MOD_PERL}) {
+                CGI->compile;
+        }
+}
+
+sub main {
+        my $cgi = CGI->new;
+        if ($cgi->request_method !~ /\AGET|HEAD\z/) {
+                return r($cgi, "405 Method Not Allowed");
+        }
+        my $path_info = decode_utf8($ENV{PATH_INFO});
+        if ($path_info eq "/") {
+                r($cgi, "404 Not Found");
+        } elsif ($path_info =~ m!$LISTNAME_RE/?\z!o) {
+                get_list_log($cgi, $1);
+        } elsif ($path_info =~ m!$LISTNAME_RE/all\z!o) {
+                get_list_all($cgi, $1);
+        } elsif ($path_info =~ m!$LISTNAME_RE/index\.atom\.xml\z!o) {
+                get_atom_index($cgi, $1);
+        } elsif ($path_info =~ m!$LISTNAME_RE/all\.atom\.xml\z!o) {
+                get_atom_all($cgi, $1);
+        } elsif ($path_info =~ m!$LISTNAME_RE/mid/(\S+)\.txt\z!o) {
+                get_mid_txt($cgi, $1, $2);
+        } elsif ($path_info =~ m!$LISTNAME_RE/mid/(\S+)\.html\z!o) {
+                get_mid_html($cgi, $1, $2);
+        } elsif ($path_info =~ m!$LISTNAME_RE/mid/(\S+)\z!o) {
+                redirect_mid_html($cgi, $1, $2);
+        } else {
+                r($cgi, "404 Not Found");
+        }
+}
+
+binmode STDOUT, ':utf8';
+main();
+
+# simple response for errors
+sub r {
+        print $_[0]->header(-type => "text/plain",
+                                -status => $_[1],
+                                -charset => 'utf-8');
+}
+
+# /$LISTNAME/all.atom.xml        -> Atom feed, includes replies
+sub get_atom_all {
+        my ($cgi, $listname) = @_;
+        my $git_dir = $pi_config->get($listname, "mainrepo");
+        defined $git_dir or return r($cgi, "404 Not Found");
+
+        require PublicInbox::Feed;
+        print $cgi->header(-type => "application/xml", -charset => 'us-ascii',
+                                -status => '200 OK');
+
+        print PublicInbox::Feed->generate($git_dir, undef,
+                                        $pi_config, $listname, $cgi);
+}
+
+# /$LISTNAME/index.atom.xml        -> Atom feed
+sub get_atom_index {
+        my ($cgi, $listname) = @_;
+        my $git_dir = $pi_config->get($listname, "mainrepo");
+        defined $git_dir or return r($cgi, "404 Not Found");
+
+        require PublicInbox::Feed;
+        print $cgi->header(-type => "application/xml", -charset => 'us-ascii',
+                                -status => '200 OK');
+
+        print PublicInbox::Feed->generate($git_dir, undef,
+                                        $pi_config, $listname, $cgi, 1);
+}