#!/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=); print "Please enter FTP Password : "; chomp($psswd=); $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 /passwordchg:no"); #cusrmgr.exe. (cusrmgr -u [-m \\] +s PasswordNeverExpires 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 default 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 \"Authenticated 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 Administrators 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_FILE,Win32::Perms::FILE); #$Dir->Set(); #$Dir->Allow("$ftpuser",Win32::Perms::CHANGE_DIR,Win32::Perms::DIR); #READ_DIR #$Dir->Allow("$ftpuser",Win32::Perms::CHANGE_FILE,Win32::Perms::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(){ # 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=); $go =~ s/[Yy]/1/; $go =~ s/[Nn]/0/; } #### -----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------