Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 20th, 2001, 02:42 PM
ponch9's Avatar
ponch9 ponch9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: San Diego, CA
Posts: 34 ponch9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 29 m 11 sec
Reputation Power: 8
Send a message via ICQ to ponch9 Send a message via AIM to ponch9 Send a message via Yahoo to ponch9
Question Automate setup of Virtual Hosting

Hi there:
I've been working for a web hosting company for more than 3 years, and not too long ago I realized that there must be a way of automating several redundant daily tasks that I have been doing throughout this time.

Therefore, I sat down and thought to myself, I would like to make it possible for the sales people to add new hosting clients to our server themselves. So I don't have to go in with the vi-editor and make changes to the httpd.conf file and adduser several times per day. But, since they don't know any UNIX, I would like to have them login to a secure backroom, made by php or something similar.

Once they are in the backroom, then they would have the ability to type in the new hosting clients domain name, 5 email usernames and passwords, ftp username and password, and submit it.

Then the php page would execute a bash or perl script or something else, that make proper additions to the apache's httpd.conf file, adds the ~/virtual_folder where the site is going to be located on the server, add a generic splash page, add ftp l/p, add up to 5 email l/p.

Is this something that can be made? Would somebody have any suggestions or information that could be useful?

Maybe any places on the web where I could find valuable info?

I found this article which is very helpful, but lack some other things that I would think is useful.

http://www.freebsdzine.org/attic/199903/isp.txt

For example, how would I run that script with php?

Also, a friend of mine sent me some perl scripts that could be used for this purpose, however, how would I use them with php? exec()?

Maybe this should be integrated with MySQL?

All help is greatly appreciated.

Sincerely Yours,
Ponch

Reply With Quote
  #2  
Old June 20th, 2001, 04:57 PM
mullaney mullaney is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 0 mullaney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ponch,

Here is some code I put together a while back. Maybe you can get some ideas from it. If you need further explanation, let me know. This was designed for a Linux box running Apache and Bind DNS.

Bob
====

#!/usr/bin/perl
###########################################################
# Usage: newdomain.pl arg1 [arg2...]
# Arguments should be domain name plus extension as
# it will appear in DNS.
#
# Created: 05/11/01
# Updated: 05/11/01
#
# By : Bob Mullaney
###########################################################

$wwwdir = '/var/www';
$dnsdir = '/usr/local/bind/zones';
$templates = '/var/www/default';
$passwd = '/etc/passwd';
$named_conf = '/etc/named.conf';
$apache_conf = '/usr/local/apache/conf/virtual.inc';
$apache_cont = '/usr/local/apache/bin/apachectl';
$hostmaster = 'hostmaster.abc.com.';
$dnsdefault = 'dns.abc.com.';
$ipdefault = '192.168.1.100';

chomp ($DATE = `date +%D`);
$domains = 0;
foreach $arg (@ARGV) {
print "\n### Beginning Processing for $arg.\n";
$USER = $arg;
$USER =~ s/\.com//;
$USER =~ s/\.org//;
$USER =~ s/\.net//;
$length = length $USER;
if ($length > 8) {
$USER = substr($USER,0,8);
}

print "# Creating user...$USER.\n";
open (FILE, "$passwd");
@users = <FILE>;
close (FILE);
$userinc = 0;
USERCHK: foreach $exist (@users) {
chomp $exist;
my @elements = split (/:/,$exist);
$uc_element = uc($elements[0]);
$uc_user = uc($USER);
#print "Comparing $uc_element with $uc_user.\n";
if ($uc_element eq $uc_user) {
print "Username $USER already taken!...";
if ($length < 8) {
$USER = "$USER$userinc";
print "Will try username $USER\n";
}
else {
chop $USER;
$USER = "$USER$userinc";
print "Will try username $USER\n";
}
#last;
$userinc++;
redo USERCHK;
}
}
system ("/usr/sbin/useradd -c \"$arg - $DATE\" -g 80 -d /home/$USER -m -s /bin/bash $USER");

print "# Setting up files...\n";
system ("mkdir -p $wwwdir/$arg/cgi-bin");
system ("mkdir -p $wwwdir/$arg/html");
system ("mkdir -p $wwwdir/$arg/logs");
system ("mkdir -p ~$USER/ftp");
system ("ln -s $wwwdir/$arg ~$USER/www");
system ("chown $USER:80 $wwwdir/$arg");
system ("chown $USER:80 $wwwdir/$arg/cgi-bin");
system ("chown $USER:80 $wwwdir/$arg/html");
system ("chown $USER:80 $wwwdir/$arg/logs");
system ("chown $USER:80 ~$USER/ftp");
system ("chown $USER:80 ~$USER/www");
system ("cp $templates/cgi-bin/index.cgi $wwwdir/$arg/cgi-bin/index.cgi");
system ("chmod 755 $wwwdir/$arg/cgi-bin/index.cgi");
system ("cp $templates/html/template.shtml $wwwdir/$arg/html/index.shtml");

print "# Updating Web Configuration...\n";
open (FILE, ">> $apache_conf");
print FILE "\n";
print FILE "<VirtualHost *>\n";
print FILE " ServerName $arg\n";
print FILE " ServerAlias *.$arg\n";
print FILE " ServerAdmin webmaster\@$arg\n";
print FILE " DocumentRoot $wwwdir/$arg/html\n";
print FILE " ScriptAlias /cgi-bin/ \"$wwwdir/$arg/cgi-bin/\"\n";
print FILE " Loglevel warn\n";
print FILE " ErrorLog $wwwdir/$arg/logs/error_log\n";
print FILE " CustomLog $wwwdir/$arg/logs/access_log common\n";
print FILE " <Directory $wwwdir/$arg/html>\n";
print FILE " Options Includes\n";
print FILE " </Directory>\n";
print FILE " <Directory $wwwdir/$arg/cgi-bin>\n";
print FILE " Options ExecCGI\n";
print FILE " </Directory>\n";
print FILE "</VirtualHost>\n";
print FILE "\n";
close (FILE);

print "# Updating DNS Configuration...\n";

if (-e "$dnsdir/db.$arg") {
print "File Already Exists!\n";
}

open (FILE, ">> $named_conf");
print FILE "\n";
print FILE "zone \"$arg\" {\n";
print FILE " type master;\n";
print FILE " file \"db.$arg\";\n";
print FILE "};\n";
close (FILE);

open (FILE, "> $dnsdir/db.$arg");
print FILE "\$TTL 900\n";
print FILE "@ IN SOA $dnsdefault $hostmaster (\n";
print FILE "2000010101 ; serial date\n";
print FILE "3600 ; refresh every hour\n";
print FILE "1800 ; retry every half hour\n";
print FILE "604800 ; expire after one week\n";
print FILE "9000 ) ; minimum TTL of 12 hours\n";
print FILE "\n";
print FILE "@ IN NS $dnsdefault\n";
print FILE "\n";
print FILE "@ IN A $ipdefault ; Answers for domain.com.\n";
print FILE "* IN CNAME @ ; Answers for all names which are undefined.\n";
print FILE "\n";
close (FILE);

print "# Done...\n";
$domains++;
}

# Restart Servers
print "\nCreated $domains new domain(s).\n";
print "# Restarting Servers.\n";
system ("$apache_cont restart");
system ("kill -HUP `cat /var/run/named.pid`");

exit;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Automate setup of Virtual Hosting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT