i have now written a script that works in my enviroment and would need further testing by other uses so that it can prove it does
this is beta quality code so be careful
dan
#!/usr/bin/php -q
# PROGRAM INFORMATION
# -------------------
# domainParking.php Version 0.02
#
# usage:
# php domainParking.php $MASTERDOMAIN $PARKEDDOMAIN $LOGINOFMASTERDOMAIN
#
# created by: Dan Hunter email:
dan@inatosnetworks.net
#
# copyright Dan Hunter 2003
#
# this script is free to use and abuse. it has not been fully tested
# and will most likely contain bugs it is also in an unfinished state
# although it has worked in ever test i have thrown at it. i will not
# class this as anything greater than beta quaility code. if this code
# breaks your system i can not be held responsible.
#
# what does this script do:
# this script was written so that i could add aliased/parked domains to
# plesk this is something that i find very lacking from the current
# versions of plesk. i have only tested this with plesk 5 and although
# from what i have seen of plesk 6 this should still work by changing
# $MASTERDOMAINAPACHECONF="httpd.include" i have made the assumption that
# all plesk 6 virtual hosts httpd.include files will have a ServerAlias
# as beta version i downloaded had this i will be expecting to upgrade
# my rackshack server to plesk 6 as soon as it becomes avalialbe there and
# then i can test and change as nessesary
#
# suggestions:
# as this script will use one of your domains up it would be an idea to have
# an unlimited version of plesk
#
# help:
# if someone finds a bug or has a better way of doing what i am tring
# to achieve please let me know also if someone wants to help with develoment
# i would be most greatful as i believe 2 heads are greater than one
#
# needed variables
$BACKUP="/home/backup/psa/qmailConfig";
$PSAHOME="/usr/local/psa";
$VIRTUALHOSTPATH="/home/httpd/vhosts";
$MASTERDOMAINAPACHECONF="vhost.conf";
$QMAIL="/var/qmail";
$RESTARTQMAIL="service qmail reload";
$UNIXTIMETEMP=gettimeofday();
$UNIXTIME=$UNIXTIMETEMP["sec"];
$SCRIPTPATH=".";
#$MASTERDOMAIN="dev.adomain.net";
#$PARKEDDOMAIN="dev.adomain.com";
$MASTERDOMAIN=$argv[1];
$PARKEDDOMAIN=$argv[2];
$LOGINOFMASTERDOMAIN=$argv[3];
$domainregex="/^[A-z0-9]([A-z0-9-]{0,61}[A-z0-9]){0,1}(.[A-z0-9]([A-z0-9-]{0,61}[A-z0-9]){0,1})+$/";
if (!preg_match($domainregex, $MASTERDOMAIN) && !preg_match($domainregex, $PARKEDDOMAIN)){
echo "you have not entered a correctly formatted domain namen";
exit;
}
if (phpversion() < 4.2){
function md5_file($inFile) {
if (file_exists($inFile)) {
$fd = fopen($inFile, 'r');
$fileContents = fread($fd, filesize($inFile));
fclose ($fd);
return md5($fileContents);
} else {
return false;
}
}
}
# start of program
echo $UNIXTIME."n";
# add the parked domains to plesk
if ($LOGINOFMASTERDOMAIN){
$domainOUTPUT = shell_exec("$PSAHOME/bin/domain.pl -c $PARKEDDOMAIN -dns true -clogin $LOGINOFMASTERDOMAIN");
echo $domainOUTPUT;
$domainprefOUTPUT = shell_exec("$PSAHOME/bin/domain_pref.pl -u $PARKEDDOMAIN -space 2 -traffic 50 -max_box 0 -max_redir 0 -boxquota 0 -max_mg 0 -max_wu 0 -max_db 0 -max_aresp 0 -webmail true") ;
echo $domainprefOUTPUT;
}
#make backup of the virtualdomains file and the rcpthosts
if (copy("$QMAIL/control/virtualdomains", "$BACKUP/virtualdomains.$UNIXTIME") && copy("$QMAIL/control/rcpthosts", "$BACKUP/rcpthosts.$UNIXTIME")){
echo "completed backup virtualdomains.$UNIXTIME and rcpthosts rcpthosts.$UNIXTIMEn";
}else{
echo "failed copy virtualdomains and rcpthostsn";
}
# create work copies of files
if (copy("$QMAIL/control/virtualdomains", "$SCRIPTPATH/virtualdomains.work") && copy("$QMAIL/control/rcpthosts", "$SCRIPTPATH/rcpthosts.work")){
echo "completed creation of work versions n";
}else{
echo "failed copy virtualdomains and rcpthostsn";
}
# load file
$contents = file("$SCRIPTPATH/virtualdomains.work");
$totalnumline =count($contents);
for($i=0 ;$i<$totalnumline ; $i++){
# loop to find the correct domain name
$contentsbits =explode(':',$contents[$i]);
if ($contentsbits[0] == $MASTERDOMAIN){
$VIRTUALHOSTNUMBER = $contentsbits[1] ;
echo "found master domain namen";
}
if ($VIRTUALHOSTNUMBER !=""){
if ($contentsbits[0] == $PARKEDDOMAIN){
echo "found parked domain namen";
$newline = $totalnumline+1;
$contents[$newline] = $PARKEDDOMAIN.":".$VIRTUALHOSTNUMBER;
$contents[$i] = "#".$contentsbits[0].":".$contentsbits[1];
}
}
}
$newfile = implode("",$contents);
$out = fopen("$SCRIPTPATH/virtualdomains.new", "w");
fwrite($out, $newfile);
fclose($out);
if (md5_file("$QMAIL/control/virtualdomains") == md5_file("$BACKUP/virtualdomains.$UNIXTIME")&& md5_file("$QMAIL/control/virtualdomains") != md5_file("$SCRIPTPATH/virtualdomains.new")){
if (copy("$SCRIPTPATH/virtualdomains.new", "$QMAIL/control/virtualdomains")){
echo "new virtualdomains file has been copied n";
}else{
echo "failed to copy the new virtualdomainsn";
}
}else{ echo"ERROR with virtualdomains filesn";
}
# apache reconfiguration
if (!file_exists($VIRTUALHOSTPATH."/".$MASTERDOMAIN."/conf/".$MASTERDOMAINAPACHECONF)) {
touch($VIRTUALHOSTPATH."/".$MASTERDOMAIN."/conf/".$MASTERDOMAINAPACHECONF); // Create blank file
chmod($VIRTUALHOSTPATH."/".$MASTERDOMAIN."/conf/".$MASTERDOMAINAPACHECONF,0644);
echo "no apache masterdomain config file found, created filen";
}else{
if (copy("$VIRTUALHOSTPATH/$MASTERDOMAIN/conf/$MASTERDOMAINAPACHECONF", "$VIRTUALHOSTPATH/$MASTERDOMAIN/conf/$MASTERDOMAINAPACHECONF.backup$UNIXTIME")){
echo "apache file backup completen";
}else{
echo "failed apache backupn";
}
}
# load file apache config file
$ap_contents = file("$VIRTUALHOSTPATH/$MASTERDOMAIN/conf/$MASTERDOMAINAPACHECONF");
$ap_totalnumline =count($ap_contents);
for($i=0 ;$i<$ap_totalnumline ; $i++){
# loop to find the correct ServerAlias
$ap_contentsbits =explode(' ',$ap_contents[$i]);
$ap_result = count ($ap_contentsbits);
for($j=0 ;$j<$ap_result ; $j++){
if ($ap_contentsbits[$j] == "ServerAlias"){
$ap_contentsbits[$ap_result-1] = "$PARKEDDOMAIN *.$PARKEDDOMAIN ".$ap_contentsbits[$ap_result-1]."n";
$foundServerAlias=1;
echo "found master SeverAlias and added parked domainsn";
}
}
$ap_contents[$i] = implode(" ",$ap_contentsbits);
}
# at the moment i am assuming that plesk 6 will always have a ServerAlias for
www.$MASTERDOMAIN
# until i have tested further and have upgraded my plesk 5 licence i can not tell but there has
# been a change from vhost.conf to httpd.include which make much more sense to me but if SeverAlias
# cannont be gaurunteed then i will have to work out where in the file this should go and put it there
if ($foundServerAlias != 1){
echo"starting adding of ServerAliasn";
if ( !is_array($ap_contents) ) {$ap_contents= array();echo"creating array";}
$ap_contents =array_reverse ($ap_contents);
array_push ($ap_contents, "ServerAlias $PARKEDDOMAIN *.$PARKEDDOMAINn");
$ap_contents =array_reverse ($ap_contents);
echo "the ServerAlias has now been added to the top of the filen";
}
$ap_newfile = implode("",$ap_contents);
$ap_out = fopen("$VIRTUALHOSTPATH/$MASTERDOMAIN/conf/$MASTERDOMAINAPACHECONF", "w");
fwrite($ap_out, $ap_newfile);
fclose($ap_out);
# restart the services
$apacheOUTPUT = shell_exec("$PSAHOME/admin/sbin/my_apci_rst");
echo "apache has now been reconfigured and restartedn";
$qmailOUTPUT = shell_exec("$PSAHOME/admin/sbin/restart_daemons qmail restart");
echo "qmail has now been reconfigured and restartedn";
echo "job completen";
?>