Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

iis ftp redirection

by 3dbc (Scribe)
on Mar 20, 2006 at 20:51 UTC ( #538040=CUFP: print w/replies, xml ) Need Help??

#!/usr/bin/perl use Win32::OLE; use Win32::NetAdmin; use Win32::Lanman; #use Win32::Perms; $server = "dmz"; print "\nHello welcome to perl IIS FTP Redirection Creator :-)\n\n"; $go = 1; while ($go==1) { print "Please enter FTP Virtual Directory Name : "; chomp($user=<STDIN>); print "Please enter FTP Password : "; chomp($psswd=<STDIN>); $Object = Win32::OLE->GetObject("IIS://localhost/MSFTPSVC/1/Root") +||die Win32::OLE->LastError(); $PathToYourNewDir = "D:\\ftproot\\$user"; %Account = ( name => "$user", password => "$psswd", home_dir => "$PathToYourNewDir", comment => "FTP User Account Redirection", usr_comment => "CRT perl implementation", flags => UF_DONT_EXPIRE_PASSWD | UF_PASSWD_CANT_CHANGE, params => '', script_path => '', full_name => "FTP account $user", workstations => "", profile => "", acct_expires => -1, #logon_hours => pack( "b168", "11111111" x 21 ), home_dir_drive => "", password_expired => 1, ); #system ("net user $user $psswd /ADD /FULLNAME:\"FTP account $user +\" /COMMENT:\"FTP User Account Redirection\" /usercomment:\"CRT perl +implementation\" /homedir:$PathToYourNewDir /expires:NEVER /passwordc +hg:no"); #cusrmgr.exe. (cusrmgr -u <User> [-m \\<machine>] +s PasswordNever +Expires if (Win32::NetAdmin::UsersExist("$server", $user)) { #### CRT print "$user already exists\n"; die; } else { print "adding user $user\n"; Win32::Lanman::NetUserAdd( "$server", \%Account ); } my $group = "FTP Users"; system ("net localgroup \"$group\" $user /ADD"); #only needed when using net user to add a the user becuase it by d +efault adds the user to the users group. #system ("net localgroup \"Users\" $user /DELETE"); makeHomefolder($PathToYourNewDir); my $type = "IIsFtpVirtualDir"; print "Creating Virtual Directory $user\n"; $VDir = $Object->Create( $type,"$user"); $VDir->{AccessRead} = 1; $VDir->{AccessWrite} = 1; $VDir->{Path} = "$PathToYourNewDir"; $VDir->SetInfo(); makePermissions($PathToYourNewDir,$user); sub makeHomefolder { #create the user directory and then eventually set security on + it print "Creating FTP Folder $_[0]\n"; system ("mkdir $_[0]"); #system ("xcacls $userRoot /t /y /g administrators:f $domain\\ +$id:c \"Authenticated Users\":r"); #system ("xcacls $userRoot\\private /e /y /R Everyone \"Authen +ticated Users\""); #print "\nSeting Ownership on Users Home Folder\n"; #system ("setowner -r $domain\\$id $userRoot"); #print "\nCreating Users Hidden Share\n"; #system ("rmtshare \\\\$homeServer\\$id\$=d:\\users\\$id"); } sub makePermissions { $stop=1; opendir DIR, "$_[0]" or &ERROR();; sub ERROR { $stop=0; } if($stop==1) { closedir DIR; $ftpuser = "\\\\$server\\$_[1]"; #machine account, pass in + the server name beginning with double backslashes #domain account, refer to + it by specifying the domain followed by a backslash print "\nModifying Security on FTP Folder for Administrato +rs and $ftpuser\n"; #$Dir = new Win32::Perms( "$_[0]") || die; #$Dir->Remove(-1); #$Dir->Allow(Administrators,Win32::Perms::FULL_CONTROL_DIR +,Win32::Perms::DIR); #$Dir->Allow(Administrators,Win32::Perms::FULL_CONTROL_FIL +E,Win32::Perms::FILE); #$Dir->Set(); #$Dir->Allow("$ftpuser",Win32::Perms::CHANGE_DIR,Win32::Pe +rms::DIR); #READ_DIR #$Dir->Allow("$ftpuser",Win32::Perms::CHANGE_FILE,Win32::P +erms::FILE); #$Dir->Set(); system "xcacls $_[0] /T /G administrators:f dmz\\$_[1]:EWX + dmz\\master_userFTP:ewxdcp /Y"; # xcacls *.* /t /c /y /g administrators:f;f test:EX;EX #xcacls D:\Inetpub\ftproot\physical_directory\*.* /t /c /y + /g administrators:f;f PC\user2:EX;EX PC\user:f;f } } $file = "\%userprofile\%\\Desktop\\ftp_access_list.txt"; if (! open(OUTPUT, ">>$file") ) { print "\nCan Not Open $file :: FATAL ERROR!\n"; die; } #$i = 1; print OUTPUT "\n$user\t\t$psswd"; # the below code will parse the ftp_access_list file for usernames + and passwords. #while(<OUTPUT>){ # chomp; # if (/(\S+)(\s+)(\S+)/) { # $ftp_href->{$i}{user} = $1; # $ftp_href->{$i}{password} = $3; # } #print "$_\n"; # print "ftp_href->{$i}{user} = $ftp_href->{$i}{user}\n"; # print "ftp_href->{$i}{password} = $ftp_href->{$i}{password}\n +"; # $i++; #} close OUTPUT; print "Would you like to create another FTP account? [y|n]: "; chomp($go=<STDIN>); $go =~ s/[Yy]/1/; $go =~ s/[Nn]/0/; }

quick and dirty, didn't use strict
Post any questions and I will respond ASAP.


-----BEGIN PERL GEEK CODE BLOCK----- Version: 0.01 P*c?P6?R M O MA--E-PU-BD--C D++S+++X WP MO+PP?n-CO--PO--o+G+A--OL!OLC-OLCC-OLL- -OLA--Ee---Ev----Eon++++Eot!Eob!Eoa!uL uS w--m+ ------END PERL GEEK CODE BLOCK------

Replies are listed 'Best First'.
Re: iis ftp redirection
by rinceWind (Monsignor) on Mar 21, 2006 at 09:03 UTC
    quick and dirty, didn't use strict

    Do you have any reason not to use strict or warnings? This script is large enough that I would be unwilling to maintain or enhance it without use strict in place.

    Have you wasted any time debugging typos that strict would have found? This nearly always justifies starting off with strict - it certainly does for me.


    Oh Lord, wonít you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, wonít you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      I don't use strict because perl doesn't and didnít require me to.

      I can appreciate strict when considering maintenance within the perl community and that ideal is probably what makes perl such a great portable language with so many useful modules. But since I havenít written any modules yet and am evolving my understanding of the perl global community this is just one small contribution for all it has done for me.

      I like perl compared to VBS because it doesn't have as many strict rules although VBS is powerful in its own right on windows systems. Perl is different especially when compared to Microsoft based languages WSH, ASP, .NET etc. and I like to be creative. Perl's flexible but yet a defined set of rules, without much restriction, is what attracts me to a programming language... somewhat similarly that is why I like PL/SQL over T-SQL. Microsoft languages have many more standard formalities, declarations... Perhaps my implementation is obscure and somewhat obfuscated according to strict implementations but it does what it says it does and it can be used on IIS 4, 5, 5.1 and 6 to disable anonymous access via IIS FTP.

      Is creative, useful, unconventional, functionality obscure and obfuscated and therefore frowned upon?
        Is creative, useful, unconventional, functionality obscure and obfuscated and therefore frowned upon?

        No, not using strict is just undisciplined. I feel pretty safe in saying that most good, creative, unconventional code is written by people who use strict strictly.

        When I was a VB programmer, it was easy to divide a line between "stuff that was crap" and "stuff that we don't know about yet but might be crap or might be great stuff" by whether it used Option Declare. So I just utterly disbelieve you. Go write great stuff. I love great stuff. But use strict and disable it only for those small parts where you know it's the best thing to do at that moment.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://538040]
Approved by planetscape
Front-paged by diotalevi
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2017-04-24 22:20 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (447 votes). Check out past polls.