Extending the API

Discussion in 'Developers' Forum' started by Xenocide, Jul 15, 2014.

  1. Xenocide

    Xenocide Member

    Hi again!

    I'd like to add some more custom functions to the API for our particular setup. Prehaps i'd release them if there's any interest.

    What's the best way to go about doing this so that it will not get over written if there's any updates?

    I assume I need to make a new file (is there a directory which gets included automatically for additions like this?) and then extend the "remoting" class to add my new functions.

    Is that correct? Do I need to write a module and "install" it or can I add another file somewhere?

    Many thanks in advance.
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Thats correct for the current releases ( In the next major version this will change to make it easier to have custom functions. In ISPConfig 3.1 (the git master branch) you have a interface/lib/classes/remote.d/ directory were you can simply drop your custom class and it gets included automaticalyl in the api. The api in 3-1 is also available as REST api beside the current SOAP api.

    there is no new module needed, you can add your file e.g. in interface/lib/classes/ and then load it with $app->load('....');
  3. Xenocide

    Xenocide Member

    That sounds fantastic. I can't wait! :)

    Thank you for another prompt, in depth and helpful reply till. I really appreciate it!

    Now I know where to look i'll have a crack and see how I get on. Thanks again!
  4. Xenocide

    Xenocide Member

    Hi till,

    Sorry to be back so soon. I was wondering if you could elaborate on this a bit more. Where can I put the $app->load() line so that it won't be over written in future updates?

    Also if I were to extend the remoting class, eg:

    class remoting { ... } 
    class custom_remoting extends remoting { ... }
    Then wherever the

    $whatever = new remoting(); 
    bit is, it would need to be changed?

    I may have to put this off until 3.1 :).
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    1) Create a new file in the interface/web/remote/ folder, e.g. custom.php with this content:

    require_once '../../lib/config.inc.php';
    $conf['start_session'] = false;
    require_once '../../lib/app.inc.php';
    if($conf['demo_mode'] == true) $app->error('This function is disabled in demo mode.');
    $server = new SoapServer(null, array('uri' => $_SERVER['REQUEST_URI']));
    2) in interface/lib/classes/ you add a file custom_remoting.inc.php which contains your custom remoteing class that extends the "normal" remoting class.

    3) from your external scripts, you use remote/custom.php as remote endpoint for the soap calls.
  6. Xenocide

    Xenocide Member

    You the man. Can I marry you?

    Thank you again. :)

Share This Page