The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Script to create Forwarding accounts

Discussion in 'cPanel Developers' started by CityBrains, Nov 17, 2005.

  1. CityBrains

    CityBrains Member

    Joined:
    Nov 17, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hi all,

    I did some search in the forums here, but couldn't find what I was looking for and wanted to know if someone can help or direct me in someway.

    I would like to have a very simple small script (If can) that will create E-Mail Forwarding accounts and one for deleting them as well.

    End results would be the same thing as what the cpanel Forwarding Account do by setting up a user@mydomain.com => user@hotmail.com and not making a POP account.

    If there is some simple string pass I can send to cpanel from my website that will do a create or a delete would be best and the rest I would setup the passing commands to create such accounts.

    I have a forum and would like my members to be able to get a automatic Forwarding account as they register their user name and e-mail address. Like Tesman@hotmail.com will create a Testman@mydomain.com, which only forwards mail that came to their Testman@mydomain.com to Testman@hotmail.com

    Ops, I forgot to say if their was a PHP script or way to send info to cPanel to do so.

    :confused:
     
    #1 CityBrains, Nov 17, 2005
    Last edited: Nov 17, 2005
  2. CityBrains

    CityBrains Member

    Joined:
    Nov 17, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I am not sure if this is close, but was looking something like the following, but to create only Forwarding Accounts and another to delete them.

    Code:
    
    http://username:password@domain:2082/frontend/bluehost/mail/doaddpop.html[/email]?email=test123&domain=domain&password=test321
    
    
    I hope someone can direct me with some good samples or posts that I can't find.
     
    #2 CityBrains, Nov 17, 2005
    Last edited: Nov 17, 2005
  3. CityBrains

    CityBrains Member

    Joined:
    Nov 17, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I notist similar posts to my question that had no replies or directions. Am I posting in the wrong section or is there some other website I might find answers? or is this something that can't be done?

    I thought it was or sounds like a simple question that I just can't find an answer.

    Would this be a question to the cPanel staff or public area? I am new with cPanel and Exim mail controls and not sure how about to go with this and was hoping anyone who can give me some directions or links to finding some answers or hints.

    I hope someone can give me some kind of answer.


    :rolleyes:
     
  4. CityBrains

    CityBrains Member

    Joined:
    Nov 17, 2005
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ok, I did my research and finally got very close to what I want. The following functions is what I use to check if the Forwarding Account exists and one to create it. This Functions I add in /usr/local/cpanel/Cpanel/Accounting.php.inc

    PHP:
    function checkfrdacct ($domain,$faddr,$taddr) {

            
    $key $faddr ': ' $taddr;
            
    $fc=file('/etc/valiases/' $domain);
            foreach(
    $fc as $line)
            {
                    if (
    strstr($line,$key)) return true;
            }
            return 
    false;
    }
    function 
    createfrdacct ($domain,$faddr,$taddr) {

            
    $key $faddr ': ' $taddr;
            
    $fc=file('/etc/valiases/' $domain);
            
    $f=fopen("/etc/valiases/" $domain,"a");
            foreach(
    $fc as $line)
            {
                    if (
    strstr($line,$key)) return false;
            }
            
    fputs($f,$key); //place $line back in file
            
    fclose($f);

            return 
    true;
    }
    This is a sample code to call them:

    PHP:
    <?
        require 
    '/usr/local/cpanel/Cpanel/Accounting.php.inc';

        
    $tt checkfrdacct'mydomain.com' 'forward@mydomain.org' 'target@realdomain.com' );
        
    $ss createfrdacct'mydomain.com' 'forward@mydomain.org' 'target@realdomain.com' );
        echo 
    $tt
        
    echo $ss
    ?>
    My problem is not that I don't have permission to write over the Forwarding domain file. I do have root access as the owner to the server, but not sure how to make my domain accounts under cpanel be able to over write this file. Any one know how or what I need to do to be able to run the above code, which calls the functions and then to over write the root area Forwarding files?
     
    #4 CityBrains, Nov 20, 2005
    Last edited: Nov 20, 2005
  5. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    I recently posted a tutorial on how to combine the remote access features of WHM with your own scripts so that you can, from a normal account, get scripts to run as root. Such scripts would then have sufficient privileges to do what you need.

    Using the methods in the tutorial but modifying it for your needs would let you achieve what you want to.

    http://forums.cpanel.net/showthread.php?t=46362
     
Loading...

Share This Page