]> git.ipfire.org Git - ipfire.org.git/commitdiff
nopaste: Add a simple cURL interface
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Feb 2024 18:51:53 +0000 (18:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Feb 2024 18:51:53 +0000 (18:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/nopaste.py

index dd7a94a665fec6327848687d349dd87a7995ff85..f0508d837bb1813bea0e8523d1043c1fff9e303c 100644 (file)
@@ -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):