]>
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) 2007 Michael Tremer & Christian Schmidt #
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';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
33 my %mainsettings = ();
37 my $errormessage = "";
41 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
42 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
44 $cgiparams{'ACTION'} = '';
45 $cgiparams{'FILE'} = '';
46 $cgiparams{'UPLOAD'} = '';
47 $cgiparams{'BACKUPLOGS'} = '';
49 &Header
::getcgihash
(\
%cgiparams);
51 ############################################################################################################################
52 ################################################ Workaround for Directories ################################################
54 system("/usr/local/bin/backupctrl makedirs >/dev/null 2>&1 ") unless ( -e
'/var/ipfire/backup/addons');
56 ############################################################################################################################
57 ############################################## System calls ohne Http Header ###############################################
60 if ( $cgiparams{'ACTION'} eq "download" )
62 open(DLFILE
, "</var/ipfire/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
63 my @fileholder = <DLFILE
>;
64 print "Content-Type:application/x-download\n";
65 print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
69 if ( $cgiparams{'ACTION'} eq "downloadaddon" )
71 open(DLFILE
, "</var/ipfire/backup/addons/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
72 my @fileholder = <DLFILE
>;
73 print "Content-Type:application/x-download\n";
74 print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
78 elsif ( $cgiparams{'ACTION'} eq "restore" )
80 my $upload = $a->param("UPLOAD");
81 open UPLOADFILE
, ">/tmp/restore.ipf";
87 system("/usr/local/bin/backupctrl restore >/dev/null 2>&1");
89 elsif ( $cgiparams{'ACTION'} eq "restoreaddon" )
91 my $upload = $a->param("UPLOAD");
92 open UPLOADFILE
, ">/tmp/$cgiparams{'UPLOAD'}";
98 system("/usr/local/bin/backupctrl restoreaddon $cgiparams{'UPLOAD'} >/dev/null 2>&1");
101 &Header
::showhttpheaders
();
103 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
();}
105 &Header
::openpage
($Lang::tr
{'backup'}, 1, "");
106 &Header
::openbigbox
('100%', 'left', '', $errormessage);
108 ############################################################################################################################
109 ################################################### Default System calls ###################################################
111 if ( $cgiparams{'ACTION'} eq "backup" )
113 if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include >/dev/null 2>&1");}
114 else {system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");}
116 if ( $cgiparams{'ACTION'} eq "addonbackup" )
118 system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1");
120 elsif ( $cgiparams{'ACTION'} eq "delete" )
122 system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1");
125 ############################################################################################################################
126 ############################################ Backups des Systems erstellen #################################################
128 if ( $message ne "" ){
129 &Header
::openbox
('100%','left',$Lang::tr
{'error messages'});
130 print "<font color='red'>$message</font>\n";
134 my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
136 &Header
::openbox
('100%', 'center', $Lang::tr
{'backup'});
139 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
140 <table width='95%' cellspacing='0'>
141 <tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>include Logfiles
142 <input type='radio' name='BACKUPLOGS' value='include'/>/
143 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> exclude Logfiles
145 <tr><td align='center' colspan='2'>
146 <input type='hidden' name='ACTION' value='backup' />
147 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
155 ############################################################################################################################
156 ############################################ Backups des Systems downloaden ################################################
158 &Header
::openbox
('100%', 'center', $Lang::tr
{'backups'});
161 <table width='95%' cellspacing='0'>
166 my $Datei = "/var/ipfire/backup/".$_;
167 my @Info = stat($Datei);
168 my $Size = $Info[7] / 1024;
169 $Size = sprintf("%02d", $Size);
170 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>";
171 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>";
179 ############################################################################################################################
180 ############################################# Backups von Addons erstellen #################################################
182 &Header
::openbox
('100%', 'center', 'addons');
184 my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`;
185 my %addons = `ls /var/ipfire/backup/addons/backup/ 2>/dev/null`;
187 print "<table width='95%' cellspacing='0'>";
188 foreach (@addonincluds){
190 delete($addons{$_."\.ipf\n"});
191 my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
192 my @Info = stat($Datei);
193 my $Size = $Info[7] / 1024;
194 $Size = sprintf("%2d", $Size);
196 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
198 <td align='right' width='5'>
199 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
200 <input type='hidden' name='ACTION' value='downloadaddon' />
201 <input type='hidden' name='FILE' value='$_.ipf' />
202 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
205 <td align='right' width='5'>
206 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
207 <input type='hidden' name='ACTION' value='delete' />
208 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
209 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
216 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td width='5' align='right'></td><td width='5' align='right'></td>";
219 <td align='right' width='5'>
220 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
221 <input type='hidden' name='ACTION' value='addonbackup' />
222 <input type='hidden' name='ADDON' value='$_' />
223 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
229 foreach (keys(%addons)){
231 my $Datei = "/var/ipfire/backup/addons/backup/".$_;
232 my @Info = stat($Datei);
233 my $Size = $Info[7] / 1024;
234 $Size = sprintf("%2d", $Size);
235 my $addon=substr($_,0,length($_)-4);
236 print "<tr><td align='center'>$Lang::tr{'backup from'} $addon $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
238 <td align='right' width='5'>
239 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
240 <input type='hidden' name='ACTION' value='downloadaddon' />
241 <input type='hidden' name='FILE' value='$_' />
242 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
245 <td align='right' width='5'>
246 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
247 <input type='hidden' name='ACTION' value='delete' />
248 <input type='hidden' name='FILE' value='addons/backup/$_' />
249 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
252 <td align='right' width='5'></td></tr>
260 ############################################################################################################################
261 ####################################### Backups des Systems wiederherstellen ###############################################
263 &Header
::openbox
('100%', 'center', $Lang::tr
{'restore'});
266 <table width='95%' cellspacing='0'>
267 <tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
268 <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>
269 <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' value='$_' /><input type='image' alt='$Lang::tr{'restore'}' title='$Lang::tr{'restore'}' src='/images/media-floppy.png' /></form></td></tr>
274 &Header
::closebigbox
();
275 &Header
::closepage
();