#!/usr/bin/perl
use Win32::OLE;
use Win32::NetAdmin;
use Win32::Lanman;
#use Win32::Perms;
$server = "dmz";
print "\nHello welcome to Chris Thomas' 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(
quick and dirty, didn't use strict
Post any questions and I will respond ASAP.
Enjoy,
3dbc
-----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------
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, wont 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, wont you burn me a Knoppix CD ?
(Missquoting Janis Joplin)
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.
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
Actually, in my experience, that definition contradicts itself. It's those subtle errors that are difficult to diagnose and fix that makes writing scripts slower and more tedious. Unless, I suppose, we use "M$"'s definition where writing does not include testing and fixing, nor does it imply writing correctly...
It's worth noting that one of the nicest, in a feel-good kind of way, improvement to my dev tool was when it could be configured to automatically insert Option Declare into everything it created. This prevented me from accidentally omitting it. Its when I'd forgotten to ensure that Option Declare was turned on that I'd just run across some bug allowed by the absence of the restriction. It's at those moments that I knew I had some pain ahead of me as I added Option Declare back in and went back to find the bugs that it had allowed to go undetected.
So no. There's absolutely no good reason whatsoever to ever neglect to use Option Declare. There is occasionally a reason to revoke strict but you should never write a script without loading it. Heck, these days I've taught emacs to automatically syntax check my perl on save because that's also really valuable. The more checks that I get automatically, the better code I can write and the less time I have to spend fiddling with stupid plumbing that I've installed wrong.
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
perlmonks.org content © perlmonks.org and 3dbc, diotalevi, rinceWind, Tanktalus
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03