* BackupPC_Admin now uses $Conf{UmaskMode}, so config.pl files
[BackupPC.git] / lib / BackupPC / CGI / View.pm
index c24b80d..2ce291e 100644 (file)
@@ -28,7 +28,7 @@
 #
 #========================================================================
 #
 #
 #========================================================================
 #
-# Version 2.1.0beta0, released 20 Mar 2004.
+# Version 3.0.0beta3, released 3 Dec 2006.
 #
 # See http://backuppc.sourceforge.net.
 #
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -78,26 +78,29 @@ sub action
     } elsif ( $type eq "ArchiveErr" ) {
         $file = "$TopDir/pc/$host/ArchiveLOG$ext";
         $comment = $Lang->{Extracting_only_Errors};
     } elsif ( $type eq "ArchiveErr" ) {
         $file = "$TopDir/pc/$host/ArchiveLOG$ext";
         $comment = $Lang->{Extracting_only_Errors};
-    } elsif ( $host ne "" && $type eq "config" ) {
-        $file = "$TopDir/pc/$host/config.pl";
-        $file = "$TopDir/conf/$host.pl"
-                    if ( $host ne "config" && -f "$TopDir/conf/$host.pl"
-                                           && !-f $file );
-    } elsif ( $type eq "docs" ) {
-        $file = "$BinDir/../doc/BackupPC.html";
     } elsif ( $type eq "config" ) {
     } elsif ( $type eq "config" ) {
-        $file = "$TopDir/conf/config.pl";
+        # Note: only works for Storage::Text
+        $file = $bpc->{storage}->ConfigPath($host);
     } elsif ( $type eq "hosts" ) {
     } elsif ( $type eq "hosts" ) {
-        $file = "$TopDir/conf/hosts";
+        # Note: only works for Storage::Text
+        $file = $bpc->ConfDir() . "/hosts";
         $linkHosts = 1;
         $linkHosts = 1;
+    } elsif ( $type eq "docs" ) {
+        $file = "$BinDir/../doc/BackupPC.html";
     } elsif ( $host ne "" ) {
     } elsif ( $host ne "" ) {
-        $file = "$TopDir/pc/$host/LOG$ext";
+        if ( !defined($In{num}) ) {
+            # get the latest LOG file
+            $file = ($bpc->sortedPCLogFiles($host))[0];
+            $file =~ s/\.z$//;
+        } else {
+            $file = "$TopDir/pc/$host/LOG$ext";
+        }
         $linkHosts = 1;
     } else {
         $linkHosts = 1;
     } else {
-        $file = "$TopDir/log/LOG$ext";
+        $file = "$LogDir/LOG$ext";
         $linkHosts = 1;
     }
         $linkHosts = 1;
     }
-    if ( !$Privileged ) {
+    if ( $type ne "docs" && !$Privileged ) {
         ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
     }
     if ( !-f $file && -f "$file.z" ) {
         ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
     }
     if ( !-f $file && -f "$file.z" ) {
@@ -106,7 +109,10 @@ sub action
     }
     my($contentPre, $contentSub, $contentPost);
     $contentPre .= eval("qq{$Lang->{Log_File__file__comment}}");
     }
     my($contentPre, $contentSub, $contentPost);
     $contentPre .= eval("qq{$Lang->{Log_File__file__comment}}");
-    if ( defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
+    if ( $file ne ""
+            && defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
+
+        $fh->utf8(1);
         my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
 
        $contentPre .= eval("qq{$Lang->{Contents_of_log_file}}");
         my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
 
        $contentPre .= eval("qq{$Lang->{Contents_of_log_file}}");
@@ -168,7 +174,7 @@ sub action
                    last if ( $s eq "" );
                    $s =~ s/[\n\r]+//g;
                    $s = ${EscHTML($s)};
                    last if ( $s eq "" );
                    $s =~ s/[\n\r]+//g;
                    $s = ${EscHTML($s)};
-                   $s =~ s/\b([\w-]+)\b/defined($Hosts->{$1})
+                   $s =~ s/\b([\w-.]+)\b/defined($Hosts->{$1})
                                            ? ${HostLink($1)} : $1/eg;
                    $c .= $s . "\n";
                }
                                            ? ${HostLink($1)} : $1/eg;
                    $c .= $s . "\n";
                }
@@ -186,16 +192,16 @@ sub action
                    last if ( $s eq "" );
                    $s =~ s/[\n\r]+//g;
                    # remove any passwords and user names
                    last if ( $s eq "" );
                    $s =~ s/[\n\r]+//g;
                    # remove any passwords and user names
-                   $s =~ s/(SmbSharePasswd.*=.*['"]).*(['"])/$1$2/ig;
-                   $s =~ s/(SmbShareUserName.*=.*['"]).*(['"])/$1$2/ig;
-                   $s =~ s/(RsyncdPasswd.*=.*['"]).*(['"])/$1$2/ig;
-                   $s =~ s/(ServerMesgSecret.*=.*['"]).*(['"])/$1$2/ig;
+                   $s =~ s/(SmbSharePasswd.*=.*['"]).*(['"])/$1****$2/ig;
+                   $s =~ s/(SmbShareUserName.*=.*['"]).*(['"])/$1****$2/ig;
+                   $s =~ s/(RsyncdPasswd.*=.*['"]).*(['"])/$1****$2/ig;
+                   $s =~ s/(ServerMesgSecret.*=.*['"]).*(['"])/$1****$2/ig;
                    $s = ${EscHTML($s)};
                    $s =~ s[(\$Conf\{.*?\})][
                        my $c = $1;
                        my $s = lc($c);
                    $s = ${EscHTML($s)};
                    $s =~ s[(\$Conf\{.*?\})][
                        my $c = $1;
                        my $s = lc($c);
-                       $s =~ s{(\W)}{sprintf("%%%02x", ord($1) )}gxe;
-                       "<a href=\"?action=view&type=docs#item_$s\">$c</a>"
+                       $s =~ s{(\W)}{_}g;
+                       "<a href=\"?action=view&type=docs#item_$s\"><tt>$c</tt></a>"
                    ]eg;
                    $c .= $s . "\n";
                }
                    ]eg;
                    $c .= $s . "\n";
                }
@@ -216,7 +222,7 @@ sub action
                return $c;
             };
            #
                return $c;
             };
            #
-           # Documentation a different header and no pre or post text,
+           # Documentation has a different header and no pre or post text,
            # so just handle it here
            #
             Header($Lang->{BackupPC__Documentation}, "", 0, $contentSub);
            # so just handle it here
            #
             Header($Lang->{BackupPC__Documentation}, "", 0, $contentSub);