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.

Cpanel PHP Accounting functions

Discussion in 'General Discussion' started by andyf, Feb 26, 2003.

  1. andyf

    andyf Well-Known Member

    Joined:
    Jan 7, 2002
    Messages:
    246
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    I notice that the Perl version of the accounting has been expanded quite significantly to include a whole list of new integration features.

    Any chance the same will be done to the PHP version soon?

    Thanks.
     
  2. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    Hi,
    I dont see any extra features with the perl accounting module,
    however, if you post the extra features you have found I would be happy to add them into the php accounting module for you,
    Thanks
     
  3. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    By the way, if anyone else would like some extra functions for the accounting module, I heard that some people wanted password modification features etc, I would be happy to add them,
    when tested working maybe the cpanel staff will add the new file into the distribution so its easier for everyone :)
     
  4. gic

    gic Well-Known Member

    Joined:
    Jun 28, 2002
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    6
    Yes. Thanks to jimcarter, I too now understand how this stuff works. If you need functions written, let me know. I have upgrade/downgrade, password mod, create, remove, and I am going to setup suspend/unsuspend. They are very easy to understand.

    I can also create new functions for you.
     
  5. andyf

    andyf Well-Known Member

    Joined:
    Jan 7, 2002
    Messages:
    246
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    Ok, I consider myself fairly proficient in PHP.

    Any chance you guys could give us a rundown on how these little babies work? :)
     
  6. gic

    gic Well-Known Member

    Joined:
    Jun 28, 2002
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    6
    Okay. The two parts. First off is how to use the fuctions. That is pretty straight forward. We will use the createacct for an example.

    PHP:
    <?
    require 
    '/usr/local/cpanel/Cpanel/Accounting.php.inc';
        
    $host "localhost";
        
    $user "root";
        
    $accesshash 'ACCESS HASH SHOULD BE PASTED HERE';    
        
    $usessl "0";

    $do createacct($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan);
    if (!
    eregi("wwwacct creation finished",$do)){
        echo 
    "Oh no.  There was a problem.";
    }
    else {
        echo 
    "Great, the account $acctuser was created successfully.";
    }
    ?>
    For this example, all that you need to give it are:
    $host = your hostname (usually localhost)
    $user = your WHM username (either root or reseller name)
    $accesshash = the access hash pasted directly from WHM
    $usessl = 1 means to use cURL, 0 means to use socket_connect
    $acctdomain = the domain name of the new account
    $acctuser = the username of the new account
    $acctpass = the password of the new account
    $acctplan = the plan name of the new account. (if the plan name has a space, replace it with a + sign)

    Just send those variable to this PHP file and it will create the account. If the account is created, it says "Great, the account $acctuser was created successfully". Otherwise it says "Oh no. There was a problem".

    -----------------

    Next, we look at functions... This came out of my Accounting.php.inc file.
    PHP:
    function changepass ($host,$user,$accesshash,$usessl,$acctpass,$acctuser) {
        
    $result whmreq("/scripts/passwd?remote=1&nohtml=1&password=${acctpass}&domain=${acctuser}&user=${acctuser}&submit-domain=Change%0D%0A++++++Password",$host,$user,$accesshash,$usessl);
        if (
    $cpanelaccterr != "") { return; }
        return 
    $result;
    }
    This is a new function that I made. It allows you to change the password of an account.

    The part after result (/scripts/passwd) was taken directly from WHM when you submit the form to change the password. Then I inlclude the variables that the password script needs.

    Now, I just have to provide the following in a PHP file:
    PHP:
    <?
    require 
    '/usr/local/cpanel/Cpanel/Accounting.php.inc';
        
    $host "localhost";
        
    $user "root";
        
    $accesshash 'ACCESS HASH GOES HERE';    
        
    $usessl "0";

    $do changepass($host,$user,$accesshash,$usessl,$acctpass,$acctuser);
    if (
    eregi("syntax mismatch",$do)){
        echo 
    "OOps, you broke it.  I don't think that the username was correct.";
    }
    else {
        echo 
    "Great job!  Your password has been changed to $acctpass.";
    }
    ?>
    Okay, in the example above, you just provide:

    $host = hostname (localhost usually)
    $user = your WHM username (root or reseller name)
    $accesshash = the access hash directly from WHM
    $usessl = 1 means to use cURL, 2 means socket_connect
    $acctpass = the new password of the account in cpanel
    $acctuser = the username of the account you want to change

    If it is successful, it prints "Great job! Your password has been changed to $acctpass". If it isn't, it prints "OOps, you broke it. I don't think that the username was correct".

    If you have any other questions, post 'em here.
     
  7. andyf

    andyf Well-Known Member

    Joined:
    Jan 7, 2002
    Messages:
    246
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    Simply call to the /scripts or /scripts2 links that WHM uses during normal operations then?

    Seems simple, I shall give it a go :)

    Thanks!
     
  8. gic

    gic Well-Known Member

    Joined:
    Jun 28, 2002
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    6
    yeppers
     
  9. ukhost

    ukhost Well-Known Member

    Joined:
    Jan 8, 2002
    Messages:
    222
    Likes Received:
    0
    Trophy Points:
    16
    Hi,

    Id like to see the ability to upgrade/downgrade, password modification and the creation/removal of reseller accounts.

    Anyone got these functions setup?

    Kind Regards,

    Neil
     
  10. r3lic

    r3lic Registered

    Joined:
    Apr 5, 2003
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I'm useing this exact same script (minus the code and the user), almost the very same example script that cpanel offers, but this thing doesn't work.

    <?php
    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host2 = "localhost";
    $user2 = "<user here>";
    $usessl = "0";
    $accesshash = '<access here>';

    $pkgs = listpkgs($host2,$user2,$accesshash,0);
    print_r($pkgs);

    ?>

    Any thought as to why it might not work?
     
  11. laundryp

    laundryp Member

    Joined:
    Apr 21, 2003
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    yep

    Might be same problem I had.

    curl was not installed, and there is a bug with using new PHP and the Accounting scripts sockets part. I fixed the bug myself and tkoweb reported it.
     
  12. s3kk3y

    s3kk3y Well-Known Member

    Joined:
    Oct 12, 2002
    Messages:
    94
    Likes Received:
    0
    Trophy Points:
    6
    I would greatly appreciate it if someone was able to create a script to auto create reseller accounts. The current way of doing it a bit tedious and long.
     
  13. jimcarter

    jimcarter Well-Known Member

    Joined:
    Jun 30, 2002
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    it is not too hard to do something like this depending on how you want the accounts to be automatically created, i.e. maybe you want them created through your billing system or something,
    unfortunately I dont feel like giving all my reseller scripts away :D
    thanks
     
  14. Steven_K

    Steven_K Member

    Joined:
    Jun 14, 2003
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    I used the code by gic to create accounts and filled in all the variables etc but the error it returned was 'Please use the this syntax wwwacct'.

    Anybody know what I should do to fix this?

    cPanel.net Support Ticket Number:
     
  15. Steven_K

    Steven_K Member

    Joined:
    Jun 14, 2003
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    UK
    Anyone? I need some help with this.

    Thanks.

    cPanel.net Support Ticket Number:
     
  16. rvskin

    rvskin Well-Known Member
    PartnerNOC

    Joined:
    Feb 19, 2003
    Messages:
    400
    Likes Received:
    1
    Trophy Points:
    18
    One thing I would like to warning you about this code. You are explosing security issue to your server. The essencial part is $accesshash now on php code which world readable. Any clients on your server could easily find them(if they know about how Cpanel works) and workaround to do with all your accounts.

    cPanel.net Support Ticket Number:
     
  17. NetPires

    NetPires Member

    Joined:
    Jul 5, 2003
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    How can I create a domain forwarding (domainfwd) using PHP remote control?

    cPanel.net Support Ticket Number:
     
  18. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Re: yep

    Hi, is this problem still existing? Because I have exactly the same problem. How can I fix this bug?

    Mike

    cPanel.net Support Ticket Number:
     
  19. andyf

    andyf Well-Known Member

    Joined:
    Jan 7, 2002
    Messages:
    246
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    UK
    Re: Re: yep

    IIRC this is due to the way it processes headers from apache in the sockets part of the script. You need to edit near line 122 and add a third condition something like:
    Code:
                      if(preg_match("'\n$'s", $buf)) {
                            $inheader = 0;
                      }
    
    the exact regexp might be a bit off, I'm recalling it from memory as I dont have access to the script right now. But it's happening because the condition which tests for the end of the header isn't being met, seems apache stopped returning all the control characters the script expects and I think it now just returns a single /n newline as the seperator.

    Alternatively (and far far more secure) is to compile php with CURL and CURL SSL and make usessl=1.

    HTH

    cPanel.net Support Ticket Number:
     
  20. CoolMike

    CoolMike Well-Known Member

    Joined:
    Sep 6, 2001
    Messages:
    307
    Likes Received:
    0
    Trophy Points:
    16
    Ok, thanks I will try this. Curl is already installed, but if I would like to use this usessl=1, I'm just getting a empty page. Here is the curl information in phpinfo():

    CURL support enabled
    CURL Information libcurl/7.10.3 OpenSSL/0.9.6b zlib/1.1.4

    Would be really great, if we get this to work.
    Thanks
    Mike

    cPanel.net Support Ticket Number:
     
Loading...

Share This Page