File:
[LON-CAPA] /
loncom /
cgi /
decompress.pl
Revision
1.17:
download - view:
text,
annotated -
select for diffs
Fri Nov 28 20:42:20 2008 UTC (15 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_99_1,
version_2_7_99_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
bz6209-base,
bz6209,
bz5969,
bz2851,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- Add localization.
- Use LONCAPA::loncgi::missing_cookie_msg() to generate missing cookie message.
1: #!/usr/bin/perl
2: #
3: #
4: # Copyright Michigan State University Board of Trustees
5: # $Id
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/cgi-bin/decompress.pl
24: #
25: # http://www.lon-capa.org/
26: #
27: # The LearningOnline Network with CAPA
28: #
29: # A CGI script that decompresses compressed files for mass uploading into
30: # construction space
31: ####
32: use strict;
33: use lib '/home/httpd/lib/perl';
34: use Apache::lonnet;
35: use Apache::lonlocal;
36: use LONCAPA::loncgi;
37:
38: my %location_of;
39: foreach my $program ('tar','gunzip','bunzip2','unzip') {
40: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
41: '/usr/sbin/') {
42: if (-x $dir.$program) {
43: $location_of{$program} = $dir.$program;
44: }
45: }
46: }
47:
48: print("Content-type: text/html\n\n");
49:
50: if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
51: &Apache::lonlocal::get_language_handle();
52: print(&LONCAPA::loncgi::missing_cookie_msg());
53: } else {
54: &Apache::lonlocal::get_language_handle();
55: my %lt = &Apache::lonlocal::texthash (
56: bade => 'Bad Environment!',
57: outo => 'Output of decompress:',
58: comp => 'Decompress complete.',
59: erro => 'An error occurred',
60: );
61: my $file=$Apache::lonnet::env{'cgi.file'};
62: my $dir=$Apache::lonnet::env{'cgi.dir'};
63: if(! $file || ! $dir) {
64: print(<<END);
65: <html><body><span class="LC_error">$lt{'bade'}</span></body></html>
66: END
67: } else {
68: print(<<END);
69: <html><body><p><b>$lt{'outo'}</b></p>
70: END
71: chdir($dir);
72: my @cmd;
73: if ($file =~ m|\.zip$|) {
74: @cmd = ($location_of{'unzip'},"-o");
75: } elsif ($file =~ m|\.tar\.gz$|
76: || $file =~ m|\.tgz$| ) {
77: @cmd = ($location_of{'tar'},"-zxpvf");
78: } elsif ($file =~ m|\.tar\.bz2$|) {
79: @cmd = ($location_of{'tar'},"-jxpvf");
80: } elsif ($file =~ m|\.bz2$|) {
81: @cmd = ($location_of{'bunzip2'});
82: } elsif ($file =~ m|\.gz$|) {
83: @cmd = ($location_of{'gunzip'});
84: } elsif ($file =~ m|\.tar$|) {
85: @cmd = ($location_of{'tar'},"-xpvf");
86: } else {
87: print('<span class="LC_error">'.&Apache::lonlocal::mt('There has been an error in determining the file type of [_1], please check the name',$file).'</span>');
88: }
89: if (@cmd) {
90: undef($!);
91: undef($@);
92: open(OUTPUT,"-|", @cmd, $file);
93: while (my $line = <OUTPUT>) { print("$line<br />"); }
94: close(OUTPUT);
95: print("<p><b>$lt{'comp'}</b></p>");
96: if ($! || $@) {
97: print('<p><span class="LC_error">'.$lt{'erro'}.'<br />'.$!.'<br />'.$@.'</span></p>');
98: }
99: }
100: print('</body></html>');
101: }
102: }
103:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>