renamed to only_increment
[BackupPC.git] / lib / BackupPC / CGI / Browse.pm
index 3993b94..014ef9e 100644 (file)
@@ -10,7 +10,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2003  Craig Barratt
+#   Copyright (C) 2003-2009  Craig Barratt
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 3.2.0, released 31 Jul 2010.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -37,6 +37,7 @@
 package BackupPC::CGI::Browse;
 
 use strict;
+use Encode qw/decode_utf8/;
 use BackupPC::CGI::Lib qw(:all);
 use BackupPC::View;
 use BackupPC::Attrib qw(:all);
@@ -60,6 +61,15 @@ sub action
     # Find the requested backup and the previous filled backup
     #
     my @Backups = $bpc->BackupInfoRead($host);
+
+    #
+    # default to the newest backup
+    #
+    if ( !defined($In{num}) && defined(@Backups) && @Backups > 0 ) {
+        $i = @Backups - 1;
+        $num = $Backups[$i]{num};
+    }
+
     for ( $i = 0 ; $i < @Backups ; $i++ ) {
         last if ( $Backups[$i]{num} == $num );
     }
@@ -70,7 +80,7 @@ sub action
     my $backupTime = timeStamp2($Backups[$i]{startTime});
     my $backupAge = sprintf("%.1f", (time - $Backups[$i]{startTime})
                                     / (24 * 3600));
