Move perl modules to perl/Debian/Dwww dir.
* Move perl modules to perl/Debian/Dwww dir.
* dwww-convert: Re-add support for DWWW_USEFILEDIR.
* dwww-find: fix a typo.
* Remove realpath sources.
* debian/dwww.cron.*: remove unneeded source'ing the functions.sh file.
* debian/*: Bump to debhelper v5.
* Standards-Version: 3.7.2 (no changes needed).
* Remove unneeded source.linian-overrides file.
* README: remove the note about apache2.
* dwww.links: move firefox search plugin to /usr/share/firefox dir.
Robert Luberda
17 years ago
0 | 0 | dwww-cache |
1 | 1 | dwww-quickfind |
2 | 2 | dwww-txt2html |
3 | realpath | |
4 | 3 | build-stamp |
5 | 4 | functions.sh |
6 | 5 | *.test |
0 | # vim:ft=perl:cindent:ts=4:sw=4:et:fdm=marker:cms=\ #\ %s | |
1 | # | |
2 | # $Id: Common.pm,v 1.2 2006-05-07 18:30:08 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::Common; | |
5 | ||
6 | use Exporter(); | |
7 | use strict; | |
8 | ||
9 | use Debian::Dwww::Utils; | |
10 | use vars qw(@ISA @EXPORT); | |
11 | @ISA = qw(Exporter); | |
12 | @EXPORT = qw(GetURL); | |
13 | ||
14 | ||
15 | my $dwww_url = "/cgi-bin/dwww"; | |
16 | my %href = # {{{ | |
17 | ( | |
18 | 'debiandoc-sgml'=> "$dwww_url#FILE#?type=application/sgml", | |
19 | 'docbook-xml' => "$dwww_url#FILE#?type=text/xml", | |
20 | 'dvi' => "$dwww_url#FILE#?type=application/x-dvi", | |
21 | 'html' => "$dwww_url#FILE#?type=html", | |
22 | 'info' => "/cgi-bin/info2www?file=", | |
23 | 'latex' => "$dwww_url#FILE#?type=application/x-latex", | |
24 | 'linuxdoc-sgml' => "$dwww_url#FILE#?type=application/sgml", | |
25 | 'pdf' => "$dwww_url#FILE#?type=application/pdf", | |
26 | 'postscript' => "$dwww_url#FILE#?type=application/postscript", | |
27 | 'ps' => "$dwww_url#FILE#?type=application/postscriptps", | |
28 | 'rtf' => "$dwww_url#FILE#?type=text/rtf", | |
29 | 'sgml' => "$dwww_url#FILE#?type=application/sgml", | |
30 | 'tar' => "$dwww_url#FILE#?type=application/tar", | |
31 | 'texinfo' => "$dwww_url#FILE#?type=application/x-texinfo", | |
32 | 'dwww-url' => "", | |
33 | 'text' => "$dwww_url#FILE#?type=text/plain", | |
34 | 'pkgsearch' => "$dwww_url?search=", | |
35 | 'man' => '/cgi-bin/dwww#FILE#?type=man', | |
36 | 'runman' => '/cgi-bin/dwww?type=runman&location=', | |
37 | 'dir' => '/cgi-bin/dwww#FILE#/?type=dir', | |
38 | 'info' => '/cgi-bin/info2www?file=', | |
39 | 'file' => '/cgi-bin/dwww', | |
40 | 'menu' => '/dwww/menu/', | |
41 | 'search' => '/cgi-bin/dwww?search=', | |
42 | 'dpkg' => '/cgi-bin/dpkg?query=' | |
43 | ); # }}} | |
44 | ||
45 | sub GetURL{ # {{{ | |
46 | my $format_name = shift; | |
47 | my $format_url = shift; | |
48 | my $dont_encode = shift; | |
49 | $dont_encode = $FALSE unless defined $dont_encode; | |
50 | ||
51 | ||
52 | $format_url = &URLEncode($format_url) unless ($dont_encode || $format_name eq 'dwww-url'); | |
53 | ||
54 | if ($href{$format_name} =~ /#FILE#/) { | |
55 | return $` . $format_url . $'; | |
56 | } else { | |
57 | return $href{$format_name} . $format_url; | |
58 | } | |
59 | ||
60 | ||
61 | } # }}} | |
62 | ||
63 | 1; |
0 | # vim:ft=perl:cindent | |
1 | # | |
2 | # $Id: DocBase.pm,v 1.5 2003-05-16 17:22:33 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::DocBase; | |
5 | ||
6 | use Exporter(); | |
7 | use Debian::Dwww::Version; | |
8 | use strict; | |
9 | ||
10 | use vars qw(@ISA @EXPORT $ErrorProc); | |
11 | @ISA = qw(Exporter); | |
12 | @EXPORT = qw(ParseDocBaseFile DwwwSection2Section $ErrorProc); | |
13 | ||
14 | ||
15 | ||
16 | sub ParseDocBaseFile { | |
17 | my $file = shift; | |
18 | my $format = undef; | |
19 | my $entry = {}; | |
20 | my ($fld, $val, $lastfld) = ('', '', ''); | |
21 | my $line = 0; | |
22 | local $_; | |
23 | ||
24 | if (not open DOCFILE, $file) { | |
25 | &$ErrorProc($file, "Can't be opened: $!"); | |
26 | return undef; | |
27 | } | |
28 | ||
29 | while (<DOCFILE>) { | |
30 | chomp; | |
31 | s/\s+$//; | |
32 | $line++; | |
33 | if (/^\s*$/) { | |
34 | # empty lines separate sections | |
35 | $format = ''; # here we define $format | |
36 | $lastfld = ''; | |
37 | } elsif (/^(\S+)\s*:\s*(.*)\s*$/) { | |
38 | ($fld, $val) = (lc $1, $2); | |
39 | ||
40 | ||
41 | if (not defined $format) { | |
42 | $entry->{$fld} = $val; | |
43 | } elsif ($format eq '' and $fld eq 'format') { | |
44 | $format = lc $val; | |
45 | } elsif ($format ne '' and $fld eq 'index') { | |
46 | $entry->{'formats'}->{$format}->{'index'} = $val; | |
47 | } elsif ($format ne '' and $fld eq 'files') { | |
48 | $entry->{'formats'}->{$format}->{'files'} = $val; | |
49 | } else { | |
50 | goto PARSE_ERROR; | |
51 | } | |
52 | $lastfld = $fld; | |
53 | } elsif (/^\s+/ and $lastfld ne '') { | |
54 | $entry->{$lastfld} .= "\n$_"; | |
55 | } else { | |
56 | goto PARSE_ERROR; | |
57 | } | |
58 | } | |
59 | ||
60 | close DOCFILE; | |
61 | ||
62 | return $entry; | |
63 | ||
64 | ||
65 | PARSE_ERROR: | |
66 | &$ErrorProc($file, "Parse error at line $line"); | |
67 | close DOCFILE; | |
68 | return undef; | |
69 | } | |
70 | ||
71 | ||
72 | sub DwwwSection2Section { | |
73 | my $entry = shift; | |
74 | ||
75 | my $sec = $entry->{'dwww-section'} if defined $entry->{'dwww-section'}; | |
76 | my $title = defined $entry->{'dwww-title'} ? $entry->{'dwww-title'} : | |
77 | defined $entry->{'title'} ? $entry->{'title'} : undef; | |
78 | ||
79 | return unless defined $sec and defined $title; | |
80 | ||
81 | if (length($sec) > length($title) && | |
82 | substr ($sec, -length($title)) eq $title) { | |
83 | $sec = substr ($sec, 0, -length($title)); | |
84 | } else { | |
85 | return; | |
86 | } | |
87 | ||
88 | $sec =~ s|^/+||; | |
89 | $sec =~ s|/+$||; | |
90 | $entry->{'section'} = $sec; | |
91 | ||
92 | } | |
93 | ||
94 | ||
95 | 1; |
0 | # vim:ft=perl:cindent:ts=4:sw=4:et:fdm=marker:cms=\ #\ %s | |
1 | # | |
2 | # $Id: Initialize.pm,v 1.10 2006-05-07 18:30:08 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::Initialize; | |
5 | ||
6 | use Exporter(); | |
7 | use Sys::Hostname; | |
8 | use strict; | |
9 | ||
10 | use vars qw(@ISA @EXPORT); | |
11 | @ISA = qw(Exporter); | |
12 | @EXPORT = qw(DwwwInitialize DwwwSetupDirs); | |
13 | ||
14 | sub DwwwInitialize() { | |
15 | my $filename = shift; | |
16 | my $hostname = &hostname(); | |
17 | $hostname =~ s/\..*$//; | |
18 | my $dwwwvars = { | |
19 | 'DWWW_DOCPATH' => "/usr/share/doc:/usr/doc:/usr/share/info:/usr/info:" | |
20 | . "/usr/share/man:/usr/man:/usr/X11R6/man:/usr/local/man:" | |
21 | . "/usr/local/doc:/usr/local/info:/usr/share/common-licenses", | |
22 | 'DWWW_ALLOWEDLINKPATH' => "/usr/share:/usr/lib:/var/www", | |
23 | 'DWWW_TMPDIR' => "/var/lib/dwww", | |
24 | 'DWWW_HTMLDIR' => "/var/lib/dwww/html", | |
25 | 'DWWW_USE_CACHE' => "yes", | |
26 | 'DWWW_KEEPDAYS' => 10, | |
27 | 'DWWW_QUICKFIND_DB' => "/var/cache/dwww/quickfind.dat", | |
28 | 'DWWW_REGDOCS_DB' => "/var/cache/dwww/regdocs.dat", | |
29 | 'DWWW_DOCBASE2PKG_DB' => "/var/cache/dwww/docbase2pkg.dat", | |
30 | 'DWWW_TITLE' => 'dwww: ' . $hostname, | |
31 | 'DWWW_DOCROOTDIR' => '/var/www', | |
32 | 'DWWW_CGIDIR' => '/usr/lib/cgi-bin', | |
33 | 'DWWW_CGIUSER' => 'www-data', | |
34 | 'DWWW_SERVERNAME' => 'localhost', | |
35 | 'DWWW_SERVERPORT' => 80 | |
36 | ||
37 | }; | |
38 | ||
39 | umask (022); | |
40 | $ENV{'PATH'} = "/usr/sbin:/usr/bin:$ENV{'PATH'}"; | |
41 | ||
42 | return $dwwwvars unless defined $filename; | |
43 | return $dwwwvars unless -r $filename; | |
44 | ||
45 | open DWWWCONF, "<$filename" or die "Can't open $filename: $!\n"; | |
46 | while (<DWWWCONF>) { | |
47 | chomp(); | |
48 | if (m/^\s*([^=]+)\s*=\s*(\S+)\s*$/) { | |
49 | $dwwwvars->{$1} = $2; | |
50 | } | |
51 | } | |
52 | close DWWWCONF or die "Can't close $filename: $!\n"; | |
53 | foreach my $k ( 'DWWW_DOCPATH', 'DWWW_ALLOWEDLINKPATH' ) { | |
54 | my @paths = split( /:/, $dwwwvars->{$k} ); | |
55 | $dwwwvars->{$k} = \@paths; | |
56 | } | |
57 | ||
58 | return $dwwwvars; | |
59 | } | |
60 | ||
61 | sub DwwwSetupDirs() { | |
62 | my $dwwwvars = shift; | |
63 | ||
64 | my $dir = "/var/cache/dwww"; | |
65 | if ( ! -d "$dir" ) { | |
66 | mkdir "$dir", 0755 or die "Cannot create directory $dir"; | |
67 | chown 0, 0, "$dir" | |
68 | } | |
69 | if ( ! -d "$dir/db" ) { | |
70 | mkdir "$dir/db", 0755 or die "Cannot create directory $dir/db"; | |
71 | my $uid = (getpwnam("$dwwwvars->{'DWWW_CGIUSER'}"))[2] or die "User $dwwwvars->{'DWWW_CGIUSER'} does not exist\n"; | |
72 | chown $uid, 0, "$dir/db"; | |
73 | } | |
74 | } | |
75 | 1; |
0 | # vim:ft=perl:cindent:ts=4:sw=4:et:fdm=marker:cms=\ #\ %s | |
1 | # | |
2 | # $Id: Utils.pm,v 1.9 2006-05-07 18:30:08 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::Utils; | |
5 | ||
6 | use Exporter(); | |
7 | use Debian::Dwww::Version; | |
8 | use Cwd qw(cwd realpath); | |
9 | use POSIX qw(strftime locale_h); | |
10 | use File::Path qw/rmtree mkpath/; | |
11 | use File::NCopy qw/copy/; | |
12 | ||
13 | use strict; | |
14 | ||
15 | use vars qw(@ISA @EXPORT); | |
16 | @ISA = qw(Exporter); | |
17 | @EXPORT = qw(URLEncode HTMLEncode HTMLEncodeAbstract StripDirs CheckAccess RedirectToURL ErrorMsg | |
18 | TemplateFile BeginTable AddToTable EndTable GetCommandOutput RenameDir $TRUE $FALSE); | |
19 | ||
20 | our $TRUE = 1; | |
21 | our $FALSE = 0; | |
22 | ||
23 | sub URLEncode { | |
24 | my $url = shift; | |
25 | $url =~ s/([^A-Za-z0-9\_\-\.\/])/"%" . unpack("H*", $1)/eg; | |
26 | # $url =~ tr/ /+/; | |
27 | return $url; | |
28 | } | |
29 | ||
30 | # HTMLEncode(what) | |
31 | sub HTMLEncode { # {{{ | |
32 | my $text = shift; | |
33 | ||
34 | ||
35 | $text =~ s/&/&/g; | |
36 | $text =~ s/</</g; | |
37 | $text =~ s/>/>/g; | |
38 | $text =~ s/"/"/g; | |
39 | return $text; | |
40 | } # }}} | |
41 | ||
42 | sub HTMLEncodeAbstract { # {{{ | |
43 | my $text = &HTMLEncode(@_); | |
44 | ||
45 | $text =~ s/^\s\s+(.*)$/<BR><TT> $1<\/TT><BR>/gm; | |
46 | $text =~ s/^\s\.\s*$/<BR>/gm; | |
47 | $text =~ s/(<BR>\s*)+/<BR>\n/g; | |
48 | $text =~ s/(http|ftp)s?:\/([\w\/~\.%#-])+[\w\/]/<A href="$&">$&<\/A>/g; | |
49 | $text =~ s/<BR>\s*$//; | |
50 | return $text; | |
51 | } # }}} | |
52 | ||
53 | sub GetDate { # {{{ | |
54 | my $old_locale = &setlocale(LC_ALL, "C"); | |
55 | my $date = &strftime ("%a %b %e %H:%M:%S %Z %Y", localtime(time)); | |
56 | &setlocale(LC_ALL, $old_locale) unless $old_locale eq "C"; | |
57 | return $date; | |
58 | } # }}} | |
59 | ||
60 | ||
61 | sub TemplateFile { # {{{ | |
62 | my $file= shift; | |
63 | my $vars= shift; # hash reference | |
64 | my $res = ''; | |
65 | local $_; | |
66 | ||
67 | ||
68 | open TEMPLATE , "<$file" or die "Can't open $file: $!"; | |
69 | while (<TEMPLATE>) { | |
70 | foreach my $k (keys %{$vars}) { | |
71 | s/\%$k\%/$vars->{$k}/g | |
72 | } | |
73 | s/\%VERSION\%/$Debian::Dwww::Version::version/o; | |
74 | s/\%DATE\%/&GetDate()/eg; | |
75 | $res .= $_; | |
76 | } | |
77 | ||
78 | close TEMPLATE; | |
79 | return $res; | |
80 | } # }}} | |
81 | ||
82 | ||
83 | sub BeginTable { # {{{ | |
84 | my $filehandle = shift; | |
85 | my $caption = shift; | |
86 | my $columns = shift; | |
87 | my $desc = shift; | |
88 | my $widths = shift; | |
89 | my $table = {}; | |
90 | ||
91 | $desc = '' unless (defined $desc); | |
92 | ||
93 | $table->{'columns'} = $columns + 0; | |
94 | $table->{'widths'} = $widths; | |
95 | $table->{'in_column'} = 0; | |
96 | $table->{'in_row'} = 0; | |
97 | ||
98 | print $filehandle "<P align=\"left\">\n"; | |
99 | print $filehandle "<STRONG>$caption</STRONG>$desc\n"; | |
100 | print $filehandle "<TABLE border=\"0\" width=\"98%\" align=\"center\">\n"; | |
101 | return $table; | |
102 | } # }}} | |
103 | ||
104 | sub AddToTable { # {{{ | |
105 | my $filehandle = shift; | |
106 | my $table = shift; | |
107 | my $what = shift; | |
108 | my ($wdth, $c, $r); | |
109 | ||
110 | $c = $table->{'in_column'}; | |
111 | $r = $table->{'in_row'}; | |
112 | ||
113 | ||
114 | if ($c == 0) { | |
115 | print $filehandle "<TR>\n" | |
116 | } | |
117 | ||
118 | if ($r == 0 && $c + 1 < $table->{'columns'}) { | |
119 | if (defined $table->{'widths'}) { | |
120 | $wdth = ' width="' . $table->{'widths'}[int($c)] .'%"'; | |
121 | } else { | |
122 | $wdth = ' width="' . int(100 / $table->{'columns'}) . '%"'; | |
123 | } | |
124 | } else { | |
125 | $wdth = ''; | |
126 | } | |
127 | ||
128 | print $filehandle "<TD align=\"left\"$wdth>$what</TD>\n"; | |
129 | ||
130 | if (++$c >= $table->{'columns'}) { | |
131 | print $filehandle "</TR>\n"; | |
132 | $c = 0; | |
133 | $r++; | |
134 | } | |
135 | $table->{'in_column'} = $c; | |
136 | $table->{'in_row'} = $r; | |
137 | } # }}} | |
138 | ||
139 | ||
140 | sub EndTable { # {{{ | |
141 | my $filehandle = shift; | |
142 | my $table = shift; | |
143 | ||
144 | while ($table->{'in_column'} != 0) { | |
145 | &AddToTable($filehandle, $table, ''); | |
146 | } | |
147 | print $filehandle "</TABLE>\n"; | |
148 | ||
149 | undef %{$table}; | |
150 | } # }}} | |
151 | ||
152 | # strips any '.' and '..' components from path | |
153 | sub StripDirs { # {{{ | |
154 | my $path = shift; | |
155 | ||
156 | ||
157 | $path = &cwd() . '/' . $path unless $path =~ /^\//; | |
158 | ||
159 | my @pc = split(/\/+/, $path); | |
160 | my @res = (); | |
161 | ||
162 | foreach my $p (@pc) { | |
163 | next if $p eq '.' || $p eq ''; | |
164 | pop(@res), next if $p eq '..'; | |
165 | push(@res, $p); | |
166 | } | |
167 | my $r = '/' . join ('/', @res); | |
168 | return $r; | |
169 | ||
170 | } # }}} | |
171 | ||
172 | # | |
173 | # Print error message and exit the program | |
174 | # usage: ErrorMsg status title message | |
175 | sub ErrorMsg { # {{{ | |
176 | my $status = shift; | |
177 | my $title = shift; | |
178 | my $message = shift; | |
179 | ||
180 | print "Status: $status\n"; | |
181 | print "Content-type: text/html; charset=iso-8895-1\n"; | |
182 | print "\n"; | |
183 | print "<HTML>\n"; | |
184 | print "<HEAD>\n"; | |
185 | print " <TITLE>$title</TITLE>\n"; | |
186 | print "</HEAD>"; | |
187 | print "<BODY>"; | |
188 | print " <H1 align=\"center\">$title</H1>\n"; | |
189 | print "$message\n"; | |
190 | print "</BODY>\n"; | |
191 | print "</HTML>\n"; | |
192 | exit 1; | |
193 | } # }}} | |
194 | ||
195 | ||
196 | # returns output of realpath($file) | |
197 | sub CheckAccess() { # {{{ | |
198 | my $dwwwvars = shift; | |
199 | my $file = shift; | |
200 | my $orig_file = shift; | |
201 | $orig_file = $file unless defined $orig_file; | |
202 | ||
203 | my $dwww_docpath = $dwwwvars->{'DWWW_DOCPATH'}; | |
204 | my $dwww_allowedlinkpath = $dwwwvars->{'DWWW_ALLOWEDLINKPATH'}; | |
205 | ||
206 | ||
207 | my $can_read_f = -r $file; | |
208 | my $exists_f = $can_read_f || -f $file; | |
209 | my $realp_file = undef; | |
210 | ||
211 | ||
212 | if ( $exists_f ) { | |
213 | $realp_file = &realpath( $file ); | |
214 | ||
215 | # file does exist, check if it match any files in @dwww_docpath | |
216 | foreach my $path (@$dwww_docpath) { | |
217 | if ( -d $path ) { | |
218 | $path = &realpath( $path ); | |
219 | if (substr($realp_file, 0, length($path)) eq $path) { | |
220 | &ErrorMsg( "403 Access Denied", | |
221 | "Access Denied", | |
222 | "The $orig_file is not readable!" ) unless $can_read_f; | |
223 | return $realp_file; # everything OK | |
224 | } | |
225 | } | |
226 | } | |
227 | } | |
228 | ||
229 | # if we're here, the file either does not exist | |
230 | # or does not match any @dwww_docpath | |
231 | my $ok = 0; | |
232 | my $strip_file = &StripDirs( $file ); | |
233 | foreach my $path (@$dwww_docpath) { | |
234 | if ( -d $path ) { | |
235 | $path = &StripDirs( $path ); | |
236 | if (substr($strip_file, 0, length($path)) eq $path) { | |
237 | $ok = 1; | |
238 | last; | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | ||
244 | # if file exists, check if it's in allowed_linkpath | |
245 | if ( $exists_f && $ok ) { | |
246 | foreach my $path (@$dwww_allowedlinkpath) { | |
247 | if ( -d $path ) { | |
248 | $path = &realpath( $path ); | |
249 | if (substr($realp_file, 0, length($path)) eq $path) { | |
250 | return $realp_file; | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | # file either does not exist or is not allowed to show | |
257 | # print suitable error message | |
258 | if ( !$exists_f && $ok ) { | |
259 | &ErrorMsg ("404 File not found", | |
260 | "File not found" , | |
261 | "dwww could not find the file $orig_file" ); | |
262 | } else { | |
263 | &ErrorMsg ("403 Access denied", | |
264 | "Access denied", | |
265 | "dwww will not allow you to read the file $orig_file" ); | |
266 | } | |
267 | ||
268 | exit 1; ### UNREACHED ### | |
269 | } # }}} | |
270 | ||
271 | sub GetCommandOutput { # {{{ | |
272 | my @args = @_; | |
273 | # fork and exec command | |
274 | open (OUT, '-|') | |
275 | || exec { $args[0] } @args; | |
276 | my @out=<OUT>; | |
277 | close OUT; | |
278 | return @out; | |
279 | } # }}} | |
280 | ||
281 | sub RedirectToURL() { # {{{ | |
282 | my $url = shift; | |
283 | ||
284 | my $name = defined $ENV{'SERVER_NAME'} ? $ENV{'SERVER_NAME'} : 'localhost'; | |
285 | my $port = defined $ENV{'SERVER_PORT'} ? ':' . $ENV{'SERVER_PORT'} : ''; | |
286 | $url = "/$url" unless $url =~ m/^\//; | |
287 | ||
288 | print "Location: http://$name$port$url\n\n"; | |
289 | } # }}} | |
290 | ||
291 | sub RenameDir() { # {{{ | |
292 | my ($srcdir, $tgtdir) = @_; | |
293 | ||
294 | &rmtree($tgtdir) or die "Cannot remove old $tgtdir directory: $!\n" if -d $tgtdir; | |
295 | if (! rename($srcdir, $tgtdir)) { | |
296 | &mkpath($tgtdir) or die "Cannot create $tgtdir: $!\n"; | |
297 | ©(\1, "$srcdir/*", $tgtdir) or die "Cannot copy $srcdir to $tgtdir: $!\n"; | |
298 | &rmtree($srcdir); | |
299 | } | |
300 | } # }}} | |
301 | ||
302 | ||
303 | 1; |
0 | # | |
1 | # $Id: Version.pm.in,v 1.2 2003-03-08 16:24:37 robert Exp $ | |
2 | # | |
3 | package Debian::Dwww::Version; | |
4 | $version='#VERSION#'; | |
5 | ||
6 | 1; |
0 | 0 | # |
1 | 1 | # Makefile for dwww. |
2 | # "@(#)dwww:$Id: Makefile,v 1.29 2006-05-07 18:30:06 robert Exp $" | |
2 | # "@(#)dwww:$Id: Makefile,v 1.30 2006-05-30 18:56:29 robert Exp $" | |
3 | 3 | # |
4 | 4 | |
5 | 5 | VERSION = $(shell dpkg-parsechangelog | sed -ne 's/^Version: *//p') |
41 | 41 | cachedir = $(prefix)/var/cache/dwww |
42 | 42 | webdocrootdir = $(prefix)/var/www |
43 | 43 | webcgidir = $(prefix)/usr/lib/cgi-bin |
44 | perlmoddir=$(prefix)/usr/share/perl5/Debian/Dwww | |
44 | perlmoddir = $(prefix)/usr/share/perl5/Debian/Dwww | |
45 | 45 | |
46 | perlmodules = Dwww/*.pm | |
47 | source_links = Debian | |
46 | perlmodules = perl/Debian/Dwww/*.pm | |
48 | 47 | |
49 | 48 | |
50 | 49 | links_end = dwww-convert.dir.end dwww-convert.end dwww-find.end |
51 | 50 | |
52 | 51 | lib = lib/[!Ceio]* lib/img/[!C]* |
53 | 52 | editorial = lib/editorial/*.html |
54 | bin = realpath dwww | |
53 | bin = dwww | |
55 | 54 | cgi = dwww.cgi |
56 | 55 | sbin = dwww-convert dwww-build dwww-cache dwww-find \ |
57 | 56 | dwww-quickfind dwww-txt2html dwww-format-man \ |
60 | 59 | man1 = man/*.1 |
61 | 60 | man8 = man/*.8 |
62 | 61 | |
63 | generated = realpath dwww-cache dwww-quickfind dwww-txt2html \ | |
64 | Dwww/Version.pm functions.sh | |
62 | generated = dwww-cache dwww-quickfind dwww-txt2html \ | |
63 | perl/Debian/Dwww/Version.pm functions.sh | |
65 | 64 | |
66 | 65 | perlprogs = dwww-find dwww-build-menu dwww-index++ |
67 | 66 | testprogs := $(patsubst %,%.test,$(perlprogs)) |
68 | 67 | |
69 | all: $(source_links) $(generated) | |
68 | all: $(generated) | |
70 | 69 | |
71 | 70 | |
72 | %::%.in $(source_links) | |
71 | %::%.in | |
73 | 72 | # try to be compatible with the both sarge and sid versions of make |
74 | PERL5LIB="." $(PERL) -e \ | |
73 | PERL5LIB="./perl" $(PERL) -e \ | |
75 | 74 | 'exec ("'$(PERL)'", "-e", join("",@ARGV)) if $$#ARGV >-1; '\ |
76 | 75 | ' $$|=1; '\ |
77 | 76 | ' use Debian::Dwww::Initialize; '\ |
94 | 93 | dwww-txt2html: dwww-txt2html.o utils.o |
95 | 94 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) |
96 | 95 | |
97 | realpath: realpath.o | |
98 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) | |
99 | ||
100 | 96 | dwww-cache: dwww-cache.o utils.o |
101 | 97 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) |
102 | 98 | |
111 | 107 | ln -s . $@ |
112 | 108 | |
113 | 109 | clean: |
114 | rm -f $(source_links) | |
115 | 110 | rm -f core *.o $(generated) |
116 | 111 | rm -f $(testprogs) |
117 | 112 | |
150 | 145 | %.test::% |
151 | 146 | rm -f $@ |
152 | 147 | echo "#!/usr/bin/perl" > $@ |
153 | echo "use lib \".\";" >> $@ | |
148 | echo "use lib \"./perl\";" >> $@ | |
154 | 149 | sed -e 's/\/usr\/share\/dwww/lib/g' $< >> $@ |
155 | 150 | chmod 555 $@ |
156 | 151 | |
157 | test: $(testprogs) $(source_links) | |
152 | test: $(testprogs) | |
158 | 153 | |
159 | 154 | .PHONY: all debug clean install installdirs test |
9 | 9 | dwww requires running a web server with CGI support (i.e. apache, |
10 | 10 | boa, roxen, wn, etc., but NOT dhttpd or fnord.) |
11 | 11 | Sorry. |
12 | ||
13 | <===================================================> | |
14 | | Using dwww with the APACHE2 web server | | |
15 | | ---------------------------------------- | | |
16 | | | | |
17 | | For some unknown reason the apache2 web server | | |
18 | | has the CGI support DISABLED by default | | |
19 | | | | |
20 | | Therefore to use dwww you have to enable the | | |
21 | | CGI module by giving the following command: | | |
22 | | a2enmod cgi | | |
23 | | | | |
24 | +===================================================+ | |
25 | 12 | |
26 | 13 | |
27 | 14 | For more information, read the manual page dwww(8), and the other |
0 | dwww (1.9.94.1) UNRELEASED; urgency=low | |
1 | ||
2 | * Move perl modules to perl/Debian/Dwww dir. | |
3 | * dwww-convert: Re-add support for DWWW_USEFILEDIR. | |
4 | * dwww-find: fix a typo. | |
5 | * Remove realpath sources. | |
6 | * debian/dwww.cron.*: remove unneeded source'ing the functions.sh file. | |
7 | * debian/*: Bump to debhelper v5. | |
8 | * Standards-Version: 3.7.2 (no changes needed). | |
9 | * Remove unneeded source.linian-overrides file. | |
10 | * README: remove the note about apache2. | |
11 | * dwww.links: move firefox search plugin to /usr/share/firefox dir. | |
12 | ||
13 | -- Robert Luberda <robert@debian.org> Tue, 30 May 2006 20:54:56 +0200 | |
14 | ||
0 | 15 | dwww (1.9.94) experimental; urgency=low |
1 | 16 | |
2 | 17 | * Stop building the realpath package, which was moved to its own source |
1 | 1 | Section: doc |
2 | 2 | Priority: optional |
3 | 3 | Maintainer: Robert Luberda <robert@debian.org> |
4 | Build-Depends: debhelper (>= 4.9), publib-dev | |
5 | Standards-Version: 3.6.2 | |
4 | Build-Depends: debhelper (>= 5), publib-dev | |
5 | Standards-Version: 3.7.2 | |
6 | 6 | |
7 | 7 | Package: dwww |
8 | 8 | Architecture: any |
0 | 0 | #!/bin/sh |
1 | # $Id: dwww.cron.daily,v 1.15 2005-04-09 10:03:27 robert Exp $ | |
1 | # $Id: dwww.cron.daily,v 1.16 2006-05-30 18:56:45 robert Exp $ | |
2 | 2 | # |
3 | 3 | # This housekeeping shell script is installed as /etc/cron.daily/dwww. |
4 | 4 | # Cron automatically runs it once a day. |
11 | 11 | |
12 | 12 | set -e |
13 | 13 | |
14 | . /usr/share/dwww/functions.sh && dwww_initialize || exit 1 | |
15 | ||
16 | 14 | dwww-refresh-cache > /dev/null |
17 | 15 | dwww-build --default > /dev/null |
18 | 16 | dwww-build-menu > /dev/null |
0 | 0 | #!/bin/sh |
1 | # $Id: dwww.cron.weekly,v 1.1 2003-02-25 22:01:45 robert Exp $ | |
1 | # $Id: dwww.cron.weekly,v 1.2 2006-05-30 18:56:45 robert Exp $ | |
2 | 2 | # |
3 | 3 | # This script creates an index of Debian documentation registered |
4 | 4 | # with doc-base. See dwww-index++(8) man page for details. |
11 | 11 | |
12 | 12 | set -e |
13 | 13 | |
14 | . /usr/share/dwww/functions.sh && dwww_initialize || exit 1 | |
15 | ||
16 | 14 | dwww-index++ > /dev/null |
17 | 15 | |
18 | 16 | exit 0 |
0 | 0 | usr/share/man/man8/dwww.8 usr/share/man/man5/dwww.conf.5 |
1 | usr/share/dwww/mozilla-dwww.src usr/lib/mozilla-firefox/searchplugins/dwww.src | |
2 | usr/share/dwww/mozilla-dwww.gif usr/lib/mozilla-firefox/searchplugins/dwww.gif | |
1 | usr/share/dwww/mozilla-dwww.src usr/share/firefox/searchplugins/dwww.src | |
2 | usr/share/dwww/mozilla-dwww.gif usr/share/firefox/searchplugins/dwww.gif | |
3 | 3 | usr/share/dwww/mozilla-dwww.src usr/lib/mozilla/searchplugins/dwww.src |
4 | 4 | usr/share/dwww/mozilla-dwww.gif usr/lib/mozilla/searchplugins/dwww.gif |
0 | This is realpath, previously part of the dwww package, which is now maintained | |
1 | by Robert Luberda <robert@debian.org> | |
2 | Original author and first dwww maintainer is Lars Wirzenius <liw@iki.fi>. | |
3 | Former maintainer was Jim Pick <jim@jimpick.com>. | |
4 | ||
5 | dwww is free software. You may copy it according to the | |
6 | GNU General Public License, version 2. A copy of the license | |
7 | is not included, but you can get one from most FTP sites that | |
8 | have GNU software, for example, ftp.gnu.org. | |
9 | ||
10 | On a Debian GNU/Linux system, the GPL can be found as | |
11 | /usr/share/common-licenses/GPL . |
0 | 0 | #!/usr/bin/make -f |
1 | 1 | # Sample debian/rules that uses debhelper. |
2 | # This file is public domain software, originally written by Joey Hess. | |
3 | # | |
4 | # This version is for a multibinary package. It also allows you to build any | |
5 | # of the binary packages independantly, via binary-<package> targets. | |
2 | # This file is public domain software, originally written by Joey Hess. | |
6 | 3 | |
7 | # Uncomment this to turn on verbose mode. | |
4 | # Uncomment this to turn on verbose mode. | |
8 | 5 | #export DH_VERBOSE=1 |
9 | ||
10 | # This has to be exported to make some magic below work. | |
11 | export DH_OPTIONS | |
6 | prefix=$(CURDIR)/debian/$(shell dh_listpackages) | |
12 | 7 | |
13 | 8 | build: build-stamp |
14 | 9 | build-stamp: |
30 | 25 | |
31 | 26 | dh_clean |
32 | 27 | |
33 | install: DH_OPTIONS= | |
34 | 28 | install: build |
35 | 29 | dh_testdir |
36 | 30 | dh_testroot |
37 | 31 | dh_clean -k |
32 | dh_installdirs | |
38 | 33 | |
39 | dh_installdirs -p dwww -Pdebian/tmp | |
40 | dh_installdirs -p realpath -Pdebian/tmp | |
41 | dh_installdirs -p dwww -Pdebian/dwww | |
42 | dh_installdirs -p realpath -Pdebian/realpath | |
43 | ||
44 | # Add here commands to install the package into debian/tmp. | |
45 | $(MAKE) prefix=$(CURDIR)/debian/tmp install | |
46 | ||
47 | install -p -m 0644 debian/dwww.lintian \ | |
48 | $(CURDIR)/debian/tmp/usr/share/lintian/overrides/dwww | |
34 | # Add here commands to install the package into debian/dwww. | |
35 | $(MAKE) prefix=$(prefix) install | |
49 | 36 | |
50 | 37 | install -p -m 0644 apache.conf \ |
51 | $(CURDIR)/debian/tmp/etc/dwww/apache.conf | |
38 | $(prefix)/etc/dwww/apache.conf | |
39 | # Build architecture-independent files here. | |
40 | binary-indep: build install | |
41 | # We have nothing to do by default. | |
52 | 42 | |
53 | dh_install --sourcedir=debian/tmp -p realpath | |
54 | dh_install --sourcedir=debian/tmp -p dwww -X'realpath*' | |
55 | ||
56 | # This single target is used to build all the packages, all at once, or | |
57 | # one at a time. So keep in mind: any options passed to commands here will | |
58 | # affect _all_ packages. Anything you want to only affect one package | |
59 | # should be put in another target, such as the install target. | |
60 | binary-common: | |
43 | # Build architecture-dependent files here. | |
44 | binary-arch: build install | |
61 | 45 | dh_testdir |
62 | 46 | dh_testroot |
63 | 47 | dh_installchangelogs |
64 | 48 | dh_installdocs |
65 | 49 | # dh_installexamples |
50 | # dh_install | |
66 | 51 | dh_installmenu |
67 | 52 | dh_installdebconf |
68 | 53 | # dh_installlogrotate |
69 | 54 | # dh_installemacsen |
55 | # dh_installcatalogs | |
70 | 56 | # dh_installpam |
71 | 57 | # dh_installmime |
72 | 58 | # dh_installinit |
78 | 64 | dh_link |
79 | 65 | dh_compress |
80 | 66 | dh_fixperms |
67 | dh_perl | |
68 | # dh_python | |
81 | 69 | # dh_makeshlibs |
82 | 70 | dh_installdeb |
83 | dh_perl | |
84 | 71 | dh_shlibdeps |
85 | 72 | dh_gencontrol |
86 | 73 | dh_md5sums |
87 | 74 | dh_builddeb |
88 | 75 | |
89 | # Build architecture independant packages using the common target. | |
90 | binary-indep: build install | |
91 | # (Uncomment this next line if you have such packages.) | |
92 | # $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common | |
93 | ||
94 | # Build architecture dependant packages using the common target. | |
95 | binary-arch: build install | |
96 | $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common | |
97 | ||
98 | # Any other binary targets build just one binary package at a time. | |
99 | binary-%: build install | |
100 | make -f debian/rules binary-common DH_OPTIONS=-p$* | |
101 | ||
102 | 76 | binary: binary-indep binary-arch |
103 | 77 | .PHONY: build clean binary-indep binary-arch binary install |
11 | 11 | # <location> is full pathname to original document |
12 | 12 | # |
13 | 13 | # Part of the Debian dwww package. Written by Lars Wirzenius. |
14 | # Modified by Robert Luberda | |
15 | # "@(#)dwww:$Id: dwww-convert,v 1.43 2006-05-07 18:30:06 robert Exp $" | |
14 | # Modified by Robert Luberda. | |
15 | # "@(#)dwww:$Id: dwww-convert,v 1.45 2006-05-30 19:22:51 robert Exp $" | |
16 | 16 | |
17 | 17 | use strict; |
18 | 18 | |
25 | 25 | # |
26 | 26 | # Setup defaults. |
27 | 27 | # |
28 | my $DWWW_USEFILEURL=0; | |
29 | 28 | ################################################################ |
30 | 29 | # |
31 | 30 | # Initialization |
41 | 40 | my $template_dir_start = "$templates_dir/dwww-convert.dir.start"; |
42 | 41 | my $template_dir_end = "$templates_dir/dwww-convert.dir.end"; |
43 | 42 | my $dwww_use_cache = lc($dwwwvars->{'DWWW_USE_CACHE'}) eq "yes"; |
43 | my $dwww_usefileurl = lc($dwwwvars->{'DWWW_USEFILEURL'}) eq "yes"; | |
44 | 44 | |
45 | 45 | |
46 | 46 | |
60 | 60 | # Builtin convertFunctions |
61 | 61 | # |
62 | 62 | |
63 | sub OpenPipe() { | |
63 | sub OpenPipe() { # {{{ | |
64 | 64 | my $program = shift; |
65 | 65 | my $mode = shift; |
66 | 66 | |
79 | 79 | open($FH, $program) or die "Can't open pipe for $program: $!\n"; |
80 | 80 | |
81 | 81 | return $FH; |
82 | } | |
83 | ||
84 | ||
85 | sub ClosePipe() { | |
82 | } # }}} | |
83 | ||
84 | ||
85 | sub ClosePipe() { # {{{ | |
86 | 86 | my $FH = shift; |
87 | 87 | |
88 | 88 | # &fflush($FH) or die("Can't flush: $!"); |
89 | 89 | return if ($FH == \*STDIN || $FH == \*STDOUT); |
90 | 90 | close($FH) or die("Cannot close filehandle: $!\n"); |
91 | } | |
92 | ||
93 | ||
94 | sub DecompressFile() { | |
91 | } # }}} | |
92 | ||
93 | ||
94 | sub DecompressFile() { # {{{ | |
95 | 95 | my $filename = shift; |
96 | 96 | my $OUT_FH = shift; |
97 | 97 | my $add_filtr_prog = shift; |
132 | 132 | } |
133 | 133 | $/=$s; |
134 | 134 | &ClosePipe($IN_FH); |
135 | } | |
135 | } # }}} | |
136 | ||
136 | 137 | # |
137 | 138 | # Create a directory listing in HTML. |
138 | 139 | # |
185 | 186 | @filelist = sort(@filelist); |
186 | 187 | my $table = &BeginTable($OUT_FH, "", 3); |
187 | 188 | foreach $f (@filelist) { |
188 | if ($DWWW_USEFILEURL && $f =~ /\.htm*$/) { | |
189 | if ($dwww_usefileurl && ($f =~ /\.htm.*$/)) { | |
189 | 190 | &AddToTable($OUT_FH, $table, |
190 | "<a href=\"file://localhost" . &URLEncode($f) . "\">" . &HTMLEncode($f) . "</a>"); | |
191 | "<a href=\"file://localhost/" . $url_dir . '/' . &URLEncode($f) . "\">" . &HTMLEncode($f) . "</a>"); | |
191 | 192 | } else { |
192 | 193 | &AddToTable($OUT_FH, $table, |
193 | 194 | "<a href=\"" . &URLEncode($f) . "\">" . &HTMLEncode($f) . "</a>"); |
200 | 201 | @dirlist = sort(@dirlist); |
201 | 202 | my $table = &BeginTable($OUT_FH, "<FONT SIZE=\"+2\">Subdirectories:</FONT>", 3); |
202 | 203 | foreach $f (@dirlist) { |
203 | &AddToTable($OUT_FH, $table, | |
204 | "<a href=\"" .&URLEncode($f) ."/" | |
205 | . "\">" . &HTMLEncode($f) . "</a>"); | |
206 | ||
207 | ### TODO ### case "$i" in | |
208 | ### TODO ### *.htm*) | |
209 | ### TODO ### if [ -n "$DWWW_USEFILEURL" ] ; then | |
210 | ### TODO ### echo "<a href=\"file://localhost$j\">$i</a>" | |
211 | ### TODO ### else | |
212 | ### TODO ### echo "<a href=\"/cgi-bin/dwww?type=file&location=$j\">$i</a>" | |
213 | ### TODO ### fi | |
214 | ### TODO ### ;; | |
215 | ### TODO ### *) | |
216 | ### TODO ### echo "<a href=\"/cgi-bin/dwww?type=file&location=$j\">$i</a>" | |
217 | ### TODO ### ;; | |
218 | ||
204 | if ($dwww_usefileurl && defined (my $g = &GuessFileName("$dir/$f/index", 1 ))) { | |
205 | &AddToTable($OUT_FH, $table, | |
206 | "<a href=\"file://localhost" . &URLEncode($g) . | |
207 | "\">" . &HTMLEncode($f) . "</a>"); | |
208 | } else { | |
209 | &AddToTable($OUT_FH, $table, | |
210 | "<a href=\"" .&URLEncode($f) | |
211 | . "/?type=dir\">" . &HTMLEncode($f) . "</a>"); | |
212 | } | |
219 | 213 | } |
220 | 214 | &EndTable($OUT_FH, $table); |
221 | 215 | } |
261 | 255 | # Convert plain text to HTML. This is really trivial, and buggy. |
262 | 256 | # Input from stdin. |
263 | 257 | # |
264 | sub BuiltinText2Html() { | |
258 | sub BuiltinText2Html() { # {{{ | |
265 | 259 | my $filename = shift; |
266 | 260 | my $cacheProg = shift; |
267 | 261 | |
276 | 270 | |
277 | 271 | print $OUT_FH &TemplateFile($template_end, { }) or die "Can't print\n"; |
278 | 272 | &ClosePipe($OUT_FH); |
279 | } | |
273 | } # }}} | |
280 | 274 | |
281 | 275 | # |
282 | 276 | # Convert info file to HTML using info2www |
283 | 277 | # |
284 | sub BuiltinInfo2Html() { | |
278 | sub BuiltinInfo2Html() { # {{{ | |
285 | 279 | my $filename = shift; |
286 | 280 | my $cacheProg = shift; |
287 | 281 | |
288 | 282 | my $cachePipe = defined $cacheProg ? " | $cacheProg" : ""; |
289 | 283 | system("/usr/lib/cgi-bin/info2www \"$filename\"" . $cachePipe); |
290 | } | |
291 | ||
292 | ||
293 | #### | |
294 | #### Convert links in an HTML and CSS documents, to be able to use the automatic | |
295 | #### decompression and conversion features. | |
296 | #### | |
297 | #### Usage: convert_html_anchors file "html"/"css" | |
298 | #### | |
299 | ###sub ConvertHtmlAnchors() { | |
300 | ### | |
301 | #### The procedure below was written by Daniel Martin <martin@snowplow.org> | |
302 | #### See bug #151637 for more info, how it works... | |
303 | ### | |
304 | ### | |
305 | ###my $file = shift; | |
306 | ###my $type = shift | |
307 | ### | |
308 | ###($directory = $file) =~ s/^[^\/]*(\/.*\/)[^\/]*$/$1/; | |
309 | ### | |
310 | ###if ($type eq "css") { | |
311 | ### $cgi = "/cgi-bin/dwww?type=file&location="; | |
312 | ###} else { | |
313 | ### $cgi = "/cgi-bin/dwww?type=file&location="; | |
314 | ###} | |
315 | ### | |
316 | ###if ($type eq "css") { | |
317 | ### | |
318 | ### s/(url\s*\(\s*)(["'\'']?)([^)\2]+)\2(\s*\))/$1.$2.mangle_anchor($3).$2.$4/ges; | |
319 | ### | |
320 | ###} else { | |
321 | ### | |
322 | ### handle_simple_tag(qw(a href)); | |
323 | ### handle_simple_tag(qw(link href)); | |
324 | ### | |
325 | ### handle_simple_tag(qw(img src)); | |
326 | ### handle_simple_tag(qw(frame src)); | |
327 | ### | |
328 | ### handle_simple_tag(qw(body background)); | |
329 | ### | |
330 | ### # Meta tags need their own sub since the matching is a little different | |
331 | ### s/<META\s+[^>]*>/transform_meta_tag($&)/iges; | |
332 | ### | |
333 | ### handle_simple_tag(qw(applet archive)); | |
334 | ### | |
335 | ###} | |
336 | ### | |
337 | ###} | |
338 | ### | |
339 | ###sub make_cgi_ref { | |
340 | ### my($target) = shift; | |
341 | ### # technically, according to rfc 2396, s. 3.4, we should also escape /, | |
342 | ### # but for our uses it does not matter and it significantly uglifies our URLs | |
343 | ### $target =~ s/[^\w_.!~\/\-]/sprintf("%%%02X",unpack("C",$&))/ge; | |
344 | ### return ($cgi . $target); | |
345 | ###} | |
346 | ### | |
347 | ###sub mangle_anchor { | |
348 | ### my($anchortext) = shift; | |
349 | ### # We do not deal with anything that starts with /cgi-bin/ | |
350 | ### if ($anchortext =~ m|^/cgi-bin/|) {return $anchortext;} | |
351 | ### # We do not deal with anything that includes a protocol or query | |
352 | ### if ($anchortext =~ /[:?]/) {return $anchortext;} | |
353 | ### # first undo html escaping | |
354 | ### $anchortext =~ s/^\s*//; | |
355 | ### $anchortext =~ s/\</</g; | |
356 | ### $anchortext =~ s/\>/>/g; | |
357 | ### $anchortext =~ s/\&(amp|(#x?)([a-fA-F\d]+));/($1 eq "amp")?"&":pack("C",($2 eq "#x")?hex($3):$3)/ge; | |
358 | ### # Now it is safe to pull of the partial fragment | |
359 | ### my ($partial) = ""; | |
360 | ### if ($anchortext =~ s/(#.*)//) {$partial=$1;} | |
361 | ### # now undo URI escaping | |
362 | ### $anchortext =~ s/%([a-fA-F\d]{2})/pack("C",hex($1))/ge; | |
363 | ### # re-html-encode potentially unsafe characters in partial. | |
364 | ### # shouldnt happen, but... | |
365 | ### if ($partial =~ s/^#//) { | |
366 | ### $partial =~ s/[<>&'\''"]/"&".unpack("C",$&).";"/ge; | |
367 | ### $partial = "#" . $partial; | |
368 | ### } | |
369 | ### # now... | |
370 | ### if (!$anchortext) {return $partial;} | |
371 | ### if ($anchortext =~ m[^/]) { | |
372 | ### return (make_cgi_ref($anchortext) . $partial); | |
373 | ### } else { | |
374 | ### return (make_cgi_ref($directory . $anchortext) . $partial); | |
375 | ### } | |
376 | ###} | |
377 | ### | |
378 | ###sub handle_simple_tag { | |
379 | ### # handle the substitution | |
380 | ### my($tag,$attr) = @_; | |
381 | ### # quoted | |
382 | ### s/(<\s*$tag[^>]*\s+$attr\s*=\s*)(["'\''])([^>\2]*?)(\2[^>]*>)/$1.$2.mangle_anchor($3).$4/iges; | |
383 | ### s/(<\s*$tag[^>]*\s+$attr\s*=\s*)([^\s"'\''][^>\s]*)(.*?>)/$1.mangle_anchor($2).$3/iegs; | |
384 | ###} | |
385 | ### | |
386 | ###sub transform_meta_tag { | |
387 | ### my($metatext) = shift; | |
388 | ### if ($metatext =~ m/equiv\s*=\s*["'\'']?refresh/is) { | |
389 | ### $metatext =~ s/(URL\s*=\s*)([^>:\s"]*)/$1.mangle_anchor($2)/ies; | |
390 | ### } | |
391 | ### return($metatext); | |
392 | ###} | |
393 | ||
394 | ||
395 | # | |
396 | # Convert links in an HTML documents | |
397 | # | |
398 | ||
399 | ###sub Builtin_Html2Html() { | |
400 | ### my $file = shift; | |
401 | ### my $convertFunction = shift; | |
402 | ### my $output = shift; | |
403 | ### | |
404 | #### my $input = &OpenconvertFunction( $convertFunction, $file ); | |
405 | #### while read (<\$input>) | |
406 | ### | |
407 | #### convert_html_anchors "$1" "html" | |
408 | #### print "<!-- Generated by dwww $dwww_version on $DATE -->" | |
409 | #### exit 0 | |
410 | ### | |
411 | ### | |
412 | ###} | |
413 | ### | |
414 | # | |
415 | # Convert links inside CSS url() function | |
416 | # | |
417 | ||
418 | ###BuiltinCss2Css() { | |
419 | ### | |
420 | ### convert_html_anchors "$1" "css" | |
421 | ### echo "/* Generated by dwww $dwww_version on $DATE */" | |
422 | ### exit 0 | |
423 | ### | |
424 | ###} | |
425 | ||
426 | sub GuessFileName() { | |
284 | } # }}} | |
285 | ||
286 | ||
287 | sub GuessFileName() { # {{{ | |
427 | 288 | my $basefile = shift; |
428 | 289 | my $is_html = shift; |
429 | 290 | |
441 | 302 | } |
442 | 303 | } |
443 | 304 | return undef; |
444 | } | |
445 | ||
446 | ||
447 | ||
448 | sub PrintHeaders() { | |
305 | } # }}} | |
306 | ||
307 | ||
308 | ||
309 | sub PrintHeaders() { # {{{ | |
449 | 310 | my $filename = shift; |
450 | 311 | my $base_name = shift; |
451 | 312 | my $mime_type = shift; |
457 | 318 | print "Last modified: " . gmtime($mtime) . "\n"; |
458 | 319 | print "Content-Disposition: inline; filename=\"$base_name\"\n"; |
459 | 320 | print "\n"; |
460 | } | |
321 | } # }}} | |
461 | 322 | |
462 | 323 | |
463 | 324 | ################################################################ |
1 | 1 | # vim:ft=perl:cindent:ts=8:et:fdm=marker:cms=\ #\ %s |
2 | 2 | # |
3 | 3 | # Find all docs related to one program or find matching entries in Debian Doc. Menu |
4 | # "$Id: dwww-find,v 1.47 2006-05-07 18:30:06 robert Exp $" | |
4 | # "$Id: dwww-find,v 1.48 2006-05-30 18:56:29 robert Exp $" | |
5 | 5 | # |
6 | 6 | |
7 | 7 | use strict; |
366 | 366 | $base =~ s/\.(gz|bz2)$//; |
367 | 367 | my $debian = ($base =~ s/\.Debian$//) ? "Debian " : ""; |
368 | 368 | next unless ( -f $_); |
369 | for ( my $i = 0; $i < $#basicdocs; $i++) { | |
369 | for ( my $i = 0; $i <= $#basicdocs; $i++) { | |
370 | 370 | if ($basicdocs[$i] eq $base) { |
371 | 371 | $docs{$debian . $base} = $_; |
372 | 372 | last; |
0 | .\" $Id: realpath.1,v 1.10 2006-01-14 11:06:27 robert Exp $ | |
1 | .TH REALPATH 1 "January 14th, 2006" "Debian" "Debian" | |
2 | .SH NAME | |
3 | realpath \- return the canonicalised absolute pathname | |
4 | .SH SYNOPSIS | |
5 | .B realpath | |
6 | .RB [ \-s | \-\-strip ] | |
7 | .RB [ \-z | \-\-zero ] | |
8 | .I " filename " ... | |
9 | .br | |
10 | .B realpath | |
11 | .BR \-\-h | \-\-help | |
12 | .br | |
13 | .B realpath | |
14 | .BR \-\-v | \-\-version | |
15 | .SH "DESCRIPTION" | |
16 | .B realpath | |
17 | converts each | |
18 | .I filename | |
19 | argument to an absolute pathname, which has no | |
20 | components that are symbolic links or the special | |
21 | .B . | |
22 | or | |
23 | .B .. | |
24 | directory entries. | |
25 | (See | |
26 | .BR realpath (3) | |
27 | for more information.) | |
28 | .br | |
29 | Please note that mostly the same functionality is provided by the `-f' option | |
30 | of the | |
31 | .BR readlink (1) | |
32 | command. | |
33 | .PP | |
34 | If option | |
35 | .B \-s | |
36 | is used | |
37 | .B realpath | |
38 | only removes | |
39 | .B . | |
40 | and | |
41 | .B .. | |
42 | directories, but not symbolic links from | |
43 | .IR filename . | |
44 | .PP | |
45 | Each converted pathname is output to the standard output, | |
46 | on its own line. | |
47 | .SH OPTIONS | |
48 | .TP 5 | |
49 | .BR \-s , \-\-strip | |
50 | Only strip | |
51 | .B . | |
52 | and | |
53 | .BR .. , | |
54 | but do not resolve symbolic links. | |
55 | .\" | |
56 | .TP 5 | |
57 | .BR \-z , \-\-zero | |
58 | Separate output filenames with the null character instead of newline, | |
59 | so it can be used with the | |
60 | .RI ` \-0 ' | |
61 | option of | |
62 | .BR xargs (1). | |
63 | .\" | |
64 | .TP 5 | |
65 | .BR \-h , \-\-help | |
66 | Print short usage information. | |
67 | .\" | |
68 | .TP 5 | |
69 | .BR \-v , \-\-version | |
70 | Show | |
71 | .BR realpath 's | |
72 | version number. | |
73 | .SH EXAMPLES | |
74 | .br | |
75 | Let's suppose that | |
76 | .I /usr/bin/X11 | |
77 | is a symbolic link, which points to directory | |
78 | .IR /usr/X11R6/bin . | |
79 | .br | |
80 | Than | |
81 | .br | |
82 | .RS | |
83 | .I realpath /../usr/bin/X11/./xterm | |
84 | .RE | |
85 | prints | |
86 | .RS | |
87 | /usr/X11R6/bin/xterm | |
88 | .RE | |
89 | but | |
90 | .RS | |
91 | .I realpath | |
92 | .BI "\-s " /../usr/bin/X11/./xterm | |
93 | .RE | |
94 | outputs | |
95 | .RS | |
96 | /usr/bin/X11/xterm | |
97 | .RE | |
98 | .SH EXIT STATUS | |
99 | .B realpath | |
100 | returns a zero exit code when | |
101 | .I all | |
102 | pathnames was successfully converted. | |
103 | .br | |
104 | In case of any errors (e.g. missing or unavailable directories in the path), | |
105 | .B realpath | |
106 | prints error message to stderr and returns a non-zero exit code. | |
107 | .RE | |
108 | .SH "SEE ALSO" | |
109 | .BR basename (1), | |
110 | .BR dirname (1), | |
111 | .BR readlink (1), | |
112 | .BR realpath (3) | |
113 | .SH AUTHOR | |
114 | Lars Wirzenius <liw@iki.fi>, as part of the dwww package. | |
115 | .br | |
116 | Modified by Robert Luberda <robert@debian.org>. |
0 | # vim:ft=perl:cindent:ts=4:sw=4:et:fdm=marker:cms=\ #\ %s | |
1 | # | |
2 | # $Id: Common.pm,v 1.2 2006-05-07 18:30:08 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::Common; | |
5 | ||
6 | use Exporter(); | |
7 | use strict; | |
8 | ||
9 | use Debian::Dwww::Utils; | |
10 | use vars qw(@ISA @EXPORT); | |
11 | @ISA = qw(Exporter); | |
12 | @EXPORT = qw(GetURL); | |
13 | ||
14 | ||
15 | my $dwww_url = "/cgi-bin/dwww"; | |
16 | my %href = # {{{ | |
17 | ( | |
18 | 'debiandoc-sgml'=> "$dwww_url#FILE#?type=application/sgml", | |
19 | 'docbook-xml' => "$dwww_url#FILE#?type=text/xml", | |
20 | 'dvi' => "$dwww_url#FILE#?type=application/x-dvi", | |
21 | 'html' => "$dwww_url#FILE#?type=html", | |
22 | 'info' => "/cgi-bin/info2www?file=", | |
23 | 'latex' => "$dwww_url#FILE#?type=application/x-latex", | |
24 | 'linuxdoc-sgml' => "$dwww_url#FILE#?type=application/sgml", | |
25 | 'pdf' => "$dwww_url#FILE#?type=application/pdf", | |
26 | 'postscript' => "$dwww_url#FILE#?type=application/postscript", | |
27 | 'ps' => "$dwww_url#FILE#?type=application/postscriptps", | |
28 | 'rtf' => "$dwww_url#FILE#?type=text/rtf", | |
29 | 'sgml' => "$dwww_url#FILE#?type=application/sgml", | |
30 | 'tar' => "$dwww_url#FILE#?type=application/tar", | |
31 | 'texinfo' => "$dwww_url#FILE#?type=application/x-texinfo", | |
32 | 'dwww-url' => "", | |
33 | 'text' => "$dwww_url#FILE#?type=text/plain", | |
34 | 'pkgsearch' => "$dwww_url?search=", | |
35 | 'man' => '/cgi-bin/dwww#FILE#?type=man', | |
36 | 'runman' => '/cgi-bin/dwww?type=runman&location=', | |
37 | 'dir' => '/cgi-bin/dwww#FILE#/?type=dir', | |
38 | 'info' => '/cgi-bin/info2www?file=', | |
39 | 'file' => '/cgi-bin/dwww', | |
40 | 'menu' => '/dwww/menu/', | |
41 | 'search' => '/cgi-bin/dwww?search=', | |
42 | 'dpkg' => '/cgi-bin/dpkg?query=' | |
43 | ); # }}} | |
44 | ||
45 | sub GetURL{ # {{{ | |
46 | my $format_name = shift; | |
47 | my $format_url = shift; | |
48 | my $dont_encode = shift; | |
49 | $dont_encode = $FALSE unless defined $dont_encode; | |
50 | ||
51 | ||
52 | $format_url = &URLEncode($format_url) unless ($dont_encode || $format_name eq 'dwww-url'); | |
53 | ||
54 | if ($href{$format_name} =~ /#FILE#/) { | |
55 | return $` . $format_url . $'; | |
56 | } else { | |
57 | return $href{$format_name} . $format_url; | |
58 | } | |
59 | ||
60 | ||
61 | } # }}} | |
62 | ||
63 | 1; |
0 | # vim:ft=perl:cindent | |
1 | # | |
2 | # $Id: DocBase.pm,v 1.5 2003-05-16 17:22:33 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::DocBase; | |
5 | ||
6 | use Exporter(); | |
7 | use Debian::Dwww::Version; | |
8 | use strict; | |
9 | ||
10 | use vars qw(@ISA @EXPORT $ErrorProc); | |
11 | @ISA = qw(Exporter); | |
12 | @EXPORT = qw(ParseDocBaseFile DwwwSection2Section $ErrorProc); | |
13 | ||
14 | ||
15 | ||
16 | sub ParseDocBaseFile { | |
17 | my $file = shift; | |
18 | my $format = undef; | |
19 | my $entry = {}; | |
20 | my ($fld, $val, $lastfld) = ('', '', ''); | |
21 | my $line = 0; | |
22 | local $_; | |
23 | ||
24 | if (not open DOCFILE, $file) { | |
25 | &$ErrorProc($file, "Can't be opened: $!"); | |
26 | return undef; | |
27 | } | |
28 | ||
29 | while (<DOCFILE>) { | |
30 | chomp; | |
31 | s/\s+$//; | |
32 | $line++; | |
33 | if (/^\s*$/) { | |
34 | # empty lines separate sections | |
35 | $format = ''; # here we define $format | |
36 | $lastfld = ''; | |
37 | } elsif (/^(\S+)\s*:\s*(.*)\s*$/) { | |
38 | ($fld, $val) = (lc $1, $2); | |
39 | ||
40 | ||
41 | if (not defined $format) { | |
42 | $entry->{$fld} = $val; | |
43 | } elsif ($format eq '' and $fld eq 'format') { | |
44 | $format = lc $val; | |
45 | } elsif ($format ne '' and $fld eq 'index') { | |
46 | $entry->{'formats'}->{$format}->{'index'} = $val; | |
47 | } elsif ($format ne '' and $fld eq 'files') { | |
48 | $entry->{'formats'}->{$format}->{'files'} = $val; | |
49 | } else { | |
50 | goto PARSE_ERROR; | |
51 | } | |
52 | $lastfld = $fld; | |
53 | } elsif (/^\s+/ and $lastfld ne '') { | |
54 | $entry->{$lastfld} .= "\n$_"; | |
55 | } else { | |
56 | goto PARSE_ERROR; | |
57 | } | |
58 | } | |
59 | ||
60 | close DOCFILE; | |
61 | ||
62 | return $entry; | |
63 | ||
64 | ||
65 | PARSE_ERROR: | |
66 | &$ErrorProc($file, "Parse error at line $line"); | |
67 | close DOCFILE; | |
68 | return undef; | |
69 | } | |
70 | ||
71 | ||
72 | sub DwwwSection2Section { | |
73 | my $entry = shift; | |
74 | ||
75 | my $sec = $entry->{'dwww-section'} if defined $entry->{'dwww-section'}; | |
76 | my $title = defined $entry->{'dwww-title'} ? $entry->{'dwww-title'} : | |
77 | defined $entry->{'title'} ? $entry->{'title'} : undef; | |
78 | ||
79 | return unless defined $sec and defined $title; | |
80 | ||
81 | if (length($sec) > length($title) && | |
82 | substr ($sec, -length($title)) eq $title) { | |
83 | $sec = substr ($sec, 0, -length($title)); | |
84 | } else { | |
85 | return; | |
86 | } | |
87 | ||
88 | $sec =~ s|^/+||; | |
89 | $sec =~ s|/+$||; | |
90 | $entry->{'section'} = $sec; | |
91 | ||
92 | } | |
93 | ||
94 | ||
95 | 1; |
0 | # vim:ft=perl:cindent:ts=4:sw=4:et:fdm=marker:cms=\ #\ %s | |
1 | # | |
2 | # $Id: Initialize.pm,v 1.10 2006-05-07 18:30:08 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::Initialize; | |
5 | ||
6 | use Exporter(); | |
7 | use Sys::Hostname; | |
8 | use strict; | |
9 | ||
10 | use vars qw(@ISA @EXPORT); | |
11 | @ISA = qw(Exporter); | |
12 | @EXPORT = qw(DwwwInitialize DwwwSetupDirs); | |
13 | ||
14 | sub DwwwInitialize() { | |
15 | my $filename = shift; | |
16 | my $hostname = &hostname(); | |
17 | $hostname =~ s/\..*$//; | |
18 | my $dwwwvars = { | |
19 | 'DWWW_DOCPATH' => "/usr/share/doc:/usr/doc:/usr/share/info:/usr/info:" | |
20 | . "/usr/share/man:/usr/man:/usr/X11R6/man:/usr/local/man:" | |
21 | . "/usr/local/doc:/usr/local/info:/usr/share/common-licenses", | |
22 | 'DWWW_ALLOWEDLINKPATH' => "/usr/share:/usr/lib:/var/www", | |
23 | 'DWWW_TMPDIR' => "/var/lib/dwww", | |
24 | 'DWWW_HTMLDIR' => "/var/lib/dwww/html", | |
25 | 'DWWW_USE_CACHE' => "yes", | |
26 | 'DWWW_KEEPDAYS' => 10, | |
27 | 'DWWW_QUICKFIND_DB' => "/var/cache/dwww/quickfind.dat", | |
28 | 'DWWW_REGDOCS_DB' => "/var/cache/dwww/regdocs.dat", | |
29 | 'DWWW_DOCBASE2PKG_DB' => "/var/cache/dwww/docbase2pkg.dat", | |
30 | 'DWWW_TITLE' => 'dwww: ' . $hostname, | |
31 | 'DWWW_DOCROOTDIR' => '/var/www', | |
32 | 'DWWW_CGIDIR' => '/usr/lib/cgi-bin', | |
33 | 'DWWW_CGIUSER' => 'www-data', | |
34 | 'DWWW_SERVERNAME' => 'localhost', | |
35 | 'DWWW_SERVERPORT' => 80 | |
36 | ||
37 | }; | |
38 | ||
39 | umask (022); | |
40 | $ENV{'PATH'} = "/usr/sbin:/usr/bin:$ENV{'PATH'}"; | |
41 | ||
42 | return $dwwwvars unless defined $filename; | |
43 | return $dwwwvars unless -r $filename; | |
44 | ||
45 | open DWWWCONF, "<$filename" or die "Can't open $filename: $!\n"; | |
46 | while (<DWWWCONF>) { | |
47 | chomp(); | |
48 | if (m/^\s*([^=]+)\s*=\s*(\S+)\s*$/) { | |
49 | $dwwwvars->{$1} = $2; | |
50 | } | |
51 | } | |
52 | close DWWWCONF or die "Can't close $filename: $!\n"; | |
53 | foreach my $k ( 'DWWW_DOCPATH', 'DWWW_ALLOWEDLINKPATH' ) { | |
54 | my @paths = split( /:/, $dwwwvars->{$k} ); | |
55 | $dwwwvars->{$k} = \@paths; | |
56 | } | |
57 | ||
58 | return $dwwwvars; | |
59 | } | |
60 | ||
61 | sub DwwwSetupDirs() { | |
62 | my $dwwwvars = shift; | |
63 | ||
64 | my $dir = "/var/cache/dwww"; | |
65 | if ( ! -d "$dir" ) { | |
66 | mkdir "$dir", 0755 or die "Cannot create directory $dir"; | |
67 | chown 0, 0, "$dir" | |
68 | } | |
69 | if ( ! -d "$dir/db" ) { | |
70 | mkdir "$dir/db", 0755 or die "Cannot create directory $dir/db"; | |
71 | my $uid = (getpwnam("$dwwwvars->{'DWWW_CGIUSER'}"))[2] or die "User $dwwwvars->{'DWWW_CGIUSER'} does not exist\n"; | |
72 | chown $uid, 0, "$dir/db"; | |
73 | } | |
74 | } | |
75 | 1; |
0 | # vim:ft=perl:cindent:ts=4:sw=4:et:fdm=marker:cms=\ #\ %s | |
1 | # | |
2 | # $Id: Utils.pm,v 1.9 2006-05-07 18:30:08 robert Exp $ | |
3 | # | |
4 | package Debian::Dwww::Utils; | |
5 | ||
6 | use Exporter(); | |
7 | use Debian::Dwww::Version; | |
8 | use Cwd qw(cwd realpath); | |
9 | use POSIX qw(strftime locale_h); | |
10 | use File::Path qw/rmtree mkpath/; | |
11 | use File::NCopy qw/copy/; | |
12 | ||
13 | use strict; | |
14 | ||
15 | use vars qw(@ISA @EXPORT); | |
16 | @ISA = qw(Exporter); | |
17 | @EXPORT = qw(URLEncode HTMLEncode HTMLEncodeAbstract StripDirs CheckAccess RedirectToURL ErrorMsg | |
18 | TemplateFile BeginTable AddToTable EndTable GetCommandOutput RenameDir $TRUE $FALSE); | |
19 | ||
20 | our $TRUE = 1; | |
21 | our $FALSE = 0; | |
22 | ||
23 | sub URLEncode { | |
24 | my $url = shift; | |
25 | $url =~ s/([^A-Za-z0-9\_\-\.\/])/"%" . unpack("H*", $1)/eg; | |
26 | # $url =~ tr/ /+/; | |
27 | return $url; | |
28 | } | |
29 | ||
30 | # HTMLEncode(what) | |
31 | sub HTMLEncode { # {{{ | |
32 | my $text = shift; | |
33 | ||
34 | ||
35 | $text =~ s/&/&/g; | |
36 | $text =~ s/</</g; | |
37 | $text =~ s/>/>/g; | |
38 | $text =~ s/"/"/g; | |
39 | return $text; | |
40 | } # }}} | |
41 | ||
42 | sub HTMLEncodeAbstract { # {{{ | |
43 | my $text = &HTMLEncode(@_); | |
44 | ||
45 | $text =~ s/^\s\s+(.*)$/<BR><TT> $1<\/TT><BR>/gm; | |
46 | $text =~ s/^\s\.\s*$/<BR>/gm; | |
47 | $text =~ s/(<BR>\s*)+/<BR>\n/g; | |
48 | $text =~ s/(http|ftp)s?:\/([\w\/~\.%#-])+[\w\/]/<A href="$&">$&<\/A>/g; | |
49 | $text =~ s/<BR>\s*$//; | |
50 | return $text; | |
51 | } # }}} | |
52 | ||
53 | sub GetDate { # {{{ | |
54 | my $old_locale = &setlocale(LC_ALL, "C"); | |
55 | my $date = &strftime ("%a %b %e %H:%M:%S %Z %Y", localtime(time)); | |
56 | &setlocale(LC_ALL, $old_locale) unless $old_locale eq "C"; | |
57 | return $date; | |
58 | } # }}} | |
59 | ||
60 | ||
61 | sub TemplateFile { # {{{ | |
62 | my $file= shift; | |
63 | my $vars= shift; # hash reference | |
64 | my $res = ''; | |
65 | local $_; | |
66 | ||
67 | ||
68 | open TEMPLATE , "<$file" or die "Can't open $file: $!"; | |
69 | while (<TEMPLATE>) { | |
70 | foreach my $k (keys %{$vars}) { | |
71 | s/\%$k\%/$vars->{$k}/g | |
72 | } | |
73 | s/\%VERSION\%/$Debian::Dwww::Version::version/o; | |
74 | s/\%DATE\%/&GetDate()/eg; | |
75 | $res .= $_; | |
76 | } | |
77 | ||
78 | close TEMPLATE; | |
79 | return $res; | |
80 | } # }}} | |
81 | ||
82 | ||
83 | sub BeginTable { # {{{ | |
84 | my $filehandle = shift; | |
85 | my $caption = shift; | |
86 | my $columns = shift; | |
87 | my $desc = shift; | |
88 | my $widths = shift; | |
89 | my $table = {}; | |
90 | ||
91 | $desc = '' unless (defined $desc); | |
92 | ||
93 | $table->{'columns'} = $columns + 0; | |
94 | $table->{'widths'} = $widths; | |
95 | $table->{'in_column'} = 0; | |
96 | $table->{'in_row'} = 0; | |
97 | ||
98 | print $filehandle "<P align=\"left\">\n"; | |
99 | print $filehandle "<STRONG>$caption</STRONG>$desc\n"; | |
100 | print $filehandle "<TABLE border=\"0\" width=\"98%\" align=\"center\">\n"; | |
101 | return $table; | |
102 | } # }}} | |
103 | ||
104 | sub AddToTable { # {{{ | |
105 | my $filehandle = shift; | |
106 | my $table = shift; | |
107 | my $what = shift; | |
108 | my ($wdth, $c, $r); | |
109 | ||
110 | $c = $table->{'in_column'}; | |
111 | $r = $table->{'in_row'}; | |
112 | ||
113 | ||
114 | if ($c == 0) { | |
115 | print $filehandle "<TR>\n" | |
116 | } | |
117 | ||
118 | if ($r == 0 && $c + 1 < $table->{'columns'}) { | |
119 | if (defined $table->{'widths'}) { | |
120 | $wdth = ' width="' . $table->{'widths'}[int($c)] .'%"'; | |
121 | } else { | |
122 | $wdth = ' width="' . int(100 / $table->{'columns'}) . '%"'; | |
123 | } | |
124 | } else { | |
125 | $wdth = ''; | |
126 | } | |
127 | ||
128 | print $filehandle "<TD align=\"left\"$wdth>$what</TD>\n"; | |
129 | ||
130 | if (++$c >= $table->{'columns'}) { | |
131 | print $filehandle "</TR>\n"; | |
132 | $c = 0; | |
133 | $r++; | |
134 | } | |
135 | $table->{'in_column'} = $c; | |
136 | $table->{'in_row'} = $r; | |
137 | } # }}} | |
138 | ||
139 | ||
140 | sub EndTable { # {{{ | |
141 | my $filehandle = shift; | |
142 | my $table = shift; | |
143 | ||
144 | while ($table->{'in_column'} != 0) { | |
145 | &AddToTable($filehandle, $table, ''); | |
146 | } | |
147 | print $filehandle "</TABLE>\n"; | |
148 | ||
149 | undef %{$table}; | |
150 | } # }}} | |
151 | ||
152 | # strips any '.' and '..' components from path | |
153 | sub StripDirs { # {{{ | |
154 | my $path = shift; | |
155 | ||
156 | ||
157 | $path = &cwd() . '/' . $path unless $path =~ /^\//; | |
158 | ||
159 | my @pc = split(/\/+/, $path); | |
160 | my @res = (); | |
161 | ||
162 | foreach my $p (@pc) { | |
163 | next if $p eq '.' || $p eq ''; | |
164 | pop(@res), next if $p eq '..'; | |
165 | push(@res, $p); | |
166 | } | |
167 | my $r = '/' . join ('/', @res); | |
168 | return $r; | |
169 | ||
170 | } # }}} | |
171 | ||
172 | # | |
173 | # Print error message and exit the program | |
174 | # usage: ErrorMsg status title message | |
175 | sub ErrorMsg { # {{{ | |
176 | my $status = shift; | |
177 | my $title = shift; | |
178 | my $message = shift; | |
179 | ||
180 | print "Status: $status\n"; | |
181 | print "Content-type: text/html; charset=iso-8895-1\n"; | |
182 | print "\n"; | |
183 | print "<HTML>\n"; | |
184 | print "<HEAD>\n"; | |
185 | print " <TITLE>$title</TITLE>\n"; | |
186 | print "</HEAD>"; | |
187 | print "<BODY>"; | |
188 | print " <H1 align=\"center\">$title</H1>\n"; | |
189 | print "$message\n"; | |
190 | print "</BODY>\n"; | |
191 | print "</HTML>\n"; | |
192 | exit 1; | |
193 | } # }}} | |
194 | ||
195 | ||
196 | # returns output of realpath($file) | |
197 | sub CheckAccess() { # {{{ | |
198 | my $dwwwvars = shift; | |
199 | my $file = shift; | |
200 | my $orig_file = shift; | |
201 | $orig_file = $file unless defined $orig_file; | |
202 | ||
203 | my $dwww_docpath = $dwwwvars->{'DWWW_DOCPATH'}; | |
204 | my $dwww_allowedlinkpath = $dwwwvars->{'DWWW_ALLOWEDLINKPATH'}; | |
205 | ||
206 | ||
207 | my $can_read_f = -r $file; | |
208 | my $exists_f = $can_read_f || -f $file; | |
209 | my $realp_file = undef; | |
210 | ||
211 | ||
212 | if ( $exists_f ) { | |
213 | $realp_file = &realpath( $file ); | |
214 | ||
215 | # file does exist, check if it match any files in @dwww_docpath | |
216 | foreach my $path (@$dwww_docpath) { | |
217 | if ( -d $path ) { | |
218 | $path = &realpath( $path ); | |
219 | if (substr($realp_file, 0, length($path)) eq $path) { | |
220 | &ErrorMsg( "403 Access Denied", | |
221 | "Access Denied", | |
222 | "The $orig_file is not readable!" ) unless $can_read_f; | |
223 | return $realp_file; # everything OK | |
224 | } | |
225 | } | |
226 | } | |
227 | } | |
228 | ||
229 | # if we're here, the file either does not exist | |
230 | # or does not match any @dwww_docpath | |
231 | my $ok = 0; | |
232 | my $strip_file = &StripDirs( $file ); | |
233 | foreach my $path (@$dwww_docpath) { | |
234 | if ( -d $path ) { | |
235 | $path = &StripDirs( $path ); | |
236 | if (substr($strip_file, 0, length($path)) eq $path) { | |
237 | $ok = 1; | |
238 | last; | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | ||
244 | # if file exists, check if it's in allowed_linkpath | |
245 | if ( $exists_f && $ok ) { | |
246 | foreach my $path (@$dwww_allowedlinkpath) { | |
247 | if ( -d $path ) { | |
248 | $path = &realpath( $path ); | |
249 | if (substr($realp_file, 0, length($path)) eq $path) { | |
250 | return $realp_file; | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | # file either does not exist or is not allowed to show | |
257 | # print suitable error message | |
258 | if ( !$exists_f && $ok ) { | |
259 | &ErrorMsg ("404 File not found", | |
260 | "File not found" , | |
261 | "dwww could not find the file $orig_file" ); | |
262 | } else { | |
263 | &ErrorMsg ("403 Access denied", | |
264 | "Access denied", | |
265 | "dwww will not allow you to read the file $orig_file" ); | |
266 | } | |
267 | ||
268 | exit 1; ### UNREACHED ### | |
269 | } # }}} | |
270 | ||
271 | sub GetCommandOutput { # {{{ | |
272 | my @args = @_; | |
273 | # fork and exec command | |
274 | open (OUT, '-|') | |
275 | || exec { $args[0] } @args; | |
276 | my @out=<OUT>; | |
277 | close OUT; | |
278 | return @out; | |
279 | } # }}} | |
280 | ||
281 | sub RedirectToURL() { # {{{ | |
282 | my $url = shift; | |
283 | ||
284 | my $name = defined $ENV{'SERVER_NAME'} ? $ENV{'SERVER_NAME'} : 'localhost'; | |
285 | my $port = defined $ENV{'SERVER_PORT'} ? ':' . $ENV{'SERVER_PORT'} : ''; | |
286 | $url = "/$url" unless $url =~ m/^\//; | |
287 | ||
288 | print "Location: http://$name$port$url\n\n"; | |
289 | } # }}} | |
290 | ||
291 | sub RenameDir() { # {{{ | |
292 | my ($srcdir, $tgtdir) = @_; | |
293 | ||
294 | &rmtree($tgtdir) or die "Cannot remove old $tgtdir directory: $!\n" if -d $tgtdir; | |
295 | if (! rename($srcdir, $tgtdir)) { | |
296 | &mkpath($tgtdir) or die "Cannot create $tgtdir: $!\n"; | |
297 | ©(\1, "$srcdir/*", $tgtdir) or die "Cannot copy $srcdir to $tgtdir: $!\n"; | |
298 | &rmtree($srcdir); | |
299 | } | |
300 | } # }}} | |
301 | ||
302 | ||
303 | 1; |