[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cobalt-developers] command line shell tools perl script



Hi All,

Here is a command line shell tools perl script:

!/usr/bin/perl
#################################################################
# This script creates a new site on a Raq 550
#################################################################
use diagnostics;
use File::Find;
#use DBI;

################################################################
#change the 3 variables  below

$sendto = "setup\@yourdomain.com";
$defaultipaddress = "12.34.56.78";
$serveradminpassword = "";

###############################################################

$mailprog = '/usr/sbin/sendmail';

print "\n\n\n\n\n\n\n\n\n\n";
print
"#################################################################\n";
print
"#################################################################\n";
print "         Command Line Install Script for Raq 550 servers\n";
print
"#################################################################\n";
print
"#################################################################\n\n
";


print "Server IP (will default to $defaultipaddress ).. ";
$ipaddress = <STDIN>;
chomp ($ipaddress);
if ($ipaddress eq "") {
   $ipaddress = "$defaultipaddress ";
   print "Default IP $ipaddress applied\n";
}


print "Domain name without the www .............. ";
$domainname = <STDIN>;
chomp ($domainname);
$domainname =  lc ($domainname);

print "Hostnamne (can be left blank if it's www.. ";
$hostname = <STDIN>;
chomp ($hostname);
$hostname   =    lc($hostname);

print "Customer name............................. ";
$custname = <STDIN>;
chomp ($custname);

print "Customer email ........................... ";
$custemail = <STDIN>;
chomp ($custemail);

print "The siteadmin username ................... ";
$adminuser  = <STDIN>;
chomp ($adminuser);
$adminuser = lc($adminuser);

print "Password desired for this site ........... ";
$password = <STDIN>;
chomp ($password);

print "FP enabled (type 'yes') .................. ";
$fpenabled  = <STDIN>;
chomp ($fpenabled);


print "Maximum number of users (default is 50) .. ";
$maxusers  = <STDIN>;
chomp ($maxusers);
if ($maxusers eq "") {$maxusers = "50";}


print "Site quota (default is 200) .............. ";
$sitequota  = <STDIN>;
chomp ($sitequota);
if ($sitequota eq "") {$sitequota = "200";}


if ($hostname eq "") {$hostname = "www";}
if ($custname eq "") {$custname = "Hello";}



####################################
# check data
# get rid of spaces
$custemail   =~ s/ //g;
$domainname  =~ s/ //g;
$password    =~ s/ //g;


if (
   ($domainname  !~ /\./)
|| ($domainname  =~ /www\./)
|| ($adminuser   =~ /\./)
|| ($adminuser   eq "")

|| ($adminuser   =~ /\S{11,}/)
|| ($adminuser   !~ /\S{4}/)

|| ($domainname  =~ /\S{70,}/)
|| ($domainname  !~ /\S{4}/)

|| ($password    =~ /\S{11,}/)
|| ($password    !~ /\S{5}/)

|| ($hostname    =~ /\./)
|| ($hostname    eq "")


|| ($password    eq "")     ) {
    print "Check over the data imput and try again\n";
    exit;
}


if ( ($custemail !~ /\@/) or ($custemail !~ /\./) ) {
    print "This does not look like a valid email address. Please go
back and try again.";
    exit;
}


##########################################
#make the vsite with or with out FP extensions
print "Creating the site. Please wait.";

if (-e "/home/sites/$hostname.$domainname/web/") {
   print "It looks like this site: $hostname.$domainname already
exists. Installer stopped. ";
   exit;
} else {
     if ($fpenabled eq "yes")  {









system("/usr/sbin/caddvsite --domain=$domainname --host=$hostname --ma
xusers=$maxusers --enable-cgi --enable-php  -e
$domainname,mail.$domainname -w
$domainname,$hostname.$domainname,mail.$domainname --enable-fpx
$password  -a -p -c -s --quota=$sitequota --ipaddr=$ipaddress");
     }  else {
          print "Not FP enabled\n\n";










system("/usr/sbin/caddvsite --domain=$domainname --host=$hostname --ma
xusers=$maxusers --enable-cgi --enable-php  -e
$domainname,mail.$domainname -w
$domainname,$hostname.$domainname,mail.$domainname --enable-fpx
$password  -a -p -c -s --quota=$sitequota --ipaddr=$ipaddress");
     }
}

#$ls=`ls -la /home/sites | grep $hostname.$domainname`;
#print "$ls";

###########################################
#add the admin user
print "Creating the admin user now \n";

if (-e "/home/sites/$hostname.$domainname/web/index.html") {



system("/usr/sbin/cadduser --name=$adminuser --password='$password' --
fullname='adminuser' --fqdn=$hostname.$domainname --admin --adminPassw
ord='$serveradminpassword'  --quota=$sitequota ");
}

else {
     print "Was not ready yet for Add user. Wait 15 seconds and try
again.\nIt might be that the shell tools are not installed.";
     sleep (5);
     if (-e "/home/sites/$hostname.$domainname/web/index.html")  {
         system("/usr/sbin/cadduser -n $hostname.$domainname -u
$adminuser -p $password -q 100 -a -e do-not-delete-the-admin-user");
     }
     else  {
         print "Still not there. I'm going to exit without adding the
user. You'll probably need to delete the site and start over.";
         exit;
     }
}

#####################################################################
   if ($custemail eq ""){$custemail=$sendto;}
   print "Send the email";
   open (MAIL, "|$mailprog -t") || &safe_die("Can't open
$mailprog!\n");
   print MAIL "From: $sendto\n";
   print MAIL "Reply-To: $sendto\n";
   print MAIL "To: $custemail\n";
   print MAIL "Cc: $sendto\n";
   print MAIL "Subject: Web Site Settings For
$hostname.$domainname\n\n";
   print MAIL "$custname,\n";
   print MAIL  "
         domain is:         $domainname \n
         admin username is: $adminuser\n
         password is:       $password\n
         ";
   close (MAIL);

######################################################################
##

print "Completed\n";


exit;