2 # HTTP basic auth plugin.
3 package IkiWiki::Plugin::httpauth;
10 hook(type => "getsetup", id => "httpauth", call => \&getsetup);
11 hook(type => "auth", id => "httpauth", call => \&auth);
12 hook(type => "formbuilder_setup", id => "httpauth",
13 call => \&formbuilder_setup);
14 hook(type => "canedit", id => "httpauth", call => \&canedit);
15 hook(type => "pagetemplate", id => "httpauth", call => \&pagetemplate);
26 example => "http://example.com/wiki/auth/ikiwiki.cgi",
27 description => "url to redirect to when authentication is needed",
31 httpauth_pagespec => {
33 example => "!*/Discussion",
34 description => "PageSpec of pages where only httpauth will be used for authentication",
40 sub redir_cgiauthurl ($;@) {
43 IkiWiki::redirect($cgi,
44 IkiWiki::cgiurl(cgiurl => $config{cgiauthurl}, @_));
52 if (defined $cgi->remote_user()) {
53 $session->param("name", $cgi->remote_user());
57 sub formbuilder_setup (@) {
60 my $form=$params{form};
61 my $session=$params{session};
63 my $buttons=$params{buttons};
65 if ($form->title eq "signin" &&
66 ! defined $cgi->remote_user() && defined $config{cgiauthurl}) {
67 my $button_text="Login with HTTP auth";
68 push @$buttons, $button_text;
70 if ($form->submitted && $form->submitted eq $button_text) {
71 # bounce thru cgiauthurl and then back to
72 # the stored postsignin action
73 redir_cgiauthurl($cgi, do => "postsignin");
78 sub test_httpauth_pagespec ($) {
81 return defined $config{httpauth_pagespec} &&
82 length $config{httpauth_pagespec} &&
83 defined $config{cgiauthurl} &&
84 pagespec_match($page, $config{httpauth_pagespec});
92 if (! defined $cgi->remote_user() && test_httpauth_pagespec($page)) {
94 IkiWiki::redirect($cgi,
95 $config{cgiauthurl}.'?'.$cgi->query_string());
104 sub pagetemplate (@_) {
106 my $template=$params{template};
108 if ($template->param("editurl") &&
109 test_httpauth_pagespec($params{page})) {
110 # go directly to cgiauthurl when editing a page matching
112 $template->param(editurl => IkiWiki::cgiurl(
113 cgiurl => $config{cgiauthurl},
114 do => "edit", page => $params{page}));