OMatic/mirrorServer.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 77 CC 3 SCAR 13.3
CC
3
Cov
0%
main
6.0
numerically
6.0
BEGIN
2.0
CRAP 3.8
1 ##############################################################################
2 # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. #
3 # #
4 # This program is free software; you can redistribute it and/or #
5 # modify it under the terms of the GNU General Public License #
6 # as published by the Free Software Foundation; either version 2 #
7 # of the License, or (at your option) any later version. #
8 # #
9 # This program is distributed in the hope that it will be useful, #
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 # GNU General Public License for more details. #
13 # #
14 # You should have received a copy of the GNU General Public License #
15 # along with this program; if not, write to the Free Software #
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#
17 # #
18 # Jon Howell can be contacted at: #
19 # 6211 Sudikoff Lab, Dartmouth College #
20 # Hanover, NH 03755-3510 #
21 # jonh@cs.dartmouth.edu #
22 # #
23 # An electronic copy of the GPL is available at: #
24 # http://www.gnu.org/copyleft/gpl.html #
25 # #
26 ##############################################################################
27  
28 use strict;
29  
30 package FAQ::OMatic::mirrorServer;
31  
32 use CGI;
33 use FAQ::OMatic;
34 use FAQ::OMatic::Item;
35 use FAQ::OMatic::install;
36  
37 sub main {
38 my $cgi = FAQ::OMatic::dispatch::cgi();
39
40 my $params = FAQ::OMatic::getParams($cgi);
41  
42 my $rt = "Content-type: text/plain\n\n";
43 $rt .= "# FAQ-O-Matic mirror master\n";
44 $rt .= "# This file describes the configuration, items, and bags of a\n"
45 ."# FAQ-O-Matic, so it can be mirrored at another site.\n";
46  
47 # mirror format version number -- sent so client (mirror) can make
48 # sure he understands the structure of the following data.
49 $rt .= "version 1.0\n";
50 $rt .= "itemURL $FAQ::OMatic::Config::itemURL\n";
51 $rt .= "bagsURL $FAQ::OMatic::Config::bagsURL\n";
52  
53 # send mirrorable config params
54 my $configInfo = FAQ::OMatic::install::configInfo();
55 my $map = FAQ::OMatic::install::readConfig();
56 my $key;
57 foreach $key (sort keys %{$configInfo}) {
58 my $ch = $configInfo->{$key};
59 next if (not $ch->{'-mirror'});
60 my $value = $map->{'$'.$key} || "''"; # undefined => ''
61 $rt.='config $'."$key = $value\n";
62 }
63  
64 # send item catalog
65 my $file;
66 my @allItems = sort numerically FAQ::OMatic::getAllItemNames();
67 foreach $file (@allItems) {
68 my $item = new FAQ::OMatic::Item($file);
69 my $lms = $item->{'LastModifiedSecs'} || time();
70 my $whatIsIt = $item->whatAmI();
71 $rt.="item $file $lms $whatIsIt\n";
72 }
73  
74 # send bags catalog
75 my @bagList = grep { not m/\.desc$/ }
76 FAQ::OMatic::getAllItemNames($FAQ::OMatic::Config::bagsDir);
77 my $bagName;
78 foreach $bagName (sort @bagList) {
79 my $item = new FAQ::OMatic::Item($bagName.".desc",
80 $FAQ::OMatic::Config::bagsDir);
81 my $lms = $item->{'LastModifiedSecs'} || time();
82 $rt.="bag $bagName $lms\n";
83 }
84  
85 print $rt;
86 }
87  
88 # sort numeric things numerically, but don't fail (sort lexically) otherwise.
89 sub numerically {
90 my $compare = FAQ::OMatic::stripInt($a) <=> FAQ::OMatic::stripInt($b);
91 if ($compare == 0) {
92 $compare = $a cmp $b;
93 }
94 return $compare;
95 }
96  
97 1;