put.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2009 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. =head1 Put Extension
  16. This module allows you to upload wiki pages using the PUT request
  17. method. For example:
  18. echo test | curl -T - http://www.emacswiki.org/cgi-bin/test/Mu
  19. This will replace the Mu page with "test".
  20. Note that you cannot use an URL that will be rewritten by Apache
  21. mod_rewrite as the target for your PUT request. Apparently mod_rewrite
  22. only works reliably for GET requests.
  23. =cut
  24. use strict;
  25. use v5.10;
  26. AddModuleDescription('put.pl');
  27. our ($q, @MyInitVariables, $MaxPost);
  28. push(@MyInitVariables, \&PutMethodHandler);
  29. sub PutMethodHandler {
  30. if ($q->request_method() eq 'PUT') {
  31. my $data;
  32. while (<STDIN>) {
  33. $data .= $_;
  34. # protect against denial of service attacks?
  35. if (length($data) > $MaxPost) {
  36. ReportError(T('Upload is limited to %s bytes', $MaxPost),
  37. '413 REQUEST ENTITY TOO LARGE');
  38. }
  39. }
  40. SetParam('title', GetId());
  41. SetParam('text', $data);
  42. }
  43. }