summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/inline.pm
blob: e7d6f250e5cfee1d563bfb40bdf8d541cb7aad1e (plain)
  1. #!/usr/bin/perl
  2. # Page inlining and blogging.
  3. package IkiWiki::Plugin::inline;
  4. use warnings;
  5. use strict;
  6. use Encode;
  7. use IkiWiki 3.00;
  8. use URI;
  9. my %knownfeeds;
  10. my %page_numfeeds;
  11. my @inline;
  12. my $nested=0;
  13. sub import {
  14. hook(type => "getopt", id => "inline", call => \&getopt);
  15. hook(type => "getsetup", id => "inline", call => \&getsetup);
  16. hook(type => "checkconfig", id => "inline", call => \&checkconfig);
  17. hook(type => "sessioncgi", id => "inline", call => \&sessioncgi);
  18. hook(type => "preprocess", id => "inline",
  19. call => \&IkiWiki::preprocess_inline);
  20. hook(type => "pagetemplate", id => "inline",
  21. call => \&IkiWiki::pagetemplate_inline);
  22. hook(type => "format", id => "inline", call => \&format, first => 1);
  23. # Hook to change to do pinging since it's called late.
  24. # This ensures each page only pings once and prevents slow
  25. # pings interrupting page builds.
  26. hook(type => "change", id => "inline", call => \&IkiWiki::pingurl);
  27. }
  28. sub getopt () {
  29. eval q{use Getopt::Long};
  30. error($@) if $@;
  31. Getopt::Long::Configure('pass_through');
  32. GetOptions(
  33. "rss!" => \$config{rss},
  34. "atom!" => \$config{atom},
  35. "allowrss!" => \$config{allowrss},
  36. "allowatom!" => \$config{allowatom},
  37. "pingurl=s" => sub {
  38. push @{$config{pingurl}}, $_[1];
  39. },
  40. );
  41. }
  42. sub getsetup () {
  43. return
  44. plugin => {
  45. safe => 1,
  46. rebuild => undef,
  47. },
  48. rss => {
  49. type => "boolean",
  50. example => 0,
  51. description => "enable rss feeds by default?",
  52. safe => 1,
  53. rebuild => 1,
  54. },
  55. atom => {
  56. type => "boolean",
  57. example => 0,
  58. description => "enable atom feeds by default?",
  59. safe => 1,
  60. rebuild => 1,
  61. },
  62. allowrss => {
  63. type => "boolean",
  64. example => 0,
  65. description => "allow rss feeds to be used?",
  66. safe => 1,
  67. rebuild => 1,
  68. },
  69. allowatom => {
  70. type => "boolean",
  71. example => 0,
  72. description => "allow atom feeds to be used?",
  73. safe => 1,
  74. rebuild => 1,
  75. },
  76. pingurl => {
  77. type => "string",
  78. example => "http://rpc.technorati.com/rpc/ping",
  79. description => "urls to ping (using XML-RPC) on feed update",
  80. safe => 1,
  81. rebuild => 0,
  82. },
  83. }
  84. sub checkconfig () {
  85. if (($config{rss} || $config{atom}) && ! length $config{url}) {
  86. error(gettext("Must specify url to wiki with --url when using --rss or --atom"));
  87. }
  88. if ($config{rss}) {
  89. push @{$config{wiki_file_prune_regexps}}, qr/\.rss$/;
  90. }
  91. if ($config{atom}) {
  92. push @{$config{wiki_file_prune_regexps}}, qr/\.atom$/;
  93. }
  94. if (! exists $config{pingurl}) {
  95. $config{pingurl}=[];
  96. }
  97. }
  98. sub format (@) {
  99. my %params=@_;
  100. # Fill in the inline content generated earlier. This is actually an
  101. # optimisation.
  102. $params{content}=~s{<div class="inline" id="([^"]+)"></div>}{
  103. delete @inline[$1,]
  104. }eg;
  105. return $params{content};
  106. }
  107. sub sessioncgi ($$) {
  108. my $q=shift;
  109. my $session=shift;
  110. if ($q->param('do') eq 'blog') {
  111. my $page=titlepage(decode_utf8($q->param('title')));
  112. $page=~s/(\/)/"__".ord($1)."__"/eg; # don't create subdirs
  113. # if the page already exists, munge it to be unique
  114. my $from=$q->param('from');
  115. my $add="";
  116. while (exists $IkiWiki::pagecase{lc($from."/".$page.$add)}) {
  117. $add=1 unless length $add;
  118. $add++;
  119. }
  120. $q->param('page', $page.$add);
  121. # now go create the page
  122. $q->param('do', 'create');
  123. # make sure the editpage plugin in loaded
  124. if (IkiWiki->can("cgi_editpage")) {
  125. IkiWiki::cgi_editpage($q, $session);
  126. }
  127. else {
  128. error(gettext("page editing not allowed"));
  129. }
  130. exit;
  131. }
  132. }
  133. # Back to ikiwiki namespace for the rest, this code is very much
  134. # internal to ikiwiki even though it's separated into a plugin.
  135. package IkiWiki;
  136. my %toping;
  137. my %feedlinks;
  138. sub preprocess_inline (@) {
  139. my %params=@_;
  140. if (! exists $params{pages} && ! exists $params{pagenames}) {
  141. error gettext("missing pages parameter");
  142. }
  143. my $raw=yesno($params{raw});
  144. my $archive=yesno($params{archive});
  145. my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
  146. my $atom=(($config{atom} || $config{allowatom}) && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
  147. my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
  148. my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick;
  149. my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1;
  150. my $feedonly=yesno($params{feedonly});
  151. if (! exists $params{show} && ! $archive) {
  152. $params{show}=10;
  153. }
  154. if (! exists $params{feedshow} && exists $params{show}) {
  155. $params{feedshow}=$params{show};
  156. }
  157. my $desc;
  158. if (exists $params{description}) {
  159. $desc = $params{description}
  160. }
  161. else {
  162. $desc = $config{wikiname};
  163. }
  164. my $actions=yesno($params{actions});
  165. if (exists $params{template}) {
  166. $params{template}=~s/[^-_a-zA-Z0-9]+//g;
  167. }
  168. else {
  169. $params{template} = $archive ? "archivepage" : "inlinepage";
  170. }
  171. my @list;
  172. if (exists $params{pagenames}) {
  173. foreach my $p (qw(sort pages)) {
  174. if (exists $params{$p}) {
  175. error sprintf(gettext("the %s and %s parameters cannot be used together"),
  176. "pagenames", $p);
  177. }
  178. }
  179. @list = split ' ', $params{pagenames};
  180. my $_;
  181. @list = map { bestlink($params{page}, $_) } @list;
  182. $params{pages} = join(" or ", @list);
  183. }
  184. else {
  185. @list = pagespec_match_list(
  186. [ grep { $_ ne $params{page} } keys %pagesources ],
  187. $params{pages}, location => $params{page});
  188. if (exists $params{sort} && $params{sort} eq 'title') {
  189. @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
  190. }
  191. elsif (exists $params{sort} && $params{sort} eq 'title_natural') {
  192. eval q{use Sort::Naturally};
  193. if ($@) {
  194. error(gettext("Sort::Naturally needed for title_natural sort"));
  195. }
  196. @list=sort { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) } @list;
  197. }
  198. elsif (exists $params{sort} && $params{sort} eq 'mtime') {
  199. @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
  200. }
  201. elsif (! exists $params{sort} || $params{sort} eq 'age') {
  202. @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
  203. }
  204. else {
  205. error sprintf(gettext("unknown sort type %s"), $params{sort});
  206. }
  207. }
  208. if (yesno($params{reverse})) {
  209. @list=reverse(@list);
  210. }
  211. if (exists $params{skip}) {
  212. @list=@list[$params{skip} .. scalar @list - 1];
  213. }
  214. my @feedlist;
  215. if ($feeds) {
  216. if (exists $params{feedshow} &&
  217. $params{feedshow} && @list > $params{feedshow}) {
  218. @feedlist=@list[0..$params{feedshow} - 1];
  219. }
  220. else {
  221. @feedlist=@list;
  222. }
  223. }
  224. if ($params{show} && @list > $params{show}) {
  225. @list=@list[0..$params{show} - 1];
  226. }
  227. add_depends($params{page}, $params{pages});
  228. # Explicitly add all currently displayed pages as dependencies, so
  229. # that if they are removed or otherwise changed, the inline will be
  230. # sure to be updated.
  231. add_depends($params{page}, join(" or ", $#list >= $#feedlist ? @list : @feedlist));
  232. if ($feeds && exists $params{feedpages}) {
  233. @feedlist=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @feedlist;
  234. }
  235. my ($feedbase, $feednum);
  236. if ($feeds) {
  237. # Ensure that multiple feeds on a page go to unique files.
  238. # Feedfile can lead to conflicts if usedirs is not enabled,
  239. # so avoid supporting it in that case.
  240. delete $params{feedfile} if ! $config{usedirs};
  241. # Tight limits on legal feedfiles, to avoid security issues
  242. # and conflicts.
  243. if (defined $params{feedfile}) {
  244. if ($params{feedfile} =~ /\// ||
  245. $params{feedfile} !~ /$config{wiki_file_regexp}/) {
  246. error("illegal feedfile");
  247. }
  248. $params{feedfile}=possibly_foolish_untaint($params{feedfile});
  249. }
  250. $feedbase=targetpage($params{destpage}, "", $params{feedfile});
  251. my $feedid=join("\0", $feedbase, map { $_."\0".$params{$_} } sort keys %params);
  252. if (exists $knownfeeds{$feedid}) {
  253. $feednum=$knownfeeds{$feedid};
  254. }
  255. else {
  256. if (exists $page_numfeeds{$params{destpage}}{$feedbase}) {
  257. if ($feeds) {
  258. $feednum=$knownfeeds{$feedid}=++$page_numfeeds{$params{destpage}}{$feedbase};
  259. }
  260. }
  261. else {
  262. $feednum=$knownfeeds{$feedid}="";
  263. if ($feeds) {
  264. $page_numfeeds{$params{destpage}}{$feedbase}=1;
  265. }
  266. }
  267. }
  268. }
  269. my $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $rss;
  270. my $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $atom;
  271. my $ret="";
  272. if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
  273. (exists $params{postform} && yesno($params{postform}))) &&
  274. IkiWiki->can("cgi_editpage")) {
  275. # Add a blog post form, with feed buttons.
  276. my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
  277. $formtemplate->param(cgiurl => $config{cgiurl});
  278. my $rootpage;
  279. if (exists $params{rootpage}) {
  280. $rootpage=bestlink($params{page}, $params{rootpage});
  281. if (!length $rootpage) {
  282. $rootpage=$params{rootpage};
  283. }
  284. }
  285. else {
  286. $rootpage=$params{page};
  287. }
  288. $formtemplate->param(rootpage => $rootpage);
  289. $formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
  290. $formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
  291. if (exists $params{postformtext}) {
  292. $formtemplate->param(postformtext =>
  293. $params{postformtext});
  294. }
  295. else {
  296. $formtemplate->param(postformtext =>
  297. gettext("Add a new post titled:"));
  298. }
  299. $ret.=$formtemplate->output;
  300. # The post form includes the feed buttons, so
  301. # emptyfeeds cannot be hidden.
  302. $emptyfeeds=1;
  303. }
  304. elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) {
  305. # Add feed buttons.
  306. my $linktemplate=template("feedlink.tmpl", blind_cache => 1);
  307. $linktemplate->param(rssurl => $rssurl) if $rss;
  308. $linktemplate->param(atomurl => $atomurl) if $atom;
  309. $ret.=$linktemplate->output;
  310. }
  311. if (! $feedonly) {
  312. require HTML::Template;
  313. my @params=IkiWiki::template_params($params{template}.".tmpl", blind_cache => 1);
  314. if (! @params) {
  315. error sprintf(gettext("nonexistant template %s"), $params{template});
  316. }
  317. my $template=HTML::Template->new(@params) unless $raw;
  318. foreach my $page (@list) {
  319. my $file = $pagesources{$page};
  320. my $type = pagetype($file);
  321. if (! $raw || ($raw && ! defined $type)) {
  322. unless ($archive && $quick) {
  323. # Get the content before populating the
  324. # template, since getting the content uses
  325. # the same template if inlines are nested.
  326. my $content=get_inline_content($page, $params{destpage});
  327. $template->param(content => $content);
  328. }
  329. $template->param(pageurl => urlto($page, $params{destpage}));
  330. $template->param(inlinepage => $page);
  331. $template->param(title => pagetitle(basename($page)));
  332. $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}));
  333. $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
  334. $template->param(first => 1) if $page eq $list[0];
  335. $template->param(last => 1) if $page eq $list[$#list];
  336. if ($actions) {
  337. my $file = $pagesources{$page};
  338. my $type = pagetype($file);
  339. if ($config{discussion}) {
  340. my $discussionlink=lc(gettext("Discussion"));
  341. if ($page !~ /.*\/\Q$discussionlink\E$/ &&
  342. (length $config{cgiurl} ||
  343. exists $links{$page."/".$discussionlink})) {
  344. $template->param(have_actions => 1);
  345. $template->param(discussionlink =>
  346. htmllink($page,
  347. $params{destpage},
  348. gettext("Discussion"),
  349. noimageinline => 1,
  350. forcesubpage => 1));
  351. }
  352. }
  353. if (length $config{cgiurl} && defined $type) {
  354. $template->param(have_actions => 1);
  355. $template->param(editurl => cgiurl(do => "edit", page => $page));
  356. }
  357. }
  358. run_hooks(pagetemplate => sub {
  359. shift->(page => $page, destpage => $params{destpage},
  360. template => $template,);
  361. });
  362. $ret.=$template->output;
  363. $template->clear_params;
  364. }
  365. else {
  366. if (defined $type) {
  367. $ret.="\n".
  368. linkify($page, $params{destpage},
  369. preprocess($page, $params{destpage},
  370. filter($page, $params{destpage},
  371. readfile(srcfile($file)))));
  372. }
  373. }
  374. }
  375. }
  376. if ($feeds && ($emptyfeeds || @feedlist)) {
  377. if ($rss) {
  378. my $rssp=$feedbase."rss".$feednum;
  379. will_render($params{destpage}, $rssp);
  380. if (! $params{preview}) {
  381. writefile($rssp, $config{destdir},
  382. genfeed("rss",
  383. $config{url}."/".$rssp, $desc, $params{guid}, $params{destpage}, @feedlist));
  384. $toping{$params{destpage}}=1 unless $config{rebuild};
  385. $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$desc (RSS)" href="$rssurl" />};
  386. }
  387. }
  388. if ($atom) {
  389. my $atomp=$feedbase."atom".$feednum;
  390. will_render($params{destpage}, $atomp);
  391. if (! $params{preview}) {
  392. writefile($atomp, $config{destdir},
  393. genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{destpage}, @feedlist));
  394. $toping{$params{destpage}}=1 unless $config{rebuild};
  395. $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$desc (Atom)" href="$atomurl" />};
  396. }
  397. }
  398. }
  399. return $ret if $raw || $nested;
  400. push @inline, $ret;
  401. return "<div class=\"inline\" id=\"$#inline\"></div>\n\n";
  402. }
  403. sub pagetemplate_inline (@) {
  404. my %params=@_;
  405. my $page=$params{page};
  406. my $template=$params{template};
  407. $template->param(feedlinks => $feedlinks{$page})
  408. if exists $feedlinks{$page} && $template->query(name => "feedlinks");
  409. }
  410. sub get_inline_content ($$) {
  411. my $page=shift;
  412. my $destpage=shift;
  413. my $file=$pagesources{$page};
  414. my $type=pagetype($file);
  415. if (defined $type) {
  416. $nested++;
  417. my $ret=htmlize($page, $destpage, $type,
  418. linkify($page, $destpage,
  419. preprocess($page, $destpage,
  420. filter($page, $destpage,
  421. readfile(srcfile($file))))));
  422. $nested--;
  423. return $ret;
  424. }
  425. else {
  426. return "";
  427. }
  428. }
  429. sub date_822 ($) {
  430. my $time=shift;
  431. my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
  432. POSIX::setlocale(&POSIX::LC_TIME, "C");
  433. my $ret=POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
  434. POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
  435. return $ret;
  436. }
  437. sub date_3339 ($) {
  438. my $time=shift;
  439. my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
  440. POSIX::setlocale(&POSIX::LC_TIME, "C");
  441. my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time));
  442. POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
  443. return $ret;
  444. }
  445. sub absolute_urls ($$) {
  446. # sucky sub because rss sucks
  447. my $content=shift;
  448. my $baseurl=shift;
  449. my $url=$baseurl;
  450. $url=~s/[^\/]+$//;
  451. # what is the non path part of the url?
  452. my $top_uri = URI->new($url);
  453. $top_uri->path_query(""); # reset the path
  454. my $urltop = $top_uri->as_string;
  455. $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(#[^"]+)"/$1 href="$baseurl$2"/mig;
  456. # relative to another wiki page
  457. $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)([^\/][^"]*)"/$1 href="$url$2"/mig;
  458. $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)([^\/][^"]*)"/$1 src="$url$2"/mig;
  459. # relative to the top of the site
  460. $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)(\/[^"]*)"/$1 href="$urltop$2"/mig;
  461. $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)(\/[^"]*)"/$1 src="$urltop$2"/mig;
  462. return $content;
  463. }
  464. sub genfeed ($$$$$@) {
  465. my $feedtype=shift;
  466. my $feedurl=shift;
  467. my $feeddesc=shift;
  468. my $guid=shift;
  469. my $page=shift;
  470. my @pages=@_;
  471. my $url=URI->new(encode_utf8(urlto($page,"",1)));
  472. my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1);
  473. my $content="";
  474. my $lasttime = 0;
  475. foreach my $p (@pages) {
  476. my $u=URI->new(encode_utf8(urlto($p, "", 1)));
  477. my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
  478. $itemtemplate->param(
  479. title => pagetitle(basename($p)),
  480. url => $u,
  481. permalink => $u,
  482. cdate_822 => date_822($pagectime{$p}),
  483. mdate_822 => date_822($pagemtime{$p}),
  484. cdate_3339 => date_3339($pagectime{$p}),
  485. mdate_3339 => date_3339($pagemtime{$p}),
  486. );
  487. if (exists $pagestate{$p}) {
  488. if (exists $pagestate{$p}{meta}{guid}) {
  489. $itemtemplate->param(guid => $pagestate{$p}{meta}{guid});
  490. }
  491. if (exists $pagestate{$p}{meta}{updated}) {
  492. $itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
  493. $itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
  494. }
  495. }
  496. if ($itemtemplate->query(name => "enclosure")) {
  497. my $file=$pagesources{$p};
  498. my $type=pagetype($file);
  499. if (defined $type) {
  500. $itemtemplate->param(content => $pcontent);
  501. }
  502. else {
  503. my $size=(srcfile_stat($file))[8];
  504. my $mime="unknown";
  505. eval q{use File::MimeInfo};
  506. if (! $@) {
  507. $mime = mimetype($file);
  508. }
  509. $itemtemplate->param(
  510. enclosure => $u,
  511. type => $mime,
  512. length => $size,
  513. );
  514. }
  515. }
  516. else {
  517. $itemtemplate->param(content => $pcontent);
  518. }
  519. run_hooks(pagetemplate => sub {
  520. shift->(page => $p, destpage => $page,
  521. template => $itemtemplate);
  522. });
  523. $content.=$itemtemplate->output;
  524. $itemtemplate->clear_params;
  525. $lasttime = $pagemtime{$p} if $pagemtime{$p} > $lasttime;
  526. }
  527. my $template=template($feedtype."page.tmpl", blind_cache => 1);
  528. $template->param(
  529. title => $page ne "index" ? pagetitle($page) : $config{wikiname},
  530. wikiname => $config{wikiname},
  531. pageurl => $url,
  532. content => $content,
  533. feeddesc => $feeddesc,
  534. guid => $guid,
  535. feeddate => date_3339($lasttime),
  536. feedurl => $feedurl,
  537. version => $IkiWiki::version,
  538. );
  539. run_hooks(pagetemplate => sub {
  540. shift->(page => $page, destpage => $page,
  541. template => $template);
  542. });
  543. return $template->output;
  544. }
  545. sub pingurl (@) {
  546. return unless @{$config{pingurl}} && %toping;
  547. eval q{require RPC::XML::Client};
  548. if ($@) {
  549. debug(gettext("RPC::XML::Client not found, not pinging"));
  550. return;
  551. }
  552. # daemonize here so slow pings don't slow down wiki updates
  553. defined(my $pid = fork) or error("Can't fork: $!");
  554. return if $pid;
  555. chdir '/';
  556. POSIX::setsid() or error("Can't start a new session: $!");
  557. open STDIN, '/dev/null';
  558. open STDOUT, '>/dev/null';
  559. open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
  560. # Don't need to keep a lock on the wiki as a daemon.
  561. IkiWiki::unlockwiki();
  562. foreach my $page (keys %toping) {
  563. my $title=pagetitle(basename($page), 0);
  564. my $url=urlto($page, "", 1);
  565. foreach my $pingurl (@{$config{pingurl}}) {
  566. debug("Pinging $pingurl for $page");
  567. eval {
  568. my $client = RPC::XML::Client->new($pingurl);
  569. my $req = RPC::XML::request->new('weblogUpdates.ping',
  570. $title, $url);
  571. my $res = $client->send_request($req);
  572. if (! ref $res) {
  573. error("Did not receive response to ping");
  574. }
  575. my $r=$res->value;
  576. if (! exists $r->{flerror} || $r->{flerror}) {
  577. error("Ping rejected: ".(exists $r->{message} ? $r->{message} : "[unknown reason]"));
  578. }
  579. };
  580. if ($@) {
  581. error "Ping failed: $@";
  582. }
  583. }
  584. }
  585. exit 0; # daemon done
  586. }
  587. 1