CLI API Documentation

Axigen's PHP Command Line Interface API reference guide

10.0.0.5

What is CLI API?

CLI API is a PHP wrapper that allows an administrator to programatically perform administration tasks on an Axigen server, such as provisioning accounts, domains or mailing lists or configuring various server parameters. It is built on top of the Axigen Command Line Interface service and it exposes many (but not all) of the commands that are available in the CLI.

When using CLI API work begins in the Axigen class (also called "the CLI Object"). The Axigen class contains code that allows the caller to establish a session to the Axigen server (using the Axigen::connect function). Once a session is established other methods can be called that return their own clasess that can be used to perform provisioning actions.

Code Examples

Establish a session

<?php
    require_once("Axigen.php");
    $session = new Axigen();
    $session->connect("IP", "CLIPORT", "ADMINUSER", "ADMINPASSWORD");
?>

List all accounts from a domain

This sample demonstrates listing all accounts from a domain.

<?php
    require_once("Axigen.php");
    $session = new Axigen();
    $session->connect("IP", "CLIPORT", "ADMINUSER", "ADMINPASSWORD");

    // check if the domain exists
    $domains = $session->listDomains();
    if(!in_array("localdomain", $domains)) {
        print "The domain \"localdomain\" doesn't exist";
        exit(1);
    }
    // load accounts
    $accounts = $session->updateDomain("localdomain")->listAccounts();
    var_dump($accounts);
?>

Add a new account (mailbox) in a domain

This sample demonstrates creating a new account in a domain, updating the new account's contact data and adding an account alias.

<?php
    # get the domain object
    $domain = $session->updateDomain("bisisica");

    # create a new account
    $account = $domain->addAccount("user10", "usr10pwd");

    # update the newly created's account data
    $account = $domain->updateAccount("user10");
    $contact_info = $account->configContactInfo();
    $contact_info->firstName = "John";
    $contact_info->lastName = "Doe";
    $contact_info->save();
    # add an alias
    $account->addAlias("john.doe");
    # save changes
    $account->save();
?>

Get server version

This sample demonstrates connecting to the Axigen CLI and retrieving the server version.

<?php
    require_once("Axigen.php");
    $session = new Axigen();
    $session->connect("IP", "CLIPORT", "ADMINUSER", "ADMINPASSWORD");
    print $session->axigenVersion();
?>

The sample above will print something like:

10.0.0.1-debug (Linux/x64)|Linux|x86_64

Configure catchAll for a domain

This sample demonstrates configuring catchAll for a domain.

<?php
    require_once("Axigen.php");
    $session = new Axigen();
    $session->connect("IP", "CLIPORT", "ADMINUSER", "ADMINPASSWORD");

    $domain = $session->updateDomain("example.com");
    $domain->catchAllType = "account";
    $domain->catchAllAccountName = "postmaster";
    $domain->catchAllFolderName = "ca_folder";
    $domain->save();
?>

Installing CLI API

Software requirements

Axigen CLI API runs on:

  • Linux supported platforms (e.g. RedHat, CentOS, Debian, Ubuntu).
  • Windows supported platforms (Windows 2008, 2012)
  • PHP supported versions (5.2-5.6)

Files and directories

  • cliclient.so/dll - needs to be located in php extension directory
  • php files - need to be located in php include path

Installing

  • edit your php.ini
  • search for extension_dir and see where the path is set to
  • search for include_path
  • append to include path ":/somepath/AxigenCliApi/"
  • append the following line to your php.ini: extension = "cliclient.so"
  • check php if is compile with threads or not to see what cliclient to copy
  • check your OS, CPU to see what cliclient library to copy
  • mv cliclient_(OS)_(CPU)_(THREADS).so to the path from extension_dir/cliclient.so
  • tar zxvf phpfiles.tgz -C /somepath/AxigenCliApi/
  • restart your apache server
  • to start using Axigen CLI API, include "Axigen.php" and check the CLI Object Documentation on how to use it.

Check for PHP Threads support

You can check if your php has Threads support by following these steps:

  • php cli:
  • run this command in a shell:
    • php --info | grep "Threads Safety"
  • php apache:
  • create a php file containing <?php phpinfo(); ?>
    • fetch that file via apache and find the "Threads Safety" string
  • If "Threads Safety" is enabled, use the library with threads, otherwise, use the one with no threads.