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