3 %# Pastebin creation webservice for Odin
5 %# (c) 2015 Mark Wooding
7 %#----- Licensing notice ----------------------------------------------------
9 %# This file is part of the `odin.gg' service, `odin-cgi'.
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.
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.
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/>.
26 my $tag = $m->dhandler_arg;
28 sub set_handoff_cookie ($$%) {
29 my ($tag, $edit, %attr) = @_;
30 Odin::bake_cookie $r, "odin-handoff.$tag=$edit",
31 -path => "$Odin::PASTEBIN_PATH/", %attr;
36 return $Odin::COOKIE{"odin-cookie-probe"} ? "" : "?honc=$edit";
39 Odin::bake_cookie $r, "odin-cookie-probe=t";
42 lang => $lang, title => $title,
43 content => Odin::tidy_pastebin_content $content
49 my $db = Odin::open_db;
50 Odin::get_pastebin $db, $tag, my %old;
52 $r->content_type("text/plain; charset=utf8");
53 $m->print($old{content});
55 $edit = $Odin::COOKIE{"odin-handoff.$tag"};
56 $m->comp("%show", tag => $tag,
57 honc => $honc, edit => $edit // $honc, %old);
61 Odin::delete_pastebin $tag, $edit;
62 set_handoff_cookie $tag, "nil", -max_age => 5;
63 $m->redirect("$Odin::PASTEBIN/");
65 set_handoff_cookie $tag, $edit;
66 my $editp = Odin::update_pastebin $tag, $edit, %props;
68 $m->redirect("$Odin::PASTEBIN/$tag" . hasuff $edit);
70 $m->comp("%edit", tag => $tag, edit => $edit, %props);
74 } elsif (defined $content) {
75 ($tag, $edit) = Odin::new_pastebin %props;
76 set_handoff_cookie $tag, $edit;
77 $m->redirect("$Odin::PASTEBIN/$tag" . hasuff $edit);
79 Odin::path_info($r) =~ m:/$:
80 or $m->redirect("$Odin::PASTEBIN/", 301);
95 <&| SELF:error, title => "not found", status => 404 &>\
96 tag ‘<% $tag %>’ not found
104 <&| SELF:error, status => 400 &>\
105 invalid paste content
113 <&| SELF:error, status => 403 &>\
123 use Digest::SHA qw(sha256_hex);