Mgr library

From ISPWiki

Jump to: navigation, search

Contents

Introduction

A library allows you to work with our software products from user scripts.

Using Perl

Start the program:

BEGIN { push @INC, '/usr/local/ispmgr/lib/perl' }

use Mgr;

Queries to the control panel (the query function)

Send a query to the control panel using the query function:

($xmldoc, $xmlroot) = Mgr::query (function_name, parameters_list[, output_type]);

where:

function_name
name of the control panel function to be called.
parameters_list
parameters to be transferred to the control panel. This is the list of lists. For example: [['elid', 'root'], ['su', 'admin']]
output_type
XML output type: xml is used by default, devel. Optional parameter.

Two values are returned:

  1. XML::LibXML::Document (XML document)
  2. XML::LibXML::Node (XML root element)

Examples

($xmldoc, $xmlroot) = Mgr::query ('user', []);

Get the users' list.

($xmldoc, $xmlroot) = Mgr::query ('user.edit', ['elid', 'someuser']);

Get the someuser's data.

($xmldoc, $xmlroot) = Mgr::query ('user.edit', ['elid', 'someuser'], 'devel');

Get the someuser's data in the 'devel' format.

Getting current user data (the session function)

If you wish to get the data of the current user who made a request to the control panel, use the session function.

$ses = Mgr::session (cookie_name, CGI_object);

Where:

cookie_name
name of the control panel cookie. E.g. 'ispmgr4'.
CGI_object
Perl object CGI: $Q = new CGI.

The function returns either undef (user not found) or the link to the hash with keys:

skin
Current skin.
lang
Current language.
sesid
User session id.
username
User name.
ip
User IP-address.

If the request was sent via mgrctl, only username will be returned.

Examples

my $Q = new CGI;
my $ses = Mgr::session ('ispmgr4', $Q);

if (!defined $ses || $ses->{username} ne 'root') {
  print "Authentication failed!\n";
  exit;
}

If the user is not authorized or does not have root privileges, you need to add the line to deny authorization.

Using Python

Start the program:

from sys import path
path.append('/usr/local/ispmgr/lib/python') 
import mgr

Control panel queries (the query function)

To send a query to the control panel, use the query function:

xmldoc, xmlroot = mgr.query(function_name, parameters_list [, output_type] [, mgrname]);

Where:

function_name
name of the control panel function to be called.
parameters_list
parameters to be transferred to the control panel. This is a list of the lists, such as [['elid', 'root'], ['su', 'admin']]
output_type
XML output. Possible values: xml is used by default, devel. Optional parameter.
mgrname
control panel to be called: ispmgr (default), billmgr, etc. Optional parameter.

The following values are returned:

  1. xml.dom.minidom.Document (an XML document)
  2. xml.dom.minidom.Element (XML root element)


Examples

xmldoc, xmlroot = mgr.query('user', [])

Get the users' list.

xmldoc, xmlroot = mgr.query('user.edit', [ ['elid', 'someuser'] ])

Get the someuser's data.

xmldoc, xmlroot = mgr.query('user.edit', [ ['elid', 'someuser'] ], out='devel')

Get the someuser's data in the 'devel' format.

Getting the current user data (the session function)

If you wish to get the current user data, use the session function.

ses = mgr.session(name_cookie, [, object_CGI] [, mgrname]);

where:

name_cookie
name of the control panel cookie, such as 'ispmgr4'.
object_CGI
HTTP_COOKIE environment variable is used by default. This is an optional parameter.
mgrname
control panel to be called.ispmgr is used by default, billmgr, etc. Optional parameter.

The function returns either None (user not found), or the hash with keys:

skin
control panel skin.
lang
control panel language.
sesid
user session ID.
username
user name.
ip
user IP address.
level
user access level.

If the request was sent via mgrctl, only username is specified.

Example

ses = mgr.session('ispmgr4')
if ses is None or ses['username'] != 'root':
    print "Authentication failed!\n"

If the user is not authorized or does not have root privileges, add the line to deny authorization.

Was this helpful? Yes | No
Personal tools