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-2009 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 3.2.0, released 31 Jul 2010.
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 ( $type eq "config" ) {
82 # Note: only works for Storage::Text
83 $file = $bpc->{storage}->ConfigPath($host);
84 } elsif ( $type eq "hosts" ) {
85 # Note: only works for Storage::Text
86 $file = $bpc->ConfDir() . "/hosts";
88 } elsif ( $type eq "docs" ) {
89 $file = $bpc->InstallDir() . "/doc/BackupPC.html";
90 } elsif ( $host ne "" ) {
91 if ( !defined($In{num}) ) {
92 # get the latest LOG file
93 $file = ($bpc->sortedPCLogFiles($host))[0];
96 $file = "$TopDir/pc/$host/LOG$ext";
100 $file = "$LogDir/LOG$ext";
103 if ( $type ne "docs" && !$Privileged ) {
104 ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
106 if ( !-f $file && -f "$file.z" ) {
110 my($contentPre, $contentSub, $contentPost);
111 $contentPre .= eval("qq{$Lang->{Log_File__file__comment}}");
113 && defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
116 my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
118 $contentPre .= eval("qq{$Lang->{Contents_of_log_file}}");
120 $contentPre .= "<pre>";
121 if ( $type eq "XferErr" || $type eq "XferErrbad"
122 || $type eq "RestoreErr"
123 || $type eq "ArchiveErr" ) {
126 # Because the content might be large, we use
127 # a sub to return the data in 64K chunks.
129 my($skipped, $c, $s);
130 while ( length($c) < 65536 ) {
131 $s = $fh->readLine();
133 $c .= eval("qq{$Lang->{skipped__skipped_lines}}")
138 if ( $s =~ /smb: \\>/
139 || $s =~ /^\s*(\d+) \(\s*\d+\.\d kb\/s\) (.*)$/
140 || $s =~ /^tar: dumped \d+ files/
141 || $s =~ /^\s*added interface/i
142 || $s =~ /^\s*restore tar file /i
143 || $s =~ /^\s*restore directory /i
144 || $s =~ /^\s*tarmode is now/i
145 || $s =~ /^\s*Total bytes written/i
146 || $s =~ /^\s*Domain=/i
147 || $s =~ /^\s*Getting files newer than/i
148 || $s =~ /^\s*Output is \/dev\/null/
149 || $s =~ /^\s*\([\d.,]* kb\/s\) \(average [\d\.]* kb\/s\)$/
150 || $s =~ /^\s+directory \\/
151 || $s =~ /^\s*Timezone is/
152 || $s =~ /^\s*creating lame (up|low)case table/i
158 $c .= eval("qq{$Lang->{skipped__skipped_lines}}")
161 $c .= ${EscHTML($s)} . "\n";
165 } elsif ( $linkHosts ) {
167 # Because the content might be large, we use
168 # a sub to return the data in 64K chunks.
172 while ( length($c) < 65536 ) {
173 $s = $fh->readLine();
174 last if ( $s eq "" );
177 $s =~ s/\b([\w-.]+)\b/defined($Hosts->{$1})
178 ? ${HostLink($1)} : $1/eg;
183 } elsif ( $type eq "config" ) {
185 # Because the content might be large, we use
186 # a sub to return the data in 64K chunks.
190 while ( length($c) < 65536 ) {
191 $s = $fh->readLine();
192 last if ( $s eq "" );
194 # remove any passwords and user names
195 $s =~ s/(SmbSharePasswd.*=.*['"]).*(['"])/$1****$2/ig;
196 $s =~ s/(SmbShareUserName.*=.*['"]).*(['"])/$1****$2/ig;
197 $s =~ s/(RsyncdPasswd.*=.*['"]).*(['"])/$1****$2/ig;
198 $s =~ s/(ServerMesgSecret.*=.*['"]).*(['"])/$1****$2/ig;
200 $s =~ s[(\$Conf\{.*?\})][
204 "<a href=\"?action=view&type=docs#item_$s\"><tt>$c</tt></a>"
210 } elsif ( $type eq "docs" ) {
212 # Because the content might be large, we use
213 # a sub to return the data in 64K chunks.
217 while ( length($c) < 65536 ) {
218 $s = $fh->readLine();
219 last if ( $s eq "" );
225 # Documentation has a different header and no pre or post text,
226 # so just handle it here
228 Header($Lang->{BackupPC__Documentation}, "", 0, $contentSub);
233 # Because the content might be large, we use
234 # a sub to return the data in 64K chunks.
238 while ( length($c) < 65536 ) {
239 $s = $fh->readLine();
240 last if ( $s eq "" );
249 if ( $type eq "docs" ) {
250 ErrorExit(eval("qq{$Lang->{Unable_to_open__file__configuration_problem}}"));
252 $contentPre .= eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}");
254 $contentPost .= "</pre>\n" if ( $type ne "docs" );
255 Header(eval("qq{$Lang->{Backup_PC__Log_File__file}}"),
256 $contentPre, !-f "$TopDir/pc/$host/backups",
257 $contentSub, $contentPost);
259 $fh->close() if ( defined($fh) );