]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - html/cgi-bin/backup.cgi
corrected some smaller bugs in some cgiŽs
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / backup.cgi
... / ...
CommitLineData
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
22use strict;
23# enable only the following on debugging purpose
24use warnings;
25use CGI::Carp 'fatalsToBrowser';
26use File::Copy;
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
32my %color = ();
33my %mainsettings = ();
34my %cgiparams=();
35my %checked = ();
36my $message = "";
37my $errormessage = "";
38
39$a = new CGI;
40
41&General::readhash("${General::swroot}/main/settings", \%mainsettings);
42&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
43
44$cgiparams{'ACTION'} = '';
45$cgiparams{'FILE'} = '';
46$cgiparams{'UPLOAD'} = '';
47$cgiparams{'BACKUPLOGS'} = '';
48
49&Header::getcgihash(\%cgiparams);
50
51############################################################################################################################
52################################################ Workaround for Directories ################################################
53
54system("/usr/local/bin/backupctrl makedirs >/dev/null 2>&1 ") unless ( -e '/var/ipfire/backup/addons');
55
56############################################################################################################################
57############################################## System calls ohne Http Header ###############################################
58
59
60if ( $cgiparams{'ACTION'} eq "download" )
61{
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";
66 print @fileholder;
67 exit (0);
68}
69if ( $cgiparams{'ACTION'} eq "downloadaddon" )
70{
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";
75 print @fileholder;
76 exit (0);
77}
78elsif ( $cgiparams{'ACTION'} eq "restore" )
79{
80 my $upload = $a->param("UPLOAD");
81 open UPLOADFILE, ">/tmp/restore.ipf";
82 binmode $upload;
83 while ( <$upload> ) {
84 print UPLOADFILE;
85 }
86 close UPLOADFILE;
87 system("/usr/local/bin/backupctrl restore >/dev/null 2>&1");
88}
89elsif ( $cgiparams{'ACTION'} eq "restoreaddon" )
90{
91 chomp($cgiparams{'UPLOAD'});
92 # we need to fix cause IE7 gives the full path and FF only the filename
93 my @temp = split(/\\/,$cgiparams{'UPLOAD'});
94 my $upload = $a->param("UPLOAD");
95 open UPLOADFILE, ">/tmp/".$temp[$#temp];
96 binmode $upload;
97 while ( <$upload> ) {
98 print UPLOADFILE;
99 }
100 close UPLOADFILE;
101 system("/usr/local/bin/backupctrl restoreaddon ".$temp[$#temp]." >/dev/null 2>&1");
102}
103
104&Header::showhttpheaders();
105
106sub 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();}
107
108&Header::openpage($Lang::tr{'backup'}, 1, "");
109&Header::openbigbox('100%', 'left', '', $errormessage);
110
111############################################################################################################################
112################################################### Default System calls ###################################################
113
114if ( $cgiparams{'ACTION'} eq "backup" )
115{
116 if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include >/dev/null 2>&1");}
117 else {system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");}
118}
119if ( $cgiparams{'ACTION'} eq "addonbackup" )
120{
121 system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1");
122}
123elsif ( $cgiparams{'ACTION'} eq "delete" )
124{
125 system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1");
126}
127
128############################################################################################################################
129############################################ Backups des Systems erstellen #################################################
130
131if ( $message ne "" ){
132 &Header::openbox('100%','left',$Lang::tr{'error messages'});
133 print "<font color='red'>$message</font>\n";
134 &Header::closebox();
135}
136
137my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
138
139&Header::openbox('100%', 'center', $Lang::tr{'backup'});
140
141print <<END
142<form method='post' action='$ENV{'SCRIPT_NAME'}'>
143<table width='95%' cellspacing='0'>
144<tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>$Lang::tr{'include logfiles'}
145 <input type='radio' name='BACKUPLOGS' value='include'/>/
146 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/>$Lang::tr{'exclude logfiles'}
147</td></tr>
148<tr><td align='center' colspan='2'>
149 <input type='hidden' name='ACTION' value='backup' />
150 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
151</td></tr>
152</table>
153</form>
154END
155;
156&Header::closebox();
157
158############################################################################################################################
159############################################ Backups des Systems downloaden ################################################
160
161&Header::openbox('100%', 'center', $Lang::tr{'backups'});
162
163print <<END
164<table width='95%' cellspacing='0'>
165END
166;
167foreach (@backups){
168chomp($_);
169my $Datei = "/var/ipfire/backup/".$_;
170my @Info = stat($Datei);
171my $Size = $Info[7] / 1024;
172$Size = sprintf("%02d", $Size);
173print "<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>";
174print "<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>";
175}
176print <<END
177</table>
178END
179;
180&Header::closebox();
181
182############################################################################################################################
183############################################# Backups von Addons erstellen #################################################
184
185&Header::openbox('100%', 'center', 'addons');
186
187my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`;
188my @addons = `ls /var/ipfire/backup/addons/backup/ 2>/dev/null`;
189my %addons;
190
191foreach (@addons){
192 my $addon=substr($_,0,length($_)-5);
193 $addons{$addon}='';
194}
195
196print "<table width='95%' cellspacing='0'>";
197foreach (@addonincluds){
198chomp($_);
199delete $addons{$_};
200my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
201my @Info = stat($Datei);
202my $Size = $Info[7] / 1024;
203$Size = sprintf("%2d", $Size);
204if ( -e $Datei ){
205print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
206print <<END
207 <td align='right' width='5'>
208 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
209 <input type='hidden' name='ACTION' value='downloadaddon' />
210 <input type='hidden' name='FILE' value='$_.ipf' />
211 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
212 </form>
213 </td>
214 <td align='right' width='5'>
215 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
216 <input type='hidden' name='ACTION' value='delete' />
217 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
218 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
219 </form>
220 </td>
221END
222;
223}
224else{
225 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td width='5' align='right'></td><td width='5' align='right'></td>";
226}
227print <<END
228 <td align='right' width='5'>
229 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
230 <input type='hidden' name='ACTION' value='addonbackup' />
231 <input type='hidden' name='ADDON' value='$_' />
232 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
233 </form>
234 </td></tr>
235END
236;
237}
238foreach (keys(%addons)){
239chomp($_);
240my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
241my @Info = stat($Datei);
242my $Size = $Info[7] / 1024;
243$Size = sprintf("%2d", $Size);
244print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
245print <<END
246 <td align='right' width='5'>
247 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
248 <input type='hidden' name='ACTION' value='downloadaddon' />
249 <input type='hidden' name='FILE' value='$_.ipf' />
250 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
251 </form>
252 </td>
253 <td align='right' width='5'>
254 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
255 <input type='hidden' name='ACTION' value='delete' />
256 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
257 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
258 </form>
259 </td>
260 <td align='right' width='5'></td></tr>
261END
262;
263}
264
265print "</table>";
266&Header::closebox();
267
268############################################################################################################################
269####################################### Backups des Systems wiederherstellen ###############################################
270
271&Header::openbox('100%', 'center', $Lang::tr{'restore'});
272
273print <<END
274<table width='95%' cellspacing='0'>
275<tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
276<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>
277<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>
278</table>
279END
280;
281&Header::closebox();
282&Header::closebigbox();
283&Header::closepage();