summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/httpauth.pm
blob: 127c321f0491978c9b88760685963f785cd1062e (plain)
  1. #!/usr/bin/perl
  2. # HTTP basic auth plugin.
  3. package IkiWiki::Plugin::httpauth;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 3.00;
  7. sub import {
  8. hook(type => "getsetup", id => "httpauth", call => \&getsetup);
  9. hook(type => "auth", id => "httpauth", call => \&auth);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. safe => 1,
  15. rebuild => 0,
  16. },
  17. cgiauthurl => {
  18. type => "string",
  19. example => "http://example.com/wiki/auth/ikiwiki.cgi",
  20. description => "url to redirect to when authentication is needed",
  21. safe => 1,
  22. rebuild => 0,
  23. },
  24. }
  25. sub auth ($$) {
  26. my $cgi=shift;
  27. my $session=shift;
  28. if (defined $cgi->remote_user()) {
  29. $session->param("name", $cgi->remote_user());
  30. }
  31. elsif (defined $config{cgiauthurl}) {
  32. IkiWiki::redirect($cgi, $config{cgiauthurl}.'?'.$cgi->query_string());
  33. exit;
  34. }
  35. }
  36. 1