X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fbackup.cgi;h=e526fc30e9c06d00f15ffa11afe63a3abd177ffc;hb=26906d98239bf79d9344e8f0796d5ca40d02ee73;hp=fbc96271b984db3b5c0d18b10dbd647d719bbc03;hpb=8e8bbd9da3bd20ce3871b92b8aab88ac7b880457;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/html/cgi-bin/backup.cgi b/html/cgi-bin/backup.cgi index fbc96271b9..e526fc30e9 100644 --- a/html/cgi-bin/backup.cgi +++ b/html/cgi-bin/backup.cgi @@ -1,15 +1,28 @@ #!/usr/bin/perl -# -# IPFire CGIs -# -# This code is distributed under the terms of the GPL -# -# (c) The IPFire Team +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2005-2010 IPFire Team # +# # +# 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 # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### use strict; # enable only the following on debugging purpose -use warnings; -use CGI::Carp 'fatalsToBrowser'; +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; use File::Copy; require '/var/ipfire/general-functions.pl'; @@ -22,7 +35,8 @@ my %cgiparams=(); my %checked = (); my $message = ""; my $errormessage = ""; -my @backups = `cd /srv/web/ipfire/html/backup && ls *.ipf`; +my @backups = ""; +my @backupisos = ""; $a = new CGI; @@ -33,65 +47,145 @@ $cgiparams{'ACTION'} = ''; $cgiparams{'FILE'} = ''; $cgiparams{'UPLOAD'} = ''; $cgiparams{'BACKUPLOGS'} = ''; + &Header::getcgihash(\%cgiparams); ############################################################################################################################ -######################################## Scanne Verzeichnisse nach Mp3 Dateien ############################################# +################################################ Workaround for Directories ################################################ -if ( $cgiparams{'ACTION'} eq "backup" ) +system("/usr/local/bin/backupctrl makedirs >/dev/null 2>&1 ") unless ( -e '/var/ipfire/backup/addons/backup') ; + +############################################################################################################################ +############################################## System calls ohne Http Header ############################################### + +# Replace slashes from filename +$cgiparams{'FILE'} =~ s/\///; + +if ( $cgiparams{'ACTION'} eq "download" ) +{ + open(DLFILE, "; + print "Content-Type:application/x-download\n"; + print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n"; + print @fileholder; + exit (0); +} +if ( $cgiparams{'ACTION'} eq "downloadiso" ) { - if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include");} - else {system("/usr/local/bin/backupctrl exclude");} + open(DLFILE, "; + print "Content-Type:application/x-download\n"; + print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n"; + print @fileholder; + exit (0); } -elsif ( $cgiparams{'ACTION'} eq "download" ) +if ( $cgiparams{'ACTION'} eq "downloadaddon" ) { - open(DLFILE, "; - print "Content-Type:application/x-download\n"; - print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n"; - print @fileholder; - exit (0); + open(DLFILE, "; + print "Content-Type:application/x-download\n"; + print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n"; + print @fileholder; + exit (0); } elsif ( $cgiparams{'ACTION'} eq "restore" ) { - my $upload = $a->param("UPLOAD"); - open UPLOADFILE, ">/tmp/restore.ipf"; - binmode $upload; - while ( <$upload> ) { - print UPLOADFILE; - } - close UPLOADFILE; - system("/usr/local/bin/backupctrl restore"); + my $upload = $a->param("UPLOAD"); + open UPLOADFILE, ">/tmp/restore.ipf"; + binmode $upload; + while ( <$upload> ) { + print UPLOADFILE; + } + close UPLOADFILE; + system("/usr/local/bin/backupctrl restore >/dev/null 2>&1"); +} +elsif ( $cgiparams{'ACTION'} eq "restoreaddon" ) +{ + chomp($cgiparams{'UPLOAD'}); + # we need to fix cause IE7 gives the full path and FF only the filename + my @temp = split(/\\/,$cgiparams{'UPLOAD'}); + my $upload = $a->param("UPLOAD"); + open UPLOADFILE, ">/tmp/".$temp[$#temp]; + binmode $upload; + while ( <$upload> ) { + print UPLOADFILE; + } + close UPLOADFILE; + system("/usr/local/bin/backupctrl restoreaddon ".$temp[$#temp]." >/dev/null 2>&1"); } - -############################################################################################################################ -########################################### rekursiv nach neuen Mp3s Scannen ##############################################ä &Header::showhttpheaders(); + +sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "

