Jump to content

Ispconfig Module


mitsos

Recommended Posts

Hi all,

Just pushed that pay now button for a blesta license :).

 

I would like to develop/help develop a blesta module for interfacing with the ISPConfig control panel. If anyone wishes to help/take over since I'm not a module developer, please download ISPConfig here. Extract the .gz file, and go into the ispconfig folder, then into remote_client. In there, there is documentation for interfacing with the server's api (open index.html in your browser), as well as examples for most (all?) functions.

 

What I need now is some pointers/hints on how to get started with the module. Eg: make this file, edit it to contain such and such, ispconfig's commands go there, test. Perhaps it might help if the cpanel module is analyzed since they are both control panels, with pressumably similar APIs.

 

Functions the module must perform:

1) Create an admin page for editing necessary module information. This must include a server list  and API access credentials for each server (access url, remote user and password, off the top of my head). Securely storing these in a secure place is a bonus (read necessity).

2)The module must be able to be told to assign new clients on this specific server (out of the list mentioned above), unless otherwise told not to, eg. server capacity is reached. Simple maximum clients = X for server Z is enough I think (in which case a new server must be selected from the list either automatically or manually by the admin).

3)Must be able to automatically provision new clients on the server, with a selected template used (eg a client selects X hosting package instead of Y during ordering, client is created on server with the template X in use (ISPConfig supports client templates)).

4)Must be able to poll the server in some way for information about the client/package (for billing addon bandwidth for example).

4)Must be able to automatically suspend the client on the server if the client did not pay.

5)Must be able to create/edit email templates. This will be helpful for the typical hosting provider scenario. Client selects package X, pays, account is created on the hosting server, client gets emailed with further instructions, eg here's your control panel, login using such and such.

6)OPTIONALLY (but extremely helpful) it must be able to administer the control panel account from within blesta. Eg: client logs in to your billing page, selects create new website, enters the domain/ftp/email/database info, and those get provissioned on the server).

 

I'm open to other user's input on required functions. And reminding everyone I'm not a developer but a sysadmin, so a bit of help getting started is required.

 

Thank you

Link to comment
Share on other sites

Been busy all day today, but managed to get a glimse at the cpanel module.

 

I have created this hierarchy:

 

/modules/
        /ispconfig/
        /apis/
             /ispconfig_api.php
        /language/
                 /en_us/
                       /en_us
                       /ispconfig.php
        /views/
              /default/
                      /manage.pdt
        ispconfig.php

 

I'm I on the right track so far?

 

 

Taking a look at /modules/cpanel/apis/cpanel_api.php shows this for adding a new account:

 

 

 

/**
    * Create a cPanel Account
    *
    * This function will allow one to create an account, the $acctconf parameter requires that the follow
    * three associations are defined:
    *    - username
    *    - password
    *    - domain
    *
    * Failure to prive these will cause an error to be logged.  Any other key/value pairs as defined by the createaccount call
    * documentation are allowed parameters for this call.
    *
    * @param array $acctconf
    * @return mixed
    * @link http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CreateAccount XML API Call documentation
    */

    public function createacct($acctconf)
    {
        if (!is_array($acctconf)) {
            error_log("createacct requires that first parameter passed to it is an array");

            return false;
        }
        if (!isset($acctconf['username']) || !isset($acctconf['password']) || !isset($acctconf['domain'])) {
            error_log("createacct requires that username, password & domain elements are in the array passed to it");

            return false;
        }

        return $this->xmlapi_query('createacct', $acctconf);
    }

I changed that to:

/**
    * Add new client
    * --------------
    * Adds a new client.
    */

    public function client_add($client_conf)
    {
        if (!is_array($client_conf)) {
            error_log("client_add requires that first parameter passed to it is an array");

            return false;
        }
        if (!isset($client_conf['username']) || !isset($client_conf['password']) || !isset($client_conf['domain'])) {
            error_log("client_add requires that username, password & domain elements are in the array passed to it");

            return false;
        }

        return $this->remoteapi_query('client_add', $client_conf);
    }

In the ispconfig download there is /ispconfig/remoting_client/examples/client_add.php which has this:

 

<?php

require('soap_config.php');


$client = new SoapClient(null, array('location' => $soap_location,
                                     'uri'      => $soap_uri,
                                     'trace' => 1,
                                     'exceptions' => 1));


