]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/backup.cgi
added backupiso to gui
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / backup.cgi
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
22 use strict;
23 # enable only the following on debugging purpose
24 #use warnings;
25 #use CGI::Carp 'fatalsToBrowser';
26 use File::Copy;
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31
32 my %color = ();
33 my %mainsettings = ();
34 my %cgiparams=();
35 my %checked = ();
36 my $message = "";
37 my $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
54 system("/usr/local/bin/backupctrl makedirs >/dev/null 2>&1 ") unless ( -e '/var/ipfire/backup/addons/backup') ;
55
56 ############################################################################################################################
57 ############################################## System calls ohne Http Header ###############################################
58
59
60 if ( $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 }
69 if ( $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 }
78 elsif ( $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 }
89 elsif ( $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
106 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();}
107
108 &Header::openpage($Lang::tr{'backup'}, 1, "");
109 &Header::openbigbox('100%', 'left', '', $errormessage);
110
111 ############################################################################################################################
112 ################################################### Default System calls ###################################################
113
114 if ( $cgiparams{'ACTION'} eq "backup" )
115 {
116 if ( $cgiparams{'BACKUPLOGS'} eq "include" ) {
117 system("/usr/local/bin/backupctrl include >/dev/null 2>&1");
118 } elsif ( $cgiparams{'BACKUPLOGS'} eq "exclude" ) {
119 system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");
120 } elsif ( $cgiparams{'BACKUPLOGS'} eq "iso" ) {
121 system("/usr/local/bin/backupctrl iso >/dev/null 2>&1");
122 }
123 }
124 if ( $cgiparams{'ACTION'} eq "addonbackup" )
125 {
126 system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1");
127 }
128 elsif ( $cgiparams{'ACTION'} eq "delete" )
129 {
130 system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1");
131 }
132
133 ############################################################################################################################
134 ############################################ Backups des Systems erstellen #################################################
135
136 if ( $message ne "" ){
137 &Header::openbox('100%','left',$Lang::tr{'error messages'});
138 print "<font color='red'>$message</font>\n";
139 &Header::closebox();
140 }
141
142 my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
143
144 &Header::openbox('100%', 'center', $Lang::tr{'backup'});
145
146 print <<END
147 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
148 <table width='95%' cellspacing='0'>
149 <tr>
150 <td align='left' width='40%'>$Lang::tr{'logs'}</td>
151 <td align='left'>
152 <input type='radio' name='BACKUPLOGS' value='include'/> $Lang::tr{'include logfiles'}<br/>
153 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> $Lang::tr{'exclude logfiles'}<br/>
154 <input type='radio' name='BACKUPLOGS' value='iso' /> $Lang::tr{'generate iso'}
155 </td>
156 </tr>
157 <tr><td align='center' colspan='2'>
158 <input type='hidden' name='ACTION' value='backup' />
159 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
160 </td></tr>
161 </table>
162 </form>
163 END
164 ;
165 &Header::closebox();
166
167 ############################################################################################################################
168 ############################################ Backups des Systems downloaden ################################################
169
170 &Header::openbox('100%', 'center', $Lang::tr{'backups'});
171
172 print <<END
173 <table width='95%' cellspacing='0'>
174 END
175 ;
176 foreach (@backups){
177 chomp($_);
178 my $Datei = "/var/ipfire/backup/".$_;
179 my @Info = stat($Datei);
180 my $Size = $Info[7] / 1024;
181 $Size = sprintf("%02d", $Size);
182 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>";
183 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>";
184 }
185 print <<END
186 </table>
187 END
188 ;
189 &Header::closebox();
190
191 ############################################################################################################################
192 ############################################# Backups von Addons erstellen #################################################
193
194 &Header::openbox('100%', 'center', 'addons');
195
196 my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`;
197 my @addons = `ls /var/ipfire/backup/addons/backup/ 2>/dev/null`;
198 my %addons;
199
200 foreach (@addons){
201 my $addon=substr($_,0,length($_)-5);
202 $addons{$addon}='';
203 }
204
205 print "<table width='95%' cellspacing='0'>";
206 foreach (@addonincluds){
207 chomp($_);
208 delete $addons{$_};
209 my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
210 my @Info = stat($Datei);
211 my $Size = $Info[7] / 1024;
212 $Size = sprintf("%2d", $Size);
213 if ( -e $Datei ){
214 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
215 print <<END
216 <td align='right' width='5'>
217 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
218 <input type='hidden' name='ACTION' value='downloadaddon' />
219 <input type='hidden' name='FILE' value='$_.ipf' />
220 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
221 </form>
222 </td>
223 <td align='right' width='5'>
224 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
225 <input type='hidden' name='ACTION' value='delete' />
226 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
227 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
228 </form>
229 </td>
230 END
231 ;
232 }
233 else{
234 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td width='5' align='right'></td><td width='5' align='right'></td>";
235 }
236 print <<END
237 <td align='right' width='5'>
238 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
239 <input type='hidden' name='ACTION' value='addonbackup' />
240 <input type='hidden' name='ADDON' value='$_' />
241 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
242 </form>
243 </td></tr>
244 END
245 ;
246 }
247 foreach (keys(%addons)){
248 chomp($_);
249 my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
250 my @Info = stat($Datei);
251 my $Size = $Info[7] / 1024;
252 $Size = sprintf("%2d", $Size);
253 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
254 print <<END
255 <td align='right' width='5'>
256 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
257 <input type='hidden' name='ACTION' value='downloadaddon' />
258 <input type='hidden' name='FILE' value='$_.ipf' />
259 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
260 </form>
261 </td>
262 <td align='right' width='5'>
263 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
264 <input type='hidden' name='ACTION' value='delete' />
265 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
266 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
267 </form>
268 </td>
269 <td align='right' width='5'></td></tr>
270 END
271 ;
272 }
273
274 print "</table>";
275 &Header::closebox();
276
277 ############################################################################################################################
278 ####################################### Backups des Systems wiederherstellen ###############################################
279
280 &Header::openbox('100%', 'center', $Lang::tr{'restore'});
281
282 print <<END
283 <table width='95%' cellspacing='0'>
284 <tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
285 <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>
286 <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>
287 </table>
288 END
289 ;
290 &Header::closebox();
291 &Header::closebigbox();
292 &Header::closepage();