]>
Commit | Line | Data |
---|---|---|
cf29614f | 1 | #!/usr/bin/perl |
70df8302 MT |
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 | ############################################################################### | |
cf29614f CS |
21 | |
22 | use strict; | |
23 | # enable only the following on debugging purpose | |
a609bfb0 CS |
24 | use warnings; |
25 | use CGI::Carp 'fatalsToBrowser'; | |
8e8bbd9d | 26 | use File::Copy; |
cf29614f CS |
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 = (); | |
8e8bbd9d | 34 | my %cgiparams=(); |
cf29614f CS |
35 | my %checked = (); |
36 | my $message = ""; | |
37 | my $errormessage = ""; | |
cf29614f | 38 | |
8e8bbd9d | 39 | $a = new CGI; |
cf29614f CS |
40 | |
41 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
42 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
43 | ||
8e8bbd9d CS |
44 | $cgiparams{'ACTION'} = ''; |
45 | $cgiparams{'FILE'} = ''; | |
46 | $cgiparams{'UPLOAD'} = ''; | |
47 | $cgiparams{'BACKUPLOGS'} = ''; | |
69addbb8 | 48 | |
8e8bbd9d | 49 | &Header::getcgihash(\%cgiparams); |
cf29614f | 50 | |
a609bfb0 CS |
51 | ############################################################################################################################ |
52 | ################################################ Workaround for Directories ################################################ | |
53 | ||
54 | system("/usr/local/bin/backupctrl makedirs >/dev/null 2>&1 ") unless ( -e '/var/ipfire/backup/addons'); | |
55 | ||
cf29614f | 56 | ############################################################################################################################ |
69addbb8 | 57 | ############################################## System calls ohne Http Header ############################################### |
cf29614f | 58 | |
69addbb8 CS |
59 | |
60 | if ( $cgiparams{'ACTION'} eq "download" ) | |
8e8bbd9d | 61 | { |
901a50cf CS |
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); | |
8e8bbd9d | 68 | } |
5ad5a6bc MT |
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 | } | |
8e8bbd9d CS |
78 | elsif ( $cgiparams{'ACTION'} eq "restore" ) |
79 | { | |
901a50cf CS |
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"); | |
8e8bbd9d | 88 | } |
5ad5a6bc MT |
89 | elsif ( $cgiparams{'ACTION'} eq "restoreaddon" ) |
90 | { | |
91 | my $upload = $a->param("UPLOAD"); | |
30945c78 | 92 | open UPLOADFILE, ">/tmp/$cgiparams{'UPLOAD'}"; |
5ad5a6bc MT |
93 | binmode $upload; |
94 | while ( <$upload> ) { | |
95 | print UPLOADFILE; | |
96 | } | |
97 | close UPLOADFILE; | |
30945c78 | 98 | system("/usr/local/bin/backupctrl restoreaddon $cgiparams{'UPLOAD'} >/dev/null 2>&1"); |
5ad5a6bc | 99 | } |
cf29614f | 100 | |
8e8bbd9d | 101 | &Header::showhttpheaders(); |
69addbb8 CS |
102 | |
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();} | |
104 | ||
8e8bbd9d CS |
105 | &Header::openpage($Lang::tr{'backup'}, 1, ""); |
106 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
107 | ||
69addbb8 CS |
108 | ############################################################################################################################ |
109 | ################################################### Default System calls ################################################### | |
110 | ||
111 | if ( $cgiparams{'ACTION'} eq "backup" ) | |
112 | { | |
901a50cf CS |
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");} | |
115 | } | |
116 | if ( $cgiparams{'ACTION'} eq "addonbackup" ) | |
117 | { | |
5ad5a6bc | 118 | system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1"); |
69addbb8 CS |
119 | } |
120 | elsif ( $cgiparams{'ACTION'} eq "delete" ) | |
121 | { | |
901a50cf | 122 | system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1"); |
69addbb8 CS |
123 | } |
124 | ||
125 | ############################################################################################################################ | |
901a50cf | 126 | ############################################ Backups des Systems erstellen ################################################# |
69addbb8 | 127 | |
8e8bbd9d CS |
128 | if ( $message ne "" ){ |
129 | &Header::openbox('100%','left',$Lang::tr{'error messages'}); | |
130 | print "<font color='red'>$message</font>\n"; | |
131 | &Header::closebox(); | |
132 | } | |
cf29614f | 133 | |
901a50cf CS |
134 | my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`; |
135 | ||
cf29614f CS |
136 | &Header::openbox('100%', 'center', $Lang::tr{'backup'}); |
137 | ||
138 | print <<END | |
139 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
140 | <table width='95%' cellspacing='0'> | |
901a50cf CS |
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 | |
144 | </td></tr> | |
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' /> | |
148 | </td></tr> | |
cf29614f CS |
149 | </table> |
150 | </form> | |
151 | END | |
152 | ; | |
153 | &Header::closebox(); | |
154 | ||
901a50cf CS |
155 | ############################################################################################################################ |
156 | ############################################ Backups des Systems downloaden ################################################ | |
157 | ||
cf29614f CS |
158 | &Header::openbox('100%', 'center', $Lang::tr{'backups'}); |
159 | ||
160 | print <<END | |
cf29614f CS |
161 | <table width='95%' cellspacing='0'> |
162 | END | |
163 | ; | |
164 | foreach (@backups){ | |
8e8bbd9d | 165 | chomp($_); |
69addbb8 | 166 | my $Datei = "/var/ipfire/backup/".$_; |
8e8bbd9d CS |
167 | my @Info = stat($Datei); |
168 | my $Size = $Info[7] / 1024; | |
169 | $Size = sprintf("%02d", $Size); | |
69addbb8 CS |
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>"; | |
cf29614f | 172 | } |
901a50cf | 173 | print <<END |
cf29614f | 174 | </table> |
8e8bbd9d CS |
175 | END |
176 | ; | |
177 | &Header::closebox(); | |
178 | ||
901a50cf CS |
179 | ############################################################################################################################ |
180 | ############################################# Backups von Addons erstellen ################################################# | |
181 | ||
182 | &Header::openbox('100%', 'center', 'addons'); | |
183 | ||
184 | my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`; | |
98ab7f50 CS |
185 | my @addons = `ls /var/ipfire/backup/addons/backup/ 2>/dev/null`; |
186 | my %addons; | |
187 | ||
188 | foreach (@addons){ | |
189 | my $addon=substr($_,0,length($_)-5); | |
190 | $addons{$addon}=''; | |
191 | } | |
901a50cf CS |
192 | |
193 | print "<table width='95%' cellspacing='0'>"; | |
194 | foreach (@addonincluds){ | |
195 | chomp($_); | |
98ab7f50 | 196 | delete $addons{$_}; |
901a50cf CS |
197 | my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf"; |
198 | my @Info = stat($Datei); | |
199 | my $Size = $Info[7] / 1024; | |
200 | $Size = sprintf("%2d", $Size); | |
201 | if ( -e $Datei ){ | |
202 | print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>"; | |
203 | print <<END | |
204 | <td align='right' width='5'> | |
205 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
5ad5a6bc MT |
206 | <input type='hidden' name='ACTION' value='downloadaddon' /> |
207 | <input type='hidden' name='FILE' value='$_.ipf' /> | |
901a50cf CS |
208 | <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' /> |
209 | </form> | |
210 | </td> | |
211 | <td align='right' width='5'> | |
212 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
213 | <input type='hidden' name='ACTION' value='delete' /> | |
214 | <input type='hidden' name='FILE' value='addons/backup/$_.ipf' /> | |
215 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /> | |
216 | </form> | |
217 | </td> | |
218 | END | |
219 | ; | |
220 | } | |
221 | else{ | |
b8e5a9c5 | 222 | print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td width='5' align='right'></td><td width='5' align='right'></td>"; |
901a50cf CS |
223 | } |
224 | print <<END | |
225 | <td align='right' width='5'> | |
226 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
227 | <input type='hidden' name='ACTION' value='addonbackup' /> | |
228 | <input type='hidden' name='ADDON' value='$_' /> | |
229 | <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' /> | |
230 | </form> | |
231 | </td></tr> | |
232 | END | |
233 | ; | |
234 | } | |
b8e5a9c5 CS |
235 | foreach (keys(%addons)){ |
236 | chomp($_); | |
98ab7f50 | 237 | my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf"; |
b8e5a9c5 CS |
238 | my @Info = stat($Datei); |
239 | my $Size = $Info[7] / 1024; | |
240 | $Size = sprintf("%2d", $Size); | |
98ab7f50 | 241 | print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>"; |
b8e5a9c5 CS |
242 | print <<END |
243 | <td align='right' width='5'> | |
244 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
245 | <input type='hidden' name='ACTION' value='downloadaddon' /> | |
98ab7f50 | 246 | <input type='hidden' name='FILE' value='$_.ipf' /> |
b8e5a9c5 CS |
247 | <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' /> |
248 | </form> | |
249 | </td> | |
250 | <td align='right' width='5'> | |
251 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
252 | <input type='hidden' name='ACTION' value='delete' /> | |
98ab7f50 | 253 | <input type='hidden' name='FILE' value='addons/backup/$_.ipf' /> |
b8e5a9c5 CS |
254 | <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' /> |
255 | </form> | |
256 | </td> | |
257 | <td align='right' width='5'></td></tr> | |
258 | END | |
259 | ; | |
260 | } | |
261 | ||
901a50cf CS |
262 | print "</table>"; |
263 | &Header::closebox(); | |
5ad5a6bc MT |
264 | |
265 | ############################################################################################################################ | |
266 | ####################################### Backups des Systems wiederherstellen ############################################### | |
267 | ||
268 | &Header::openbox('100%', 'center', $Lang::tr{'restore'}); | |
269 | ||
270 | print <<END | |
271 | <table width='95%' cellspacing='0'> | |
272 | <tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr> | |
273 | <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> | |
274 | <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> | |
275 | </table> | |
276 | END | |
277 | ; | |
278 | &Header::closebox(); | |
cf29614f CS |
279 | &Header::closebigbox(); |
280 | &Header::closepage(); |