1 #=============================================================
3 # BackupPC::CGI::RSS package
7 # This module implements an RSS page for the CGI interface.
10 # Rich Duzenbury (rduz at theduz dot com)
13 # Copyright (C) 2005-2007 Rich Duzenbury and 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 3.1.0, released 25 Nov 2007.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::RSS;
40 use BackupPC::CGI::Lib qw(:all);
45 my $base_url = 'http://' . $ENV{'SERVER_NAME'} . $ENV{SCRIPT_NAME};
47 my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
48 $strNone, $strGood, $hostCntGood, $hostCntNone);
50 binmode(STDOUT, ":utf8");
52 my $rss = new XML::RSS (version => '0.91',
55 $rss->channel( title => eval("qq{$Lang->{RSS_Doc_Title}}"),
57 language => $Conf{Language},
58 description => eval("qq{$Lang->{RSS_Doc_Description}}"),
61 $hostCntGood = $hostCntNone = 0;
62 GetStatusInfo("hosts");
63 my $Privileged = CheckPermission();
65 foreach my $host ( GetUserHosts(1) ) {
66 my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate, $reasonHilite);
68 my @Backups = $bpc->BackupInfoRead($host);
69 my $fullCnt = $incrCnt = 0;
70 my $fullAge = $incrAge = -1;
72 $bpc->ConfigRead($host);
75 next if ( $Conf{XferMethod} eq "archive" );
76 next if ( !$Privileged && !CheckPermission($host) );
78 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
79 if ( $Backups[$i]{type} eq "full" ) {
81 if ( $fullAge < 0 || $Backups[$i]{startTime} > $fullAge ) {
82 $fullAge = $Backups[$i]{startTime};
83 $fullSize = $Backups[$i]{size} / (1024 * 1024);
84 $fullDur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
86 $fullSizeTot += $Backups[$i]{size} / (1024 * 1024);
89 if ( $incrAge < 0 || $Backups[$i]{startTime} > $incrAge ) {
90 $incrAge = $Backups[$i]{startTime};
92 $incrSizeTot += $Backups[$i]{size} / (1024 * 1024);
99 $fullAge = sprintf("%.1f", (time - $fullAge) / (24 * 3600));
100 $fullRate = sprintf("%.2f",
101 $fullSize / ($fullDur <= 0 ? 1 : $fullDur));
103 if ( $incrAge < 0 ) {
106 $incrAge = sprintf("%.1f", (time - $incrAge) / (24 * 3600));
108 $fullTot += $fullCnt;
109 $incrTot += $incrCnt;
110 $fullSize = sprintf("%.2f", $fullSize / 1000);
111 $incrAge = " " if ( $incrAge eq "" );
112 $reasonHilite = $Conf{CgiStatusHilightColor}{$Status{$host}{reason}}
113 || $Conf{CgiStatusHilightColor}{$Status{$host}{state}};
114 $reasonHilite = " bgcolor=\"$reasonHilite\"" if ( $reasonHilite ne "" );
115 if ( $Status{$host}{state} ne "Status_backup_in_progress"
116 && $Status{$host}{state} ne "Status_restore_in_progress"
117 && $Status{$host}{error} ne "" ) {
118 ($shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;
119 $shortErr = " ($shortErr)";
122 my $host_state = $Lang->{$Status{$host}{state}};
123 my $host_last_attempt = $Lang->{$Status{$host}{reason}} . $shortErr;
125 $str = eval("qq{$Lang->{RSS_Host_Summary}}");
127 $rss->add_item(title => $host . ', ' .
130 link => $base_url . '?host=' . $host,
131 description => $str);
134 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
135 $incrSizeTot = sprintf("%.2f", $incrSizeTot / 1000);
136 my $now = timeStamp2(time);
138 print 'Content-type: text/xml', "\r\n\r\n",