<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# HTTP basic auth plugin.
package IkiWiki::Plugin::httpauth;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "httpauth", call =&gt; \&amp;getsetup);
	hook(type =&gt; "auth", id =&gt; "httpauth", call =&gt; \&amp;auth);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 0,
		},
		cgiauthurl =&gt; {
			type =&gt; "string",
			example =&gt; "http://example.com/wiki/auth/ikiwiki.cgi",
			description =&gt; "url to redirect to when authentication is needed",
			safe =&gt; 1,
			rebuild =&gt; 0,
		},
}

sub auth ($$) {
	my $cgi=shift;
	my $session=shift;

	if (defined $cgi-&gt;remote_user()) {
		$session-&gt;param("name", $cgi-&gt;remote_user());
	}
	elsif (defined $config{cgiauthurl}) {
		IkiWiki::redirect($cgi, $config{cgiauthurl}.'?'.$cgi-&gt;query_string());
		exit;
	}
}

1
</pre></body></html>