+ elsif ($form->submitted eq 'Register') {
+ my $user_name=$form->field('name');
+ if (userinfo_setall($user_name, {
+ 'email' => $form->field('email'),
+ 'password' => $form->field('password'),
+ 'regdate' => time
+ })) {
+ $form->field(name => "confirm_password", type => "hidden");
+ $form->field(name => "email", type => "hidden");
+ $form->text("Registration successful. Now you can Login.");
+ print $session->header();
+ print misctemplate($form->title, $form->render(submit => ["Login"]));
+ }
+ else {
+ error("Error saving registration.");
+ }
+ }
+ elsif ($form->submitted eq 'Mail Password') {
+ my $user_name=$form->field("name");
+ my $template=HTML::Template->new(
+ filename => "$config{templatedir}/passwordmail.tmpl"
+ );
+ $template->param(
+ user_name => $user_name,
+ user_password => userinfo_get($user_name, "password"),
+ wikiurl => $config{url},
+ wikiname => $config{wikiname},
+ REMOTE_ADDR => $ENV{REMOTE_ADDR},
+ );
+
+ eval q{use Mail::Sendmail};
+ my ($fromhost) = $config{cgiurl} =~ m!/([^/]+)!;
+ sendmail(
+ To => userinfo_get($user_name, "email"),
+ From => "$config{wikiname} admin <".(getpwuid($>))[0]."@".$fromhost.">",
+ Subject => "$config{wikiname} information",
+ Message => $template->output,
+ ) or error("Failed to send mail");
+
+ $form->text("Your password has been emailed to you.");
+ $form->field(name => "name", required => 0);
+ print $session->header();
+ print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
+ }
+ }
+ else {
+ print $session->header();
+ print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
+ }
+} #}}}
+
+sub is_admin ($) { #{{{
+ my $user_name=shift;
+
+ return grep { $_ eq $user_name } @{$config{adminuser}};
+} #}}}
+
+sub glob_match ($$) { #{{{
+ my $page=shift;
+ my $glob=shift;
+
+ # turn glob into safe regexp
+ $glob=quotemeta($glob);
+ $glob=~s/\\\*/.*/g;
+ $glob=~s/\\\?/./g;
+ $glob=~s!\\/!/!g;
+
+ $page=~/^$glob$/i;
+} #}}}
+
+sub globlist_match ($$) { #{{{
+ my $page=shift;
+ my @globlist=split(" ", shift);
+
+ # check any negated globs first
+ foreach my $glob (@globlist) {
+ return 0 if $glob=~/^!(.*)/ && glob_match($page, $1);
+ }
+
+ foreach my $glob (@globlist) {
+ return 1 if glob_match($page, $glob);
+ }
+
+ return 0;
+} #}}}
+
+sub page_locked ($$;$) { #{{{
+ my $page=shift;
+ my $session=shift;
+ my $nonfatal=shift;
+
+ my $user=$session->param("name");
+ return if length $user && is_admin($user);
+
+ foreach my $admin (@{$config{adminuser}}) {
+ my $locked_pages=userinfo_get($admin, "locked_pages");
+ if (globlist_match($page, userinfo_get($admin, "locked_pages"))) {
+ return 1 if $nonfatal;
+ error(htmllink("", $page, 1)." is locked by ".
+ htmllink("", $admin, 1)." and cannot be edited.");
+ }
+ }
+
+ return 0;
+} #}}}
+
+sub cgi_prefs ($$) { #{{{
+ my $q=shift;
+ my $session=shift;
+
+ eval q{use CGI::FormBuilder};
+ my $form = CGI::FormBuilder->new(
+ title => "preferences",
+ fields => [qw(do name password confirm_password email locked_pages)],
+ header => 0,
+ method => 'POST',
+ validate => {
+ confirm_password => {
+ perl => q{eq $form->field("password")},
+ },
+ email => 'EMAIL',
+ },
+ required => 'NONE',
+ javascript => 0,
+ params => $q,
+ action => $q->request_uri,
+ template => (-e "$config{templatedir}/prefs.tmpl" ?
+ "$config{templatedir}/prefs.tmpl" : "")
+ );
+ my @buttons=("Save Preferences", "Logout", "Cancel");
+
+ my $user_name=$session->param("name");
+ $form->field(name => "do", type => "hidden");
+ $form->field(name => "name", disabled => 1,
+ value => $user_name, force => 1);
+ $form->field(name => "password", type => "password");
+ $form->field(name => "confirm_password", type => "password");
+ $form->field(name => "locked_pages", size => 50,
+ comment => "(".htmllink("", "GlobList", 1).")");
+
+ if (! is_admin($user_name)) {
+ $form->field(name => "locked_pages", type => "hidden");
+ }
+
+ if (! $form->submitted) {
+ $form->field(name => "email", force => 1,
+ value => userinfo_get($user_name, "email"));
+ $form->field(name => "locked_pages", force => 1,
+ value => userinfo_get($user_name, "locked_pages"));
+ }
+
+ if ($form->submitted eq 'Logout') {
+ $session->delete();
+ print $q->redirect($config{url});