$Lang::tr{'pagerefresh'}
";&Header::closebox();} + &Header::openpage($Lang::tr{'backup'}, 1, ""); &Header::openbigbox('100%', 'left', '', $errormessage); +############################################################################################################################ +################################################### Default System calls ################################################### + +if ( $cgiparams{'ACTION'} eq "backup" ) +{ + if ( $cgiparams{'BACKUPLOGS'} eq "include" ) { + system("/usr/local/bin/backupctrl include >/dev/null 2>&1"); + } elsif ( $cgiparams{'BACKUPLOGS'} eq "exclude" ) { + system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1"); + } elsif ( $cgiparams{'BACKUPLOGS'} eq "iso" ) { + system("/usr/local/bin/backupctrl iso >/dev/null 2>&1"); + } +} +if ( $cgiparams{'ACTION'} eq "addonbackup" ) +{ + system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1"); +} +elsif ( $cgiparams{'ACTION'} eq "delete" ) +{ + system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1"); +} + +############################################################################################################################ +############################################ Backups des Systems erstellen ################################################# + if ( $message ne "" ){ &Header::openbox('100%','left',$Lang::tr{'error messages'}); print "$message\n"; &Header::closebox(); } +if ( -e "/var/ipfire/backup/" ){ + @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`; +} + +if ( -e "/var/tmp/backupiso/" ){ + @backupisos = `cd /var/tmp/backupiso/ && ls *.iso 2>/dev/null`; +} + &Header::openbox('100%', 'center', $Lang::tr{'backup'}); print < - - + + + + +
$Lang::tr{'logs'}include Logfiles / - exclude Logfiles
-
$Lang::tr{'logs'} + $Lang::tr{'include logfiles'}
+ $Lang::tr{'exclude logfiles'}
+ $Lang::tr{'generate iso'} +
+ + +
END ; &Header::closebox(); +############################################################################################################################ +############################################ Backups des Systems downloaden ################################################ + &Header::openbox('100%', 'center', $Lang::tr{'backups'}); print <$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size MB
"; +print "
"; +} +foreach (@backupisos){ chomp($_); -my $Datei = "/srv/web/ipfire/html/backup/".$_; +my $Datei = "/var/tmp/backupiso/".$_; my @Info = stat($Datei); -my $Size = $Info[7] / 1024; -$Size = sprintf("%02d", $Size); -print "
$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB
"; +my $Size = $Info[7] / 1024 / 1024; +$Size = sprintf("%0.2f", $Size); +print "$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size MB
"; +print "
"; } -print < END ; &Header::closebox(); +############################################################################################################################ +############################################# Backups von Addons erstellen ################################################# + +&Header::openbox('100%', 'center', 'addons'); + +my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`; +my @addons = `ls /var/ipfire/backup/addons/backup/ 2>/dev/null`; +my %addons; + +foreach (@addons){ + my $addon=substr($_,0,length($_)-5); + $addons{$addon}=''; +} + +print ""; +foreach (@addonincluds){ +chomp($_); +delete $addons{$_}; +my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf"; +my @Info = stat($Datei); +my $Size = $Info[7] / 1024; + +if ( -e $Datei ){ + if ($Size < 1) { + $Size = sprintf("%.2f", $Size); + print ""; + } else { + $Size = sprintf("%2d", $Size); + print ""; + + } + +print < +
+ + + + + +
+END +; +} +else{ + print ""; +} +print < +
+ + + + +
+END +; +} +foreach (keys(%addons)){ +chomp($_); +my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf"; +my @Info = stat($Datei); +my $Size = $Info[7] / 1024; +$Size = sprintf("%2d", $Size); +print ""; +print < +
+ + + + + +
+ +END +; +} + +print "
$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."
$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])." +
+ + + +
+
$Lang::tr{'backup from'} $_
$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])." +
+ + + +
+
"; +&Header::closebox(); + +############################################################################################################################ +####################################### Backups des Systems wiederherstellen ############################################### + &Header::openbox('100%', 'center', $Lang::tr{'restore'}); print < -
$Lang::tr{'backup'}
+
$Lang::tr{'backupwarning'}


+$Lang::tr{'backup'}
+$Lang::tr{'backupaddon'}
END ;