Help - Search - Members - Calendar
Full Version: Domain Aliases
The Planet Forums > Control Panels > Plesk
smack
Ok, with regular ol' Apache this is a very simple setup, but with Plesk...hmm.

I've got to have multiple domain names point to one domain space...somehow. A solution via plesk would be ideal...otherwise I'll just have to set it up with the registrar.

Any suggestions?
zacpac
this is something that i am in the middle of writing a script todo the script is doesnt work properly at the moment and i know what it needs to do so when i am finished with it i will post it but if you want to give me a hand finishing it let me know

dan ;-)
levovich
Use steps below at your own risk. I don't provide any warranty and will not assume responsibility if you screw up the server. However, I should also say that the solution below works for me and a couple of other people I know.

Don't forget to change <$domain> to your actual domain, e.g. testdomain.com. Don't forget to change <$ip> to your actual ip, e.g. 123.123.123.123.

1. pico /var/named/run-root/etc/named.conf
2. Add the following lines at the end of the file and save it:
QUOTE
zone "<$domain>" {
       type master;
       file "<$domain>";
};

3. pico /var/named/run-root/var/<$domain>
4. Add the following lines and save the file:
QUOTE
$TTL 86400

@ IN SOA ns1.<$domain>. [email=info@<$domain>]info@<$domain>[/email]. (
1016902773 ; serial
10800 ; refresh
3600 ; retry
604800 ; expire
86400 ) ; minimum

<$domain>. IN NS ns1.<$domain>.
<$domain>. IN NS ns2.<$domain>.
www. <$domain>. IN A <$ip>
<$domain>. IN A <$ip>

5. pico /etc/httpd/conf/httpd.conf
6. Add the following lines at the end of the file and save it:
QUOTE
Include conf/httpd.domainalias

7. pico /etc/httpd/conf/httpd.domainalias
8. Add the following lines at the end of the file and save it:
QUOTE

ServerName <$domain>
RedirectPermanent / http://www.<$targetdomain>/  

9. service named restart
10. service httpd restart
11. service psa restart
zacpac
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";

?>
it_ideas
How to Operate your script ?

i am ready to test for making alias of domain..
zacpac
log in as root

then cd to the dir with the script in it

please change the $BACKUP="/home/backup/psa/qmailConfig";
to something that you will use

> ./domainParking.php masterDomain.Name aliasDomain.Name pleskCPUsername

exapmle is

if you have dell.com and you want to alias dell.co.uk and the master CP login is johndell

> ./domainParking.php dell.com dell.co.uk johndell

if you have any more questions please let me know
it_ideas
./domainParking.php voxhits.com voxhits.net cybervox
1064630904
ERROR: Execution failed. Conflict found in 'ip' field: must be specified

1 error(s) found. Please run '/usr/local/psa/bin/domain.pl -h' for usage information
ERROR: Execution failed. Conflict found in 'update' command; cannot find domain 'voxhits.net' in PSA database


Warning: copy(/root/backup/psa/qmailConfig/virtualdomains.1064630904): failed to open stream: No such file or directory in /root/subdomain/domainParking.php on line 91

failed copy virtualdomains and rcpthosts
completed creation of work versions
found master domain name


Warning: md5_file(): Unable to open file in /root/subdomain/domainParking.php on line 129

ERROR with virtualdomains files
apache file backup complete
found master SeverAlias and added parked domains
apache has now been reconfigured and restarted
qmail has now been reconfigured and restarted
job complete
it_ideas
[root@ns2 subdomain]# ./domainParking.php voxhits.com voxhits.net cybervox
1064631152
ERROR: Execution failed. Conflict found in 'ip' field: must be specified

1 error(s) found. Please run '/usr/local/psa/bin/domain.pl -h' for usage information
ERROR: Execution failed. Conflict found in 'update' command; cannot find domain 'voxhits.net' in PSA database
completed backup virtualdomains.1064631152 and rcpthosts rcpthosts.1064631152
completed creation of work versions
found master domain name
ERROR with virtualdomains files
no apache masterdomain config file found, created file
starting adding of ServerAlias
the ServerAlias has now been added to the top of the file
apache has now been reconfigured and restarted
qmail has now been reconfigured and restarted
job complete
zacpac
can you let me know what version of plesk your are using ?

i think the problem might be that the domain has a static ip address and is not namebased. but i wrote this script for plesk 5.0.5 and havent had a chance to test with plesk 6 as yet

cheers

dan
it_ideas
6.0.1
zacpac
cheers i will download 6.0.1 and run some tests from what i have seen it has a different way of dealing with ip addresses by allowing to have multiple namebased ipaddresses

to create an alias with out using the script

add the new domain name to the customers account making sure it has the correct ipaddress in the DNS section

add this to a vhost.conf file in the master domain's conf folder

ServerAlias aliased.domain *.aliased.domain

restart apache using this command

/usr/local/psa/admin/bin/my_apci_rst

for aliasing the mail go to

/var/qmail/control

edit the virtualdomains file

find the master domain and note the number after the :

next find the aliased domain name

this will have a different number after it what i do is put a # to comment that line out then insert a new line either straight after that line or at the bottom of the file with

aliased.domain:master.domain number

eg.

voxhits.com:1
#voxhits.net:2
voxhits.net:1

after that restart qmail

service qmail restart

and that will create your aliased domain the only problem is that the end user logging in will not really see this or understand this as there is nothing to let them know in the control panel to let them know this has happened

if you have any problems with my instructions please let me know
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.