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_CVS, released 3 Jul 2003.
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}}")) if ( $num ne "" && $num !~ /^\d+$/ );
56 if ( $type eq "XferLOG" ) {
57 $file = "$TopDir/pc/$host/SmbLOG$ext";
58 $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
59 } elsif ( $type eq "XferLOGbad" ) {
60 $file = "$TopDir/pc/$host/SmbLOG.bad";
61 $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
62 } elsif ( $type eq "XferErrbad" ) {
63 $file = "$TopDir/pc/$host/SmbLOG.bad";
64 $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
65 $comment = $Lang->{Extracting_only_Errors};
66 } elsif ( $type eq "XferErr" ) {
67 $file = "$TopDir/pc/$host/SmbLOG$ext";
68 $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
69 $comment = $Lang->{Extracting_only_Errors};
70 } elsif ( $type eq "RestoreLOG" ) {
71 $file = "$TopDir/pc/$host/RestoreLOG$ext";
72 } elsif ( $type eq "RestoreErr" ) {
73 $file = "$TopDir/pc/$host/RestoreLOG$ext";
74 $comment = $Lang->{Extracting_only_Errors};
75 } elsif ( $type eq "ArchiveLOG" ) {
76 $file = "$TopDir/pc/$host/ArchiveLOG$ext";
77 } elsif ( $type eq "ArchiveErr" ) {
78 $file = "$TopDir/pc/$host/ArchiveLOG$ext";
79 $comment = $Lang->{Extracting_only_Errors};
80 } elsif ( $host ne "" && $type eq "config" ) {
81 $file = "$TopDir/pc/$host/config.pl";
82 $file = "$TopDir/conf/$host.pl"
83 if ( $host ne "config" && -f "$TopDir/conf/$host.pl"
85 } elsif ( $type eq "docs" ) {
86 $file = "$BinDir/../doc/BackupPC.html";
87 if ( open(LOG, $file) ) {
90 $content .= $_ while ( <LOG> );
92 Header($Lang->{BackupPC__Documentation}, $content);
95 ErrorExit(eval("qq{$Lang->{Unable_to_open__file__configuration_problem}}"));
98 } elsif ( $type eq "config" ) {
99 $file = "$TopDir/conf/config.pl";
100 } elsif ( $type eq "hosts" ) {
101 $file = "$TopDir/conf/hosts";
102 } elsif ( $host ne "" ) {
103 $file = "$TopDir/pc/$host/LOG$ext";
105 $file = "$TopDir/log/LOG$ext";
108 if ( !$Privileged ) {
109 ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
111 if ( !-f $file && -f "$file.z" ) {
116 $content .= eval ("qq{$Lang->{Log_File__file__comment}}");
117 if ( defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
118 my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
120 $content .= ( eval ("qq{$Lang->{Contents_of_log_file}}"));
123 if ( $type eq "XferErr" || $type eq "XferErrbad"
124 || $type eq "RestoreErr" ) {
127 $_ = $fh->readLine();
129 $content .= (eval ("qq{$Lang->{skipped__skipped_lines}}"))
134 || /^\s*(\d+) \(\s*\d+\.\d kb\/s\) (.*)$/
135 || /^tar: dumped \d+ files/
136 || /^added interface/i
137 || /^restore tar file /i
138 || /^restore directory /i
139 || /^tarmode is now/i
140 || /^Total bytes written/i
142 || /^Getting files newer than/i
143 || /^Output is \/dev\/null/
144 || /^\([\d\.]* kb\/s\) \(average [\d\.]* kb\/s\)$/
145 || /^\s+directory \\/
153 $content .= (eval("qq{$Lang->{skipped__skipped_lines}}"))
156 $content .= ${EscHTML($_)};
158 } elsif ( $linkHosts ) {
160 $_ = $fh->readLine();
161 last if ( $_ eq "" );
162 my $s = ${EscHTML($_)};
163 $s =~ s/\b([\w-]+)\b/defined($Hosts->{$1})
164 ? ${HostLink($1)} : $1/eg;
167 } elsif ( $type eq "config" ) {
169 $_ = $fh->readLine();
170 last if ( $_ eq "" );
171 # remove any passwords and user names
172 s/(SmbSharePasswd.*=.*['"]).*(['"])/$1$2/ig;
173 s/(SmbShareUserName.*=.*['"]).*(['"])/$1$2/ig;
174 s/(RsyncdPasswd.*=.*['"]).*(['"])/$1$2/ig;
175 s/(ServerMesgSecret.*=.*['"]).*(['"])/$1$2/ig;
176 $content .= ${EscHTML($_)};
180 $_ = $fh->readLine();
181 last if ( $_ eq "" );
182 $content .= ${EscHTML($_)};
187 $content .= ( eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}"));
192 Header(eval("qq{$Lang->{Backup_PC__Log_File__file}}"), $content);