]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/backup.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2013 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
23 # enable only the following on debugging purpose
25 #use CGI::Carp 'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
34 my %mainsettings = ();
38 my $errormessage = "";
44 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
45 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
47 $cgiparams{'ACTION'} = '';
48 $cgiparams{'FILE'} = '';
49 $cgiparams{'UPLOAD'} = '';
50 $cgiparams{'BACKUPLOGS'} = '';
52 &Header
::getcgihash
(\
%cgiparams);
54 ############################################################################################################################
55 ################################################ Workaround for Directories ################################################
57 system("/usr/local/bin/backupctrl makedirs >/dev/null 2>&1 ") unless ( -e
'/var/ipfire/backup/addons/backup') ;
59 ############################################################################################################################
60 ############################################## System calls ohne Http Header ###############################################
62 if ($cgiparams{'ACTION'} eq "download") {
63 my $file = &sanitise_file
($cgiparams{'FILE'});
64 exit(1) unless defined($file);
68 } elsif ($cgiparams{'ACTION'} eq "downloadiso") {
69 my $file = &sanitise_file
($cgiparams{'FILE'});
70 exit(1) unless defined($file);
74 } elsif ($cgiparams{'ACTION'} eq "downloadaddon") {
75 my $file = &sanitise_file
($cgiparams{'FILE'});
76 exit(1) unless defined($file);
80 } elsif ( $cgiparams{'ACTION'} eq "restore") {
81 my $upload = $a->param("UPLOAD");
82 open UPLOADFILE
, ">/tmp/restore.ipf";
88 system("/usr/local/bin/backupctrl restore >/dev/null 2>&1");
90 elsif ( $cgiparams{'ACTION'} eq "restoreaddon" )
92 chomp($cgiparams{'UPLOAD'});
93 # we need to fix cause IE7 gives the full path and FF only the filename
94 my @temp = split(/\\/,$cgiparams{'UPLOAD'});
95 my $upload = $a->param("UPLOAD");
96 open UPLOADFILE
, ">/tmp/".$temp[$#temp];
102 system("/usr/local/bin/backupctrl restoreaddon ".$temp[$#temp]." >/dev/null 2>&1");
105 &Header
::showhttpheaders
();
107 sub refreshpage
{&Header
::openbox
( 'Waiting', 1, "<meta http-equiv='refresh' content='1;'>" );print "<center><img src='/images/clock.gif' alt='' /><br/><font color='red'>$Lang::tr{'pagerefresh'}</font></center>";&Header
::closebox
();}
109 &Header
::openpage
($Lang::tr
{'backup'}, 1, "");
110 &Header
::openbigbox
('100%', 'left', '', $errormessage);
112 ############################################################################################################################
113 ################################################### Default System calls ###################################################
115 if ( $cgiparams{'ACTION'} eq "backup" )
117 if ( $cgiparams{'BACKUPLOGS'} eq "include" ) {
118 system("/usr/local/bin/backupctrl include >/dev/null 2>&1");
119 } elsif ( $cgiparams{'BACKUPLOGS'} eq "exclude" ) {
120 system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");
121 } elsif ( $cgiparams{'BACKUPLOGS'} eq "iso" ) {
122 system("/usr/local/bin/backupctrl iso >/dev/null 2>&1");
125 if ( $cgiparams{'ACTION'} eq "addonbackup" )
127 # Exit if there is any dots or slashes in the addon name
128 exit(1) if ($cgiparams{'ADDON'} =~ /(\.|\/)/);
130 # Check if the addon exists
131 exit(1) unless (-e
"/var/ipfire/backup/addons/includes/$cgiparams{'ADDON'}");
133 system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1");
135 elsif ( $cgiparams{'ACTION'} eq "delete" )
137 my $file = &sanitise_file
($cgiparams{'FILE'});
138 exit(1) unless defined($file);
140 $file = &File
::Basename
::basename
($file);
142 system("/usr/local/bin/backupctrl $file >/dev/null 2>&1");
145 ############################################################################################################################
146 ############################################ Backups des Systems erstellen #################################################
148 if ( $message ne "" ){
149 &Header
::openbox
('100%','left',$Lang::tr
{'error messages'});
150 print "<font color='red'>$message</font>\n";
154 if ( -e
"/var/ipfire/backup/" ){
155 @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
158 if ( -e
"/var/tmp/backupiso/" ){
159 @backupisos = `cd /var/tmp/backupiso/ && ls *.iso 2>/dev/null`;
162 &Header
::openbox
('100%', 'center', );
165 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
166 <table width='95%' cellspacing='0'>
168 <td align='left' width='40%'>$Lang::tr{'logs'}</td>
170 <input type='radio' name='BACKUPLOGS' value='include'/> $Lang::tr{'include logfiles'}<br/>
171 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> $Lang::tr{'exclude logfiles'}<br/>
174 my $MACHINE=`uname -m`;
175 if ( ! ( $MACHINE =~ "arm" )) {
176 print" <input type='radio' name='BACKUPLOGS' value='iso' /> $Lang::tr{'generate iso'}<br/>"
181 <tr><td align='center' colspan='2'>
182 <input type='hidden' name='ACTION' value='backup' />
183 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
191 ############################################################################################################################
192 ############################################ Backups des Systems downloaden ################################################
194 &Header
::openbox
('100%', 'center', $Lang::tr
{'backups'});
197 <table width='95%' cellspacing='0'>
201 if ( $_ !~ /ipf$/){next;}
203 my $Datei = "/var/ipfire/backup/".$_;
204 my @Info = stat($Datei);
205 my $Size = $Info[7] / 1024 / 1024;
206 $Size = sprintf("%0.2f", $Size);
207 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>";
208 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>";
210 foreach (@backupisos){
211 if ( $_ !~ /iso$/){next;}
213 my $Datei = "/var/tmp/backupiso/".$_;
214 my @Info = stat($Datei);
215 my $Size = $Info[7] / 1024 / 1024;
216 $Size = sprintf("%0.2f", $Size);
217 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>";
218 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>";
226 ############################################################################################################################
227 ############################################# Backups von Addons erstellen #################################################
229 &Header
::openbox
('100%', 'center', $Lang::tr
{'addons'});
231 my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`;
232 my @addons = `ls /var/ipfire/backup/addons/backup/ 2>/dev/null`;
236 my $addon=substr($_,0,length($_)-5);
240 print "<table width='95%' cellspacing='0'>";
241 foreach (@addonincluds){
244 my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
245 my @Info = stat($Datei);
246 my $Size = $Info[7] / 1024;
250 $Size = sprintf("%.2f", $Size);
251 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
253 $Size = sprintf("%2d", $Size);
254 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
259 <td align='right' width='5'>
260 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
261 <input type='hidden' name='ACTION' value='downloadaddon' />
262 <input type='hidden' name='FILE' value='$_.ipf' />
263 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
266 <td align='right' width='5'>
267 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
268 <input type='hidden' name='ACTION' value='delete' />
269 <input type='hidden' name='FILE' value='addons//backup/$_.ipf' />
270 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
277 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td width='5' align='right'></td><td width='5' align='right'></td>";
280 <td align='right' width='5'>
281 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
282 <input type='hidden' name='ACTION' value='addonbackup' />
283 <input type='hidden' name='ADDON' value='$_' />
284 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
290 foreach (keys(%addons)){
292 my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
293 my @Info = stat($Datei);
294 my $Size = $Info[7] / 1024;
295 $Size = sprintf("%2d", $Size);
296 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
298 <td align='right' width='5'>
299 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
300 <input type='hidden' name='ACTION' value='downloadaddon' />
301 <input type='hidden' name='FILE' value='$_.ipf' />
302 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
305 <td align='right' width='5'>
306 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
307 <input type='hidden' name='ACTION' value='delete' />
308 <input type='hidden' name='FILE' value='addons//backup/$_.ipf' />
309 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
312 <td align='right' width='5'></td></tr>
320 ############################################################################################################################
321 ####################################### Backups des Systems wiederherstellen ###############################################
323 &Header
::openbox
('100%', 'center', $Lang::tr
{'restore'});
326 <table width='95%' cellspacing='0'>
327 <tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
328 <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>
329 <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>
334 &Header
::closebigbox
();
335 &Header
::closepage
();
337 sub sanitise_file
() {
340 # Filenames cannot contain any slashes
341 return undef if ($file =~ /\//);
343 # File must end with .ipf or .iso
344 return undef unless ($file =~ /\.(ipf|iso)$/);
346 # Convert to absolute path
347 if (-e
"/var/ipfire/backup/$file") {
348 return "/var/ipfire/backup/$file";
349 } elsif (-e
"/var/ipfire/backup/addons/backup/$file") {
350 return "/var/ipfire/backup/addons/backup/$file";
351 } elsif (-e
"/var/tmp/backupiso/$file") {
352 return "/var/tmp/backupiso/$file";
355 # File does not seem to exist
361 my @stat = stat($file);
364 print "Content-Disposition: attachment; filename=" . &File
::Basename
::basename
($file) . "\n";
365 print "Content-Type: application/octet-stream\n";
366 print "Content-Length: $stat[7]\n";
370 open(FILE
, "<$file") or die "Unable to open $file: $!";