]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/web/nopaste.py
nopaste: Add a simple cURL interface
[ipfire.org.git] / 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):