]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/backup.cgi
Pakfire laedt die Listen jetzt besser und hat eine veraenderte Oberflaeche bekommen.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / backup.cgi
CommitLineData
cf29614f
CS
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8
9use strict;
10# enable only the following on debugging purpose
cb5e9c6c
CS
11#use warnings;
12#use CGI::Carp 'fatalsToBrowser';
8e8bbd9d 13use File::Copy;
cf29614f
CS
14
15require '/var/ipfire/general-functions.pl';
16require "${General::swroot}/lang.pl";
17require "${General::swroot}/header.pl";
18
19my %color = ();
20my %mainsettings = ();
8e8bbd9d 21my %cgiparams=();
cf29614f
CS
22my %checked = ();
23my $message = "";
24my $errormessage = "";
69addbb8 25my @backups = `cd /var/ipfire/backup/ && ls *.ipf`;
cf29614f 26
8e8bbd9d 27$a = new CGI;
cf29614f
CS
28
29&General::readhash("${General::swroot}/main/settings", \%mainsettings);
30&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
31
8e8bbd9d
CS
32$cgiparams{'ACTION'} = '';
33$cgiparams{'FILE'} = '';
34$cgiparams{'UPLOAD'} = '';
35$cgiparams{'BACKUPLOGS'} = '';
69addbb8 36
8e8bbd9d 37&Header::getcgihash(\%cgiparams);
cf29614f
CS
38
39############################################################################################################################
69addbb8 40############################################## System calls ohne Http Header ###############################################
cf29614f 41
69addbb8
CS
42
43if ( $cgiparams{'ACTION'} eq "download" )
8e8bbd9d 44{
69addbb8 45 open(DLFILE, "</var/ipfire/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
8e8bbd9d
CS
46 my @fileholder = <DLFILE>;
47 print "Content-Type:application/x-download\n";
48 print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
49 print @fileholder;
50 exit (0);
51}
52elsif ( $cgiparams{'ACTION'} eq "restore" )
53{
54 my $upload = $a->param("UPLOAD");
55 open UPLOADFILE, ">/tmp/restore.ipf";
56 binmode $upload;
57 while ( <$upload> ) {
58 print UPLOADFILE;
59 }
60 close UPLOADFILE;
900832fa 61 system("/usr/local/bin/backupctrl restore >/dev/null");
8e8bbd9d 62}
cf29614f 63
8e8bbd9d 64&Header::showhttpheaders();
69addbb8
CS
65
66sub 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();}
67
8e8bbd9d
CS
68&Header::openpage($Lang::tr{'backup'}, 1, "");
69&Header::openbigbox('100%', 'left', '', $errormessage);
70
69addbb8
CS
71############################################################################################################################
72################################################### Default System calls ###################################################
73
74if ( $cgiparams{'ACTION'} eq "backup" )
75{
76 if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include >/dev/null");}
77 else {system("/usr/local/bin/backupctrl exclude >/dev/null");}
78 refreshpage();
79}
80elsif ( $cgiparams{'ACTION'} eq "delete" )
81{
82 system("/usr/local/bin/backupctrl $cgiparams{'FILE'} >/dev/null");
83 refreshpage();
84}
85
86############################################################################################################################
87########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค
88
8e8bbd9d
CS
89if ( $message ne "" ){
90 &Header::openbox('100%','left',$Lang::tr{'error messages'});
91 print "<font color='red'>$message</font>\n";
92 &Header::closebox();
93}
cf29614f
CS
94
95&Header::openbox('100%', 'center', $Lang::tr{'backup'});
96
97print <<END
98<form method='post' action='$ENV{'SCRIPT_NAME'}'>
99<table width='95%' cellspacing='0'>
8e8bbd9d
CS
100<tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>include Logfiles <input type='radio' name='BACKUPLOGS' value='include'/>/
101 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> exclude Logfiles</td></tr>
cf29614f 102<tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='backup' />
8e8bbd9d 103 <input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/document-save.png' /></td></tr>
cf29614f
CS
104</table>
105</form>
106END
107;
108&Header::closebox();
109
110&Header::openbox('100%', 'center', $Lang::tr{'backups'});
111
112print <<END
cf29614f
CS
113<table width='95%' cellspacing='0'>
114END
115;
116foreach (@backups){
8e8bbd9d 117chomp($_);
69addbb8 118my $Datei = "/var/ipfire/backup/".$_;
8e8bbd9d
CS
119my @Info = stat($Datei);
120my $Size = $Info[7] / 1024;
121$Size = sprintf("%02d", $Size);
69addbb8
CS
122print "<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>";
123print "<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
CS
124}
125print <<END
126</table>
8e8bbd9d
CS
127END
128;
129&Header::closebox();
130
131&Header::openbox('100%', 'center', $Lang::tr{'restore'});
132
133print <<END
134<table width='95%' cellspacing='0'>
69addbb8 135<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 136</table>
cf29614f
CS
137END
138;
139&Header::closebox();
140&Header::closebigbox();
141&Header::closepage();