try {
    if($session_id = $client->login($username,$password)) {
        echo 'Logged successfull. Session ID:'.$session_id.'<br />';
    }
    
    //* Set the function parameters.
    $reseller_id = 0; // this id has to be 0 if the client shall not be assigned to admin or if the client is a reseller
    $params = array(
            'company_name' => 'awesomecompany',
            'contact_name' => 'name',
            'customer_no' => '1',
            'vat_id' => '1',
            'street' => 'fleetstreet',
            'zip' => '21337',
            'city' => 'london',
            'state' => 'bavaria',
            'country' => 'GB',
            'telephone' => '123456789',
            'mobile' => '987654321',
            'fax' => '546718293',
            'email' => 'e@mail.int',
            'internet' => '',
            'icq' => '111111111',
            'notes' => 'awesome',
            'default_mailserver' => 1,
            'limit_maildomain' => -1,
            'limit_mailbox' => -1,
            'limit_mailalias' => -1,
            'limit_mailaliasdomain' => -1,
            'limit_mailforward' => -1,
            'limit_mailcatchall' => -1,
            'limit_mailrouting' => 0,
            'limit_mailfilter' => -1,
            'limit_fetchmail' => -1,
            'limit_mailquota' => -1,
            'limit_spamfilter_wblist' => 0,
            'limit_spamfilter_user' => 0,
            'limit_spamfilter_policy' => 1,
            'default_webserver' => 1,
            'limit_web_ip' => '',
            'limit_web_domain' => -1,
            'limit_web_quota' => -1,
            'web_php_options' => 'no,fast-cgi,cgi,mod,suphp',
            'limit_web_subdomain' => -1,
            'limit_web_aliasdomain' => -1,
            'limit_ftp_user' => -1,
            'limit_shell_user' => 0,
            'ssh_chroot' => 'no,jailkit,ssh-chroot',
            'limit_webdav_user' => 0,
            'default_dnsserver' => 1,
            'limit_dns_zone' => -1,
            'limit_dns_slave_zone' => -1,
            'limit_dns_record' => -1,
            'default_dbserver' => 1,
            'limit_database' => -1,
            'limit_cron' => 0,
            'limit_cron_type' => 'url',
            'limit_cron_frequency' => 5,
            'limit_traffic_quota' => -1,
            'limit_client' => 0, // If this value is > 0, then the client is a reseller
            'parent_client_id' => 0,
            'username' => 'guy3',
            'password' => 'brush',
            'language' => 'en',
            'usertheme' => 'default',
            'template_master' => 0,
            'template_additional' => '',
            'created_at' => 0
            );
    
    $affected_rows = $client->client_add($session_id, $reseller_id, $params);
    
    echo "Client: ".$affected_rows."<br>";

    
    if($client->logout($session_id)) {
        echo 'Logged out.<br />';
    }
    
    
} catch (SoapFault $e) {
    echo $client->__getLastResponse();
    die('SOAP Error: '.$e->getMessage());
}

?>

