Fixed small navigation bug in CGI Action_Browse for top-level directory.
[BackupPC.git] / cgi-bin / BackupPC_Admin
index 63f03af..85d8807 100755 (executable)
@@ -360,6 +360,9 @@ sub Action_View
         $comment = "(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";
         if ( open(LOG, $file) ) {
@@ -402,7 +405,8 @@ sub Action_View
             while ( 1 ) {
                 $_ = $fh->readLine();
                 if ( $_ eq "" ) {
-                   print(eval ("qq{$Lang->{skipped__skipped_lines}}"));
+                   print(eval ("qq{$Lang->{skipped__skipped_lines}}"))
+                                                   if ( $skipped );
                    last;
                }
                 if ( /smb: \\>/
@@ -425,7 +429,8 @@ sub Action_View
                    $skipped++;
                    next;
                }
-               print(eval("qq{$Lang->{skipped__skipped_lines}}")) if ( $skipped );
+               print(eval("qq{$Lang->{skipped__skipped_lines}}"))
+                                                    if ( $skipped );
                $skipped = 0;
                 print ${EscapeHTML($_)};
             }
@@ -598,10 +603,10 @@ sub Action_Browse
             my($dirOpen, $gotDir, $imgStr, $img);
             my $fURI = $f;                             # URI escaped $f
             my $shareURI = $share;                     # URI escaped $share
-            my $path = "$relDir/$f";
+            (my $path = "$relDir/$f") =~ s{//+}{/}g;
            if ( $shareURI eq "" ) {
                $shareURI = $path;
-               $path  = "";
+               $path  = "/";
            }
             $path =~ s{^/+}{/};
             $path     =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
@@ -708,9 +713,10 @@ EOF
         # Prune the last directory off $relDir, or at the very end
        # do the top-level directory.
         #
-       if ( $relDir eq "" ) {
+       if ( $relDir eq "" || $relDir eq "/" ) {
            $currDir = $share;
            $share = "";
+           $relDir = "";
        } else {
            $relDir =~ s/(.*)\/(.*)/$1/;
            $currDir = $2;
@@ -750,17 +756,16 @@ EOF
     }
     my @otherDirs;
     foreach my $i ( $view->backupList($share, $dir) ) {
-        next if ( $i == $num );
         my $path = $dir;
         my $shareURI = $share;
         $path =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
         $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
-        push(@otherDirs, <<EOF);
-<a href="$MyURL?action=browse&host=$host&num=$i&share=$shareURI&dir=$path">$i</a>
-EOF
+        push(@otherDirs, "<a href=\"$MyURL?action=browse&host=$host&num=$i"
+                       . "&share=$shareURI&dir=$path\">$i</a>");
+
     }
     if ( @otherDirs ) {
-       my $otherDirs  = join(", ", @otherDirs);
+       my $otherDirs  = join(",\n", @otherDirs);
         $filledBackup .= eval("qq{$Lang->{Visit_this_directory_in_backup}}");
     }
  
@@ -944,7 +949,7 @@ EOF
         Trailer();
     } elsif ( $In{type} == 4 ) {
        if ( !defined($Hosts->{$In{hostDest}}) ) {
-           ErrorExit(eval("qq{$Lang->{Host_doesn_t_exist}}"));
+           ErrorExit(eval("qq{$Lang->{Host__doesn_t_exist}}"));
        }
        if ( !CheckPermission($In{hostDest}) ) {
            ErrorExit(eval("qq{$Lang->{You_don_t_have_permission_to_restore_onto_host}}"));
@@ -1232,9 +1237,7 @@ EOF
     <td align="right">  $MBNew </td>
 </tr>
 EOF
-        $Backups[$i]{compress} ||= "off";
-       my $is_compress = $Lang->{off};
-       if ($Backups[$i]{compress} ne "off") {$is_compress = $Lang->{on}; }
+       my $is_compress = $Backups[$i]{compress} || $Lang->{off};
        if (! $ExistComp) { $ExistComp = "&nbsp;"; }
        if (! $MBExistComp) { $MBExistComp = "&nbsp;"; }
         $compStr .= <<EOF;
@@ -1603,8 +1606,12 @@ sub ErrorExit
                             if ( defined($bpc) );
     if ( !defined($Lang->{Error}) ) {
        Header("BackupPC: Error");
+        $mesg = <<EOF if ( !defined($mesg) );
+There is some problem with the BackupPC installation.
+Please check the permissions on BackupPC_Admin.
+EOF
        print <<EOF;
-${h1("Error: Language strings not defined!!")}
+${h1("Error: Unable to read config.pl or language strings!!")}
 <p>$mesg</p>
 EOF
        Trailer();
@@ -1739,7 +1746,6 @@ sub genPoolInfo
     my $poolTime   = timeStamp2($info->{"${name}Time"});
     $info->{"${name}FileCntRm"} = $info->{"${name}FileCntRm"} + 0;
     return eval("qq{$Lang->{Pool_Stat}}");
-
 }
 
 ###########################################################################
@@ -1761,8 +1767,10 @@ sub Header
         { link => "?action=queue",             name => $Lang->{Current_queues} },
         { link => "?action=view&type=docs",    name => $Lang->{Documentation},
                                                priv => 1},
+        { link => "http://backuppc.sourceforge.net/faq", name => "FAQ",
+                                               priv => 1},
         { link => "http://backuppc.sourceforge.net", name => "SourceForge",
-                                                     priv => 1},
+                                               priv => 1},
     );
     print $Cgi->header();
     print <<EOF;