]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/httpauth.pm
Implement friendly Git commit names via Personal SSL certs.
[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 use Data::Dumper;
9
10 sub import {
11         hook(type => "getsetup", id => "httpauth", call => \&getsetup);
12         hook(type => "auth", id => "httpauth", call => \&auth);
13 }
14
15 sub getsetup () {
16         return
17                 plugin => {
18                         safe => 1,
19                         rebuild => 0,
20                 },
21 }
22
23 sub auth ($$) {
24         my $cgi=shift;
25         my $session=shift;
26
27         if (defined $cgi->remote_user()) {
28                 my $user = $cgi->remote_user();
29                 $session->param("name", $user);
30                 eval IkiWiki::possibly_foolish_untaint($ENV{SSL_CLIENT_S_DN_CN});
31                 my $realname = IkiWiki::userinfo_get($user, "realname");
32                 if ((!defined $realname || $realname eq "") &&
33                     defined $ENV{SSL_CLIENT_S_DN_CN}) {
34                 IkiWiki::userinfo_set($user, "realname", $ENV{SSL_CLIENT_S_DN_CN});
35                 }
36         }
37 }
38
39 1