File:
[LON-CAPA] /
loncom /
auth /
restrictedaccess.pm
Revision
1.8:
download - view:
text,
annotated -
select for diffs
Fri Feb 13 17:20:26 2009 UTC (15 years, 7 months ago) by
bisitz
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_99_1,
version_2_8_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,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
Added missing CVS Ids for automatic version numbering to script header
(Irrespective if the script is still in use or not)
# The LearningOnline Network
# Passphrase Entry and Validation for Portfolio files
#
# $Id: restrictedaccess.pm,v 1.8 2009/02/13 17:20:26 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::restrictedaccess;
use strict;
use lib '/home/httpd/lib/perl/';
use Apache::Constants qw(:common :http REDIRECT);
use CGI::Cookie();
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonauth();
use Apache::lonlocal;
use Apache::lonacc;
use Fcntl qw(:flock);
use LONCAPA;
sub handler {
my $r = shift;
my $origurl = &unescape($env{'form.origurl'});
if (!defined($origurl)) {
$origurl = $r->uri;
}
my $msg='';
if (exists($env{'form.pass1'})) {
my ($result,$end) = &check_pass($r,$origurl);
if ($result eq 'ok') {
&Apache::lonnet::allowuploaded('/adm/restrictedaccess',
$origurl);
$env{'request.state'} = "published";
$env{'request.filename'} = $origurl;
$r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$origurl);
return REDIRECT;
} else {
$msg = 'Invalid passphrase';
}
}
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
$r->print(&Apache::loncommon::start_page('Passphrase protected file'));
&print_entryform($r,$origurl,$msg);
return OK;
}
sub setup_handler {
my ($r) = @_;
$r->set_handlers('PerlHandler'=>
[\&Apache::restrictedaccess::handler]);
$r->handler('perl-script');
}
sub print_entryform {
my ($r,$origurl,$msg) = @_;
$r->print('<script type="text/javascript">
function verify() {
if (document.passform.pass1.value == "") {
alert("You must enter a passphrase");
return;
}
document.passform.submit();
}
</script>');
if ($msg ne '') {
$r->print('<span class="LC_error">'.$msg.'</span>');
}
$r->print('<div align="center"><form name="passform" method="post" '.
'action="/adm/restrictedaccess">');
$r->print('<br /><br /><br />');
$r->print(&Apache::loncommon::start_data_table());
$r->print(&Apache::loncommon::start_data_table_row());
$r->print('<td><span class="LC_nobreak">'.&mt('Passphrase: ').'</span></td>'.
'<td><input type="password" size="20" name="pass1" /></td>');
$r->print(&Apache::loncommon::end_data_table_row());
$r->print(&Apache::loncommon::start_data_table_row());
$r->print('<td align="center" colspan="2"><br />'.
'<input type="button" name="sendpass" value="'.
&mt('Submit passphrase').'" onClick="verify()" /></td>');
$r->print(&Apache::loncommon::end_data_table_row());
$r->print(&Apache::loncommon::end_data_table());
$r->print('<input type="hidden" name="origurl" value="'.
&escape($origurl).'" /></form></div>');
$r->print(&Apache::loncommon::end_page());
}
sub check_pass {
my ($r,$origurl) = @_;
my (undef,$udom,$unum,$file_name,$group) =
&Apache::lonnet::parse_portfolio_url($origurl);
my $curr_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
my %acc_controls = &Apache::lonnet::get_access_controls($curr_perms,
$group,$file_name);
my $access_hash = $acc_controls{$file_name};
my ($result,$end);
foreach my $key (sort(keys(%{$access_hash}))) {
if ($key =~ /^[^:]+:guest_(\d+)/) {
$end = $1;
if ($env{'form.pass1'} eq $access_hash->{$key}{'password'}) {
$result = 'ok';
} else {
$result = 'fail';
}
last;
}
}
return ($result,$end);
}
1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>