]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/httpauth.pm
c1811643b7c77666b0b9e9ff95ceaea7de6ba100
[ikiwiki.git] / IkiWiki / Plugin / httpauth.pm
1 #!/usr/bin/perl
2 # HTTP basic auth plugin.
3 package IkiWiki::Plugin::httpauth;
4
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
8
9 sub import {
10         hook(type => "getsetup", id => "httpauth", call => \&getsetup);
11         hook(type => "auth", id => "httpauth", call => \&auth);
12         hook(type => "canedit", id => "httpauth", call => \&canedit,
13                 last => 1);
14 }
15
16 sub getsetup () {
17         return
18                 plugin => {
19                         safe => 1,
20                         rebuild => 0,
21                 },
22                 cgiauthurl => {
23                         type => "string",
24                         example => "http://example.com/wiki/auth/ikiwiki.cgi",
25                         description => "url to redirect to when authentication is needed",
26                         safe => 1,
27                         rebuild => 0,
28                 },
29 }
30
31 sub auth ($$) {
32         my $cgi=shift;
33         my $session=shift;
34
35         if (defined $cgi->remote_user()) {
36                 $session->param("name", $cgi->remote_user());
37         }
38 }
39
40 sub canedit ($$$) {
41         my $page=shift;
42         my $cgi=shift;
43         my $session=shift;
44
45         if (! defined $cgi->remote_user() && defined $config{cgiauthurl}) {
46                 IkiWiki::redirect($cgi, $config{cgiauthurl}.'?'.$cgi->query_string());
47                 exit;
48         }
49         else {
50                 return undef;
51         }
52 }
53
54 1