Inspired by
Protect Downloads.
There are a number of problems with the way ActivePerl sets up Script Mappings for IIS...
- You need execute permission (i.e. you can run a .exe by entering it in the URL)
- You can't access $ENV{path_info} (i.e. /script.pl/path_info won't work
- only .pl and .plx are set up
This script fixes all the above.
Update: Fixed bug caused by differences between NT & 2000. Script now detects if NT or 2000 (sort of)
Update 2: Added .pm mapping, to stop people being able to view source of perl modules that might be in a webroot.
# MDSN: http://msdn.microsoft.com/library/en-us/iisref/html/psdk/asp/a
+pro9tkj.asp
use strict;
use warnings;
use Win32::OLE qw(in);
# Connect to IIS on the Local Machine with ADSI...
my $iis_web_object = Win32::OLE->GetObject("IIS://LocalHost/W3SVC")
or die "Can't access IIS on the local machine\n";
my ($perl_path) = $^X =~ /(.*)\\[^\\]+$/;
my $iis_verbs = ((Win32::GetOSVersion)[1] == 5) ? 'GET,HEAD,POST' : 'P
+UT,DELETE';
foreach my $path (in $iis_web_object->GetDataPaths("ScriptMaps", 0))
{
my $node = Win32::OLE->GetObject($path);
print "Setting $path...\n";
my $str_maps = $node->{ScriptMaps};
my %script_maps;
foreach (in @$str_maps) {
my ($ext, $exe, $script, $verbs) = split /,/, $_, 4;
$script_maps{$ext} = { exe => $exe, script => $script, verbs=>
+ $verbs}
}
$script_maps{'.pl'} = $script_maps{'.pm'} = $script_maps{'.cgi'}
+=
{ exe => $^X.' "%s" %s', script=> 1, verbs=> $iis_verbs };
$script_maps{'.plx'} =
{ exe => $perl_path."\\perlIS.dll", script=> 1, verbs=> $iis_ve
+rbs };
my $new_maps = [];
foreach (sort keys %script_maps) {
push @$new_maps, join ',',
$_ , $script_maps{$_}->{exe} , $script_maps{$_}->{script}
+,
$script_maps{$_}->{verbs}
}
$node->{ScriptMaps} = $new_maps;
$node->SetInfo();
}
undef $iis_web_object;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.