-    my $view = BackupPC::View->new($bpc, $host, \@Backups);
+    my $view = BackupPC::View->new($bpc, $host, \@Backups, {nlink => 1, only_increment => $In{only_increment}});
 
     if ( $dir eq "" || $dir eq "." || $dir eq ".." ) {
        $attr = $view->dirAttrib($num, "", "");
@@ -84,6 +94,9 @@ sub action
     $dir = "/$dir" if ( $dir !~ /^\// );
     my $relDir  = $dir;
     my $currDir = undef;
+    if ( $dir =~ m{(^|/)\.\.(/|$)} ) {
+        ErrorExit($Lang->{Nice_try__but_you_can_t_put});
+    }
 
     #
     # Loop up the directory tree until we hit the top.
@@ -94,6 +107,7 @@ sub action
 
        $attr = $view->dirAttrib($num, $share, $relDir);
         if ( !defined($attr) ) {
+            $relDir = decode_utf8($relDir);
             ErrorExit(eval("qq{$Lang->{Can_t_browse_bad_directory_name2}}"));
         }
 
@@ -126,28 +140,29 @@ sub action
                 # Display directory if it exists in current backup.
                 # First find out if there are subdirs
                 #
-               my($bold, $unbold, $BGcolor);
+                my $tdStyle;
+                my $linkStyle = "fview";
                $img |= 1 << 6;
                $img |= 1 << 5 if ( $attr->{$f}{nlink} > 2 );
                if ( $dirOpen ) {
-                   $bold = "<b>";
-                   $unbold = "</b>";
+                    $linkStyle = "fviewbold";
                    $img |= 1 << 2;
                    $img |= 1 << 3 if ( $attr->{$f}{nlink} > 2 );
                }
                my $imgFileName = sprintf("%07b.gif", $img);
                $imgStr = "<img src=\"$Conf{CgiImageDirURL}/$imgFileName\" align=\"absmiddle\" width=\"9\" height=\"19\" border=\"0\">";
                if ( "$relDir/$f" eq $dir ) {
-                   $BGcolor = " bgcolor=\"$Conf{CgiHeaderBgColor}\"";
+                    $tdStyle = "fviewon";
                } else {
-                   $BGcolor = "";
+                    $tdStyle = "fviewoff";
                }
                my $dirName = $f;
                $dirName =~ s/ /&nbsp;/g;
+                $dirName = decode_utf8($dirName);
                push(@DirStr, {needTick => 1,
-                              tdArgs   => $BGcolor,
+                               tdArgs   => " class=\"$tdStyle\"",
                               link     => <<EOF});
-<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$imgStr</a><a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path" style="font-size:13px;font-family:arial;text-decoration:none;line-height:15px">&nbsp;$bold$dirName$unbold</a></td></tr>
+<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$imgStr</a><a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path" class="$linkStyle">&nbsp;$dirName</a></td></tr>
 EOF
                 $fileCnt++;
                 $gotDir = 1;
@@ -181,34 +196,42 @@ EOF
                 #
                 # This is the selected directory, so display all the files
                 #
-                my $attrStr;
+                my ($attrStr, $iconStr);
                 if ( defined($a = $attr->{$f}) ) {
                     my $mtimeStr = $bpc->timeStamp($a->{mtime});
                    # UGH -> fix this
                     my $typeStr  = BackupPC::Attrib::fileType2Text(undef,
                                                                   $a->{type});
                     my $modeStr  = sprintf("0%o", $a->{mode} & 07777);
+                    $iconStr = <<EOF;
+<img src="$Conf{CgiImageDirURL}/icon-$typeStr.png" valign="top">
+EOF
                     $attrStr .= <<EOF;
-    <td align="center">$typeStr</td>
-    <td align="center">$modeStr</td>
-    <td align="center">$a->{backupNum}</td>
-    <td align="right">$a->{size}</td>
-    <td align="right">$mtimeStr</td>
+    <td align="center" class="fviewborder">$typeStr</td>
+    <td align="center" class="fviewborder">$modeStr</td>
+    <td align="center" class="fviewborder">$a->{backupNum}</td>
+    <td align="right" class="fviewborder">$a->{size}</td>
+    <td align="right" class="fviewborder">$mtimeStr</td>
 </tr>
 EOF
                 } else {
-                    $attrStr .= "<td colspan=\"5\" align=\"center\"> </td>\n";
+                    $attrStr .= "<td colspan=\"5\" align=\"center\" class=\"fviewborder\"> </td>\n";
                 }
                (my $fDisp = "${EscHTML($f)}") =~ s/ /&nbsp;/g;
+                $fDisp = decode_utf8($fDisp);
                 if ( $gotDir ) {
                     $fileStr .= <<EOF;
-<tr bgcolor="#ffffcc"><td><input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a></td>
+<tr><td class="fviewborder">
+    <input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;$iconStr&nbsp;<a href="$MyURL?action=browse&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a>
+</td>
 $attrStr
 </tr>
 EOF
                 } else {
                     $fileStr .= <<EOF;
-<tr bgcolor="#ffffcc"><td><input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;<a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a></td>
+<tr><td class="fviewborder">
+    <input type="checkbox" name="fcb$checkBoxCnt" value="$path">&nbsp;$iconStr&nbsp;<a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$fDisp</a>
+</td>
 $attrStr
 </tr>
 EOF
@@ -232,7 +255,7 @@ EOF
        }
     }
     $share = $currDir;
-    my $dirDisplay = "$share/$dir";
+    my $dirDisplay = decode_utf8("$share/$dir");
     $dirDisplay =~ s{//+}{/}g;
     $dirDisplay =~ s{/+$}{}g;
     $dirDisplay = "/" if ( $dirDisplay eq "" );
@@ -243,7 +266,6 @@ EOF
        my $numF = join(", #", @mergeNums);
         $filledBackup = eval("qq{$Lang->{This_display_is_merged_with_backup}}");
     }
-    Header(eval("qq{$Lang->{Browse_backup__num_for__host}}"));
 
     foreach my $d ( @DirStrPrev ) {
        $dirStr .= "<tr><td$d->{tdArgs}>$d->{link}\n";
@@ -264,20 +286,25 @@ EOF
     } else {
        $fileStr = eval("qq{$Lang->{The_directory_is_empty}}");
     }
-    my @otherDirs;
     my $pathURI  = $dir;
     my $shareURI = $share;
     $pathURI  =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
     $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
-    foreach my $i ( $view->backupList($share, $dir) ) {
-        push(@otherDirs, "<a href=\"$MyURL?action=browse&host=${EscURI($host)}"
-                       . "&num=$i&share=$shareURI&dir=$pathURI\">$i</a>");
-    }
-    if ( @otherDirs ) {
-       my $otherDirs  = join(",\n", @otherDirs);
+    if ( my @otherDirs = $view->backupList($share, $dir) ) {
+        my $otherDirs;
+        foreach my $i ( @otherDirs ) {
+            my $selected;
+            my $showDate  = timeStamp2($Backups[$i]{startTime});
+           my $backupNum = $Backups[$i]{num};
+            $selected   = " selected" if ( $backupNum == $num );
+            $otherDirs .= "<option value=\"$MyURL?action=browse&host=${EscURI($host)}&num=$backupNum&share=$shareURI&dir=$pathURI\"$selected>#$backupNum - ($showDate)</option>\n";
+        }
         $filledBackup .= eval("qq{$Lang->{Visit_this_directory_in_backup}}");
     }
-    print (eval("qq{$Lang->{Backup_browse_for__host}}"));
+    $dir   = decode_utf8($dir);
+    $share = decode_utf8($share);
+    my $content = eval("qq{$Lang->{Backup_browse_for__host}}");
+    Header(eval("qq{$Lang->{Browse_backup__num_for__host}}"), $content);
     Trailer();
 }