]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/backup.cgi
kleine Korrektur in der Samba CGI
[people/teissler/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 /srv/web/ipfire/html/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 &Header::getcgihash(\%cgiparams);
37
38 ############################################################################################################################
39 ######################################## Scanne Verzeichnisse nach Mp3 Dateien #############################################
40
41 if ( $cgiparams{'ACTION'} eq "backup" )
42 {
43 if ( $cgiparams{'BACKUPLOGS'} eq "include" ){system("/usr/local/bin/backupctrl include");}
44 else {system("/usr/local/bin/backupctrl exclude");}
45 }
46 elsif ( $cgiparams{'ACTION'} eq "download" )
47 {
48 open(DLFILE, "</srv/web/ipfire/html/backup/$cgiparams{'FILE'}") or die "Unable to open $cgiparams{'FILE'}: $!";
49 my @fileholder = <DLFILE>;
50 print "Content-Type:application/x-download\n";
51 print "Content-Disposition:attachment;filename=$cgiparams{'FILE'}\n\n";
52 print @fileholder;
53 exit (0);
54 }
55 elsif ( $cgiparams{'ACTION'} eq "restore" )
56 {
57 my $upload = $a->param("UPLOAD");
58 open UPLOADFILE, ">/tmp/restore.ipf";
59 binmode $upload;
60 while ( <$upload> ) {
61 print UPLOADFILE;
62 }
63 close UPLOADFILE;
64 system("/usr/local/bin/backupctrl restore");
65 }
66
67 ############################################################################################################################
68 ########################################### rekursiv nach neuen Mp3s Scannen ##############################################รค
69
70 &Header::showhttpheaders();
71 &Header::openpage($Lang::tr{'backup'}, 1, "");
72 &Header::openbigbox('100%', 'left', '', $errormessage);
73
74 if ( $message ne "" ){
75 &Header::openbox('100%','left',$Lang::tr{'error messages'});
76 print "<font color='red'>$message</font>\n";
77 &Header::closebox();
78 }
79
80 &Header::openbox('100%', 'center', $Lang::tr{'backup'});
81
82 print <<END
83 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
84 <table width='95%' cellspacing='0'>
85 <tr><td align='left' width='40%'>$Lang::tr{'logs'}</td><td align='left'>include Logfiles <input type='radio' name='BACKUPLOGS' value='include'/>/
86 <input type='radio' name='BACKUPLOGS' value='exclude' checked='checked'/> exclude Logfiles</td></tr>
87 <tr><td align='center' colspan='2'><input type='hidden' name='ACTION' value='backup' />
88 <input type='image' alt='$Lang::tr{'Scan for Files'}' title='$Lang::tr{'Scan for Files'}' src='/images/document-save.png' /></td></tr>
89 </table>
90 </form>
91 END
92 ;
93 &Header::closebox();
94
95 &Header::openbox('100%', 'center', $Lang::tr{'backups'});
96
97 print <<END
98 <table width='95%' cellspacing='0'>
99 END
100 ;
101 foreach (@backups){
102 chomp($_);
103 my $Datei = "/srv/web/ipfire/html/backup/".$_;
104 my @Info = stat($Datei);
105 my $Size = $Info[7] / 1024;
106 $Size = sprintf("%02d", $Size);
107 print "<tr><td align='left'><form method='post' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'backup from'} $_ $Lang::tr{'size'} $Size KB <input type='hidden' name='ACTION' value='download' /><input type='hidden' name='FILE' value='$_' /><input type='image' src='/images/package-x-generic.png' /></form></td></tr>";
108 }
109 print <<END
110 </table>
111 END
112 ;
113 &Header::closebox();
114
115 &Header::openbox('100%', 'center', $Lang::tr{'restore'});
116
117 print <<END
118 <table width='95%' cellspacing='0'>
119 <tr><td align='left'><form method='post' enctype='multipart/form-data' action='$ENV{'SCRIPT_NAME'}'>$Lang::tr{'backup'}</td><td align='left'><input type="file" size='50' name="UPLOAD" /><input type='submit' name='ACTION' value='restore' /></form></td></tr>
120 </table>
121 END
122 ;
123 &Header::closebox();
124 &Header::closebigbox();
125 &Header::closepage();