1 #============================================================= -*-perl-*-
3 # BackupPC::CGI::View package
7 # This module implements the View action for the CGI interface.
10 # Craig Barratt <cbarratt@users.sourceforge.net>
13 # Copyright (C) 2003 Craig Barratt
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #========================================================================
31 # Version 2.1.0, released 20 Jun 2004.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::View;
40 use BackupPC::CGI::Lib qw(:all);
41 use BackupPC::FileZIO;
45 my $Privileged = CheckPermission($In{host});
53 my $ext = $num ne "" ? ".$num" : "";
55 ErrorExit(eval("qq{$Lang->{Invalid_number__num}}"))
56 if ( $num ne "" && $num !~ /^\d+$/ );
57 if ( $type eq "XferLOG" ) {
58 $file = "$TopDir/pc/$host/SmbLOG$ext";
59 $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
60 } elsif ( $type eq "XferLOGbad" ) {
61 $file = "$TopDir/pc/$host/SmbLOG.bad";
62 $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
63 } elsif ( $type eq "XferErrbad" ) {
64 $file = "$TopDir/pc/$host/SmbLOG.bad";
65 $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
66 $comment = $Lang->{Extracting_only_Errors};
67 } elsif ( $type eq "XferErr" ) {
68 $file = "$TopDir/pc/$host/SmbLOG$ext";
69 $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
70 $comment = $Lang->{Extracting_only_Errors};
71 } elsif ( $type eq "RestoreLOG" ) {
72 $file = "$TopDir/pc/$host/RestoreLOG$ext";
73 } elsif ( $type eq "RestoreErr" ) {
74 $file = "$TopDir/pc/$host/RestoreLOG$ext";
75 $comment = $Lang->{Extracting_only_Errors};
76 } elsif ( $type eq "ArchiveLOG" ) {
77 $file = "$TopDir/pc/$host/ArchiveLOG$ext";
78 } elsif ( $type eq "ArchiveErr" ) {
79 $file = "$TopDir/pc/$host/ArchiveLOG$ext";
80 $comment = $Lang->{Extracting_only_Errors};
81 } elsif ( $host ne "" && $type eq "config" ) {
82 $file = "$TopDir/pc/$host/config.pl";
83 $file = "$TopDir/conf/$host.pl"
84 if ( $host ne "config" && -f "$TopDir/conf/$host.pl"
86 } elsif ( $type eq "docs" ) {
87 $file = "$BinDir/../doc/BackupPC.html";
88 } elsif ( $type eq "config" ) {
89 $file = "$TopDir/conf/config.pl";
90 } elsif ( $type eq "hosts" ) {
91 $file = "$TopDir/conf/hosts";
93 } elsif ( $host ne "" ) {
94 $file = "$TopDir/pc/$host/LOG$ext";
97 $file = "$TopDir/log/LOG$ext";
100 if ( $type ne "docs" && !$Privileged ) {
101 ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
103 if ( !-f $file && -f "$file.z" ) {
107 my($contentPre, $contentSub, $contentPost);
108 $contentPre .= eval("qq{$Lang->{Log_File__file__comment}}");
109 if ( defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
110 my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
112 $contentPre .= eval("qq{$Lang->{Contents_of_log_file}}");
114 $contentPre .= "<pre>";
115 if ( $type eq "XferErr" || $type eq "XferErrbad"
116 || $type eq "RestoreErr"
117 || $type eq "ArchiveErr" ) {
120 # Because the content might be large, we use
121 # a sub to return the data in 64K chunks.
123 my($skipped, $c, $s);
124 while ( length($c) < 65536 ) {
125 $s = $fh->readLine();
127 $c .= eval("qq{$Lang->{skipped__skipped_lines}}")
132 if ( $s =~ /smb: \\>/
133 || $s =~ /^\s*(\d+) \(\s*\d+\.\d kb\/s\) (.*)$/
134 || $s =~ /^tar: dumped \d+ files/
135 || $s =~ /^\s*added interface/i
136 || $s =~ /^\s*restore tar file /i
137 || $s =~ /^\s*restore directory /i
138 || $s =~ /^\s*tarmode is now/i
139 || $s =~ /^\s*Total bytes written/i
140 || $s =~ /^\s*Domain=/i
141 || $s =~ /^\s*Getting files newer than/i
142 || $s =~ /^\s*Output is \/dev\/null/
143 || $s =~ /^\s*\([\d.,]* kb\/s\) \(average [\d\.]* kb\/s\)$/
144 || $s =~ /^\s+directory \\/
145 || $s =~ /^\s*Timezone is/
146 || $s =~ /^\s*creating lame (up|low)case table/i
152 $c .= eval("qq{$Lang->{skipped__skipped_lines}}")
155 $c .= ${EscHTML($s)} . "\n";
159 } elsif ( $linkHosts ) {
161 # Because the content might be large, we use
162 # a sub to return the data in 64K chunks.
166 while ( length($c) < 65536 ) {
167 $s = $fh->readLine();
168 last if ( $s eq "" );
171 $s =~ s/\b([\w-]+)\b/defined($Hosts->{$1})
172 ? ${HostLink($1)} : $1/eg;
177 } elsif ( $type eq "config" ) {
179 # Because the content might be large, we use
180 # a sub to return the data in 64K chunks.
184 while ( length($c) < 65536 ) {
185 $s = $fh->readLine();
186 last if ( $s eq "" );
188 # remove any passwords and user names
189 $s =~ s/(SmbSharePasswd.*=.*['"]).*(['"])/$1****$2/ig;
190 $s =~ s/(SmbShareUserName.*=.*['"]).*(['"])/$1****$2/ig;
191 $s =~ s/(RsyncdPasswd.*=.*['"]).*(['"])/$1****$2/ig;
192 $s =~ s/(ServerMesgSecret.*=.*['"]).*(['"])/$1****$2/ig;
194 $s =~ s[(\$Conf\{.*?\})][
197 $s =~ s{(\W)}{sprintf("%%%02x", ord($1) )}gxe;
198 "<a href=\"?action=view&type=docs#item_$s\"><tt>$c</tt></a>"
204 } elsif ( $type eq "docs" ) {
206 # Because the content might be large, we use
207 # a sub to return the data in 64K chunks.
211 while ( length($c) < 65536 ) {
212 $s = $fh->readLine();
213 last if ( $s eq "" );
219 # Documentation has a different header and no pre or post text,
220 # so just handle it here
222 Header($Lang->{BackupPC__Documentation}, "", 0, $contentSub);
227 # Because the content might be large, we use
228 # a sub to return the data in 64K chunks.
232 while ( length($c) < 65536 ) {
233 $s = $fh->readLine();
234 last if ( $s eq "" );
243 if ( $type eq "docs" ) {
244 ErrorExit(eval("qq{$Lang->{Unable_to_open__file__configuration_problem}}"));
246 $contentPre .= eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}");
248 $contentPost .= "</pre>\n" if ( $type ne "docs" );
249 Header(eval("qq{$Lang->{Backup_PC__Log_File__file}}"),
250 $contentPre, !-f "$TopDir/pc/$host/backups",
251 $contentSub, $contentPost);
253 $fh->close() if ( defined($fh) );