-
Notifications
You must be signed in to change notification settings - Fork 9
/
MkMSOfficeIndex-3.0.pl
194 lines (167 loc) · 5.06 KB
/
MkMSOfficeIndex-3.0.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/local/bin/perl -w
=head1 NAME
MkMSOfficeIndex - creates an HTML-index containing informations on all MS-office (and others) files in a directory
=head1 SYNOPSIS
MkMSOfficeIndex <RelativePathToDir> # generates index for this path
MkMSOfficeIndex [-h|-H|-help] # get this help
=head1 DESCRIPTION
generates in <RelativePathToDir> a file MkMSOfficeIndex.html containing metainformations
of all Microsoft office (and others) files in <RelativePathToDir>.
It supports recursive index-trees (see EXAMPLE).
=head1 EXAMPLE
find . -type d -exec MkMSOfficeIndex '{}' \\;
=head1 AUTHOR
B.Weiler, Siemens AG, ICN TR ON E A, 2.99, [email protected]
=head1 CAVEATS
void
=head1 PREREQUISITES
5.004;
Pod::Usage;
Config;
Cwd;
HTML::FormatText;
HTML::Parse;
file(1)
OLE-Storage-0.386
=head1 COREQUISITES
mswordview (http://www.gnu.org/~caolan/docs/MSWordView.html)
=head1 OSNAMES
This script is known to work on C<Solaris 2.5.1>
=head1 SCRIPT CATEGORIES
CPAN
=cut
use strict;
use 5.004;
use Pod::Usage;
use Config;
use Cwd;
use HTML::FormatText;
use HTML::Parse;
my $Lib="$Config{prefix}/bin";
my $LibMswordview="/usr/local/bin/mswordview";
my $MkWinwordIndex="MkMSOfficeIndex.html";
my ($File,$is);
my $Dir=shift;
chomp $Dir;
pod2usage(-verbose => 2) if((not defined $Dir)or($Dir =~/-h|^\//i));
open(INDEX,">$Dir/$MkWinwordIndex") or die $!;
my @MetaList=qw(Filename Application Title Authress Created);
my %Meta;
push(@MetaList,"Last saved");
push(@MetaList,"MetaInfos");
push(@MetaList,"DocumentContent");
print INDEX"<H1 ALIGN=\"center\">Directory Listing of Microsoft office Files</H1>\n";
print INDEX"Directory: ".cwd()."/$Dir<P>\b";
print INDEX"<TABLE BORDER=1><TR BGCOLOR=\"yellow\">";
foreach $is (@MetaList){print INDEX"<TH>$is</TH>\n"}
print INDEX"</TR>\n";
opendir(DH,$Dir) or die $!;
foreach $File (sort readdir(DH)){
next if($File=~/^\./);
next if($File eq $MkWinwordIndex);
if($File=~/\.(doc|xls|ppt|mpp)$/i){
#print STDERR "$Dir/$File\n";
print INDEX "<TR>";
my @il;
foreach $is (@MetaList){$Meta{$is}='-'}
$Meta{Filename}="<A HREF=\"./$File\">$File</A>";
open(PIPE,"$Lib/ldat '$Dir/$File' |") or die $!;
while(<PIPE>){
chomp;
foreach $is (@MetaList){
next unless($_=~$is);
$Meta{$is}=$_;
$Meta{$is}=~s|^.*?:||;
}
push(@il,$_);
$Meta{Filename}.="<BR><FONT COLOR=\"red\"><B>Error found in Document!</B></FONT>" if(/Error/);
}
close PIPE;
$Meta{MetaInfos}="<PRE><FONT SIZE=-1>".join('<BR>',@il)."</FONT></PRE>";
#if($File=~/\.doc/){
if($Meta{Application} =~ /Microsoft\s+Word/){
$Meta{"DocumentContent"}="<PRE><FONT SIZE=-1>";
my $ii=0;
my $is='';
if($Meta{Application} !~ /8\./){
open(PIPE,"$Lib/lhalw --to_stdout --column 70 '$Dir/$File' |") or die $!;
while(<PIPE>){
chomp;
next if($ii==10);
$ii++;
$Meta{"DocumentContent"}.="$_\n";
}
close(PIPE);
}else{
if(-e $LibMswordview){
open(PIPE,"$LibMswordview -n -t 2 -m -i $ENV{HOME}/tmp -o - '$Dir/$File' |") or die $!;
while(<PIPE>){
chomp;
$is.="$_\n";
}
close(PIPE);
$is=HTML::FormatText->new->format(parse_html($is));
my @is=split("\n",$is);
$#is=10 if $#is >10;
$Meta{"DocumentContent"}.=join("\n",@is);
}else{$Meta{"DocumentContent"}.="Glimpse on content not provided\n"}
}
$Meta{"DocumentContent"}.="\n(...truncated)</FONT></PRE>";
}
foreach $is (@MetaList){print INDEX"<TD>$Meta{$is}</TD>\n"}
print INDEX"</TR>\n";
}
else{
foreach $is (@MetaList){$Meta{$is}='-'}
if(-l "$Dir/$File"){
$Meta{Filename}="<A HREF=\"./".readlink("$Dir/$File")."/$MkWinwordIndex\">$File</A>";
$Meta{Application}="Is a link";
}
elsif(-d "$Dir/$File"){
$Meta{Filename}="<A HREF=\"./$File/$MkWinwordIndex\">$File</A>";
$Meta{Application}="Is a directory";
}
else{
$Meta{Filename}="<A HREF=\"./$File\">$File</A>";
$Meta{Application}="not a MS-Office application";
open(PH,"file '$Dir/$File' |") or die $!;
while(<PH>){
$Meta{Application}.=", is probably ".$1 if(/.*?:\s*(.*)/);
}
close PH;
$Meta{"DocumentContent"}="<PRE><FONT SIZE=-1>";
if($File =~/\.html?$/i){
my $is='';
open(FH,"$Dir/$File") or die $!;
while(<FH>){
chomp;
$is.="$_\n";
}
close FH;
$is=HTML::FormatText->new->format(parse_html($is));
my @is=split("\n",$is);
$#is=10 if $#is >10;
$Meta{"DocumentContent"}.=join("\n",@is);
}elsif(-T "$Dir/$File"){
my $ii=0;
my $is='';
open(FH,"$Dir/$File") or die $!;
while(<FH>){
chomp;
next if($ii==10);
$ii++;
$Meta{"DocumentContent"}.="$_\n";
}
close FH;
}else{$Meta{"DocumentContent"}.="Glimpse on content not provided\n"}
$Meta{"DocumentContent"}.="\n(...truncated)</FONT></PRE>";
}
print INDEX "<TR>";
foreach $is (@MetaList){print INDEX"<TD>$Meta{$is}</TD>\n"}
print INDEX"</TR>\n";
}
}
closedir(DH);
print INDEX"</TABLE>";
print INDEX"Generated by $0 at ".scalar(localtime())."\n";
close INDEX;