New ISPConfig module for WHMCS

Discussion in 'Tips/Tricks/Mods' started by cwispy, Dec 11, 2014.

Thread Status:
Not open for further replies.
  1. webguyz

    webguyz Active Member HowtoForge Supporter

    Was also thinking a cool feature would be to find the server in a servers group that has the least amount of disk space used and install the new website on that server. Can't imagine that would be possible using just remote API. Would require a script on each server periodically updating a table with the name of the server and total disk space used and then do a Select Min(disk_space) on table to find the least busy server and balance out all servers for best performance. Anyone else have thoughts on how to accomplish load balancing if you have a lot of servers?
     
  2. webguyz

    webguyz Active Member HowtoForge Supporter

    cwispy,
    I'm having an issue with php-fpm and the script. I create the new domain ok and it says the version of php I'm using using is php-fpm, but I am unable to run a php file on the new website AND all the other websites on that server get a 500 error when trying to run .php files. I have to go to the newly created website and check the 'Use Socket for PHP-FPM' box which is not checked when created and then have to restart php5-fpm and apache2 and then I can use php-fpm on all websites without getting a 500 error when running any .php file.

    Can it be set to have the new domain have the 'Use Sockets for PHP-FPM' checked during creation? Took me a while to realize what was happening. Thought I had a bad install of the slave server but after re-creating the slave server (carefully) and getting the same result it has to be the script not setting something.

    If I manually create a website using the gui the 'Use Socket for PHP-FPM' box is checked and it defaults to dynamic process manager and I have no problems running .php files on the new site or other websites on that server.

    Any ideas as to whats going on?

    Thanks!
     
  3. webguyz

    webguyz Active Member HowtoForge Supporter

    Added a few more parameters to the $ispcparams array in the ispccfg3.php script and now my newly added websites via the script are working as I wanted them to using php-fpm as a default:

    'php_fpm_use_socket' => 'y',
    'pm' => 'dynamic',
    'pm_max_children' => '10',
    'pm_start_servers' => '2',
    'pm_min_spare_servers' => '1',
    'pm_max_spare_servers' => '5',
    'pm_process_idle_timeout' => '10',
    'pm_max_requests' => '0',
     
  4. radim_h

    radim_h Member HowtoForge Supporter

    Hello cwispy,

    i have tested the module and i see one problem.
    You are creating new ISPConfig user account for every new page of WHMCS the client. But when i want to create second webpage for same WHMCS user, script tries to create same user second time. I get errro, page is not created and in WHMCS activity log i see an error "Module Create Failed - Service ID: 404 - Error: SOAP Error: customer_no_error_unique<br /> username_error_unique<br> Duplicate username<br />"

    And some questions:
    - is it possible somehow to create DNS record when only domain with no webhosting is created?

    - haven you think about direct logging into ISPConfig , i mean in clientarea page in whmcs, do not show clients login/pass in "Change password" section and take client directly into ISPConfig when cliking on "CONTROLPANEL LOGIN" which should be called "manage webpage" or something ?

    I also do not understand numbering in ISPCOnfig,my first "Customer No," in clean installation is 394.
    BTW it would be great have Customer No in ISPC depending on customer Number in WHMCS, as for customer 55, first ISPC account 55-1, second one 55-2 etc.. ISPC allows it..
     
    Last edited: Apr 18, 2015
    the1matrix1 likes this.
  5. cwispy

    cwispy Active Member

    Hi Webguyz,

    I have my systems configuring the sites using php-fpm and I do not get the issue you were getting. Did you configure the php settings in System, Server Config, <your webserver>. Web, Php settings?

    Thats the only settings I can think of that might be different to mine.
     
  6. cwispy

    cwispy Active Member

    Hi Radim_h,

    The customer number in ISPConfig is to the product_id in WHMCS. That way there is never a duplicate ID used which was the initial problem I ran into when I used the WHMCS customer_id.
     
  7. webguyz

    webguyz Active Member HowtoForge Supporter

    Hmm, all six of my web servers have the same setting in System,Server Config * ,Web, php settings. Not sure why mine is acting different from yours, but I'm just happy its working. :) Great job on this script!!
     
  8. radim_h

    radim_h Member HowtoForge Supporter

    Hi cwispy.
    so why then i have descibed problem
    "When i want to create second webpage for same WHMCS user, script tries to create same user second time. I get errro, page is not created and in WHMCS activity log i see an error "Module Create Failed - Service ID: 404 - Error: SOAP Error: customer_no_error_unique<br /> username_error_unique<br> Duplicate username<br />" " ?

    downloaded script from here https://github.com/cwispy/ispcfg3 , is this the newest version ? it is saying ispcfg3.php is 2 moths old..
     
  9. webguyz

    webguyz Active Member HowtoForge Supporter

    radim_

    Check your ISPConfig clients and make sure the user your trying to add does not already exist. When I was checking out the script initially I would get those errors because even if the whole script was not successful, it did get thru to add a new client. Went I tried to re-run the order in the orders list it would give me that error your getting. I went to ispconfig and looked in the clients and sure enough that client was added, even if the overall script failed for some reason.

    If your testing the script and it fails, it may have already created the client so check that. I would have to delete the client in ispconfig and then re-run the pending order.
     
  10. radim_h

    radim_h Member HowtoForge Supporter

    Hello,
    i have downloaded zip file from github and it has date Feb 22 08:02. Is this the latest version of script?
     
  11. cwispy

    cwispy Active Member

    Yes that would be the latest version on github.
     
  12. AVG

    AVG Member

    Hello cwispy.
    I have a question.
    Well, if client is manuali created another ftp user by control panel in ISPConfig, then for example WHMCS is suspended client, WHMCS is suspending only that ftp client which is created by WHMCS --> API --> ISPConfig.
    That client which is created manuali in ISPConfig remains active.
     
  13. cwispy

    cwispy Active Member

    Hi AVG,

    This is a good pickup. At the moment, the script is only configured to disable to the ftp account it creates. This will need to be changed.

    cwispy
     
  14. AVG

    AVG Member

    In ISPCongig user interface there is an option like Locked (disables all webs etc.) for each client, but i dont now if it works from ISPConfig API.
     
  15. cwispy

    cwispy Active Member

    This function is not available through the API as yet as far as I am aware.
     
  16. cwispy

    cwispy Active Member

    I have just submitted the below patch to github for the ftp user suspending issue.

    Code:
             
    @@ -784,15 +784,20 @@ function ispcfg3_SuspendAccount( $params ) {
    
    if ( $addftpuser == 'on' ) {
               
    -           $username = $username . 'admin';
    -           $ftpclient = $client->sites_ftp_user_get( $session_id, array( 'username' => $username ) );
    -         
    -           $ftpclient[0]['active'] = 'n';
    -           $ftpclient[0]['password'] = '';
    -           $ftpid = $client->sites_ftp_user_update( $session_id, $sys_userid, $ftpclient[0]['ftp_user_id'], $ftpclient[0] );
    -         
    -           logModuleCall('ispconfig','Suspend Ftp User',$ftpclient[0]['ftp_user_id'], $ftpclient,'','');
    +            $ftpclient = $client->sites_ftp_user_get( $session_id, array( 'username' => $username.'%' ) );
              
    +            $i = 0;
    +            $j = 1;
    +            while ($j <= count($ftpclient) ) {
    +          
    +                $ftpclient[$i]['active'] = 'n';
    +                $ftpclient[$i]['password'] = '';
    +                $ftpid = $client->sites_ftp_user_update( $session_id, $sys_userid, $ftpclient[$i]['ftp_user_id'], $ftpclient[$i] );
    +                $i++;
    +                $j++;
    +                logModuleCall('ispconfig','Suspend Ftp User',$ftpclient[$i]['ftp_user_id'], $ftpclient[$i],'','');
    +          
    +            }
             }
           
             if ( $addmaildomain == 'on' ) {
    @@ -917,15 +922,20 @@ function ispcfg3_UnsuspendAccount( $params ) {
           
             if ( $addftpuser == 'on' ) {
               
    -           $username = $username . 'admin';
    -           $ftpclient = $client->sites_ftp_user_get( $session_id, array( 'username' => $username ) );
    -         
    -           $ftpclient[0]['active'] = 'y';
    -           $ftpclient[0]['password'] = '';
    -           $ftpid = $client->sites_ftp_user_update( $session_id, $sys_userid, $ftpclient[0]['ftp_user_id'], $ftpclient[0] );
    -         
    -           logModuleCall('ispconfig','UnSuspend Ftp User',$ftpclient[0]['ftp_user_id'], $ftpclient,'','');
    +            $ftpclient = $client->sites_ftp_user_get( $session_id, array( 'username' => $username.'%' ) );
              
    +            $i = 0;
    +            $j = 1;
    +            while ($j <= count($ftpclient) ) {
    +          
    +                $ftpclient[$i]['active'] = 'y';
    +                $ftpclient[$i]['password'] = '';
    +                $ftpid = $client->sites_ftp_user_update( $session_id, $sys_userid, $ftpclient[$i]['ftp_user_id'], $ftpclient[$i] );
    +                $i++;
    +                $j++;
    +                logModuleCall('ispconfig','UnSuspend Ftp User',$ftpclient[$i]['ftp_user_id'], $ftpclient[$i],'','');
    +          
    +            }
             }
    
     
  17. cwispy

    cwispy Active Member

    Committed some more changes to github just now. I have started adding code that will add the appropriate dns records depending on the server that is chosen to host the service. This means you need to alter the DNS Template in ISPConfg. Remove all the records except the Zone and NS records. For example.

    Code:
    [ZONE]
    origin={DOMAIN}.
    ns={NS1}.
    mbox={EMAIL}.
    refresh=7200
    retry=540
    expire=604800
    minimum=86400
    ttl=3600
    
    [DNS_RECORDS]
    NS|{DOMAIN}.|{NS1}.|0|3600
    NS|{DOMAIN}.|{NS2}.|0|3600
    Currently I have the MX record done.

    I have also added the additional fields to the website creation for php-fpm that were missing and removed some unused code here and there.
     
  18. cwispy

    cwispy Active Member

    I have now added code to add an A record and a CNAME record for the website. It will add these records to dns for the website.

    domain.tld. IN A <webserver ip address>
    www IN CNAME domain.tld.

    Note: This code relies on the IP addresses in WHMCS being correct. If the server names and ip addresses are incorrect, you will end up with errors in the created dns records, or you may get an error during creation.
     
  19. webguyz

    webguyz Active Member HowtoForge Supporter

    Thanks for the updates!

    Was thinking of a possibility of having a group of webservers in WHMCS and choosing one that had the least amount of websites. Originally was thinking least of amount of space used but that would be too messy. But the remote api can get a list of web sites and the servers they are on so it should be possible to get the server with a least amount of websites from a set of servers in a group and present that as being the webserver to install the new account on and add to the DNS in your script.

    Just a thought.
     
  20. cwispy

    cwispy Active Member

    This code already does a random selection of the server in the event that there is more than one server available for the task.

    Code:
            if (count( $server['web_server'] ) == 1 ) {
               
                $defaultwebserver = $server['web_server'][0]['server_id'];
               
            } else {
               
                $rnd = rand(0, ( count( $server['web_server'] ) - 1 ) );
                $defaultwebserver = $server['web_server'][$rnd]['server_id'];
               
            }
    I guess it could be improved upon, but that would require more effort and probably some way of tracking the load on the servers to know which server to go to next.
     
Thread Status:
Not open for further replies.

Share This Page