pagestats: Add show parameter. Closes: #562129
[ikiwiki] / 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 }
13
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => 0,
19                 },
20                 cgiauthurl => {
21                         type => "string",
22                         example => "http://example.com/wiki/auth/ikiwiki.cgi",
23                         description => "url to redirect to when authentication is needed",
24                         safe => 1,
25                         rebuild => 0,
26                 },
27 }
28
29 sub auth ($$) {
30         my $cgi=shift;
31         my $session=shift;
32
33         if (defined $cgi->remote_user()) {
34                 $session->param("name", $cgi->remote_user());
35         }
36         elsif (defined $config{cgiauthurl}) {
37                 IkiWiki::redirect($cgi, $config{cgiauthurl}.'?'.$cgi->query_string());
38                 exit;
39         }
40 }
41
42 1