summaryrefslogtreecommitdiff
path: root/IkiWiki/CGI.pm
blob: a050434782c6445d8cb9d05738305bee3ea5833e (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. use IkiWiki::UserInfo;
  7. use open qw{:utf8 :std};
  8. use Encode;
  9. sub printheader ($) { #{{{
  10. my $session=shift;
  11. if ($config{sslcookie}) {
  12. print $session->header(-charset => 'utf-8',
  13. -cookie => $session->cookie(-secure => 1));
  14. } else {
  15. print $session->header(-charset => 'utf-8');
  16. }
  17. } #}}}
  18. sub showform ($$$$;@) { #{{{
  19. my $form=shift;
  20. my $buttons=shift;
  21. my $session=shift;
  22. my $cgi=shift;
  23. if (exists $hooks{formbuilder}) {
  24. run_hooks(formbuilder => sub {
  25. shift->(form => $form, cgi => $cgi, session => $session,
  26. buttons => $buttons);
  27. });
  28. }
  29. printheader($session);
  30. print misctemplate($form->title, $form->render(submit => $buttons), @_);
  31. }
  32. sub redirect ($$) { #{{{
  33. my $q=shift;
  34. my $url=shift;
  35. if (! $config{w3mmode}) {
  36. print $q->redirect($url);
  37. }
  38. else {
  39. print "Content-type: text/plain\n";
  40. print "W3m-control: GOTO $url\n\n";
  41. }
  42. } #}}}
  43. sub check_canedit ($$$;$) { #{{{
  44. my $page=shift;
  45. my $q=shift;
  46. my $session=shift;
  47. my $nonfatal=shift;
  48. my $canedit;
  49. run_hooks(canedit => sub {
  50. return if defined $canedit;
  51. my $ret=shift->($page, $q, $session);
  52. if (defined $ret) {
  53. if ($ret eq "") {
  54. $canedit=1;
  55. }
  56. elsif (ref $ret eq 'CODE') {
  57. $ret->() unless $nonfatal;
  58. $canedit=0;
  59. }
  60. elsif (defined $ret) {
  61. error($ret) unless $nonfatal;
  62. $canedit=0;
  63. }
  64. }
  65. });
  66. return $canedit;
  67. } #}}}
  68. sub decode_cgi_utf8 ($) { #{{{
  69. # decode_form_utf8 method is needed for 5.10
  70. if ($] < 5.01) {
  71. my $cgi = shift;
  72. foreach my $f ($cgi->param) {
  73. $cgi->param($f, map { decode_utf8 $_ } $cgi->param($f));
  74. }
  75. }
  76. } #}}}
  77. sub decode_form_utf8 ($) { #{{{
  78. if ($] >= 5.01) {
  79. my $form = shift;
  80. foreach my $f ($form->field) {
  81. $form->field(name => $f,
  82. value => decode_utf8($form->field($f)),
  83. force => 1,
  84. );
  85. }
  86. }
  87. } #}}}
  88. # Check if the user is signed in. If not, redirect to the signin form and
  89. # save their place to return to later.
  90. sub needsignin ($$) { #{{{
  91. my $q=shift;
  92. my $session=shift;
  93. if (! defined $session->param("name") ||
  94. ! userinfo_get($session->param("name"), "regdate")) {
  95. $session->param(postsignin => $ENV{QUERY_STRING});
  96. cgi_signin($q, $session);
  97. cgi_savesession($session);
  98. exit;
  99. }
  100. } #}}}
  101. sub cgi_signin ($$) { #{{{
  102. my $q=shift;
  103. my $session=shift;
  104. decode_cgi_utf8($q);
  105. eval q{use CGI::FormBuilder};
  106. error($@) if $@;
  107. my $form = CGI::FormBuilder->new(
  108. title => "signin",
  109. name => "signin",
  110. charset => "utf-8",
  111. method => 'POST',
  112. required => 'NONE',
  113. javascript => 0,
  114. params => $q,
  115. action => $config{cgiurl},
  116. header => 0,
  117. template => {type => 'div'},
  118. stylesheet => baseurl()."style.css",
  119. );
  120. my $buttons=["Login"];
  121. if ($q->param("do") ne "signin" && !$form->submitted) {
  122. $form->text(gettext("You need to log in first."));
  123. }
  124. $form->field(name => "do", type => "hidden", value => "signin",
  125. force => 1);
  126. decode_form_utf8($form);
  127. run_hooks(formbuilder_setup => sub {
  128. shift->(form => $form, cgi => $q, session => $session,
  129. buttons => $buttons);
  130. });
  131. decode_form_utf8($form);
  132. if ($form->submitted) {
  133. $form->validate;
  134. }
  135. showform($form, $buttons, $session, $q);
  136. } #}}}
  137. sub cgi_postsignin ($$) { #{{{
  138. my $q=shift;
  139. my $session=shift;
  140. # Continue with whatever was being done before the signin process.
  141. if (defined $session->param("postsignin")) {
  142. my $postsignin=CGI->new($session->param("postsignin"));
  143. $session->clear("postsignin");
  144. cgi($postsignin, $session);
  145. cgi_savesession($session);
  146. exit;
  147. }
  148. else {
  149. error(gettext("login failed, perhaps you need to turn on cookies?"));
  150. }
  151. } #}}}
  152. sub cgi_prefs ($$) { #{{{
  153. my $q=shift;
  154. my $session=shift;
  155. needsignin($q, $session);
  156. decode_cgi_utf8($q);
  157. # The session id is stored on the form and checked to
  158. # guard against CSRF.
  159. my $sid=$q->param('sid');
  160. if (! defined $sid) {
  161. $q->delete_all;
  162. }
  163. elsif ($sid ne $session->id) {
  164. error(gettext("Your login session has expired."));
  165. }
  166. eval q{use CGI::FormBuilder};
  167. error($@) if $@;
  168. my $form = CGI::FormBuilder->new(
  169. title => "preferences",
  170. name => "preferences",
  171. header => 0,
  172. charset => "utf-8",
  173. method => 'POST',
  174. validate => {
  175. email => 'EMAIL',
  176. },
  177. required => 'NONE',
  178. javascript => 0,
  179. params => $q,
  180. action => $config{cgiurl},
  181. template => {type => 'div'},
  182. stylesheet => baseurl()."style.css",
  183. fieldsets => [
  184. [login => gettext("Login")],
  185. [preferences => gettext("Preferences")],
  186. [admin => gettext("Admin")]
  187. ],
  188. );
  189. my $buttons=["Save Preferences", "Logout", "Cancel"];
  190. decode_form_utf8($form);
  191. run_hooks(formbuilder_setup => sub {
  192. shift->(form => $form, cgi => $q, session => $session,
  193. buttons => $buttons);
  194. });
  195. decode_form_utf8($form);
  196. $form->field(name => "do", type => "hidden", value => "prefs",
  197. force => 1);
  198. $form->field(name => "sid", type => "hidden", value => $session->id,
  199. force => 1);
  200. $form->field(name => "email", size => 50, fieldset => "preferences");
  201. my $user_name=$session->param("name");
  202. # XXX deprecated, should be removed eventually
  203. $form->field(name => "banned_users", size => 50, fieldset => "admin");
  204. if (! is_admin($user_name)) {
  205. $form->field(name => "banned_users", type => "hidden");
  206. }
  207. if (! $form->submitted) {
  208. $form->field(name => "email", force => 1,
  209. value => userinfo_get($user_name, "email"));
  210. if (is_admin($user_name)) {
  211. my $value=join(" ", get_banned_users());
  212. if (length $value) {
  213. $form->field(name => "banned_users", force => 1,
  214. value => join(" ", get_banned_users()),
  215. comment => "deprecated; please move to banned_users in setup file");
  216. }
  217. else {
  218. $form->field(name => "banned_users", type => "hidden");
  219. }
  220. }
  221. }
  222. if ($form->submitted eq 'Logout') {
  223. $session->delete();
  224. redirect($q, $config{url});
  225. return;
  226. }
  227. elsif ($form->submitted eq 'Cancel') {
  228. redirect($q, $config{url});
  229. return;
  230. }
  231. elsif ($form->submitted eq 'Save Preferences' && $form->validate) {
  232. if (defined $form->field('email')) {
  233. userinfo_set($user_name, 'email', $form->field('email')) ||
  234. error("failed to set email");
  235. }
  236. # XXX deprecated, should be removed eventually
  237. if (is_admin($user_name)) {
  238. set_banned_users(grep { ! is_admin($_) }
  239. split(' ',
  240. $form->field("banned_users"))) ||
  241. error("failed saving changes");
  242. if (! length $form->field("banned_users")) {
  243. $form->field(name => "banned_users", type => "hidden");
  244. }
  245. }
  246. $form->text(gettext("Preferences saved."));
  247. }
  248. showform($form, $buttons, $session, $q);
  249. } #}}}
  250. sub cgi_editpage ($$) { #{{{
  251. my $q=shift;
  252. my $session=shift;
  253. decode_cgi_utf8($q);
  254. my @fields=qw(do rcsinfo subpage from page type editcontent comments);
  255. my @buttons=("Save Page", "Preview", "Cancel");
  256. eval q{use CGI::FormBuilder};
  257. error($@) if $@;
  258. my $form = CGI::FormBuilder->new(
  259. fields => \@fields,
  260. charset => "utf-8",
  261. method => 'POST',
  262. required => [qw{editcontent}],
  263. javascript => 0,
  264. params => $q,
  265. action => $config{cgiurl},
  266. header => 0,
  267. table => 0,
  268. template => scalar template_params("editpage.tmpl"),
  269. wikiname => $config{wikiname},
  270. );
  271. decode_form_utf8($form);
  272. run_hooks(formbuilder_setup => sub {
  273. shift->(form => $form, cgi => $q, session => $session,
  274. buttons => \@buttons);
  275. });
  276. decode_form_utf8($form);
  277. # This untaint is safe because we check file_pruned.
  278. my $page=$form->field('page');
  279. $page=possibly_foolish_untaint($page);
  280. my $absolute=($page =~ s#^/+##);
  281. if (! defined $page || ! length $page ||
  282. file_pruned($page, $config{srcdir})) {
  283. error("bad page name");
  284. }
  285. my $baseurl=$config{url}."/".htmlpage($page);
  286. my $from;
  287. if (defined $form->field('from')) {
  288. ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
  289. }
  290. my $file;
  291. my $type;
  292. if (exists $pagesources{$page} && $form->field("do") ne "create") {
  293. $file=$pagesources{$page};
  294. $type=pagetype($file);
  295. if (! defined $type || $type=~/^_/) {
  296. error(sprintf(gettext("%s is not an editable page"), $page));
  297. }
  298. if (! $form->submitted) {
  299. $form->field(name => "rcsinfo",
  300. value => rcs_prepedit($file), force => 1);
  301. }
  302. $form->field(name => "editcontent", validate => '/.*/');
  303. }
  304. else {
  305. $type=$form->param('type');
  306. if (defined $type && length $type && $hooks{htmlize}{$type}) {
  307. $type=possibly_foolish_untaint($type);
  308. }
  309. elsif (defined $from && exists $pagesources{$from}) {
  310. # favor the type of linking page
  311. $type=pagetype($pagesources{$from});
  312. }
  313. $type=$config{default_pageext} unless defined $type;
  314. $file=$page.".".$type;
  315. if (! $form->submitted) {
  316. $form->field(name => "rcsinfo", value => "", force => 1);
  317. }
  318. $form->field(name => "editcontent", validate => '/.+/');
  319. }
  320. $form->field(name => "do", type => 'hidden');
  321. $form->field(name => "sid", type => "hidden", value => $session->id,
  322. force => 1);
  323. $form->field(name => "from", type => 'hidden');
  324. $form->field(name => "rcsinfo", type => 'hidden');
  325. $form->field(name => "subpage", type => 'hidden');
  326. $form->field(name => "page", value => $page, force => 1);
  327. $form->field(name => "type", value => $type, force => 1);
  328. $form->field(name => "comments", type => "text", size => 80);
  329. $form->field(name => "editcontent", type => "textarea", rows => 20,
  330. cols => 80);
  331. $form->tmpl_param("can_commit", $config{rcs});
  332. $form->tmpl_param("indexlink", indexlink());
  333. $form->tmpl_param("helponformattinglink",
  334. htmllink($page, $page, "ikiwiki/formatting",
  335. noimageinline => 1,
  336. linktext => "FormattingHelp"));
  337. if ($form->submitted eq "Cancel") {
  338. if ($form->field("do") eq "create" && defined $from) {
  339. redirect($q, "$config{url}/".htmlpage($from));
  340. }
  341. elsif ($form->field("do") eq "create") {
  342. redirect($q, $config{url});
  343. }
  344. else {
  345. redirect($q, "$config{url}/".htmlpage($page));
  346. }
  347. return;
  348. }
  349. elsif ($form->submitted eq "Preview") {
  350. my $new=not exists $pagesources{$page};
  351. if ($new) {
  352. # temporarily record its type
  353. $pagesources{$page}=$page.".".$type;
  354. }
  355. my $content=$form->field('editcontent');
  356. run_hooks(editcontent => sub {
  357. $content=shift->(
  358. content => $content,
  359. page => $page,
  360. cgi => $q,
  361. session => $session,
  362. );
  363. });
  364. my $preview=htmlize($page, $page, $type,
  365. linkify($page, $page,
  366. preprocess($page, $page,
  367. filter($page, $page, $content), 0, 1)));
  368. run_hooks(format => sub {
  369. $preview=shift->(
  370. page => $page,
  371. content => $preview,
  372. );
  373. });
  374. $form->tmpl_param("page_preview", $preview);
  375. if ($new) {
  376. delete $pagesources{$page};
  377. }
  378. # previewing may have created files on disk
  379. saveindex();
  380. }
  381. elsif ($form->submitted eq "Save Page") {
  382. $form->tmpl_param("page_preview", "");
  383. }
  384. if ($form->submitted ne "Save Page" || ! $form->validate) {
  385. if ($form->field("do") eq "create") {
  386. my @page_locs;
  387. my $best_loc;
  388. if (! defined $from || ! length $from ||
  389. $from ne $form->field('from') ||
  390. file_pruned($from, $config{srcdir}) ||
  391. $from=~/^\// ||
  392. $absolute ||
  393. $form->submitted eq "Preview") {
  394. @page_locs=$best_loc=$page;
  395. }
  396. else {
  397. my $dir=$from."/";
  398. $dir=~s![^/]+/+$!!;
  399. if ((defined $form->field('subpage') && length $form->field('subpage')) ||
  400. $page eq gettext('discussion')) {
  401. $best_loc="$from/$page";
  402. }
  403. else {
  404. $best_loc=$dir.$page;
  405. }
  406. push @page_locs, $dir.$page;
  407. push @page_locs, "$from/$page";
  408. while (length $dir) {
  409. $dir=~s![^/]+/+$!!;
  410. push @page_locs, $dir.$page;
  411. }
  412. push @page_locs, "$config{userdir}/$page"
  413. if length $config{userdir};
  414. }
  415. @page_locs = grep {
  416. ! exists $pagecase{lc $_}
  417. } @page_locs;
  418. if (! @page_locs) {
  419. # hmm, someone else made the page in the
  420. # meantime?
  421. if ($form->submitted eq "Preview") {
  422. # let them go ahead with the edit
  423. # and resolve the conflict at save
  424. # time
  425. @page_locs=$page;
  426. }
  427. else {
  428. redirect($q, "$config{url}/".htmlpage($page));
  429. return;
  430. }
  431. }
  432. my @editable_locs = grep {
  433. check_canedit($_, $q, $session, 1)
  434. } @page_locs;
  435. if (! @editable_locs) {
  436. # let it throw an error this time
  437. map { check_canedit($_, $q, $session) } @page_locs;
  438. }
  439. my @page_types;
  440. if (exists $hooks{htmlize}) {
  441. @page_types=grep { !/^_/ }
  442. keys %{$hooks{htmlize}};
  443. }
  444. $form->tmpl_param("page_select", 1);
  445. $form->field(name => "page", type => 'select',
  446. options => [ map { [ $_, pagetitle($_, 1) ] } @editable_locs ],
  447. value => $best_loc);
  448. $form->field(name => "type", type => 'select',
  449. options => \@page_types);
  450. $form->title(sprintf(gettext("creating %s"), pagetitle($page)));
  451. }
  452. elsif ($form->field("do") eq "edit") {
  453. check_canedit($page, $q, $session);
  454. if (! defined $form->field('editcontent') ||
  455. ! length $form->field('editcontent')) {
  456. my $content="";
  457. if (exists $pagesources{$page}) {
  458. $content=readfile(srcfile($pagesources{$page}));
  459. $content=~s/\n/\r\n/g;
  460. }
  461. $form->field(name => "editcontent", value => $content,
  462. force => 1);
  463. }
  464. $form->tmpl_param("page_select", 0);
  465. $form->field(name => "page", type => 'hidden');
  466. $form->field(name => "type", type => 'hidden');
  467. $form->title(sprintf(gettext("editing %s"), pagetitle($page)));
  468. }
  469. showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
  470. }
  471. else {
  472. # save page
  473. check_canedit($page, $q, $session);
  474. # The session id is stored on the form and checked to
  475. # guard against CSRF. But only if the user is logged in,
  476. # as anonok can allow anonymous edits.
  477. if (defined $session->param("name")) {
  478. my $sid=$q->param('sid');
  479. if (! defined $sid || $sid ne $session->id) {
  480. error(gettext("Your login session has expired."));
  481. }
  482. }
  483. my $exists=-e "$config{srcdir}/$file";
  484. if ($form->field("do") ne "create" && ! $exists &&
  485. ! defined srcfile($file, 1)) {
  486. $form->tmpl_param("message", template("editpagegone.tmpl")->output);
  487. $form->field(name => "do", value => "create", force => 1);
  488. $form->tmpl_param("page_select", 0);
  489. $form->field(name => "page", type => 'hidden');
  490. $form->field(name => "type", type => 'hidden');
  491. $form->title(sprintf(gettext("editing %s"), $page));
  492. showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
  493. return;
  494. }
  495. elsif ($form->field("do") eq "create" && $exists) {
  496. $form->tmpl_param("message", template("editcreationconflict.tmpl")->output);
  497. $form->field(name => "do", value => "edit", force => 1);
  498. $form->tmpl_param("page_select", 0);
  499. $form->field(name => "page", type => 'hidden');
  500. $form->field(name => "type", type => 'hidden');
  501. $form->title(sprintf(gettext("editing %s"), $page));
  502. $form->field("editcontent",
  503. value => readfile("$config{srcdir}/$file").
  504. "\n\n\n".$form->field("editcontent"),
  505. force => 1);
  506. showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
  507. return;
  508. }
  509. my $content=$form->field('editcontent');
  510. run_hooks(editcontent => sub {
  511. $content=shift->(
  512. content => $content,
  513. page => $page,
  514. cgi => $q,
  515. session => $session,
  516. );
  517. });
  518. $content=~s/\r\n/\n/g;
  519. $content=~s/\r/\n/g;
  520. $content.="\n" if $content !~ /\n$/;
  521. $config{cgi}=0; # avoid cgi error message
  522. eval { writefile($file, $config{srcdir}, $content) };
  523. $config{cgi}=1;
  524. if ($@) {
  525. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  526. force => 1);
  527. my $mtemplate=template("editfailedsave.tmpl");
  528. $mtemplate->param(error_message => $@);
  529. $form->tmpl_param("message", $mtemplate->output);
  530. $form->field("editcontent", value => $content, force => 1);
  531. $form->tmpl_param("page_select", 0);
  532. $form->field(name => "page", type => 'hidden');
  533. $form->field(name => "type", type => 'hidden');
  534. $form->title(sprintf(gettext("editing %s"), $page));
  535. showform($form, \@buttons, $session, $q,
  536. forcebaseurl => $baseurl);
  537. return;
  538. }
  539. my $conflict;
  540. if ($config{rcs}) {
  541. my $message="";
  542. if (defined $form->field('comments') &&
  543. length $form->field('comments')) {
  544. $message=$form->field('comments');
  545. }
  546. if (! $exists) {
  547. rcs_add($file);
  548. }
  549. # Prevent deadlock with post-commit hook by
  550. # signaling to it that it should not try to
  551. # do anything.
  552. disable_commit_hook();
  553. $conflict=rcs_commit($file, $message,
  554. $form->field("rcsinfo"),
  555. $session->param("name"), $ENV{REMOTE_ADDR});
  556. enable_commit_hook();
  557. rcs_update();
  558. }
  559. # Refresh even if there was a conflict, since other changes
  560. # may have been committed while the post-commit hook was
  561. # disabled.
  562. require IkiWiki::Render;
  563. refresh();
  564. saveindex();
  565. if (defined $conflict) {
  566. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  567. force => 1);
  568. $form->tmpl_param("message", template("editconflict.tmpl")->output);
  569. $form->field("editcontent", value => $conflict, force => 1);
  570. $form->field("do", "edit", force => 1);
  571. $form->tmpl_param("page_select", 0);
  572. $form->field(name => "page", type => 'hidden');
  573. $form->field(name => "type", type => 'hidden');
  574. $form->title(sprintf(gettext("editing %s"), $page));
  575. showform($form, \@buttons, $session, $q,
  576. forcebaseurl => $baseurl);
  577. return;
  578. }
  579. else {
  580. # The trailing question mark tries to avoid broken
  581. # caches and get the most recent version of the page.
  582. redirect($q, "$config{url}/".htmlpage($page)."?updated");
  583. }
  584. }
  585. } #}}}
  586. sub check_banned ($$) { #{{{
  587. my $q=shift;
  588. my $session=shift;
  589. my $name=$session->param("name");
  590. if (defined $name) {
  591. # XXX banned in userinfo is deprecated, should be removed
  592. # eventually, and only banned_users be checked.
  593. if (userinfo_get($session->param("name"), "banned") ||
  594. grep { $name eq $_ } @{$config{banned_users}}) {
  595. print $q->header(-status => "403 Forbidden");
  596. $session->delete();
  597. print gettext("You are banned.");
  598. cgi_savesession($session);
  599. exit;
  600. }
  601. }
  602. }
  603. sub cgi_getsession ($) { #{{{
  604. my $q=shift;
  605. eval q{use CGI::Session};
  606. error($@) if $@;
  607. CGI::Session->name("ikiwiki_session_".encode_utf8($config{wikiname}));
  608. my $oldmask=umask(077);
  609. my $session = eval {
  610. CGI::Session->new("driver:DB_File", $q,
  611. { FileName => "$config{wikistatedir}/sessions.db" })
  612. };
  613. if (! $session || $@) {
  614. error($@." ".CGI::Session->errstr());
  615. }
  616. umask($oldmask);
  617. return $session;
  618. } #}}}
  619. sub cgi_savesession ($) { #{{{
  620. my $session=shift;
  621. # Force session flush with safe umask.
  622. my $oldmask=umask(077);
  623. $session->flush;
  624. umask($oldmask);
  625. } #}}}
  626. sub cgi (;$$) { #{{{
  627. my $q=shift;
  628. my $session=shift;
  629. eval q{use CGI};
  630. error($@) if $@;
  631. $CGI::DISABLE_UPLOADS=$config{cgi_disable_uploads};
  632. if (! $q) {
  633. binmode(STDIN);
  634. $q=CGI->new;
  635. binmode(STDIN, ":utf8");
  636. run_hooks(cgi => sub { shift->($q) });
  637. }
  638. my $do=$q->param('do');
  639. if (! defined $do || ! length $do) {
  640. my $error = $q->cgi_error;
  641. if ($error) {
  642. error("Request not processed: $error");
  643. }
  644. else {
  645. error("\"do\" parameter missing");
  646. }
  647. }
  648. # Need to lock the wiki before getting a session.
  649. lockwiki();
  650. loadindex();
  651. if (! $session) {
  652. $session=cgi_getsession($q);
  653. }
  654. # Auth hooks can sign a user in.
  655. if ($do ne 'signin' && ! defined $session->param("name")) {
  656. run_hooks(auth => sub {
  657. shift->($q, $session)
  658. });
  659. if (defined $session->param("name")) {
  660. # Make sure whatever user was authed is in the
  661. # userinfo db.
  662. if (! userinfo_get($session->param("name"), "regdate")) {
  663. userinfo_setall($session->param("name"), {
  664. email => "",
  665. password => "",
  666. regdate => time,
  667. }) || error("failed adding user");
  668. }
  669. }
  670. }
  671. check_banned($q, $session);
  672. run_hooks(sessioncgi => sub { shift->($q, $session) });
  673. if ($do eq 'signin') {
  674. cgi_signin($q, $session);
  675. cgi_savesession($session);
  676. }
  677. elsif ($do eq 'prefs') {
  678. cgi_prefs($q, $session);
  679. }
  680. elsif ($do eq 'create' || $do eq 'edit') {
  681. cgi_editpage($q, $session);
  682. }
  683. elsif (defined $session->param("postsignin") || $do eq 'postsignin') {
  684. cgi_postsignin($q, $session);
  685. }
  686. else {
  687. error("unknown do parameter");
  688. }
  689. } #}}}
  690. # Does not need to be called directly; all errors will go through here.
  691. sub cgierror ($) { #{{{
  692. my $message=shift;
  693. print "Content-type: text/html\n\n";
  694. print misctemplate(gettext("Error"),
  695. "<p class=\"error\">".gettext("Error").": $message</p>");
  696. die $@;
  697. } #}}}
  698. 1