###############################################################################
# #
# IPFire.org - A linux based firewall #
-# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
+# Copyright (C) 2005-2013 IPFire Team <info@ipfire.org> #
# #
# 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 #
my %checked = ();
my $message = "";
my $errormessage = "";
-my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
+my @backups = "";
+my @backupisos = "";
$a = new CGI;
&Header::getcgihash(\%cgiparams);
+############################################################################################################################
+################################################ Workaround for Directories ################################################
+
+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, "</var/ipfire/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
- my @fileholder = <DLFILE>;
- print "Content-Type:application/x-download\n";
- print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
- print @fileholder;
- exit (0);
+ open(DLFILE, "</var/ipfire/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
+ my @fileholder = <DLFILE>;
+ print "Content-Type:application/x-download\n";
+ my @fileinfo = stat("/var/ipfire/backup/$cgiparams{'FILE'}");
+ print "Content-Length:$fileinfo[7]\n";
+ print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
+ print @fileholder;
+ exit (0);
+}
+if ( $cgiparams{'ACTION'} eq "downloadiso" )
+{
+ open(DLFILE, "</var/tmp/backupiso/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
+ my @fileholder = <DLFILE>;
+ print "Content-Type:application/x-download\n";
+ my @fileinfo = stat("/var/tmp/backupiso/$cgiparams{'FILE'}");
+ print "Content-Length:$fileinfo[7]\n";
+ print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
+ print @fileholder;
+ exit (0);
+}
+if ( $cgiparams{'ACTION'} eq "downloadaddon" )
+{
+ open(DLFILE, "</var/ipfire/backup/addons/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
+ my @fileholder = <DLFILE>;
+ print "Content-Type:application/x-download\n";
+ my @fileinfo = stat("/var/ipfire/backup/addons/backup/$cgiparams{'FILE'}");
+ print "Content-Length:$fileinfo[7]\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 >/dev/null 2>&1");
+ 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");
}
&Header::showhttpheaders();
if ( $cgiparams{'ACTION'} eq "backup" )
{
- if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include >/dev/null 2>&1");}
- else {system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");}
- refreshpage();
+ 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");
- refreshpage();
+ system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1");
}
############################################################################################################################
-########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค
+############################################ Backups des Systems erstellen #################################################
if ( $message ne "" ){
&Header::openbox('100%','left',$Lang::tr{'error messages'});
&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 <<END
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
<table width='95%' cellspacing='0'>
-<tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>include Logfiles <input type='radio' name='BACKUPLOGS' value='include'/>/
- <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> exclude Logfiles</td></tr>
-<tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='backup' />
- <input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/document-save.png' /></td></tr>
+<tr>
+ <td align='left' width='40%'>$Lang::tr{'logs'}</td>
+ <td align='left'>
+ <input type='radio' name='BACKUPLOGS' value='include'/> $Lang::tr{'include logfiles'}<br/>
+ <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> $Lang::tr{'exclude logfiles'}<br/>
+END
+;
+my $MACHINE=`uname -m`;
+if ( ! ( $MACHINE =~ "arm" )) {
+ print" <input type='radio' name='BACKUPLOGS' value='iso' /> $Lang::tr{'generate iso'}<br/>"
+}
+print <<END
+ </td>
+</tr>
+<tr><td align='center' colspan='2'>
+ <input type='hidden' name='ACTION' value='backup' />
+ <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
+</td></tr>
</table>
</form>
END
;
&Header::closebox();
+############################################################################################################################
+############################################ Backups des Systems downloaden ################################################
+
&Header::openbox('100%', 'center', $Lang::tr{'backups'});
print <<END
END
;
foreach (@backups){
+if ( $_ !~ /ipf$/){next;}
chomp($_);
my $Datei = "/var/ipfire/backup/".$_;
my @Info = stat($Datei);
-my $Size = $Info[7] / 1024;
-$Size = sprintf("%02d", $Size);
-print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB</td><td width='5'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='download' /><input type='hidden' name='FILE' value='$_' /><input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' /></form></td>";
+my $Size = $Info[7] / 1024 / 1024;
+$Size = sprintf("%0.2f", $Size);
+print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size MB</td><td width='5'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='download' /><input type='hidden' name='FILE' value='$_' /><input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' /></form></td>";
print "<td width='5'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='delete' /><input type='hidden' name='FILE' value='$_' /><input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /></form></td></tr>";
}
-print <<END
+foreach (@backupisos){
+if ( $_ !~ /iso$/){next;}
+chomp($_);
+my $Datei = "/var/tmp/backupiso/".$_;
+my @Info = stat($Datei);
+my $Size = $Info[7] / 1024 / 1024;
+$Size = sprintf("%0.2f", $Size);
+print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size MB</td><td width='5'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='downloadiso' /><input type='hidden' name='FILE' value='$_' /><input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' /></form></td>";
+print "<td width='5'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='delete' /><input type='hidden' name='FILE' value='$_' /><input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /></form></td></tr>";
+}
+print <<END
</table>
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 "<table width='95%' cellspacing='0'>";
+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 "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
+ } else {
+ $Size = sprintf("%2d", $Size);
+ print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
+
+ }
+
+print <<END
+ <td align='right' width='5'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='downloadaddon' />
+ <input type='hidden' name='FILE' value='$_.ipf' />
+ <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
+ </form>
+ </td>
+ <td align='right' width='5'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='delete' />
+ <input type='hidden' name='FILE' value='addons//backup/$_.ipf' />
+ <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
+ </form>
+ </td>
+END
+;
+}
+else{
+ print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td width='5' align='right'></td><td width='5' align='right'></td>";
+}
+print <<END
+ <td align='right' width='5'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='addonbackup' />
+ <input type='hidden' name='ADDON' value='$_' />
+ <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
+ </form>
+ </td></tr>
+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 "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
+print <<END
+ <td align='right' width='5'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='downloadaddon' />
+ <input type='hidden' name='FILE' value='$_.ipf' />
+ <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
+ </form>
+ </td>
+ <td align='right' width='5'>
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='delete' />
+ <input type='hidden' name='FILE' value='addons//backup/$_.ipf' />
+ <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
+ </form>
+ </td>
+ <td align='right' width='5'></td></tr>
+END
+;
+}
+
+print "</table>";
+&Header::closebox();
+
+############################################################################################################################
+####################################### Backups des Systems wiederherstellen ###############################################
+
&Header::openbox('100%', 'center', $Lang::tr{'restore'});
print <<END
<table width='95%' cellspacing='0'>
-<tr><td align='left'>$Lang::tr{'backup'}</td><td align='left'><form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'><input type="file" size='50' name="UPLOAD" /><input type='hidden' name='ACTION' value='restore' /><input type='hidden' name='FILE' value='$_' /><input type='image' alt='$Lang::tr{'restore'}' title='$Lang::tr{'restore'}' src='/images/media-floppy.png' /></form></td></tr>
+<tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
+<tr><td align='left'>$Lang::tr{'backup'}</td><td align='left'><form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'><input type="file" size='50' name="UPLOAD" /><input type='hidden' name='ACTION' value='restore' /><input type='hidden' name='FILE' /><input type='image' alt='$Lang::tr{'restore'}' title='$Lang::tr{'restore'}' src='/images/media-floppy.png' /></form></td></tr>
+<tr><td align='left'>$Lang::tr{'backupaddon'}</td><td align='left'><form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'><input type="file" size='50' name="UPLOAD" /><input type='hidden' name='ACTION' value='restoreaddon' /><input type='hidden' name='FILE' /><input type='image' alt='$Lang::tr{'restore'}' title='$Lang::tr{'restore'}' src='/images/media-floppy.png' /></form></td></tr>
</table>
END
;
&Header::closebox();
&Header::closebigbox();
-&Header::closepage();
+&Header::closepage();
\ No newline at end of file