From: Michael Tremer Date: Fri, 23 Feb 2024 18:51:53 +0000 (+0000) Subject: nopaste: Add a simple cURL interface X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f678c97b441f072b0d6b886b8c1ff586088a54ed;p=ipfire.org.git nopaste: Add a simple cURL interface Signed-off-by: Michael Tremer --- diff --git a/src/web/nopaste.py b/src/web/nopaste.py index dd7a94a6..f0508d83 100644 --- a/src/web/nopaste.py +++ b/src/web/nopaste.py @@ -26,6 +26,30 @@ class CreateHandler(base.AnalyticsMixin, base.BaseHandler): # Redirect to the paste return self.redirect("/view/%s" % paste.uuid) + # cURL Interface + + def check_xsrf_cookie(self): + # Skip the check on PUT + if self.request.method == "PUT": + return + + # Perform the check as usual + super().check_xsrf_cookie() + + # XXX implement HTTP Basic authentication + + @base.ratelimit(minutes=15, requests=5) + def put(self): + with self.db.transaction(): + paste = self.backend.nopaste.create( + self.request.body, address=self.get_remote_ip()) + + # Send a message to the client + self.write("https://%s/view/%s\n" % (self.request.host, paste.uuid)) + + # All done + self.finish() + class RawHandler(base.AnalyticsMixin, base.BaseHandler): def get(self, uid):