the soap_config.php file referenced there has this: (I believe this is irrelevant to the add client function I want to implement above, do correct me if I'm wrong (excluding the logging into the API part))

 

<?php

$username = 'admin';
$password = 'admin';

/*
$soap_location = 'http://localhost:8080/ispconfig3_3.0.5/interface/web/remote/index.php';
$soap_uri = 'http://localhost:8080/ispconfig3_3.0.5/interface/web/remote/';
*/


$soap_location = 'http://192.168.0.105:8080/remote/index.php';
$soap_uri = 'http://192.168.0.105:8080/remote/';


?>

 

I'm I on the right track, I'm I doing it completely wrong...? Please spare a light for a blind man (you could say I'm completely and utterly blind, always hated programming)

Link to comment
Share on other sites

I bit more info that popped into my mind when I got up and walked away from the pc. cpanel thinks that each client can only have 1 domain (vaguely remember this, code above seems to agree though). ispconfig thinks that each client can have a trillion (well not really, but many) domains. So the best compromise IMHO is to assign the client to the server using blesta's client ID (what I'm manually doing now), instead of a domain, which helps with administration as well.

Link to comment
Share on other sites

Been busy all day today, but managed to get a glimse at the cpanel module.

 

I have created this hierarchy:

 

/modules/
        /ispconfig/
        /apis/
             /ispconfig_api.php
        /language/
                 /en_us/
                       /en_us
                       /ispconfig.php
        /views/
              /default/
                      /manage.pdt
        ispconfig.php

 

I'm I on the right track so far?

 

The module file structure should be a minimum of:

/modules/
        /ispconfig/
            /language/
                /en_us/
                    /ispconfig.php
            /views/
                /default/
                    /manage.pdt
            ispconfig.php

You should look online for a copy of the ISPConfig API in PHP that you can integrate with, and not attempt to use the cPanel API with some tweaks. It looks like you have some sample code, which might help create some API functionality if you were going to do write the API for the module yourself, but that is definitely a time-consuming process.

 

The Module documentation may help you better understand how modules in Blesta work and what is necessary to develop your own.

Link to comment
Share on other sites

I have looked at the online documentation, but it's so limited, I didn't get anything out of it (except the module structure).

I don't know if I'm doing anything right (or wrong) which is frustrating to say the least.

 

For example can anyone glance over this and tell me if it will work?

 


   /**
    * Change an ISPConfig client's Password
    *--------------------------------------
    * Changes a client's password.
    * @param string $client_id The client's ID to change the password of
    * @param string $new_password The new password to change to
    * @return mixed
    *
    */
    public function client_change_password($client_id, $new_password)
    {

            if (!isset($session_id) || !isset($client_id)) {
            error_log("Changing a password requires the remote API's ID and the client's ID");

            return false;
        }

        return $remote_api->client_change_password($client_id, $new_password);
    }

Giving as much info as I can. ISPConfig's API (as far as I can tell, since even that documentation is pretty limited (only 1 example with a bit of commentary on the net)) is "something" that listens for remote instructions. Will the above code send those instructions? Assigning the $new_password is not what I'm trying to do at the moment, just getting the code to send that instruction right, since a form of some sort has to be created first to get the new password from the user/admin. The $remote_api in this case should be a function (if that's the right name) to login using the url/user/pass/session_id.

I hope I'm making some sense :P

Link to comment
Share on other sites

Hotter or colder?

    public function client_get($client_id)
    {
        if (!isset($client_id)) {
            error_log("client_get requires the client's ID");

            return false;
        }
        $client_record = $remote_api->client_get_id($sys_userid);

        return $client_record;
    }

Edit:had a revelation (or a stroke)

Link to comment
Share on other sites

$sys_userid is undefined. I can't tell if that function is intended to be a part of the ISPConfig API you're writing or not, but assuming that $remote_api is an object reference to the ISPConfig API, which contains the client_get_id method that accepts the parameter for $sys_userid--and indeed the API performs the necessary remote request upon calling this method--then yes, you could make that API request to perform the action. That is a lot of assumptions, and you still haven't gotten to the point of integrating that functionality through Blesta.

 

Usually when I begin writing a module, I start with the module itself in Blesta by building the required module methods and then integrate the API (if one is already available) to perform the actions on the module.

 

But like I mentioned, you should look online for an API integration that already exists. That will save you 5-20 hours of time from writing your own. Then it comes down to creating the module in Blesta and simply calling the API to perform actions. I would suggest looking over the code in existing modules to get a better idea of how the modules in Blesta work, but when it comes to the API, they are all different, and it's up to you to determine how best to integrate it with the module.

Link to comment
Share on other sites

Not to bust your bubble but the ISPConfig API is horrid and is in dire need of reworking.  I had the same idea for Blesta 2.5 when I got it but after I dove into it I realized it wasn't worth it.  Now, Blesta 3 has a hell of a better plugin architecture which makes it easier and more pleasant to work with, but the ISPConfig API is still leaving a lot to be desired.

 

You can do a lot with it, don't get me wrong.  But you're going to run into a lot of issues mostly due to poor documentation and even poorer code writing that the ISPConfig team has done with their product.  I literally had to read through each line to see what was needed and where.

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
  • 8 months later...
  • 2 months later...

I have a little update: I am implementing an ISPConfig Module myself now. It is still a work under progress right now though, and there are some limitations.

 

What is implemented already

- Adding and connecting to ISPConfig servers (singleserver and multiserver)

- Create packages, and automatically getting the available client templates from the selected ISPConfig Server. If multiserver, you can also select the web, db, mail and ns server (also automatically fetched from the ISPConfig multiserver-master, and available in a dropdown). 

- Create services in blesta,(by admin, or by order) -> Client is created in ISPConfig with the selected client template from the package. Possible auto generation of username, password and client contact name. (if "use Module is checked - else service is only created in Blesta)

- Delete services in blesta -> Client is deleted in ISPConfig (if "use Module is checked)

- If you already have clients in ISPConfig, and want to add them to Blesta, you can add a service in Blesta, and don't check the "use module" checkbox. You can then manually enter a the clientID of the existing ISPConfig client. Then the Blesta service and the ISPConfig client are connected through the clientID.

- You can suspend and unsuspend a service, which locks/disables the client in ISPConfig. However, this is a new function in ISPConfig, and the remote API function for locking/disabling clients is not working correctly yet. So this will only really work as soon as the ISPConfig team fixes this function.

 

What is not implemented, but should be i guess...

- Reselling is not implemented at all. We don't need that, so I just ignored the reselling options of ISPConfig and Blesta

 

The error-handling is also very lacking atm, and the source code is lacking documentation. But like I said - work in progress. :)

 

Below is a little screenshot of package creation for a multiserver.

post-10703-0-92160900-1417641933_thumb.p

Link to comment
Share on other sites

  • 1 month later...

thynan,

 

Interested in a ISPConfig integration with Blesta. Currently on WHMCS but moving one of my brands and decided to go with Blesta since it does multicompany. Is there a Git Hub location for your work? Do you want some help checking this out or is this a private endeavor?

 

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Hi, sorry for the late answer, I wasn't working on Blesta for a while..

 

At the moment there is no Git Hub location for the project. However, after checking back with my CEO we decided to make the module public. I will create a Git Hub project and check back here when i'm done. I will have to do some cleanup / documentation first, because atm it's still a bit too messy. :) 

 

It may take me a few days to get to it however, since I'm a bit swamped with work currently.

Link to comment
Share on other sites

  • 5 weeks later...
  • 7 months later...
Hi guys! 

Sorry for the delay. We were waiting for the new domain management of blesta to be finished, so the whole thing was put on ice. However, we now launched our blesta installation without domain management, and are using a workaround with universal module...

 

The module is used by us in production. However it is definitely not finished as a module that works out of the box for everyone. But maybe some of you can use it, or use it with some modifications, or even as a starting point for your own development.

 

I already wrote about the functions a bit a few posts back: http://www.blesta.com/forums/index.php?/topic/1210-ispconfig-module/?p=27826

 

Some Info, if you want to try the module:

  1. In our company, we have a free domain for every customer who orders a hosting package. To replicate this in the blesta module, i added a "domain" field, which the user can fill out during the order. If the customer entered a valid domain, the module automatically creates a DNS-Zone in ISPConfig for the user, using the default dns template configured in ISPConfig. The domain is also shown in the blesta UI, so the customer sees it as "included domain" This is a workaround, because it would be better to manage this with a domain module, but as I mentioned above, we are still waiting for the new domain management before managing domains correctly in blesta.  This "domain functionality" can be rather easily "pulled out" of the module though. Just search for the word domain, and remove what you dont need. (there are some TODO notes reagarding the domain/zone-file functionality in the code - check those out too)
  2. Reseller functions are not implemented at all.
  3. Be aware that this module is a work in progress, and definitely test everything on a testserver before using it. 
  4. I used the cpanel module which was implemented by the blesta devs themselves as a "guideline" for this module. And by "guideline" I mean that I copy pasted vigorously. ;) The reason for that is, that many of the functions (managing Servers, Packages, Services etc) are very similar in all hosting-panel modules, so it made sense to work with the structure that the blesta developers provided in their modules. 
  5. I did not really test the server-groups and the "use first non full server" option that blesta provides. That is one of the parts I copied from the cpanel module... It should work, but don't assume it before you tried.
  6. Generally read the TODO notes in the ispconfig.php file - they may offer some insight.. :)
 

Install instructions:

  • Install module as usual
  • Create a remote user in your ispconfig installation (system -> remote users)
  • You need to add some custom functions to the remoting.inc.php file of ispconfig. This is described in the remoting.inc.php file I included in the module.
  • Go to blesta -> system -> modules -> ispconfig -> manage -> add server

 

We usually use gitlab in our company, however for this project I set up a GitHub repo. This is my first GitHub repo - so bear with me. :)

I didn't create any issues or extensive readme yet - if some of you are interested in continuing development and organizing some collarboration, just let me know.

 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...