]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/backup.cgi
Kleinere fixes an der Backup Routine
[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 ############################################## System calls ohne Http Header ###############################################
53
54
55 if ( $cgiparams{'ACTION'} eq "download" )
56 {
57 open(DLFILE, "</var/ipfire/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
58 my @fileholder = <DLFILE>;
59 print "Content-Type:application/x-download\n";
60 print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
61 print @fileholder;
62 exit (0);
63 }
64 if ( $cgiparams{'ACTION'} eq "downloadaddon" )
65 {
66 open(DLFILE, "</var/ipfire/backup/addons/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
67 my @fileholder = <DLFILE>;
68 print "Content-Type:application/x-download\n";
69 print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
70 print @fileholder;
71 exit (0);
72 }
73 elsif ( $cgiparams{'ACTION'} eq "restore" )
74 {
75 my $upload = $a->param("UPLOAD");
76 open UPLOADFILE, ">/tmp/restore.ipf";
77 binmode $upload;
78 while ( <$upload> ) {
79 print UPLOADFILE;
80 }
81 close UPLOADFILE;
82 system("/usr/local/bin/backupctrl restore >/dev/null 2>&1");
83 }
84 elsif ( $cgiparams{'ACTION'} eq "restoreaddon" )
85 {
86 my $upload = $a->param("UPLOAD");
87 open UPLOADFILE, ">/tmp/$cgiparams{'UPLOAD'}";
88 binmode $upload;
89 while ( <$upload> ) {
90 print UPLOADFILE;
91 }
92 close UPLOADFILE;
93 system("/usr/local/bin/backupctrl restoreaddon $cgiparams{'UPLOAD'} >/dev/null 2>&1");
94 }
95
96 &Header::showhttpheaders();
97
98 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();}
99
100 &Header::openpage($Lang::tr{'backup'}, 1, "");
101 &Header::openbigbox('100%', 'left', '', $errormessage);
102
103 ############################################################################################################################
104 ################################################### Default System calls ###################################################
105
106 if ( $cgiparams{'ACTION'} eq "backup" )
107 {
108 if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include >/dev/null 2>&1");}
109 else {system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");}
110 }
111 if ( $cgiparams{'ACTION'} eq "addonbackup" )
112 {
113 system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1");
114 }
115 elsif ( $cgiparams{'ACTION'} eq "delete" )
116 {
117 system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1");
118 }
119
120 ############################################################################################################################
121 ############################################ Backups des Systems erstellen #################################################
122
123 if ( $message ne "" ){
124 &Header::openbox('100%','left',$Lang::tr{'error messages'});
125 print "<font color='red'>$message</font>\n";
126 &Header::closebox();
127 }
128
129 my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
130
131 &Header::openbox('100%', 'center', $Lang::tr{'backup'});
132
133 print <<END
134 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
135 <table width='95%' cellspacing='0'>
136 <tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>include Logfiles
137 <input type='radio' name='BACKUPLOGS' value='include'/>/
138 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> exclude Logfiles
139 </td></tr>
140 <tr><td align='center' colspan='2'>
141 <input type='hidden' name='ACTION' value='backup' />
142 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
143 </td></tr>
144 </table>
145 </form>
146 END
147 ;
148 &Header::closebox();
149
150 ############################################################################################################################
151 ############################################ Backups des Systems downloaden ################################################
152
153 &Header::openbox('100%', 'center', $Lang::tr{'backups'});
154
155 print <<END
156 <table width='95%' cellspacing='0'>
157 END
158 ;
159 foreach (@backups){
160 chomp($_);
161 my $Datei = "/var/ipfire/backup/".$_;
162 my @Info = stat($Datei);
163 my $Size = $Info[7] / 1024;
164 $Size = sprintf("%02d", $Size);
165 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>";
166 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>";
167 }
168 print <<END
169 </table>
170 END
171 ;
172 &Header::closebox();
173
174 ############################################################################################################################
175 ############################################# Backups von Addons erstellen #################################################
176
177 &Header::openbox('100%', 'center', 'addons');
178
179 my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`;
180
181 print "<table width='95%' cellspacing='0'>";
182 foreach (@addonincluds){
183 chomp($_);
184 my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
185 my @Info = stat($Datei);
186 my $Size = $Info[7] / 1024;
187 $Size = sprintf("%2d", $Size);
188 if ( -e $Datei ){
189 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
190 print <<END
191 <td align='right' width='5'>
192 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
193 <input type='hidden' name='ACTION' value='downloadaddon' />
194 <input type='hidden' name='FILE' value='$_.ipf' />
195 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
196 </form>
197 </td>
198 <td align='right' width='5'>
199 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
200 <input type='hidden' name='ACTION' value='delete' />
201 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
202 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
203 </form>
204 </td>
205 END
206 ;
207 }
208 else{
209 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td colspan='2' width='10'></td>";
210 }
211 print <<END
212 <td align='right' width='5'>
213 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
214 <input type='hidden' name='ACTION' value='addonbackup' />
215 <input type='hidden' name='ADDON' value='$_' />
216 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
217 </form>
218 </td></tr>
219 END
220 ;
221 }
222 print "</table>";
223 &Header::closebox();
224
225 ############################################################################################################################
226 ####################################### Backups des Systems wiederherstellen ###############################################
227
228 &Header::openbox('100%', 'center', $Lang::tr{'restore'});
229
230 print <<END
231 <table width='95%' cellspacing='0'>
232 <tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
233 <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>
234 <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>
235 </table>
236 END
237 ;
238 &Header::closebox();
239 &Header::closebigbox();
240 &Header::closepage();