line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# HTML::EP::Glimpse - A simple search engine using Glimpse |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (C) 1998 Jochen Wiedmann |
7
|
|
|
|
|
|
|
# Am Eisteich 9 |
8
|
|
|
|
|
|
|
# 72555 Metzingen |
9
|
|
|
|
|
|
|
# Germany |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Phone: +49 7123 14887 |
12
|
|
|
|
|
|
|
# Email: joe@ispsoft.de |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# All rights reserved. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# You may distribute this module under the terms of either |
17
|
|
|
|
|
|
|
# the GNU General Public License or the Artistic License, as |
18
|
|
|
|
|
|
|
# specified in the Perl README file. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################################ |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
1625
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
23
|
1
|
|
|
1
|
|
398
|
use HTML::EP::Install (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use File::Basename (); |
25
|
|
|
|
|
|
|
use File::Path (); |
26
|
|
|
|
|
|
|
use ExtUtils::MakeMaker (); |
27
|
|
|
|
|
|
|
use Exporter (); |
28
|
|
|
|
|
|
|
use Symbol (); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package HTML::EP::Glimpse::Install; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use vars qw(@EXPORT @ISA $VERSION); |
34
|
|
|
|
|
|
|
@EXPORT = qw(Install Config); |
35
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
36
|
|
|
|
|
|
|
$VERSION = '0.02'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub Install { |
39
|
|
|
|
|
|
|
require HTML::EP::Glimpse::Config; |
40
|
|
|
|
|
|
|
my $cfg = $HTML::EP::Glimpse::Config::config; |
41
|
|
|
|
|
|
|
my $basedir = $cfg->{'html_base_dir'}; |
42
|
|
|
|
|
|
|
print "Copying HTML files from directory 'html' to $basedir.\n"; |
43
|
|
|
|
|
|
|
HTML::EP::Install::InstallHtmlFiles('html', $basedir); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Create the "var" directory and make it owned by the web servers UID |
46
|
|
|
|
|
|
|
my $vardir = File::Spec->catdir($basedir, "admin", "var"); |
47
|
|
|
|
|
|
|
my($user, $passwd, $uid, $gid) = getpwnam($cfg->{'httpd_user'}); |
48
|
|
|
|
|
|
|
die "No such user: $cfg->{'httpd_user'}" unless defined $uid; |
49
|
|
|
|
|
|
|
if (-d $vardir) { |
50
|
|
|
|
|
|
|
my ($dev, $ino, $mode,$nlink,$u,$g) = stat $vardir; |
51
|
|
|
|
|
|
|
print STDERR "Warning: Directory $vardir is not owned by the httpd", |
52
|
|
|
|
|
|
|
" user, $cfg->{'httpd_user'}\n" unless $u == $uid; |
53
|
|
|
|
|
|
|
print STDERR "Warning: Directory $vardir is not writable and readable", |
54
|
|
|
|
|
|
|
" by the owner" unless ($mode & 0700) == 0700; |
55
|
|
|
|
|
|
|
} else { |
56
|
|
|
|
|
|
|
print "Creating directory $vardir, mode 0700, owned by $cfg->{'httpd_user'}.\n"; |
57
|
|
|
|
|
|
|
File::Path::mkpath($vardir, 0, 0700); |
58
|
|
|
|
|
|
|
chown $uid, $gid, $vardir; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub PathOf { |
64
|
|
|
|
|
|
|
my $self = shift; my $prog = shift; |
65
|
|
|
|
|
|
|
foreach my $dir (File::Spec->path()) { |
66
|
|
|
|
|
|
|
my $f = File::Spec->catfile($dir, $prog); |
67
|
|
|
|
|
|
|
return $f if -x $f; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
File::Spec->catfile("/usr/bin", $prog); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub new { |
73
|
|
|
|
|
|
|
my $proto = shift(); |
74
|
|
|
|
|
|
|
my $file = shift() || "lib/HTML/EP/Glimpse/Config.pm"; |
75
|
|
|
|
|
|
|
my $cfg = eval { |
76
|
|
|
|
|
|
|
require HTML::EP::Glimpse::Config; |
77
|
|
|
|
|
|
|
$HTML::EP::Glimpse::Config::config; |
78
|
|
|
|
|
|
|
} || {}; |
79
|
|
|
|
|
|
|
bless($cfg, (ref($proto) || $proto)); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $config = shift(); |
82
|
|
|
|
|
|
|
$config = (! -f $file ) unless defined $config; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
if ($config || !defined($cfg->{'install_html_files'})) { |
85
|
|
|
|
|
|
|
my $reply = ExtUtils::MakeMaker::prompt |
86
|
|
|
|
|
|
|
("Install HTML files", |
87
|
|
|
|
|
|
|
(!defined($cfg->{'install_html_files'}) || |
88
|
|
|
|
|
|
|
$cfg->{'install_html_files'}) ? "y" : "n"); |
89
|
|
|
|
|
|
|
$cfg->{'install_html_files'} = ($reply =~ /y/i); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
if ($cfg->{'install_html_files'} && |
92
|
|
|
|
|
|
|
($config || !$cfg->{'html_base_dir'})) { |
93
|
|
|
|
|
|
|
$cfg->{'html_base_dir'} = ExtUtils::MakeMaker::prompt |
94
|
|
|
|
|
|
|
("Directory for installing HTML files", |
95
|
|
|
|
|
|
|
($cfg->{'html_base_dir'} || "/home/httpd/html/Glimpse")); |
96
|
|
|
|
|
|
|
$cfg->{'vardir'} = File::Spec->catdir($cfg->{'html_base_dir'}, |
97
|
|
|
|
|
|
|
'admin', 'var'); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
if ($config || !$cfg->{'httpd_user'}) { |
100
|
|
|
|
|
|
|
$cfg->{'httpd_user'} = ExtUtils::MakeMaker::prompt |
101
|
|
|
|
|
|
|
("UID the httpd is running as", |
102
|
|
|
|
|
|
|
($cfg->{'httpd_user'} || "nobody")); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
if ($config || !$cfg->{'glimpse_path'}) { |
105
|
|
|
|
|
|
|
$cfg->{'glimpse_path'} = ExtUtils::MakeMaker::prompt |
106
|
|
|
|
|
|
|
("Path of the glimpse binary", |
107
|
|
|
|
|
|
|
$cfg->{'glimpse_path'} || $cfg->PathOf("glimpse")) |
108
|
|
|
|
|
|
|
|| die "Missing path of glimpse binary"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
print STDERR "Warning: Program $cfg->{'glimpse_path'} not found." |
111
|
|
|
|
|
|
|
unless -x $cfg->{'glimpse_path'}; |
112
|
|
|
|
|
|
|
if ($config || !$cfg->{'glimpseindex_path'}) { |
113
|
|
|
|
|
|
|
$cfg->{'glimpseindex_path'} = ExtUtils::MakeMaker::prompt |
114
|
|
|
|
|
|
|
("Path of the glimpseindex binary", |
115
|
|
|
|
|
|
|
$cfg->{'glimpseindex_path'} || $cfg->PathOf("glimpseindex")) |
116
|
|
|
|
|
|
|
|| die "Missing path of glimpseindex binary"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
$cfg; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub Save { |
122
|
|
|
|
|
|
|
my $self = shift; my $file = shift() || "lib/HTML/EP/Glimpse/Config.pm"; |
123
|
|
|
|
|
|
|
require Data::Dumper; |
124
|
|
|
|
|
|
|
my $d = "package HTML::EP::Glimpse::Config;\nuse vars qw(\$config);\n" |
125
|
|
|
|
|
|
|
. Data::Dumper->new([$self], ["config"])->Indent(1)->Dump(); |
126
|
|
|
|
|
|
|
print "Creating configuration:\n$d\n" if $main::debug; |
127
|
|
|
|
|
|
|
my $dir = File::Basename::dirname($file); |
128
|
|
|
|
|
|
|
File::Path::mkpath($dir, 0, 0755) unless -d $dir; |
129
|
|
|
|
|
|
|
my $fh = Symbol::gensym(); |
130
|
|
|
|
|
|
|
(open($fh, ">$file") and (print $fh $d) and close($fh)) |
131
|
|
|
|
|
|
|
or die "Failed to create $file: $!"; |
132
|
|
|
|
|
|
|
$self; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub Config { |
136
|
|
|
|
|
|
|
my($proto, $file); |
137
|
|
|
|
|
|
|
if (@_) { |
138
|
|
|
|
|
|
|
($proto, $file) = @_; |
139
|
|
|
|
|
|
|
} else { |
140
|
|
|
|
|
|
|
($file) = @ARGV; |
141
|
|
|
|
|
|
|
$proto = "HTML::EP::Glimpse::Install"; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
my $self = $proto->new($file, 1); |
144
|
|
|
|
|
|
|
my $c = ref $self; |
145
|
|
|
|
|
|
|
($c =~ s/Install$/Config/) |
146
|
|
|
|
|
|
|
or die "Cannot handle class name $c: Must end with Install"; |
147
|
|
|
|
|
|
|
$c =~ s/\:\:/\//g; |
148
|
|
|
|
|
|
|
$c .= ".pm"; |
149
|
|
|
|
|
|
|
$self->Save($file || $INC{$c}); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |