chiark / gitweb /
d8573b5bd23d1042bf7949ed833586c8157b17e5
[odin-cgi] / mason / pastebin / %show
1 %# -*-html-*-
2 %#
3 %# Pastebin display webservice for Odin
4 %#
5 %# (c) 2015 Mark Wooding
6 %#
7 %#----- Licensing notice ----------------------------------------------------
8 %#
9 %# This file is part of the `odin.gg' service, `odin-cgi'.
10 %#
11 %# `odin-cgi' is free software; you can redistribute it and/or modify
12 %# it under the terms of the GNU Affero General Public License as
13 %# published by the Free Software Foundation; either version 3 of the
14 %# License, or (at your option) any later version.
15 %#
16 %# `odin-cgi' is distributed in the hope that it will be useful,
17 %# but WITHOUT ANY WARRANTY; without even the implied warranty of
18 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 %# GNU Affero General Public License for more details.
20 %#
21 %# You should have received a copy of the GNU Affero General Public
22 %# License along with `odin-cgi'; if not, see
23 %# <http://www.gnu.org/licenses/>.
24 %#
25 <&| SELF:wrapper,
26         title => Odin::escapify($m, $title) . " (odin.gg Paste Bin)" &>
27 <h1><tt>odin.gg</tt> Paste Bin: <% $title %></h1>
28 <div class="menu">
29   <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?op=raw" |h %>">Raw</a></span>
30 % if (defined $edit) {
31   <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?edit=$edit" |h %>">Edit</a></span>
32 % }
33   <span class="item"><a href="<% "$Odin::PASTEBIN/" |h %>">New</a></span>
34 </div>
35 % if (defined $honc) {
36 <div class="note">
37 <p>Your browser doesn't appear to be accepting my cookies.
38 <p>Don't share the link to this page with other people.  <b>If you do,
39   they'll be able to edit this paste just as you can</b>, using the
40   <b>Edit</b> link at the top of the page.
41 <p>Instead, share this link:
42   <a href="<% "$Odin::PASTEBIN/$tag" |h %>"><%
43     "$Odin::PASTEBIN/$tag" |h %></a>
44 </div>
45 % }
46 % if ($lang eq 'txt') {
47 <pre class="paste">
48 <% $content |h %>\
49 </pre>
50 % } elsif ($lang =~ /^hl:(.*)$/) {
51 <pre class="paste">
52 % filter "highlight", $m, $content,
53 %   "highlight", "-Ohtml", "-f", "-t8", "-S$1";
54 </pre>
55 % } elsif ($lang eq "md") {
56 % filter "markdown", $m, $content,
57 %   "markdown", "-fnohtml,autolink,safelink,footnote";
58 % } else {
59 <div class="note">
60 <p>I don't know how to display content with language
61   &lsquo;<% $lang |h %>&rsquo;.  This is a bug in the Pastebin program.
62   Here's the raw text, in case that's useful.
63 </div>
64 <pre class="paste">
65 <% $content |h %>\
66 </pre>
67 % }
68 </&>
69 %#
70 <%args>
71         $content
72         $title
73         $lang
74         $tag
75         $honc
76         $edit
77 </%args>
78 %#
79 <%init>
80         my $db = Odin::open_db;
81 </%init>
82 %#
83 <%once>
84         use utf8;
85
86         sub filter ($$$@) {
87           my ($what, $m, $content, @cmd) = @_;
88           my $kid = open my $fh, "-|" // die "fork: $!";
89           if ($kid == 0) {
90             open my $hl, "|-", @cmd or die "open $what: $!";
91             syswrite $hl, $content // die "$what write: $!";
92             close $hl or die "$what kid: $!, $?";
93             exit 0;
94           } else {
95             while (sysread $fh, my $buf, 8192) { $m->print($buf); }
96             close $fh and waitpid $kid, 0
97               or die "$what parent: $!, $?";
98           }
99         }
100 </%once>