#!/usr/bin/perl

print "What is the domain?\n";
$domain = <STDIN>;
chomp($domain);
$domain = lc($domain);

print "Enable WebStats Service ?\n";
$serv1 = <STDIN>;
chomp($serv1);
$serv1 = lc($serv1);

print "Enable Customised Logs Service ?\n";
$serv2 = <STDIN>;
chomp($serv2);
$serv2 = lc($serv2);

print "Enable Multiple Email Service ?\n";
$serv3 = <STDIN>;
chomp($serv3);
$serv3 = lc($serv3);

print "Enable Updates Service ?\n";
$serv4 = <STDIN>;
chomp($serv4);
$serv4 = lc($serv4);

print "Enable Scripting Service ?\n";
$serv5 = <STDIN>;
chomp($serv5);
$serv5 = lc($serv5);

print "Enable Database Service ?\n";
$serv6 = <STDIN>;
chomp($serv6);
$serv6 = lc($serv6);

print "Give me the pop user id ?\n";
$userid = <STDIN>;
chomp($userid);
$userid = lc($userid);

print "Give me the password ?\n";
$pass = <STDIN>;
chomp($pass);
$pass = lc($pass);

system("cp -r /home/vhosts/.admin/webpages/.admin /home/vhosts/www.$domain/webpages");

if ($serv1 eq "yes") {

#system("mkdir /home/vhosts/www.$domain/webpages/webstats");
      open (MAIN, ">/home/vhosts/www.$domain/webpages/webstats/.accesscontrol")
 or
      die("unable to open main webstats accesscontrol File.");

        print MAIN "AuthUserFile /home/vhosts/www.$domain/cgi-bin/.admin/.htpass/.controller0\n";
        print MAIN "AuthName \"Secure Area - Admin Only\"\n";
        print MAIN "AuthType Basic\n";
        print MAIN "<limit GET>\n";
        print MAIN "require valid-user\n";
        print MAIN "</limit>\n";

      close(MAIN);

}

system("echo $pass | passwd $userid --stdin");

system("cp -r /home/vhosts/.admin/cgi-bin/.admin /home/vhosts/www.$domain/cgi-bin");

      open (MAINCONF, ">/home/vhosts/www.$domain/cgi-bin/.admin/config/main.pl") or
      die("unable to open main Config File.");

        print MAINCONF "\#\!/usr/bin/perl\n";
        print MAINCONF "\n";
        print MAINCONF "\$domain_name            = \"$domain\"\;\n";
        print MAINCONF "\$main_path              = \"/home/vhosts\"\;\n";
        print MAINCONF "\$working_directory      = \"www.$domain/webpages/.admin\"\;\n";
        print MAINCONF "\$ip_address             = \"213.161.75.222\"\;\n";
        print MAINCONF "\$script_location        = \"www.$domain/cgi-bin/.admin\"\;\n";
        print MAINCONF "\$default_work_dir       = \"www.$domain\"\;\n";
        print MAINCONF "\$htaccess_1             = \".controller1\"\;\n";
        print MAINCONF "\$htaccess_2             = \".controller2\"\;\n";
        print MAINCONF "\$htaccess_3             = \".controller3\"\;\n";
        print MAINCONF "\$access_file            = \".htaccess\"\;\n";
        print MAINCONF "\n\n";
        print MAINCONF "1\;";

      close(MAINCONF);

      open (MAINCONF2, ">/home/vhosts/www.$domain/cgi-bin/.admin/config/variables.pl")
 or
      die("unable to open main Variables File.");

        print MAINCONF2 "\#\!/usr/bin/perl\n";
        print MAINCONF2 "\n";
        print MAINCONF2 "\$htaccess               = \"0\"\;\n";
        print MAINCONF2 "\$alias_password         = \"$pass\"\;\n";
        print MAINCONF2 "\$server_hostname        = \"cluster1.my-hosts.com\"\;\n";
        print MAINCONF2 "\$no_pop_boxes           = \"0\"\;\n";
        print MAINCONF2 "\$service_1              = \"$serv1\"\;\n";
        print MAINCONF2 "\$service_2              = \"$serv2\"\;\n";
        print MAINCONF2 "\$service_3              = \"$serv3\"\;\n";
        print MAINCONF2 "\$service_4              = \"$serv4\"\;\n";
        print MAINCONF2 "\$service_5              = \"$serv5\"\;\n";
        print MAINCONF2 "\$service_6              = \"$serv6\"\;\n";
        print MAINCONF2 "\n\n";
        print MAINCONF2 "2\;";

      close(MAINCONF2);

      open (MAIN2, ">/home/vhosts/www.$domain/webpages/.admin/.accesscontrol")
 or
      die("unable to open main web admin accesscontrol File.");

        print MAIN2 "AuthUserFile /home/vhosts/www.$domain/cgi-bin/.admin/.htpass/.controller0\n";
        print MAIN2 "AuthName \"Secure Area - Admin Only\"\n";
        print MAIN2 "AuthType Basic\n";
        print MAIN2 "<limit GET>\n";
        print MAIN2 "require valid-user\n";
        print MAIN2 "</limit>\n";

      close(MAIN2);

      open (MAIN3, ">/home/vhosts/www.$domain/cgi-bin/.admin/.accesscontrol")
 or
      die("unable to open main webstats accesscontrol File.");

        print MAIN3 "AuthUserFile /home/vhosts/www.$domain/cgi-bin/.admin/.htpass/.controller0\n";
        print MAIN3 "AuthName \"Secure Area - Admin Only\"\n";
        print MAIN3 "AuthType Basic\n";
        print MAIN3 "<limit GET>\n";
        print MAIN3 "require valid-user\n";
        print MAIN3 "</limit>\n";

      close(MAIN3);

      open (MAIN4, ">/home/vhosts/www.$domain/cgi-bin/.admin/.htpass/.controller0")
 or
      die("unable to open main Password File.");

        print MAIN4 "$userid:$pass2\n";

      close(MAIN4);

system("chown -R $userid:www /home/vhosts/www.$domain/*");
system("chmod -R 777 /home/vhosts/www.$domain/*");
system("chmod -R 750 /home/vhosts/www.$domain/cgi-bin/.admin");
system("chmod -R 750 /home/vhosts/www.$domain/webpages/.admin*");
system("chown -R www:www /home/vhosts/www.$domain/cgi-bin/.admin*");
system("chown -R www:www /home/vhosts/www.$domain/webpages/.admin*");
system("chown $userid:www /home/vhosts/www.$domain");

print "done \n";
print "userid = $userid Password - $pass \n";
