home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / bin / IISScriptMap.pl < prev    next >
Encoding:
Text File  |  2002-02-01  |  2.1 KB  |  79 lines

  1. ###############################################################################
  2. #
  3. # File:         IISScriptMap.pl
  4. # Author:       Michael Smith <mike.smith@activestate.com>
  5. # Description:  Creates script mappings in the IIS metabase.
  6. #
  7. # Copyright ⌐ 2000, ActiveState Tool Corp. All rights reserved.
  8. #
  9. ###############################################################################
  10. BEGIN {
  11.     $tmp = $ENV{'TEMP'} || $ENV{'tmp'} || 
  12.     ($Config{'osname'} eq 'MSWin32' ? 'c:/temp' : '/tmp');
  13.     open(STDERR, ">> $tmp/ActivePerlInstall.log");
  14. }
  15.  
  16. use strict;
  17. use Win32::OLE;
  18.  
  19. my $error = AddFileExtMapping(@ARGV);
  20. exit(0);
  21.  
  22. sub AddFileExtMapping {
  23.     my $serverID        = shift;
  24.  
  25.     if ($serverID =~ /;/) {
  26.     my @rest = @_;
  27.     my @servers = split /;/, $serverID;
  28.     for my $id (@servers) {
  29.         AddFileExtMapping($id,@rest);
  30.     }
  31.     return;
  32.     }
  33.  
  34.     my $virtDir            = shift;
  35.  
  36.     if ($virtDir =~ /;/) {
  37.     my @rest = @_;
  38.     my @dirs = split /;/, $virtDir, -1;
  39.     for my $dir (@dirs) {
  40.         AddFileExtMapping($serverID,$dir,@rest);
  41.     }
  42.     return;
  43.     }
  44.  
  45.     my $fileExt            = shift;
  46.     my $execPath        = shift;
  47.     my $flags            = shift;
  48.     my $methodExclude        = shift;
  49.  
  50.     my $node = "IIS://localhost/W3SVC";
  51.  
  52.     # NOTE: A serverID of "0" is treated as the W3SVC root; any supplied
  53.     # virtual directory for this case is ignored.
  54.  
  55.     $node .= "/$serverID/ROOT" if $serverID > 0;
  56.     $node .= "/$virtDir" if $serverID > 0 and length($virtDir) > 0;
  57.  
  58.     # Get the IIsVirtualDir Automation Object
  59.     my $server = Win32::OLE->GetObject($node) ||
  60.     return;
  61.     
  62.     # create our new script mapping entry
  63.     my $scriptMapping = "$fileExt,$execPath";
  64.     $scriptMapping .= ",$flags";
  65.     $scriptMapping .= ",$methodExclude";
  66.     
  67.     my @ScriptMaps = @{$server->{ScriptMaps}};
  68.     my @NewScriptMaps = map { 
  69.     /^\Q$fileExt,\E.*/ ? $scriptMapping : $_ } @ScriptMaps;
  70.     push(@NewScriptMaps, $scriptMapping) 
  71.     unless grep {/^\Q$fileExt,\E.*/} @NewScriptMaps;
  72.     print join("\n", @NewScriptMaps);
  73.     
  74.     $server->{ScriptMaps} = \@NewScriptMaps;
  75.  
  76.     # Save the new script mappings
  77.     $server->SetInfo(); 
  78. }
  79.