Fuer den Urlfilter ein Background Image gemacht
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / backup.cgi
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
9 use strict;
10 # enable only the following on debugging purpose
11 use warnings;
12 use CGI::Carp 'fatalsToBrowser';
13 use File::Copy;
14
15 require '/var/ipfire/general-functions.pl';
16 require "${General::swroot}/lang.pl";
17 require "${General::swroot}/header.pl";
18
19 my %color = ();
20 my %mainsettings = ();
21 my %cgiparams=();
22 my %checked = ();
23 my $message = "";
24 my $errormessage = "";
25 my @backups = `cd /var/ipfire/backup/ && ls *.ipf`;
26
27 $a = new CGI;
28
29 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
30 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
31
32 $cgiparams{'ACTION'} = '';
33 $cgiparams{'FILE'} = '';
34 $cgiparams{'UPLOAD'} = '';
35 $cgiparams{'BACKUPLOGS'} = '';
36
37 &Header::getcgihash(\%cgiparams);
38
39 ############################################################################################################################
40 ############################################## System calls ohne Http Header ###############################################
41
42
43 if ( $cgiparams{'ACTION'} eq "download" )
44 {
45 open(DLFILE, "</var/ipfire/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
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 }
52 elsif ( $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;
61 system("/usr/local/bin/backupctrl restore");
62 }
63
64 &Header::showhttpheaders();
65
66 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();}
67
68 &Header::openpage($Lang::tr{'backup'}, 1, "");
69 &Header::openbigbox('100%', 'left', '', $errormessage);
70
71 ############################################################################################################################
72 ################################################### Default System calls ###################################################
73
74 if ( $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 }
80 elsif ( $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
89 if ( $message ne "" ){
90 &Header::openbox('100%','left',$Lang::tr{'error messages'});
91 print "<font color='red'>$message</font>\n";
92 &Header::closebox();
93 }
94
95 &Header::openbox('100%', 'center', $Lang::tr{'backup'});
96
97 print <<END
98 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
99 <table width='95%' cellspacing='0'>
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>
102 <tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='backup' />
103 <input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/document-save.png' /></td></tr>
104 </table>
105 </form>
106 END
107 ;
108 &Header::closebox();
109
110 &Header::openbox('100%', 'center', $Lang::tr{'backups'});
111
112 print <<END
113 <table width='95%' cellspacing='0'>
114 END
115 ;
116 foreach (@backups){
117 chomp($_);
118 my $Datei = "/var/ipfire/backup/".$_;
119 my @Info = stat($Datei);
120 my $Size = $Info[7] / 1024;
121 $Size = sprintf("%02d", $Size);
122 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>";
123 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>";
124 }
125 print <<END
126 </table>
127 END
128 ;
129 &Header::closebox();
130
131 &Header::openbox('100%', 'center', $Lang::tr{'restore'});
132
133 print <<END
134 <table width='95%' cellspacing='0'>
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>
136 </table>
137 END
138 ;
139 &Header::closebox();
140 &Header::closebigbox();
141 &Header::closepage();