|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
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; |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Automate setup of Virtual Hosting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|