1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice

Domain Aliasing script

Discussion in 'Plesk for Linux - 8.x and Older' started by zymsys, Dec 17, 2004.

  1. zymsys

    zymsys Guest

    0
     
    I saw a lot of people requesting the domain aliasing feature, and for me it is a show stopper. I'm trying to migrate to plesk and without it I can't do that migration.

    I looked for existing hacks to do this, but couldn't find anything. I wrote this script, and it seems to work pretty well. I hope it will either help some of you, or someone will point out that something bad will happen if I use it before I begin to depend on it!

    Code:
    #!/bin/bash
    
    # Do not use a www prefix with these domain names!
    # $1    Existing domain as known by plesk
    # $2    New domain to create
    
    echo "ServerAlias $1:80 [url]www.[/url]$2" >> /home/httpd/vhosts/$1/conf/vhost.conf
    echo "ServerAlias $1:80 $2" >> /home/httpd/vhosts/$1/conf/vhost.conf
    echo $2 >> /var/qmail/control/rcpthosts
    DOMNUM=`grep "$1:" /var/qmail/control/virtualdomains | cut -f 2 -d':'`
    echo "$2:$DOMNUM" >> /var/qmail/control/virtualdomains
    /usr/local/psa/admin/sbin/websrvmng -a -v
    QSPID=`ps aux |grep qmail-send |grep -v grep|sed 's/[^0-9]*\([0-9]*\).*/\1/'`
    kill -HUP $QSPID
    
    I called my copy newalias, and it is run like this:

    Code:
    ./newalias existingdomain.com newdomain.com
    
     
  2. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    Do you think that this script is OK to be added to PSA Power Toys 3?
    Is not hard to transform it and add to be inside Control Panel
     
  3. zymsys

    zymsys Guest

    0
     
    I'd be honoured if you added this to your Power Toys package. I haven't tried it yet myself, but I would be very interested to see what's involved.
     
  4. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    Tell me how can be reverse an alias, for example I want to get out an alias from a domain, cause I have changed my mind.

    If we include in Power Toys, we need to add a solution to reverse/uninstall it.
     
  5. zymsys

    zymsys Guest

    0
     
    Sorry this took so long, I've been busy on another project and just catching my breath now. Here's the un-install script:
    Code:
    #!/bin/bash
    # Do not use a www prefix with these domain names!
    # $1    Existing domain as known by plesk
    # $2    Aliased domain to remove
    
    grep -v \ [url]www.[/url]$2$ /home/httpd/vhosts/$1/conf/vhost.conf | grep -v \ $2$ > /home/httpd/vhosts/$1/conf/vhost.conf.new
    cp /home/httpd/vhosts/$1/conf/vhost.conf /home/httpd/vhosts/$1/conf/vhost.conf.bak
    mv /home/httpd/vhosts/$1/conf/vhost.conf.new /home/httpd/vhosts/$1/conf/vhost.conf
    grep -v ^$2$ /var/qmail/control/rcpthosts > /var/qmail/control/rcpthosts.new
    cp /var/qmail/control/rcpthosts /var/qmail/control/rcpthosts.bak
    mv /var/qmail/control/rcpthosts.new /var/qmail/control/rcpthosts
    DOMNUM=`grep "$1:" /var/qmail/control/virtualdomains | cut -f 2 -d':'`
    grep -v ^$2:5$ /var/qmail/control/virtualdomains > /var/qmail/control/virtualdomains.new
    cp /var/qmail/control/virtualdomains /var/qmail/control/virtualdomains.bak
    mv /var/qmail/control/virtualdomains.new /var/qmail/control/virtualdomains
    /usr/local/psa/admin/sbin/websrvmng -a -v
    QSPID=`ps aux |grep qmail-send |grep -v grep|sed 's/[^0-9]*\([0-9]*\).*/\1/'`
    kill -HUP $QSPID
    
     
  6. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    grep -v ^qualityhosting.net$ /var/qmail/control/rcpthosts > /var/qmail/control/rcpthosts.new

    ??, can you explain this, why qualityhosting.net ... is not $1?
     
  7. zymsys

    zymsys Guest

    0
     
    D'oh, I feel stupid! Qualityhosting.net is a domain I own that I don't normally use, and I used it for testing commands from the command line, then cutting and pasting them into the script when I saw that they worked right. I replaced qualityhosting.net with $2 manually instead of doing any kind of search and replace, and I see now that I missed a couple. Of course when I re-ran the script to test the whole thing it still worked fine because the domain was the same.

    Thanks for pointing that out! I've edited my post above to correct the silly error.
     
  8. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    It is work this script, with only one problem, DNS.
    If DNS is keepd on same server, then it will not work the site until is not added in DNS the domain.
    Is there a way to fix this, like: if DNS on (something = 1) then do ... else do nothing.
     
  9. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    OK, we finally find a solution for PLESK Alias.
    For the moment is basd on "made by hand", we work to add to Power Toys.

    Edit /etc/named.conf
    Add line
    include "/include/psaptzone.files";

    before
    /*
    zone "domain.com" {

    Save it.
    touch /var/named/run-root/include/psaptzone.files
    chown named:named /var/named/run-root/include/psaptzone.files

    Here you can add additional DNS (is an example)
    joe /var/named/run-root/include/psaptzone.files

    zone "grafxsoftware.com" {
    type master;
    file "/include/grafxsoftware.com";
    allow-transfer {
    193.226.140.147;
    193.226.140.248;
    common-allow-transfer;
    };
    };

    Save and edit
    joe /var/named/run-root/include/grafxsoftware.com

    Add a Zone like
    $TTL 86400

    @ IN SOA ns.grafx.ro. it.grafx.ro. (
    1109238549 ; Serial
    10800 ; Refresh
    3600 ; Retry
    604800 ; Expire
    86400 ) ; Minimum

    grafxsoftware.com. IN NS ns.grafx.ro.
    grafxsoftware.com. IN NS ns2.grafx.ro.
    mail.grafxsoftware.com. IN A 193.226.140.147
    grafxsoftware.com. IN A 193.226.140.147
    webmail.grafxsoftware.com. IN A 193.226.140.147
    ftp.grafxsoftware.com. IN CNAME grafxsoftware.com.
    lists.grafxsoftware.com. IN CNAME grafxsoftware.com.
    www.grafxsoftware.com. IN CNAME grafxsoftware.com.
    grafxsoftware.com. IN MX 10 mail.grafxsoftware.com.

    then create that 2 shell script what was discussed on this topic.

    newalias.sh

    #!/bin/bash
    # Do not use a www prefix with these domain names!
    # $1 Existing domain as known by plesk
    # $2 New domain to create

    echo "ServerAlias $1:80 www.$2" >> /home/httpd/vhosts/$1/conf/vhost.conf
    echo "ServerAlias $1:80 $2" >> /home/httpd/vhosts/$1/conf/vhost.conf
    echo $2 >> /var/qmail/control/rcpthosts
    DOMNUM=`grep "$1:" /var/qmail/control/virtualdomains | cut -f 2 -d':'`
    echo "$2:$DOMNUM" >> /var/qmail/control/virtualdomains
    /usr/local/psa/admin/sbin/websrvmng -a -v
    QSPID=`ps aux |grep qmail-send |grep -v grep|sed 's/[^0-9]*\([0-9]*\).*/\1/'`
    kill -HUP $QSPID

    uninsalias.sh

    #!/bin/bash
    # Do not use a www prefix with these domain names!
    # $1 Existing domain as known by plesk
    # $2 Aliased domain to remove

    grep -v \ www.$2$ /home/httpd/vhosts/$1/conf/vhost.conf | grep -v \ $2$ > /home/httpd/vhosts/$1/conf/vhost.conf.new
    cp /home/httpd/vhosts/$1/conf/vhost.conf /home/httpd/vhosts/$1/conf/vhost.conf.bak
    mv /home/httpd/vhosts/$1/conf/vhost.conf.new /home/httpd/vhosts/$1/conf/vhost.conf
    grep -v ^$2$ /var/qmail/control/rcpthosts > /var/qmail/control/rcpthosts.new
    cp /var/qmail/control/rcpthosts /var/qmail/control/rcpthosts.bak
    mv /var/qmail/control/rcpthosts.new /var/qmail/control/rcpthosts
    DOMNUM=`grep "$1:" /var/qmail/control/virtualdomains | cut -f 2 -d':'`
    grep -v ^$2:5$ /var/qmail/control/virtualdomains > /var/qmail/control/virtualdomains.new
    cp /var/qmail/control/virtualdomains /var/qmail/control/virtualdomains.bak
    mv /var/qmail/control/virtualdomains.new /var/qmail/control/virtualdomains
    /usr/local/psa/admin/sbin/websrvmng -a -v
    QSPID=`ps aux |grep qmail-send |grep -v grep|sed 's/[^0-9]*\([0-9]*\).*/\1/'`
    kill -HUP $QSPID

    Hope this help.
    This needed on case when the same PLESK maintain also the DNS.
     
  10. lauren

    lauren Guest

    0
     
    I think this solution works fine to setup domain aliases, but i have a doubt:

    I think Plesk rewrites configuration files (i.e. with mchk), but i don't know when it makes these actions.

    I try to execute mchk and it rewrites virtualhosts and rcpthosts and we loose the e-mail domain aliases.

    That involves that we need to run again the script every time Plesk rewrites config files.

    I'm in a mistake?
    knows anynone when Plesk rewrite config files?
     
  11. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    Don't know 100%, but as we tested is working fine.
     
  12. zymsys

    zymsys Guest

    0
     
    I've been using my original alias scripts posted above since posting them, and in that time the virtualhosts and rcpthosts files did get overwritten only once when upgrading Plesk. I also lost my antivirus wrapper. For the next upgrade I plan to write a "pre-upgrade" script to back up those files and a "post-backup" script to restore them.

    I would like to know what other events (if any) would cause them to be nuked.
     
  13. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    OK, need help.
    We are stucked.

    We have tried to add Domain Alias Script BUT we have problem to write into vhost.conf

    If we execute from shell, everything is OK, but if we call from PLESK Control Panel script have a deny, cannot write into /home/httpd/vhosts/$1/conf/ same is working in /tmp for example.

    Seems that we don't have with PHP to write into config folder.
    Anyone have an ideea? We are out from ideeas.

    We tried to execute from PHP file, we tried to make separate shell script and call from PHP, with root:psaadm, root:root, no luck :-(
     
  14. zymsys

    zymsys Guest

    0
     
    I've worked around similar problems in the past by using a suid root C wrapper to the shell script. This is playing with fire though and great care has to be taken for the wrapper to check all inputs and make sure it's root access isn't abused by an attacker.

    The permissions on the conf folder are 750, and it is owned by root, so root permissions are absolutely required to create a file in this folder.

    I would be happy to contribute a wrapper to do this, but I'm so absolutely swamped with development work its hard to find any time, and I use these scripts from the command prompt as root, so I don't have a personal need for them.

    Still, I want to help, so if I haven't posted anything in one week's time, PM or email me and I'll do my best to make some time. It should only take an hour or so. It would help me if you could send me what you have since I know a lot less about writing plesk extensions than I do about coding UNIX in C! My email address is vic@acm.org.
     
  15. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    I think in the same way is done by PLESK, but is not documented.
    If they do, is need to be a way to do it, just all source is closed and I don't think PLESK will help us on this. :-(
     
  16. lvalics

    lvalics Silver Pleskian Plesk Guru

    36
    43%
    Joined:
    Jun 20, 2003
    Messages:
    960
    Likes Received:
    28
    Location:
    Romania
    OK, we have done it.
    I will need a few betat tester for this new version, beta version.
    I looking only for beta testers who knows shell working as well, if something is going wrong, then solve it, cause not all can be from PLESK solve.

    If you want to apply, please write to it@grafx.ro

    What is new?

    - VHOST Writer, 100% editable with predefined things like open_basedir and php_flag log_errors (we will extend if anyone have other ideeas.

    - Alias/Unalias a domain (not available in this beta, mnday or thuesday will be

    Even if is seems that is a small adition to a new version, belive us is not. Those two is major ones :))
     
  17. thewolf

    thewolf Regular Pleskian

    25
    57%
    Joined:
    Mar 11, 2004
    Messages:
    231
    Likes Received:
    0
    Hi,

    Do you know if SWsoft has any plan to include a domain aliasing (web and email) feature in the next Plesk version?

    Thanks.
     
  18. zymsys

    zymsys Guest

    0
     
    I just got a reply in regards to this from SW-Soft support on Wednesday:
    So they are aware we want it, but I have no idea if they plan to act on it.
     
Loading...