summaryrefslogtreecommitdiff
path: root/IkiWiki/CGI.pm
blob: 3ba6cf7f84aebbb314716aa0361f9639faa0c90f (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use IkiWiki;
  5. use IkiWiki::UserInfo;
  6. use open qw{:utf8 :std};
  7. use Encode;
  8. package IkiWiki;
  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 redirect ($$) { #{{{
  19. my $q=shift;
  20. my $url=shift;
  21. if (! $config{w3mmode}) {
  22. print $q->redirect($url);
  23. }
  24. else {
  25. print "Content-type: text/plain\n";
  26. print "W3m-control: GOTO $url\n\n";
  27. }
  28. } #}}}
  29. sub page_locked ($$;$) { #{{{
  30. my $page=shift;
  31. my $session=shift;
  32. my $nonfatal=shift;
  33. my $user=$session->param("name");
  34. return if defined $user && is_admin($user);
  35. foreach my $admin (@{$config{adminuser}}) {
  36. my $locked_pages=userinfo_get($admin, "locked_pages");
  37. if (pagespec_match($page, userinfo_get($admin, "locked_pages"))) {
  38. return 1 if $nonfatal;
  39. error(htmllink("", "", $page, 1)." is locked by ".
  40. htmllink("", "", $admin, 1)." and cannot be edited.");
  41. }
  42. }
  43. return 0;
  44. } #}}}
  45. sub decode_form_utf8 ($) { #{{{
  46. my $form = shift;
  47. foreach my $f ($form->field) {
  48. next if Encode::is_utf8(scalar $form->field($f));
  49. $form->field(name => $f,
  50. value => decode_utf8($form->field($f)),
  51. force => 1,
  52. );
  53. }
  54. } #}}}
  55. sub cgi_recentchanges ($) { #{{{
  56. my $q=shift;
  57. unlockwiki();
  58. # Optimisation: building recentchanges means calculating lots of
  59. # links. Memoizing htmllink speeds it up a lot (can't be memoized
  60. # during page builds as the return values may change, but they
  61. # won't here.)
  62. eval q{use Memoize};
  63. memoize("htmllink");
  64. eval q{use Time::Duration};
  65. eval q{use CGI 'escapeHTML'};
  66. my $changelog=[rcs_recentchanges(100)];
  67. foreach my $change (@$changelog) {
  68. $change->{when} = concise(ago($change->{when}));
  69. $change->{user} = htmllink("", "", escapeHTML($change->{user}), 1);
  70. my $is_excess = exists $change->{pages}[10]; # limit pages to first 10
  71. delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
  72. $change->{pages} = [
  73. map {
  74. $_->{link} = htmllink("", "", $_->{page}, 1);
  75. $_;
  76. } @{$change->{pages}}
  77. ];
  78. push @{$change->{pages}}, { link => '...' } if $is_excess;
  79. }
  80. my $template=template("recentchanges.tmpl");
  81. $template->param(
  82. title => "RecentChanges",
  83. indexlink => indexlink(),
  84. wikiname => $config{wikiname},
  85. changelog => $changelog,
  86. baseurl => baseurl(),
  87. );
  88. run_hooks(pagetemplate => sub {
  89. shift->(page => "", destpage => "", template => $template);
  90. });
  91. print $q->header(-charset => 'utf-8'), $template->output;
  92. } #}}}
  93. sub cgi_signin ($$) { #{{{
  94. my $q=shift;
  95. my $session=shift;
  96. eval q{use CGI::FormBuilder};
  97. my $form = CGI::FormBuilder->new(
  98. title => "signin",
  99. fields => [qw(do title page subpage from name password)],
  100. header => 1,
  101. charset => "utf-8",
  102. method => 'POST',
  103. validate => {
  104. confirm_password => {
  105. perl => q{eq $form->field("password")},
  106. },
  107. email => 'EMAIL',
  108. },
  109. required => 'NONE',
  110. javascript => 0,
  111. params => $q,
  112. action => $config{cgiurl},
  113. header => 0,
  114. template => (-e "$config{templatedir}/signin.tmpl" ?
  115. {template_params("signin.tmpl")} : ""),
  116. stylesheet => baseurl()."style.css",
  117. );
  118. decode_form_utf8($form);
  119. $form->field(name => "name", required => 0);
  120. $form->field(name => "do", type => "hidden");
  121. $form->field(name => "page", type => "hidden");
  122. $form->field(name => "title", type => "hidden");
  123. $form->field(name => "from", type => "hidden");
  124. $form->field(name => "subpage", type => "hidden");
  125. $form->field(name => "password", type => "password", required => 0);
  126. if ($form->submitted eq "Register" || $form->submitted eq "Create Account") {
  127. $form->title("register");
  128. $form->text("");
  129. $form->field(name => "name", comment => "use FirstnameLastName");
  130. $form->fields(qw(do title page subpage from name password confirm_password email));
  131. $form->field(name => "confirm_password", type => "password");
  132. $form->field(name => "email", type => "text");
  133. }
  134. if ($q->param("do") ne "signin" && !$form->submitted) {
  135. $form->text("You need to log in first.");
  136. }
  137. if ($form->submitted) {
  138. # Set required fields based on how form was submitted.
  139. my %required=(
  140. "Login" => [qw(name password)],
  141. "Register" => [],
  142. "Create Account" => [qw(name password confirm_password email)],
  143. "Mail Password" => [qw(name)],
  144. );
  145. foreach my $opt (@{$required{$form->submitted}}) {
  146. $form->field(name => $opt, required => 1);
  147. }
  148. # Validate password differently depending on how
  149. # form was submitted.
  150. if ($form->submitted eq 'Login') {
  151. $form->field(
  152. name => "password",
  153. validate => sub {
  154. length $form->field("name") &&
  155. shift eq userinfo_get($form->field("name"), 'password');
  156. },
  157. );
  158. $form->field(name => "name", validate => '/^\w+$/');
  159. }
  160. else {
  161. $form->field(name => "password", validate => 'VALUE');
  162. }
  163. # And make sure the entered name exists when logging
  164. # in or sending email, and does not when registering.
  165. if ($form->submitted eq 'Create Account') {
  166. $form->field(
  167. name => "name",
  168. validate => sub {
  169. my $name=shift;
  170. length $name &&
  171. $name=~/$config{wiki_file_regexp}/ &&
  172. ! userinfo_get($name, "regdate");
  173. },
  174. );
  175. }
  176. else {
  177. $form->field(
  178. name => "name",
  179. validate => sub {
  180. my $name=shift;
  181. length $name &&
  182. userinfo_get($name, "regdate");
  183. },
  184. );
  185. }
  186. }
  187. else {
  188. # First time settings.
  189. $form->field(name => "name", comment => "use FirstnameLastName");
  190. if ($session->param("name")) {
  191. $form->field(name => "name", value => $session->param("name"));
  192. }
  193. }
  194. if ($form->submitted && $form->validate) {
  195. if ($form->submitted eq 'Login') {
  196. $session->param("name", $form->field("name"));
  197. if (defined $form->field("do") &&
  198. $form->field("do") ne 'signin') {
  199. redirect($q, cgiurl(
  200. do => $form->field("do"),
  201. page => $form->field("page"),
  202. title => $form->field("title"),
  203. subpage => $form->field("subpage"),
  204. from => $form->field("from"),
  205. ));
  206. }
  207. else {
  208. redirect($q, $config{url});
  209. }
  210. }
  211. elsif ($form->submitted eq 'Create Account') {
  212. my $user_name=$form->field('name');
  213. if (userinfo_setall($user_name, {
  214. 'email' => $form->field('email'),
  215. 'password' => $form->field('password'),
  216. 'regdate' => time
  217. })) {
  218. $form->field(name => "confirm_password", type => "hidden");
  219. $form->field(name => "email", type => "hidden");
  220. $form->text("Account creation successful. Now you can Login.");
  221. printheader($session);
  222. print misctemplate($form->title, $form->render(submit => ["Login"]));
  223. }
  224. else {
  225. error("Error creating account.");
  226. }
  227. }
  228. elsif ($form->submitted eq 'Mail Password') {
  229. my $user_name=$form->field("name");
  230. my $template=template("passwordmail.tmpl");
  231. $template->param(
  232. user_name => $user_name,
  233. user_password => userinfo_get($user_name, "password"),
  234. wikiurl => $config{url},
  235. wikiname => $config{wikiname},
  236. REMOTE_ADDR => $ENV{REMOTE_ADDR},
  237. );
  238. eval q{use Mail::Sendmail};
  239. sendmail(
  240. To => userinfo_get($user_name, "email"),
  241. From => "$config{wikiname} admin <$config{adminemail}>",
  242. Subject => "$config{wikiname} information",
  243. Message => $template->output,
  244. ) or error("Failed to send mail");
  245. $form->text("Your password has been emailed to you.");
  246. $form->field(name => "name", required => 0);
  247. printheader($session);
  248. print misctemplate($form->title, $form->render(submit => ["Login", "Mail Password"]));
  249. }
  250. elsif ($form->submitted eq "Register") {
  251. printheader($session);
  252. print misctemplate($form->title, $form->render(submit => ["Create Account"]));
  253. }
  254. }
  255. elsif ($form->submitted eq "Create Account") {
  256. printheader($session);
  257. print misctemplate($form->title, $form->render(submit => ["Create Account"]));
  258. }
  259. else {
  260. printheader($session);
  261. print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
  262. }
  263. } #}}}
  264. sub cgi_prefs ($$) { #{{{
  265. my $q=shift;
  266. my $session=shift;
  267. eval q{use CGI::FormBuilder};
  268. my $form = CGI::FormBuilder->new(
  269. title => "preferences",
  270. fields => [qw(do name password confirm_password email
  271. subscriptions locked_pages)],
  272. header => 0,
  273. charset => "utf-8",
  274. method => 'POST',
  275. validate => {
  276. confirm_password => {
  277. perl => q{eq $form->field("password")},
  278. },
  279. email => 'EMAIL',
  280. },
  281. required => 'NONE',
  282. javascript => 0,
  283. params => $q,
  284. action => $config{cgiurl},
  285. template => (-e "$config{templatedir}/prefs.tmpl" ?
  286. {template_params("prefs.tmpl")} : ""),
  287. stylesheet => baseurl()."style.css",
  288. );
  289. my @buttons=("Save Preferences", "Logout", "Cancel");
  290. my $user_name=$session->param("name");
  291. $form->field(name => "do", type => "hidden");
  292. $form->field(name => "name", disabled => 1,
  293. value => $user_name, force => 1);
  294. $form->field(name => "password", type => "password");
  295. $form->field(name => "confirm_password", type => "password");
  296. $form->field(name => "subscriptions", size => 50,
  297. comment => "(".htmllink("", "", "PageSpec", 1).")");
  298. $form->field(name => "locked_pages", size => 50,
  299. comment => "(".htmllink("", "", "PageSpec", 1).")");
  300. $form->field(name => "banned_users", size => 50);
  301. if (! is_admin($user_name)) {
  302. $form->field(name => "locked_pages", type => "hidden");
  303. $form->field(name => "banned_users", type => "hidden");
  304. }
  305. if ($config{httpauth}) {
  306. $form->field(name => "password", type => "hidden");
  307. $form->field(name => "confirm_password", type => "hidden");
  308. }
  309. if (! $form->submitted) {
  310. $form->field(name => "email", force => 1,
  311. value => userinfo_get($user_name, "email"));
  312. $form->field(name => "subscriptions", force => 1,
  313. value => userinfo_get($user_name, "subscriptions"));
  314. $form->field(name => "locked_pages", force => 1,
  315. value => userinfo_get($user_name, "locked_pages"));
  316. if (is_admin($user_name)) {
  317. $form->field(name => "banned_users", force => 1,
  318. value => join(" ", get_banned_users()));
  319. }
  320. }
  321. decode_form_utf8($form);
  322. if ($form->submitted eq 'Logout') {
  323. $session->delete();
  324. redirect($q, $config{url});
  325. return;
  326. }
  327. elsif ($form->submitted eq 'Cancel') {
  328. redirect($q, $config{url});
  329. return;
  330. }
  331. elsif ($form->submitted eq "Save Preferences" && $form->validate) {
  332. foreach my $field (qw(password email subscriptions locked_pages)) {
  333. if (length $form->field($field)) {
  334. userinfo_set($user_name, $field, $form->field($field)) || error("failed to set $field");
  335. }
  336. }
  337. if (is_admin($user_name)) {
  338. set_banned_users(grep { ! is_admin($_) }
  339. split(' ', $form->field("banned_users")));
  340. }
  341. $form->text("Preferences saved.");
  342. }
  343. printheader($session);
  344. print misctemplate($form->title, $form->render(submit => \@buttons));
  345. } #}}}
  346. sub cgi_editpage ($$) { #{{{
  347. my $q=shift;
  348. my $session=shift;
  349. my @fields=qw(do rcsinfo subpage from page type editcontent comments);
  350. my @buttons=("Save Page", "Preview", "Cancel");
  351. eval q{use CGI::FormBuilder; use CGI::FormBuilder::Template::HTML};
  352. my $renderer=CGI::FormBuilder::Template::HTML->new(
  353. fields => \@fields,
  354. template_params("editpage.tmpl"),
  355. );
  356. run_hooks(pagetemplate => sub {
  357. shift->(page => "", destpage => "", template => $renderer->engine);
  358. });
  359. my $form = CGI::FormBuilder->new(
  360. fields => \@fields,
  361. header => 1,
  362. charset => "utf-8",
  363. method => 'POST',
  364. validate => {
  365. editcontent => '/.+/',
  366. },
  367. required => [qw{editcontent}],
  368. javascript => 0,
  369. params => $q,
  370. action => $config{cgiurl},
  371. table => 0,
  372. template => $renderer,
  373. );
  374. decode_form_utf8($form);
  375. # This untaint is safe because titlepage removes any problematic
  376. # characters.
  377. my ($page)=$form->field('page');
  378. $page=titlepage(possibly_foolish_untaint($page));
  379. if (! defined $page || ! length $page ||
  380. $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
  381. error("bad page name");
  382. }
  383. my $from;
  384. if (defined $form->field('from')) {
  385. ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
  386. }
  387. my $file;
  388. my $type;
  389. if (exists $pagesources{$page}) {
  390. $file=$pagesources{$page};
  391. $type=pagetype($file);
  392. }
  393. else {
  394. $type=$form->param('type');
  395. if (defined $type && length $type && $hooks{htmlize}{$type}) {
  396. $type=possibly_foolish_untaint($type);
  397. }
  398. elsif (defined $from) {
  399. # favor the type of linking page
  400. $type=pagetype($pagesources{$from});
  401. }
  402. $type=$config{default_pageext} unless defined $type;
  403. $file=$page.".".$type;
  404. }
  405. my $newfile=0;
  406. if (! -e "$config{srcdir}/$file") {
  407. $newfile=1;
  408. }
  409. $form->field(name => "do", type => 'hidden');
  410. $form->field(name => "from", type => 'hidden');
  411. $form->field(name => "rcsinfo", type => 'hidden');
  412. $form->field(name => "subpage", type => 'hidden');
  413. $form->field(name => "page", value => $page, force => 1);
  414. $form->field(name => "type", value => $type, force => 1);
  415. $form->field(name => "comments", type => "text", size => 80);
  416. $form->field(name => "editcontent", type => "textarea", rows => 20,
  417. cols => 80);
  418. $form->tmpl_param("can_commit", $config{rcs});
  419. $form->tmpl_param("indexlink", indexlink());
  420. $form->tmpl_param("helponformattinglink",
  421. htmllink("", "", "HelpOnFormatting", 1));
  422. $form->tmpl_param("baseurl", baseurl());
  423. if (! $form->submitted) {
  424. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  425. force => 1);
  426. }
  427. if ($form->submitted eq "Cancel") {
  428. if ($newfile && defined $from) {
  429. redirect($q, "$config{url}/".htmlpage($from));
  430. }
  431. elsif ($newfile) {
  432. redirect($q, $config{url});
  433. }
  434. else {
  435. redirect($q, "$config{url}/".htmlpage($page));
  436. }
  437. return;
  438. }
  439. elsif ($form->submitted eq "Preview") {
  440. my $content=$form->field('editcontent');
  441. my $comments=$form->field('comments');
  442. $form->field(name => "editcontent",
  443. value => $content, force => 1);
  444. $form->field(name => "comments",
  445. value => $comments, force => 1);
  446. $config{rss}=$config{atom}=0; # avoid preview writing a feed!
  447. $form->tmpl_param("page_preview",
  448. htmlize($page, $type,
  449. linkify($page, "",
  450. preprocess($page, $page,
  451. filter($page, $content)))));
  452. }
  453. else {
  454. $form->tmpl_param("page_preview", "");
  455. }
  456. $form->tmpl_param("page_conflict", "");
  457. if (! $form->submitted || $form->submitted eq "Preview" ||
  458. ! $form->validate) {
  459. if ($form->field("do") eq "create") {
  460. my @page_locs;
  461. my $best_loc;
  462. if (! defined $from || ! length $from ||
  463. $from ne $form->field('from') ||
  464. $from=~/$config{wiki_file_prune_regexp}/ ||
  465. $from=~/^\// ||
  466. $form->submitted eq "Preview") {
  467. @page_locs=$best_loc=$page;
  468. }
  469. else {
  470. my $dir=$from."/";
  471. $dir=~s![^/]+/+$!!;
  472. if ((defined $form->field('subpage') && length $form->field('subpage')) ||
  473. $page eq 'discussion') {
  474. $best_loc="$from/$page";
  475. }
  476. else {
  477. $best_loc=$dir.$page;
  478. }
  479. push @page_locs, $dir.$page;
  480. push @page_locs, "$from/$page";
  481. while (length $dir) {
  482. $dir=~s![^/]+/+$!!;
  483. push @page_locs, $dir.$page;
  484. }
  485. }
  486. @page_locs = grep {
  487. ! exists $pagecase{lc $_} &&
  488. ! page_locked($_, $session, 1)
  489. } @page_locs;
  490. if (! @page_locs) {
  491. # hmm, someone else made the page in the
  492. # meantime?
  493. redirect($q, "$config{url}/".htmlpage($page));
  494. return;
  495. }
  496. my @page_types;
  497. if (exists $hooks{htmlize}) {
  498. @page_types=keys %{$hooks{htmlize}};
  499. }
  500. $form->tmpl_param("page_select", 1);
  501. $form->field(name => "page", type => 'select',
  502. options => \@page_locs, value => $best_loc);
  503. $form->field(name => "type", type => 'select',
  504. options => \@page_types);
  505. $form->title("creating ".pagetitle($page));
  506. }
  507. elsif ($form->field("do") eq "edit") {
  508. page_locked($page, $session);
  509. if (! defined $form->field('editcontent') ||
  510. ! length $form->field('editcontent')) {
  511. my $content="";
  512. if (exists $pagesources{$page}) {
  513. $content=readfile(srcfile($pagesources{$page}));
  514. $content=~s/\n/\r\n/g;
  515. }
  516. $form->field(name => "editcontent", value => $content,
  517. force => 1);
  518. }
  519. $form->tmpl_param("page_select", 0);
  520. $form->field(name => "page", type => 'hidden');
  521. $form->field(name => "type", type => 'hidden');
  522. $form->title("editing ".pagetitle($page));
  523. }
  524. print $form->render(submit => \@buttons);
  525. }
  526. else {
  527. # save page
  528. page_locked($page, $session);
  529. my $content=$form->field('editcontent');
  530. $content=~s/\r\n/\n/g;
  531. $content=~s/\r/\n/g;
  532. writefile($file, $config{srcdir}, $content);
  533. my $message="web commit ";
  534. if (defined $session->param("name") &&
  535. length $session->param("name")) {
  536. $message.="by ".$session->param("name");
  537. }
  538. else {
  539. $message.="from $ENV{REMOTE_ADDR}";
  540. }
  541. if (defined $form->field('comments') &&
  542. length $form->field('comments')) {
  543. $message.=": ".$form->field('comments');
  544. }
  545. if ($config{rcs}) {
  546. if ($newfile) {
  547. rcs_add($file);
  548. }
  549. # prevent deadlock with post-commit hook
  550. unlockwiki();
  551. # presumably the commit will trigger an update
  552. # of the wiki
  553. my $conflict=rcs_commit($file, $message,
  554. $form->field("rcsinfo"));
  555. if (defined $conflict) {
  556. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  557. force => 1);
  558. $form->tmpl_param("page_conflict", 1);
  559. $form->field("editcontent", value => $conflict, force => 1);
  560. $form->field(name => "comments", value => $form->field('comments'), force => 1);
  561. $form->field("do", "edit)");
  562. $form->tmpl_param("page_select", 0);
  563. $form->field(name => "page", type => 'hidden');
  564. $form->field(name => "type", type => 'hidden');
  565. $form->title("editing $page");
  566. print $form->render(submit => \@buttons);
  567. return;
  568. }
  569. }
  570. else {
  571. require IkiWiki::Render;
  572. refresh();
  573. saveindex();
  574. }
  575. # The trailing question mark tries to avoid broken
  576. # caches and get the most recent version of the page.
  577. redirect($q, "$config{url}/".htmlpage($page)."?updated");
  578. }
  579. } #}}}
  580. sub cgi () { #{{{
  581. eval q{use CGI};
  582. eval q{use CGI::Session};
  583. my $q=CGI->new;
  584. run_hooks(cgi => sub { shift->($q) });
  585. my $do=$q->param('do');
  586. if (! defined $do || ! length $do) {
  587. my $error = $q->cgi_error;
  588. if ($error) {
  589. error("Request not processed: $error");
  590. }
  591. else {
  592. error("\"do\" parameter missing");
  593. }
  594. }
  595. # Things that do not need a session.
  596. if ($do eq 'recentchanges') {
  597. cgi_recentchanges($q);
  598. return;
  599. }
  600. elsif ($do eq 'hyperestraier') {
  601. cgi_hyperestraier();
  602. }
  603. CGI::Session->name("ikiwiki_session_".encode_utf8($config{wikiname}));
  604. my $oldmask=umask(077);
  605. my $session = CGI::Session->new("driver:DB_File", $q,
  606. { FileName => "$config{wikistatedir}/sessions.db" });
  607. umask($oldmask);
  608. # Everything below this point needs the user to be signed in.
  609. if (((! $config{anonok} || $do eq 'prefs') &&
  610. (! $config{httpauth}) &&
  611. (! defined $session->param("name") ||
  612. ! userinfo_get($session->param("name"), "regdate"))) || $do eq 'signin') {
  613. cgi_signin($q, $session);
  614. # Force session flush with safe umask.
  615. my $oldmask=umask(077);
  616. $session->flush;
  617. umask($oldmask);
  618. return;
  619. }
  620. if ($config{httpauth} && (! defined $session->param("name"))) {
  621. if (! defined $q->remote_user()) {
  622. error("Could not determine authenticated username.");
  623. }
  624. else {
  625. $session->param("name", $q->remote_user());
  626. if (! userinfo_get($session->param("name"), "regdate")) {
  627. userinfo_setall($session->param("name"), {
  628. email => "",
  629. password => "",
  630. regdate=>time,
  631. });
  632. }
  633. }
  634. }
  635. if (userinfo_get($session->param("name"), "banned")) {
  636. print $q->header(-status => "403 Forbidden");
  637. $session->delete();
  638. print "You are banned.";
  639. exit;
  640. }
  641. if ($do eq 'create' || $do eq 'edit') {
  642. cgi_editpage($q, $session);
  643. }
  644. elsif ($do eq 'prefs') {
  645. cgi_prefs($q, $session);
  646. }
  647. elsif ($do eq 'blog') {
  648. my $page=titlepage(decode_utf8($q->param('title')));
  649. # if the page already exists, munge it to be unique
  650. my $from=$q->param('from');
  651. my $add="";
  652. while (exists $pagecase{lc "$from/$page$add"}) {
  653. $add=1 unless length $add;
  654. $add++;
  655. }
  656. $q->param('page', $page.$add);
  657. # now run same as create
  658. $q->param('do', 'create');
  659. cgi_editpage($q, $session);
  660. }
  661. else {
  662. error("unknown do parameter");
  663. }
  664. } #}}}
  665. 1