#!/usr/bin/perl use strict; use warnings; use CGI qw(-no_xhtml); use IO::Pipe; my $q = CGI->new(); my $dir = CGI::unescape($q->url(-absolute => 1)); $dir =~ s/\/*$//; my $style = <header(-charset => 'utf-8'); print $q->start_html( -title => "Index of $dir", -style => {-code => $style}, ); print $q->h1($q->escapeHTML("Index of $dir")); AFS_INFO: { last if $dir !~ /^\/afs\//; my @cmds = ('whichcell', 'whereis', 'listacl'); my %f = map {$_ => IO::Pipe->reader('fs', $_, '-path', $dir)} @cmds; my %out = map {local $/; $_ => $f{$_}->getline} @cmds; $f{$_}->close and $? == 0 or last AFS_INFO for @cmds; my ($cell) = $out{'whichcell'} =~ /^File \Q$dir\E lives in cell '(.*?)'\s*$/; my ($hosts) = $out{'whereis'} =~ /^File \Q$dir\E is on hosts? (.*?)\s*$/; my @hosts = split /\s+/, $hosts; my ($acl) = $out{'listacl'} =~ /^Access list for \Q$dir\E is\nNormal rights:\n((?: .*\n)*)/; my @admins = $acl =~ /^ (.*) .*a.*$/mg; my @groups = grep {/:/} @admins; my %members; if (@groups) { my $f = IO::Pipe->reader('pts', 'membership', (map {('-nameorid', $_)} @groups), '-cell', $cell, '-noauth'); my %members_str = do {local $/; $f->getline} =~ /^Members of (.*) \(id: .*\) are:\n((?: .*\n)*)/mg; %members = map {$_ => [$members_str{$_} =~ /^ (.*)$/mg]} keys %members_str; $f->close; } my $admins_html = join(', ', map {$q->b($q->escapeHTML("$_")) . (/:/ ? ' (' . join(', ', map {$q->escapeHTML($_)} @{$members{$_}}) . ')' : '')} @admins); print $q->div( {-class => 'note'}, $q->p( 'This content is being served through the ' . $q->a({href => 'http://en.wikipedia.org/wiki/Andrew_File_System'}, 'AFS') . (@hosts == 1 ? ' server ' : ' servers ') . join(', ', map {$q->b($q->escapeHTML($_))} @hosts) . ' in the ' . $q->a({href => "/afs/$cell/"}, $q->b($q->escapeHTML($cell)) . ' AFS cell') . '. If you have any questions about this content, please contact the ' . (@admins == 1 ? 'administrator' : 'administrators') . ' of this directory, who made it publicly available. The administrators of the ' . $q->escapeHTML($q->server_name) . ' AFS gateway are not responsible for this content and have no ability to remove it.' ), $q->p( (@admins == 1 ? 'The administrator of this directory is ' : 'The administrators of this directory are ') . $q->span( {-class => 'admins'}, $admins_html . ' of ' . $q->escapeHTML($cell) ) . '.' ) ); } # Closing are written by Apache.