Calls to API from plugin handler code
Calls to the ispmanager API can be made in several ways (described in detail here), inside the plugin code it is preferable to use the mgrctl utility — its advantages are described above.
By default, mgrctl returns data as text (example call for webdomain.edit function - new site creation form - first output lines):
ssl_port=443
ssi=on
basedir=on
log_access=on
log_error=on
show_params=yes
...
Example of text output for a list (netactconn function - list of active connections):
key=ihttpd->85297 appname=ihttpd count=1
key=sshd->523147 appname=sshd count=1
You can use the -o devel option to get XML or -o json to get JSON if it is more convenient to work with other formats in your handler.
Request parameters can be passed to the mgrctl utility in the format parameter name_parameter=parameter_value. The sok=ok parameter can be used to send form data to perform the appropriate operation.
The su=user_name parameter allows the function to be executed as a specific user (plugin code is executed as root super administrator and therefore mgrctl in plugin code will be executed as root by default).
Examples of mgrctl utility calls:
- Get example.com data in JSON format:
/usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain.edit elid=example.com -o json
- Create a site with the name example.com and admin email admin@example.com, get the result of the operation in XML format:
/usr/local/mgr5/sbin/mgrctl -m ispmgr webdomain.edit name=example.com sok=ok "email=admin@example.com" -o devel
- Get a list of all databases available to the user john in text format:
/usr/local/mgr5/sbin/mgrctl -m ispmgr db su=john
Example of using ispmanager API in plugin: output of a database list
A useful way to get parameters for calls to standard ispmanager functions is also described here.