Results 1 to 3 of 3
Thread: Auto Creation Web Sites in IIS
-
06-02-2005, 03:23 PM #1Retired Moderator
- Join Date
- Mar 2004
- Location
- Singapore
- Posts
- 6,990
Auto Creation Web Sites in IIS
I am not asking for controlpanels. Just a utility so that once you login you can have an easier time using that utility that can create web and ftp sites. Very afraid of my client creating themselves, they keep giving anonymous ftp.
-
06-02-2005, 04:07 PM #2Web Hosting Master
- Join Date
- May 2001
- Location
- @ Work - Usually!
- Posts
- 835
If you can run perl then this is somthing I put together to do exactly what you are asking. You can tweak it for your needs:
This is the PERL code:
PHP Code:#=======================================================================
use CGI;
use MD5;
# DECLARE VARIABLES
#=======================================================================
our $CGI = new CGI;
use CGI::Carp qw(fatalsToBrowser);
our %CONFIG;
$do = $CGI->param('do');
$result = &get_ini;
# DO ROUTINE
#=======================================================================
if ($do eq 'add_site') { $result = &add_site; }
elsif ($do eq 'delete_site') { $result = &delete_site; }
elsif ($do) { $result = "500:Command not understood"; }
else { $result = "500:No command given"; }
# PRINT STDOUT
#=======================================================================
print "Content-type: text/plain\n\n"
."$result";
# ROUTINES
#=======================================================================
# CREATE SITE
sub add_site
{
# REQUIRED PARAMETERS
$domain = $CGI->param('domain') || return "500:Domain required";
$username = $CGI->param('username') || return "500:Username required";
$password = $CGI->param('password') || return "500:Password required";
$quota = $CGI->param('quota') || return "500:Quota required";
$perl = $CGI->param('perl');
$php = $CGI->param('php');
$asp = $CGI->param('asp');
$ssi = $CGI->param('ssi');
$aspx = $CGI->param('aspx');
if ($asp) { $script_maps{'.asp'} = { exe => 'C:\\WINDOWS\\system32\\inetsrv\\asp.dll' , script => 5, verbs => 'GET,HEAD,POST,TRACE' } }
if ($aspx) { $script_maps{'.aspx'} = { exe => 'C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322\\aspnet_isapi.dll', script => 1, verbs => 'GET,HEAD,POST,DEBUG' } }
if ($ssi) { $script_maps{'.shtml'} = { exe => 'C:\\WINDOWS\\system32\\inetsrv\\ssinc.dll', script => 5, verbs => 'GET,POST' } }
if ($perl) { $script_maps{'.pl'} = { exe => 'C:\\Perl\\bin\\perl.exe "%s" %s', script => 5, verbs => 'GET,HEAD,POST' } }
if ($perl) { $script_maps{'.cgi'} = { exe => 'C:\\Perl\\bin\\perl.exe "%s" %s', script => 5, verbs => 'GET,HEAD,POST' } }
if ($php) { $script_maps{'.php'} = { exe => 'C:\\PHP\\php.exe' , script => 1, verbs => 'GET,HEAD,POST' } }
# SOME CHECKING
if (-e "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain") { return "500:Domain already here (FILESYSTEM)"; }
open FTP, "C:\\CONTROL\\ftpconfig.txt"; @lines = <FTP>; close (FTP);
foreach $line (@lines)
{
if ($line =~ /^$domain\:/i) { return "500:Domain already here (FTP)"; }
}
if (length($username) < 6) { return "500:Username too short"; }
if (length($password) < 6) { return "500:Password too short"; }
if (length($username) > 15)
{
$username = substr($username, 0, 14);
while (!$user_available)
{
foreach $line (@lines)
{
if ($line =~ /^$domain\:$username\:/i) { $match = true; }
}
if ($match) { $i++; $username = $username.$i; }
else { $user_available = true; }
}
}
# CREATE IIS
mkdir ("$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain");
mkdir ("$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\web");
mkdir ("$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\logs");
mkdir ("$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\database");
$result1 = `iisweb /create "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\web" $domain /i $CONFIG{SYSTEM_IP} /d [url]www.[/url]$domain /b 80`;
(@RESULT) = split(/\n/,$result1);
foreach $result_line (@RESULT)
{
if ($result_line =~ /metabase path/i)
{
($metabase_path) = $result_line =~ /^.*[=\s](\S+)$/i;
}
}
use Win32;
use Win32::OLE;
my $web=Win32::OLE -> GetObject("IIS://localhost/$metabase_path/Root") or $result2 .= "Win32::OLE -> GetObject() failed $!\n\nGetObject(\"IIS://localhost/W3SVC/108664378/Root\")";
$result2 = `net user "$username" "$password" /ADD /EXPIRES:NEVER /FULLNAME:"$domain" /PASSWORDCHG:NO /ACTIVE:YES`;
$result2 .= `cscript //nologo C:\\Inetpub\\AdminScripts\\adsutil.vbs SET $metabase_path/ServerBindings "$CONFIG{SYSTEM_IP}:80:$domain" "$CONFIG{SYSTEM_IP}:80:[url]www.[/url]$domain" "$CONFIG{SYSTEM_IP}:80:$domain.$CONFIG{TEMP_DOMAIN}"`;
$result2 .= `cscript //nologo C:\\Inetpub\\AdminScripts\\adsutil.vbs SET $metabase_path/AnonymousUserName "$CONFIG{WINDOWS_DOMAIN}\\$username"`;
$result2 .= `cscript //nologo C:\\Inetpub\\AdminScripts\\adsutil.vbs SET $metabase_path/AnonymousUserPass "$password"`;
$result2 .= `cscript //nologo C:\\Inetpub\\AdminScripts\\adsutil.vbs SET $metabase_path/AnonymousPasswordSync "true"`;
$result2 .= `cscript //nologo C:\\Inetpub\\AdminScripts\\adsutil.vbs SET $metabase_path/LogFileDirectory "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\logs"`;
$result2 .= `cscript //nologo C:\\Inetpub\\AdminScripts\\adsutil.vbs SET $metabase_path/LogFileLocaltimeRollover "true"`;
if (%script_maps)
{
$result2 .= "ADDING EXTENSIONS\n";
use Win32;
use Win32::OLE;
my $web=Win32::OLE -> GetObject("IIS://localhost/$metabase_path/Root") or $result2 .= "Win32::OLE -> GetObject() failed $!\n\nGetObject(\"IIS://localhost/W3SVC/108664378/Root\")";
my $new_maps = [];
foreach (sort keys %script_maps)
{
push @$new_maps, join ',',$_ , $script_maps{$_}->{exe} , $script_maps{$_}->{script} ,$script_maps{$_}->{verbs}
}
$web->{"ScriptMaps"} = $new_maps;
$web->{"AppFriendlyName"} = "$domain";
$web->{"AspEnableParentPaths"} = "true";
$web->SetInfo();
}
$result2 .= `cacls "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain" /T /E /G "$username:F"`;
$result2 .= `cacls "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain" /T /E /G "Users:W"`;
# CREATE FTP SITE
$config_line = "$domain:$username:$password:$quota:\n";
open OUT, ">>C:\\CONTROL\\ftpconfig.txt";
print OUT $config_line;
close OUT;
&create_bftpd();
# RETURN ALL IS WELL
return "200:Website created:$domain:$username:$password\n\n$result1\n\n$result2\n\n$metabase_path";
}
# DELETE SITE
sub delete_site
{
# REQUIRED PARAMETERS
$domain = $CGI->param('domain') || return "500:Domain required";
# GET USERNAME
open FTP, "C:\\CONTROL\\ftpconfig.txt"; @lines = <FTP>; close (FTP);
foreach $line (@lines)
{
if ($line =~ /^$domain\:/i)
{
(undef,$username,undef) = split(/\:/,$line);
}
}
# DELETE IIS
$result1 = `iisweb /delete $domain`;
$result2 = `net user "$username" /DELETE`;
$result2 .= `RMDIR /S /Q "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\database"`;
$result2 .= `RMDIR /S /Q "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\logs"`;
$result2 .= `RMDIR /S /Q "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain\\web"`;
$result2 .= `RMDIR /S /Q "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$domain"`;
# DELETE FTP SITE
foreach $line (@lines) { unless ($line =~ /^$domain\:/i) { $ftp_buffer .= $line; } }
open OUT, ">C:\\CONTROL\\ftpconfig.txt";
print OUT $ftp_buffer;
close OUT;
&create_bftpd();
return "200:Website deleted\n\n$result1\n\n$result2";
}
# CREATE FTP CONFIG (BULLETPROOF FTPD)
sub create_bftpd
{
$cfg = "[{DOMAIN}]\n"
."Login={USER}\@{DOMAIN}\n"
."Pass={PASS}\n"
."Home-Ip=$CONFIG{SYSTEM_IP}\n"
."RelativePath=1\n"
."TimeOut=600\n"
."MaxConPerIp=1\n"
."MaxUsers=0\n"
."RatioMethod=0\n"
."RatioUp=1\n"
."RatioDown=1\n"
."RatioCredit=0\n"
."MaxSpeedRcv=512\n"
."MaxSpeedSnd=512\n"
."QuotaCurrent=0\n"
."QuotaEnabled={QUOTA_ENABLED}\n"
."QuotaMax={QUOTA}\n"
."Dir0={HOME}\n"
."Attr0=RWDAMLSK\n\n";
open FTP, "C:\\CONTROL\\ftpconfig.txt"; @lines = <FTP>; close (FTP);
foreach $line (@lines)
{
($ftp_domain,$ftp_user,$ftp_password,$quota) = split(/\:/,$line);
if (!$quota) { $quota = 0; $quota_enabled = 0; }
else { $quota_enabled = 1; }
next if (!$ftp_domain);
$md5 = new MD5;
$md5_passwd = $md5->hexhash($ftp_password);
$md5_passwd = "\U$md5_passwd";
$ftp_home = "$CONFIG{SYSTEM_DISK}:$CONFIG{SITE_PATH}\\$ftp_domain";
$user_out = $cfg;
$user_out =~ s/{DOMAIN}/$ftp_domain/g;
$user_out =~ s/{USER}/$ftp_user/g;
$user_out =~ s/{HOME}/$ftp_home/g;
$user_out =~ s/{PASS}/$md5_passwd/g;
$user_out =~ s/{QUOTA}/$quota/g;
$user_out =~ s/{QUOTA_ENABLED}/$quota_enabled/g;
$buffer .= $user_out;
}
open FTP, ">$CONFIG{BFTPD_PATH}\\Users.ini" or die "Cant open Users.ini : $!";
print FTP $buffer;
close FTP;
open RELOAD, ">$CONFIG{BFTPD_PATH}\\reload" or die "Cant open reload";
close RELOAD;
}
# GET GLOBALS FROM INI FILE
sub get_ini
{
open INI, "C:\\CONTROL\\config.ini" or return "500:Cant open ini";
@lines = <INI>; close(INI);
foreach $line (@lines)
{
chomp $line;
next if ($line !~ /=/);
($var,$val) = $line =~ m/^(\S+).*[\s=]\"(.*)\"/;
$CONFIG{$var} = $val;
}
}
#=======================================================================
-
06-02-2005, 08:09 PM #3Retired Moderator
- Join Date
- Mar 2004
- Location
- Singapore
- Posts
- 6,990
Thanks a million Sir! I will try it out.