X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/07c9cddb50856d8f94c9618187227027a27fe4c8..c01485ae1ad751ac87eb3cfa392f6d276d5b1157:/IkiWiki/CGI.pm?ds=sidebyside diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index a3486cbb4..81cb42d13 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -9,7 +9,7 @@ use IkiWiki::UserInfo; use open qw{:utf8 :std}; use Encode; -sub printheader ($) { #{{{ +sub printheader ($) { my $session=shift; if ($config{sslcookie}) { @@ -19,9 +19,9 @@ sub printheader ($) { #{{{ print $session->header(-charset => 'utf-8', -cookie => $session->cookie(-httponly => 1)); } -} #}}} +} -sub showform ($$$$;@) { #{{{ +sub showform ($$$$;@) { my $form=shift; my $buttons=shift; my $session=shift; @@ -38,7 +38,7 @@ sub showform ($$$$;@) { #{{{ print misctemplate($form->title, $form->render(submit => $buttons), @_); } -sub redirect ($$) { #{{{ +sub redirect ($$) { my $q=shift; my $url=shift; if (! $config{w3mmode}) { @@ -48,9 +48,9 @@ sub redirect ($$) { #{{{ print "Content-type: text/plain\n"; print "W3m-control: GOTO $url\n\n"; } -} #}}} +} -sub decode_cgi_utf8 ($) { #{{{ +sub decode_cgi_utf8 ($) { # decode_form_utf8 method is needed for 5.10 if ($] < 5.01) { my $cgi = shift; @@ -58,9 +58,9 @@ sub decode_cgi_utf8 ($) { #{{{ $cgi->param($f, map { decode_utf8 $_ } $cgi->param($f)); } } -} #}}} +} -sub decode_form_utf8 ($) { #{{{ +sub decode_form_utf8 ($) { if ($] >= 5.01) { my $form = shift; foreach my $f ($form->field) { @@ -70,11 +70,11 @@ sub decode_form_utf8 ($) { #{{{ ); } } -} #}}} +} # Check if the user is signed in. If not, redirect to the signin form and # save their place to return to later. -sub needsignin ($$) { #{{{ +sub needsignin ($$) { my $q=shift; my $session=shift; @@ -85,9 +85,9 @@ sub needsignin ($$) { #{{{ cgi_savesession($session); exit; } -} #}}} +} -sub cgi_signin ($$) { #{{{ +sub cgi_signin ($$) { my $q=shift; my $session=shift; @@ -127,9 +127,9 @@ sub cgi_signin ($$) { #{{{ } showform($form, $buttons, $session, $q); -} #}}} +} -sub cgi_postsignin ($$) { #{{{ +sub cgi_postsignin ($$) { my $q=shift; my $session=shift; @@ -144,9 +144,9 @@ sub cgi_postsignin ($$) { #{{{ else { error(gettext("login failed, perhaps you need to turn on cookies?")); } -} #}}} +} -sub cgi_prefs ($$) { #{{{ +sub cgi_prefs ($$) { my $q=shift; my $session=shift; @@ -254,9 +254,9 @@ sub cgi_prefs ($$) { #{{{ } showform($form, $buttons, $session, $q); -} #}}} +} -sub check_banned ($$) { #{{{ +sub check_banned ($$) { my $q=shift; my $session=shift; @@ -275,7 +275,7 @@ sub check_banned ($$) { #{{{ } } -sub cgi_getsession ($) { #{{{ +sub cgi_getsession ($) { my $q=shift; eval q{use CGI::Session; use HTML::Entities}; @@ -294,32 +294,34 @@ sub cgi_getsession ($) { #{{{ umask($oldmask); return $session; -} #}}} +} -# The session id is stored on the form and checked to -# guard against CSRF. But only if the user is logged in, -# as anonok can allow anonymous edits. -sub checksessionexpiry ($$) { # {{{ +# To guard against CSRF, the user's session id (sid) +# can be stored on a form. This function will check +# (for logged in users) that the sid on the form matches +# the session id in the cookie. +sub checksessionexpiry ($$) { + my $q=shift; my $session = shift; - my $sid = shift; if (defined $session->param("name")) { + my $sid=$q->param('sid'); if (! defined $sid || $sid ne $session->id) { error(gettext("Your login session has expired.")); } } -} # }}} +} -sub cgi_savesession ($) { #{{{ +sub cgi_savesession ($) { my $session=shift; # Force session flush with safe umask. my $oldmask=umask(077); $session->flush; umask($oldmask); -} #}}} +} -sub cgi (;$$) { #{{{ +sub cgi (;$$) { my $q=shift; my $session=shift; @@ -389,16 +391,16 @@ sub cgi (;$$) { #{{{ else { error("unknown do parameter"); } -} #}}} +} # Does not need to be called directly; all errors will go through here. -sub cgierror ($) { #{{{ +sub cgierror ($) { my $message=shift; print "Content-type: text/html\n\n"; print misctemplate(gettext("Error"), "
".gettext("Error").": $message
"); die $@; -} #}}} +} 1