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 ( $host ne "" && $type eq "config" ) {
76 $file = "$TopDir/pc/$host/config.pl";
77 $file = "$TopDir/conf/$host.pl"
78 if ( $host ne "config" && -f "$TopDir/conf/$host.pl"
80 } elsif ( $type eq "docs" ) {
81 $file = "$BinDir/../doc/BackupPC.html";
82 if ( open(LOG, $file) ) {
84 Header($Lang->{BackupPC__Documentation});
85 print while ( <LOG> );
89 ErrorExit(eval("qq{$Lang->{Unable_to_open__file__configuration_problem}}"));
92 } elsif ( $type eq "config" ) {
93 $file = "$TopDir/conf/config.pl";
94 } elsif ( $type eq "hosts" ) {
95 $file = "$TopDir/conf/hosts";
96 } elsif ( $host ne "" ) {
97 $file = "$TopDir/pc/$host/LOG$ext";
99 $file = "$TopDir/log/LOG$ext";
102 if ( !$Privileged ) {
103 ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
105 if ( !-f $file && -f "$file.z" ) {
109 Header(eval("qq{$Lang->{Backup_PC__Log_File__file}}") );
110 print( eval ("qq{$Lang->{Log_File__file__comment}}"));
111 if ( defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
112 my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
114 print ( eval ("qq{$Lang->{Contents_of_log_file}}"));
117 if ( $type eq "XferErr" || $type eq "XferErrbad"
118 || $type eq "RestoreErr" ) {
121 $_ = $fh->readLine();
123 print(eval ("qq{$Lang->{skipped__skipped_lines}}"))
128 || /^\s*(\d+) \(\s*\d+\.\d kb\/s\) (.*)$/
129 || /^tar: dumped \d+ files/
130 || /^added interface/i
131 || /^restore tar file /i
132 || /^restore directory /i
133 || /^tarmode is now/i
134 || /^Total bytes written/i
136 || /^Getting files newer than/i
137 || /^Output is \/dev\/null/
138 || /^\([\d\.]* kb\/s\) \(average [\d\.]* kb\/s\)$/
139 || /^\s+directory \\/
147 print(eval("qq{$Lang->{skipped__skipped_lines}}"))
150 print ${EscHTML($_)};
152 } elsif ( $linkHosts ) {
154 $_ = $fh->readLine();
155 last if ( $_ eq "" );
156 my $s = ${EscHTML($_)};
157 $s =~ s/\b([\w-]+)\b/defined($Hosts->{$1})
158 ? ${HostLink($1)} : $1/eg;
161 } elsif ( $type eq "config" ) {
163 $_ = $fh->readLine();
164 last if ( $_ eq "" );
165 # remove any passwords and user names
166 s/(SmbSharePasswd.*=.*['"]).*(['"])/$1$2/ig;
167 s/(SmbShareUserName.*=.*['"]).*(['"])/$1$2/ig;
168 s/(RsyncdPasswd.*=.*['"]).*(['"])/$1$2/ig;
169 s/(ServerMesgSecret.*=.*['"]).*(['"])/$1$2/ig;
170 print ${EscHTML($_)};
174 $_ = $fh->readLine();
175 last if ( $_ eq "" );
176 print ${EscHTML($_)};
181 printf( eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}"));