]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/backup.cgi
Korrekturen damit der Build wieder laeuft
[people/teissler/ipfire-2.x.git] / html / cgi-bin / backup.cgi
CommitLineData
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
22use strict;
23# enable only the following on debugging purpose
5ad5a6bc
MT
24#use warnings;
25#use CGI::Carp 'fatalsToBrowser';
8e8bbd9d 26use File::Copy;
cf29614f
CS
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
32my %color = ();
33my %mainsettings = ();
8e8bbd9d 34my %cgiparams=();
cf29614f
CS
35my %checked = ();
36my $message = "";
37my $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
CS
50
51############################################################################################################################
69addbb8 52############################################## System calls ohne Http Header ###############################################
cf29614f 53
69addbb8
CS
54
55if ( $cgiparams{'ACTION'} eq "download" )
8e8bbd9d 56{
901a50cf
CS
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);
8e8bbd9d 63}
5ad5a6bc
MT
64if ( $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}
8e8bbd9d
CS
73elsif ( $cgiparams{'ACTION'} eq "restore" )
74{
901a50cf
CS
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");
8e8bbd9d 83}
5ad5a6bc
MT
84elsif ( $cgiparams{'ACTION'} eq "restoreaddon" )
85{
86 my $upload = $a->param("UPLOAD");
87 open UPLOADFILE, ">/var/$cgiparams{'UPLOAD'}";
88 binmode $upload;
89 while ( <$upload> ) {
90 print UPLOADFILE;
91 }
92 close UPLOADFILE;
93 system("cp /var/ipfire/backup/addons/backup/$cgiparams{'UPLOAD'} /tmp/restore.ipf >/dev/null 2>&1");
94 system("/usr/local/bin/backupctrl restore >/dev/null 2>&1");
95}
cf29614f 96
8e8bbd9d 97&Header::showhttpheaders();
69addbb8
CS
98
99sub 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();}
100
8e8bbd9d
CS
101&Header::openpage($Lang::tr{'backup'}, 1, "");
102&Header::openbigbox('100%', 'left', '', $errormessage);
103
69addbb8
CS
104############################################################################################################################
105################################################### Default System calls ###################################################
106
107if ( $cgiparams{'ACTION'} eq "backup" )
108{
901a50cf
CS
109 if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include >/dev/null 2>&1");}
110 else {system("/usr/local/bin/backupctrl exclude >/dev/null 2>&1");}
111}
112if ( $cgiparams{'ACTION'} eq "addonbackup" )
113{
5ad5a6bc 114 system("/usr/local/bin/backupctrl addonbackup $cgiparams{'ADDON'} >/dev/null 2>&1");
69addbb8
CS
115}
116elsif ( $cgiparams{'ACTION'} eq "delete" )
117{
901a50cf 118 system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null 2>&1");
69addbb8
CS
119}
120
121############################################################################################################################
901a50cf 122############################################ Backups des Systems erstellen #################################################
69addbb8 123
8e8bbd9d
CS
124if ( $message ne "" ){
125 &Header::openbox('100%','left',$Lang::tr{'error messages'});
126 print "<font color='red'>$message</font>\n";
127 &Header::closebox();
128}
cf29614f 129
901a50cf
CS
130my @backups = `cd /var/ipfire/backup/ && ls *.ipf 2>/dev/null`;
131
cf29614f
CS
132&Header::openbox('100%', 'center', $Lang::tr{'backup'});
133
134print <<END
135<form method='post' action='$ENV{'SCRIPT_NAME'}'>
136<table width='95%' cellspacing='0'>
901a50cf
CS
137<tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>include Logfiles
138 <input type='radio' name='BACKUPLOGS' value='include'/>/
139 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> exclude Logfiles
140</td></tr>
141<tr><td align='center' colspan='2'>
142 <input type='hidden' name='ACTION' value='backup' />
143 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
144</td></tr>
cf29614f
CS
145</table>
146</form>
147END
148;
149&Header::closebox();
150
901a50cf
CS
151############################################################################################################################
152############################################ Backups des Systems downloaden ################################################
153
cf29614f
CS
154&Header::openbox('100%', 'center', $Lang::tr{'backups'});
155
156print <<END
cf29614f
CS
157<table width='95%' cellspacing='0'>
158END
159;
160foreach (@backups){
8e8bbd9d 161chomp($_);
69addbb8 162my $Datei = "/var/ipfire/backup/".$_;
8e8bbd9d
CS
163my @Info = stat($Datei);
164my $Size = $Info[7] / 1024;
165$Size = sprintf("%02d", $Size);
69addbb8
CS
166print "<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>";
167print "<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 168}
901a50cf 169print <<END
cf29614f 170</table>
8e8bbd9d
CS
171END
172;
173&Header::closebox();
174
901a50cf
CS
175############################################################################################################################
176############################################# Backups von Addons erstellen #################################################
177
178&Header::openbox('100%', 'center', 'addons');
179
180my @addonincluds = `ls /var/ipfire/backup/addons/includes/ 2>/dev/null`;
181
182print "<table width='95%' cellspacing='0'>";
183foreach (@addonincluds){
184chomp($_);
185my $Datei = "/var/ipfire/backup/addons/backup/".$_.".ipf";
186my @Info = stat($Datei);
187my $Size = $Info[7] / 1024;
188$Size = sprintf("%2d", $Size);
189if ( -e $Datei ){
190print "<tr><td align='center'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB $Lang::tr{'date'} ".localtime($Info[9])."</td>";
191print <<END
192 <td align='right' width='5'>
193 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
5ad5a6bc
MT
194 <input type='hidden' name='ACTION' value='downloadaddon' />
195 <input type='hidden' name='FILE' value='$_.ipf' />
901a50cf
CS
196 <input type='image' alt='$Lang::tr{'download'}' title='$Lang::tr{'download'}' src='/images/package-x-generic.png' />
197 </form>
198 </td>
199 <td align='right' width='5'>
200 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
201 <input type='hidden' name='ACTION' value='delete' />
202 <input type='hidden' name='FILE' value='addons/backup/$_.ipf' />
203 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
204 </form>
205 </td>
206END
207;
208}
209else{
210 print "<tr><td align='center'>$Lang::tr{'backup from'} $_ </td><td colspan='2' width='10'></td>";
211}
212print <<END
213 <td align='right' width='5'>
214 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
215 <input type='hidden' name='ACTION' value='addonbackup' />
216 <input type='hidden' name='ADDON' value='$_' />
217 <input type='image' alt='$Lang::tr{'backup'}' title='$Lang::tr{'backup'}' src='/images/document-save.png' />
218 </form>
219 </td></tr>
220END
221;
222}
223print "</table>";
224&Header::closebox();
5ad5a6bc
MT
225
226############################################################################################################################
227####################################### Backups des Systems wiederherstellen ###############################################
228
229&Header::openbox('100%', 'center', $Lang::tr{'restore'});
230
231print <<END
232<table width='95%' cellspacing='0'>
233<tr><td align='center' colspan='2'><font color='red'><br />$Lang::tr{'backupwarning'}</font><br /><br /></td></tr>
234<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>
235<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>
236</table>
237END
238;
239&Header::closebox();
cf29614f
CS
240&Header::closebigbox();
241&Header::closepage();