added only_increment param to all action=browse links
[BackupPC.git] / lib / BackupPC / CGI / LOGlist.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::CGI::LOGlist package
4 #
5 # DESCRIPTION
6 #
7 #   This module implements the LOGlist action for the CGI interface.
8 #
9 # AUTHOR
10 #   Craig Barratt  <cbarratt@users.sourceforge.net>
11 #
12 # COPYRIGHT
13 #   Copyright (C) 2003-2009  Craig Barratt
14 #
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.
19 #
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.
24 #
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
28 #
29 #========================================================================
30 #
31 # Version 3.2.0, released 31 Jul 2010.
32 #
33 # See http://backuppc.sourceforge.net.
34 #
35 #========================================================================
36
37 package BackupPC::CGI::LOGlist;
38
39 use strict;
40 use BackupPC::CGI::Lib qw(:all);
41
42 sub action
43 {
44     my $Privileged = CheckPermission($In{host});
45
46     if ( !$Privileged ) {
47         ErrorExit($Lang->{Only_privileged_users_can_view_log_files});
48     }
49     my $host = $In{host};
50     my($url0, $hdr, @files, $str);
51     if ( $host ne "" ) {
52         $url0 = "&host=${EscURI($host)}";
53         $hdr = "for host $host";
54     } else {
55         $url0 = "";
56         $hdr = "";
57     }
58
59     foreach my $file ( $bpc->sortedPCLogFiles($host) ) {
60         my $url1 = "&num=$1" if ( $file =~ /LOG\.(\d+)(\.z)?$/ );
61         $url1    = "&num="   if ( $file =~ /LOG(\.z)?$/ );
62         next if ( !-f $file );
63         my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
64         my $size     = (stat($file))[7];
65         (my $fStr    = $file) =~ s{.*/}{};
66         $str .= <<EOF;
67 <tr><td> <a href="$MyURL?action=view&type=LOG$url0$url1"><tt>$fStr</tt></a></td>
68     <td align="right"> $size </td>
69     <td> $mtimeStr </td></tr>
70 EOF
71     }
72     my $content = eval("qq{$Lang->{Log_File_History__hdr}}");
73     Header($Lang->{BackupPC__Log_File_History},
74                 $content, !-f "$TopDir/pc/$host/backups");
75     Trailer();
76 }
77
78 sub compareLOGName
79 {
80     #my($a, $b) = @_;
81
82     my $na = $1 if ( $a =~ /LOG\.(\d+)/ );
83     my $nb = $1 if ( $b =~ /LOG\.(\d+)/ );
84
85     if ( length($na) >= 5 && length($nb) >= 5 ) {
86         #
87         # Both new style.  Bigger numbers are more recent.
88         #
89         return $nb <=> $na;
90     } elsif ( length($na) >= 5 && length($nb) < 5 ) {
91         return -1;
92     } elsif ( length($na) < 5 && length($nb) >= 5 ) {
93         return 1;
94     } else {
95         #
96         # Both old style.  Smaller numbers are more recent.
97         #
98         return $na - $nb;
99     }
100 }
101
102
103 1;